From 293b5c063c1d7723e1c34e6d689d435203f04964 Mon Sep 17 00:00:00 2001 From: AJ Fontaine Date: Fri, 29 Nov 2024 23:35:53 -0500 Subject: [PATCH] Remove candy friendship loss from fainting --- src/field/pokemon.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 961cb943731..c3f782b2ee4 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -4272,26 +4272,27 @@ export class PlayerPokemon extends Pokemon { } addFriendship(friendship: integer): void { - const starterSpeciesId = this.species.getRootSpeciesId(); - const fusionStarterSpeciesId = this.isFusion() && this.fusionSpecies ? this.fusionSpecies.getRootSpeciesId() : 0; - const starterData = [ - this.scene.gameData.starterData[starterSpeciesId], - fusionStarterSpeciesId ? this.scene.gameData.starterData[fusionStarterSpeciesId] : null - ].filter(d => !!d); - const amount = new Utils.IntegerHolder(friendship); - let candyFriendshipMultiplier = CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER; - if (this.scene.eventManager.isEventActive()) { - candyFriendshipMultiplier *= this.scene.eventManager.getFriendshipMultiplier(); - } - const starterAmount = new Utils.IntegerHolder(Math.floor(friendship * (this.scene.gameMode.isClassic && friendship > 0 ? candyFriendshipMultiplier : 1) / (fusionStarterSpeciesId ? 2 : 1))); - if (amount.value > 0) { + if (friendship > 0) { + const starterSpeciesId = this.species.getRootSpeciesId(); + const fusionStarterSpeciesId = this.isFusion() && this.fusionSpecies ? this.fusionSpecies.getRootSpeciesId() : 0; + const starterData = [ + this.scene.gameData.starterData[starterSpeciesId], + fusionStarterSpeciesId ? this.scene.gameData.starterData[fusionStarterSpeciesId] : null + ].filter(d => !!d); + const amount = new Utils.IntegerHolder(friendship); this.scene.applyModifier(PokemonFriendshipBoosterModifier, true, this, amount); - this.scene.applyModifier(PokemonFriendshipBoosterModifier, true, this, starterAmount); + let candyFriendshipMultiplier = CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER; + if (this.scene.eventManager.isEventActive()) { + candyFriendshipMultiplier *= this.scene.eventManager.getFriendshipMultiplier(); + } + const starterAmount = new Utils.IntegerHolder(Math.floor(friendship * (this.scene.gameMode.isClassic && friendship > 0 ? candyFriendshipMultiplier : 1) / (fusionStarterSpeciesId ? 2 : 1))); + //Add friendship to this PlayerPokemon this.friendship = Math.min(this.friendship + amount.value, 255); if (this.friendship === 255) { this.scene.validateAchv(achvs.MAX_FRIENDSHIP); } + //Add to candy progress for this mon's starter species and its fused species (if it has one) starterData.forEach((sd: StarterDataEntry, i: integer) => { const speciesId = !i ? starterSpeciesId : fusionStarterSpeciesId as Species; sd.friendship = (sd.friendship || 0) + starterAmount.value; @@ -4301,10 +4302,8 @@ export class PlayerPokemon extends Pokemon { } }); } else { - this.friendship = Math.max(this.friendship + amount.value, 0); - for (const sd of starterData) { - sd.friendship = Math.max((sd.friendship || 0) + starterAmount.value, 0); - } + //Lose friendship upon fainting + this.friendship = Math.max(this.friendship + friendship, 0); } } /**