2020-10-15 05:49:49 +02:00
|
|
|
#include "common.h"
|
2021-12-12 14:53:19 +01:00
|
|
|
#include "battle/battle.h"
|
|
|
|
#include "script_api/battle.h"
|
|
|
|
#include "effects.h"
|
2020-10-15 05:49:49 +02:00
|
|
|
|
2021-10-03 19:42:38 +02:00
|
|
|
s32 calc_item_check_hit(void) {
|
2021-02-20 15:41:30 +01:00
|
|
|
BattleStatus* battleStatus = &gBattleStatus;
|
2022-02-08 19:33:05 +01:00
|
|
|
ActorState* state = &battleStatus->playerActor->state;
|
2021-10-03 19:42:38 +02:00
|
|
|
s32 actorID = battleStatus->currentTargetID;
|
2020-11-18 06:20:28 +01:00
|
|
|
s8 currentTargetPartS8;
|
|
|
|
u32 currentTargetPart;
|
|
|
|
Actor* actor;
|
|
|
|
ActorPart* actorPart;
|
|
|
|
|
|
|
|
currentTargetPart = currentTargetPartS8 = battleStatus->currentTargetPart;
|
|
|
|
battleStatus->currentTargetID2 = battleStatus->currentTargetID;
|
|
|
|
battleStatus->currentTargetPart2 = currentTargetPartS8;
|
|
|
|
|
|
|
|
actor = get_actor(actorID);
|
|
|
|
if (actor != NULL) {
|
|
|
|
actorPart = get_actor_part(actor, currentTargetPart);
|
|
|
|
ASSERT(actorPart != NULL);
|
|
|
|
|
2021-11-11 05:30:59 +01:00
|
|
|
if (!(actorPart->eventFlags & ACTOR_EVENT_FLAG_ILLUSORY)) {
|
2020-11-18 06:20:28 +01:00
|
|
|
if (actor->transStatus == 0xE) {
|
2021-03-29 09:34:39 +02:00
|
|
|
return HIT_RESULT_MISS;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
2022-06-10 20:06:12 +02:00
|
|
|
if (actor->stoneStatus == STATUS_STONE) {
|
|
|
|
sfx_play_sound_at_position(SOUND_IMMUNE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
2021-03-29 09:34:39 +02:00
|
|
|
return HIT_RESULT_IMMUNE;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
2021-12-12 14:53:19 +01:00
|
|
|
if ((battleStatus->currentAttackElement & DAMAGE_TYPE_JUMP) && (actorPart->eventFlags & ACTOR_EVENT_FLAG_SPIKY_TOP)) {
|
2022-06-10 20:06:12 +02:00
|
|
|
sfx_play_sound_at_position(SOUND_HIT_NORMAL, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
2021-03-29 09:34:39 +02:00
|
|
|
return HIT_RESULT_LANDED_ON_SPIKE;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-03-29 09:34:39 +02:00
|
|
|
return HIT_RESULT_MISS;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-29 09:34:39 +02:00
|
|
|
return HIT_RESULT_HIT;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
2020-10-15 05:49:49 +02:00
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
s32 calc_item_damage_enemy(void) {
|
|
|
|
BattleStatus* battleStatus = &gBattleStatus;
|
2022-02-08 19:33:05 +01:00
|
|
|
Actor* player = battleStatus->playerActor;
|
2021-12-21 23:12:59 +01:00
|
|
|
s32 currentTargetID = battleStatus->currentTargetID;
|
2022-02-08 19:33:05 +01:00
|
|
|
Actor* partner = battleStatus->partnerActor;
|
2021-12-21 23:12:59 +01:00
|
|
|
s32 currentTargetPartID = battleStatus->currentTargetPart;
|
2022-02-08 19:33:05 +01:00
|
|
|
s32 sp18;
|
|
|
|
s32 sp1C = FALSE;
|
|
|
|
s32 actorClass;
|
|
|
|
s32 isFireDamage = FALSE;
|
|
|
|
s32 isElectricDamage = FALSE;
|
|
|
|
s32 isIceDamage = FALSE;
|
|
|
|
Actor* target;
|
|
|
|
ActorPart* targetPart;
|
|
|
|
Evt* script;
|
2021-12-21 23:12:59 +01:00
|
|
|
s32 attackDamage;
|
2022-02-08 19:33:05 +01:00
|
|
|
s32 temp;
|
|
|
|
s32 targetDefense;
|
|
|
|
ActorState* state;
|
2021-12-21 23:12:59 +01:00
|
|
|
s32 dispatchEvent;
|
2022-02-08 19:33:05 +01:00
|
|
|
s32 wasStatusInflicted;
|
|
|
|
s32 ret;
|
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
battleStatus->wasStatusInflicted = FALSE;
|
|
|
|
battleStatus->lastAttackDamage = 0;
|
2022-02-08 19:33:05 +01:00
|
|
|
battleStatus->attackerActorID = player->actorID;
|
2021-12-21 23:12:59 +01:00
|
|
|
battleStatus->currentTargetID2 = battleStatus->currentTargetID;
|
|
|
|
battleStatus->currentTargetPart2 = battleStatus->currentTargetPart;
|
2022-02-08 19:33:05 +01:00
|
|
|
target = get_actor(currentTargetID);
|
|
|
|
wasStatusInflicted = FALSE;
|
|
|
|
|
|
|
|
if (target == NULL) {
|
2021-12-21 23:12:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:33:05 +01:00
|
|
|
targetPart = get_actor_part(target, currentTargetPartID);
|
|
|
|
if (targetPart == NULL) {
|
2021-12-21 23:12:59 +01:00
|
|
|
PANIC();
|
2022-02-08 19:33:05 +01:00
|
|
|
}
|
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
|
2022-02-08 19:33:05 +01:00
|
|
|
target->lastDamageTaken = 0;
|
|
|
|
actorClass = currentTargetID & ACTOR_CLASS_MASK;
|
|
|
|
if (!(gBattleStatus.flags1 & BS_FLAGS1_80000)) {
|
|
|
|
state = &player->state;
|
2021-12-21 23:12:59 +01:00
|
|
|
} else {
|
2022-02-08 19:33:05 +01:00
|
|
|
state = &partner->state;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_FIRE) {
|
2022-06-10 20:06:12 +02:00
|
|
|
fx_ring_blast(0, state->goalPos.x, state->goalPos.y, state->goalPos.z + 5.0f, 1.0f, 24);
|
2021-12-21 23:12:59 +01:00
|
|
|
isFireDamage = TRUE;
|
|
|
|
}
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_ELECTRIC) {
|
2022-02-08 19:33:05 +01:00
|
|
|
func_80251474(target);
|
2021-12-21 23:12:59 +01:00
|
|
|
isElectricDamage = TRUE;
|
|
|
|
}
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_WATER) {
|
2022-06-10 20:06:12 +02:00
|
|
|
fx_water_splash(0, state->goalPos.x, state->goalPos.y, state->goalPos.z + 5.0f, 1.0f, 24);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_ICE) {
|
2022-02-08 19:33:05 +01:00
|
|
|
fx_big_snowflakes(0, state->goalPos.x, state->goalPos.y, state->goalPos.z + 5.0f);
|
2021-12-21 23:12:59 +01:00
|
|
|
isIceDamage = TRUE;
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (!(battleStatus->currentAttackElement & DAMAGE_TYPE_REMOVE_BUFFS)) {
|
|
|
|
if ((targetPart->eventFlags & ACTOR_EVENT_FLAG_ILLUSORY) ||
|
|
|
|
((target->transStatus == STATUS_E) || ((targetPart->eventFlags & ACTOR_EVENT_FLAG_800) && !(battleStatus->currentAttackElement & DAMAGE_TYPE_QUAKE))))
|
|
|
|
{
|
2021-12-21 23:12:59 +01:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (target->stoneStatus == STATUS_STONE) {
|
|
|
|
sfx_play_sound_at_position(SOUND_IMMUNE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
func_8024EFE0(state->goalPos.x, state->goalPos.y, state->goalPos.z, 0, 1, 1);
|
|
|
|
show_damage_popup(state->goalPos.x, state->goalPos.y, state->goalPos.z, 0, 0);
|
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (gBattleStatus.flags1 & (BS_FLAGS1_40 | BS_FLAGS1_200)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (targetPart->partFlags3 & battleStatus->currentAttackElement) {
|
|
|
|
sp18 = TRUE;
|
|
|
|
} else {
|
|
|
|
sp18 = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetPart->eventFlags & (ACTOR_EVENT_FLAG_ENCHANTED | ACTOR_EVENT_FLAG_80000)) {
|
2021-12-21 23:12:59 +01:00
|
|
|
battleStatus->currentAttackElement &= ~DAMAGE_TYPE_IGNORE_DEFENSE;
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
temp = get_defense(target, targetPart->defenseTable, battleStatus->currentAttackElement);
|
2021-12-21 23:12:59 +01:00
|
|
|
if (!(battleStatus->currentAttackElement & DAMAGE_TYPE_IGNORE_DEFENSE)) {
|
2022-02-08 19:33:05 +01:00
|
|
|
temp += target->defenseBoost;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
attackDamage = battleStatus->currentAttackDamage;
|
|
|
|
if (attackDamage > 99) {
|
|
|
|
attackDamage = 99;
|
|
|
|
}
|
|
|
|
if (attackDamage <= 0) {
|
2022-02-08 19:33:05 +01:00
|
|
|
temp = 0;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
attackDamage -= temp;
|
|
|
|
target->hpChangeCounter = 0;
|
|
|
|
|
|
|
|
if (attackDamage <= 0) {
|
|
|
|
target->hpChangeCounter = 0;
|
|
|
|
ret = 2;
|
2021-12-21 23:12:59 +01:00
|
|
|
if (!(battleStatus->currentAttackElement & DAMAGE_TYPE_STATUS_ALWAYS_HITS)) {
|
|
|
|
dispatchEvent = EVENT_UNKNOWN_TRIGGER;
|
2022-02-08 19:33:05 +01:00
|
|
|
sfx_play_sound_at_position(SOUND_IMMUNE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
2021-12-21 23:12:59 +01:00
|
|
|
battleStatus->lastAttackDamage = 0;
|
2022-02-08 19:33:05 +01:00
|
|
|
} else {
|
2021-12-21 23:12:59 +01:00
|
|
|
dispatchEvent = EVENT_UNKNOWN_TRIGGER;
|
2022-02-08 19:33:05 +01:00
|
|
|
battleStatus->lastAttackDamage = 0;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-02-08 19:33:05 +01:00
|
|
|
target->damageCounter += attackDamage;
|
|
|
|
target->hpChangeCounter -= attackDamage;
|
2021-12-21 23:12:59 +01:00
|
|
|
battleStatus->lastAttackDamage = 0;
|
|
|
|
dispatchEvent = EVENT_HIT_COMBO;
|
2022-02-08 19:33:05 +01:00
|
|
|
ret = 0;
|
|
|
|
if (!(targetPart->flags & ACTOR_PART_FLAG_2000) && !sp18 && !(targetPart->targetFlags & ACTOR_PART_FLAG_4)) {
|
|
|
|
target->currentHP -= attackDamage;
|
|
|
|
if (target->currentHP <= 0) {
|
|
|
|
target->currentHP = 0;
|
2021-12-21 23:12:59 +01:00
|
|
|
dispatchEvent = EVENT_DEATH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
battleStatus->lastAttackDamage += attackDamage;
|
2022-02-08 19:33:05 +01:00
|
|
|
target->lastDamageTaken = battleStatus->lastAttackDamage;
|
|
|
|
target->hpChangeCounter = 0;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (targetPart->flags & ACTOR_PART_FLAG_2000) {
|
|
|
|
dispatch_event_actor(target, dispatchEvent);
|
|
|
|
func_8024EFE0(state->goalPos.x, state->goalPos.y, state->goalPos.z, 0, 1, 3);
|
|
|
|
sfx_play_sound_at_position(SOUND_IMMUNE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
2021-12-21 23:12:59 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_2000) {
|
|
|
|
battleStatus->lastAttackDamage = 0;
|
|
|
|
dispatchEvent = EVENT_DEATH;
|
2022-02-08 19:33:05 +01:00
|
|
|
ret = 0;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if (dispatchEvent == EVENT_HIT_COMBO) {
|
|
|
|
dispatchEvent = EVENT_HIT;
|
|
|
|
}
|
|
|
|
if (dispatchEvent == EVENT_UNKNOWN_TRIGGER) {
|
|
|
|
dispatchEvent = EVENT_IMMUNE;
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
if (target->currentHP <= 0 && dispatchEvent == EVENT_IMMUNE) {
|
|
|
|
dispatchEvent = EVENT_DEATH;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
} else if (dispatchEvent == EVENT_DEATH) {
|
|
|
|
dispatchEvent = EVENT_HIT_COMBO;
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
2022-02-08 19:33:05 +01:00
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_REMOVE_BUFFS) {
|
|
|
|
dispatchEvent = EVENT_IMMUNE;
|
|
|
|
if (targetPart->eventFlags & ACTOR_EVENT_FLAG_ENCHANTED) {
|
|
|
|
dispatchEvent = EVENT_STAR_BEAM;
|
|
|
|
wasStatusInflicted = TRUE;
|
|
|
|
}
|
|
|
|
if (targetPart->eventFlags & ACTOR_EVENT_FLAG_400000) {
|
|
|
|
dispatchEvent = EVENT_STAR_BEAM;
|
|
|
|
wasStatusInflicted = TRUE;
|
|
|
|
}
|
|
|
|
if (targetPart->eventFlags & ACTOR_EVENT_FLAG_80000) {
|
|
|
|
dispatchEvent = EVENT_1D;
|
|
|
|
}
|
|
|
|
ret = 0;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_REMOVE_BUFFS) {
|
|
|
|
if (gBattleStatus.flags1 & 0x20) {
|
|
|
|
if ((target->attackBoost > 0 || target->defenseBoost > 0) ||
|
|
|
|
((target->staticStatus == 0 && target->transStatus != 0) || target->staticStatus != 0))
|
|
|
|
{
|
|
|
|
target->attackBoost = 0;
|
|
|
|
target->defenseBoost = 0;
|
|
|
|
target->isGlowing = FALSE;
|
|
|
|
dispatchEvent = EVENT_HIT;
|
|
|
|
if (target->staticStatus != 0) {
|
|
|
|
target->staticStatus = 0;
|
|
|
|
target->staticDuration = 0;
|
|
|
|
remove_status_static(target->hudElementDataIndex);
|
|
|
|
}
|
|
|
|
if (target->transStatus != 0) {
|
|
|
|
target->transStatus = 0;
|
|
|
|
target->transDuration = 0;
|
|
|
|
remove_status_transparent(target->hudElementDataIndex);
|
|
|
|
}
|
|
|
|
wasStatusInflicted = TRUE;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
}
|
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_PEACH_BEAM) {
|
|
|
|
dispatchEvent = EVENT_IMMUNE;
|
2022-02-08 19:33:05 +01:00
|
|
|
if (targetPart->eventFlags & ACTOR_EVENT_FLAG_ENCHANTED) {
|
2021-12-21 23:12:59 +01:00
|
|
|
dispatchEvent = EVENT_14;
|
|
|
|
wasStatusInflicted = TRUE;
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
if (targetPart->eventFlags & ACTOR_EVENT_FLAG_80000) {
|
2021-12-21 23:12:59 +01:00
|
|
|
dispatchEvent = EVENT_14;
|
|
|
|
wasStatusInflicted = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_SPIN_SMASH) {
|
|
|
|
if (dispatchEvent == EVENT_HIT) {
|
|
|
|
dispatchEvent = EVENT_SPIN_SMASH_HIT;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
if (dispatchEvent == EVENT_DEATH) {
|
|
|
|
dispatchEvent = EVENT_SPIN_SMASH_DEATH;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if ((battleStatus->currentAttackElement & (DAMAGE_TYPE_JUMP | DAMAGE_TYPE_POW)) &&
|
|
|
|
(targetPart->eventFlags & ACTOR_EVENT_FLAG_GROUNDABLE))
|
|
|
|
{
|
|
|
|
if (dispatchEvent == EVENT_HIT) {
|
|
|
|
dispatchEvent = EVENT_FALL_TRIGGER;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
if (dispatchEvent == EVENT_IMMUNE) {
|
|
|
|
dispatchEvent = EVENT_FALL_TRIGGER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if ((battleStatus->currentAttackElement & DAMAGE_TYPE_POW) &&
|
|
|
|
(targetPart->eventFlags & ACTOR_EVENT_FLAG_800000))
|
|
|
|
{
|
|
|
|
if (dispatchEvent == EVENT_HIT) {
|
|
|
|
dispatchEvent = EVENT_FALL_TRIGGER;
|
|
|
|
}
|
|
|
|
if (dispatchEvent == EVENT_IMMUNE) {
|
|
|
|
dispatchEvent = EVENT_FALL_TRIGGER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if ((battleStatus->currentAttackElement & (DAMAGE_TYPE_JUMP | DAMAGE_TYPE_POW | DAMAGE_TYPE_QUAKE)) &&
|
|
|
|
(targetPart->eventFlags & ACTOR_EVENT_FLAG_FLIPABLE))
|
|
|
|
{
|
|
|
|
if (dispatchEvent == EVENT_HIT) {
|
|
|
|
dispatchEvent = EVENT_FLIP_TRIGGER;
|
|
|
|
}
|
|
|
|
if (dispatchEvent == EVENT_IMMUNE) {
|
|
|
|
dispatchEvent = EVENT_FLIP_TRIGGER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
if (battleStatus->currentAttackElement & DAMAGE_TYPE_FIRE) {
|
|
|
|
if (dispatchEvent == EVENT_HIT) {
|
|
|
|
dispatchEvent = EVENT_BURN_HIT;
|
|
|
|
}
|
|
|
|
if (dispatchEvent == EVENT_DEATH) {
|
|
|
|
dispatchEvent = EVENT_BURN_DEATH;
|
|
|
|
}
|
|
|
|
isFireDamage = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) &&
|
|
|
|
battleStatus->lastAttackDamage >= 0 &&
|
|
|
|
dispatchEvent != EVENT_DEATH &&
|
|
|
|
dispatchEvent != EVENT_SPIN_SMASH_DEATH &&
|
|
|
|
dispatchEvent != EVENT_EXPLODE_TRIGGER)
|
|
|
|
{
|
|
|
|
// Using this macro because it's nicer to look at, and it also is necessary to wrap the first 5 of these in a
|
|
|
|
// do-while-0 OR to wrap each one individually. It's more likely that it's a macro instead, and much cleaner
|
|
|
|
#define INFLICT_STATUS(STATUS_TYPE) \
|
|
|
|
do { \
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_##STATUS_TYPE) && \
|
|
|
|
try_inflict_status(target, STATUS_##STATUS_TYPE, STATUS_##STATUS_TYPE##_TURN_MOD)) { \
|
|
|
|
wasStatusInflicted = TRUE; \
|
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
INFLICT_STATUS(SHRINK);
|
|
|
|
INFLICT_STATUS(POISON);
|
|
|
|
INFLICT_STATUS(STONE);
|
|
|
|
INFLICT_STATUS(SLEEP);
|
|
|
|
INFLICT_STATUS(STOP);
|
|
|
|
INFLICT_STATUS(STATIC);
|
|
|
|
INFLICT_STATUS(FEAR);
|
|
|
|
INFLICT_STATUS(PARALYZE);
|
|
|
|
INFLICT_STATUS(DIZZY);
|
|
|
|
|
|
|
|
#undef INFLICT_STATUS
|
|
|
|
|
|
|
|
if (wasStatusInflicted) {
|
|
|
|
if (dispatchEvent == EVENT_UNKNOWN_TRIGGER) {
|
|
|
|
dispatchEvent = EVENT_HIT_COMBO;
|
|
|
|
}
|
|
|
|
if (dispatchEvent == EVENT_IMMUNE) {
|
|
|
|
dispatchEvent = EVENT_HIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = target->actorBlueprint->baseStatusChance;
|
|
|
|
temp = (battleStatus->statusChance * temp) / 100;
|
|
|
|
|
|
|
|
if ((gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) && (battleStatus->currentAttackElement & DAMAGE_TYPE_FEAR)) {
|
|
|
|
if (rand_int(99) < temp &&
|
|
|
|
!(target->debuff == STATUS_FEAR ||
|
|
|
|
target->debuff == STATUS_DIZZY ||
|
|
|
|
target->debuff == STATUS_PARALYZE ||
|
|
|
|
target->debuff == STATUS_SLEEP ||
|
|
|
|
target->debuff == STATUS_FROZEN ||
|
|
|
|
target->debuff == STATUS_STOP) &&
|
|
|
|
!(target->flags & ACTOR_FLAG_400))
|
|
|
|
{
|
|
|
|
dispatchEvent = EVENT_SCARE_AWAY;
|
|
|
|
ret = 0;
|
|
|
|
sp1C = TRUE;
|
|
|
|
gBattleStatus.flags1 |= 0x39;
|
|
|
|
sfx_play_sound_at_position(SOUND_231, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
wasStatusInflicted = TRUE;
|
|
|
|
gBattleStatus.flags1 |= 0x40;
|
2021-12-21 23:12:59 +01:00
|
|
|
} else {
|
2022-02-08 19:33:05 +01:00
|
|
|
dispatchEvent = EVENT_IMMUNE;
|
|
|
|
ret = 2;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
battleStatus->wasStatusInflicted = wasStatusInflicted;
|
|
|
|
|
|
|
|
if (
|
|
|
|
(sp1C && (gBattleStatus.flags1 & (BS_FLAGS1_40 | BS_FLAGS1_200))) ||
|
|
|
|
((gBattleStatus.flags1 & (BS_FLAGS1_40 | BS_FLAGS1_200)) && !(gBattleStatus.flags1 & BS_FLAGS1_80))
|
|
|
|
) {
|
|
|
|
if (battleStatus->lastAttackDamage > 0) {
|
|
|
|
sfx_play_sound_at_position(SOUND_231, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (battleStatus->lastAttackDamage > 0 || (battleStatus->currentAttackElement & DAMAGE_TYPE_STATUS_ALWAYS_HITS) && sp1C) {
|
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_40) {
|
|
|
|
func_802667F0(0, target, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
} else {
|
|
|
|
func_802667F0(3, target, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE) {
|
2022-02-08 19:33:05 +01:00
|
|
|
func_80266970(target);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
dispatch_event_actor(target, dispatchEvent);
|
|
|
|
|
|
|
|
if (actorClass == ACTOR_PARTNER) {
|
|
|
|
if ((battleStatus->lastAttackDamage > 0) && (gBattleStatus.flags1 & BS_FLAGS1_SP_EVT_ACTIVE)) {
|
|
|
|
inflict_status(target, STATUS_DAZE, battleStatus->lastAttackDamage);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (!(target->flags & ACTOR_FLAG_NO_DMG_POPUP)) {
|
2021-12-21 23:12:59 +01:00
|
|
|
if (battleStatus->lastAttackDamage == 0) {
|
2022-02-08 19:33:05 +01:00
|
|
|
if (!sp1C && !wasStatusInflicted) {
|
|
|
|
func_8024EFE0(state->goalPos.x, state->goalPos.y, state->goalPos.z, 0, 1, 3);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
} else if (!sp18) {
|
2021-12-21 23:12:59 +01:00
|
|
|
if (battleStatus->currentAttackElement & (DAMAGE_TYPE_SMASH | DAMAGE_TYPE_NO_OTHER_DAMAGE_POPUPS)) {
|
2022-02-08 19:33:05 +01:00
|
|
|
show_damage_popup(state->goalPos.x, state->goalPos.y, state->goalPos.z, battleStatus->lastAttackDamage, 0);
|
2021-12-21 23:12:59 +01:00
|
|
|
} else {
|
2022-02-08 19:33:05 +01:00
|
|
|
func_802664DC(state->goalPos.x, state->goalPos.y, state->goalPos.z, battleStatus->lastAttackDamage, 0);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
if (!(targetPart->targetFlags & 4)) {
|
|
|
|
func_802666E4(target, state->goalPos.x, state->goalPos.y, state->goalPos.z, battleStatus->lastAttackDamage);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if (battleStatus->lastAttackDamage > 0 && !sp18) {
|
|
|
|
func_80267018(target, 1);
|
|
|
|
if (isFireDamage) {
|
|
|
|
sfx_play_sound_at_position(SOUND_HIT_FIRE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
} else if (isElectricDamage) {
|
|
|
|
sfx_play_sound_at_position(SOUND_HIT_SHOCK, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
} else if (isIceDamage) {
|
|
|
|
sfx_play_sound_at_position(SOUND_HIT_ICE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
} else {
|
|
|
|
sfx_play_sound_at_position(SOUND_HIT_NORMAL, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
if ((battleStatus->lastAttackDamage <= 0 && !wasStatusInflicted) || (targetPart->flags & ACTOR_FLAG_2000)) {
|
|
|
|
sfx_play_sound_at_position(SOUND_IMMUNE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_SLEEP) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoSleepHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_SLEEP, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_DIZZY) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoDizzyHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_STATUS, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_PARALYZE) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoParalyzeHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_STATUS, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_POISON) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoPoisonHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_STATUS, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_STOP) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoStopHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_STATUS, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_FROZEN) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoFreezeHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
2022-08-06 14:14:04 +02:00
|
|
|
script->varTablePtr[3] = target;
|
2022-02-08 19:33:05 +01:00
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_STATUS, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackStatus & STATUS_FLAG_SHRINK) && wasStatusInflicted) {
|
2022-08-06 14:14:04 +02:00
|
|
|
script = start_script(&DoShrinkHit, EVT_PRIORITY_A, 0);
|
2022-02-08 19:33:05 +01:00
|
|
|
script->varTable[0] = state->goalPos.x;
|
|
|
|
script->varTable[1] = state->goalPos.y;
|
|
|
|
script->varTable[2] = state->goalPos.z;
|
2022-08-06 14:14:04 +02:00
|
|
|
script->varTablePtr[3] = target;
|
2022-02-08 19:33:05 +01:00
|
|
|
sfx_play_sound_at_position(SOUND_INFLICT_STATUS, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
if ((battleStatus->currentAttackElement & DAMAGE_TYPE_SMASH) && (target->actorType == ACTOR_TYPE_GOOMNUT_TREE)) {
|
|
|
|
sfx_play_sound_at_position(SOUND_SMASH_GOOMNUT_TREE, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
func_80266ADC(target);
|
|
|
|
|
2021-12-21 23:12:59 +01:00
|
|
|
if (gBattleStatus.flags1 & (BS_FLAGS1_40 | BS_FLAGS1_200)) {
|
2022-02-08 19:33:05 +01:00
|
|
|
if (ret == 0) {
|
|
|
|
ret = 1;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
if (ret == 2) {
|
|
|
|
ret = 3;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:33:05 +01:00
|
|
|
|
|
|
|
return ret;
|
2021-12-21 23:12:59 +01:00
|
|
|
}
|
2020-10-15 05:49:49 +02:00
|
|
|
|
2021-08-22 23:50:10 +02:00
|
|
|
ApiStatus ItemDamageEnemy(Evt* script, s32 isInitialCall) {
|
2021-02-20 15:41:30 +01:00
|
|
|
BattleStatus* battleStatus = &gBattleStatus;
|
2020-11-18 06:20:28 +01:00
|
|
|
Bytecode* args = script->ptrReadPos;
|
|
|
|
s32 itemDamageOut = *args++;
|
2022-02-21 17:05:36 +01:00
|
|
|
s32 flags;
|
2020-11-18 06:20:28 +01:00
|
|
|
Actor* actor;
|
|
|
|
s32 itemDamage;
|
|
|
|
|
|
|
|
battleStatus->currentAttackElement = *args++;
|
|
|
|
battleStatus->currentAttackEventSuppression = 0;
|
|
|
|
battleStatus->currentAttackStatus = *args++;
|
2021-08-29 18:51:56 +02:00
|
|
|
battleStatus->currentAttackDamage = evt_get_variable(script, *args++);
|
2022-02-21 17:05:36 +01:00
|
|
|
flags = *args++;
|
|
|
|
|
|
|
|
if ((flags & (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) == (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_10) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2022-02-21 17:05:36 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_40) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_200) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_80) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
actor = get_actor(script->owner1.actorID);
|
|
|
|
battleStatus->currentTargetID = actor->targetActorID;
|
|
|
|
battleStatus->currentTargetPart = actor->targetPartIndex;
|
|
|
|
battleStatus->statusChance = battleStatus->currentAttackStatus;
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (battleStatus->statusChance == 0xFF) {
|
2020-11-18 06:20:28 +01:00
|
|
|
battleStatus->statusChance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
|
|
|
|
|
|
|
|
itemDamage = calc_item_damage_enemy();
|
|
|
|
if (itemDamage < 0) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
|
|
|
|
2021-08-29 18:51:56 +02:00
|
|
|
evt_set_variable(script, itemDamageOut, itemDamage);
|
2020-11-18 06:20:28 +01:00
|
|
|
if (!does_script_exist_by_ref(script)) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiStatus_DONE2;
|
|
|
|
}
|
|
|
|
|
2021-08-22 23:50:10 +02:00
|
|
|
ApiStatus ItemAfflictEnemy(Evt* script, s32 isInitialCall) {
|
2021-02-20 15:41:30 +01:00
|
|
|
BattleStatus* battleStatus = &gBattleStatus;
|
2020-11-18 06:20:28 +01:00
|
|
|
Bytecode* args = script->ptrReadPos;
|
|
|
|
s32 itemDamageOut = *args++;
|
|
|
|
Actor* actor;
|
|
|
|
s32 itemDamage;
|
2022-02-21 17:05:36 +01:00
|
|
|
s32 flags;
|
2020-11-18 06:20:28 +01:00
|
|
|
|
|
|
|
battleStatus->currentAttackElement = *args++;
|
|
|
|
battleStatus->currentAttackEventSuppression = 0;
|
|
|
|
battleStatus->currentAttackStatus = *args++;
|
2021-08-29 18:51:56 +02:00
|
|
|
battleStatus->currentAttackStatus |= evt_get_variable(script, *args++);
|
|
|
|
battleStatus->currentAttackDamage = evt_get_variable(script, *args++);
|
2022-02-21 17:05:36 +01:00
|
|
|
flags = *args++;
|
|
|
|
|
|
|
|
if ((flags & (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) == (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_10) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2022-02-21 17:05:36 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_40) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_200) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_80) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
actor = get_actor(script->owner1.actorID);
|
|
|
|
battleStatus->currentTargetID = actor->targetActorID;
|
|
|
|
battleStatus->currentTargetPart = actor->targetPartIndex;
|
|
|
|
battleStatus->statusChance = battleStatus->currentAttackStatus;
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (battleStatus->statusChance == 0xFF) {
|
2020-11-18 06:20:28 +01:00
|
|
|
battleStatus->statusChance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
|
|
|
|
|
|
|
|
itemDamage = calc_item_damage_enemy();
|
|
|
|
if (itemDamage < 0) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
|
|
|
|
2021-08-29 18:51:56 +02:00
|
|
|
evt_set_variable(script, itemDamageOut, itemDamage);
|
2020-11-18 06:20:28 +01:00
|
|
|
if (!does_script_exist_by_ref(script)) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiStatus_DONE2;
|
|
|
|
}
|
|
|
|
|
2021-08-22 23:50:10 +02:00
|
|
|
ApiStatus func_80252B3C(Evt* script, s32 isInitialCall) {
|
2021-02-20 15:41:30 +01:00
|
|
|
BattleStatus* battleStatus = &gBattleStatus;
|
2020-11-18 06:20:28 +01:00
|
|
|
Bytecode* args = script->ptrReadPos;
|
|
|
|
s32 itemDamageOut = *args++;
|
2022-02-21 17:05:36 +01:00
|
|
|
s32 flags;
|
2020-11-18 06:20:28 +01:00
|
|
|
Actor* actor;
|
|
|
|
s32 itemDamage;
|
|
|
|
|
|
|
|
battleStatus->currentAttackElement = *args++;
|
|
|
|
battleStatus->currentAttackEventSuppression = 0;
|
2021-08-29 18:51:56 +02:00
|
|
|
battleStatus->currentAttackStatus = evt_get_variable(script, *args++);
|
|
|
|
battleStatus->currentAttackDamage = evt_get_variable(script, *args++);
|
2022-02-21 17:05:36 +01:00
|
|
|
flags = *args++;
|
|
|
|
|
|
|
|
if ((flags & (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) == (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_10) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2022-02-21 17:05:36 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_40) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_200) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_80) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
actor = get_actor(script->owner1.actorID);
|
|
|
|
battleStatus->currentTargetID = actor->targetActorID;
|
|
|
|
battleStatus->currentTargetPart = actor->targetPartIndex;
|
|
|
|
battleStatus->statusChance = battleStatus->currentAttackStatus;
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (battleStatus->statusChance == 0xFF) {
|
2020-11-18 06:20:28 +01:00
|
|
|
battleStatus->statusChance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
|
|
|
|
|
|
|
|
itemDamage = calc_item_damage_enemy();
|
|
|
|
if (itemDamage < 0) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
|
|
|
|
2021-08-29 18:51:56 +02:00
|
|
|
evt_set_variable(script, itemDamageOut, itemDamage);
|
2020-11-18 06:20:28 +01:00
|
|
|
if (!does_script_exist_by_ref(script)) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiStatus_DONE2;
|
|
|
|
}
|
|
|
|
|
2021-08-22 23:50:10 +02:00
|
|
|
ApiStatus ItemCheckHit(Evt* script, s32 isInitialCall) {
|
2021-02-20 15:41:30 +01:00
|
|
|
BattleStatus* battleStatus = &gBattleStatus;
|
2020-11-18 06:20:28 +01:00
|
|
|
Bytecode* args = script->ptrReadPos;
|
|
|
|
s32 itemDamageOut = *args++;
|
2022-02-21 17:05:36 +01:00
|
|
|
s32 flags;
|
2020-11-18 06:20:28 +01:00
|
|
|
Actor* actor;
|
|
|
|
s32 itemDamage;
|
|
|
|
|
|
|
|
battleStatus->currentAttackElement = *args++;
|
|
|
|
battleStatus->currentAttackEventSuppression = 0;
|
|
|
|
battleStatus->currentAttackStatus = *args++;
|
2021-08-29 18:51:56 +02:00
|
|
|
battleStatus->currentAttackDamage = evt_get_variable(script, *args++);
|
2022-02-21 17:05:36 +01:00
|
|
|
flags = *args++;
|
|
|
|
|
|
|
|
if ((flags & (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) == (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE)) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_10) {
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
|
|
|
} else if (flags & BS_FLAGS1_SP_EVT_ACTIVE) {
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2022-02-21 17:05:36 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_10;
|
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_SP_EVT_ACTIVE;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_40) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_40;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_200) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_200;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (flags & BS_FLAGS1_80) {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 |= BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
} else {
|
2021-12-12 14:53:19 +01:00
|
|
|
gBattleStatus.flags1 &= ~BS_FLAGS1_80;
|
2020-11-18 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
actor = get_actor(script->owner1.actorID);
|
|
|
|
battleStatus->currentTargetID = actor->targetActorID;
|
|
|
|
battleStatus->currentTargetPart = actor->targetPartIndex;
|
|
|
|
battleStatus->statusChance = battleStatus->currentAttackStatus;
|
|
|
|
|
2022-02-21 17:05:36 +01:00
|
|
|
if (battleStatus->statusChance == 0xFF) {
|
2020-11-18 06:20:28 +01:00
|
|
|
battleStatus->statusChance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
|
2020-10-15 05:49:49 +02:00
|
|
|
|
2020-11-18 06:20:28 +01:00
|
|
|
itemDamage = calc_item_check_hit();
|
|
|
|
if (itemDamage < 0) {
|
|
|
|
return ApiStatus_FINISH;
|
|
|
|
}
|
2020-10-15 05:49:49 +02:00
|
|
|
|
2021-08-29 18:51:56 +02:00
|
|
|
evt_set_variable(script, itemDamageOut, itemDamage);
|
2020-10-15 05:49:49 +02:00
|
|
|
|
2020-11-18 06:20:28 +01:00
|
|
|
return ApiStatus_DONE2;
|
|
|
|
}
|