Пример #1
0
        public void AddExhaustion(float amount, int cause)
        {
            if (this.IsCreative || this.IsSpectator)
            {
                return;
            }
            PlayerExhaustEventArgs playerExhaustEvent = new PlayerExhaustEventArgs(this, amount, cause);

            PlayerEvents.OnPlayerExhaust(playerExhaustEvent);
            if (playerExhaustEvent.IsCancel)
            {
                return;
            }
            float exhaustion = this.Exhaustion + playerExhaustEvent.Amount;

            while (exhaustion >= 4f)
            {
                exhaustion -= 4f;
                if (this.Saturation != 0)
                {
                    this.TakeSaturation(1f);
                }
                else
                {
                    this.TakeHunger(1f);
                }
            }
            this.Exhaustion = exhaustion;
        }
Пример #2
0
        /// <summary>
        /// <see cref="Player"/> の満腹度消耗値を増加させます
        /// </summary>
        /// <param name="amount"></param>
        /// <param name="cause"></param>
        public virtual void Exhaust(float amount, int cause = PlayerExhaustEventArgs.CAUSE_CUSTOM)
        {
            PlayerExhaustEventArgs args = new PlayerExhaustEventArgs(this, amount, cause);

            Server.Instance.Event.Player.OnPlayerExhaust(this, args);
            if (args.IsCancel)
            {
                return;
            }
            amount = args.Amount;

            float exhaustion = this.GetExhaustion() + amount;

            while (exhaustion >= 4f)
            {
                exhaustion -= 4f;
                float saturation = this.GetSaturation();
                if (saturation > 0)
                {
                    saturation = Math.Max(0, saturation - 1f);
                    this.SetSaturation(saturation);
                }
                else
                {
                    float hunger = this.GetHunger();
                    if (hunger > 0)
                    {
                        this.SetHunger(hunger - 1);
                    }
                }
            }
            this.SetExhaustion(exhaustion);
        }
 public static void OnPlayerExhaust(PlayerExhaustEventArgs args)
 {
     PlayerExhaust?.Invoke(args);
 }