xoxfaby / BetterUI

Risk of Rain 2 mod BetterUI
Other
59 stars 33 forks source link

Add DeregisterStat method to ItemStats.cs #146

Closed alexander-mcdowell closed 1 year ago

alexander-mcdowell commented 1 year ago

For any mods that change the descriptions of vanilla item stats, it should be possible to modify or remove existing stats attached to an item.

For instance, I am working on a mod that, in addition to other things, changes the radius of the Warbanner from an initial radius of 16m to 8m. However, the "Radius" stat on the Warbanner tooltip still maintains a value of 16m, increasing by 8m for each stack. The only methods I have access to within ItemStats.cs allow me to add a second "Radius" tag but not replace the existing tag.

A DeregisterStat method would allow me to remove the first radius tag and use the existing RegisterStat method to add a corrected tag in its place.

xoxfaby commented 1 year ago

I've added helper methods that make this possible without publicizing BetterUI, these methods are

BetterUI.ItemStats.GetItemStats(ItemDef itemDef)
BetterUI.ItemStats.GetItemTags(ItemStat itemStat)
BetterUI.ItemStats.GetItemModifers(ItemTag itemTag)

These give you access to the respective lists. This means you can, for example, get all the ItemStats for the vanilla ItemDef you've changed the behaviour for and then remove any incorrect ItemStats and replace them, or you should also be able to edit the relevant values on the existing ItemStat, if only numbers or scaling, etc. were changed.

I recommend you take a look at the ItemStats.cs file to see what values there are to change or use. If the existing scaling formulas or formatters are not sufficient, you can always define your own.

In the future there will likely be more user friendly methods to interact with existing ItemStats, but this raw access should at least allow access to remove or modify existing stats as needed.