//private static float GetMultiplier() //{ // if (Settings.Instance.HeroSkillExperienceOverrideMultiplierEnabled) //return Settings.Instance.HeroSkillExperienceMultiplier; //else // return Math.Max(1, 0.0315769 * Math.Pow(skillLevel, 1.020743)); //} static bool Prefix(Hero __instance, SkillObject skill, float xpAmount) { try { if (hdFieldInfo == null) { GetFieldInfo(); } HeroDeveloper hd = (HeroDeveloper)hdFieldInfo.GetValue(__instance); if (hd != null) { if (xpAmount > 0) { float newXpAmount = (int)Math.Ceiling(xpAmount * Settings.Instance.HeroSkillExperienceMultiplier); hd.AddSkillXp(skill, newXpAmount, true, true); } else { hd.AddSkillXp(skill, xpAmount, true, true); } } } catch (Exception ex) { ModDebug.ShowError($"An exception occurred whilst trying to apply the hero xp multiplier.", "", ex); } return(false); }
static bool Prefix(Hero __instance, SkillObject skill, int xpAmount) { try { HeroDeveloper hd = (HeroDeveloper)(typeof(Hero).GetField("_heroDeveloper", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(__instance)); if (hd != null) { if (xpAmount > 0) { double multiplier = GetMultiplier(__instance.GetSkillValue(skill)); int newXpAmount = (int)Math.Ceiling(xpAmount * multiplier); hd.AddSkillXp(skill, newXpAmount); } else { hd.AddSkillXp(skill, xpAmount); } } } catch (Exception ex) { ModDebug.ShowError($"An exception occurred whilst trying to apply the hero xp multiplier.", "", ex); } return(false); }
static bool Prefix(Hero __instance, SkillObject skill, float xpAmount) { try { if (hdFieldInfo == null) { GetFieldInfo(); } HeroDeveloper hd = (HeroDeveloper)hdFieldInfo !.GetValue(__instance); if (!(BannerlordTweaksSettings.Instance is { } settings)) { return(true); } if (hd != null) { if (xpAmount > 0) { if (settings.HeroSkillExperienceMultiplierEnabled && hd.Hero.IsHumanPlayerCharacter) { if (settings.PerSkillBonusEnabled) { float PerSkillBonus = GetPerSkillBonus(skill, xpAmount); xpAmount = PerSkillBonus; } float newXpAmount = (int)Math.Ceiling(xpAmount * settings.HeroSkillExperienceMultiplier); hd.AddSkillXp(skill, newXpAmount, true, true); } else if (settings.CompanionSkillExperienceMultiplierEnabled && !hd.Hero.IsHumanPlayerCharacter && (hd.Hero.Clan == Hero.MainHero.Clan)) { if (settings.PerSkillBonusEnabled) { float PerSkillBonus = GetPerSkillBonus(skill, xpAmount); xpAmount = PerSkillBonus; } float newXpAmount = (int)Math.Ceiling(xpAmount * settings.CompanionSkillExperienceMultiplier); hd.AddSkillXp(skill, newXpAmount, true, true); } else { hd.AddSkillXp(skill, xpAmount, true, true); } } else { hd.AddSkillXp(skill, xpAmount, true, true); } } } catch (Exception ex) { DebugHelpers.ShowError("An exception occurred while trying to apply the hero xp multiplier.", "", ex); } return(false); }
static bool Prefix(Hero __instance, SkillObject skill, int xpAmount) { try { HeroDeveloper hd = (HeroDeveloper)(typeof(Hero).GetField("_heroDeveloper", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(__instance)); if (hd != null) { if (xpAmount > 0) { double multiplier = GetMultiplier(__instance, __instance.GetSkillValue(skill), skill); int newXpAmount = (int)Math.Ceiling(xpAmount * multiplier); hd.AddSkillXp(skill, newXpAmount); } else { hd.AddSkillXp(skill, xpAmount); } } } catch (Exception ex) { } return(false); }
static bool Prefix(Hero __instance, SkillObject skill, int xpAmount) { try { HeroDeveloper hd = (HeroDeveloper)(typeof(Hero).GetField("_heroDeveloper", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(__instance)); if (hd != null) { double multiplier = GetMultiplier(__instance.GetSkillValue(skill)); int newXpAmount = (int)Math.Ceiling(xpAmount * multiplier); hd.AddSkillXp(skill, newXpAmount); //MessageBox.Show($"Skill: {skill.Name}\nLevel: {__instance.GetSkillValue(skill)}\nMultiplier: {multiplier}\nOld xp amount: {xpAmount}\nNew xp amount: {newXpAmount}"); } } catch (Exception ex) { MessageBox.Show($"An exception occurred whilst trying to apply the xp multiplier.\n\nException:\n{ex.Message}\n\n{ex.InnerException?.Message}"); } return(false); }