From 7907dff1617ad5f5250ea6be8985fddaec97a0e1 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 2 Jun 2023 14:44:04 -0400 Subject: [PATCH] you can now flee a battle --- src/server/api.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/server/api.ts b/src/server/api.ts index d990e1f..3df5fac 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -277,6 +277,25 @@ io.on('connection', async socket => { socket.on('fight', async (data: {action: 'attack' | 'cast' | 'flee', target: 'head' | 'body' | 'arms' | 'legs'}) => { const monster = await loadMonsterFromFight(player.id); + const roundData: FightRound = { + monster, + player, + winner: 'in-progress', + roundDetails: [], + rewards: { + exp: 0, + gold: 0, + levelIncrease: false + } + }; + if(data.action === 'flee') { + roundData.roundDetails.push(`You managed to escape from the ${monster.name}!`) + roundData.winner = 'monster'; + await clearFight(player.id); + + socket.emit('fight-over', {roundData, monsters: []}); + return; + } const equippedItems = await getEquippedItems(player.id); // we only use this if the player successfully defeated the monster @@ -325,18 +344,6 @@ io.on('connection', async socket => { boost.damage += item.boost_damage; }); - const roundData: FightRound = { - monster, - player, - winner: 'in-progress', - roundDetails: [], - rewards: { - exp: 0, - gold: 0, - levelIncrease: false - } - }; - const primaryStat = data.action === 'attack' ? player.strength : player.constitution; const boostStat = data.action === 'attack' ? boost.strength : boost.constitution; const attackType = data.action === 'attack' ? 'physical' : 'magical'; -- 2.25.1