Path-of-Terraria / PathOfTerraria

GNU General Public License v3.0
1 stars 3 forks source link

Improve Comparison System for Affixes #311

Closed GabeHasWon closed 3 months ago

GabeHasWon commented 4 months ago

Summary

At the moment, Affixes only can compare (i.e. say "+x% buff" or the opposite) when there are pre-defined values in EntityModifier, even when doing so is deeply inconvenient.

Using the AffixPlayer class, create a system that does this comparison using StrengthOf(someAffix) alongside some localization tools in Affix to compare and create difference tooltips without necessitating being in EntityModifier. Ideally, this would also allow for more customization, such as saying You take fall damage when losing a no fall damage affix instead of - fall damage immunity.

Reasonings

In my experience, the current comparison system in EntityModifier is really awkward to use and is very commonly a roadblock in creating affixes that do not modify simple stats. For example, a "deal additional damage to poisoned monsters" affix would require a dictionary of StatModifiers indexed by buff ID, and then be very inflexible as to how it's displayed regardless. A better system would significantly streamline development and make it way easier to customize how affixes are written, displayed and compared.

GabeHasWon commented 3 months ago

So what I'm thinking right now is making a handler for all tooltips, and having devs manually add their tooltip or their difference to that handler. It sucks that it's less automatic than the existing system, but realistically the existing system isn't automatic either; and requires using a field, which then needs to modify the stat, which is incredibly awkward.

GabeHasWon commented 3 months ago

image Not very tested, but it's a great start. Affixes control their own localized comparison now, and the only code you'd add or change is this, per affix:

    public override void ApplyTooltip(Player player, Item item, AffixTooltipsHandler handler)
    {
        handler.AddOrModify(GetType(), item,Value * 100, Language.GetText($"Mods.PathOfTerraria.Affixes.{GetType().Name}.Description"), null);
    }
GabeHasWon commented 3 months ago

image Example of a custom affix tooltip. Instead of the old system's "-1 Fall Damage immunity", it's nice and customized to fit the functionality.

CollinHerber commented 3 months ago

Nice yeah I think that's a great idea. Gives us more control and is less black magic and obvious how it works.