const int I_MAGIC_ARMOR_ACTIVE = 61; //Item used to handle actal Magic Armor properties, Golden Ring by default.
const int CR_MAGIC_ARMOR_FUEL = 1;//ID of counter used as fuel.
const int SFX_MAGIC_ARMOR_FUEL_DRAIN = 47;//Sound to play, when Magic Armor absorbs damage and drains fuel.
const int SFX_MAGIC_ARMOR_OUT_OF_FUEL = 3;//Sound to play, when Magic Armor runs out of fuel and deactivates
const int MAGIC_ARMOR_SPILL_OVER_DAMAGE = 1;//If>0, upon running out of fuel, excess damage is applied to Link, not vanish.
const int CMB_FORCEFIELD_AURA = 0;//Combo used to render active protective aura (3x3 tiles), when Magic Armor is active.
const int CSET_FORCEFIELD_AURA = 0;//CSet used to render active protective aura.
//Twilight Princess Magic Armor.
//A suit of enchanted armor, that can be activated/deactivated. When active, it reduces damage by a huge factor. But his protection is fuel-powered.
//1. Set up 2 items, 1 for activator/deactivator(to be accessed from subscreen) and 1 for actual armor(Ring class, I_MAGIC_ARMOR_ACTIVE).
//2. Global script combining, put
// int OldLinkHP = Link->HP;
// before main loop of active global script.
// then put
// OldLinkHP=UpdateMagicArmor(OldLinkHP);
// before Waitdraw command inside the main loop of Active global script.
//3. For 1st item from step 1, assign Magic Armor item script into onAction script slot.
//4. For 2nd item, the armor ring, set D0 to fuel cost multiplier. By default, Magic Armor uses 1 unit of fuel for each 1 HP absorbed. For instance, Magic Armor
// with Divisor of 8 against a Fire Gleeok`s breath attack (2 hearts in damage, if no protection, 32 HP). 4 HP slips through, 32-4=28 HP is absorbed, and 28 units of // fuel are used.
item script MagicArmor{
void run(){
if (Link->Item[I_MAGIC_ARMOR_ACTIVE]) Link->Item[I_MAGIC_ARMOR_ACTIVE]=false;
else if (Game->Counter[CR_MAGIC_ARMOR_FUEL]>0) Link->Item[I_MAGIC_ARMOR_ACTIVE]=true;
}
}
global script MagicArmorActive{
void run(){
int OldLinkHP = Link->HP;
while(true){
OldLinkHP=UpdateMagicArmor(OldLinkHP);
Waitframe();
}
}
}
int UpdateMagicArmor(int OldLinkHP){
if (!Link->Item[I_MAGIC_ARMOR_ACTIVE]){
return Link->HP;
}
if (CMB_FORCEFIELD_AURA>0)Screen->DrawCombo(3, Link->X-16, Link->Y-16,CMB_FORCEFIELD_AURA, 3, 3,CSET_FORCEFIELD_AURA, -1, -1,0,0,0,0,0,true,OP_OPAQUE);
if (Link->Action==LA_GOTHURTLAND||Link->Action==LA_GOTHURTWATER){
if (Link->HP<OldLinkHP){
itemdata it = Game->LoadItemData(I_MAGIC_ARMOR_ACTIVE);
int modifier = Cond(it->InitD[0]==0, 1, it->InitD[0]);
int cost = Floor((it->Power-1)*(OldLinkHP-Link->HP)*modifier);
// Trace(cost);
if (Game->Counter[CR_MAGIC_ARMOR_FUEL]>=cost){
Game->PlaySound(SFX_MAGIC_ARMOR_FUEL_DRAIN);
Game->Counter[CR_MAGIC_ARMOR_FUEL]-=cost;
if (Game->Counter[CR_MAGIC_ARMOR_FUEL]<=0){
Game->PlaySound(SFX_MAGIC_ARMOR_OUT_OF_FUEL);
Link->Item[I_MAGIC_ARMOR_ACTIVE]=false;
}
}
else{
if (MAGIC_ARMOR_SPILL_OVER_DAMAGE>0){
int spill = cost - Game->Counter[CR_MAGIC_ARMOR_FUEL];
Link->HP-=spill;
}
Game->Counter[CR_MAGIC_ARMOR_FUEL]=0;
Game->PlaySound(SFX_MAGIC_ARMOR_OUT_OF_FUEL);
Link->Item[I_MAGIC_ARMOR_ACTIVE]=false;
}
}
}
return Link->HP;
}