private static readonly FieldInfo IsBattleEncounteredField = AccessTools.Field(HeroBehaviorsStructType, "IsBattleEncountered"); // type: bool //static bool Prefix(DynamicBodyCampaignBehavior __instance, ref Dictionary<Hero, object> ____heroBehaviorsDictionary) static bool Prefix(DynamicBodyCampaignBehavior __instance) { IDictionary dictionary = (IDictionary)AccessTools.Field(typeof(DynamicBodyCampaignBehavior), "_heroBehaviorsDictionary").GetValue(__instance); foreach (var hero in dictionary.Keys.Cast <Hero>()) { //This is probably invalid because the bandit soldier is not a hero object if (hero.IsChild && hero.MapFaction.IsBanditFaction) { float banditAge = 21; hero.SetBirthDay(HeroHelper.GetRandomBirthDayForAge((int)banditAge)); DynamicBodyProperties banditDynamicBodyProperties = new DynamicBodyProperties(hero.Age, hero.Weight, hero.Build); BodyProperties banditBodyProperties = new BodyProperties(banditDynamicBodyProperties, hero.BodyProperties.StaticProperties); hero.CharacterObject.UpdatePlayerCharacterBodyProperties(banditBodyProperties, hero.IsFemale); } if (!hero.IsChild && (hero.IsHumanPlayerCharacter || hero.IsPlayerCompanion)) { float heroAge = hero.Age + 0.0119047f; DynamicBodyProperties dynamicBodyProperties = new DynamicBodyProperties(heroAge, hero.Weight, hero.Build); BodyProperties heroBodyProperties = new BodyProperties(dynamicBodyProperties, hero.BodyProperties.StaticProperties); hero.CharacterObject.UpdatePlayerCharacterBodyProperties(heroBodyProperties, hero.IsFemale); } } return(false); }
public override void OnBeforeSave() { if (Game.Current == null || !(Game.Current.GameType is Campaign)) { return; } //CampaignTime deltaTime = CampaignTime.Now - TimeSinceLastSave; CampaignTime deltaTime = GetDeltaTime(true); //double yearsElapsed = deltaTime.ToYears; //TimeSinceLastSave = CampaignTime.Now; foreach (Hero hero in Game.Current.ObjectManager.GetObjectTypeList <Hero>()) { //TODO:: Why is this conflicting now??? /*ddouble newAge = hero.Age + yearsElapsed; * DynamicBodyProperties dynamicBodyProperties = new DynamicBodyProperties((float)newAge, hero.Weight, hero.Build);*/ DynamicBodyProperties dynamicBodyProperties = new DynamicBodyProperties(hero.Age, hero.Weight, hero.Build); BodyProperties heroBodyProperties = new BodyProperties(dynamicBodyProperties, hero.BodyProperties.StaticProperties); //BodyProperties heroBodyProperties = hero.BodyProperties; //CharacterBodyManager.CopyDynamicBodyProperties(dynamicBodyProperties, heroBodyProperties.DynamicProperties); hero.CharacterObject.UpdatePlayerCharacterBodyProperties(heroBodyProperties, hero.IsFemale); if (hero.IsHumanPlayerCharacter && DCCSettings.Instance != null && DCCSettings.Instance.DebugMode) { InformationManager.DisplayMessage(new InformationMessage(GetFormattedAgeDebugMessage(hero, hero.Age), ColorManager.Red)); } } }
//static bool Prefix(DynamicBodyCampaignBehavior __instance, ref Dictionary<Hero, object> ____heroBehaviorsDictionary) static bool Prefix(DynamicBodyCampaignBehavior __instance) { if (DCCSettings.Instance != null && DCCSettings.Instance.IgnoreDailyTick) { IDictionary dictionary = (IDictionary)AccessTools.Field(typeof(DynamicBodyCampaignBehavior), "_heroBehaviorsDictionary").GetValue(__instance); CampaignTime deltaTime = CampaignTime.Now - SubModule.TimeSinceLastSave; double yearsElapsed = deltaTime.ToYears; SubModule.TimeSinceLastSave = CampaignTime.Now; foreach (DictionaryEntry heroBehaviors in dictionary) { Hero hero = (Hero)heroBehaviors.Key; if (!DCCSettings.Instance.DisableAutoAging) { if (hero.IsHumanPlayerCharacter && DCCSettings.Instance.DebugMode) { InformationManager.DisplayMessage(new InformationMessage(DebugSetAppearanceMsg.ToString() + hero.Name, ColorManager.Red)); var test = new DynamicBodyProperties(hero.DynamicBodyProperties.Age + 12f, hero.DynamicBodyProperties.Weight, hero.DynamicBodyProperties.Build); InformationManager.DisplayMessage(new InformationMessage(DebugResultMsg.ToString() + test, ColorManager.Red)); hero.DynamicBodyProperties.Equals(test); // TODO: Get access to keyValuePair w/ Reflection /*float weight = hero.DynamicBodyProperties.Weight; * float build = hero.DynamicBodyProperties.Build; * ____heroBehaviorsDictionary.Key.DynamicBodyProperties = new DynamicBodyProperties(____heroBehaviorsDictionary.Key.Age, weight, build;*/ } double newAge = hero.DynamicBodyProperties.Age + yearsElapsed; DynamicBodyProperties bodyProperties = new DynamicBodyProperties((float)newAge, hero.DynamicBodyProperties.Weight, hero.DynamicBodyProperties.Build); hero.DynamicBodyProperties = bodyProperties; if (hero.IsHumanPlayerCharacter && DCCSettings.Instance.DebugMode) { InformationManager.DisplayMessage(new InformationMessage(SubModule.GetFormattedAgeDebugMessage(hero, hero.DynamicBodyProperties.Age), ColorManager.Red)); } } } return(false); } else { return(true); } }
// Should be fixed by e1.4.3 #if false private void OnDailyTick(Hero hero) { if (!hero.IsTemplate && !hero.IsMinorFactionHero && hero.IsNoble) { if (hero.IsAlive && (hero.Age - hero.DynamicBodyProperties.Age) > 1f) { DynamicBodyProperties dp = hero.DynamicBodyProperties; dp.Age = hero.Age; hero.DynamicBodyProperties = dp; } if ((int)hero.BirthDay.ElapsedDaysUntilNow % CampaignTime.DaysInYear == 0) { OnHeroGrows(hero); } } }
//static bool Prefix(DynamicBodyCampaignBehavior __instance, ref Dictionary<Hero, object> ____heroBehaviorsDictionary) static bool Prefix(DynamicBodyCampaignBehavior __instance) { if (!DCCSettingsUtil.Instance.IgnoreDailyTick) { return(true); } //CampaignTime deltaTime = CampaignTime.Now - SubModule.TimeSinceLastSave; CampaignTime deltaTime = SubModule.GetDeltaTime(true); double yearsElapsed = deltaTime.ToYears; //SubModule.TimeSinceLastSave = CampaignTime.Now; if (!DCCSettingsUtil.Instance.DisableAutoAging) { IDictionary dictionary = (IDictionary)AccessTools.Field(typeof(DynamicBodyCampaignBehavior), "_heroBehaviorsDictionary").GetValue(__instance); foreach (var hero in dictionary.Keys.Cast <Hero>()) { if (hero.IsHumanPlayerCharacter && DCCSettingsUtil.Instance.DebugMode) { InformationManager.DisplayMessage(new InformationMessage(DebugSetAppearanceMsg.ToString() + hero.Name, ColorManager.Red)); var test = new DynamicBodyProperties(hero.Age, hero.Weight, hero.Build); InformationManager.DisplayMessage(new InformationMessage(DebugResultMsg.ToString() + test, ColorManager.Red)); hero.BodyProperties.DynamicProperties.Equals(test); } // TODO:: Why is this conflicting now??? /*double newAge = hero.Age + yearsElapsed; * DynamicBodyProperties dynamicBodyProperties = new DynamicBodyProperties((float)newAge, hero.Weight, hero.Build);*/ DynamicBodyProperties dynamicBodyProperties = new DynamicBodyProperties(hero.Age, hero.Weight, hero.Build); BodyProperties heroBodyProperties = new BodyProperties(dynamicBodyProperties, hero.BodyProperties.StaticProperties); //BodyProperties heroBodyProperties = hero.BodyProperties; //CharacterBodyManager.CopyDynamicBodyProperties(dynamicBodyProperties, heroBodyProperties.DynamicProperties); hero.CharacterObject.UpdatePlayerCharacterBodyProperties(heroBodyProperties, hero.IsFemale); if (hero.IsHumanPlayerCharacter && DCCSettingsUtil.Instance.DebugMode) { InformationManager.DisplayMessage(new InformationMessage(SubModule.GetFormattedAgeDebugMessage(hero, hero.Age), ColorManager.Red)); } } } return(false); }
static bool Prefix(ref Dictionary <Hero, object> ____heroBehaviorsDictionary) { if (Settings.Instance.IgnoreDailyTick == true) { IDictionary dictionary = (IDictionary)typeof(DynamicBodyCampaignBehavior).GetField("_heroBehaviorsDictionary", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(____heroBehaviorsDictionary); foreach (object obj in dictionary.Keys) { Hero hero = (Hero)obj; if (Settings.Instance.DisableAutoAging == false) { if (hero.IsHumanPlayerCharacter) { if (Settings.Instance.DebugMode == true) { InformationManager.DisplayMessage(new InformationMessage("[Debug] Set appearance for: " + hero.Name, ColorManager.Red)); } var test = new DynamicBodyProperties(hero.DynamicBodyProperties.Age + 12f, hero.DynamicBodyProperties.Weight, hero.DynamicBodyProperties.Build); if (Settings.Instance.DebugMode == true) { InformationManager.DisplayMessage(new InformationMessage("[Debug] Result: " + test, ColorManager.Red)); } hero.DynamicBodyProperties.Equals(test); // TODO: Get access to keyValuePair w/ Reflection /*float weight = hero.DynamicBodyProperties.Weight; * float build = hero.DynamicBodyProperties.Build; * ____heroBehaviorsDictionary.Key.DynamicBodyProperties = new DynamicBodyProperties(____heroBehaviorsDictionary.Key.Age, weight, build;*/ } } } return(false); } else { return(true); } }
public static string HeroBodyPropertiesToString(Hero hero) { DynamicBodyProperties dynamicProperties = hero.BodyProperties.DynamicProperties; StaticBodyProperties staticProperties = hero.BodyProperties.StaticProperties; return(string.Join(";", new object[] { hero.IsFemale.ToString(), dynamicProperties.Age, dynamicProperties.Build, dynamicProperties.Weight, staticProperties.KeyPart1, staticProperties.KeyPart2, staticProperties.KeyPart3, staticProperties.KeyPart4, staticProperties.KeyPart5, staticProperties.KeyPart6, staticProperties.KeyPart7, staticProperties.KeyPart8 })); }
public override void OnBeforeSave() { if (Game.Current != null && Game.Current.GameType is Campaign) { CampaignTime deltaTime = CampaignTime.Now - TimeSinceLastSave; double yearsElapsed = deltaTime.ToYears; TimeSinceLastSave = CampaignTime.Now; foreach (Hero hero in Game.Current.ObjectManager.GetObjectTypeList <Hero>()) { double newAge = hero.DynamicBodyProperties.Age + yearsElapsed; DynamicBodyProperties bodyProperties = new DynamicBodyProperties((float)newAge, hero.DynamicBodyProperties.Weight, hero.DynamicBodyProperties.Build); hero.DynamicBodyProperties = bodyProperties; if (hero.IsHumanPlayerCharacter && DCCSettings.Instance != null && DCCSettings.Instance.DebugMode) { InformationManager.DisplayMessage(new InformationMessage(GetFormattedAgeDebugMessage(hero, hero.DynamicBodyProperties.Age), ColorManager.Red)); } } } }
// Yeah, um, structs are passed by value in C#. So this method should basically do nothing. Unless you use // the 'ref' keyword. Unfortunately, it still won't work because both DynamicBodyProperties and BodyProperties // are themselves structs. To change the latter's DynamicProperties property's underlying field without actually // replacing its value, you will need to somehow acquire a reference to said field, becausing just // accessing it will return a copy of it. Not only that, but you also have to do the same for // Hero.BodyProperties itself since, as noted before, BodyProperties is a struct. // Good luck with that. Besides, this is overengineering when a BodyProperties constructor exist that // actually works as intended. - Designer225 public static void CopyDynamicBodyProperties(DynamicBodyProperties src, DynamicBodyProperties target) { target.Age = src.Age; target.Build = src.Build; target.Weight = src.Weight; }