Add fights
This commit is contained in:
parent
a14be66890
commit
b79e970b07
5 changed files with 323 additions and 0 deletions
|
|
@ -1,8 +1,12 @@
|
|||
import { getUserNameById } from "../../helpers.js";
|
||||
import { state } from "../../store/store.js";
|
||||
import {
|
||||
Attack,
|
||||
attackPunch,
|
||||
attacks,
|
||||
npcBecky,
|
||||
npcs,
|
||||
type IAttack,
|
||||
type IEntity,
|
||||
type INPC,
|
||||
type INPCData,
|
||||
|
|
@ -16,6 +20,7 @@ import { Race, raceHuman, races, type IRace } from "./structures/races.js";
|
|||
import type { ILevel } from "./types.js";
|
||||
|
||||
const createPlayer = (name: string): IPlayer => ({
|
||||
isPlayer: true,
|
||||
name: name,
|
||||
description: "",
|
||||
race: Race.HUMAN,
|
||||
|
|
@ -35,6 +40,7 @@ const createPlayer = (name: string): IPlayer => ({
|
|||
stealth: 0,
|
||||
charisma: 0,
|
||||
lockpicking: 0,
|
||||
attacks: [Attack.PUNCH, Attack.KICK],
|
||||
});
|
||||
|
||||
const createNpcData = (npc: INPC): INPCData => ({
|
||||
|
|
@ -43,6 +49,10 @@ const createNpcData = (npc: INPC): INPCData => ({
|
|||
dead: false,
|
||||
});
|
||||
|
||||
const isPlayer = (entity: IEntity): boolean => {
|
||||
return "isPlayer" in entity;
|
||||
};
|
||||
|
||||
const existsPlayer = (name: string): boolean => {
|
||||
return (
|
||||
state.game.players.find(
|
||||
|
|
@ -62,6 +72,12 @@ const existsEntity = (name: string): boolean => {
|
|||
return existsPlayer(name) || existsNpc(name);
|
||||
};
|
||||
|
||||
const getAttack = (id: Attack): IAttack => {
|
||||
const attack = attacks.find((attack) => attack.id === id);
|
||||
|
||||
return attack ? attack : attackPunch;
|
||||
};
|
||||
|
||||
const getPlayer = (userId: string): IPlayer => {
|
||||
return getPlayerByName(getUserNameById(userId));
|
||||
};
|
||||
|
|
@ -176,9 +192,11 @@ const getSpeed = (entity: IEntity) => {
|
|||
export {
|
||||
createPlayer,
|
||||
createNpcData,
|
||||
isPlayer,
|
||||
existsPlayer,
|
||||
existsNpc,
|
||||
existsEntity,
|
||||
getAttack,
|
||||
getPlayer,
|
||||
getPlayerByName,
|
||||
getEntityByName,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue