Items
This commit is contained in:
parent
77c3da28dc
commit
fa844d37cb
|
@ -1,20 +1,32 @@
|
|||
- id: pond
|
||||
name: Pond
|
||||
nearby: []
|
||||
nearby:
|
||||
- lake
|
||||
- river
|
||||
- sea
|
||||
hasSand: true
|
||||
objects: []
|
||||
- id: lake
|
||||
name: Lake
|
||||
nearby: []
|
||||
nearby:
|
||||
- pond
|
||||
- river
|
||||
- sea
|
||||
hasSand: false
|
||||
objects: []
|
||||
- id: river
|
||||
name: River
|
||||
nearby: []
|
||||
nearby:
|
||||
- pond
|
||||
- lake
|
||||
- sea
|
||||
hasSand: false
|
||||
objects: []
|
||||
- id: sea
|
||||
name: Sea
|
||||
nearby: []
|
||||
nearby:
|
||||
- pond
|
||||
- lake
|
||||
- river
|
||||
hasSand: true
|
||||
objects: []
|
||||
|
|
7281
config/pokedex.yml
7281
config/pokedex.yml
File diff suppressed because it is too large
Load Diff
|
@ -35,3 +35,8 @@ model AuthToken {
|
|||
id Int @id @default(autoincrement())
|
||||
token String @unique
|
||||
}
|
||||
|
||||
model LocationObjectStorage {
|
||||
id String @id
|
||||
objects Json @default("[]")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import { Logger } from "@util/Logger";
|
||||
import { argv } from "bun";
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||
import YAML from "yaml";
|
||||
|
||||
const logger = new Logger("Pokemon Converter");
|
||||
|
||||
const inFile = argv[2];
|
||||
const outFile = argv[3];
|
||||
|
||||
if (typeof inFile !== "string" || typeof outFile !== "string") {
|
||||
logger.error(`Usage: <infile> <outfile>`);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (!existsSync(inFile)) {
|
||||
logger.error("Input file not found");
|
||||
process.exit();
|
||||
}
|
||||
|
||||
logger.info("Reading YAML...");
|
||||
|
||||
let data: any;
|
||||
|
||||
try {
|
||||
const jdata = readFileSync(inFile).toString();
|
||||
data = YAML.parse(jdata);
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
// data[i].name = data[i].name.english;
|
||||
data[i].pokeID = data[i].id;
|
||||
data[i].id = data[i].name.toLowerCase();
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
logger.error("YAML read error");
|
||||
process.exit();
|
||||
}
|
||||
|
||||
logger.info("Writing file...");
|
||||
writeFileSync(outFile, YAML.stringify(data));
|
||||
logger.info("Done.");
|
|
@ -0,0 +1,40 @@
|
|||
import Command from "@server/commands/Command";
|
||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
||||
import { locations } from "@server/fish/locations";
|
||||
import { nearby } from "./nearby";
|
||||
|
||||
export const go = new Command(
|
||||
"go",
|
||||
["go"],
|
||||
"Go to another location",
|
||||
"go <location>",
|
||||
"command.fishing.go",
|
||||
async ({ id, command, args, prefix, part, user }) => {
|
||||
if (!args[0])
|
||||
return `Maybe you wanted to see what's ${prefix}${nearby.aliases[0]}?`;
|
||||
|
||||
const inventory = await getInventory(user.inventoryId);
|
||||
if (!inventory) return;
|
||||
|
||||
let loc = locations.find(loc => loc.id == inventory.location);
|
||||
if (!loc) loc = locations[0];
|
||||
|
||||
let nextLoc: ILocation | undefined;
|
||||
|
||||
for (const nearID of loc.nearby) {
|
||||
let near = locations.find(loc => loc.id == nearID);
|
||||
if (!near) continue;
|
||||
|
||||
if (near.name.toLowerCase().includes(args[0].toLowerCase()))
|
||||
nextLoc = near;
|
||||
}
|
||||
|
||||
if (!nextLoc)
|
||||
return `The place "${args[0]}" is not ${prefix}${nearby.aliases[0]}.`;
|
||||
|
||||
inventory.location = nextLoc.id;
|
||||
updateInventory(inventory);
|
||||
|
||||
return `You went to ${nextLoc.name}.`;
|
||||
}
|
||||
);
|
|
@ -0,0 +1,31 @@
|
|||
import Command from "@server/commands/Command";
|
||||
import { logger } from "@server/commands/handler";
|
||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
||||
import { locations } from "@server/fish/locations";
|
||||
|
||||
export const look = new Command(
|
||||
"look",
|
||||
["look", "see"],
|
||||
"Look at your surroundings",
|
||||
"look",
|
||||
"command.fishing.look",
|
||||
async ({ id, command, args, prefix, part, user }) => {
|
||||
const inventory = await getInventory(user.inventoryId);
|
||||
if (!inventory) return;
|
||||
|
||||
let loc = locations.find(loc => loc.id == inventory.location);
|
||||
if (!loc) loc = locations[0];
|
||||
|
||||
const objList: string[] = [];
|
||||
|
||||
for (const obj of loc.objects) {
|
||||
objList.push(
|
||||
`${obj.emoji || ""}${obj.name}${
|
||||
obj.count ? (obj.count > 1 ? ` (x${obj.count})` : "") : ""
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
return `There's ${objList.join(", ")}, about.`;
|
||||
}
|
||||
);
|
|
@ -0,0 +1,31 @@
|
|||
import Command from "@server/commands/Command";
|
||||
import { logger } from "@server/commands/handler";
|
||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
||||
import { locations } from "@server/fish/locations";
|
||||
|
||||
export const nearby = new Command(
|
||||
"nearby",
|
||||
["nearby"],
|
||||
"Look at nearby locations",
|
||||
"nearby",
|
||||
"command.fishing.nearby",
|
||||
async ({ id, command, args, prefix, part, user }) => {
|
||||
const inventory = await getInventory(user.inventoryId);
|
||||
if (!inventory) return;
|
||||
|
||||
let loc = locations.find(loc => loc.id == inventory.location);
|
||||
if (!loc) loc = locations[0];
|
||||
|
||||
logger.debug(loc.nearby);
|
||||
|
||||
const nearbyList: string[] = [];
|
||||
|
||||
for (const nearID of loc.nearby) {
|
||||
const near = locations.find(loc => loc.id == nearID);
|
||||
if (!near) continue;
|
||||
nearbyList.push(near.name);
|
||||
}
|
||||
|
||||
return `Nearby places: ${nearbyList.join(", ") || "(none)"}`;
|
||||
}
|
||||
);
|
|
@ -0,0 +1,62 @@
|
|||
import Command from "@server/commands/Command";
|
||||
import { logger } from "@server/commands/handler";
|
||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
||||
import { locations } from "@server/fish/locations";
|
||||
import { go } from "./go";
|
||||
import { addItem } from "@server/items";
|
||||
|
||||
export const take = new Command(
|
||||
"take",
|
||||
["take"],
|
||||
"Take something from your surroundings",
|
||||
"take <something>",
|
||||
"command.fishing.take",
|
||||
async ({ id, command, args, prefix, part, user }) => {
|
||||
let taking = args[0];
|
||||
|
||||
if (!taking) {
|
||||
return `Are you going to ${prefix}take <something>?`;
|
||||
}
|
||||
|
||||
const inventory = await getInventory(user.inventoryId);
|
||||
if (!inventory) return;
|
||||
|
||||
let loc = locations.find(loc => loc.id == inventory.location);
|
||||
if (!loc)
|
||||
return `Something is broken, just ${prefix}${go.aliases[0]} somewhere else first`;
|
||||
|
||||
let foundObject: IObject | undefined;
|
||||
|
||||
const items = inventory.items as unknown as IItem[];
|
||||
const fish = inventory.fishSack as unknown as IFish[];
|
||||
const pokemon = inventory.pokemon as unknown as IPokemon[];
|
||||
|
||||
for (const obj of loc.objects) {
|
||||
if (obj.name.toLowerCase().includes(taking.toLowerCase()))
|
||||
foundObject = obj;
|
||||
}
|
||||
|
||||
if (!foundObject) return `There is no "${taking}" here.`;
|
||||
|
||||
switch (foundObject.objtype) {
|
||||
case "item":
|
||||
addItem(items, foundObject);
|
||||
break;
|
||||
case "fish":
|
||||
addItem(fish, foundObject);
|
||||
break;
|
||||
case "pokemon":
|
||||
addItem(pokemon as unknown as IObject[], foundObject);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
(inventory as any).items = items;
|
||||
(inventory as any).fishSack = fish;
|
||||
(inventory as any).pokemon = pokemon;
|
||||
|
||||
await updateInventory(inventory);
|
||||
return `You picked up the ${foundObject.name}.`;
|
||||
}
|
||||
);
|
|
@ -0,0 +1,25 @@
|
|||
import Command from "@server/commands/Command";
|
||||
import { getInventory } from "@server/data/inventory";
|
||||
|
||||
export const inventory = new Command(
|
||||
"inventory",
|
||||
["inventory", "inv"],
|
||||
"Look at your inventory",
|
||||
"data",
|
||||
"command.util.inventory",
|
||||
async ({ id, command, args, prefix, part, user }) => {
|
||||
const inventory = await getInventory(user.inventoryId);
|
||||
if (!inventory) return;
|
||||
|
||||
const items = inventory.items as unknown as IItem[];
|
||||
|
||||
return `Inventory: ${items
|
||||
.map(
|
||||
item =>
|
||||
`${item.emoji || ""}${item.name}${
|
||||
item.count ? ` (x${item.count})` : ""
|
||||
}`
|
||||
)
|
||||
.join(", ")}`;
|
||||
}
|
||||
);
|
|
@ -4,6 +4,11 @@ import { help } from "./general/help";
|
|||
import { setcolor } from "./util/setcolor";
|
||||
import { data } from "./util/data";
|
||||
import { location } from "./fishing/location";
|
||||
import { go } from "./fishing/go";
|
||||
import { nearby } from "./fishing/nearby";
|
||||
import { look } from "./fishing/look";
|
||||
import { take } from "./fishing/take";
|
||||
import { inventory } from "./general/inventory";
|
||||
|
||||
interface ICommandGroup {
|
||||
id: string;
|
||||
|
@ -16,7 +21,7 @@ export const commandGroups: ICommandGroup[] = [];
|
|||
const general: ICommandGroup = {
|
||||
id: "general",
|
||||
displayName: "General",
|
||||
commands: [help]
|
||||
commands: [help, inventory]
|
||||
};
|
||||
|
||||
commandGroups.push(general);
|
||||
|
@ -24,7 +29,7 @@ commandGroups.push(general);
|
|||
const fishing: ICommandGroup = {
|
||||
id: "fishing",
|
||||
displayName: "Fishing",
|
||||
commands: [fish, location]
|
||||
commands: [fish, location, go, nearby, look, take]
|
||||
};
|
||||
|
||||
commandGroups.push(fishing);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import prisma from "./prisma";
|
||||
|
||||
export async function createObjectStorage(id: string, objects: TObjectArray) {
|
||||
return prisma.locationObjectStorage.create({
|
||||
data: { id, objects }
|
||||
});
|
||||
}
|
||||
|
||||
export async function getObjectStorage(id: string) {
|
||||
return prisma.locationObjectStorage.findUnique({
|
||||
where: { id }
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateObjectStorage(id: string, objects: TObjectArray) {
|
||||
return prisma.locationObjectStorage.update({
|
||||
where: { id },
|
||||
data: { objects }
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteObjectStorage(id: string) {
|
||||
return prisma.locationObjectStorage.delete({
|
||||
where: { id }
|
||||
});
|
||||
}
|
|
@ -3,6 +3,10 @@ import { loadConfig } from "@util/config";
|
|||
|
||||
export const fish = loadConfig<IFish[]>("config/fish.yml", []);
|
||||
|
||||
for (let i = 0; i < fish.length; i++) {
|
||||
fish[i].objtype = "fish";
|
||||
}
|
||||
|
||||
const logger = new Logger("Fishies");
|
||||
|
||||
export function randomFish(location: string, r: number = Math.random()) {
|
||||
|
|
|
@ -1,31 +1,38 @@
|
|||
import {
|
||||
createObjectStorage,
|
||||
getObjectStorage,
|
||||
updateObjectStorage
|
||||
} from "@server/data/location";
|
||||
import { Logger } from "@util/Logger";
|
||||
import { loadConfig } from "@util/config";
|
||||
import { addTickEvent, removeTickEvent } from "@util/tick";
|
||||
|
||||
export const locations = loadConfig<ILocation[]>("config/locations.yml", [
|
||||
{
|
||||
id: "pond",
|
||||
name: "Pond",
|
||||
nearby: [],
|
||||
nearby: ["lake", "river", "sea"],
|
||||
hasSand: true,
|
||||
objects: []
|
||||
},
|
||||
{
|
||||
id: "lake",
|
||||
name: "Lake",
|
||||
nearby: [],
|
||||
nearby: ["pond", "river", "sea"],
|
||||
hasSand: false,
|
||||
objects: []
|
||||
},
|
||||
{
|
||||
id: "river",
|
||||
name: "River",
|
||||
nearby: [],
|
||||
nearby: ["pond", "lake", "sea"],
|
||||
hasSand: false,
|
||||
objects: []
|
||||
},
|
||||
{
|
||||
id: "sea",
|
||||
name: "Sea",
|
||||
nearby: [],
|
||||
nearby: ["pond", "lake", "river"],
|
||||
hasSand: true,
|
||||
objects: []
|
||||
}
|
||||
|
@ -33,24 +40,60 @@ export const locations = loadConfig<ILocation[]>("config/locations.yml", [
|
|||
|
||||
const sand: IItem = {
|
||||
id: "sand",
|
||||
objtype: "item",
|
||||
name: "Sand"
|
||||
};
|
||||
|
||||
let sandInterval: Timer;
|
||||
let objectInterval: Timer;
|
||||
const logger = new Logger("Places");
|
||||
|
||||
export function startSandInterval() {
|
||||
sandInterval = setInterval(() => {
|
||||
for (const loc of locations) {
|
||||
if (!loc.hasSand) continue;
|
||||
export function populateSand() {
|
||||
for (const loc of locations) {
|
||||
if (!loc.hasSand) continue;
|
||||
|
||||
let existing = loc.objects.find(obj => obj.id == "sand");
|
||||
if (typeof existing !== "undefined") continue;
|
||||
let existing = loc.objects.find(obj => obj.id == "sand");
|
||||
if (typeof existing !== "undefined") continue;
|
||||
|
||||
loc.objects.push(sand);
|
||||
loc.objects.push(sand);
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadObjects() {
|
||||
for (const loc of locations) {
|
||||
let storage = await getObjectStorage(loc.id);
|
||||
if (!storage) continue;
|
||||
if (!storage.objects) continue;
|
||||
|
||||
if (storage.objects == null) continue;
|
||||
|
||||
if (typeof storage.objects == "string") {
|
||||
storage.objects = JSON.parse(storage.objects);
|
||||
}
|
||||
}, 6000);
|
||||
|
||||
loc.objects = storage.objects as unknown as IObject[];
|
||||
}
|
||||
}
|
||||
|
||||
export function stopSandInterface() {
|
||||
clearInterval(sandInterval);
|
||||
export async function saveObjects() {
|
||||
for (const loc of locations) {
|
||||
let storage = await getObjectStorage(loc.id);
|
||||
|
||||
if (!storage) {
|
||||
storage = await createObjectStorage(loc.id, loc.objects);
|
||||
} else {
|
||||
await updateObjectStorage(loc.id, loc.objects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function startObjectTimers() {
|
||||
loadObjects();
|
||||
addTickEvent(populateSand);
|
||||
addTickEvent(saveObjects);
|
||||
}
|
||||
|
||||
export function stopObjectTimers() {
|
||||
saveObjects();
|
||||
removeTickEvent(populateSand);
|
||||
removeTickEvent(saveObjects);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import "./api/server";
|
||||
import "./cli/readline";
|
||||
import { startSandInterval } from "./fish/locations";
|
||||
import { startObjectTimers } from "./fish/locations";
|
||||
|
||||
startSandInterval();
|
||||
startObjectTimers();
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
export function addItem(arr: IObject[], item: IObject) {
|
||||
let found = false;
|
||||
let i = 0;
|
||||
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
if (item.id == arr[i].id) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
arr.push(item);
|
||||
return;
|
||||
}
|
||||
|
||||
let inc = 1;
|
||||
if (item.count) inc = item.count;
|
||||
|
||||
if (!arr[i].count) {
|
||||
arr[i].count = inc + 1;
|
||||
} else {
|
||||
(arr[i].count as number) += inc;
|
||||
}
|
||||
}
|
|
@ -21,13 +21,21 @@ interface CountComponent {
|
|||
count: number;
|
||||
}
|
||||
|
||||
interface IItem {
|
||||
interface IObject extends JsonValue {
|
||||
id: string;
|
||||
objtype: string;
|
||||
name: string;
|
||||
emoji?: string;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
interface IFish extends JsonValue {
|
||||
interface IItem extends IObject {
|
||||
objtype: "item";
|
||||
}
|
||||
|
||||
interface IFish extends IObject {
|
||||
id: string;
|
||||
objtype: "fish";
|
||||
name: string;
|
||||
size: number;
|
||||
rarity: number;
|
||||
|
@ -41,14 +49,11 @@ interface IFish extends JsonValue {
|
|||
emoji?: string;
|
||||
}
|
||||
|
||||
interface IPokemon extends JsonValue {
|
||||
interface IPokemon extends IObject {
|
||||
id: number;
|
||||
name: {
|
||||
english: string;
|
||||
japanese: string;
|
||||
chinese: string;
|
||||
french: string;
|
||||
};
|
||||
objtype: "pokemon";
|
||||
emoji?: string;
|
||||
name: string;
|
||||
type: string[];
|
||||
base: {
|
||||
HP: number;
|
||||
|
@ -60,6 +65,7 @@ interface IPokemon extends JsonValue {
|
|||
};
|
||||
}
|
||||
|
||||
type TObjectArray = JsonArray & IObject[];
|
||||
type TInventoryItems = JsonArray & IItem[];
|
||||
type TFishSack = JsonArray & IFish[];
|
||||
type TPokemonSack = JsonArray & IPokemon[];
|
||||
|
@ -89,6 +95,6 @@ interface ILocation {
|
|||
id: string;
|
||||
name: string;
|
||||
nearby: string[];
|
||||
objects: (IItem | IFish | IPokemon)[];
|
||||
objects: IObject[];
|
||||
hasSand: boolean;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue