Chillu1 / ModiBuff

Buff/Debuff/Modifier library focused on feature set and performance, while maintaining 0 GC. Fully pooled
Mozilla Public License 2.0
139 stars 4 forks source link

Dispel #28

Closed Chillu1 closed 10 months ago

Chillu1 commented 11 months ago

Before implementing dispel mechanic, it's probably best to implement tags #26 first.

Dispel mechanic is a pretty common in games with buff/debuff mechanics. It would be nice to have helper/QoL logic inside ModiBuff.Core for dispelling certain modifier types, this is where tags can help a lot with tagging what kind of modifiers to dispel (remove and revert).

Possible dispel tags: Offensive, Defensive, Movement, Basic/Hard Dispel, Undispellable.

Possible API ModifierController.Dispel(int tagFlags)/ModifierController.Dispel<TTag>(TTag tagFlags)

Chillu1 commented 10 months ago

Mostly implemented, but with game logic instead of ModiBuff.Core.

Either through: CallbackEffect with multi-tag, CallbackEffect with single event, or CallbackUnit.

//Most control-oriented dispel solution
add => add("InitStatusEffectSleep_RemoveOnDispel")
    .Tag(TagType.BasicDispel)
    .Effect(new StatusEffectEffect(StatusEffectType.Sleep, 5f, true), EffectOn.Init)
    .Remove(RemoveEffectOn.CallbackEffect)
    .CallbackEffect(CallbackType.Dispel, removeEffect =>
        new DispelEvent((target, source, eventTag) =>
        {
            if ((TagType.BasicDispel & eventTag) != 0)
                removeEffect.Effect(target, source);
        })),
add => add("InitStatusEffectSleep_RemoveOnDispel")
    .Tag(TagType.StrongDispel)
    .Effect(new StatusEffectEffect(StatusEffectType.Sleep, 5f, true), EffectOn.Init)
    .Remove(RemoveEffectOn.CallbackEffect)
    .CallbackEffect(CallbackType.StrongDispel, removeEffect => new StrongDispelEvent(removeEffect.Effect)),
//Easiest dispel solution, note that we can't control for what else can happen in the dispel event
add => add("InitStatusEffectSleep_RemoveOnDispel")
    .Tag(TagType.StrongDispel)
    .Effect(new StatusEffectEffect(StatusEffectType.Sleep, 5f, true), EffectOn.Init)
    .Remove(RemoveEffectOn.CallbackUnit)
    .CallbackUnit(CallbackUnitType.StrongDispel)

Taken from: https://github.com/Chillu1/ModiBuff/blob/5024dac0e913c4028e7671981b8787dda2a962f1/ModiBuff/ModiBuff.Tests/CallbackEffectTests.cs#L93