//Hate Spell, v0.3; 8th August, 2019; ZoriaRPG
//Spell Item to increase weapon power of a specific itemclass while the item is active.
//D0: A sound to play as an error...
//D1: The item class to use. Defaults to IC_SWORD.
//D2: Damage Multiplier
//Item Editor Fields
// Cost Counter: The counter to check.
// Cost: The cost to apply per revolution.
// Timer: The number of frames to wait before checking the cost.
item script hatespell
{
void run(int errSfx, int affectedItemClass, float power_multiplier)
{
int f;
bool quit_by_button_press;
affectedItemClass = ( affectedItemClass > 0 ) affectedItemClass : IC_SWORD;
power_multiplier = ( power_multiplier > 0 ) power_multiplier : 1.5000;
int tempitmpower[256];
if ( Game->Counter[this->CostCounter] < this->Cost )
{
Audio->PlaySound(errSfx); Quit(); //If we can't pay the cost, quit.
}
for ( int q = 0; q < 256; ++q )
{
itemdata theItem = Game->LoadItemData(q);
if ( theItem->Class == affectedItemClass )
{
tempitmpower[q] = theItem->Power+1;
theItem->Power *= power_multiplier;
}
}
while(1)
{
++f;
if ( f < 0 ) f = 1; //fix underflows
unless ( ((f%this->CostTimer)) ) //every n frames, apply the cost
{
if((Game->Counter[this->CostCounter] -= this->Cost) > 0)
{
Waitframe();
}
else break;
}
if (( Hero->PressA && Hero->ItemA == this->ID ) ||( Hero->PressB && Hero->ItemB == this->ID ) || quit_by_button_press )
{
break; ///Using the item again, ends its effect.
}
Waitframe();
}
Audio->PlaySound(this->UseSound); //Play the use sound again, when deactivating.
//Restore original item Power values, as the effect has ended.
for ( int q = 0; q < 256; ++q )
{
itemdata theItem = Game->LoadItemData(q);
if ( theItem->Class == affectedItemClass )
{
if ( tempitmpower[q] )
{
theItem->Power = tempitmpower[q]-1;
}
}
}
Quit();
}
}
Comments