/// <summary>Modifies system by regenerating or decaying given value, resseting and calling on second passed each second</summary>
 public override void Modify(StatSystem system)
 {
     timePassed  += Time.deltaTime;
     currentValue = (int)(timePassed * valuePerSecond);
     if (currentValue != valueModified)
     {
         int difference = Mathf.Abs(currentValue - valueModified);
         valueModified += difference;
         if (modifiesCurrent)
         {
             system.ModifyCurrent(this, increase ? difference : -difference);
         }
         else
         {
             system.ModifyMax(this, increase ? difference : -difference);
             if (modifiesCurrentWithMax && !system.IsFull)
             {
                 system.ModifyCurrent(this, increase ? difference : -difference);
             }
         }
     }
     if (timePassed >= 1f)
     {
         OnSecondPassedEvent?.Invoke(name, valueModified);
         timePassed    = 0;
         valueModified = 0;
     }
 }
예제 #2
0
        /// <summary>Modifies system stat based on given time and time passed</summary>
        public override void Modify(StatSystem system)
        {
            if (time == 0f)
            {
                //if time is 0 no calculations have to be done and value can just modify the system once
                if (modifiesCurrent)
                {
                    system.ModifyCurrent(this, increase ? value : -value);
                }
                else
                {
                    system.ModifyMax(this, increase ? value : -value);
                }
                return;
            }

            timePassed  += UnityEngine.Time.deltaTime;
            currentValue = (int)(timePassed / time * value);
            if (currentValue != valueModified)
            {
                int difference = Mathf.Abs(currentValue - valueModified);
                valueModified += difference;

                if (currentValue > value)
                {
                    //handle overshot with large numbers and short times
                    int overShot = currentValue - value;
                    difference -= overShot;
                }

                if (modifiesCurrent)
                {
                    system.ModifyCurrent(this, increase ? difference : -difference);
                }
                else
                {
                    system.ModifyMax(this, increase ? difference : -difference);
                    if (modifiesCurrentWithMax && !system.IsFull)
                    {
                        system.ModifyCurrent(this, increase ? difference : -difference);
                    }
                }
            }
        }