Add fights

This commit is contained in:
Aslan 2026-01-23 11:00:11 -05:00
parent 9a24161eea
commit c02062eb47
2 changed files with 31 additions and 9 deletions

View file

@ -188,7 +188,7 @@ const getHealthPercentage = (entity: IPlayer | INPC): number => {
};
const getSpeed = (entity: IEntity) => {
return 60 + 3 + Math.sqrt(entity.agility + entity.endurance) / 2;
return 3 + Math.sqrt(entity.agility + entity.endurance) / 2;
};
export {

View file

@ -49,12 +49,23 @@ const fightEntity = async (
let winner: IPlayer | TFullNPC | undefined = undefined;
let loser: IPlayer | TFullNPC | undefined = undefined;
let round = 0;
while (true) {
await sleep(5000);
await sleep(3000);
round++;
client.sendTextMessage(roomId, `Round ${round}`);
client.sendTextMessage(
roomId,
`${attacker.name}: ${attacker.health}/${getMaxHealth(attacker)}HP\n${defender.name}: ${defender.health}/${getMaxHealth(defender)}HP`,
);
await sleep(3000);
const attackerWon = fightRound(
client,
roomId,
attacker,
attackerAttacks,
attackerDamage,
defender,
@ -70,6 +81,7 @@ const fightEntity = async (
const defenderWon = fightRound(
client,
roomId,
attacker,
defenderAttacks,
defenderDamage,
attacker,
@ -85,7 +97,7 @@ const fightEntity = async (
client.sendTextMessage(
roomId,
`${attacker.name} has won the fight against ${defender.name}!`,
`${winner.name} has won the fight against ${loser.name}!`,
);
if (isPlayer(loser)) {
@ -99,6 +111,7 @@ const fightEntity = async (
const fightRound = (
client: MatrixClient,
roomId: string,
attacker: IPlayer | TFullNPC,
attackerAttacks: Attack[],
attackerDamage: number,
defender: IPlayer | TFullNPC,
@ -121,17 +134,26 @@ const fightRound = (
defender.health -= attackerAttackDamage;
if (defender.health <= 0) {
const msg = getRandomAttackMessage(
let msg =
getRandomAttackMessage(
defender.health <= -getMaxHealth(defender)
? attackerAttackInfo.messagesOverpower
: attackerAttackInfo.messagesDead,
);
) + `; Dealing ${attackerAttackDamage} damage`;
msg = msg.replaceAll("ATTACKER", attacker.name);
msg = msg.replaceAll("DEFENDER", defender.name);
client.sendTextMessage(roomId, msg);
return true;
}
const msg = getRandomAttackMessage(attackerAttackInfo.messages);
let msg =
getRandomAttackMessage(attackerAttackInfo.messages) +
`; Dealing ${attackerAttackDamage} damage`;
msg = msg.replaceAll("ATTACKER", attacker.name);
msg = msg.replaceAll("DEFENDER", defender.name);
client.sendTextMessage(roomId, msg);
return false;