clean up code and made more extensible for future use

This commit is contained in:
Benjamin 2024-10-25 01:45:34 -04:00
parent c364348a16
commit 2a325df3c6
5 changed files with 13 additions and 9 deletions

View File

@ -3343,7 +3343,7 @@ export class PostWeatherLapseDamageAbAttr extends PostWeatherLapseAbAttr {
const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name;
scene.queueMessage(i18next.t("abilityTriggers:postWeatherLapseDamage", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }));
pokemon.damageAndUpdate(Utils.toDmgValue(pokemon.getMaxHp() / (16 / this.damageFactor)), HitResult.OTHER);
pokemon.turnData.lastDmgSrc = 0;
pokemon.turnData.lastDmgSrc = WeatherType.HARSH_SUN;
}
return true;

View File

@ -2796,7 +2796,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.battleData.hitCount++;
const attackResult = { move: move.id, result: result as DamageResult, damage: damage, critical: isCritical, sourceId: source.id, sourceBattlerIndex: source.getBattlerIndex() };
this.turnData.attacksReceived.unshift(attackResult);
this.turnData.lastDmgSrc = source.id;
this.turnData.lastDmgSrc = source;
if (source.isPlayer() && !this.isPlayer()) {
this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, new Utils.NumberHolder(damage));
}
@ -5126,7 +5126,7 @@ export class PokemonTurnData {
public statStagesDecreased: boolean = false;
public moveEffectiveness: TypeDamageMultiplier | null = null;
public combiningPledge?: Moves;
public lastDmgSrc: integer;
public lastDmgSrc: Pokemon | WeatherType | StatusEffect;
}
export enum AiType {

View File

@ -96,13 +96,13 @@ export class FaintPhase extends PokemonPhase {
const alivePlayField = this.scene.getField(true);
alivePlayField.forEach(p => applyPostKnockOutAbAttrs(PostKnockOutAbAttr, p, pokemon));
if (pokemon.turnData?.attacksReceived?.length) {
const defeatSource = this.scene.getPokemonById(pokemon.turnData?.lastDmgSrc);
const selfKO = pokemon === defeatSource;
if (defeatSource?.isOnField()) {
const defeatSource = pokemon.turnData.lastDmgSrc;
if (defeatSource instanceof Pokemon && defeatSource?.isOnField()) {
applyPostVictoryAbAttrs(PostVictoryAbAttr, defeatSource);
const pvmove = allMoves[pokemon.turnData.attacksReceived[0].move];
const pvattrs = pvmove.getAttrs(PostVictoryStatStageChangeAttr);
if (pvattrs.length && !selfKO) {
if (pvattrs.length) {
for (const pvattr of pvattrs) {
pvattr.applyPostVictory(defeatSource, defeatSource, pvmove);
}

View File

@ -25,17 +25,19 @@ export class PostTurnStatusEffectPhase extends PokemonPhase {
if (!cancelled.value) {
this.scene.queueMessage(getStatusEffectActivationText(pokemon.status.effect, getPokemonNameWithAffix(pokemon)));
const damage = new Utils.NumberHolder(0);
pokemon.turnData.lastDmgSrc = 0;
switch (pokemon.status.effect) {
case StatusEffect.POISON:
damage.value = Math.max(pokemon.getMaxHp() >> 3, 1);
pokemon.turnData.lastDmgSrc = StatusEffect.POISON;
break;
case StatusEffect.TOXIC:
damage.value = Math.max(Math.floor((pokemon.getMaxHp() / 16) * pokemon.status.toxicTurnCount), 1);
pokemon.turnData.lastDmgSrc = StatusEffect.TOXIC;
break;
case StatusEffect.BURN:
damage.value = Math.max(pokemon.getMaxHp() >> 4, 1);
applyAbAttrs(ReduceBurnDamageAbAttr, pokemon, null, false, damage);
pokemon.turnData.lastDmgSrc = StatusEffect.BURN;
break;
}
if (damage.value) {

View File

@ -54,7 +54,9 @@ export class WeatherEffectPhase extends CommonAnimPhase {
const immune = !pokemon || !!pokemon.getTypes(true, true).filter(t => this.weather?.isTypeDamageImmune(t)).length;
if (!immune) {
inflictDamage(pokemon);
pokemon.turnData.lastDmgSrc = 0;
if (this.weather?.weatherType) {
pokemon.turnData.lastDmgSrc = this.weather.weatherType;
}
}
});
}