diff --git a/src/services/game/entity.ts b/src/services/game/entity.ts index d435366..a4c9f41 100644 --- a/src/services/game/entity.ts +++ b/src/services/game/entity.ts @@ -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 { diff --git a/src/services/game/game.ts b/src/services/game/game.ts index 851b351..19db02c 100644 --- a/src/services/game/game.ts +++ b/src/services/game/game.ts @@ -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( - defender.health <= -getMaxHealth(defender) - ? attackerAttackInfo.messagesOverpower - : attackerAttackInfo.messagesDead, - ); + 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;