Hi there,
im currently thinking about a flexible damage system and unfortunately im stuck at a certain point.
We have several different objects, that will be modeled as such:
- Weapons, that provide “damage sets” consisting of one or several damagetypes
- Damage types, that represent some kind of real damage. This could be anything, from physical damage to magic stuff like paralysis
- Armor: They have a set of filter objects that flter applied damage
- Damagefilter: A object that can modify a specific damagetype.
If damage should be inflicted to some object, the damage set is retrieved from the weapon. this set is then passed to the filterset provided by the armor, which will modify each damage type trough a interface which is common for all damagetypes. After that, each damagetype will be apply()-ed with the target object as parameter.
The apply() method of the damagetype implements modifying a target object through a interface, like “damageable” wich deals with physical damage. Other damage types may use different interfaces like “movable”.
And this is the point where im stuck; because the target object will be not only a “unit” object that implements all that interfaces.
Say, for example, a unit is attacking some wall.
The used weapon has physical damage and paralization.
Let me explain that with some basic pseudocode:
(interface damagetype is cut out, it provides methods to the filter objects. That works i think.)
class PhysicalDamage implements damagetype{
// implementing the apply() method from damagetype
function apply(object) {
object.removeHealth(10); // remove 10 HP; this is a method provided by the "damageable" interface
}
}
class ParalizerDamage implements damagetype{
// implementing the apply() method from damagetype
function apply(object) {
object.slowDown(5); // slow down target; provided by the "movable" interface
}
}
class TestWeapon {
function getDamageSet() {
return new Array(new ParalizerDamage(), new PhysicalDamage());
}
}
So, like you see, apply() misses some technique to see, if it can apply its damage to the target object. However, it cannot know which objects will be passed in, so i need some generic way to test if damage an be applied.
And exactly that is the point, which i cannot solve. How to do that in a generic, object oriented way that may be extended in the future?
As a side note, it is okay if the DamageType would silently do nothing if the target object cant be modified by it because the damaga does not apply (wall cant move anyway).
I thougt about using handlers, but dont know if this is the best way to do that. In this idea, i wanted apply() to fetch a suitable handler from the target object, which then handles the damagetype; but i wanted the DamageType to contain the damage-apply code, not some handler.