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) => { const getSpeed = (entity: IEntity) => {
return 60 + 3 + Math.sqrt(entity.agility + entity.endurance) / 2; return 3 + Math.sqrt(entity.agility + entity.endurance) / 2;
}; };
export { export {

View file

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