Hi all, right now I'm working with creating and implementing item bonuses and so far I was pretty successful with implementing my own negate ninja stone item bonus. However for my second item bonus idea I wanted to do something a little more ambitious. For reference sake I'm primarily working with pre-renewal in case that's important information before going forward.
Right now we have this item bonus here:
bonus2 bMagicAtkEle,e,x; Increases damage of e element magic by x%
And basically my idea is I want to create a new version of this bonus only it also includes melee and range damage instead of just magic. So I went ahead and implemented these 2 new item bonuses to start with:
bonus2 bRangeAtkEle,e,x; Increases damage of e element range by x% // Custom [Neutral]
bonus2 bMeleeAtkEle,e,x; Increases damage of e element melee by x% // Custom [Neutral]
Just to make sure I did everything correctly I did some digging around to see how bMagicAtkEle was implemented, and here's a collection of images showing everything I edited here:
https://www.dropbox.com/s/v0qnakxjoo5vmod/item_bonus_practice.png?dl=0
After I did this I went ahead and did some digging around to see how magic_atk_ele was implemented into the game and I found that it was in battle.c being used in this switch condition here starting at line 579 battle.c:
switch( attack_type ) {
case BF_MAGIC:
// Affected by attacker ATK bonuses
if( sd && !(nk&NK_NO_CARDFIX_ATK) ) {
cardfix = cardfix * (100 + sd->magic_addrace[tstatus->race] + sd->magic_addrace[RC_ALL] + sd->magic_addrace2[t_race2]) / 100;
if( !(nk&NK_NO_ELEFIX) ) { // Affected by Element modifier bonuses
cardfix = cardfix * (100 + sd->magic_addele[tstatus->def_ele] + sd->magic_addele[ELE_ALL] +
sd->magic_addele_script[tstatus->def_ele] + sd->magic_addele_script[ELE_ALL]) / 100;
cardfix = cardfix * (100 + sd->magic_atk_ele[rh_ele] + sd->magic_atk_ele[ELE_ALL]) / 100;
}
cardfix = cardfix * (100 + sd->magic_addsize[tstatus->size] + sd->magic_addsize[SZ_ALL]) / 100;
cardfix = cardfix * (100 + sd->magic_addclass[tstatus->class_] + sd->magic_addclass[CLASS_ALL]) / 100;
for( i = 0; i < ARRAYLENGTH(sd->add_mdmg) && sd->add_mdmg[i].rate; i++ ) {
if( sd->add_mdmg[i].class_ == t_class ) {
cardfix = cardfix * (100 + sd->add_mdmg[i].rate) / 100;
break;
}
}
APPLY_CARDFIX(damage, cardfix);
}
Then I noticed below here that there was a case for BF_WEAPON: where it had an if statement for if the attacking method was range or melee. So based on this what I tried to do was I tried to copy the line in BF_MAGIC: that said this:
cardfix = cardfix * (100 + sd->magic_atk_ele[rh_ele] + sd->magic_atk_ele[ELE_ALL]) / 100;
I made 2 copies of it and replaced where it said "magic_atk_ele" with "range_atk_ele" and "melee_atk_ele" respectively and placed them where I "thought" it made sense in these locations of battle.c:
Starting at line 661 battle.c:
if( !(((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
continue;
ele_fix += sd->right_weapon.addele2[i].rate;
}
cardfix = cardfix * (100 + sd->range_atk_ele[rh_ele] + sd->range_atk_ele[ELE_ALL]) / 100;
cardfix = cardfix * (100 + ele_fix) / 100;
}
Starting at line 687 battle.c:
if( !(((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
continue;
ele_fix += sd->right_weapon.addele2[i].rate;
}
cardfix = cardfix * (100 + sd->melee_atk_ele[rh_ele] + sd->melee_atk_ele[ELE_ALL]) / 100;
cardfix = cardfix * (100 + ele_fix) / 100;
}
The reason why I thought to place them in those locations was because I noticed that in BF_MAGIC: the magic_atk_ele line was encased in this if statement here:
if( sd && !(nk&NK_NO_CARDFIX_ATK) )
So after I did this I threw bMagicAtkEle, bRangeAtkEle, and bMeleeAtkEle onto 3 separate cards, took it in game after compiling the changes, and then I gave it a go. the results I got were very strange though.
The magic part works as intended, it will give me a reasonable number if I say Ele_Fire,100; for instance, I get a result like this: ~350 -> ~700 per hit with fire bolt on average. But then when I try to use the Melee and Range versions that's when things start to get weird. For instance if I try to use it with mammonite I will get a result such as this without fire element: ~550 on average. But then once I introduce the fire element I'll get a result such as this: ~1200 on average, which seems normal. But then I realized that the melee and range value start to stack, because if you combine the melee and range cards with these bonuses together, you'll get a ridiculous number such as this: ~3000 on average. What's even more strange is that if you take off the weapon with the cards on it, switch to a weapon with no cards in it at all, and then enchant fire element into it, it'll still do like ~3000 despite there being no cards there, which is telling me that somehow the effect is carrying over to other weapons.
So that's where I am and what I tried at the moment. I thought I knew what I was doing at first but I think I'm either not using the right formula, I didn't implement the item bonus "fully" or "correctly", or it's possible that I just didn't put the damage formula in the right spot in the source. Thank you all for your help and support.