public void Add(CreatureModifier cm) { // recursive call throughout the cain. if (next != null) { next.Add(cm); } else { next = cm; } }
public static void Test() { var goblin = new Creature("Goblin", 2, 2); Console.WriteLine(goblin); var root = new CreatureModifier(goblin); // This modifier stops all other modifiers from executing, // that's why if activated, it should be one of the first // modifiers to execute. // root.Add(new NoBonusesModifier(goblin)); Console.WriteLine("Let's double the goblin's attack"); root.Add(new DoubleAttackModifier(goblin)); Console.WriteLine("Let's increase the goblin's defense"); root.Add(new IncreaseDefenseModifier(goblin)); root.Handle(); Console.WriteLine(goblin); }