Skip to content

Commit

Permalink
feat: multi callback unit and effect units support in recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chillu1 committed Aug 8, 2024
1 parent 12566bd commit e273168
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public ModifierGenerator(in ModifierRecipeData data)
_timeComponentCount++;

_modifierEffectsCreator = new ModifierEffectsCreator(data.EffectWrappers, data.RemoveEffectWrapper,
data.DispelRegisterWrapper, data.CallbackUnitRegisterWrapper, data.CallbackEffectRegisterWrappers,
data.CallbackEffectUnitsRegisterWrapper);
data.DispelRegisterWrapper, data.CallbackUnitRegisterWrappers, data.CallbackEffectRegisterWrappers,
data.CallbackEffectUnitsRegisterWrappers);

if (HasApplyChecks)
{
Expand Down
28 changes: 25 additions & 3 deletions ModiBuff/ModiBuff/Core/Modifier/Creation/Recipe/EffectOn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ public enum EffectOn
CallbackUnit = 16,
CallbackEffect = 32,
CallbackEffectUnits = 64,
CallbackEffect2 = 128,
CallbackEffect3 = 256,
CallbackEffect4 = 512,
CallbackUnit2 = 128,
CallbackUnit3 = 256,
CallbackUnit4 = 512,
CallbackEffect2 = 1024,
CallbackEffect3 = 2048,
CallbackEffect4 = 4096,
CallbackEffectUnits2 = 8192,
CallbackEffectUnits3 = 16384,
CallbackEffectUnits4 = 32768,
}

public static class EffectOnExtensions
Expand All @@ -25,12 +31,28 @@ public static class EffectOnExtensions

public static class EffectOnCallbackEffectData
{
public static readonly EffectOn[] AllCallbackUnitData =
{
EffectOn.CallbackUnit,
EffectOn.CallbackUnit2,
EffectOn.CallbackUnit3,
EffectOn.CallbackUnit4,
};

public static readonly EffectOn[] AllCallbackEffectData =
{
EffectOn.CallbackEffect,
EffectOn.CallbackEffect2,
EffectOn.CallbackEffect3,
EffectOn.CallbackEffect4,
};

public static readonly EffectOn[] AllCallbackEffectUnitsData =
{
EffectOn.CallbackEffectUnits,
EffectOn.CallbackEffectUnits2,
EffectOn.CallbackEffectUnits3,
EffectOn.CallbackEffectUnits4,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public sealed class ModifierEffectsCreator
private readonly EffectWrapper[] _savableEffectsWrappers;
private readonly EffectWrapper _removeEffectWrapper;
private readonly EffectWrapper _dispelRegisterWrapper;
private readonly EffectWrapper _callbackUnitRegisterWrapper;
private readonly EffectWrapper[] _callbackUnitRegisterWrappers;
private readonly EffectWrapper[] _callbackEffectRegisterWrappers;
private readonly EffectWrapper _callbackEffectUnitsRegisterWrapper;
private readonly EffectWrapper[] _callbackEffectUnitsRegisterWrappers;

private IRevertEffect[] _revertEffects;
private IEffect[] _initEffects;
private IEffect[] _intervalEffects;
private IEffect[] _durationEffects;
private IStackEffect[] _stackEffects;
private IEffect[] _callbackUnitEffects;
private IEffect[][] _callbackUnitEffects;
private IEffect[][] _callbackEffectEffects;
private IEffect[] _callbackEffectUnitsEffects;
private IEffect[][] _callbackEffectUnitsEffects;

private int _revertEffectsIndex,
_initEffectsIndex,
Expand All @@ -33,22 +33,28 @@ public sealed class ModifierEffectsCreator
_callbackUnitEffectsIndex,
_callbackEffectEffectsIndex,
_callbackEffectUnitsEffectsIndex,
_callbackUnitEffectsIndex2,
_callbackUnitEffectsIndex3,
_callbackUnitEffectsIndex4,
_callbackEffectEffectsIndex2,
_callbackEffectEffectsIndex3,
_callbackEffectEffectsIndex4;
_callbackEffectEffectsIndex4,
_callbackEffectUnitsEffectsIndex2,
_callbackEffectUnitsEffectsIndex3,
_callbackEffectUnitsEffectsIndex4;

public ModifierEffectsCreator(List<EffectWrapper> effectWrappers, EffectWrapper removeEffectWrapper,
EffectWrapper dispelRegisterWrapper, EffectWrapper callbackUnitRegisterWrapper,
EffectWrapper[] callbackEffectRegisterWrappers, EffectWrapper callbackEffectUnitsRegisterWrapper)
EffectWrapper dispelRegisterWrapper, EffectWrapper[] callbackUnitRegisterWrappers,
EffectWrapper[] callbackEffectRegisterWrappers, EffectWrapper[] callbackEffectUnitsRegisterWrappers)
{
var effectsWithModifierInfoWrappers = new List<EffectWrapper>();
var savableEffectsWrappers = new List<EffectWrapper>();
_effectWrappers = effectWrappers.ToArray();
_removeEffectWrapper = removeEffectWrapper;
_dispelRegisterWrapper = dispelRegisterWrapper;
_callbackUnitRegisterWrapper = callbackUnitRegisterWrapper;
_callbackUnitRegisterWrappers = callbackUnitRegisterWrappers;
_callbackEffectRegisterWrappers = callbackEffectRegisterWrappers;
_callbackEffectUnitsRegisterWrapper = callbackEffectUnitsRegisterWrapper;
_callbackEffectUnitsRegisterWrappers = callbackEffectUnitsRegisterWrappers;

for (int i = 0; i < _effectWrappers.Length; i++)
{
Expand Down Expand Up @@ -76,12 +82,24 @@ public ModifierEffectsCreator(List<EffectWrapper> effectWrappers, EffectWrapper
_callbackEffectEffectsIndex++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffectUnits) != 0)
_callbackEffectUnitsEffectsIndex++;
if ((effectWrapper.EffectOn & EffectOn.CallbackUnit2) != 0)
_callbackUnitEffectsIndex2++;
if ((effectWrapper.EffectOn & EffectOn.CallbackUnit3) != 0)
_callbackUnitEffectsIndex3++;
if ((effectWrapper.EffectOn & EffectOn.CallbackUnit4) != 0)
_callbackUnitEffectsIndex4++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffect2) != 0)
_callbackEffectEffectsIndex2++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffect3) != 0)
_callbackEffectEffectsIndex3++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffect4) != 0)
_callbackEffectEffectsIndex4++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffectUnits2) != 0)
_callbackEffectUnitsEffectsIndex2++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffectUnits3) != 0)
_callbackEffectUnitsEffectsIndex3++;
if ((effectWrapper.EffectOn & EffectOn.CallbackEffectUnits4) != 0)
_callbackEffectUnitsEffectsIndex4++;
}

_effectsWithModifierInfoWrappers = effectsWithModifierInfoWrappers.ToArray();
Expand Down Expand Up @@ -115,16 +133,24 @@ public SyncedModifierEffects Create(int genId)
_stackEffectsIndex = 0;
}

if (_callbackUnitEffectsIndex > 0)
{
_callbackUnitEffects = new IEffect[_callbackUnitEffectsIndex];
_callbackUnitEffectsIndex = 0;
}
if (_callbackUnitEffectsIndex > 0 || _callbackUnitEffectsIndex2 > 0 ||
_callbackUnitEffectsIndex3 > 0 || _callbackUnitEffectsIndex4 > 0)
_callbackUnitEffects = new IEffect[4][];

if (_callbackEffectEffectsIndex > 0 || _callbackEffectEffectsIndex2 > 0 ||
_callbackEffectEffectsIndex3 > 0 || _callbackEffectEffectsIndex4 > 0)
_callbackEffectEffects = new IEffect[4][];

if (_callbackEffectUnitsEffectsIndex > 0 || _callbackEffectUnitsEffectsIndex2 > 0 ||
_callbackEffectUnitsEffectsIndex3 > 0 || _callbackEffectUnitsEffectsIndex4 > 0)
_callbackEffectUnitsEffects = new IEffect[4][];

if (_callbackUnitEffectsIndex > 0)
{
_callbackUnitEffects[0] = new IEffect[_callbackUnitEffectsIndex];
_callbackUnitEffectsIndex = 0;
}

if (_callbackEffectEffectsIndex > 0)
{
_callbackEffectEffects[0] = new IEffect[_callbackEffectEffectsIndex];
Expand All @@ -133,10 +159,28 @@ public SyncedModifierEffects Create(int genId)

if (_callbackEffectUnitsEffectsIndex > 0)
{
_callbackEffectUnitsEffects = new IEffect[_callbackEffectUnitsEffectsIndex];
_callbackEffectUnitsEffects[0] = new IEffect[_callbackEffectUnitsEffectsIndex];
_callbackEffectUnitsEffectsIndex = 0;
}

if (_callbackUnitEffectsIndex2 > 0)
{
_callbackUnitEffects[1] = new IEffect[_callbackUnitEffectsIndex2];
_callbackUnitEffectsIndex2 = 0;
}

if (_callbackUnitEffectsIndex3 > 0)
{
_callbackUnitEffects[2] = new IEffect[_callbackUnitEffectsIndex3];
_callbackUnitEffectsIndex3 = 0;
}

if (_callbackUnitEffectsIndex4 > 0)
{
_callbackUnitEffects[3] = new IEffect[_callbackUnitEffectsIndex4];
_callbackUnitEffectsIndex4 = 0;
}

if (_callbackEffectEffectsIndex2 > 0)
{
_callbackEffectEffects[1] = new IEffect[_callbackEffectEffectsIndex2];
Expand All @@ -155,6 +199,24 @@ public SyncedModifierEffects Create(int genId)
_callbackEffectEffectsIndex4 = 0;
}

if (_callbackEffectUnitsEffectsIndex2 > 0)
{
_callbackEffectUnitsEffects[1] = new IEffect[_callbackEffectUnitsEffectsIndex2];
_callbackEffectUnitsEffectsIndex2 = 0;
}

if (_callbackEffectUnitsEffectsIndex3 > 0)
{
_callbackEffectUnitsEffects[2] = new IEffect[_callbackEffectUnitsEffectsIndex3];
_callbackEffectUnitsEffectsIndex3 = 0;
}

if (_callbackEffectUnitsEffectsIndex4 > 0)
{
_callbackEffectUnitsEffects[3] = new IEffect[_callbackEffectUnitsEffectsIndex4];
_callbackEffectUnitsEffectsIndex4 = 0;
}

if (_revertEffectsIndex > 0)
{
_revertEffects = new IRevertEffect[_revertEffectsIndex];
Expand Down Expand Up @@ -183,17 +245,29 @@ public SyncedModifierEffects Create(int genId)
if ((effectOn & EffectOn.Stack) != 0)
_stackEffects[_stackEffectsIndex++] = (IStackEffect)effect;
if ((effectOn & EffectOn.CallbackUnit) != 0)
_callbackUnitEffects[_callbackUnitEffectsIndex++] = effect;
_callbackUnitEffects[0][_callbackUnitEffectsIndex++] = effect;
if ((effectOn & EffectOn.CallbackEffect) != 0)
_callbackEffectEffects[0][_callbackEffectEffectsIndex++] = effect;
if ((effectOn & EffectOn.CallbackEffectUnits) != 0)
_callbackEffectUnitsEffects[_callbackEffectUnitsEffectsIndex++] = effect;
_callbackEffectUnitsEffects[0][_callbackEffectUnitsEffectsIndex++] = effect;
if ((effectOn & EffectOn.CallbackUnit2) != 0)
_callbackUnitEffects[1][_callbackUnitEffectsIndex2++] = effect;
if ((effectOn & EffectOn.CallbackUnit3) != 0)
_callbackUnitEffects[2][_callbackUnitEffectsIndex3++] = effect;
if ((effectOn & EffectOn.CallbackUnit4) != 0)
_callbackUnitEffects[3][_callbackUnitEffectsIndex4++] = effect;
if ((effectOn & EffectOn.CallbackEffect2) != 0)
_callbackEffectEffects[1][_callbackEffectEffectsIndex2++] = effect;
if ((effectOn & EffectOn.CallbackEffect3) != 0)
_callbackEffectEffects[2][_callbackEffectEffectsIndex3++] = effect;
if ((effectOn & EffectOn.CallbackEffect4) != 0)
_callbackEffectEffects[3][_callbackEffectEffectsIndex4++] = effect;
if ((effectOn & EffectOn.CallbackEffectUnits2) != 0)
_callbackEffectUnitsEffects[1][_callbackEffectUnitsEffectsIndex2++] = effect;
if ((effectOn & EffectOn.CallbackEffectUnits3) != 0)
_callbackEffectUnitsEffects[2][_callbackEffectUnitsEffectsIndex3++] = effect;
if ((effectOn & EffectOn.CallbackEffectUnits4) != 0)
_callbackEffectUnitsEffects[3][_callbackEffectUnitsEffectsIndex4++] = effect;
}

EffectStateInfo effectStateInfo = default;
Expand All @@ -217,13 +291,14 @@ public SyncedModifierEffects Create(int genId)
//Set the effects arrays on our special effects (callback, event, remove-revert)
//No need to reset manually special wrappers manually
//Since they're always fed to effectWrappers, that we reset at the end
_callbackUnitRegisterWrapper?.GetEffectAs<IRecipeFeedEffects>().SetEffects(_callbackUnitEffects);
for (int i = 0; i < _callbackUnitRegisterWrappers?.Length; i++)
_callbackUnitRegisterWrappers[i].GetEffectAs<IRecipeFeedEffects>().SetEffects(_callbackUnitEffects[i]);
for (int i = 0; i < _callbackEffectRegisterWrappers?.Length; i++)
_callbackEffectRegisterWrappers[i].GetEffectAs<IRecipeFeedEffects>()
.SetEffects(_callbackEffectEffects[i]);

_callbackEffectUnitsRegisterWrapper?.GetEffectAs<IRecipeFeedEffects>()
.SetEffects(_callbackEffectUnitsEffects);
for (int i = 0; i < _callbackEffectUnitsRegisterWrappers?.Length; i++)
_callbackEffectUnitsRegisterWrappers[i].GetEffectAs<IRecipeFeedEffects>()
.SetEffects(_callbackEffectUnitsEffects[i]);

if (_removeEffectWrapper != null && _revertEffects != null)
_removeEffectWrapper.GetEffectAs<RemoveEffect>().SetRevertibleEffects(_revertEffects);
Expand Down
Loading

0 comments on commit e273168

Please sign in to comment.