public bool RemoveStatusEffect(StatusEffectBase statEff)
        {
            statusEffects.Remove(statEff);

            var count = statusEffects.Count;

            if (count > 1)
            {
                statEffCount.text = "" + count;
            }
            else if (count == 1)
            {
                statEffCount.text = "";
            }
            else
            {
                onStatusEffectRemoved?.Invoke(statEff);

                return(true);
            }

            onStatusEffectRemoved?.Invoke(statEff);

            return(false);
        }
Esempio n. 2
0
        private void OnStatusEffectRemoved(StatusEffectData data, StatusEffectBase statEff)
        {
            if (!existingListings.ContainsKey(data))
            {
                return;
            }

            var toRemoveListing = existingListings[data].RemoveStatusEffect(statEff);

            if (toRemoveListing)
            {
                Destroy(existingListings[data].gameObject);

                existingListings.Remove(data);
            }
        }
Esempio n. 3
0
        private void OnStatusEffectAdded(StatusEffectData data, StatusEffectBase statEff)
        {
            if (existingListings.ContainsKey(data))
            {
                existingListings[data].AddStatusEffect(statEff);
            }
            else
            {
                var listing = CreateListing();
                listing.UpdateImageIcon(data.StatusEffectIcon);

                existingListings.Add(data, listing);

                OnStatusEffectAdded(data, statEff);
            }
        }
        private bool ExtendStatusEffectDuration(float duration, StatusEffectBase statEff)
        {
            var statusEffTimer = (DownTimer)TimerTickerSingleton.Instance
                                 .GetTimer(statEff);

            if (statusEffTimer == null)
            {
                Debug.LogError("We have a problem chief");
                Debug.Break();

                return(false);
            }

            statusEffTimer.SetNewTime(statusEffTimer.Time + duration);

            return(true);
        }
        private bool RefreshStatusEffectDuration(StatusEffectBase statEff)
        {
            var statusEffTimer = (DownTimer)TimerTickerSingleton.Instance
                                 .GetTimer(statEff);

            if (statusEffTimer == null)
            {
                Debug.LogError("We have a problem chief");
                Debug.Break();

                return(false);
            }

            statusEffTimer.Reset();

            return(true);
        }
        private void AddRemovalTimerForStatus(StatusEffectData statusEffectType, StatusEffectBase statusEffect,
                                              float duration)
        {
            var timer = new DownTimer(duration)
            {
                OnTimerEnd = () =>
                {
                    statusEffect.OnRemove();
                    RemoveStatusEffect(statusEffectType, statusEffect);
                }
            };

            timer.OnTimerEnd += () =>
                                Debug.Log("Removed: " + statusEffect + " : " + TimerTickerSingleton.Instance.RemoveTimer(statusEffect));

            TimerTickerSingleton.Instance.AddTimer(timer, statusEffect);
        }
        public void AddStatusEffect(StatusEffectBase statEff)
        {
            statusEffects.Add(statEff);

            var count = statusEffects.Count;

            if (count > 1)
            {
                statEffCount.text = "" + count;
            }
            else
            {
                statEffCount.text = "";
            }

            onStatusEffectAdded?.Invoke(statEff);
        }
        private void RemoveStatusEffect(StatusEffectData key, StatusEffectBase statusEffect)
        {
            if (currentStatusEffects.ContainsKey(key))
            {
                if (currentStatusEffects[key].Count == 1)
                {
                    currentStatusEffects.Remove(key);

                    onStatEffRemoved?.Invoke(key, statusEffect);
                }
                else
                {
                    currentStatusEffects[key].Remove(statusEffect);

                    onStatEffRemoved?.Invoke(key, statusEffect);
                }
            }

            UpdateExternalMovementValue();
        }
        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);
        }
 // Called ForceRemove as potions and spells would technically FORCE the removal of the status effects
 // So would status effects canceling each other out such as water and fire canceling each other out
 public void ForceRemoveStatusEffect(StatusEffectData statEffType, StatusEffectBase statEff)
 {
     RemoveStatusEffect(statEffType, statEff);
 }