private List <LevelUpMenu> FinalizeBattle(Squad Attacker, int AttackerPlayerIndex, Squad Defender, int DefenderPlayerIndex, SquadBattleResult Result, List <Unit> ListDeadDefender) { List <LevelUpMenu> ListBattleRecap = new List <LevelUpMenu>(); for (int U = 0; U < Attacker.UnitsAliveInSquad; U++) { LevelUpMenu BattleRecap = FinalizeBattle(Attacker[U], Attacker, AttackerPlayerIndex, Result.ArrayResult[U].Target, Defender, DefenderPlayerIndex, Result.ArrayResult[U], ListDeadDefender); if (BattleRecap != null) { ListBattleRecap.Add(BattleRecap); } } if (!Attacker.ListAttackedTeam.Contains(ListPlayer[DefenderPlayerIndex].Team)) { Attacker.ListAttackedTeam.Add(ListPlayer[DefenderPlayerIndex].Team); } if (!Defender.ListAttackedTeam.Contains(ListPlayer[AttackerPlayerIndex].Team)) { Defender.ListAttackedTeam.Add(ListPlayer[AttackerPlayerIndex].Team); } return(ListBattleRecap); }
public void CreateAnimation(string AnimationName, DeathmatchMap Map, Squad ActiveSquad, Squad EnemySquad, Attack ActiveAttack, SquadBattleResult BattleResult, AnimationScreen.AnimationUnitStats UnitStats, AnimationBackground ActiveTerrain, string ExtraText, bool IsLeftAttacking) { AnimationScreen NewAnimationScreen = new AnimationScreen(AnimationName, Map, ActiveSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveTerrain, ExtraText, IsLeftAttacking); ListNextAnimationScreen.Add(NewAnimationScreen); }
public void UpdateUnitDisplay() { if (UnitDisplayCounter < TimeToDisplay) { ++UnitDisplayCounter; if (UnitDisplayCounter == TimeToDisplay) { UnitDisplayCounter = 0; int SquadIndex = -1; for (int P = 0; P < Map.ListPlayer.Count && SquadIndex == -1; P++) { SquadIndex = Map.CheckForSquadAtPosition(P, Map.CursorPosition, Vector3.Zero); if (SquadIndex >= 0) { if (P == Map.ActivePlayerIndex) { BoxColor = Color.Green; } else { BoxColor = Color.Red; } Squad DefendingSquad = Map.ListPlayer[P].ListSquad[SquadIndex]; Map.TargetPlayerIndex = P; Map.TargetSquadIndex = SquadIndex; if (ActiveAttack != null) { SupportSquadHolder ActiveSquadSupport = new SupportSquadHolder(); SupportSquadHolder TargetSquadSupport = new SupportSquadHolder(); ActiveSquadSupport.PrepareAttackSupport(Map, PlayerIndex, ActiveSquad, P, SquadIndex); TargetSquadSupport.PrepareDefenceSupport(Map, P, DefendingSquad); BattleResult = Map.CalculateFinalHP(ActiveSquad, ActiveSquadSupport.ActiveSquadSupport, Map.ActivePlayerIndex, FormationChoices.Focused, DefendingSquad, TargetSquadSupport.ActiveSquadSupport, P, SquadIndex, true, false); } else { BattleResult.ArrayResult = new BattleResult[DefendingSquad.UnitsAliveInSquad]; for (int U = 0; U < DefendingSquad.UnitsAliveInSquad; ++U) { BattleResult.ArrayResult[U] = new BattleResult(); BattleResult.ArrayResult[U].SetTarget(P, SquadIndex, U, DefendingSquad[U]); } } } } } } }
public EndBattleAnimationScreen(DeathmatchMap Map, Squad Attacker, SupportSquadHolder ActiveSquadSupport, int AttackerPlayerIndex, Squad TargetSquad, SupportSquadHolder TargetSquadSupport, int DefenderPlayerIndex, SquadBattleResult ResultAttack, SquadBattleResult ResultDefend) { this.Map = Map; this.Attacker = Attacker; this.ActiveSquadSupport = ActiveSquadSupport; this.AttackerPlayerIndex = AttackerPlayerIndex; this.TargetSquad = TargetSquad; this.TargetSquadSupport = TargetSquadSupport; this.DefenderPlayerIndex = DefenderPlayerIndex; this.ResultAttack = ResultAttack; this.ResultDefend = ResultDefend; }
public void CreateAnimation(AnimationInfo Info, DeathmatchMap Map, Squad ActiveSquad, Squad EnemySquad, Attack ActiveAttack, SquadBattleResult BattleResult, AnimationScreen.AnimationUnitStats UnitStats, AnimationBackground ActiveTerrain, string ExtraText, bool IsLeftAttacking) { AnimationScreen NewAnimationScreen = new AnimationScreen(Info.AnimationName, Map, ActiveSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveTerrain, ExtraText, IsLeftAttacking); NewAnimationScreen.Load(); NewAnimationScreen.UpdateKeyFrame(0); Dictionary <int, Timeline> DicExtraTimeline = Info.GetExtraTimelines(NewAnimationScreen); foreach (KeyValuePair <int, Timeline> ActiveExtraTimeline in DicExtraTimeline) { NewAnimationScreen.ListAnimationLayer[0].AddTimelineEvent(ActiveExtraTimeline.Key, ActiveExtraTimeline.Value); } ListNextAnimationScreen.Add(NewAnimationScreen); }
private void FinalizeBattle(Squad Attacker, int AttackerPlayerIndex, Squad Defender, int DefenderPlayerIndex, SquadBattleResult Result, List <Unit> ListDeadDefender) { for (int U = 0; U < Attacker.UnitsAliveInSquad; U++) { FinalizeBattle(Attacker[U], Attacker, AttackerPlayerIndex, Result.ArrayResult[U].Target, Defender, DefenderPlayerIndex, Result.ArrayResult[U], ListDeadDefender); } if (!Attacker.ListAttackedTeam.Contains(ListPlayer[DefenderPlayerIndex].Team)) { Attacker.ListAttackedTeam.Add(ListPlayer[DefenderPlayerIndex].Team); } if (!Defender.ListAttackedTeam.Contains(ListPlayer[AttackerPlayerIndex].Team)) { Defender.ListAttackedTeam.Add(ListPlayer[AttackerPlayerIndex].Team); } }
public void GenerateNextAnimationScreens(Squad ActiveSquad, SupportSquadHolder ActiveSquadSupport, Squad TargetSquad, SupportSquadHolder TargetSquadSupport, AnimationScreen.AnimationUnitStats UnitStats, AnimationScreen.BattleAnimationTypes BattleAnimationType, SquadBattleResult AttackingResult) { bool IsActiveSquadOnRight = BattleAnimationType == AnimationScreen.BattleAnimationTypes.RightAttackLeft || BattleAnimationType == AnimationScreen.BattleAnimationTypes.LeftConteredByRight; bool HorionztalMirror = BattleAnimationType == AnimationScreen.BattleAnimationTypes.RightConteredByLeft || BattleAnimationType == AnimationScreen.BattleAnimationTypes.LeftAttackRight; Squad NonDemoRightSquad; Squad NonDemoRightSupport; Squad NonDemoLeftSquad; Squad NonDemoLeftSupport; GetLeftRightSquads(IsActiveSquadOnRight, ActiveSquad, ActiveSquadSupport, TargetSquad, TargetSquadSupport, out NonDemoRightSquad, out NonDemoRightSupport, out NonDemoLeftSquad, out NonDemoLeftSupport); Squad AttackingSquad = NonDemoRightSquad; Squad ActiveUnitSupport = NonDemoRightSupport; Attack ActiveAttack = AttackingSquad.CurrentLeader.CurrentAttack; string ActiveTerrain = NonDemoRightSquad.CurrentMovement; SquadBattleResult BattleResult = AttackingResult; Squad EnemySquad = NonDemoLeftSquad; Squad EnemySupport = NonDemoLeftSupport; if (BattleAnimationType == AnimationScreen.BattleAnimationTypes.LeftAttackRight || BattleAnimationType == AnimationScreen.BattleAnimationTypes.LeftConteredByRight) { AttackingSquad = NonDemoLeftSquad; ActiveUnitSupport = NonDemoLeftSupport; ActiveAttack = AttackingSquad.CurrentLeader.CurrentAttack; ActiveTerrain = NonDemoLeftSquad.CurrentMovement; EnemySquad = NonDemoRightSquad; EnemySupport = NonDemoRightSupport; } string ExtraTextIntro = AttackingSquad.CurrentLeader.FullName + " Attacks!"; string ExtraTextHit = AttackingSquad.CurrentLeader.FullName + " hits! " + EnemySquad.CurrentLeader.FullName + " takes " + BattleResult.ArrayResult[0].AttackDamage + " damage!"; string ExtraTextMiss = AttackingSquad.CurrentLeader.FullName + " misses! " + EnemySquad.CurrentLeader.FullName + " takes 0 damage!"; string ExtraTextKill = EnemySquad.CurrentLeader.FullName + " is destroyed!"; AnimationBackground ActiveAnimationBackground = new AnimationBackground2D("Backgrounds 2D/Ground", Content, GraphicsDevice); CreateAnimation(AttackingSquad.CurrentLeader.Animations.MoveFoward, this, AttackingSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, "", HorionztalMirror); CreateAnimation(ActiveAttack.Animations.Start, this, AttackingSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, ExtraTextIntro, HorionztalMirror); if (BattleResult.ArrayResult[0].AttackMissed) { CreateAnimation(ActiveAttack.Animations.EndMiss, this, AttackingSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, ExtraTextMiss, HorionztalMirror); } else { // Check for support if (EnemySupport != null) { CreateAnimation("Default Animations/Support In", this, EnemySquad, EnemySupport, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, "", HorionztalMirror); if (BattleResult.ArrayResult[0].Target.ComputeRemainingHPAfterDamage(BattleResult.ArrayResult[0].AttackDamage) > 0) { CreateAnimation(ActiveAttack.Animations.EndHit, this, AttackingSquad, EnemySupport, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, "", HorionztalMirror); CreateAnimation("Default Animations/Support Out", this, EnemySquad, EnemySupport, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, "", HorionztalMirror); } else { CreateAnimation(ActiveAttack.Animations.EndDestroyed, this, AttackingSquad, EnemySupport, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, "", HorionztalMirror); CreateAnimation("Default Animations/Support Destroyed", this, EnemySquad, EnemySupport, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, "", HorionztalMirror); } } else { if (BattleResult.ArrayResult[0].Target.ComputeRemainingHPAfterDamage(BattleResult.ArrayResult[0].AttackDamage) <= 0) { CreateAnimation(ActiveAttack.Animations.EndDestroyed, this, AttackingSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, ExtraTextKill, HorionztalMirror); } else { CreateAnimation(ActiveAttack.Animations.EndHit, this, AttackingSquad, EnemySquad, ActiveAttack, BattleResult, UnitStats, ActiveAnimationBackground, ExtraTextHit, HorionztalMirror); } } } }
public void InitPlayerBattle(Squad ActiveSquad, SupportSquadHolder ActiveSquadSupport, int AttackerPlayerIndex, Squad TargetSquad, SupportSquadHolder TargetSquadSupport, int DefenderPlayerIndex, bool IsActiveSquadOnRight) { if (TargetSquad.CurrentLeader.Boosts.AttackFirstModifier && !ActiveSquad.CurrentLeader.Boosts.AttackFirstModifier) { Squad ActiveSquadTemp = ActiveSquad; SupportSquadHolder ActiveSquadSupportTemp = ActiveSquadSupport; int AttackerPlayerIndexTemp = AttackerPlayerIndex; ActiveSquad = TargetSquad; ActiveSquadSupport = TargetSquadSupport; AttackerPlayerIndex = DefenderPlayerIndex; TargetSquad = ActiveSquadTemp; TargetSquadSupport = ActiveSquadSupportTemp; DefenderPlayerIndex = AttackerPlayerIndexTemp; } ActivePlayerIndex = AttackerPlayerIndex; ActiveSquadIndex = ListPlayer[AttackerPlayerIndex].ListSquad.IndexOf(ActiveSquad); TargetPlayerIndex = DefenderPlayerIndex; TargetSquadIndex = ListPlayer[TargetPlayerIndex].ListSquad.IndexOf(TargetSquad); bool ShowAnimation = Constants.ShowAnimation && ActiveSquad.CurrentLeader.CurrentAttack.Animations.Start.AnimationName != null; ListNextAnimationScreen.Clear(); NonDemoScreen.ListNonDemoBattleFrame.Clear(); ListActionMenuChoice.RemoveAllSubActionPanels(); SquadBattleResult AttackingResult = CalculateFinalHP(ActiveSquad, ActiveSquadSupport.ActiveSquadSupport, ActivePlayerIndex, BattleMenuOffenseFormationChoice, TargetSquad, TargetSquadSupport.ActiveSquadSupport, TargetPlayerIndex, true, true); AnimationScreen.AnimationUnitStats UnitStats = new AnimationScreen.AnimationUnitStats(ActiveSquad, TargetSquad, IsActiveSquadOnRight); SquadBattleResult DefendingResult = new SquadBattleResult(new BattleResult[1] { new BattleResult() }); if (ShowAnimation) { if (IsActiveSquadOnRight) { GenerateNextAnimationScreens(ActiveSquad, ActiveSquadSupport, TargetSquad, TargetSquadSupport, UnitStats, AnimationScreen.BattleAnimationTypes.RightAttackLeft, AttackingResult); } else { GenerateNextAnimationScreens(ActiveSquad, ActiveSquadSupport, TargetSquad, TargetSquadSupport, UnitStats, AnimationScreen.BattleAnimationTypes.LeftAttackRight, AttackingResult); } } if (AttackingResult.ArrayResult[0].Target.ComputeRemainingHPAfterDamage(AttackingResult.ArrayResult[0].AttackDamage) > 0) { //Counter. if (TargetSquad.CurrentLeader.BattleDefenseChoice == Unit.BattleDefenseChoices.Attack) { DefendingResult = CalculateFinalHP(TargetSquad, null, TargetPlayerIndex, BattleMenuDefenseFormationChoice, ActiveSquad, null, ActivePlayerIndex, true, true); if (ShowAnimation) { if (IsActiveSquadOnRight) { GenerateNextAnimationScreens(ActiveSquad, ActiveSquadSupport, TargetSquad, TargetSquadSupport, UnitStats, AnimationScreen.BattleAnimationTypes.RightConteredByLeft, DefendingResult); } else { GenerateNextAnimationScreens(ActiveSquad, ActiveSquadSupport, TargetSquad, TargetSquadSupport, UnitStats, AnimationScreen.BattleAnimationTypes.LeftConteredByRight, DefendingResult); } } } } if (ShowAnimation) { PushScreen(ListNextAnimationScreen[0]); ListNextAnimationScreen.RemoveAt(0); ListNextAnimationScreen.Add(new EndBattleAnimationScreen(this, ActiveSquad, ActiveSquadSupport, AttackerPlayerIndex, TargetSquad, TargetSquadSupport, DefenderPlayerIndex, AttackingResult, DefendingResult)); } else { NonDemoScreen.InitNonDemo(ActiveSquad, ActiveSquadSupport, AttackerPlayerIndex, AttackingResult, BattleMenuOffenseFormationChoice, TargetSquad, TargetSquadSupport, DefenderPlayerIndex, DefendingResult, BattleMenuDefenseFormationChoice, IsActiveSquadOnRight); NonDemoScreen.Alive = true; ListGameScreen.Insert(0, NonDemoScreen); } //AttackingSquad Activations. for (int U = 0; U < ActiveSquad.UnitsAliveInSquad; U++) { ActiveSquad[U].UpdateSkillsLifetime(SkillEffect.LifetimeTypeBattle); } //DefendingSquad Activations. for (int U = 0; U < TargetSquad.UnitsAliveInSquad; U++) { TargetSquad[U].UpdateSkillsLifetime(SkillEffect.LifetimeTypeBattle); } FinalizeMovement(ActiveSquad, (int)GetTerrain(ActiveSquad).MovementCost); ActiveSquad.EndTurn(); bool HasAfterAttack = false; ActionPanelDeathmatch AfterAttack = new ActionPanelMainMenu(this, ActiveSquad, AttackerPlayerIndex); if (ActiveSquad.CurrentLeader.Boosts.PostAttackModifier.Attack) { HasAfterAttack = true; AfterAttack.AddChoiceToCurrentPanel(new ActionPanelAttackPart1(ActiveSquad.CanMove, ActiveSquad, AttackerPlayerIndex, this)); } if (ActiveSquad.CurrentLeader.Boosts.PostAttackModifier.Move) { HasAfterAttack = true; CursorPosition = ActiveSquad.Position; AfterAttack.AddChoiceToCurrentPanel(new ActionPanelMovePart1(this, ActiveSquad.Position, CameraPosition, ActiveSquad, AttackerPlayerIndex, true)); } if (HasAfterAttack) { AfterAttack.AddChoiceToCurrentPanel(new ActionPanelWait(this, ActiveSquad)); ListActionMenuChoice.Add(AfterAttack); } }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { if (!IsInit) { IsInit = true; for (int P = 0; P < Map.ListPlayer.Count && (RightSquad == null || LeftSquad == null); P++) { for (int U = 0; U < Map.ListPlayer[P].ListSquad.Count && (RightSquad == null || LeftSquad == null); U++) { if (Map.ListPlayer[P].ListSquad[U].ID == _RightUnitID) { RightSquad = Map.ListPlayer[P].ListSquad[U]; Map.ActivePlayerIndex = P; Map.ActiveSquadIndex = U; } else if (Map.ListPlayer[P].ListSquad[U].ID == _LeftUnitID) { LeftSquad = Map.ListPlayer[P].ListSquad[U]; Map.TargetPlayerIndex = P; Map.TargetSquadIndex = U; } else { continue; } } } if (RightSquad == null || LeftSquad == null) { ExecuteEvent(this, 0); IsEnded = true; return; } BattleMap.SquadBattleResult RightUnitResult = new BattleMap.SquadBattleResult(); BattleMap.SquadBattleResult LeftUnitResult = new BattleMap.SquadBattleResult(); RightUnitResult.ArrayResult = new BattleResult[1] { new BattleResult() }; LeftUnitResult.ArrayResult = new BattleResult[1] { new BattleResult() }; RightUnitResult.ArrayResult[0].AttackDamage = _RightUnitAttackDamage; LeftUnitResult.ArrayResult[0].AttackDamage = _LeftUnitAttackDamage; Squad Attacker = RightSquad; Squad Defender = LeftSquad; //Play battle theme. if (Attacker.CurrentLeader.BattleTheme == null || Attacker.CurrentLeader.BattleThemeName != GameScreen.FMODSystem.sndActiveBGMName) { if (Attacker.CurrentLeader.BattleTheme != null) { GameScreen.FMODSystem.sndActiveBGM.Stop(); Attacker.CurrentLeader.BattleTheme.SetLoop(true); Attacker.CurrentLeader.BattleTheme.PlayAsBGM(); GameScreen.FMODSystem.sndActiveBGMName = Attacker.CurrentLeader.BattleThemeName; } } RightSquad.CurrentLeader.AttackIndex = 0; if (!string.IsNullOrWhiteSpace(AttackingUnitWeaponName)) { for (int A = 0; A < RightSquad.CurrentLeader.ListAttack.Count; ++A) { if (RightSquad.CurrentLeader.ListAttack[A].ItemName == AttackingUnitWeaponName) { RightSquad.CurrentLeader.AttackIndex = A; } } } LeftSquad.CurrentLeader.AttackIndex = 0; if (!string.IsNullOrWhiteSpace(AttackingUnitWeaponName)) { for (int A = 0; A < LeftSquad.CurrentLeader.ListAttack.Count; ++A) { if (LeftSquad.CurrentLeader.ListAttack[A].ItemName == DefendingUnitWeaponName) { LeftSquad.CurrentLeader.AttackIndex = A; } } } SquadBattleResult AttackingResult = Map.CalculateFinalHP(RightSquad, null, 0, FormationChoices.Focused, LeftSquad, null, Map.TargetPlayerIndex, Map.TargetSquadIndex, true, true); AttackingResult.ArrayResult[0].AttackMissed = false; AttackingResult.ArrayResult[0].AttackDamage = AttackingUnitAttackDamage; AttackingResult.ArrayResult[0].SetTarget(Map.TargetPlayerIndex, Map.TargetSquadIndex, 0, Map.TargetSquad.CurrentLeader); AnimationScreen.AnimationUnitStats UnitStats = new AnimationScreen.AnimationUnitStats(RightSquad, LeftSquad, true); if (IsCounterattack) { ListNextAnimationScreen = Map.GenerateNextAnimationScreens(RightSquad, new SupportSquadHolder(), LeftSquad, new SupportSquadHolder(), UnitStats, AnimationScreen.BattleAnimationTypes.RightConteredByLeft, AttackingResult, out _, null, out _, null); } else { ListNextAnimationScreen = Map.GenerateNextAnimationScreens(RightSquad, new SupportSquadHolder(), LeftSquad, new SupportSquadHolder(), UnitStats, AnimationScreen.BattleAnimationTypes.RightAttackLeft, AttackingResult, out _, null, out _, null); } Map.PushScreen(ListNextAnimationScreen[0]); } else { if (!Map.ListGameScreen.Contains(ListNextAnimationScreen[0])) { ListNextAnimationScreen.Remove(ListNextAnimationScreen[0]); if (ListNextAnimationScreen.Count > 0) { Map.PushScreen(ListNextAnimationScreen[0]); } else { ExecuteEvent(this, 0); IsEnded = true; } } } }
public SquadBattleResult CalculateFinalHP(Squad Attacker, Squad SupportAttacker, int AttackerPlayerIndex, FormationChoices AttackerFormationChoice, Squad Defender, Squad SupportDefender, int DefenderPlayerIndex, int DefenderSquadIndex, bool ActivateSkills, bool CalculateCritical) { SquadBattleResult SquadResult = new SquadBattleResult(new BattleResult[Attacker.UnitsAliveInSquad]); Squad TargetSquad = Defender; if (SupportDefender != null) { TargetSquad = SupportDefender; } GlobalBattleContext.Result.SetTarget(-1, -1, -1, null); GlobalBattleContext.SupportAttack = null; GlobalBattleContext.SupportDefend = null; if (SupportAttacker != null) { GlobalBattleContext.SupportAttack = SupportAttacker.CurrentLeader; } if (SupportDefender != null) { GlobalBattleContext.SupportDefend = SupportDefender.CurrentLeader; } int TotalLeaderDamage = 0; if (ActivateSkills) { if (Attacker.CurrentLeader.CurrentAttack != null) { TotalLeaderDamage = GetBattleResult(Attacker.CurrentLeader, Attacker, 1, DefenderPlayerIndex, DefenderSquadIndex, 0, false, CalculateCritical).AttackDamage; } ActivateAutomaticSkills(Attacker, Attacker.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, TargetSquad, TargetSquad.CurrentLeader); ActivateAutomaticSkills(TargetSquad, TargetSquad.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, Attacker, Attacker.CurrentLeader); if (AttackerFormationChoice == FormationChoices.Spread) { for (int i = 1; i < Attacker.UnitsAliveInSquad && i < TargetSquad.UnitsAliveInSquad; i++) { if (Attacker[i].CurrentAttack != null) { ActivateAutomaticSkills(Attacker, Attacker[i], DeathmatchSkillRequirement.BattleStartRequirementName, TargetSquad, TargetSquad[i]); ActivateAutomaticSkills(TargetSquad, TargetSquad[i], DeathmatchSkillRequirement.BattleStartRequirementName, Attacker, Attacker[i]); } } } else if (AttackerFormationChoice == FormationChoices.Focused) { int DefenderHP = TargetSquad.CurrentLeader.HP; for (int i = 1; i < Attacker.UnitsAliveInSquad; i++) { if (Attacker[i].CurrentAttack != null && DefenderHP >= 0) { TotalLeaderDamage += GetBattleResult(Attacker[i], Attacker, WingmanDamageModifier, DefenderPlayerIndex, DefenderSquadIndex, 0, false, CalculateCritical).AttackDamage; DefenderHP = TargetSquad.CurrentLeader.ComputeRemainingHPAfterDamage(TotalLeaderDamage); ActivateAutomaticSkills(Attacker, Attacker[i], DeathmatchSkillRequirement.BattleStartRequirementName, TargetSquad, TargetSquad.CurrentLeader); ActivateAutomaticSkills(TargetSquad, TargetSquad.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, Attacker, Attacker[i]); } } } else if (AttackerFormationChoice == FormationChoices.ALL) { for (int i = 1; i < TargetSquad.UnitsAliveInSquad; i++) { ActivateAutomaticSkills(Attacker, Attacker.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, TargetSquad, TargetSquad[i]); ActivateAutomaticSkills(TargetSquad, TargetSquad[i], DeathmatchSkillRequirement.BattleStartRequirementName, Attacker, Attacker.CurrentLeader); } } if (SupportAttacker != null && TargetSquad.CurrentLeader.ComputeRemainingHPAfterDamage(TotalLeaderDamage) > 0) { ActivateAutomaticSkills(SupportAttacker, SupportAttacker.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, TargetSquad, TargetSquad.CurrentLeader); ActivateAutomaticSkills(TargetSquad, TargetSquad.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, SupportAttacker, SupportAttacker.CurrentLeader); } if (SupportDefender != null) { ActivateAutomaticSkills(SupportDefender, SupportDefender.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, Attacker, null); ActivateAutomaticSkills(SupportDefender, SupportDefender.CurrentLeader, DeathmatchSkillRequirement.SupportDefendRequirementName, Attacker, null); } } if (Attacker.CurrentLeader.CurrentAttack != null) { SquadResult.ArrayResult[0] = GetBattleResult(Attacker.CurrentLeader, Attacker, 1, DefenderPlayerIndex, DefenderSquadIndex, 0, ActivateSkills, CalculateCritical); } TotalLeaderDamage = SquadResult.ArrayResult[0].AttackDamage; if (AttackerFormationChoice == FormationChoices.Spread) { for (int i = 1; i < Attacker.UnitsAliveInSquad && i < TargetSquad.UnitsAliveInSquad; i++) { if (Attacker[i].CurrentAttack != null) { SquadResult.ArrayResult[i] = GetBattleResult(Attacker[i], Attacker, WingmanDamageModifier, DefenderPlayerIndex, DefenderSquadIndex, i, ActivateSkills, CalculateCritical); } } } else if (AttackerFormationChoice == FormationChoices.Focused) { int DefenderHP = TargetSquad.CurrentLeader.HP; for (int i = 1; i < Attacker.UnitsAliveInSquad; i++) { if (Attacker[i].CurrentAttack != null && DefenderHP >= 0) { SquadResult.ArrayResult[i] = GetBattleResult(Attacker[i], Attacker, WingmanDamageModifier, DefenderPlayerIndex, DefenderSquadIndex, 0, ActivateSkills, CalculateCritical); TotalLeaderDamage += SquadResult.ArrayResult[i].AttackDamage; DefenderHP = TargetSquad.CurrentLeader.ComputeRemainingHPAfterDamage(SquadResult.ArrayResult[i].AttackDamage); } } } else if (AttackerFormationChoice == FormationChoices.ALL) { for (int i = 1; i < TargetSquad.UnitsAliveInSquad; i++) { SquadResult.ArrayResult[i] = GetBattleResult(Attacker.CurrentLeader, Attacker, 1, DefenderPlayerIndex, DefenderSquadIndex, i, ActivateSkills, CalculateCritical); } } if (SupportAttacker != null && TargetSquad.CurrentLeader.ComputeRemainingHPAfterDamage(TotalLeaderDamage) > 0) { if (ActivateSkills) { ActivateAutomaticSkills(SupportAttacker, SupportAttacker.CurrentLeader, DeathmatchSkillRequirement.BattleStartRequirementName, TargetSquad, null); ActivateAutomaticSkills(SupportAttacker, SupportAttacker.CurrentLeader, DeathmatchSkillRequirement.SupportAttackRequirementName, TargetSquad, null); } SquadResult.ResultSupportAttack = GetBattleResult(SupportAttacker.CurrentLeader, SupportAttacker, 0.75f, DefenderPlayerIndex, DefenderSquadIndex, 0, ActivateSkills, CalculateCritical); } if (ActivateSkills) { UpdateMapEvent(EventTypeOnBattle, 0); } return(SquadResult); }
public void FinalizeBattle(Squad Attacker, SupportSquadHolder ActiveSquadSupport, int AttackerPlayerIndex, Squad TargetSquad, SupportSquadHolder TargetSquadSupport, int DefenderPlayerIndex, SquadBattleResult ResultAttack, SquadBattleResult ResultDefend) { Squad Target = TargetSquad; if (TargetSquadSupport.ActiveSquadSupport != null) { Target = TargetSquadSupport.ActiveSquadSupport; //Remove 1 Support Defend. --TargetSquadSupport.ActiveSquadSupport.CurrentLeader.Boosts.SupportDefendModifier; } List <Unit> ListDeadDefender = new List <Unit>(); List <LevelUpMenu> ListBattleRecap = new List <LevelUpMenu>(); ListBattleRecap.AddRange(FinalizeBattle(Attacker, AttackerPlayerIndex, Target, DefenderPlayerIndex, ResultAttack, ListDeadDefender)); //Counter attack if (TargetSquad.CurrentLeader.BattleDefenseChoice == Unit.BattleDefenseChoices.Attack && TargetSquad.CurrentLeader.HP > 0) { ListBattleRecap.AddRange(FinalizeBattle(TargetSquad, DefenderPlayerIndex, Attacker, AttackerPlayerIndex, ResultDefend, new List <Unit>())); } //Support Attack if (ActiveSquadSupport.ActiveSquadSupport != null && Attacker.CurrentLeader.HP > 0 && TargetSquad.CurrentLeader.HP > 0) { //Remove 1 Support Defend. --ActiveSquadSupport.ActiveSquadSupport.CurrentLeader.Boosts.SupportAttackModifier; LevelUpMenu BattleRecap = FinalizeBattle(ActiveSquadSupport.ActiveSquadSupport.CurrentLeader, ActiveSquadSupport.ActiveSquadSupport, AttackerPlayerIndex, TargetSquad.CurrentLeader, TargetSquad, DefenderPlayerIndex, ResultAttack.ResultSupportAttack, ListDeadDefender); if (BattleRecap != null) { ListBattleRecap.Add(BattleRecap); } } #region Explosions //Explosion of death cutscene if (Attacker.CurrentLeader == null) { PushScreen(new BattleMapScreen.ExplosionCutscene(CenterCamera, this, Attacker)); } if (TargetSquad.CurrentLeader == null) { PushScreen(new BattleMapScreen.ExplosionCutscene(CenterCamera, this, TargetSquad)); } #endregion bool HasRecap = false; for (int R = ListBattleRecap.Count - 1; R >= 0; --R) { if (Constants.ShowBattleRecap && ListBattleRecap[R].IsHuman) { PushScreen(ListBattleRecap[R]); if (!HasRecap) { ListBattleRecap[R].SetBattleContent(true, Attacker, ActiveSquadSupport, DefenderPlayerIndex, TargetSquad, TargetSquadSupport); } else { ListBattleRecap[R].SetBattleContent(false, Attacker, ActiveSquadSupport, DefenderPlayerIndex, TargetSquad, TargetSquadSupport); } HasRecap = true; } else { ListBattleRecap[R].LevelUp(); } } if (!HasRecap) { GlobalBattleContext.SetContext(ActiveSquad, ActiveSquad.CurrentLeader, ActiveSquad.CurrentLeader.Pilot, TargetSquad, TargetSquad.CurrentLeader, TargetSquad.CurrentLeader.Pilot, ActiveParser); UpdateMapEvent(EventTypeOnBattle, 1); GlobalBattleContext.SetContext(null, null, null, null, null, null, ActiveParser); //Don't update the leader until after the events are processed. (If a battle map event try to read the leader of a dead unit it will crash on a null pointer as dead units have no leader) Attacker.UpdateSquad(); if (ActiveSquadSupport != null && ActiveSquadSupport.ActiveSquadSupport != null) { ActiveSquadSupport.ActiveSquadSupport.UpdateSquad(); } TargetSquad.UpdateSquad(); if (TargetSquadSupport != null && TargetSquadSupport.ActiveSquadSupport != null) { TargetSquadSupport.ActiveSquadSupport.UpdateSquad(); } GameRule.OnSquadDefeated(DefenderPlayerIndex, TargetSquad); } }
public void FinalizeBattle(Squad Attacker, SupportSquadHolder ActiveSquadSupport, int AttackerPlayerIndex, Squad TargetSquad, SupportSquadHolder TargetSquadSupport, int DefenderPlayerIndex, SquadBattleResult ResultAttack, SquadBattleResult ResultDefend) { Squad Target = TargetSquad; if (TargetSquadSupport.ActiveSquadSupport != null) { Target = TargetSquadSupport.ActiveSquadSupport; //Remove 1 Support Defend. --TargetSquadSupport.ActiveSquadSupport.CurrentLeader.Boosts.SupportDefendModifier; } List <Unit> ListDeadDefender = new List <Unit>(); FinalizeBattle(Attacker, AttackerPlayerIndex, Target, DefenderPlayerIndex, ResultAttack, ListDeadDefender); //Counter attack if (TargetSquad.CurrentLeader.BattleDefenseChoice == Unit.BattleDefenseChoices.Attack && TargetSquad.CurrentLeader.HP > 0) { FinalizeBattle(TargetSquad, DefenderPlayerIndex, Attacker, AttackerPlayerIndex, ResultDefend, new List <Unit>()); } //Support Attack if (ActiveSquadSupport.ActiveSquadSupport != null && Attacker.CurrentLeader.HP > 0 && TargetSquad.CurrentLeader.HP > 0) { //Remove 1 Support Defend. --ActiveSquadSupport.ActiveSquadSupport.CurrentLeader.Boosts.SupportAttackModifier; FinalizeBattle(ActiveSquadSupport.ActiveSquadSupport.CurrentLeader, ActiveSquadSupport.ActiveSquadSupport, AttackerPlayerIndex, TargetSquad.CurrentLeader, TargetSquad, DefenderPlayerIndex, ResultAttack.ResultSupportAttack, ListDeadDefender); } Attacker.UpdateSquad(); if (ActiveSquadSupport != null && ActiveSquadSupport.ActiveSquadSupport != null) { ActiveSquadSupport.ActiveSquadSupport.UpdateSquad(); } TargetSquad.UpdateSquad(); if (TargetSquadSupport != null && TargetSquadSupport.ActiveSquadSupport != null) { TargetSquadSupport.ActiveSquadSupport.UpdateSquad(); } #region Explosions //Explosion of death cutscene if (Attacker.CurrentLeader == null) { PushScreen(new BattleMapScreen.ExplosionCutscene(CenterCamera, this, Attacker)); } if (TargetSquad.CurrentLeader == null) { PushScreen(new BattleMapScreen.ExplosionCutscene(CenterCamera, this, TargetSquad)); } #endregion UpdateMapEvent(EventTypeOnBattle, 1); }
public void InitPlayerBattle(bool IsActiveSquadOnRight) { int FinalActivePlayerIndex = ActivePlayerIndex; int FinalActiveSquadIndex = ActiveSquadIndex; Squad FinalActiveSquad = ActiveSquad; SupportSquadHolder FinalActiveSquadSupport = ActiveSquadSupport; int FinalTargetPlayerIndex = TargetPlayerIndex; int FinalTargetSquadIndex = TargetSquadIndex; Squad FinalTargetSquad = TargetSquad; SupportSquadHolder FinalTargetSquadSupport = TargetSquadSupport; if (TargetSquad.CurrentLeader.Boosts.AttackFirstModifier && !ActiveSquad.CurrentLeader.Boosts.AttackFirstModifier) { FinalActivePlayerIndex = TargetPlayerIndex; FinalActiveSquadIndex = TargetSquadIndex; FinalActiveSquad = TargetSquad; FinalActiveSquadSupport = TargetSquadSupport; FinalTargetPlayerIndex = ActivePlayerIndex; FinalTargetSquadIndex = ActiveSquadIndex; FinalTargetSquad = ActiveSquad; FinalTargetSquadSupport = ActiveSquadSupport; } bool ShowAnimation = Constants.ShowAnimation && FinalActiveSquad.CurrentLeader.CurrentAttack.GetAttackAnimations(Map.ActiveParser).Start.AnimationName != null; ListNextAnimationScreen.Clear(); Map.NonDemoScreen.ListNonDemoBattleFrame.Clear(); if (Map.IsOfflineOrServer) { AttackingResult = Map.CalculateFinalHP(FinalActiveSquad, FinalActiveSquadSupport.ActiveSquadSupport, FinalActivePlayerIndex, Map.BattleMenuOffenseFormationChoice, FinalTargetSquad, FinalTargetSquadSupport.ActiveSquadSupport, FinalTargetPlayerIndex, FinalTargetSquadIndex, true, true); DefendingResult = new SquadBattleResult(new BattleResult[1] { new BattleResult() }); } else { Map.CalculateFinalHP(FinalActiveSquad, FinalActiveSquadSupport.ActiveSquadSupport, FinalActivePlayerIndex, Map.BattleMenuOffenseFormationChoice, FinalTargetSquad, FinalTargetSquadSupport.ActiveSquadSupport, FinalTargetPlayerIndex, FinalTargetSquadIndex, true, true); } AnimationScreen.AnimationUnitStats UnitStats = new AnimationScreen.AnimationUnitStats(FinalActiveSquad, FinalTargetSquad, IsActiveSquadOnRight); AnimationBackground TargetSquadBackground = null; AnimationBackground TargetSquadForeground = null; if (ShowAnimation) { AnimationScreen.BattleAnimationTypes BattleAnimationType = AnimationScreen.BattleAnimationTypes.LeftAttackRight; if (IsActiveSquadOnRight) { BattleAnimationType = AnimationScreen.BattleAnimationTypes.RightAttackLeft; } ListNextAnimationScreen.AddRange(Map.GenerateNextAnimationScreens(FinalActiveSquad, FinalActiveSquadSupport, FinalTargetSquad, FinalTargetSquadSupport, UnitStats, BattleAnimationType, AttackingResult, out TargetSquadBackground, null, out TargetSquadForeground, null)); } if (AttackingResult.ArrayResult[0].Target.ComputeRemainingHPAfterDamage(AttackingResult.ArrayResult[0].AttackDamage) > 0) { //Counter. if (FinalTargetSquad.CurrentLeader.BattleDefenseChoice == Unit.BattleDefenseChoices.Attack) { if (Map.IsOfflineOrServer) { DefendingResult = Map.CalculateFinalHP(FinalTargetSquad, null, FinalTargetPlayerIndex, Map.BattleMenuDefenseFormationChoice, FinalActiveSquad, null, FinalActivePlayerIndex, FinalActiveSquadIndex, true, true); } else { Map.CalculateFinalHP(FinalTargetSquad, null, FinalTargetPlayerIndex, Map.BattleMenuDefenseFormationChoice, FinalActiveSquad, null, FinalActivePlayerIndex, FinalActiveSquadIndex, true, true); } if (ShowAnimation) { AnimationScreen.BattleAnimationTypes BattleAnimationType = AnimationScreen.BattleAnimationTypes.LeftConteredByRight; if (IsActiveSquadOnRight) { BattleAnimationType = AnimationScreen.BattleAnimationTypes.RightConteredByLeft; } ListNextAnimationScreen.AddRange(Map.GenerateNextAnimationScreens(FinalActiveSquad, FinalActiveSquadSupport, FinalTargetSquad, FinalTargetSquadSupport, UnitStats, BattleAnimationType, DefendingResult, out _, TargetSquadBackground, out _, TargetSquadForeground)); } } } if (Map.IsClient) { if (ShowAnimation) { Map.PushScreen(ListNextAnimationScreen[0]); ListNextAnimationScreen.RemoveAt(0); ListNextAnimationScreen.Add(new EndBattleAnimationScreen(Map, FinalActiveSquad, FinalActiveSquadSupport, FinalActivePlayerIndex, FinalTargetSquad, FinalTargetSquadSupport, FinalTargetPlayerIndex, AttackingResult, DefendingResult)); } else { Map.NonDemoScreen.InitNonDemo(FinalActiveSquad, FinalActiveSquadSupport, FinalActivePlayerIndex, AttackingResult, Map.BattleMenuOffenseFormationChoice, FinalTargetSquad, FinalTargetSquadSupport, FinalTargetPlayerIndex, DefendingResult, Map.BattleMenuDefenseFormationChoice, IsActiveSquadOnRight); Map.NonDemoScreen.Alive = true; Map.ListGameScreen.Insert(0, Map.NonDemoScreen); } } //AttackingSquad Activations. for (int U = 0; U < FinalActiveSquad.UnitsAliveInSquad; U++) { FinalActiveSquad[U].UpdateSkillsLifetime(SkillEffect.LifetimeTypeBattle); } //DefendingSquad Activations. for (int U = 0; U < FinalTargetSquad.UnitsAliveInSquad; U++) { FinalTargetSquad[U].UpdateSkillsLifetime(SkillEffect.LifetimeTypeBattle); } Map.FinalizeMovement(FinalActiveSquad, (int)Map.GetTerrain(FinalActiveSquad).MovementCost); FinalActiveSquad.EndTurn(); if (Map.IsClient) { bool HasAfterAttack = false; ActionPanelDeathmatch AfterAttack = new ActionPanelMainMenu(Map, FinalActivePlayerIndex, FinalActiveSquadIndex); if (FinalActiveSquad.CurrentLeader.Boosts.PostAttackModifier.Attack) { HasAfterAttack = true; AfterAttack.AddChoiceToCurrentPanel(new ActionPanelAttackPart1(Map, FinalActivePlayerIndex, FinalActiveSquadIndex, FinalActiveSquad.CanMove)); } if (FinalActiveSquad.CurrentLeader.Boosts.PostAttackModifier.Move) { HasAfterAttack = true; Map.CursorPosition = FinalActiveSquad.Position; AfterAttack.AddChoiceToCurrentPanel(new ActionPanelMovePart1(Map, FinalActivePlayerIndex, FinalActiveSquadIndex, FinalActiveSquad.Position, Map.CameraPosition, true)); } if (HasAfterAttack) { AfterAttack.AddChoiceToCurrentPanel(new ActionPanelWait(Map, FinalActiveSquad)); ListActionMenuChoice.Add(AfterAttack); } } }