Exemplo n.º 1
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;
        }
    }
Exemplo n.º 2
0
    private bool isStructureCloseEnough(IStructure structure)
    {
        if (structure == null || structure.isDestroyed())
        {
            return(false);
        }
        bool closeEnough = false;

        foreach (var pathNode in structure.getPathNodeList())
        {
            //Debug.Log("Distance: " + Vector2.Distance(transform.position, pathNode.getPos()));
            if (Vector2.Distance(transform.position, pathNode.getPos()) <= 1.1f)
            {
                closeEnough = true;
            }
        }

        return(closeEnough);
    }
Exemplo n.º 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;
        }
        }
    }