Merge pull request #2106 from Sneed69/PartyBattlerShouldAvoidHazards

PartyBattlerShouldAvoidHazards rewrite
This commit is contained in:
Eduardo Quezada D'Ottone 2022-12-30 17:55:53 -03:00 committed by GitHub
commit 0e1836d42b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 9 deletions

View File

@ -142,6 +142,7 @@ u16 CalcTypeEffectivenessMultiplier(u16 move, u8 moveType, u8 battlerAtk, u8 bat
u16 CalcPartyMonTypeEffectivenessMultiplier(u16 move, u16 speciesDef, u16 abilityDef);
u16 GetTypeModifier(u8 atkType, u8 defType);
s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId);
s32 GetStealthHazardDamageByTypesAndHP(u8 hazardType, u8 type1, u8 type2, u32 maxHp);
u16 GetMegaEvolutionSpecies(u16 preEvoSpecies, u16 heldItemId);
u16 GetPrimalReversionSpecies(u16 preEvoSpecies, u16 heldItemId);
u16 GetWishMegaEvolutionSpecies(u16 preEvoSpecies, u16 moveId1, u16 moveId2, u16 moveId3, u16 moveId4);

View File

@ -2429,19 +2429,41 @@ static bool32 PartyBattlerShouldAvoidHazards(u8 currBattler, u8 switchBattler)
{
struct Pokemon *mon = GetPartyBattlerPartyData(currBattler, switchBattler);
u16 ability = GetMonAbility(mon); // we know our own party data
u16 holdEffect = GetBattlerHoldEffect(GetMonData(mon, MON_DATA_HELD_ITEM), TRUE);
u16 holdEffect;
u16 species = GetMonData(mon, MON_DATA_SPECIES);
u32 flags = gSideStatuses[GetBattlerSide(currBattler)] & (SIDE_STATUS_SPIKES | SIDE_STATUS_STEALTH_ROCK | SIDE_STATUS_STICKY_WEB | SIDE_STATUS_TOXIC_SPIKES);
s32 hazardDamage = 0;
u8 type1 = gBaseStats[species].type1;
u8 type2 = gBaseStats[species].type2;
u32 maxHp = GetMonData(mon, MON_DATA_MAX_HP);
if (flags == 0)
return FALSE;
if (ability == ABILITY_MAGIC_GUARD || ability == ABILITY_LEVITATE
|| holdEffect == HOLD_EFFECT_HEAVY_DUTY_BOOTS)
if (ability == ABILITY_MAGIC_GUARD)
return FALSE;
if (gFieldStatuses & STATUS_FIELD_MAGIC_ROOM || ability == ABILITY_KLUTZ)
holdEffect = HOLD_EFFECT_NONE;
else
holdEffect = gItems[GetMonData(mon, MON_DATA_HELD_ITEM)].holdEffect;
if (holdEffect == HOLD_EFFECT_HEAVY_DUTY_BOOTS)
return FALSE;
if (flags & (SIDE_STATUS_SPIKES | SIDE_STATUS_STEALTH_ROCK) && GetMonData(mon, MON_DATA_HP) < (GetMonData(mon, MON_DATA_MAX_HP) / 8))
return TRUE;
if (flags & SIDE_STATUS_STEALTH_ROCK)
hazardDamage += GetStealthHazardDamageByTypesAndHP(gBattleMoves[MOVE_STEALTH_ROCK].type, type1, type2, maxHp);
if (flags & SIDE_STATUS_SPIKES && ((type1 != TYPE_FLYING && type2 != TYPE_FLYING
&& ability != ABILITY_LEVITATE && holdEffect != HOLD_EFFECT_AIR_BALLOON)
|| holdEffect == HOLD_EFFECT_IRON_BALL || gFieldStatuses & STATUS_FIELD_GRAVITY))
{
u8 spikesDmg = maxHp / ((5 - gSideTimers[GetBattlerSide(currBattler)].spikesAmount) * 2);
if (spikesDmg == 0)
spikesDmg = 1;
hazardDamage += spikesDmg;
}
if (hazardDamage >= GetMonData(mon, MON_DATA_HP))
return TRUE;
return FALSE;
}

View File

@ -9602,11 +9602,8 @@ u16 GetTypeModifier(u8 atkType, u8 defType)
return sTypeEffectivenessTable[atkType][defType];
}
s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId)
s32 GetStealthHazardDamageByTypesAndHP(u8 hazardType, u8 type1, u8 type2, u32 maxHp)
{
u8 type1 = gBattleMons[battlerId].type1;
u8 type2 = gBattleMons[battlerId].type2;
u32 maxHp = gBattleMons[battlerId].maxHP;
s32 dmg = 0;
u16 modifier = UQ_4_12(1.0);
@ -9649,6 +9646,15 @@ s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId)
return dmg;
}
s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId)
{
u8 type1 = gBattleMons[battlerId].type1;
u8 type2 = gBattleMons[battlerId].type2;
u32 maxHp = gBattleMons[battlerId].maxHP;
return GetStealthHazardDamageByTypesAndHP(hazardType, type1, type2, maxHp);
}
bool32 IsPartnerMonFromSameTrainer(u8 battlerId)
{
if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT && gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS)