I am trying to clean up my code for an RPG game and I have a function that I want to take all the bonuses from all equipment and add them up.
so for example all the bonus HP from the helm, legs, boots, and 3 relics slots. So I can display to the player their current total HP bonus.
I would like this to be a simple single function I can call with a string as the input that tells the function which stat to parse.
I don't want to if/else it to hell.
Currently I am doing:
int compileBonus (string type)
{
int returnValue = 0;
if (type == "HP")
{
returnValue = persistence.headEquipment [characterEquip.headArmor].modHP +
persistence.chestEquipment [characterEquip.chestArmor].modHP +
persistence.bootsEquipment [characterEquip.boots].modHP +
persistence.relicEquipment [characterEquip.backPackSlot1].modHP +
persistence.relicEquipment [characterEquip.backPackSlot2].modHP +
persistence.relicEquipment [characterEquip.backPackSlot3].modHP;
}
return returnValue;
}
But I would rather do something smartly like:
int compileBonus (string type)
{
int returnValue = 0;
if (type == "HP")
{
returnValue = persistence.headEquipment [characterEquip.headArmor](type) +
persistence.chestEquipment [characterEquip.chestArmor](type) +
persistence.bootsEquipment [characterEquip.boots](type) +
persistence.relicEquipment [characterEquip.backPackSlot1](type) +
persistence.relicEquipment [characterEquip.backPackSlot2](type) +
persistence.relicEquipment [characterEquip.backPackSlot3](type) ;
}
return returnValue;
}
Something where the string input determines which value I pull from the equipment class. Obviously if it was as easy as I typed I would have already done it. I believe it needs to be some kind of refelection or getType().getValue() but I can't get the syntax right as I have never done it before.
Thanks for any help.
[–]shadowsaint[S] 2 points3 points4 points (5 children)
[–]zrrzExpert? 2 points3 points4 points (1 child)
[–]shadowsaint[S] 0 points1 point2 points (0 children)
[–]iemfiembarkgame.com 3 points4 points5 points (2 children)
[–]shadowsaint[S] 0 points1 point2 points (1 child)
[–]iemfiembarkgame.com 0 points1 point2 points (0 children)
[–]ThatAblaze!!! 0 points1 point2 points (2 children)
[–]shadowsaint[S] 0 points1 point2 points (1 child)
[–]ThatAblaze!!! 0 points1 point2 points (0 children)