This commit is contained in:
Aslan 2026-01-20 19:54:45 -05:00
parent d36e98ad0b
commit c071b286af
23 changed files with 713 additions and 11 deletions

View file

@ -0,0 +1,52 @@
import { getUserNameById } from "../../helpers.js";
import { state } from "../../store/store.js";
import type { IPlayer } from "./structures/entities.js";
import { itemShortsword } from "./structures/items.js";
import { Location } from "./structures/locations.js";
import { Race, raceHuman, races, type IRace } from "./structures/races.js";
const createPlayer = (name: string): IPlayer => ({
name: name,
description: "",
race: Race.HUMAN,
location: Location.FARLANDS,
inventory: {
items: [itemShortsword],
},
experience: 0,
health: 100,
vitality: 0,
strength: 0,
endurance: 0,
agility: 0,
dexterity: 0,
intelligence: 0,
wisdom: 0,
stealth: 0,
charisma: 0,
lockpicking: 0,
});
const getPlayerById = (userId: string): IPlayer => {
return getPlayer(getUserNameById(userId));
};
const getPlayer = (name: string): IPlayer => {
const player = state.game.players.find((player) => player.name === name);
if (player) {
return player;
}
const newPlayer = createPlayer(name);
state.game.players.push(newPlayer);
return newPlayer;
};
const getRace = (id: Race): IRace => {
const race = races.find((race) => race.id === id);
return race ? race : raceHuman;
};
export { createPlayer, getPlayerById, getPlayer, getRace };