internal static void Postfix(RulesetItem __instance, IAttributeValueProvider attributeValueProvider, List <RulesetItemProperty> ___dynamicItemProperties, ref int __result) { // __result contains currently computed ACM Main.Log($"RulesetItem_ComputeAttackHitEnhancement: AHE={__result}"); __result += AttackEnhancementHelper.GetEnhancement(__instance, attributeValueProvider, ___dynamicItemProperties, "AHE"); }
internal static int GetEnhancement(RulesetItem __instance, IAttributeValueProvider attributeValueProvider, List <RulesetItemProperty> ___dynamicItemProperties, string type) { using (new MethodLogger($"AttackEnhancementHelper:{type}")) { // TODO: is the RulesetItem for your scaling weapon? // if( __instance.ItemDefinition.Name != "...." ) // something like that var gameManager = ServiceRepository.GetService <IGameService>(); if (gameManager != null) { Main.Log($"AttackEnhancementHelper: Got game manager"); var hero = gameManager.EnumerateHeroes()?.FirstOrDefault(h => h.Guid == __instance.BearerGuid); if (hero?.ClassesAndLevels != null) { // get bearer level for our target class (PsiWarrior) var level = hero?.ClassesAndLevels //.Where(kvp => kvp.Key.Name == "Fighter") // TODO .Select(kvp => (int?)kvp.Value).SingleOrDefault() ?? 0; Main.Log($"AttackEnhancementHelper: Hero={hero.Name}, Level={level}"); if (level > 0) { // It may possible to modify behaviour using FeatureDefinitionAttackModifier //if (___dynamicItemProperties != null) //{ // var enhancement = ___dynamicItemProperties // .OfType<IAttackModificationProvider>() // .Where(p => p.AttackRollModifierMethod == (RuleDefinitions.AttackModifierMethod)1000) // (your AttackModifierMethod) // .Select(p => attributeValueProvider.TryGetAttributeValue($"{type}:{level}")) // .SingleOrDefault(); // Main.Log($"AttackEnhancementHelper: Enhancement={enhancement}"); // return enhancement + level; //} // But just taking a simple approach. Try to get the enhancement using attributeValueProvider. // If the IAttributeValueProvider is your RulesetCharacterHero, then you can possibly add and register additional attributes // for your hero. Or just patch TryGetAttributeValue as below. int enhancement = attributeValueProvider.TryGetAttributeValue($"{type}:{level}"); Main.Log($"AttackEnhancementHelper: Enhancement={enhancement}"); return(enhancement); } } } return(0); } }
public static T SetEquipmentItem <T>(this T entity, RulesetItem value) where T : GuiEquipmentItem { entity.SetField("equipmentItem", value); return(entity); }