I'm working on the inventory system for my game, and am interested in how do I implement additional weapon and armor properties that are not just damage or armor?
If all I have is damage and armor, the equation is simple: damage = weapon damage - armor;
But I'm looking for a more interesting user experience - namely items that have 2-3 properties that modify various game mechanics.
For example, I can use a bunch of flags and write a big if/else statement in my attack method and check for all these at appropriate points:
if (weapon is vampiric) { heal attacker for x }
if(weapon is holy) { check defender type, add extra damage }
if(armor absorbs first x damage) { reduce damage to defender by x }
Another way that I thought might be better is the decorator design pattern - progressively wrapping the output of one weapon creation into another :
public class Main {
public static final void main(String[] args) {
Weapon w = new MeleeWeapon();
w = new Holy(w);
w = new Vampiric;
w = new Enchanted(w,1);
Damage damage = w.damage();
}
}
It seems to me that decorator would allow me to write more flexible code and add more types later, but I'm not sure if it will just move the if/else statements into the weapons special property method.