From: xangelo Date: Fri, 2 Jun 2023 18:44:04 +0000 (-0400) Subject: you can now flee a battle X-Git-Tag: v0.0.1~73 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=7907dff1617ad5f5250ea6be8985fddaec97a0e1;p=risinglegends.git you can now flee a battle --- 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';