Below is the switch statements for optimal dmg stack prevention on hit based abilities:
Code:
//Binary check for mult skill trigger
new skillcheck = 0;
//Relm Level
new relm_level=skill_level_relm[attacker];
//Spear Level
new spear_level=skill_level_spear[attacker];
//Relm Prop
if(relm_level>0 && Math_GetRandomFloat( 0.0, 1.0 ) <= RelmChanse[relm_level])
{
skillcheck+=1;
}
//Spear Prop
if(spear_level>0 && Math_GetRandomFloat( 0.0, 1.0 ) <= SpearChanse[spear_level])
{
skillcheck+=2;
}
switch (skillcheck)
{
//Runs if Relm was selected
case 1:
{
Relm(victim,attacker,dmg,relm_level);
}
//Runs if Spear was selected
case 2:
{
Spear(victim,attacker,dmg,spear_level);
}
//Runs if both were selected and selects 1
case 3:
{
new chance = Math_GetRandomInt( 1, 2 );
switch (chance)
{
//Runs if Relm was selected
case 1:
{
Relm(victim,attacker,dmg,relm_level);
}
//Runs if Spear was selected
case 2:
{
Spear(victim,attacker,dmg,spear_level);
}
//Checks for erros
default:
{
PrintToChat(attacker,"[ERROR] Out of bounds vale for stacked skill, please report.");
}
}
}
}
Note that in this code the abilities themselves are methods which are called by the appropriate switch. An example of a method is below:
Code:
public Relm(any:victim,any:attacker,any:dmg,any:skill_level)
{
//skill code here
}
This methodology makes it impossible for the dmg stack prevention to effect the probability of a skill actually occurring. Also the use of switches dramatically improves performance which is especially important for a function that can be called very often. Also note the use of && vs nested ifs for when a new variable creation is not needed. This reduces the number of calls.