Exemplo n.º 1
0
 public Worker(WorkersUnion union)
 {
     this.state           = State.Working;
     this.union           = union;
     this.inventory       = new Inventory(5); // TODO: Make inventory size configurable.
     this.targetContainer = null;
 }
Exemplo n.º 2
0
 public ItemEvent(ItemEventType type, SmallItem item) :
     base(EventType.ItemEvent)
 {
     this.itemEventType = type;
     this.largeItem     = null;
     this.smallItem     = item;
 }
Exemplo n.º 3
0
    public LargeItem CreateLargeItem(string type)
    {
        // Look up if we have a custom prototype for this item type. If we do,
        // clone that prototype for our new item.
        LargeItem item;
        LargeItem proto;

        if (largeItemTypes.TryGetValue(type, out proto))
        {
            item = proto.Clone();
        }
        else
        {
            // This type doesn't have it's own prototype, so we'll just use the
            // generic base type instead.
            item = new LargeItem(game, type);
        }

        // Store the item in our database for future lookups and add it to our
        // indexes.
        largeItems.Add(item);
        UpdateIndexes(type, item);

        // And done. Return the item!
        return(item);
    }
Exemplo n.º 4
0
 public TileEvent(TileEventType type, Board.Tile tile) :
     base(EventType.TileEvent)
 {
     this.tileEventType = type;
     this.tile          = tile;
     this.largeItem     = null;
     this.smallItem     = null;
 }
Exemplo n.º 5
0
 public Tile(Board board, TileType type, IntVector2 position)
 {
     this.board      = board;
     this.type       = type;
     this.position   = position;
     this.largeItem  = null;
     this.smallItems = new List <SmallItem>();
 }
Exemplo n.º 6
0
        public void RemoveLargeItem()
        {
            if (HasSmallItems())
            {
                Debug.Log(this + " dropping small items on floor.");
            }
            LargeItem item = this.largeItem;

            this.largeItem = null;
            SendTileEvent(Events.TileEventType.LargeItemRemoved, item);
        }
Exemplo n.º 7
0
 public void SetLargeItem(LargeItem item)
 {
     if (HasLargeItem())
     {
         Debug.LogError(this + " already has a large item.");
         return;
     }
     largeItem     = item;
     item.position = position;
     SendTileEvent(Events.TileEventType.LargeItemAdded, item);
 }
Exemplo n.º 8
0
    private void UpdateCollection(float deltaTime)
    {
        // TODO: Pull inventory component from container.
        Item.Chest chest = targetContainer as Item.Chest;
        foreach (string itemType in GetMissingItemTypes())
        {
            SmallItem item = chest.inventory.GetItemByType(itemType);
            if (item != null)
            {
                // TODO: Remove the item from the target container too.
                // chest.inventory.RemoveItemOfType(itemType);

                // TODO: Figure out better way of handling items than by reference.
                inventory.AddItem(new ItemReference(item));
            }
        }

        // We're done with this container.
        targetContainer = null;
    }
Exemplo n.º 9
0
    public void Update(float deltaTime)
    {
        if (state == State.Idle)
        {
            // TODO: Add non-work jobs like eating, sleeping, or recreation.
            return;
        }

        if (path != null && path.Count > 0)
        {
            // If we have a path to follow, move along it.
            UpdateMovement(deltaTime);
        }
        else if (job == null)
        {
            // If we don't have a job, ask our union to find us one.
            job = union.FindJob(this);
            if (job != null)
            {
                state = HasRequiredItemsForJob() ? State.Working : State.Collecting;
            }
        }
        else if (state == State.Working)
        {
            if (!position.IsNextTo(job.position))
            {
                // If we are working and not next to the job, build a path to
                // the job.
                BuildPathNextTo(job.position);

                if (path == null)
                {
                    // TODO:    Determine if the failure to path was because the
                    //          worker is boxed in or if the job is boxed in.
                    Debug.LogError("Failed to build path to " + job.position);
                    Debug.LogError("Dropping job on the ground and idling.");
                    job   = null;
                    state = State.Idle;
                    return;
                }
            }
            else
            {
                // If we are working and are next to the job, do some work.
                UpdateWork(deltaTime);
            }
        }
        else if (state == State.Collecting)
        {
            if (HasRequiredItemsForJob())
            {
                // If we have all the items we need, change into the working state.
                state           = State.Working;
                targetContainer = null;
                path            = null;
            }
            else if (targetContainer == null)
            {
                // If we are collecting items and we do not have a container to
                // get the item from, find one.
                targetContainer = FindContainerWithJobItems();

                if (targetContainer == null)
                {
                    // TODO:    Queue a job to create the unfound item type(s)
                    //          and requeue our current job.
                    Debug.LogError("Failed to find containers with required items.");
                    Debug.LogError("Dropping job on the ground.");
                    job = null;
                    return;
                }
            }
            else if (!position.IsNextTo(targetContainer.position))
            {
                // If we are collecting items and we know where to get the items
                // but are not next to it, build a path to the container.
                BuildPathNextTo(targetContainer.position);

                if (path == null)
                {
                    // TODO:    Limit container finding to ones we can actually
                    //          get to.
                    Debug.LogError("Failed to find path to " + targetContainer.position);
                    Debug.LogError("Dropping job on the ground.");
                    job             = null;
                    targetContainer = null;
                    return;
                }
            }
            else
            {
                // If we are collecting items and are next to the item source,
                // pick up the items we need.
                UpdateCollection(deltaTime);
            }
        }
    }
Exemplo n.º 10
0
 protected LargeItem(LargeItem other)
 {
     this.game = other.game;
     this.type = other.type;
 }
Exemplo n.º 11
0
 public void SetLargeItemProto(string type, LargeItem proto)
 {
     largeItemTypes.Add(type, proto);
 }
Exemplo n.º 12
0
 public void Destroy(LargeItem item)
 {
     // Only need to remove the item from the main database. The indexes will
     // clean themselves on next access.
     largeItems.Remove(item);
 }
Exemplo n.º 13
0
 private void SendTileEvent(Events.TileEventType eventType, LargeItem item)
 {
     SendTileEvent(new Events.TileEvent(eventType, this, item));
 }