Hi there
I’ve been trying to create an overview of needed scripts/functions for a battle system and the best way to do them.
Combat units will consists of a unit type and a number, displaying how many there are of the given unit - think heroes of might and magic.
What I can’t figure out is how and where to place the damage dealing/damage taken aspect.
Example 1:
Unit: Swordsman
Health: 100
Damage: 10
Scenario: team 1 (100 swordsmen) vs team 2 (100 swordsmen).
Team 1 attack:
100 x 10 = 1000. Kills 10 swordsmen on team 2.
Team 2 attack:
90 x 10 = 900. Kills 9 swordsmen on team 1.
And so on…
------------
I guess this could be done in multiple ways, but a simple way would seem to be making an attack function in the swordsman script, telling it to deal 10 x count damage to the enemy unit targeted, subtract that amount from enemy total health and have that units script calculate the current number of swordsmen.
That should work right? (or is there a smarter way to do it?)
What I can’t figure out is how to deal with a more advanced units.
Example 2:
Unit: Knight
Health: 150
Damage: 20
Special: Reduce all damage received by 7.
Scenario: team 1 (20 knights) vs team 2 (100 swordsmen).
Team 1 attack:
20 x 20 = 400. Kills 4 swordsmen on team 2.
Team 2 attack:
94 x 10 = 940, but with knight reduction it’s effectively 94 x 3 = 282. Kills 1 knight, and deal 132 to another.
and so on…
------------
How would you guys go about implementing abilities like this?
I can’t figure out what part of the code to implement the damage reduction.
Is the best approach to make an if statement, that check if the opponent have any sort of damage reduction, before dealing damage?
Or is it smarter to code units with damage reduction so that the unit, every time it has it’s health lowered, check how many units attacked it, and reduce the damage?
When talking about the best approach I guess simplicity has to be considered, but also what is best for future implementation of new abilities. I mean if I later on wanted to add a %-based damage reduction, the first approach would require additional scripting to all units.
A third option would be to make some sort of combatdamageManager i guess…
Any of you guys have any good advice or bright ideas on this matter?
Thank you for reading