public static int GetModifiedRelation(this Hero hero, Hero otherHero) { ExplainedNumber relationBetweenHeroes = new ExplainedNumber(CharacterRelationManager.GetHeroRelation(hero, otherHero), null, null); deGetPersonalityEffects(Campaign.Current.Models.DiplomacyModel is DefaultDiplomacyModel defaultDiplomacyModel ? defaultDiplomacyModel : new DefaultDiplomacyModel(), ref relationBetweenHeroes, hero, otherHero); return(MBMath.Round(MBMath.ClampFloat(relationBetweenHeroes.ResultNumber + (RelativesHelper.BloodRelatives(hero, otherHero) ? 30f : 0f), -100f, 100f))); }
//Adds the relation to the detrmained allies private void SetRelation(Hero alliedHero, int currentRelation, int newRelation, int rel, bool isLordParty) { int relationCap = FTRConfig.newInstance.FTRInitialize.RelationCap; int relToCap; if (relationCap > currentRelation) { if (relationCap >= newRelation) { CharacterRelationManager.SetHeroRelation(Hero.MainHero, alliedHero, newRelation); if (isLordParty == true) { CharacterRelationManager.SetHeroRelation(Hero.MainHero, alliedHero.Clan.Leader, newRelation); } RelationshipOutput(rel, newRelation, alliedHero.ToString()); } else { if (rel >= (relationCap - currentRelation)) { relToCap = relationCap - currentRelation; newRelation = currentRelation + relToCap; CharacterRelationManager.SetHeroRelation(Hero.MainHero, alliedHero, newRelation); if (isLordParty == true) { CharacterRelationManager.SetHeroRelation(Hero.MainHero, alliedHero.Clan.Leader, newRelation); } RelationshipOutput(relToCap, newRelation, alliedHero.ToString()); } } } }
public static void DetermineSupport(MakePeaceKingdomDecision __instance, ref float __result, Clan clan, DecisionOutcome possibleOutcome) { var test1 = new PeaceBarterable(__instance.Kingdom, __instance.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan); //InformationManager.DisplayMessage(new InformationMessage(__instance.FactionToMakePeaceWith.Name.ToString() + ":" + test1.ToString())); var shouldPeaceBeDeclared = (bool)possibleOutcome.GetType().GetField("ShouldPeaceBeDeclared", BindingFlags.Instance | BindingFlags.Public).GetValue(possibleOutcome); if (DiplomacySetting.Instance.EnableMakePeaceStrategyPlus) { var atWars = (from x in clan.Kingdom.Stances where x.IsAtWar && x.Faction1.IsKingdomFaction && x.Faction2.IsKingdomFaction select x).ToArray <StanceLink>(); //var plus = 2 * atWars.Length * (float)(new PeaceBarterable(__instance.Kingdom, __instance.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan)) * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence(); var plus = 1f; var settlementsOccupyed = DiplomacySetting.GetFactionSettlementOccupyedByFaction(clan.MapFaction, __instance.FactionToMakePeaceWith).Sum(a => a.IsCastle ? 2 : 3); plus *= settlementsOccupyed == 0 ? 0f : (float)Math.Sqrt(settlementsOccupyed); StanceLink stanceWith = clan.MapFaction.GetStanceWith(__instance.FactionToMakePeaceWith); var toDays = stanceWith.WarStartDate.ElapsedDaysUntilNow; //兼容旧档 if (toDays > 2000) { Traverse.Create(stanceWith).Property("WarStartDate").SetValue(CampaignTime.Now); toDays = stanceWith.WarStartDate.ElapsedDaysUntilNow; } var daysFactor = Math.Min(9, toDays < 20 ? 1 : toDays / 20f); var factor = Math.Max(0, daysFactor - plus); var clanMercy = clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 20; if (shouldPeaceBeDeclared) { __result += Math.Abs(__result) / 10 * (factor) + clanMercy; } else { // __result -= Math.Abs(__result) / 10 * (resultFactor) - clanMercy; } } if (__instance.ProposerClan == Clan.PlayerClan && DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision > 0 && __result >= 0) { var relation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader); relation = relation > 0 ? relation : 0; if (shouldPeaceBeDeclared) { __result += Math.Abs(__result) * DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision * relation / 100f; } else { __result -= Math.Abs(__result) * DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision / 10 * relation / 100f; } } }
private static void EscapedPrisoner()//Escaped Prisoner start { Hero mainhero = Hero.MainHero; Hero lord = Hero.FindAll((Hero tmp) => (tmp.Culture.StringId == mainhero.Culture.StringId) && tmp.IsAlive && !tmp.MapFaction.IsMinorFaction && tmp.IsPartyLeader && tmp.PartyBelongedTo.IsHolding == false).GetRandomElementInefficiently <Hero>(); if (lord != null) { Vec2 escapePosition = lord.PartyBelongedTo.Position2D; CharacterRelationManager.SetHeroRelation(mainhero, lord, -50); if (CSCharCreationOption.CSLocationOption == 9) { MobileParty.MainParty.Position2D = escapePosition; MapState mapstate; mapstate = (GameStateManager.Current.ActiveState as MapState); mapstate.Handler.TeleportCameraToMainParty(); } } //Using Looter gear as baseline CharacterObject characterObject = MBObjectManager.Instance.GetObject <CharacterObject>("looter"); Hero.MainHero.BattleEquipment.FillFrom(characterObject.Equipment); Hero.MainHero.CivilianEquipment.FillFrom(characterObject.Equipment); }
private bool game_menu_steal_encounter_threat_on_condition(MenuCallbackArgs args) { args.optionLeaveType = GameMenuOption.LeaveType.ForceToGiveGoods; //Option icon if (!isDetected) { return(false); } int relationCost = 50; if (Settlement.CurrentSettlement.Notables == null) { args.IsEnabled = false; args.Tooltip = new TextObject("There is no Gang Leader notables in this settlement.", null); } else { foreach (Hero notableHero in Settlement.CurrentSettlement.Notables) { if (notableHero.IsGangLeader && CharacterRelationManager.GetHeroRelation(Hero.MainHero, notableHero) > relationCost) { args.IsEnabled = true; return(true); } } args.IsEnabled = false; args.Tooltip = new TextObject("No Gang Leader notables in this settlmenet have a relation higher than " + relationCost + " with you.", null); } return(true); }
//Determains if AI parties relationship will be changed private void AddPlayerRelationshipWithLords(int rel, List <PartyBase> allyParties) { bool isLordParty = true; List <String> clans = new List <String>(); for (int i = 0; i <= allyParties.Count - 1; i++) { if (!clans.Contains(allyParties[i].Owner.Clan.ToString())) { clans.Add(allyParties[i].Owner.Clan.ToString()); } } //Setting the relation with allied partys leaders in battle for (int i = 0; i <= allyParties.Count - 1; i++) { if (clans != null && !allyParties[i].Owner.Equals(Hero.MainHero)) { if (clans.Contains(allyParties[i].Owner.Clan.ToString())) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, allyParties[i].Owner.Clan.Leader); int newRelation = currentRelation + rel; for (int k = 0; k <= allyParties.Count - 1; k++) { if (allyParties[i].Owner.Clan.Equals(allyParties[k].Owner.Clan) && !allyParties[k].Owner.Equals(Hero.MainHero)) { SetRelation(allyParties[k].Owner, currentRelation, newRelation, rel, isLordParty); } } clans.Remove(allyParties[i].Owner.Clan.ToString()); } } } }
//Determains if childrens relationship will be changed private void AddPlayerRelationshipWithChildren(int rel, List <PartyBase> parties, List <PartyBase> enemyParties, bool lostBattle) { bool isLordParty = false; List <Hero> children = new List <Hero>(Hero.MainHero.Children); List <Hero> childrenRemaining = new List <Hero>(Hero.MainHero.Children); //Adds relation to children if they are in your party and you won for (int i = 0; i <= children.Count - 1; i++) { if (!children[i].IsChild && PartyBase.MainParty.MemberRoster.Contains(children[i].CharacterObject)) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, children[i]); int newRelation = currentRelation + rel; childrenRemaining.Remove(children[i]); SetRelation(children[i], currentRelation, newRelation, rel, isLordParty); } } //Adds relation to children if they are leading own party in battle if (childrenRemaining.Count > 0) { for (int i = 0; i <= parties.Count - 1; i++) { for (int k = 0; i <= children.Count - 1; i++) { if (!children[i].IsChild && parties[i].ToString().Equals(children[k].ToString() + "'s Party")) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, children[k]); int newRelation = currentRelation + rel; childrenRemaining.Remove(children[k]); SetRelation(children[k], currentRelation, newRelation, rel, isLordParty); } } } } //Adds relation to children if battle is lost and they have been taken prisoner if (childrenRemaining.Count > 0 && enemyParties.Count > 0 && lostBattle == true) { for (int i = 0; i <= enemyParties.Count - 1; i++) { if (!enemyParties[i].Equals(PartyBase.MainParty)) { enemyParties[i].LeaderHero.SyncLastSeenInformation(); for (int j = 0; j <= childrenRemaining.Count - 1; j++) { if (!childrenRemaining[j].IsChild) { childrenRemaining[j].SyncLastSeenInformation(); if (enemyParties[i].LeaderHero.GetMapPoint().Equals(childrenRemaining[j].GetMapPoint())) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, childrenRemaining[j]); int newRelation = currentRelation + rel; SetRelation(childrenRemaining[j], currentRelation, newRelation, rel, isLordParty); } } } } } } }
private void OnHourlyTickEvent(MobileParty mobileParty) { Hero companion = mobileParty.LeaderHero; if (mobileParty == MobileParty.MainParty || companion == null || !mobileParty.IsLordParty || companion.Clan != Clan.PlayerClan) { return; } Settlement target = mobileParty.TargetSettlement; if (mobileParty.DefaultBehavior != AiBehavior.PatrolAroundPoint || target.OwnerClan != Clan.PlayerClan) { return; } if (mobileParty.Position2D.DistanceSquared(target.Position2D) > MinPatrolDistance) { //InformationManager.DisplayMessage(new InformationMessage(companion.Name + " too far away from " + target.Name)); mobileParty.SetMoveGoToSettlement(target); return; } //InformationManager.DisplayMessage(new InformationMessage(companion.Name + " patrolling around " + target.Name)); int companion_relation; foreach (Hero notable in target.Notables) { companion_relation = CharacterRelationManager.GetHeroRelation(companion, notable) + 1; if (companion_relation % HoursRequirement == 0) { // reset companion personal relation companion_relation = 0; // increase player relation int oldRelation = notable.GetRelation(Hero.MainHero); ChangeRelationAction.ApplyPlayerRelation(notable, 1, false, false); int newRelation = notable.GetRelation(Hero.MainHero); int relation_change = newRelation - oldRelation; if (relation_change > 0) { TextObject textObject = GameTexts.FindText("str_your_relation_increased_with_notable", null); TextObject heroText = new TextObject(); ZenDzeeCompatibilityHelper.SetTextVariable(heroText, "NAME", notable.Name); ZenDzeeCompatibilityHelper.SetTextVariable(textObject, "HERO", heroText); ZenDzeeCompatibilityHelper.SetTextVariable(textObject, "VALUE", newRelation); ZenDzeeCompatibilityHelper.SetTextVariable(textObject, "MAGNITUDE", relation_change); InformationManager.DisplayMessage(new InformationMessage(textObject.ToString())); } } CharacterRelationManager.SetHeroRelation(companion, notable, companion_relation); } }
//Determains if companions relationship will be changed private void AddPlayerRelationshipWithCompanions(int rel, List <PartyBase> parties, List <PartyBase> enemyParties, bool lostBattle) { bool isLordParty = false; List <Hero> companionsInParty = new List <Hero>(Hero.MainHero.CompanionsInParty.ToList <Hero>()); List <Hero> clanCompanions = new List <Hero>(Clan.PlayerClan.Companions.ToList <Hero>()); List <Hero> clanCompanionsRemaining = new List <Hero>(Clan.PlayerClan.Companions.ToList <Hero>()); //Adds relation to companions if they are in your party and you won if (companionsInParty != null && companionsInParty.Count > 0) { for (int i = 0; i <= companionsInParty.Count - 1; i++) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, companionsInParty[i]); int newRelation = currentRelation + rel; clanCompanionsRemaining.Remove(companionsInParty[i]); SetRelation(companionsInParty[i], currentRelation, newRelation, rel, isLordParty); } } //Adds relation to companions if they are leading own party in battle if (clanCompanionsRemaining.Count > 0) { for (int i = 0; i <= parties.Count - 1; i++) { for (int j = 0; j <= clanCompanions.Count - 1; j++) { if (parties[i].ToString().Equals(clanCompanions[j].ToString() + "'s Party")) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, clanCompanions[j]); int newRelation = currentRelation + rel; clanCompanionsRemaining.Remove(clanCompanions[j]); SetRelation(clanCompanions[j], currentRelation, newRelation, rel, isLordParty); } } } } //Adds relation to companions if battle is lost and they have been taken prisoner if (clanCompanionsRemaining.Count > 0 && enemyParties.Count > 0 && lostBattle == true) { for (int i = 0; i <= enemyParties.Count - 1; i++) { if (!enemyParties[i].Equals(PartyBase.MainParty)) { enemyParties[i].Owner.SyncLastSeenInformation(); for (int j = 0; j <= clanCompanionsRemaining.Count - 1; j++) { clanCompanionsRemaining[j].SyncLastSeenInformation(); if (enemyParties[i].Owner.GetMapPoint().Equals(clanCompanionsRemaining[j].GetMapPoint())) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, clanCompanionsRemaining[j]); int newRelation = currentRelation + rel; SetRelation(clanCompanionsRemaining[j], currentRelation, newRelation, rel, isLordParty); } } } } } }
public static int GetExpectGoldCostOfRelation(Clan clan, int relation) { var now = CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader); var end = (now + relation) > 100 ? 100 : now + relation; var cost = (end < 0 ? -1 : 1) * end * end * 10 - (now < 0 ? -1 : 1) * now * now * 10; return(cost); }
private void ApplyAddRelation(Hero hero, Clan clan, int daysToNow) { var relation = GetExpectRelation(hero, clan, daysToNow); var cost = GetExpectGoldCostOfRelation(clan, relation); if (Hero.MainHero.Gold > cost * 1.2 && CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader) < 100) { ChangeRelationAction.ApplyPlayerRelation(clan.Leader, GetExpectRelation(hero, clan, daysToNow, false)); GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, clan.Leader, cost); } }
private static void SetVassal(Hero hero) { //Find a clan that matches culture string culture = hero.Culture.StringId; Hero lord = Hero.FindAll((Hero tmp) => (tmp.Culture.StringId == hero.Culture.StringId) && tmp.IsAlive && tmp.IsFactionLeader && !tmp.MapFaction.IsMinorFaction).GetRandomElementInefficiently <Hero>(); if (lord != null) //Adding to prevent crash on custom cultures with no kingdom { Clan targetclan = lord.Clan; CharacterRelationManager.SetHeroRelation(hero, lord, 10); ChangeKingdomAction.ApplyByJoinToKingdom(hero.Clan, targetclan.Kingdom, false); GainKingdomInfluenceAction.ApplyForJoiningFaction(hero, 10f); } }
private static void ApplyInternal(Hero hero, Hero toHero, int relation, int cap, bool showQuickNotification = true) { if (!MercenarySettings.Instance.ApplyRelationshipRulesToNPC && hero != Hero.MainHero) { return; } //var contractorKingdomHeroRelation = hero.GetRelation(toHero); var contractorKingdomHeroRelation = CharacterRelationManager.GetHeroRelation(hero, toHero); if (contractorKingdomHeroRelation + relation < cap) { ChangeRelationAction.ApplyRelationChangeBetweenHeroes(hero, toHero, relation, showQuickNotification && hero == Hero.MainHero); } }
private static void ExiledDmgRelation() { Hero mainhero = Hero.MainHero; Hero lord = Hero.FindAll((Hero tmp) => (tmp.Culture.StringId == mainhero.Culture.StringId) && tmp.IsAlive && tmp.IsFactionLeader && !tmp.MapFaction.IsMinorFaction).GetRandomElement <Hero>(); CharacterRelationManager.SetHeroRelation(mainhero, lord, -50); foreach (Hero alllord in Hero.FindAll((alllord) => (alllord.MapFaction == lord.MapFaction) && alllord.IsAlive)) { CharacterRelationManager.SetHeroRelation(mainhero, alllord, -5); } ; CharacterRelationManager.SetHeroRelation(mainhero, lord, -50); ChangeCrimeRatingAction.Apply(lord.MapFaction, 49, false); //float test = Campaign.Current. }
//Determains if spouse relationship will be changed private void AddPlayerRelationshipWithSpouse(int rel, List <PartyBase> parties, List <PartyBase> enemyParties, bool lostBattle) { bool setSpouse = false; bool isLordParty = false; //Adds relation to spouse if they are in your party and you won if (PartyBase.MainParty.MemberRoster.Contains(Hero.MainHero.Spouse.CharacterObject)) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, Hero.MainHero.Spouse); int newRelation = currentRelation + rel; setSpouse = true; SetRelation(Hero.MainHero.Spouse, currentRelation, newRelation, rel, isLordParty); } //Adds relation to spouse if they are leading own party in battle if (setSpouse != true) { for (int i = 0; i <= parties.Count - 1; i++) { if (parties[i].ToString().Equals(Hero.MainHero.Spouse.ToString() + "'s Party")) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, Hero.MainHero.Spouse); int newRelation = currentRelation + rel; setSpouse = true; SetRelation(Hero.MainHero.Spouse, currentRelation, newRelation, rel, isLordParty); } } } //Adds relation to spouse if battle is lost and they have been taken prisoner if (setSpouse != true && enemyParties.Count > 0 && lostBattle == true) { Hero.MainHero.Spouse.SyncLastSeenInformation(); for (int i = 0; i <= enemyParties.Count - 1; i++) { if (!enemyParties[i].Equals(PartyBase.MainParty)) { enemyParties[i].LeaderHero.SyncLastSeenInformation(); if (Hero.MainHero.Spouse.GetMapPoint().Equals(enemyParties[i].LeaderHero.GetMapPoint())) { int currentRelation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, Hero.MainHero.Spouse); int newRelation = currentRelation + rel; SetRelation(Hero.MainHero.Spouse, currentRelation, newRelation, rel, isLordParty); } } } } }
private static IEnumerable <Clan> FriendlyClans(Clan destroyedClan) { // Find a friendly clan in the same kingdom var originClanLeader = destroyedClan.Leader; var originKingdom = destroyedClan.Kingdom; if (originKingdom == null || originKingdom.IsEliminated || originClanLeader == null) { return(null); } return(originKingdom.Clans.Where(c => !c.IsEliminated && c.Leader.IsAlive && !c.IsUnderMercenaryService && c.Leader != Hero.MainHero && c.Leader.IsFriend(originClanLeader) && c.Heroes.Where(x => x.IsChild).ToList().Count < ChildrenLimitPerClan ) .OrderBy(clan => clan.Heroes.Where(x => x.IsChild).ToList().Count) .ThenBy(clan => CharacterRelationManager.GetHeroRelation(originClanLeader, clan.Leader)) .ToList()); }
/*****************/ /*** RELATIONS ***/ /*****************/ /*** Change Relation ***/ public static void ChangeRelation(Hero lord1, Hero lord2, int change) { if (lord1 != null && lord2 != null) { int relation = CharacterRelationManager.GetHeroRelation(lord1, lord2) + change; if (relation > 100) { relation = 100; } else { if (relation < -100) { relation = -100; } } CharacterRelationManager.SetHeroRelation(lord1, lord2, relation); } }
public static void ChangeRelation(Hero lord1, Hero lord2, int change) { bool flag = lord1 != null && lord2 != null; if (flag) { int num = CharacterRelationManager.GetHeroRelation(lord1, lord2) + change; bool flag2 = num > 100; if (flag2) { num = 100; } else { bool flag3 = num < -100; if (flag3) { num = -100; } } CharacterRelationManager.SetHeroRelation(lord1, lord2, num); } }
private void UpdatePersonalRelation(Hero baseHero, Hero otherHero, int relationChange) { int newValue = MBMath.ClampInt(CharacterRelationManager.GetHeroRelation(baseHero, otherHero) + relationChange, -100, 100); CharacterRelationManager.SetHeroRelation(baseHero, otherHero, newValue); }
public static bool Prefix(Hero otherHero, Hero __instance, ref bool __result) { __result = CharacterRelationManager.GetHeroRelation(__instance, otherHero) > SeparatismConfig.Settings.FriendThreshold; return(false); }