Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Behaviour
- {
- Item owner;
- public Behaviour()
- {
- // base class, does nothing.
- }
- public void Attach(Item item)
- {
- owner = item;
- }
- }
- public class Harvestable : Behaviour()
- {
- public Harvestable()
- {
- // This is just a base class so it doesn't do anything?
- }
- public virtual void Harvest()
- {
- // maybe log that the class was not set correctly
- }
- }
- public class HarvestReplace : Harvestable
- {
- ItemType replaceType;
- public HarvestReplace(ItemType replaceWith)
- {
- this.replaceType = replaceWith;
- }
- public override void Harvest()
- {
- owner.Remove();
- owner.World.AddItem(replaceType);
- }
- }
- public class ItemType
- {
- someVar someProperty;
- List<Behaviour> behaviours;
- public ItemType(ushort id)
- {
- // EXAMPLE if it was a tree, in reality there's a load of different types here.
- ItemType tree = new ItemType;
- tree.someProperty = someValue;
- tree.behaviours = new List<Behaviour>();
- tree.behaviours.Add(new HarvestReplace(ItemTypes.Log);
- }
- }
- public class Item
- {
- World world;
- someVar someProperty;
- Harvestable harvestable;
- public Item(World parent, ItemType type, Vector3 position
- {
- // Get all the basics
- world = parent;
- this.someProperty = type.property;
- // now assign behaviours from type
- // Uh this won't actually work with multiple objects as you're assigning an object reference
- // I.e: Create TreeA then TreeB and Harvest TreeA, TreeB will get deleted.
- foreach(Behaviour behaviour in type.behaviours)
- {
- behaviour.Attach(this);
- if(behaviour is Harvestable)
- {
- this.harvestable = behaviour;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement