public void OnSessionLaunched(CampaignGameStarter campaignGameStarter) { foreach (Hero hero in Hero.All.ToList()) { if (Hero.MainHero.Children.Contains(hero)) { MAHelper.OccupationToLord(hero.CharacterObject); hero.Clan = null; hero.Clan = Clan.PlayerClan; } } AddDialogs(campaignGameStarter); }
public void OnSessionLaunched(CampaignGameStarter campaignGameStarter) { foreach (Hero hero in Hero.All.ToList()) { // The old fix for occupations not sticking if (hero.Spouse == Hero.MainHero || Hero.MainHero.ExSpouses.Contains(hero)) { MAHelper.OccupationToLord(hero.CharacterObject); hero.Clan = null; hero.Clan = Clan.PlayerClan; } } AddDialogs(campaignGameStarter); }
private void conversation_adopt_child_on_consequence() { // Similar system from Recruit Everyone if (_notAdoptableAgents is not null) { _notAdoptableAgents.Add(_agent); } Agent agent = (Agent)Campaign.Current.ConversationManager.OneToOneConversationAgent; CharacterObject character = CharacterObject.OneToOneConversationCharacter; // Add a bit of the DeliverOffspring method into the mix Hero hero = HeroCreator.CreateSpecialHero(character, Settlement.CurrentSettlement, null, null, (int)agent.Age); int becomeChildAge = Campaign.Current.Models.AgeModel.BecomeChildAge; CharacterObject characterObject = CharacterObject.ChildTemplates.FirstOrDefault((CharacterObject t) => t.Culture == character.Culture && t.Age <= becomeChildAge && t.IsFemale == character.IsFemale && t.Occupation == Occupation.Lord); if (characterObject is not null) { Equipment equipment = characterObject.FirstCivilianEquipment.Clone(false); Equipment equipment2 = new(false); equipment2.FillFrom(equipment, false); EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment); EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment2); } MAHelper.OccupationToLord(hero.CharacterObject); hero.Clan = Clan.PlayerClan; AccessTools.Method(typeof(HeroDeveloper), "CheckInitialLevel").Invoke(hero.HeroDeveloper, null); hero.CharacterObject.IsFemale = character.IsFemale; BodyProperties bodyPropertiesValue = agent.BodyPropertiesValue; AccessTools.Property(typeof(Hero), "StaticBodyProperties").SetValue(hero, bodyPropertiesValue.StaticProperties); // Selects player as the parent if (Hero.MainHero.IsFemale) { hero.Mother = Hero.MainHero; } else { hero.Father = Hero.MainHero; } hero.IsNoble = true; hero.HasMet = true; // Too much work to try and implement the log /* * CharacterAdoptedLogEntry characterAdoptedLogEntry = new(hero, Hero.MainHero); * Campaign.Current.CampaignInformationManager.NewMapNoticeAdded(new AdoptionMapNotification(hero, Hero.MainHero, characterAdoptedLogEntry.GetEncyclopediaText())); */ // Cool idea. Might put this into Recruit Everyone, too! AccessTools.Field(typeof(Agent), "_name").SetValue(agent, hero.Name); OnHeroAdopted(Hero.MainHero, hero); // Follows you! I like this feature :3 Campaign.Current.ConversationManager.ConversationEndOneShot += FollowMainAgent; int heroComesOfAge = Campaign.Current.Models.AgeModel.HeroComesOfAge; var instance = Traverse.Create <CampaignEventDispatcher>().Property("Instance").GetValue <CampaignEventDispatcher>(); if (hero.Age > becomeChildAge || (hero.Age == becomeChildAge && hero.BirthDay.GetDayOfYear < CampaignTime.Now.GetDayOfYear)) { // CampaignEventDispatcher.Instance.OnHeroGrowsOutOfInfancy(hero); Traverse.Create(instance).Method("OnHeroGrowsOutOfInfancy", new Type[] { typeof(Hero) }).GetValue(new object[] { hero }); } if (hero.Age > heroComesOfAge || (hero.Age == heroComesOfAge && hero.BirthDay.GetDayOfYear < CampaignTime.Now.GetDayOfYear)) { // CampaignEventDispatcher.Instance.OnHeroComesOfAge(hero); Traverse.Create(instance).Method("OnHeroComesOfAge", new Type[] { typeof(Hero) }).GetValue(new object[] { hero }); } }
private void conversation_courtship_success_on_consequence() { ISettingsProvider settings = new MASettings(); Hero hero = Hero.MainHero; Hero spouse = Hero.OneToOneConversationHero; Hero oldSpouse = hero.Spouse; Hero cheatedSpouse = spouse.Spouse; // If you are marrying a kingdom ruler as a kingdom ruler yourself, // the kingdom ruler will have to give up being clan head. // Apparently causes issues if this is not done. if (spouse.IsFactionLeader && !spouse.IsMinorFactionHero) { if (hero.Clan.Kingdom != spouse.Clan.Kingdom) { if (hero.Clan.Kingdom?.Leader != hero) { // Join kingdom due to lowborn status if (hero.Clan.Leader == Hero.MainHero) { ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(hero.Clan); if (hero.Clan.Leader == Hero.MainHero) { MAHelper.Print("No Heirs"); DestroyClanAction.Apply(hero.Clan); MAHelper.Print("Eliminated Player Clan"); } } foreach (Hero companion in hero.Clan.Companions.ToList()) { bool inParty = false; if (companion.PartyBelongedTo == MobileParty.MainParty) { inParty = true; } RemoveCompanionAction.ApplyByFire(hero.Clan, companion); AddCompanionAction.Apply(spouse.Clan, companion); if (inParty) { AddHeroToPartyAction.Apply(companion, MobileParty.MainParty, true); } } hero.Clan = spouse.Clan; var current = Traverse.Create <Campaign>().Property("Current").GetValue <Campaign>(); Traverse.Create(current).Property("PlayerDefaultFaction").SetValue(spouse.Clan); MAHelper.Print("Lowborn Player Married to Kingdom Ruler"); } else { ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(spouse.Clan); MAHelper.Print("Kingdom Ruler Stepped Down and Married to Player"); } } } // New nobility MAHelper.OccupationToLord(spouse.CharacterObject); if (!spouse.IsNoble) { spouse.IsNoble = true; MAHelper.Print("Spouse to Noble"); } // Dodge the party crash for characters part 1 bool dodge = false; if (spouse.PartyBelongedTo == MobileParty.MainParty) { AccessTools.Property(typeof(Hero), "PartyBelongedTo").SetValue(spouse, null, null); MAHelper.Print("Spouse Already in Player's Party"); dodge = true; } // Apply marriage ChangeRomanticStateAction.Apply(hero, spouse, Romance.RomanceLevelEnum.Marriage); MAHelper.Print("Marriage Action Applied"); if (oldSpouse is not null) { MAHelper.RemoveExSpouses(oldSpouse); } // Dodge the party crash for characters part 2 if (dodge) { AccessTools.Property(typeof(Hero), "PartyBelongedTo").SetValue(spouse, MobileParty.MainParty, null); } // Activate character if not already activated if (!spouse.HasMet) { spouse.HasMet = true; } if (!spouse.IsActive) { spouse.ChangeState(Hero.CharacterStates.Active); MAHelper.Print("Activated Spouse"); } if (spouse.IsPlayerCompanion) { spouse.CompanionOf = null; MAHelper.Print("Spouse No Longer Companion"); } if (settings.Cheating && cheatedSpouse is not null) { MAHelper.RemoveExSpouses(cheatedSpouse, true); MAHelper.RemoveExSpouses(spouse, true); MAHelper.Print("Spouse Broke Off Past Marriage"); } MAHelper.RemoveExSpouses(hero); MAHelper.RemoveExSpouses(spouse); PlayerEncounter.LeaveEncounter = true; // New fix to stop some kingdom rulers from disappearing if (spouse.PartyBelongedTo != MobileParty.MainParty) { AddHeroToPartyAction.Apply(spouse, MobileParty.MainParty, true); } }