void Start()
        {
            abilities        = GetComponent <EnemySpells>().ability;
            safeAbility      = GetComponent <EnemySpells>().safeAbility;
            targets          = FindObjectsOfType <Fighter>();
            mover            = GetComponent <Mover>();
            onRailsMover     = GetComponent <OnRailsMover>();
            cooldown         = GetComponent <CoolDown>();
            channel          = GetComponent <Channel>();
            attackIndicator  = GetComponent <AttackIndicator>();
            attackReceiver   = GetComponent <AttackReceiver>();
            attackExecutor   = GetComponent <AttackExecutor>();
            enemyTarget      = GetComponent <EnemyTarget>();
            spline           = GetComponent <splineMove>();
            stateMachine     = GetComponent <StateMachine>();
            animationHandler = GetComponent <AnimationHandler>();

            allEnemies   = FindObjectsOfType <EnemyTarget>();
            allActors    = FindObjectsOfType <Fighter>();
            allPushables = FindObjectsOfType <Pushable>();

            combatController     = FindObjectOfType <CombatController>();
            cooldown.isOnCD      = true;
            channel.isChanneling = false;
            channel.channel      = 0f;

            //print("allPushables start count: " + allPushables.Length);

            //perform attack once will be used to check if the current attack is in progress
        }
Beispiel #2
0
 void Start()
 {
     mover            = GetComponent <Mover>();
     enemyTarget      = GetComponent <EnemyTarget>();
     combatController = FindObjectOfType <CombatController>();
     spline           = GetComponent <splineMove>();
     savedWing        = GetComponent <EnemyTarget>().wing;
 }
        public bool MeleeTargeting(EnemyTarget target)
        {
            Pushable[] pushables      = FindObjectsOfType <Pushable>();
            Vector2Int targetPosition = target.GetComponent <Mover>().GetGridPos();
            Vector2Int actorPosition  = mover.GetGridPos();

            if (actorPosition.x == targetPosition.x)
            {
                foreach (Pushable pushable in pushables)
                {
                    Vector2Int pushablePosition = pushable.GetComponent <Mover>().GetGridPos();

                    if (pushablePosition.x == actorPosition.x)
                    {
                        if (pushablePosition.y > actorPosition.y && pushablePosition.y < targetPosition.y)
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }

            if (actorPosition.y == targetPosition.y)
            {
                foreach (Pushable pushable in pushables)
                {
                    Vector2Int pushablePosition = pushable.GetComponent <Mover>().GetGridPos();

                    if (pushablePosition.y == actorPosition.y)
                    {
                        if (target.wing == Wing.port)
                        {
                            if (pushablePosition.x < actorPosition.x && pushablePosition.x > targetPosition.x)
                            {
                                return(false);
                            }
                        }

                        if (target.wing == Wing.starboard)
                        {
                            if (pushablePosition.x > actorPosition.x && pushablePosition.x < targetPosition.x)
                            {
                                return(false);
                            }
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
        public void HighlightTargettedCells(EnemyAttack attack, EnemyTarget enemy)
        {
            GetTargetCells(attack, enemy);

            if (!areCellsColored)
            {
                saveCellsToClear = GetTargetCells(attack, enemy);
                ColorCells(attack.attackTarget, saveCellsToClear);
                areCellsColored = true;
            }
        }
 // Start is called before the first frame update
 void Start()
 {
     if (GetComponent <Fighter>() != null)
     {
         fighter = GetComponent <Fighter>();
     }
     if (GetComponent <EnemyTarget>() != null)
     {
         enemyTarget = GetComponent <EnemyTarget>();
     }
 }
Beispiel #6
0
        public bool CheckAttack(EnemyTarget target, int abilityInPosition)
        {
            if (abilities[abilityInPosition].actorTargetingType == ActorTargetingType.melee)
            {
                if (!targetingManager.MeleeTargeting(target))
                {
                    return(false);
                }
            }

            return(true);
        }
        private List <Cell> GetTargetCells(EnemyAttack attack, EnemyTarget enemy)
        {
            switch (attack.targettingClass)
            {
            case TargettingClass.relative:
                return(RelativeTargetting(attack, enemy));

            case TargettingClass.global:
                return(GlobalTargetting(attack, enemy));

            default:
                Debug.LogError("targetting class not assigned properly");
                return(null);
            }
        }
        private List <Cell> RelativeTargetting(EnemyAttack attack, EnemyTarget enemy)
        {
            List <Cell> convertedCells = new List <Cell>();

            for (var i = 0; i < attack.relativeTargetCells.Length; i++)
            {
                var convertedVector = RelativeCoordinateConversion(enemy.wing, enemy.GetComponent <Mover>().GetGridPos(), attack.relativeTargetCells[i]);

                if (combatController.ListOfcells.ContainsKey(convertedVector))
                {
                    convertedCells.Add(combatController.ListOfcells[convertedVector]);
                }
            }

            return(convertedCells);
        }
        private List <Cell> GlobalTargetting(EnemyAttack attack, EnemyTarget enemy)
        {
            List <Cell> convertedCells = new List <Cell>();

            for (var i = 0; i < attack.globalTargetCells.Length; i++)
            {
                var currentVector = attack.globalTargetCells[i];

                if (combatController.ListOfcells.ContainsKey(currentVector))
                {
                    convertedCells.Add(combatController.ListOfcells[currentVector]);
                }
            }

            return(convertedCells);
        }
Beispiel #10
0
        // Start is called before the first frame update
        void Start()
        {
            if (GetComponent <Fighter>() != null)
            {
                fighter = GetComponent <Fighter>();
                ResetStats(true);
            }

            if (GetComponent <EnemyTarget>() != null)
            {
                enemyTarget = GetComponent <EnemyTarget>();
                ResetStats(true);
            }

            animationHandler = GetComponent <AnimationHandler>();
        }
Beispiel #11
0
        public List <Pushable> MakeListOfPushablesRelative(EnemyAttack ability, EnemyTarget enemyTarget)
        {
            Pushable[]      pushableArray   = FindObjectsOfType <Pushable>();
            List <Pushable> listOfPushables = new List <Pushable>(pushableArray);
            List <Pushable> deleteMeList    = new List <Pushable>();
            Mover           mover           = enemyTarget.GetComponent <Mover>();

            if (enemyTarget.wing == Wing.port || enemyTarget.wing == Wing.starboard)
            {
                listOfPushables.Sort(SortByX);
            }
            else
            {
                listOfPushables.Sort(SortByY);
                listOfPushables.Reverse();
            }


            if (enemyTarget.wing == Wing.starboard)
            {
                listOfPushables.Reverse();
            }

            bool       deleteRest = false;
            Vector2Int interferenceCheck;


            foreach (Pushable pushable in listOfPushables)
            {
                if (enemyTarget.wing == Wing.port)
                {
                    if (ability.push == Push.north)
                    {
                        interferenceCheck = new Vector2Int(pushable.GetGridPos().x + 1, pushable.GetGridPos().y);
                    }
                    else
                    {
                        interferenceCheck = new Vector2Int(pushable.GetGridPos().x - 1, pushable.GetGridPos().y);
                    }
                }

                else if (enemyTarget.wing == Wing.starboard)
                {
                    if (ability.push == Push.north)
                    {
                        interferenceCheck = new Vector2Int(pushable.GetGridPos().x - 1, pushable.GetGridPos().y);
                    }
                    else
                    {
                        interferenceCheck = new Vector2Int(pushable.GetGridPos().x + 1, pushable.GetGridPos().y);
                    }
                }
                else
                {
                    if (ability.push == Push.north)
                    {
                        interferenceCheck = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - 1);
                    }
                    else
                    {
                        interferenceCheck = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + 1);
                    }
                }

                if ((enemyTarget.wing == Wing.starboard) || (enemyTarget.wing == Wing.port))
                {
                    if (pushable.GetGridPos().y != mover.GetGridPos().y)
                    {
                        deleteMeList.Add(pushable);
                        continue;
                    }
                }
                else
                {
                    if (pushable.GetGridPos().x != mover.GetGridPos().x)
                    {
                        deleteMeList.Add(pushable);
                        continue;
                    }
                }

                if (pushable.GetComponent <Obstacle>() != null)
                {
                    deleteMeList.Add(pushable);
                    deleteRest = true;
                }

                if (combatController.ListOfcells.ContainsKey(interferenceCheck))
                {
                    if (combatController.ListOfcells[interferenceCheck].isOccupied)
                    {
                        Obstacle[] obstacles = FindObjectsOfType <Obstacle>();
                        foreach (Obstacle obstacle in obstacles)
                        {
                            if (obstacle.GetComponent <Pushable>().GetGridPos() == interferenceCheck)
                            {
                                deleteMeList.Add(pushable);
                                break;
                            }
                        }
                    }

                    if (combatController.ListOfcells[interferenceCheck].isEnemyCell)
                    {
                        deleteMeList.Add(pushable);
                    }

                    if (combatController.ListOfcells[interferenceCheck] == null)
                    {
                        deleteMeList.Add(pushable);
                    }
                }

                if (deleteRest == true)
                {
                    deleteMeList.Add(pushable);
                }
            }

            foreach (Pushable pushable in deleteMeList)
            {
                listOfPushables.Remove(pushable);
            }

            if (ability.push == Push.north)
            {
                listOfPushables.Reverse();
            }

            return(listOfPushables);
        }
        //translates from global coordinates to relative coordinates
        private Vector2Int[] TranslateRelativeTargetCells(Vector2Int[] relativeTargetCells, EnemyTarget enemy)
        {
            Vector2Int[] convertedVector = new Vector2Int[relativeTargetCells.Length];
            int          enemyX          = enemy.GetComponent <Mover>().GetGridPos().x;
            int          enemyY          = enemy.GetComponent <Mover>().GetGridPos().y;


            for (var i = 0; i < relativeTargetCells.Length; i++)
            {
                switch (enemy.wing)
                {
                case Wing.port:
                    convertedVector[i] = new Vector2Int(enemyX + relativeTargetCells[i].x, enemyY + relativeTargetCells[i].y);
                    //print(this.name + " is adding cell to target: " + convertedVector[i]);
                    break;

                case Wing.starboard:
                    convertedVector[i] = new Vector2Int(enemyX - relativeTargetCells[i].x, enemyY + relativeTargetCells[i].y);
                    //print(this.name + " is adding cell to target: " + convertedVector[i]);
                    break;

                case Wing.bow:
                    convertedVector[i] = new Vector2Int(enemyX - relativeTargetCells[i].y, enemyY - relativeTargetCells[i].x);
                    //print(this.name + " is adding cell to target: " + convertedVector[i]);
                    break;

                default:
                    convertedVector[i] = new Vector2Int(0, 0);
                    //Debug.LogError("enemy wing is not defined.");
                    break;
                }
            }

            return(convertedVector);
        }
        //switch (stateMachine.state)
        //{

        //    //PlayerState
        //    case State.channeling:
        //        channel.CheckChannel();
        //        Targetting(selectedAbility);
        //        if (!channel.isChanneling)
        //        {
        //            state = State.animating;
        //        }
        //        break;

        //    //PlayerState
        //    case State.animating:

        //        print(attackInProgress);

        //        if (!attackInProgress)
        //        {
        //            AIController[] enemies = FindObjectsOfType<AIController>();
        //            foreach(AIController enemy in enemies)
        //            {
        //                if (enemy.attackInProgress == true && enemy.gameObject!= this.gameObject)
        //                {
        //                    return;
        //                }
        //            }
        //            attackInProgress = true;
        //            PerformAttack(selectedAbility);
        //        }

        //foreach (Cell cell in attackIndicator.convertedCells)
        //{
        //    cell.enemyHighlight = false;
        //    attackIndicator.areCellsColored = false;
        //    cell.DoDefaultColor();
        //    enemyTarget.SaveMaterial();
        //    enemyTarget.DoDefaultMaterial();
        //}
        //            break;
        //    }
        //}


        /* GOALS WITHIN THIS CODE
         * 1. Segment out a combat controller utilized public method pool. This pool will handle calculations that are universal such as zodiac and magic interactions
         * 2. AIController should handle the decisions of the AI. Namely, seeing which abilities are available to it. Checking to see which ones are best. and picking between them.
         * 3. An Attack Executor (should be shared with FIGHTER class) Class should handle distributing damage and effects. It will use the singleton, Combat Controller, to access universal algorithms in calculating damage.
         * 4. Animation needs to be accounted for with a separate timer. The timer will tick normally when not moving or pushing else it will wait for moving or pushing to complete then issue the same "END OF ANIMATION" method.
         * 5. AIController should resemble a player brain. Any limitations of the enemy class not related to decision making should be relegated to another class.
         * 6. NEW CLASSES: CC.AttackAlgorithms, AnimationTimer, AttackExecutor, AttackReceiver, PlayerState
         */


        //Pre targeting for relative global and support targeting
        //dont think this needed.

        private List <AttackReceiver> GetTargets(EnemyAttack ability, EnemyTarget enemy)
        {
            allPushables = FindObjectsOfType <Pushable>();
            List <AttackReceiver> newTargets           = new List <AttackReceiver>();
            List <Pushable>       translatedTargetList = new List <Pushable>();

            switch (ability.targettingClass)
            {
            case TargettingClass.global:

                foreach (Pushable pushable in allPushables)
                {
                    foreach (Vector2Int position in ability.globalTargetCells)
                    {
                        if (pushable.GetComponent <Mover>().GetGridPos() == position)
                        {
                            translatedTargetList.Add(pushable);
                        }
                    }
                }

                //remove targets based on beeline targeting
                if (ability.attackTarget == AttackTarget.beeline)
                {
                    switch (enemyTarget.wing)
                    {
                    case Wing.bow:
                        translatedTargetList.Sort(SortByY);
                        translatedTargetList.Reverse();
                        break;

                    case Wing.port:
                        translatedTargetList.Sort(SortByX);
                        break;

                    case Wing.starboard:
                        translatedTargetList.Sort(SortByX);
                        translatedTargetList.Reverse();
                        break;

                    default:
                        print("NO WING DEFINED");
                        break;
                    }
                }

                //final list
                foreach (Pushable pushable in translatedTargetList)
                {
                    if (pushable.GetComponent <AttackReceiver>() != null)
                    {
                        newTargets.Add(pushable.GetComponent <AttackReceiver>());
                    }

                    if (ability.attackTarget == AttackTarget.beeline)
                    {
                        break;
                    }
                }


                break;

            case TargettingClass.relative:

                Vector2Int[] translatedTargetCells = TranslateRelativeTargetCells(ability.relativeTargetCells, enemy);

                //print("allPushables count: " + allPushables.Length);

                foreach (Pushable pushable in allPushables)
                {
                    foreach (Vector2Int position in translatedTargetCells)
                    {
                        if (pushable.GetComponent <Mover>().GetGridPos() == position)
                        {
                            translatedTargetList.Add(pushable);
                            //print("adding pushable");
                        }
                    }
                }

                //print("translatedTargetCells: " + translatedTargetList.Count);

                //remove targets based on beeline targeting
                if (ability.attackTarget == AttackTarget.beeline)
                {
                    switch (enemyTarget.wing)
                    {
                    case Wing.bow:
                        translatedTargetList.Sort(SortByY);
                        translatedTargetList.Reverse();
                        break;

                    case Wing.port:
                        translatedTargetList.Sort(SortByX);
                        break;

                    case Wing.starboard:
                        translatedTargetList.Sort(SortByX);
                        translatedTargetList.Reverse();
                        break;

                    default:
                        print("NO WING DEFINED");
                        break;
                    }
                }

                //final list
                foreach (Pushable pushable in translatedTargetList)
                {
                    if (pushable.GetComponent <AttackReceiver>() != null)
                    {
                        newTargets.Add(pushable.GetComponent <AttackReceiver>());
                    }

                    if (pushable.GetComponent <Destroyable>() != null)
                    {
                        pushable.GetComponent <Destroyable>().DestroySelf();
                    }

                    if (ability.attackTarget == AttackTarget.beeline)
                    {
                        break;
                    }
                }

                break;

            case TargettingClass.support:

                EnemyTarget randomEnemy = SelectRandomSupportTarget();

                newTargets.Add(randomEnemy.GetComponent <AttackReceiver>());
                break;

            case TargettingClass.self:

                newTargets.Add(attackReceiver);
                break;

            //this case inherits "melee Target" from the TestAbility method. This is to reduce redundancy in finding available targets.
            case TargettingClass.melee:

                if (meleeTarget == null)
                {
                    print("no melee targets, ATTACK FILTERING ERROR");
                }

                newTargets.Add(meleeTarget.GetComponent <AttackReceiver>());

                break;

            case TargettingClass.homing:

                Fighter randomActor = SelectRandomHomingTarget();

                if (randomActor != null)
                {
                    newTargets.Add(randomActor.GetComponent <AttackReceiver>());
                }

                break;

            case TargettingClass.allAllies:

                foreach (Fighter fighter in allActors)
                {
                    if (!fighter.isDead)
                    {
                        if (!fighter.isIntangible)
                        {
                            newTargets.Add(fighter.GetComponent <AttackReceiver>());
                        }
                    }
                }

                break;

            case TargettingClass.allFoes:

                foreach (EnemyTarget target in allEnemies)
                {
                    newTargets.Add(target.GetComponent <AttackReceiver>());
                }

                break;

            default:
                print("no valid targeting class error.");
                break;
            }

            return(newTargets);
        }