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 internal void CalculatePossiblePath(CharacterTurn ct) { BaseCharacter selectedChar = ct.character; Vector2 temp = new Vector2(-1); if (ct.returnCompleteArea().Find(t => t.mapPosition.Contains(GameProcessor.EditorCursorPos)) != null) { temp = (GameProcessor.EditorCursorPos / 64).ToPoint().ToVector2() * 64; } if (temp != new Vector2(-1)) // if (temp != new Vector2(-1) && !selectedChar.spriteGameSize.Contains(temp)) { List <Node> nodes = new List <Node>(); if (CombatProcessor.zone.Contains(GameProcessor.EditorCursorPos) && !PathMoveHandler.bIsBusy) { nodes = PathFinder.NewPathSearch(selectedChar.position, GameProcessor.EditorCursorPos, ct.returnCompleteArea()); } if (nodes.Count > 2) { for (int i = 0; i < nodes.Count - 1; i++) { Node pn = nodes[i]; Node n = nodes[i + 1]; Node na = nodes.Count > i + 2 ? nodes[i + 2] : null; lai.Add(new arrowInfo(pn, n, na)); } } else if (nodes.Count == 2) { Point pos = selectedChar.positionToMapCoords().ToPoint(); if (pos.X + 1 == nodes[1].coord.X) { lai.Add(new arrowInfo(rightL, new Rectangle((nodes[1].coord.ToVector2() * 64).ToPoint(), new Point(64)))); } else if (pos.X - 1 == nodes[1].coord.X) { lai.Add(new arrowInfo(leftL, new Rectangle((nodes[1].coord.ToVector2() * 64).ToPoint(), new Point(64)))); } else if (pos.Y + 1 == nodes[1].coord.Y) { lai.Add(new arrowInfo(downL, new Rectangle((nodes[1].coord.ToVector2() * 64).ToPoint(), new Point(64)))); } else if (pos.Y - 1 == nodes[1].coord.Y) { lai.Add(new arrowInfo(upL, new Rectangle((nodes[1].coord.ToVector2() * 64).ToPoint(), new Point(64)))); } } } }
public void Update() { var gts = groupTurnSet.Find(g => !g.bIsCompleted); //CombatProcessor.encounterEnemies if (bIsPlayerTurnSet && !EncounterInfo.currentTurn().bPlayerTurnEnemyOverriden&& !BattleGUI.bIsRunning && !bSelectingArea) { if (!KeyboardMouseUtility.AnyButtonsPressed() && Keyboard.GetState().IsKeyDown(Keys.X)) { var temp = EncounterInfo.encounterGroups.FindAll(eg => eg.bIsPlayerTurnSet); foreach (var item in temp) { item.bIsCompleted = true; } } if (EncounterInfo.currentTurn().selectedCharTurn != null && bRegenerateRadius) { RegenerateRadius(); } currentEnemy = null; if (selectedCharTurn != null && !selectedCharTurn.bIsCompleted) { var tempTile = selectedCharTurn.returnCompleteArea().Find(t => t.mapPosition.Contains(GameProcessor.EditorCursorPos)); if (tempTile != null) { if (CombatArrowLayout.bShouldRecheck(tempTile)) { CombatArrowLayout.Start(tempTile, selectedCharTurn); } } else { CombatArrowLayout.bMustDraw = false; CombatArrowLayout.Clear(); } } else { if (CombatArrowLayout.CanClear()) { CombatArrowLayout.Clear(); } } } else if (bIsPlayerTurnSet && BattleGUI.bIsRunning) { } else if (bIsEnemyTurnSet || EncounterInfo.currentTurn().bPlayerTurnEnemyOverriden) { UpdateEnemyLogic(gts); } if (bSelectingArea) { } if (gts == null) { bIsCompleted = true; } if (bIsCompleted && !bPlayerTurnEnemyOverriden && !LUA.LuaExecutionList.DemandOverride() && !PathMoveHandler.bIsBusy && BattleGUI.TurnEffectsList.Find(te => te.bMustShow) == default(ChangeTurnEffect)) { ResetAndChangeGroup(); } }
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; } } }