예제 #1
0
    public IEnumerator storeFood()
    {
        if (toCarry.GetType().IsSubclassOf(typeof(Foods)))
        {
            //Debug.Log("Storing food");
            FoodStorage sRoom  = null;
            NavNode     target = null;
            for (int i = 0; i < NavGraph.rooms.Count; i++)
            {
                if (NavGraph.rooms[i].specialization == null)
                {
                    continue;
                }
                if (NavGraph.rooms[i].specialization.GetType() == typeof(FoodStorage))
                {
                    NavNode spot = ((FoodStorage)NavGraph.rooms[i].specialization).demandFreeSpot();
                    Debug.Log("spot " + spot);
                    if (spot != null)
                    {
                        sRoom  = (FoodStorage)NavGraph.rooms[i].specialization;
                        target = spot;
                        // Debug.Log("targeting");
                    }
                }
            }
            if (target == null)
            {
                //Debug.Log("No Target");
                lookForJob = true;
                World.w.workers.Add(this);
                yield break;
            }
            Debug.Log("moving " + toCarry + " to " + target.position);
            path = PathFind.getPath(World.w.GetBlockNegCoor(position).navNode, target);
            startWalking();
            while (Vector2.Distance(position, target.position) > .2f)
            {
                yield return(null);
            }
            sRoom.addFood(new StorageElement((Foods)toCarry, target.position));
        }
        else
        {
            //Debug.Log("Storing item");

            ResourcesStorage sRoom  = null;
            NavNode          target = null;
            for (int i = 0; i < NavGraph.rooms.Count; i++)
            {
                if (NavGraph.rooms[i].specialization == null)
                {
                    continue;
                }
                if (NavGraph.rooms[i].specialization.GetType() == typeof(ResourcesStorage))
                {
                    NavNode spot = ((ResourcesStorage)NavGraph.rooms[i].specialization).demandFreeSpot();
                    if (spot != null)
                    {
                        sRoom  = (ResourcesStorage)NavGraph.rooms[i].specialization;
                        target = spot;
                    }
                }
            }
            if (target == null)
            {
                lookForJob = true;
                World.w.workers.Add(this);
                yield break;
            }
            Debug.Log("moving " + toCarry + " to " + target.position);

            path = PathFind.getPath(World.w.GetBlock(position).navNode, target);
            startWalking();
            while (Vector2.Distance(position, target.position) > .2f)
            {
                yield return(null);
            }
            sRoom.addResource(new ResourcesElement((Resource)toCarry, target.position));
        }
        lookForJob = true;
        World.w.workers.Add(this);
        toCarry = null;
        anime.SetInteger("toCarryID", 0);
        anime.SetInteger("Direction", anime.GetInteger("Direction") - 4);
        yield return(null);
    }