示例#1
0
 private void CheckBatteryLevel()
 {
     if (Charge <= 0 && _depleted == false)
     {
         OnDepleted?.Invoke();
         _depleted = true;
     }
 }
示例#2
0
        public int Gather(int amount)
        {
            if (Type == SourceTypes.None || IsDepleted || amount == 0)
            {
                return(0);
            }

            if (Type == SourceTypes.FlimsyFruit || Type == SourceTypes.FlimsyMeat)
            {
                int gath = Residual - amount > 0 ? amount : Residual;

                Residual -= gath;
                Gathered += gath;

                if (gath > 0)
                {
                    OnResidualChanged?.Invoke(this, Residual);
                    OnGathered?.Invoke(this);
                }

                if (Residual == 0)
                {
                    OnDepleted?.Invoke(this);
                }

                return(gath);
            }
            else
            {
                int gath = Size - Gathered - amount > 0 ? amount : Size - Gathered;

                Gathered += gath;

                if (gath > 0)
                {
                    OnGathered?.Invoke(this);
                }

                if (Size - Gathered <= 0)
                {
                    Residual = 0;

                    //todo: think if change event is needed here
                    OnResidualChanged?.Invoke(this, Residual);
                    OnDepleted?.Invoke(this);

                    return(Size);
                }
                else
                {
                    return(0);
                }
            }
        }
示例#3
0
        public DamageInfo Hit(IDamagable damagable, Collider2D col, Vector3 position, Vector3 normal)
        {
            DamageInfo damage = new DamageInfo(Damage, Color);
            float      life   = damagable.TakeDamage(damage);

            HitInfo info = new HitInfo(damage, col, position, normal, this, _weapon, Damage <= 0f);

            if (Damage - damage.DamageDealt <= 0f)
            {
                EmitHitEffect(position, normal);
                OnDepleted?.Invoke(info);
            }

            OnHit?.Invoke(info);
            if (life <= 0.001f)
            {
                OnKill?.Invoke(info);
            }
            return(damage);
        }