#include "gbafe.h"
extern int pr_SpellthiefId;
bool thumb_SkillTester(struct Unit * unit, u8 sid);
void Proc_Spellthief(struct BattleUnit * actor, struct BattleUnit * target, struct BattleHit * hit, struct BattleStats * stat)
{
int i, weapon, wtype;
if (!(stat->config & BATTLE_CONFIG_REAL))
return;
if (!thumb_SkillTester(&target->unit, pr_SpellthiefId))
return;
if (!(hit->attributes & BATTLE_HIT_ATTR_MISS))
return;
weapon = actor->weaponBefore;
/* Skip unbreakable weapon */
if (GetItemAttributes(weapon) & IA_UNBREAKABLE)
return;
wtype = GetItemType(weapon);
switch (wtype) {
case ITYPE_ANIMA:
case ITYPE_LIGHT:
case ITYPE_DARK:
break;
default:
return;
}
/* If attacker use the same weapon as target */
if (target == &gBattleTarget && ITEM_INDEX(weapon) == ITEM_INDEX(target->weaponBefore) && target->canCounter)
{
if (ITEM_USES(target->weapon) < GetItemMaxUses(weapon))
{
target->weapon = ITEM_INDEX(target->weapon) | ((ITEM_USES(target->weapon) + 1) << 8);
return;
}
}
for (i = 0; i < UNIT_ITEM_COUNT; i++)
{
if (target->unit.items[i] == 0)
{
target->unit.items[i] = ITEM_INDEX(weapon) | (1 << 8);
return;
}
else if (ITEM_INDEX(target->unit.items[i]) == ITEM_INDEX(weapon))
{
if (ITEM_USES(target->unit.items[i]) < GetItemMaxUses(weapon))
{
target->unit.items[i] = ITEM_INDEX(target->unit.items[i]) | ((ITEM_USES(target->unit.items[i]) + 1) << 8);
return;
}
}
}
}
compiled:
ALIGN 4
PUSH
ORG CURRENTOFFSET+$1;Proc_Spellthief:
POP
WORD $4646B5F0 $464F46D6 $B5C0881B $6000D $7DB0014 $BCE0D406 $46B146BA $BCF046A8 $4700BC01 $284B37 $4B377819 $F876F000 $D0F02800 $79B6823 $274AD5ED $4B335BF6 $F0000030 $2308F86B $4004001C $D1E24203 $4B2F0030 $F862F000 $28023805 $4B2DD8DB $D027429D $4699231E $469833E1 $469A4B2A $464B44A9 $2F00881F $33D03A $407B4642 $D006421A $469C2302 $44E13401 $D1F02C05 $30E7C1 $F843F000 $42870A3F $64DAF2 $8BE0192C $33010A03 $4643021A $43134003 $E7B083E3 $27FF5BEB $421F4073 $2352D1D2 $2B0056EB $2348D0CE $5AEB4698 $46990A1B $4B110030 $F822F000 $DAC34581 $5AEA4643 $33010A13 $21B403A $46424313 $E79252AB $228021FF $63340C $524031 $430A18EB $E78880DA
POIN pr_SpellthiefId
POIN thumb_SkillTester
WORD $801756D $8017549 $203A56C $80175B1 $47504718
Add external definations:
ALIGN 4
/* Define the skill index by yourself */
pr_SpellthiefId:
WORD 148
thumb_SkillTester:
POIN SkillTester | 1
And insert the compiled label Proc_Spellthief
to the proc skills:
// EngineHacks\Necessary\CalcLoops\BattleProcCalcLoop\BattleProcCalcLoop.event
ProcLoopParent:
// ...
POIN Proc_Spellthief
// ...