예제 #1
0
    public Walker(IWalker objectToWalk, float speed)
    {
        this.objectToWalk = objectToWalk;
        this.speed        = speed;

        walkerStatus = WalkerStatus.CollectingBlocks;
    }
예제 #2
0
    private void findNextTarget()
    {
        if (InventoryCalls())
        {
            walkerStatus = WalkerStatus.InventoryCalls;
            return;
        }
        Debug.Log("Finding new target");
        IStructure targetStructure = objectToWalk.getNextTarget();

        Debug.Log("TargetStructure: " + targetStructure);

        if (targetStructure != null && !targetStructure.isDestroyed())
        {
            Debug.Log("TargetStructure: " + targetStructure);
            SetTargetPosition(targetStructure, out bool success);
            if (!success)
            {
                findNextTarget();
            }
        }
        else
        {
            Debug.Log("getNextTarget found no target, sleeping for 1 sec");
            activated = false;
        }
    }
예제 #3
0
    public void DecideNextAction()
    {
        Debug.Log("Deciding next action");
        switch (walkerStatus)
        {
        case WalkerStatus.CollectingBlocks:
        {
            if (objectToWalk.getItemInventory().isFull())
            {
                depositBlocksInSilo();
                return;
            }

            if (targetStructure == null || targetStructure.isDestroyed())
            {
                findNextTarget();
                return;
            }

            if (isStructureCloseEnough(targetStructure))
            {
                Debug.Log("mining");
                objectToWalk.Mine();
                return;
            }
            else
            {
                Debug.Log("not close enough to mine");
            }

            break;
        }

        case WalkerStatus.InventoryCalls:
        {
            IInventory inventory = objectToWalk.getItemInventory();
            Debug.Log("Status: Inventory Call");

            if (activeJobCall == null)
            {
                JobCall jobCall = JobController.Instance.getNextJobCall();

                if (jobCall == null || jobCall.itemToBeDelivered.getAmount() == 0)
                {
                    Debug.Log("Found no Inventory calls");
                    walkerStatus    = WalkerStatus.CollectingBlocks;
                    targetStructure = null;
                    DecideNextAction();
                    return;
                }
                Debug.Log("JobCall: item amount: " + jobCall.itemToBeDelivered.getAmount());
                activeJobCall = jobCall;
                Item itemInInv = inventory.TryGetItem(jobCall.itemToBeDelivered);
                if (itemInInv == null || itemInInv.getAmount() == 0)
                {
                    SetTargetPosition(Silo.Instance, out bool success);
                }
                else
                {
                    SetTargetPosition(activeJobCall.targetStructure, out bool success);
                    if (!success)
                    {
                        targetStructure = null;
                        walkerStatus    = WalkerStatus.CollectingBlocks;
                        DecideNextAction();
                    }
                }
            }

            if (activeJobCall.itemToBeDelivered.getAmount() == 0)
            {
                activeJobCall = null;
                DecideNextAction();
                return;
            }


            Item itemInInvv = inventory.TryGetItem(activeJobCall.itemToBeDelivered);
            if (itemInInvv == null || itemInInvv.getAmount() == 0)
            {
                if (!inventory.isEmpty())
                {
                    depositBlocksInSilo();
                    return;
                }

                TakeItems();
                return;
            }

            DepositItems();
            break;
        }
        }
    }