1. public class Behaviour
  2. {
  3.     Item owner;
  4.  
  5.     public Behaviour()
  6.     {
  7.         // base class, does nothing.
  8.     }
  9.  
  10.     public void Attach(Item item)
  11.     {
  12.         owner = item;
  13.     }
  14. }
  15.  
  16. public class Harvestable : Behaviour()
  17. {
  18.     public Harvestable()
  19.     {
  20.         // This is just a base class so it doesn't do anything?
  21.     }
  22.  
  23.     public virtual void Harvest()
  24.     {
  25.        // maybe log that the class was not set correctly
  26.     }
  27. }
  28.  
  29. public class HarvestReplace : Harvestable
  30. {
  31.     ItemType replaceType;
  32.  
  33.     public HarvestReplace(ItemType replaceWith)
  34.     {
  35.          this.replaceType = replaceWith;
  36.     }
  37.  
  38.     public override void Harvest()
  39.     {
  40.         owner.Remove();
  41.         owner.World.AddItem(replaceType);
  42.     }
  43. }
  44.  
  45. public class ItemType
  46. {
  47.     someVar someProperty;
  48.     List<Behaviour> behaviours;
  49.  
  50.     public ItemType(ushort id)
  51.     {
  52.         // EXAMPLE if it was a tree, in reality there's a load of different types here.
  53.         ItemType tree = new ItemType;
  54.         tree.someProperty = someValue;
  55.         tree.behaviours = new List<Behaviour>();
  56.         tree.behaviours.Add(new HarvestReplace(ItemTypes.Log);
  57.     }
  58. }
  59.  
  60. public class Item
  61. {
  62.     World world;
  63.     someVar someProperty;
  64.     Harvestable harvestable;
  65.  
  66.     public Item(World parent, ItemType type, Vector3 position
  67.     {
  68.         // Get all the basics
  69.         world = parent;
  70.         this.someProperty = type.property;
  71.  
  72.         // now assign behaviours from type
  73.         // Uh this won't actually work with multiple objects as you're assigning an object reference
  74.         // I.e: Create TreeA then TreeB and Harvest TreeA, TreeB will get deleted.
  75.         foreach(Behaviour behaviour in type.behaviours)
  76.         {
  77.             behaviour.Attach(this);
  78.             if(behaviour is Harvestable)
  79.             {
  80.                 this.harvestable = behaviour;
  81.             }
  82.         }
  83.          
  84.     }
  85. }