public class World
{
List<Item> _Items;
public World()
{
// assign all the stuff, blah blahy
_Items = new List<Item>;
}
public AddItem(Item item)
{
_Items.Add(item);
}
public RemoveItem(Item item)
{
_Items.Remove(item);
}
}
public class ItemActions
{
public List<Action<Item>> _actions;
public ItemActions()
{
_actions = new List<Action<Item>>();
}
public void AddAction(Action<Item> action)
{
_actions.Add(action);
}
public void ApplyAll(Item item)
{
foreach(Action action in _actions)
{
action(item);
}
}
}
public class ItemType
{
// boring properties and more
ItemActions onHarvest;
public ItemType()
{
tree.properties = yada;
tree.onHarvest = new List<Action>();
tree.onHarvest.AddAction(delegate(Item i) { i.Parent.AddItem(new Item(Parent, ItemTypes.Log)); };
tree.onHarvest.AddAction(delegate(Item i) { i.Remove(); };
}
}
public class Item
{
World Parent;
public Item(World parent, ItemType itemtype)
{
Parent = parent;
// assign properties from type, boring stuff.
this.stuff = itemtype.stuff
}
public void Remove()
{
Parent.RemoveItem(this);
}
}
public class ItemHarvestable : Item
{
ItemActions OnHarvest;
public ItemHarvestable(World parent, ItemType itemtype) : base(parent, itemtype)
{
OnHarvest = itemtype.onHarvest;
}
public void Harvest()
{
OnHarvest.ApplyAll(this);
}
}