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 void OnPlayerWinTournament() { if (Campaign.Current.GameMode != CampaignGameMode.Campaign) { return; } GainRenownAction.Apply(Hero.MainHero, this._tournamentGame.TournamentWinRenown, false); if (Hero.MainHero.MapFaction.IsKingdomFaction && Hero.MainHero.MapFaction.Leader != Hero.MainHero) { GainKingdomInfluenceAction.ApplyForDefault(Hero.MainHero, 1f); } Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(this._tournamentGame.Prize, 1, true); if (this.OverallExpectedDenars > 0) { GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.OverallExpectedDenars, false); } Campaign.Current.TournamentManager.OnPlayerWinTournament(this._tournamentGame.GetType()); }
//REVISIT - convert to transpiler patch to just change our prize payment // All we really need to change is instead of giving an ItemObject - which has no ItemModifers, we give them an ItemRosterEquipement, which can have ItemModifiers private static bool Prefix(ref TournamentBehavior __instance) { //Override Standard behavior if (Campaign.Current.GameMode != CampaignGameMode.Campaign) { return(false); } /* Give Gold, Influence, Renown */ if (__instance.OverallExpectedDenars > 0) { GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, __instance.OverallExpectedDenars, false); } GainRenownAction.Apply(Hero.MainHero, __instance.TournamentGame.TournamentWinRenown, false); if (Hero.MainHero.MapFaction.IsKingdomFaction && Hero.MainHero.MapFaction.Leader != Hero.MainHero) { GainKingdomInfluenceAction.ApplyForDefault(Hero.MainHero, TournamentPrizePoolBehavior.TournamentReward.BonusInfluence); } /* Give Item Prize */ if (!TournamentXPSettings.Instance.EnableItemModifiersForPrizes) { if (!TournamentPrizePoolBehavior.TournamentReward.PrizeGiven) { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true); TournamentPrizePoolBehavior.TournamentReward.PrizeGiven = true; } } else { TournamentPrizePool currentPool = null; string prizeStringId = ""; try { if (!TournamentPrizePoolBehavior.TournamentReward.PrizeGiven) { currentPool = TournamentPrizePoolBehavior.GetTournamentPrizePool(__instance.Settlement); prizeStringId = __instance.TournamentGame.Prize.StringId; //Beta1.2 #if VERSION120 Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(currentPool.Prizes.Where(x => x.EquipmentElement.Item.StringId == prizeStringId).First().EquipmentElement, 1, true); #endif //Release1.1.1 #if VERSION111 Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(currentPool.Prizes.Where(x => x.EquipmentElement.Item.StringId == prizeStringId).First(), 1, true); #endif TournamentPrizePoolBehavior.TournamentReward.PrizeGiven = true; } } catch (Exception ex) { ErrorLog.Log("ERROR: Tournament XPanded: OnPlayerWinTournament\nError Awarding Prize"); ErrorLog.Log("TournamentPrizePool:\n"); if (currentPool != null) { ErrorLog.Log(Newtonsoft.Json.JsonConvert.SerializeObject(currentPool)); } ErrorLog.Log(ex.ToStringFull()); if (!TournamentPrizePoolBehavior.TournamentReward.PrizeGiven) { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true); TournamentPrizePoolBehavior.TournamentReward.PrizeGiven = true; } } } Campaign.Current.TournamentManager.OnPlayerWinTournament(__instance.TournamentGame.GetType()); return(false); }
//REVISIT - convert to transpiler patch to just change our prize payment // All we really need to change is instead of giving an ItemObject - which has no ItemModifers, we give them an ItemRosterEquipement, which can have ItemModifiers private static bool Prefix(ref TournamentBehavior __instance) { //Override Standard behavior if (Campaign.Current.GameMode != CampaignGameMode.Campaign) { return(false); } var tournamentInfo = TournamentsXPandedBehavior.GetTournamentInfo(__instance.TournamentGame.Town); var settlement = __instance.Settlement; /* Give Gold, Influence, Renown */ if (__instance.OverallExpectedDenars > 0) { GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, __instance.OverallExpectedDenars, false); } GainRenownAction.Apply(Hero.MainHero, __instance.TournamentGame.TournamentWinRenown, false); if (Hero.MainHero.MapFaction.IsKingdomFaction && Hero.MainHero.MapFaction.Leader != Hero.MainHero) { GainKingdomInfluenceAction.ApplyForDefault(Hero.MainHero, tournamentInfo.Rewards.BonusInfluence); } /* Give Reputation */ try { if (TournamentXPSettings.Instance.BonusReputationForTournamentWin > 0) { List <Hero> heros = new List <Hero>(); foreach (var n in settlement.Notables) { if (!heros.Contains(n)) { heros.Add(n); } } foreach (var v in settlement.BoundVillages) { foreach (var n in v.Settlement.Notables) { if (!heros.Contains(n)) { heros.Add(n); } } } if (settlement.OwnerClan.Heroes.Any <Hero>()) { foreach (var n in settlement.OwnerClan.Heroes) { if (!heros.Contains(n)) { heros.Add(n); } } } if (settlement.HeroesWithoutParty.Count > 0) { foreach (var n in settlement.HeroesWithoutParty) { if (!heros.Contains(n)) { heros.Add(n); } } } foreach (var h in heros) { if (MBRandom.RandomFloat < .51f) { ChangeRelationAction.ApplyPlayerRelation(h, TournamentXPSettings.Instance.BonusReputationForTournamentWin, true, false); } } } MBTextManager.SetTextVariable("RELATION_VALUE", TournamentXPSettings.Instance.BonusReputationForTournamentWin, false); InformationManager.AddQuickInformation(new TextObject("{=o0qwDa0q}Your relation increased by {RELATION_VALUE} with nearby notables.", null), 0, null, ""); } catch (Exception ex) { ErrorLog.Log("Error giving Reputation:\n" + ex.ToStringFull()); } /* Give Item Prize */ if (!TournamentXPSettings.Instance.EnableItemModifiersForPrizes) { if (!tournamentInfo.Rewards.PrizeGiven) { try { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true); tournamentInfo.Rewards.PrizeGiven = true; } catch (Exception ex) { ErrorLog.Log("Error assigning prize\n" + ex.ToStringFull()); } } } else { try { if (!tournamentInfo.Rewards.PrizeGiven) { try { if (!String.IsNullOrWhiteSpace(tournamentInfo.SelectedPrizeStringId)) { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(tournamentInfo.SelectedPrizeItem.ToItemRosterElement().EquipmentElement, 1, true); tournamentInfo.Rewards.PrizeGiven = true; } } catch (Exception ex) { ErrorLog.Log("Error assigning prize\n" + ex.ToStringFull()); } } } catch (Exception ex) { ErrorLog.Log("ERROR: Tournament XPanded: OnPlayerWinTournament\nError Awarding Prize"); ErrorLog.Log("TournamentPrizePool:\n"); if (tournamentInfo != null) { ErrorLog.Log(Newtonsoft.Json.JsonConvert.SerializeObject(tournamentInfo)); } ErrorLog.Log(ex.ToStringFull()); } } if (!tournamentInfo.Rewards.PrizeGiven) { try { Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(__instance.TournamentGame.Prize, 1, true); tournamentInfo.Rewards.PrizeGiven = true; } catch (Exception ex2) { ErrorLog.Log("Error assigning prize\n" + ex2.ToStringFull()); } } tournamentInfo.ReRollsUsed = 0; Campaign.Current.TournamentManager.OnPlayerWinTournament(__instance.TournamentGame.GetType()); return(false); }