Add travel

This commit is contained in:
Aslan 2026-01-21 15:42:18 -05:00
parent c9b4f62a59
commit eea6031423
4 changed files with 134 additions and 28 deletions

View file

@ -1,9 +1,10 @@
import { getUserNameById } from "../../helpers.js";
import { state } from "../../store/store.js";
import type { IPlayer } from "./structures/entities.js";
import type { IEntity, 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";
import type { ILevel } from "./types.js";
const createPlayer = (name: string): IPlayer => ({
name: name,
@ -49,4 +50,27 @@ const getRace = (id: Race): IRace => {
return race ? race : raceHuman;
};
export { createPlayer, getPlayerById, getPlayer, getRace };
const getLevel = (experience: number): ILevel => {
let tmpExperience = experience;
let experienceToNextLevel = 50;
let level = 0;
while (tmpExperience >= experienceToNextLevel) {
level++;
tmpExperience -= experienceToNextLevel;
experienceToNextLevel = experienceToNextLevel *= 1.25;
}
return {
level: level,
totalExperience: Math.floor(experience),
experienceInLevel: Math.floor(tmpExperience),
experienceToNextLevel: Math.floor(experienceToNextLevel),
};
};
const getSpeed = (entity: IEntity) => {
return 1 + Math.sqrt(entity.agility + entity.endurance) / 3;
};
export { createPlayer, getPlayerById, getPlayer, getRace, getLevel, getSpeed };