How to dynamically modify item damage?

Users who are viewing this thread

Hello, I'm trying to implement Power Strike skill like in Warband. When spawning an agent, I'd like to increase its weapon damage depending on how much power strike the character has. I noticed that in an EquipmentElement you can specify an ItemModifier which has method ModifyDamage which looks like what I'm looking for.
C#:
public EquipmentElement(ItemObject item, ItemModifier itemModifier = null) { /* ... */ }
public int ModifyDamage(int baseDamage) => baseDamage + _damage;
So I tried creating an ItemModifier but the only public constructor doesn't allow to set the _damage field. So here I used reflection:
C#:
var itemModifier = new ItemModifier(); 
typeof(ItemModifier)
    .GetField("_damage", BindingFlags.Instance | BindingFlags.NonPublic)
    .SetValue(itemModifier, 500); // supposed to add 500 to the weapon damage
After setting a breakpoint on the ModifyDamage method, it is correctly called with the expected values when spawning the agent but when hitting some bots the damage stay the same. Is the ItemModifier not completely implemented or did I miss something?

Also, the ItemModifier API is very restrictive, how to:
  1. Increase swing damage but not thrust damage?
  2. Increase Pila (polearm that can be thrown) melee damage but not ranged damage?
Ideally, before spawning an agent I would be able to copy an ItemObject (without setting the fields one by one) and edit the weapon stats individually. Is it possible to do that?
 
According to patch note beta e1.5.5, item modifiers should be fixed.
Item Modifiers Update:
  • While modifiers worked mostly as intended for armours, they did not work correctly for weapons(stats of weapons were not affected by them), that's fixed.

However, the item modifier API is too coarse for my use case and I don't want to implement an AgentApplyDamageModel. I think I'll stick with modifying an ItemObject with reflection. Having an API in Bannerlord to do that would help :/
 
Top Bottom