public void ReGenerateTurn()
 {
     selectedCharTurn.ReGenerateTurn(GameProcessor.loadedMap.possibleTilesGameZone(CombatProcessor.zoneTiles));
 }
        internal void UpdateEnemyLogic(CharacterTurn gts)
        {
            if (!PathMoveHandler.bIsBusy)
            {
                PathMoveHandler.SkipPathMovement();
            }
            if (gts != null && !LUA.LuaExecutionList.DemandOverride() && !PathMoveHandler.bIsBusy && !bTest && BattleGUI.TurnEffectsList.Find(te => te.bMustShow) == null)
            {
                if (bPlayerTurnEnemyOverriden)
                {
                    gts = currentEnemy;
                }

                if (GameProcessor.cameraFollowTarget != gts.character)
                {
                    GameProcessor.cameraFollowTarget = gts.character;
                }

                bTest = true;
                //randomEnemy = GamePlayUtility.Randomize(0, CombatProcessor.heroCharacters.Count - 1);
                selectedCharTurn = null;
                currentEnemy     = gts;
                AIUtility.AIPreCalculate(gts.returnCompleteArea(), gts);
                //AIUtility.Report(AIBehaviour.ProcessBehaviour(currentEnemy.character,AIUtility.possibleAITargets));
                BaseCharacter target = null;
                var           temp   = AIBehaviour.ProcessBehaviour(currentEnemy.character, AIUtility.possibleAITargets);
                if (temp.Count != 0)
                {
                    target = AIUtility.SelectTargetBasedOnBehaviour(temp);
                }

                var playableMap = GameProcessor.loadedMap.possibleTilesGameZoneForEnemy(CombatProcessor.zoneTiles, currentEnemy.character);

                var beep = new KeyValuePair <List <List <BasicTile> >, List <BasicAbility> >();
                if (target != null)
                {
                    // var beep = AIUtility.returnTilesToAttackFrom(CombatProcessor.zoneTiles,gts.character,target);
                    beep = AIUtility.returnTilesToAttackFrom(gts.returnCompleteArea(), playableMap, gts.character, target);

                    while (beep.Key.Count == 0 && beep.Value.Count == 0 && AIUtility.possibleAITargets.Count - 1 > 0)
                    {
                        AIUtility.possibleAITargets.Remove(target);
                        target = AIUtility.SelectTargetBasedOnBehaviour(AIBehaviour.ProcessBehaviour(currentEnemy.character, AIUtility.possibleAITargets));
                        beep   = AIUtility.returnTilesToAttackFrom(playableMap, playableMap, gts.character, target);
                    }
                }

                if (target != null && beep.Key.Count == 0 && beep.Value.Count == 0)
                {
                    target = null;
                }

                gts.ReGenerateTurn(playableMap);

                List <Node> allPossibleNodes;
                if (target != null)
                {
                    //allPossibleNodes = PathFinder.NewPathSearch(gts.character.position, target.position + new Vector2(64, 0), playableMap);
                    var enemyFavor = AIUtility.returnFavoredAttackAndPosition(beep, gts.character, target);
                    if (enemyFavor.Key != null)
                    {
                        allPossibleNodes = PathFinder.NewPathSearch(gts.character.position, enemyFavor.Key.mapPosition.Location.ToVector2(), playableMap);
                    }
                    else
                    {
                        allPossibleNodes = null;
                    }
                    AITarget = target;
                    AIbtba   = enemyFavor;
                }
                else
                {
                    List <int>   amountOfCharsForEachGroup = new List <int>();
                    List <float> percentagesForEachGroup   = new List <float>();
                    int          totalChars = 0;
                    foreach (var item in gts.parentTS.targetGroups)
                    {
                        int tempCount = item.charactersInGroup.FindAll(c => c.IsAlive()).Count;
                        totalChars += tempCount;
                        amountOfCharsForEachGroup.Add(tempCount);
                    }

                    foreach (var item in amountOfCharsForEachGroup)
                    {
                        percentagesForEachGroup.Add(((float)item / (float)totalChars) * 100);
                    }

                    TurnSet targetGroup = null;
                    int     tempIndex   = 0;
                    while (targetGroup == null)
                    {
                        int randomNumber = GamePlayUtility.Randomize(0, 100);
                        if (percentagesForEachGroup[tempIndex] >= randomNumber)
                        {
                            targetGroup = targetGroups[tempIndex];
                        }
                        tempIndex++;
                        if (tempIndex > percentagesForEachGroup.Count)
                        {
                            targetGroup = targetGroups[0];
                        }
                    }

                    BaseCharacter randomCharacter = targetGroup.charactersInGroup.FindAll(c => c.IsAlive())[GamePlayUtility.Randomize(0, targetGroup.charactersInGroup.FindAll(c => c.IsAlive()).Count)];

                    allPossibleNodes = PathFinder.NewPathSearch(gts.character.position, randomCharacter.position + new Vector2(64, 0), playableMap);
                }
                if (allPossibleNodes != null)
                {
                    CombatProcessor.what = new List <Node>(allPossibleNodes);
                    var NodesWithinRange = MapListUtility.findEqualNodesToTileList(allPossibleNodes, gts.returnCompleteArea());
                    PathMoveHandler.Start(gts.character, NodesWithinRange);
                }

                //FinalizeEnemyRound();
            }

            if (gts != null && !PathMoveHandler.bIsBusy && bTest && !GameProcessor.bStartCombatZoom)
            {
                //THIS IS THE VERY LAST LINE BEFORE AN ENEMY HAS IT'S TURN COMPLETED
                if (!AIbtba.Equals(default(KeyValuePair <BasicTile, BasicAbility>)))
                {
                    if ((AIbtba.Key == null || AIbtba.Key.mapPosition.Location.ToVector2() == gts.character.position) && AIbtba.Value.abilityCanHitTargetInRange(gts.character, AITarget) && AIbtba.Value.IsAbilityAvailable(gts.character.trueSTATChart()))
                    {
                        FaceCharacterInCorrectDirection(gts.character, AITarget);

                        GameProcessor.StartBattleSoon(gts.character, AITarget, gts.character.AbilityList().IndexOf(AIbtba.Value));
                        //GameProcessor.StartBattleSoon(gts.character, AITarget, gts.character.AbilityList().IndexOf(gts.character.AbilityList().Find(ba => ba.abilityName.Equals(AIbtba.Value.abilityName))));
                    }
                    else
                    {
                        if (!currentEnemy.character.attackedAsAI)
                        {
                            LastDitchEffortAttack();
                        }
                        else
                        {
                            FinalizeEnemyRound();
                        }
                    }
                }
                else
                {
                    if (!currentEnemy.character.attackedAsAI)
                    {
                        LastDitchEffortAttack();
                    }
                    else
                    {
                        FinalizeEnemyRound();
                    }
                }
                //
            }
            else if (gts == null)
            {
                if (bPlayerTurnEnemyOverriden)
                {
                    bPlayerTurnEnemyOverriden = false;
                }
            }
        }