public void FinalizeEnemyRound()
        {
            currentEnemy.character.attackedAsAI = false;
            BattleGUI.End();
            bTest    = false;
            AITarget = null;
            AIbtba   = default(KeyValuePair <BasicTile, BasicAbility>);
            currentEnemy.character.attackedAsAI = false;
            currentEnemy.bIsCompleted           = true;
            //var MaxAP = currentEnemy.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP];
            //BasicTile finalTile = currentEnemy.returnCompleteArea().Find(t => t.mapPosition.Location == PathMoveHandler.finalPos.ToPoint());
            //var expendedAP = currentEnemy.characterArea.IndexOf(currentEnemy.characterArea.Find(area => area.Contains(finalTile))) + 1;
            //currentEnemy.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP] += MaxAP - expendedAP;

            if (currentEnemy.character.bSaveAP || true)
            {
                var       MaxAP      = currentEnemy.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP];
                BasicTile finalTile  = currentEnemy.returnCompleteArea().Find(t => t.mapPosition.Location == PathMoveHandler.finalPos.ToPoint());
                var       expendedAP = currentEnemy.characterArea.IndexOf(currentEnemy.characterArea.Find(area => area.Contains(finalTile))) + 1;
                currentEnemy.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP] += MaxAP - expendedAP;
            }

            if (currentEnemy.character.bAIExecuteDefend)
            {
                BattleGUI.DefendOption(currentEnemy.character, currentEnemy.character);
            }

            //   Console.WriteLine(currentEnemy.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP]);
            BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.postCT, this.toLuaTurnSetInfo());
            TBAGW.EncounterInfo.currentTurn().bPlayerTurnEnemyOverriden = false; //This line must always be after the Execute line

            EncounterInfo.ClearDeathChars();
            EncounterInfo.UpdateAllStats();
        }
        static public void Update(GameTime gt)
        {
            bBattleWon = objective.ObjectiveReached(encounterGroups);
            bIsRunning = bBattleWon;

            if (EncounterObjective.Lost(objective))
            {
                CombatProcessor.bLostBattle = true;
            }


            if (bBattleWon && !CombatProcessor.bAfterBattleScreen)
            {
                CombatProcessor.InitiateVictory();
            }
            else if (!bBattleWon)
            {
                LUA.LuaBScriptEvent.msTime = gt.ElapsedGameTime.Milliseconds;
                if (bGenerateLuaTurnInfo)
                {
                    turnSetInfo          = currentTurn().toLuaTurnSetInfo();
                    bGenerateLuaTurnInfo = false;
                }
                BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.updateEV, turnSetInfo);
                encounterGroups[currentGroupIndex].Update();
            }
        }
        public void FinalizeCharacterRound()
        {
            BattleGUI.End();
            bPlayerMustSelectAction       = false;
            selectedCharTurn.bIsCompleted = true;

            if (selectedCharTurn.character.bSaveAP)
            {
                var       MaxAP      = selectedCharTurn.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP];
                BasicTile finalTile  = selectedCharTurn.returnCompleteArea().Find(t => t.mapPosition.Location == PathMoveHandler.finalPos.ToPoint());
                var       expendedAP = selectedCharTurn.characterArea.IndexOf(selectedCharTurn.characterArea.Find(area => area.Contains(finalTile))) + 1;
                selectedCharTurn.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP] += MaxAP - expendedAP;
            }

            //Console.WriteLine(selectedCharTurn.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP]);
            BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.postCT, this.toLuaTurnSetInfo());
            EncounterInfo.ClearDeathChars();

            selectedCharTurn = null;
            EncounterInfo.UpdateAllStats();
        }
        private void ResetAndChangeGroup()
        {
            bIsCompleted = false;
            foreach (var item in groupTurnSet)
            {
                item.bIsCompleted = false;
            }

            if (bIsPlayerTurnSet)
            {
                BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.postPT, this.toLuaTurnSetInfo());
            }
            else
            {
                BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.postET, this.toLuaTurnSetInfo());
            }


            EncounterInfo.ChangeGroup();

            randomEnemy = GamePlayUtility.Randomize(0, CombatProcessor.heroCharacters.Count - 1);
        }
        public void Start()
        {
            bIsCompleted     = true;
            selectedCharTurn = null;
            GenerateTurns();
            BattleGUI.UpdateGUIElements();

            if (bIsPlayerTurnSet)
            {
                BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.startPT, this.toLuaTurnSetInfo());
            }
            else
            {
                BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.startET, this.toLuaTurnSetInfo());
            }

            PlayerController.previousSelected        = null;
            groupTurnSet.ForEach(gts => gts.stepsSet = 0);
            EncounterInfo.UpdateAllStats();
            selectedCharTurn = null;
            bFirstTurn       = false;
            PlayerController.selectedSprite = null;
        }