Exemplo n.º 1
0
        //attack the assigned target.
        void AttackTarget()
        {
            //making sure that the NPC faction in an attack in progress and that there's a valid target:
            if (currentTarget == null || isAttacking == false)
            {
                return;
            }

            MovementManager.AttackModes attackMode = MovementManager.AttackModes.none;

            Building targetBuilding = currentTarget.Type == EntityTypes.building ? (Building)currentTarget : null; //is this target a building?

            //if the current target is a building and it is being constructed:
            if (targetBuilding != null && targetBuilding.WorkerMgr.currWorkers > 0)
            {
                Unit[] workersList = targetBuilding.WorkerMgr.GetAll(); //get all workers in the worker manager
                //attack the workers first: go through the workers positions
                for (int i = 0; i < workersList.Length; i++)
                {
                    //find worker:
                    if (workersList[i] != null && workersList[i].BuilderComp.IsInProgress() == true)
                    {
                        //assign it as target.
                        currentTarget = workersList[i];
                        //force attack units to attack it:
                        attackMode = MovementManager.AttackModes.change;
                    }
                }
            }

            //launch the actual attack:
            gameMgr.MvtMgr.LaunchAttack(currentAttackUnits, currentTarget, currentTarget.GetSelection().transform.position, attackMode, false);
        }
        /// <summary>
        /// Orders the NPC faction to engage its currently set target.
        /// </summary>
        public void EngageCurrentTarget()
        {
            if (!IsAttacking || //not actively attacking?
                currentTarget == null || //has a current target?
                targetFaction == null || //no target faction assigned?
                gameMgr.InPeaceTime() || //or still in peace time?
                currentAttackUnits.Count == 0)    //or no more attack units?
            {
                return;
            }

            MovementManager.AttackModes attackMode = MovementManager.AttackModes.none;

            //if the current target is a building and it is being constructed:
            if (currentTarget.Type == EntityTypes.building && (currentTarget as Building).WorkerMgr.currWorkers > 0)
            {
                Unit[] workersList = (currentTarget as Building).WorkerMgr.GetAll(); //get all workers in the worker manager
                //attack the workers first: go through the workers positions
                for (int i = 0; i < workersList.Length; i++)
                {
                    //find worker:
                    if (workersList[i] != null && workersList[i].BuilderComp.IsInProgress() == true)
                    {
                        //assign it as target.
                        currentTarget = workersList[i];
                        //force attack units to attack it:
                        attackMode = MovementManager.AttackModes.change;
                    }
                }
            }

            //launch the actual attack:
            gameMgr.MvtMgr.LaunchAttack(
                //if only idle units can be sent to attack, make sure this is the case.
                sendOnlyIdle ? currentAttackUnits.Where(unit => unit.IsIdle()).ToList() : currentAttackUnits
                , currentTarget, currentTarget.GetSelection().transform.position, attackMode, false);
        }
Exemplo n.º 3
0
        //attack the assigned target building.
        void AttackTargetBuilding()
        {
            //making sure that the NPC faction in an attack in progress and that there's a valid target building:
            if (currentTargetBuilding == null || isAttacking == false)
            {
                return;
            }

            GameObject target = currentTargetBuilding.gameObject;

            MovementManager.AttackModes attackMode = MovementManager.AttackModes.None;

            //if the current target building is being constructed:
            if (currentTargetBuilding.WorkerMgr.CurrentWorkers > 0)
            {
                //attack the workers first: go through the workers positions
                for (int i = 0; i < currentTargetBuilding.WorkerMgr.WorkerPositions.Length; i++)
                {
                    //find worker:
                    if (currentTargetBuilding.WorkerMgr.WorkerPositions[i].CurrentUnit != null)
                    {
                        //is the worker actually at the building constructing it:
                        if (currentTargetBuilding.WorkerMgr.WorkerPositions[i].CurrentUnit.BuilderMgr.IsBuilding == true)
                        {
                            //assign it as target.
                            target = currentTargetBuilding.WorkerMgr.WorkerPositions[i].CurrentUnit.gameObject;
                            //force attack units to attack it:
                            attackMode = MovementManager.AttackModes.Change;
                        }
                    }
                }
            }

            //launch the actual attack:
            mvtMgr.LaunchAttack(currentAttackUnits, target, attackMode);
        }