I know, that the title isn't quite clear, but i don't know how to name it better, therefore i will jump directly to the example.
Given some Unit (npc, bot etc) that has Healh Points(HP) and also Shield Points(SP). The Unit can deal damage as well as can be damaged by other Unit. When one Unit attacks another the damage must be absorbed (some part of that damage should affect the HP, the other SP) For example, Unit has the following stats:
- HP: 100 000
- SP: 100 000
- Damage distribution: 80/20 (80% of the overall damage will affect shields, other 20% will health)
So, let's say Unit received damage about 100 000. After that, the stats should be like this:
- HP: 80 000
- SP: 20 000
The question is: How to implement this kind of distribution?
I've done something that works, but it cannot be the final solution, at least because it's does not take into account the remained difference in case where damage were bigger than Shield Points. E.g after 100 000 HP, 100 000 SP and 200 000 DMG our Unit should ended up with 0 HP and 0 SP. My solution works in different way (i.e wrong), so the HP remains 80 000 but SP 0. Thus 100 000 damage points were not even considered. The calculations that i perform stands for:
damage // overall damage
damage_hp = damage * 0.20 // take 20% of the total damage value
damage_sp = damage * 0.80 // take the rest 80%
hp = hp - damage_hp; // dealing appropriate damage
sp = sp - damage_sp; // same here
To handle the cases described above (when damage_sp has bigger value than sp itself), i use if-statment, but i do believe that there is more regular/rational solution to doing this kind of thing, in more mathematical way or something.
I would appreciate any hints.
Aucun commentaire:
Enregistrer un commentaire