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
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';