From: xangelo Date: Fri, 25 Aug 2023 15:04:25 +0000 (-0400) Subject: feat: expoential exp drop-off/gain X-Git-Tag: v0.2.15~1 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=c8bd4d64fc2d345595f37e2b42b7d3dcbfa3d249;p=risinglegends.git 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. --- 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)