From c8bd4d64fc2d345595f37e2b42b7d3dcbfa3d249 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 25 Aug 2023 11:04:25 -0400 Subject: [PATCH] feat: expoential exp drop-off/gain When you are over 3 levels of the monster you are fighting you start gaining less exp. When you are under 3 levels of the monster you are fighting, you start gaining more exp. --- src/server/fight.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/server/fight.ts b/src/server/fight.ts index 9b377e6..855589a 100644 --- a/src/server/fight.ts +++ b/src/server/fight.ts @@ -23,6 +23,19 @@ export async function blockPlayerInFight(req: AuthRequest, res: Response, next: res.send(Alert.ErrorAlert(`You are currently in a fight with a ${fight.name}`)); } +function exponentialExp(exp: number, monsterLevel: number, playerLevel: number): number { + let finalExp = exp; + + if((monsterLevel+3) < playerLevel) { + finalExp = Math.floor(exp * Math.pow(Math.E, ((monsterLevel + 3) - playerLevel)/5)); + } + else if(monsterLevel > (playerLevel + 3)) { + finalExp = Math.floor(exp * Math.pow(Math.E, ((playerLevel + 3) - monsterLevel)/5)); + } + + return Math.floor(finalExp); +} + export async function fightRound(player: Player, monster: MonsterWithFaction, data: {action: 'attack' | 'cast' | 'flee', target: 'head' | 'body' | 'arms' | 'legs'}) { const playerSkills = await getPlayerSkillsAsObject(player.id); const roundData: FightRound = { @@ -196,11 +209,13 @@ export async function fightRound(player: Player, monster: MonsterWithFaction, d roundData.monster.hp = 0; roundData.winner = 'player'; - roundData.rewards.exp = monster.exp; + const expGained = exponentialExp(monster.exp, monster.level, player.level); + + roundData.rewards.exp = expGained; roundData.rewards.gold = monster.gold; player.gold += monster.gold; - player.exp += monster.exp; + player.exp += expGained; if(player.exp >= expToLevel(player.level + 1)) { player.exp -= expToLevel(player.level + 1) -- 2.25.1