public static int CompareInteractionType(StatusEffectInteraction x, StatusEffectInteraction y) { if ((int)x.InteractionType > (int)y.InteractionType) { return(1); } if (x.InteractionType == y.InteractionType) { return(0); } return(-1); }
public StatusEffectAddResult AddStatusEffect(StatusEffectData statEffType, StatusEffectBase statEff, float duration , out StatusEffectInteraction buffInteraction) { buffInteraction = null; if (statEff == null || statEffType == null) { Debug.Log("This is null?"); return(StatusEffectAddResult.Failed); } var res = CheckInteractions(statEffType, out var buff); // Failed in this case means that there were either no interactions or none // with the status effects in here, so we can proceed to add as normal if (res == StatusEffectAddResult.SpellBuff || res == StatusEffectAddResult.Finished) { buffInteraction = buff; return(res); } var statEffExists = currentStatusEffects.ContainsKey(statEffType); if (statEffExists) { // it exists, check if we can stack it, and how switch (statEff.StackType) { case StatusEffectStackType.IgnoreIfExists: { Debug.Log("Status effect exists with IgnoreIfExists, ignoring"); Debug.Log("-------------------------------"); break; } case StatusEffectStackType.DurationExtend: { // No point in grabbing anything but the first element as it can't stack in the first place var statEffToExt = currentStatusEffects[statEffType][0]; Debug.Log("Extending duration, prev duration: " + TimerTickerSingleton.Instance.GetTimer(statEffToExt).Time); if (!ExtendStatusEffectDuration(duration, statEffToExt)) { // Duration wasn't extended for whatever reason, most likely an error return(StatusEffectAddResult.Failed); } Debug.Log("New duration: " + TimerTickerSingleton.Instance.GetTimer(statEffToExt).Time); Debug.Log("-------------------------------"); break; } case StatusEffectStackType.FullStack: { Debug.Log("Full stack, prev stack count: " + currentStatusEffects[statEffType].Count); currentStatusEffects[statEffType].Add(statEff); AddRemovalTimerForStatus(statEffType, statEff, duration); onStatEffAdded?.Invoke(statEffType, statEff); Debug.Log("New stack count: " + currentStatusEffects[statEffType].Count); Debug.Log("-------------------------------"); break; } case StatusEffectStackType.DurationRefresh: { // No point in grabbing anything but the first element as it can't stack in the first place var statEffToRef = currentStatusEffects[statEffType][0]; Debug.Log("Refreshing duration, prev duration: " + TimerTickerSingleton.Instance.GetTimer(statEffToRef).Time); if (!RefreshStatusEffectDuration(statEffToRef)) { // Duration wasn't extended for whatever reason, most likely an error return(StatusEffectAddResult.Failed); } Debug.Log("New duration: " + TimerTickerSingleton.Instance.GetTimer(statEffToRef).Time); Debug.Log("-------------------------------"); break; } case StatusEffectStackType.DurationRefreshAndFullStack: { var statEffs = currentStatusEffects[statEffType]; Debug.Log("Refreshing duration and full stack, prev count:" + statEffs.Count + " , Prev dur of first element: " + TimerTickerSingleton.Instance.GetTimer(statEffs[0]).Time); foreach (var statEffToRef in statEffs) { if (!RefreshStatusEffectDuration(statEffToRef)) { // Duration wasn't extended for whatever reason, most likely an error return(StatusEffectAddResult.Failed); } } statEffs.Add(statEff); AddRemovalTimerForStatus(statEffType, statEff, duration); Debug.Log("New count: " + statEffs.Count + " , New dur of first element:" + TimerTickerSingleton.Instance.GetTimer(statEffs[0]).Time); Debug.Log("-------------------------------"); onStatEffAdded?.Invoke(statEffType, statEff); break; } } } else { // it doesn't exist, so we can add it regardless of it's stack type Debug.Log("Added new status effect: " + statEffType.Name); Debug.Log("-------------------------------"); currentStatusEffects.Add(statEffType, new List <StatusEffectBase>() { statEff }); AddRemovalTimerForStatus(statEffType, statEff, duration); onStatEffAdded?.Invoke(statEffType, statEff); } UpdateExternalMovementValue(); return(StatusEffectAddResult.Finished); }
// Runs to check for special interactions, if there are none proceed to add effects normally private StatusEffectAddResult CheckInteractions(StatusEffectData data, out StatusEffectInteraction buffInteraction) { buffInteraction = null; if (data.Interactions.Count <= 0) { return(StatusEffectAddResult.Failed); } foreach (var interaction in data.Interactions) { if (!currentStatusEffects.ContainsKey(interaction.Target)) { continue; } switch (interaction.InteractionType) { case InteractionType.RemoveAndCombine: { Debug.Log("Combining, interaction:" + interaction.Name + ", Base: " + data.Name + " Target: " + interaction.Target.Name + " Result: " + interaction.Result); // remove target, don't add this, add result RemoveAllOfType(interaction.Target); AddStatusEffect(interaction.Result, StatusEffectFactory.CreateStatusEffect(interaction.Result) , interaction.Result.Duration, out var buff); return(StatusEffectAddResult.Finished); } case InteractionType.ModifySpellDamage: { // remove target, don't add this, get StatusEffectAddResult.SpellBuff returned // somehow Debug.Log("Buffing spell, interaction:" + interaction.Name + " , Base: " + data.Name + " , Target: " + interaction.Target.Name + " , Effectiveness: " + interaction.Effectiveness); RemoveAllOfType(interaction.Target); buffInteraction = interaction; return(StatusEffectAddResult.SpellBuff); } case InteractionType.RemoveBoth: { // remove target, don't add this Debug.Log("Removing both, interaction:" + interaction.Name + " , Base: " + data.Name + " , Target: " + interaction.Target.Name + " , Result: " + interaction.Result); RemoveAllOfType(interaction.Target); return(StatusEffectAddResult.Finished); } } } return(StatusEffectAddResult.Failed); }