public bool GetCurrentStratagemSuccess(Troop troop, bool inevitableSuccess, bool invincible, bool lowerIntelligenceInvincible) { int num = 0; bool flag = false; if (!this.CurrentStratagem.Friendly) { if (invincible) { flag = false; } else if (lowerIntelligenceInvincible && (this.TroopIntelligence < troop.TroopIntelligence)) { flag = false; } else if (inevitableSuccess && (this.TroopIntelligence > troop.TroopIntelligence)) { flag = true; } else { num = ((((this.TroopIntelligence + this.StratagemChanceIncrement) + this.Leader.Calmness) - troop.TroopIntelligence) - troop.ChanceDecrementOfStratagem) - troop.Leader.Calmness; int chance = this.CurrentStratagem.Chance + num; flag = GameObject.Chance(chance); } } else { flag = GameObject.Chance(this.TroopIntelligence + this.StratagemChanceIncrement); } if (!this.CurrentStratagem.Friendly) { if (flag) { if (this.OrientationTroop == troop) { this.WaitForDeepChaos = !troop.NeverBeIntoChaos && GameObject.Chance(this.ChaosAfterStratagemSuccessChance); this.WaitForDeepChaosFrameCount = 100; } if (this.OnStratagemSuccess != null) { this.OnStratagemSuccess(this, troop, this.CurrentStratagem, true); } } else { GameObjects.Animations.TileAnimation animation = base.Scenario.GeneratorOfTileAnimation.AddTileAnimation(TileAnimationKind.抵挡, troop.Position, false); if (animation != null) { troop.TryToPlaySound(troop.Position, animation.LinkedAnimation.SoundPath, false); } if (this.OnResistStratagem != null) { this.OnResistStratagem(this, troop, this.CurrentStratagem, true); } } } else if (flag) { if (((troop != null) && (this.OnStratagemSuccess != null)) && (this != troop)) { this.OnStratagemSuccess(this, troop, this.CurrentStratagem, false); } } else if ((troop != null) && (this.OnResistStratagem != null)) { this.OnResistStratagem(this, troop, this.CurrentStratagem, false); } int increment = (2 + (flag ? 1 : 0)) + (this.WaitForDeepChaos ? 2 : 0); this.IncreaseStratagemExperience(increment, true); if (troop != null) { troop.IncreaseStratagemExperience(increment, false); } if (this.BelongedFaction != null) { if (flag) { if (this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemSuccess > 0f) { this.IncreaseCombativity(StaticMethods.GetRandomValue((int) ((this.Leader.Calmness * 100) * this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemSuccess), 100)); } return flag; } if (this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemFail > 0f) { this.IncreaseCombativity(StaticMethods.GetRandomValue((int) ((this.Leader.Calmness * 100) * this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemFail), 100)); } } return flag; }
public static void CheckTroopRout(Troop sending, Troop receiving) { if (!receiving.Destroyed && ((receiving.Quantity <= 0) || (receiving.Morale <= 0))) { Faction belongedFaction = null; Person leader = null; if (receiving.BelongedFaction != null) { belongedFaction = receiving.BelongedFaction; leader = belongedFaction.Leader; } if (sending.OnRout != null) { sending.OnRout(sending, receiving); } if (receiving.OnRouted != null) { receiving.OnRouted(sending, receiving); } GameObjects.Animations.TileAnimation animation = sending.Scenario.GeneratorOfTileAnimation.AddTileAnimation(TileAnimationKind.被击破, receiving.Position, false); if (animation != null) { receiving.TryToPlaySound(receiving.Position, animation.LinkedAnimation.SoundPath, false); } if ((sending.BelongedFaction != null) && (belongedFaction != null)) { sending.Scenario.ChangeDiplomaticRelation(sending.BelongedFaction.ID, receiving.BelongedFaction.ID, -10); sending.Scenario.ReflectDiplomaticRelations(sending.BelongedFaction.ID, receiving.BelongedFaction.ID, -10); } if (sending.BelongedFaction != null) { sending.IncreaseRoutExperience(true); sending.AddRoutCount(); } if (belongedFaction != null) { receiving.IncreaseRoutExperience(false); receiving.AddRoutedCount(); receiving.ReleaseCaptiveBeforeBeRouted(); if (sending.BelongedFaction != null) { sending.CheckCaptiveBeforeRout(receiving); } } if (sending.StartingArchitecture != null) { sending.StartingArchitecture.AddPopulationPack((int) (sending.Scenario.GetDistance(receiving.Position, sending.StartingArchitecture.ArchitectureArea) / 2.0), receiving.GetPopulation()); } receiving.BeRouted(); if (sending.Combativity < sending.Army.CombativityCeiling) { sending.IncreaseCombativity(10 + sending.RoutIncrementOfCombativity); if (sending.PreAction == TroopPreAction.无) { sending.PreAction = TroopPreAction.鼓舞; } } if (sending.Morale < sending.Army.MoraleCeiling) { sending.IncreaseMorale(5); if (sending.PreAction == TroopPreAction.无) { sending.PreAction = TroopPreAction.鼓舞; } } } }
public bool GetCurrentStratagemSuccess(Troop troop, bool inevitableSuccess, bool invincible, bool lowerIntelligenceInvincible) { int num = 0; bool flag = false; if (!this.CurrentStratagem.Friendly) { if (invincible) { flag = false; } else if (lowerIntelligenceInvincible && (this.TroopIntelligence < troop.TroopIntelligence)) { flag = false; } else if (inevitableSuccess && (this.TroopIntelligence > troop.TroopIntelligence)) { flag = true; } else { num = ((((this.TroopIntelligence + this.StratagemChanceIncrement) + this.Leader.Calmness) - troop.TroopIntelligence) - troop.ChanceDecrementOfStratagem) - troop.Leader.Calmness; int chance = this.CurrentStratagem.Chance + num; flag = GameObject.Chance(chance); } } else { flag = GameObject.Chance(this.TroopIntelligence + this.StratagemChanceIncrement); } if (!this.CurrentStratagem.Friendly) { if (flag) { if (this.OrientationTroop == troop) { this.WaitForDeepChaos = !troop.NeverBeIntoChaos && GameObject.Chance(this.ChaosAfterStratagemSuccessChance); this.WaitForDeepChaosFrameCount = 100; } if (this.OnStratagemSuccess != null) { this.OnStratagemSuccess(this, troop, this.CurrentStratagem, true); } this.Persons.GetMaxIntelligencePerson().StratagemSuccessCount++; troop.Persons.GetMaxIntelligencePerson().StratagemBeSuccessCount++; } else { GameObjects.Animations.TileAnimation animation = base.Scenario.GeneratorOfTileAnimation.AddTileAnimation(TileAnimationKind.抵挡, troop.Position, false); if (animation != null) { troop.TryToPlaySound(troop.Position, this.getSoundPath(animation.LinkedAnimation), false); } if (this.OnResistStratagem != null) { this.OnResistStratagem(this, troop, this.CurrentStratagem, true); } this.Persons.GetMaxIntelligencePerson().StratagemFailCount++; troop.Persons.GetMaxIntelligencePerson().StratagemBeFailCount++; } } else if (flag) { if (((troop != null) && (this.OnStratagemSuccess != null)) && (this != troop)) { this.OnStratagemSuccess(this, troop, this.CurrentStratagem, false); } this.Persons.GetMaxIntelligencePerson().StratagemSuccessCount++; } else if ((troop != null) && (this.OnResistStratagem != null)) { this.OnResistStratagem(this, troop, this.CurrentStratagem, false); this.Persons.GetMaxIntelligencePerson().StratagemFailCount++; } int increment = (2 + (flag ? 1 : 0)) + (this.WaitForDeepChaos ? 2 : 0); this.IncreaseStratagemExperience(increment, true); if (troop != null) { troop.IncreaseStratagemExperience(increment, false); } if (this.BelongedFaction != null) { if (flag) { if (this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemSuccess > 0f) { this.IncreaseCombativity(StaticMethods.GetRandomValue((int)((this.Leader.Calmness * 100) * this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemSuccess), 100)); } if (troop.BelongedFaction != this.BelongedFaction) { troop.army.Tiredness += this.stratagemTirednessIncrease; } if (this.stratagemStealTroop > 0 && troop.BelongedFaction != this.BelongedFaction) { int c = Math.Min(troop.Quantity, this.stratagemStealTroop); troop.DecreaseQuantity(c); this.IncreaseQuantity(c); Troop.CheckTroopRout(this, troop); } if (this.stratagemStealInjury > 0 && troop.BelongedFaction != this.BelongedFaction) { int c = Math.Min(troop.InjuryQuantity, this.stratagemStealInjury); troop.DecreaseInjuryQuantity(c); this.IncreaseInjuryQuantity(c); } if (this.stratagemMoraleDecrease > 0 && troop.BelongedFaction != this.BelongedFaction) { troop.DecreaseMorale(this.stratagemMoraleDecrease); } if (this.stratagemCombativityDecrease > 0 && troop.BelongedFaction != this.BelongedFaction) { troop.DecreaseCombativity(this.stratagemCombativityDecrease); } if (this.stratagemTroopDecrease > 0 && troop.BelongedFaction != this.BelongedFaction) { troop.DecreaseQuantity(this.stratagemTroopDecrease); Troop.CheckTroopRout(this, troop); } if (this.stratagemInjuryDecrease > 0 && troop.BelongedFaction != this.BelongedFaction) { troop.DecreaseInjuryQuantity(this.stratagemInjuryDecrease); } if (this.stratagemLoyaltyDecrease > 0 && troop.BelongedFaction != this.BelongedFaction) { foreach (Person p in troop.Persons) { p.Loyalty -= this.stratagemLoyaltyDecrease; if (p.Loyalty < 0) { p.Loyalty = 0; } } } if (this.stratagemStealFood > 0 && troop.BelongedFaction != this.BelongedFaction) { int c = Math.Min(troop.Food, this.stratagemStealFood); troop.Food -= c; this.IncreaseFood(c); } return flag; } if (this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemFail > 0f) { this.IncreaseCombativity(StaticMethods.GetRandomValue((int)((this.Leader.Calmness * 100) * this.BelongedFaction.RateOfCombativityRecoveryAfterStratagemFail), 100)); } } return flag; }
public static void CheckTroopRout(Troop receiving) { if (!receiving.Destroyed && ((receiving.Quantity <= 0) || (receiving.Morale <= 0))) { if (receiving.OnRouted != null) { receiving.OnRouted(null, receiving); } GameObjects.Animations.TileAnimation animation = receiving.Scenario.GeneratorOfTileAnimation.AddTileAnimation(TileAnimationKind.被击破, receiving.Position, false); if (animation != null) { receiving.TryToPlaySound(receiving.Position, animation.LinkedAnimation.SoundPath, false); } if (receiving.BelongedFaction != null) { receiving.IncreaseRoutExperience(false); receiving.AddRoutedCount(); } if (receiving.StartingArchitecture != null) { receiving.StartingArchitecture.AddPopulationPack((int) (receiving.Scenario.GetDistance(receiving.Position, receiving.StartingArchitecture.ArchitectureArea) / 2.0), receiving.GetPopulation()); } receiving.BeRouted(); } }
public static void CheckTroopRout(Troop sending, Troop receiving) { if (!receiving.Destroyed && ((receiving.Quantity <= 0) || (receiving.Morale <= 0) || receiving.PersonCount == 0)) { Faction belongedFaction = null; Person leader = null; if (receiving.BelongedFaction != null) { belongedFaction = receiving.BelongedFaction; leader = belongedFaction.Leader; } if (sending.OnRout != null) { sending.OnRout(sending, receiving); } if (receiving.OnRouted != null) { receiving.OnRouted(sending, receiving); } GameObjects.Animations.TileAnimation animation = sending.Scenario.GeneratorOfTileAnimation.AddTileAnimation(TileAnimationKind.被击破, receiving.Position, false); if (animation != null) { receiving.TryToPlaySound(receiving.Position, Troop.getSoundPath(receiving, animation.LinkedAnimation), false); } if ((sending.BelongedFaction != null) && (belongedFaction != null)) { sending.Scenario.ChangeDiplomaticRelation(sending.BelongedFaction.ID, receiving.BelongedFaction.ID, -10); sending.Scenario.ReflectDiplomaticRelations(sending.BelongedFaction.ID, receiving.BelongedFaction.ID, -10); } if (sending.BelongedFaction != null) { sending.IncreaseRoutExperience(true); sending.AddRoutCount(); foreach (Person p in sending.persons) { foreach (Person q in sending.persons) { if (p == q) continue; p.AdjustRelation(q, 1f / (sending.persons.Count - 1), 3); } } } if (GameObject.Chance(sending.stealTreasureRate) && sending.BelongedFaction != null) { foreach (Person p in receiving.Persons.GetRandomList()) { if (p.TreasureCount > 0) { Treasure t = (Treasure)p.Treasures[GameObject.Random(p.Treasures.Count)]; p.LoseTreasure(t); sending.BelongedFaction.Leader.ReceiveTreasure(t); break; } } } if (belongedFaction != null) { receiving.IncreaseRoutExperience(false); receiving.AddRoutedCount(); receiving.ReleaseCaptiveBeforeBeRouted(); if (sending.BelongedFaction != null) { sending.CheckCaptiveBeforeRout(receiving); } } if (sending.StartingArchitecture != null) { sending.StartingArchitecture.AddPopulationPack((int)(sending.Scenario.GetDistance(receiving.Position, sending.StartingArchitecture.ArchitectureArea) / 2.0), receiving.GetPopulation()); } Architecture oldLandedArch = sending.Scenario.GetArchitectureByPosition(receiving.Position); if (sending.Army.Kind.ArchitectureCounterDamageRate <= 0 && oldLandedArch != null && !sending.BelongedFaction.IsFriendly(oldLandedArch.BelongedFaction)) { sending.TargetArchitecture = oldLandedArch; } foreach (Person p in sending.Persons) { foreach (KeyValuePair<int, int> i in p.CommandDecrease) { if (GameObject.Chance(i.Key)) { receiving.Leader.BaseCommand -= i.Value; } } foreach (KeyValuePair<int, int> i in p.StrengthDecrease) { if (GameObject.Chance(i.Key)) { receiving.Leader.BaseStrength -= i.Value; } } foreach (KeyValuePair<int, int> i in p.IntelligenceDecrease) { if (GameObject.Chance(i.Key)) { receiving.Leader.BaseIntelligence -= i.Value; } } foreach (KeyValuePair<int, int> i in p.PoliticsDecrease) { if (GameObject.Chance(i.Key)) { receiving.Leader.BasePolitics -= i.Value; } } foreach (KeyValuePair<int, int> i in p.GlamourDecrease) { if (GameObject.Chance(i.Key)) { receiving.Leader.BaseGlamour -= i.Value; } } foreach (KeyValuePair<int, int> i in p.ReputationDecrease) { if (GameObject.Chance(i.Key)) { receiving.Leader.BaseReputation -= i.Value; } } foreach (KeyValuePair<int, int> i in p.LoseSkill) { if (GameObject.Chance(i.Key)) { for (int si = 0; si < i.Value; ++si) { if (receiving.Leader.Skills.Skills.Count > 0) { receiving.Leader.Skills.Skills.Remove(GameObject.Random(receiving.Leader.Skills.Skills.Count)); } } } } foreach (KeyValuePair<int, int> i in p.CommandIncrease) { if (GameObject.Chance(i.Key)) { p.BaseCommand += i.Value; } } foreach (KeyValuePair<int, int> i in p.StrengthIncrease) { if (GameObject.Chance(i.Key)) { p.BaseStrength += i.Value; } } foreach (KeyValuePair<int, int> i in p.IntelligenceIncrease) { if (GameObject.Chance(i.Key)) { p.BaseIntelligence += i.Value; } } foreach (KeyValuePair<int, int> i in p.PoliticsIncrease) { if (GameObject.Chance(i.Key)) { p.BasePolitics += i.Value; } } foreach (KeyValuePair<int, int> i in p.GlamourIncrease) { if (GameObject.Chance(i.Key)) { p.BaseGlamour += i.Value; } } foreach (KeyValuePair<int, int> i in p.ReputationIncrease) { if (GameObject.Chance(i.Key)) { p.BaseReputation += i.Value; } } } foreach (Person p in receiving.persons) { foreach (Person q in sending.persons) { if (p == q) continue; p.AdjustRelation(q, -0.5f / Math.Max(1, sending.persons.Count - 1), -3); } } receiving.BeRouted(); if (sending.Combativity < sending.Army.CombativityCeiling) { sending.IncreaseCombativity(10 + sending.RoutIncrementOfCombativity); if (sending.PreAction == TroopPreAction.无) { sending.PreAction = TroopPreAction.鼓舞; } } if (sending.Morale < sending.Army.MoraleCeiling) { sending.IncreaseMorale(5); if (sending.PreAction == TroopPreAction.无) { sending.PreAction = TroopPreAction.鼓舞; } } } }