private void OnConversationEnded(CharacterObject character) { PartyOrder partyOrder; if (character == null) { partyOrder = (PartyOrder)null; } else { Hero heroObject = character.HeroObject; partyOrder = heroObject != null?heroObject.getOrder() : (PartyOrder)null; } if (partyOrder == null) { return; } Hero heroObject1 = character.HeroObject; PartyOrder order = heroObject1.getOrder(); if (!heroObject1.IsPartyLeader) { return; } if (order.Behavior == AiBehavior.EscortParty) { heroObject1.PartyBelongedTo.SetMoveEscortParty(order.TargetParty); } heroObject1.PartyBelongedTo.Ai.RethinkAtNextHourlyTick = true; }
private static void Postfix( DefaultTargetScoreCalculatingModel __instance, Settlement settlement, MobileParty mobileParty, ref float __result) { PartyOrder partyOrder; if (mobileParty == null) { partyOrder = (PartyOrder)null; } else { Hero leaderHero = mobileParty.LeaderHero; partyOrder = leaderHero != null?leaderHero.getOrder() : (PartyOrder)null; } if (partyOrder == null) { return; } PartyOrder order = mobileParty.LeaderHero.getOrder(); if (settlement.OwnerClan == mobileParty.LeaderHero.Clan) { __result *= order.OwnClanVillagesScoreMultiplier; } else { __result *= order.FriendlyVillagesScoreMultiplier; } }
private static void Postfix(MobileParty __instance, Vec2 point) { if (!Input.IsKeyDown((InputKey)Config.Value.OrderEscortEngageHoldKey) || !__instance.IsMainParty) { return; } foreach (KeyValuePair <Hero, PartyOrder> order in PartyAICommandsBehavior.Instance.order_map) { Hero key = order.Key; PartyOrder partyOrder = order.Value; if (key != null && partyOrder != null && (key.PartyBelongedTo != null && partyOrder.Behavior == AiBehavior.EscortParty) && partyOrder.TargetParty == __instance) { MobileParty partyBelongedTo = key.PartyBelongedTo; float distance = Campaign.Current.Models.MapDistanceModel.GetDistance(__instance, partyBelongedTo); if ((double)distance < (double)partyBelongedTo.SeeingRange) { partyBelongedTo.SetMoveEscortParty(__instance); partyOrder.TempTargetParty = (MobileParty)null; } else if ((double)distance < (double)__instance.SeeingRange) { InformationManager.DisplayMessage(new InformationMessage(partyBelongedTo.Name?.ToString() + " can't see our signals!", Colors.Red)); } } } }
private static void Postfix(MobileParty __instance, MapEvent mapEvent) { PartyOrder partyOrder1; if (__instance == null) { partyOrder1 = (PartyOrder)null; } else { Hero leaderHero = __instance.LeaderHero; partyOrder1 = leaderHero != null?leaderHero.getOrder() : (PartyOrder)null; } if (partyOrder1 == null || __instance.LeaderHero.getOrder().Behavior != AiBehavior.EscortParty) { return; } foreach (KeyValuePair <Hero, PartyOrder> order in PartyAICommandsBehavior.Instance.order_map) { Hero key = order.Key; PartyOrder partyOrder2 = order.Value; if (key != null && partyOrder2 != null && (key.PartyBelongedTo != null && partyOrder2.Behavior == AiBehavior.EscortParty) && partyOrder2.TargetParty == MobileParty.MainParty) { key.PartyBelongedTo.SetMoveEscortParty(partyOrder2.TargetParty); partyOrder2.TempTargetParty = (MobileParty)null; } } }
public static void RegisterOrder(Hero leader, PartyOrder order) { if (PartyAICommandsBehavior.Instance.order_map == null) { PartyAICommandsBehavior.Instance.order_map = new Dictionary <Hero, PartyOrder>(); } PartyAICommandsBehavior.Instance.order_map[leader] = order; leader.PartyBelongedTo.SetInititave(order.AttackInitiative, order.AvoidInitiative, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow); }
public static void Postfix(MobileParty __instance, MobileParty party) { PartyOrder partyOrder1; if (party == null) { partyOrder1 = (PartyOrder)null; } else { Hero leaderHero = party.LeaderHero; partyOrder1 = leaderHero != null?leaderHero.getOrder() : (PartyOrder)null; } if (partyOrder1 != null && party.LeaderHero.getOrder().Behavior == AiBehavior.EscortParty && party.LeaderHero.getOrder().TargetParty == __instance) { party.SetMoveModeHold(); } else { if (!Input.IsKeyDown((InputKey)Config.Value.OrderEscortEngageHoldKey)) { return; } foreach (KeyValuePair <Hero, PartyOrder> order in PartyAICommandsBehavior.Instance.order_map) { Hero key = order.Key; PartyOrder partyOrder2 = order.Value; if (key != null && partyOrder2 != null && (key.PartyBelongedTo != null && partyOrder2.Behavior == AiBehavior.EscortParty) && partyOrder2.TargetParty == __instance) { MobileParty partyBelongedTo = key.PartyBelongedTo; float distance = Campaign.Current.Models.MapDistanceModel.GetDistance(__instance, partyBelongedTo); if ((double)distance < (double)partyBelongedTo.SeeingRange) { if (!FactionManager.IsAtWarAgainstFaction(party.MapFaction, __instance.MapFaction)) { partyBelongedTo.SetMoveEscortParty(__instance); } else { partyBelongedTo.SetMoveEngageParty(party); partyOrder2.TempTargetParty = party; } } else if ((double)distance < (double)__instance.SeeingRange) { InformationManager.DisplayMessage(new InformationMessage(partyBelongedTo.Name?.ToString() + " can't see our signals!", Colors.Red)); } } } } }
private void OnSettlementLeft(MobileParty party, Settlement settlement) { if (party != MobileParty.MainParty) { return; } foreach (KeyValuePair <Hero, PartyOrder> order in PartyAICommandsBehavior.Instance.order_map) { Hero key = order.Key; PartyOrder partyOrder = order.Value; if (key != null && partyOrder != null && (key.PartyBelongedTo != null && partyOrder.Behavior == AiBehavior.EscortParty) && (partyOrder.TargetParty == MobileParty.MainParty && partyOrder.TempTargetParty == null)) { key.PartyBelongedTo.SetMoveEscortParty(partyOrder.TargetParty); } } }
private void OnAfterSettlementEntered(MobileParty party, Settlement settlement, Hero hero) { if (party != MobileParty.MainParty) { return; } foreach (KeyValuePair <Hero, PartyOrder> order in PartyAICommandsBehavior.Instance.order_map) { Hero key = order.Key; PartyOrder partyOrder = order.Value; if (key != null && partyOrder != null && (key.PartyBelongedTo != null && partyOrder.Behavior == AiBehavior.EscortParty) && (partyOrder.TargetParty == MobileParty.MainParty && partyOrder.TempTargetParty == null)) { key.PartyBelongedTo.SetMoveGoToSettlement(settlement); Traverse.Create((object)key.PartyBelongedTo).Method("OnAiTickInternal").GetValue(); } } }
private static void Postfix( MobileParty __instance, float ____attackInitiative, float ____avoidInitiative, AiBehavior bestInitiativeBehavior, MobileParty bestInitiativeTargetParty, ref float bestInitiativeBehaviorScore, Vec2 avarageEnemyVec) { if (__instance == null) { return; } Hero leaderHero = __instance.LeaderHero; int num; if (leaderHero == null) { num = 0; } else { PartyOrder order = leaderHero.getOrder(); if (order == null) { num = 0; } else { int behavior = (int)order.Behavior; num = 1; } } if (num == 0 || bestInitiativeTargetParty == null || (__instance.IsJoiningArmy || bestInitiativeBehavior != AiBehavior.EngageParty) || !bestInitiativeTargetParty.IsBandit || __instance.LeaderHero.getOrder().Behavior != AiBehavior.PatrolAroundPoint && (__instance.LeaderHero.getOrder().Behavior != AiBehavior.EscortParty || (double)____attackInitiative <= 0.0)) { return; } Vec2 v = (bestInitiativeTargetParty.BesiegedSettlement != null ? bestInitiativeTargetParty.GetVisualPosition().AsVec2 : bestInitiativeTargetParty.Position2D) - __instance.Position2D; if ((double)bestInitiativeBehaviorScore >= 1.10000002384186 || (double)__instance.GetCachedPureSpeed() <= (double)bestInitiativeTargetParty.GetCachedPureSpeed() * 1.05 && (double)bestInitiativeTargetParty.Bearing.DotProduct(v) > 0.0) { return; } bestInitiativeBehaviorScore = 1.1f; }
private static void Postfix( MobileParty __instance, float ____attackInitiative, float ____avoidInitiative, MobileParty enemyParty, ref float avoidScore, ref float attackScore) { if (__instance == null) { return; } Hero leaderHero = __instance.LeaderHero; int num; if (leaderHero == null) { num = 0; } else { PartyOrder order = leaderHero.getOrder(); if (order == null) { num = 0; } else { int behavior = (int)order.Behavior; num = 1; } } if (num == 0 || __instance.IsJoiningArmy || (!enemyParty.IsLordParty || enemyParty.LeaderHero == null) || !enemyParty.LeaderHero.IsNoble) { return; } attackScore *= ____attackInitiative; avoidScore *= ____avoidInitiative; if ((double)attackScore < 1.0) { return; } avoidScore = 0.0f; }
private static void Postfix(Hero companion, EndCaptivityDetail detail) { if (companion.Clan != Hero.MainHero.Clan || companion.PartyBelongedTo != null && companion.PartyBelongedTo.Party.Owner == companion || ((companion != null ? companion.getOrder() : (PartyOrder)null) == null || !companion.IsAlive || companion.Clan.CommanderLimit <= companion.Clan.WarParties.Count <MobileParty>((Func <MobileParty, bool>)(p => !p.IsGarrison && !p.IsMilitia && !p.IsVillager && !p.IsCaravan)))) { return; } companion.ChangeState(Hero.CharacterStates.Active); MobilePartyHelper.CreateNewClanMobileParty(companion, companion.Clan, out bool _); if (companion.PartyBelongedTo == null) { return; } PartyOrder order = companion.getOrder(); if (order.Behavior == AiBehavior.EscortParty && (double)order.ScoreMinimum > 1.0) { companion.PartyBelongedTo.SetInititave(0.0f, 1f, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow); } else { companion.PartyBelongedTo.SetInititave(order.AttackInitiative, order.AvoidInitiative, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow); } }
private static bool Prefix(Hero prisoner, EndCaptivityDetail detail) { if (prisoner.Clan != Hero.MainHero.Clan || prisoner.PartyBelongedToAsPrisoner == null || (prisoner.IsActive || !prisoner.IsAlive) || prisoner.PartyBelongedTo != null && prisoner.PartyBelongedTo.Party.Owner == prisoner || detail != EndCaptivityDetail.ReleasedAfterBattle && detail != EndCaptivityDetail.ReleasedAfterPeace && detail != EndCaptivityDetail.RemovedParty || (prisoner.Clan.CommanderLimit <= prisoner.Clan.WarParties.Count <MobileParty>((Func <MobileParty, bool>)(p => !p.IsGarrison && !p.IsMilitia && !p.IsVillager && !p.IsCaravan)) || (double)prisoner.PartyBelongedToAsPrisoner.Position2D.DistanceSquared(MobileParty.MainParty.VisualPosition2DWithoutError) >= 25.0)) { return(true); } StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.EndCaptivityAction); PartyBase belongedToAsPrisoner = prisoner.PartyBelongedToAsPrisoner; IFaction faction = belongedToAsPrisoner != null ? belongedToAsPrisoner.MapFaction : (IFaction)CampaignData.NeutralFaction; Traverse.Create((object)CampaignEventDispatcher.Instance).Method("OnHeroPrisonerReleased", new Type[4] { typeof(Hero), typeof(PartyBase), typeof(IFaction), typeof(EndCaptivityDetail) }, (object[])null).GetValue((object)prisoner, (object)belongedToAsPrisoner, (object)faction, (object)detail); EndCaptivityActionPatch.SpawnPartyAtPosition(prisoner, MobileParty.MainParty.VisualPosition2DWithoutError); if (prisoner.PartyBelongedTo != null && (prisoner != null ? prisoner.getOrder() : (PartyOrder)null) != null) { PartyOrder order = prisoner.getOrder(); if (order.Behavior == AiBehavior.EscortParty && (double)order.ScoreMinimum > 1.0) { if ((double)Campaign.Current.Models.MapDistanceModel.GetDistance(prisoner.PartyBelongedTo, MobileParty.MainParty) > 15.0) { prisoner.PartyBelongedTo.SetInititave(0.0f, 1f, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow); } else { prisoner.PartyBelongedTo.SetInititave(order.AttackInitiative, order.AvoidInitiative, CampaignTime.YearsFromNow(100f).RemainingHoursFromNow); } prisoner.PartyBelongedTo.SetMoveEscortParty(order.TargetParty); } } return(false); }
private static bool Prefix( TroopRoster __instance, CharacterObject character, int count, int index, ref int __result) { PartyBase partyBase = Traverse.Create((object)__instance).Property <PartyBase>("OwnerParty").Value; if (partyBase?.MobileParty?.LeaderHero != null && partyBase.MobileParty.LeaderHero != Hero.MainHero && (partyBase?.MobileParty?.LeaderHero?.Clan == Hero.MainHero.Clan && partyBase.MapEvent != null && (partyBase.MapEvent.HasWinner && partyBase.MemberRoster != (TroopRoster)null) && (partyBase.PrisonRoster != (TroopRoster)null && character != null))) { Hero leaderHero = partyBase.MobileParty.LeaderHero; if (__instance == partyBase.MemberRoster) { if (partyBase.PartySizeLimit <= partyBase.NumberOfAllMembers) { __result = -1; return(false); } if (leaderHero.getTemplate() != (TroopRoster)null) { int troopCount = leaderHero.getTemplate().GetTroopCount(character); switch (troopCount) { case 0: __result = -1; break; case 1: return(true); default: if (troopCount - leaderHero.PartyBelongedTo.MemberRoster.GetTroopCount(character) > 0) { goto case 1; } else { break; } } __result = -1; return(false); } } else if (__instance == partyBase.PrisonRoster) { if (partyBase.PrisonerSizeLimit > partyBase.NumberOfPrisoners) { if (leaderHero != null) { PartyOrder order = leaderHero.getOrder(); int num1; if (order == null) { num1 = 0; } else { int num2 = order.StopTakingPrisoners ? 1 : 0; num1 = 1; } if (num1 == 0 || !leaderHero.getOrder().StopTakingPrisoners || character.IsHero) { goto label_18; } } else { goto label_18; } } __result = -1; return(false); } } label_18: return(true); }
private static void Postfix(MobileParty mobileParty, PartyThinkParams p) { PartyOrder partyOrder; if (mobileParty == null) { partyOrder = (PartyOrder)null; } else { Hero leaderHero = mobileParty.LeaderHero; partyOrder = leaderHero != null?leaderHero.getOrder() : (PartyOrder)null; } if (partyOrder == null) { return; } PartyOrder order = mobileParty.LeaderHero.getOrder(); foreach (KeyValuePair <AIBehaviorTuple, float> keyValuePair in p.AIBehaviorScores.ToList <KeyValuePair <AIBehaviorTuple, float> >()) { float num = keyValuePair.Value; IMapPoint party = keyValuePair.Key.Party; if (keyValuePair.Key.AiBehavior == AiBehavior.GoToSettlement) { if (!order.LeaveTroopsToGarrisonOtherClans) { num *= AiMilitaryBehaviorHourlyTickPatch.getDoNotReplenishGarrisonCorrectionMult(mobileParty, (Settlement)party); } p.AIBehaviorScores[keyValuePair.Key] = num * order.PartyMaintenanceScoreMultiplier; } else if (keyValuePair.Key.AiBehavior == AiBehavior.DefendSettlement || keyValuePair.Key.AiBehavior == AiBehavior.PatrolAroundPoint) { p.AIBehaviorScores[keyValuePair.Key] = ((Settlement)keyValuePair.Key.Party).OwnerClan != mobileParty.LeaderHero.Clan ? num * order.FriendlyVillagesScoreMultiplier : num * order.OwnClanVillagesScoreMultiplier; } else if (keyValuePair.Key.AiBehavior == AiBehavior.BesiegeSettlement || keyValuePair.Key.AiBehavior == AiBehavior.AssaultSettlement) { p.AIBehaviorScores[keyValuePair.Key] = num * order.HostileSettlementsScoreMultiplier; } else if (keyValuePair.Key.AiBehavior == AiBehavior.RaidSettlement) { if (!order.AllowRaidingVillages) { p.AIBehaviorScores[keyValuePair.Key] = 0.0f; } } else if (keyValuePair.Key.AiBehavior == AiBehavior.EngageParty) { InformationManager.DisplayMessage(new InformationMessage("EngageParty: " + keyValuePair.Key.Party.Name?.ToString() + " " + keyValuePair.Value.ToString())); } } if (mobileParty.IsDisbanding) { mobileParty.LeaderHero.cancelOrder(); } else { if (order.Behavior == AiBehavior.None) { return; } if (mobileParty.Army != null && mobileParty.Army.LeaderParty == Hero.MainHero.PartyBelongedTo) { mobileParty.LeaderHero.cancelOrder(); } else if (order.Behavior == AiBehavior.PatrolAroundPoint) { if (order.TargetSettlement == null) { int num = (int)MessageBox.Show("Patrol target settlement not set, please report this bug to the developer of Party Ai Overhaul."); } AIBehaviorTuple key = new AIBehaviorTuple((IMapPoint)order.TargetSettlement, order.Behavior); if (p.AIBehaviorScores.ContainsKey(key)) { p.AIBehaviorScores[key] = order.getScore(p.AIBehaviorScores[key]); } else { p.AIBehaviorScores.Add(key, order.getScore()); } } else { if (order.Behavior != AiBehavior.EscortParty) { return; } AIBehaviorTuple key = new AIBehaviorTuple((IMapPoint)order.TargetParty, order.Behavior); if (p.AIBehaviorScores.ContainsKey(key)) { p.AIBehaviorScores[key] = order.getScore(p.AIBehaviorScores[key]); } else { p.AIBehaviorScores.Add(key, order.getScore()); } if ((double)order.ScoreMinimum <= 1.0 || order.TargetParty != Hero.MainHero.PartyBelongedTo || mobileParty.GetNumDaysForFoodToLast() >= 3) { return; } InformationManager.DisplayMessage(new InformationMessage(mobileParty.Name?.ToString() + " is short on food.", Colors.Red)); } } }