コード例 #1
0
    public void DoTask()
    {
        Resource.ResourceType nextType = currentTask.GetNextMissing();
        if (nextType == Resource.ResourceType.NULL)
        {
            SetState(State.TRAVELLING_TO_TASK);

            //Debug.Log("Calling GetPath to travel to task");
            if (!SetPath(Path.GetPath(currentTile.GetKVPair(), currentTask.associatedTile.GetKVPair())))
            {
                AbandonTask();
            }
        }
        else
        {
            // Get the next resource
            var kvs = new List <KeyValuePair <int, int> >();
            foreach (TileBase tile in mgr.GetTilesContaining(nextType))
            {
                //Debug.Log(tile);
                kvs.Add(tile.GetKVPair());
            }
            //Debug.Log("Calling GetPath to retrieve resource for task");
            if (SetPath(Path.GetPath(currentTile.GetKVPair(), kvs)))
            {
                TileBase targetTile = mgr.GetTileBase(currentPath.endX, currentPath.endY);
                targetTile.FindResource(nextType).Claim(this);
                SetState(State.RETRIEVING_RESOURCE);
            }
            else
            {
                AbandonTask();
            }
        }
    }