Esempio n. 1
0
        public static UnitOrder GenerateIdleOrder()
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.WAIT_FOR_COMMAND;
            tmp.doingOrder  = true;
            return(tmp);
        }
Esempio n. 2
0
        public static UnitOrder GenerateTargetOrder(InteractingComponent newTarget)
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.TARGET;
            tmp.p.AddParameter <InteractingComponent>("Target", newTarget);
            return(tmp);
        }
Esempio n. 3
0
        public static UnitOrder GenerateGetItemOrder(Vector3 basePosition, UnitBaseBehaviourComponent unit, InteractingComponent interactWith)
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.GATHER_ITEMS;
            tmp.p.AddParameter <Vector3>("NextPos", NavMeshPositionGenerator.GetInstance.GenerateCandidatePosition(basePosition, 0.75f, unit, false));
            tmp.p.AddParameter <InteractingComponent>("InteractWith", interactWith);
            return(tmp);
        }
Esempio n. 4
0
        public static UnitOrder GenerateMoveOrder(Vector3 basePosition, UnitBaseBehaviourComponent unit)
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.MOVE_TOWARDS;
            tmp.p.AddParameter <Vector3>("NextPos", NavMeshPositionGenerator.GetInstance.GenerateCandidatePosition(basePosition, 0.75f, unit, false));

            return(tmp);
        }
Esempio n. 5
0
        public static UnitOrder GenerateMoveOrder(Vector3 clickedPosition)
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.MOVE_TOWARDS;
            tmp.p.AddParameter <Vector3>("NextPos", clickedPosition);

            return(tmp);
        }
Esempio n. 6
0
        public static UnitOrder GenerateInteractOrder(InteractingComponent interactWith, ActionType action)
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.INTERACT;
            tmp.p.AddParameter <ActionType>("Action", action);
            tmp.p.AddParameter <InteractingComponent>("InteractWith", interactWith);

            return(tmp);
        }
Esempio n. 7
0
        public static UnitOrder GenerateGatherResourceOrder(InteractingComponent interactWith, ActionType action)
        {
            UnitOrder tmp = new UnitOrder();

            tmp.commandName = Commands.GATHER_RESOURCES;
            tmp.actionType  = ActionType.Gather;
            tmp.p.AddParameter <ActionType>("Action", action);
            tmp.p.AddParameter <InteractingComponent>("InteractWith", interactWith);

            return(tmp);
        }
Esempio n. 8
0
 public void QueueOrder(UnitOrder thisOrder)
 {
     if (unitOrders.Count > 0)
     {
         if (unitOrders.Peek() != thisOrder)
         {
             unitOrders.Enqueue(thisOrder);
         }
     }
     else
     {
         unitOrders.Enqueue(thisOrder);
     }
     if (currentOrder == null)
     {
         currentOrder = unitOrders.Dequeue();
     }
 }
Esempio n. 9
0
 public void AddNewOrder(UnitOrder orderSet)
 {
     unitOrders.Enqueue(orderSet);
 }
Esempio n. 10
0
        public void ReceiveOrder(UnitOrder newOrder, bool forceOrder = true)
        {
            //Debug.Log("receiving order :" + newOrder.commandName.ToString());
            if (!forceOrder)
            {
                //Debug.Log(this.gameObject.name + " Queueing Order : " + newOrder.commandName);
                QueueOrder(newOrder);
            }
            else
            {
                //Debug.Log(this.gameObject.name +  " Forcing New Order : " + newOrder.commandName);
                unitOrders.Clear();
                currentOrder = newOrder;
            }

            currentOrder.doingOrder = true;
            ActionType nextOrder = ActionType.Wait;
            Vector3    nextPos   = transform.position;

            switch (currentOrder.commandName)
            {
            case Commands.INTERACT:
                // TODO
                interactWith = newOrder.p.GetWithKeyParameterValue <InteractingComponent>("InteractWith", null);
                if (interactWith == null)
                {
                    return;
                }
                MakeUnitLookAt(interactWith);

                nextOrder = newOrder.p.GetWithKeyParameterValue <ActionType>("Action", ActionType.Wait);
                // Implement Converse / Pull Lever / Open door shit like that ( for NPCs, since player will use POPUPs).
                break;

            case Commands.MOVE_TOWARDS:
                RemoveCurrentInteraction();
                if (!canMove)
                {
                    return;
                }

                currentCommand = Commands.MOVE_TOWARDS;
                nextPos        = currentOrder.p.GetWithKeyParameterValue <Vector3>("NextPos", transform.position);
                MoveTowards(nextPos);
                break;

            case Commands.WAIT_FOR_COMMAND:
                interactWith   = null;
                currentCommand = Commands.WAIT_FOR_COMMAND;
                MoveTowards(nextPos);
                break;

            case Commands.GATHER_RESOURCES:
                interactWith   = newOrder.p.GetWithKeyParameterValue <InteractingComponent>("InteractWith", null);
                currentCommand = Commands.GATHER_RESOURCES;
                if (interactWith == null)
                {
                    return;
                }
                MakeUnitLookAt(interactWith);

                // Start Sending Damage to the tree
                if (IsInteractionAllowed(ActionType.Gather, interactWith))
                {
                    interactWith.StartInteraction(this, currentOrder.actionType);
                }
                break;

            case Commands.GATHER_ITEMS:
                nextPos        = currentOrder.p.GetWithKeyParameterValue <Vector3>("NextPos", transform.position);
                interactWith   = newOrder.p.GetWithKeyParameterValue <InteractingComponent>("InteractWith", null);
                currentCommand = Commands.GATHER_ITEMS;
                MoveTowards(nextPos);
                MakeUnitLookAt(interactWith);
                break;

            case Commands.TARGET:
                targetUnit = newOrder.p.GetWithKeyParameterValue <InteractingComponent>("Target", null);
                MakeUnitLookAt(targetUnit);
                break;
            }
        }