Ejemplo n.º 1
0
    // Metabolism tick
    private void ServerUpdateMe()
    {
        if (bloodSystem.HeartStopped)
        {
            return;
        }

        //Apply hunger
        nutritionLevel -= HungerRate;

        //Apply effects
        for (int i = effects.Count - 1; i >= 0; i--)
        {
            MetabolismEffect e = effects[i];

            if (e.duration <= 0)
            {
                effects.RemoveAt(i);
                continue;
            }

            nutritionLevel         += e.totalNutrients / e.initialDuration;
            bloodSystem.ToxinLevel += e.totalToxins / e.initialDuration;
            e.duration--;
            effects[i] = e;
        }

        nutritionLevel = Mathf.Clamp(nutritionLevel, 0, NUTRITION_LEVEL_MAX);

        HungerState oldState = this.HungerState;

        if (nutritionLevel > NUTRITION_LEVEL_STUFFED)         //TODO: Make character nauseous when he's too full
        {
            HungerState = HungerState.Full;
        }
        else if (nutritionLevel > NUTRITION_LEVEL_NORMAL)
        {
            HungerState = HungerState.Normal;
        }
        else if (nutritionLevel > NUTRITION_LEVEL_HUNGRY)
        {
            HungerState = HungerState.Hungry;
        }
        else if (nutritionLevel > NUTRITION_LEVEL_MALNOURISHED)
        {
            HungerState = HungerState.Malnourished;
        }
        else
        {
            HungerState = HungerState.Starving;
        }

        if (oldState != this.HungerState)
        {
            SetHungerState(HungerState);
            // HungerState was altered, send new one to player
            UpdateHungerStateMessage.Send(this.gameObject, HungerState);
        }
    }
    public static UpdateHungerStateMessage Send(GameObject recipient, HungerState state)
    {
        UpdateHungerStateMessage msg = new UpdateHungerStateMessage
        {
            State = state
        };

        msg.SendTo(recipient);
        return(msg);
    }
Ejemplo n.º 3
0
    void UpdateMe()
    {
        //Server only
        if (CustomNetworkManager.Instance._isServer)
        {
            tick += Time.deltaTime;

            if (tick >= metabolismRate && !bloodSystem.HeartStopped)             //Metabolism tick
            {
                //Apply hunger
                nutritionLevel -= HungerRate;

                //Apply effects
                for (int i = effects.Count - 1; i >= 0; i--)
                {
                    MetabolismEffect e = effects[i];

                    if (e.duration <= 0)
                    {
                        effects.RemoveAt(i);
                        continue;
                    }

                    nutritionLevel         += e.totalNutrients / e.initialDuration;
                    bloodSystem.ToxinLevel += e.totalToxins / e.initialDuration;
                    e.duration--;
                    effects[i] = e;
                }

                nutritionLevel = Mathf.Clamp(nutritionLevel, 0, MAX_NUTRITION_LEVEL);

                HungerState oldState = this.HungerState;

                if (nutritionLevel > 150)                 //TODO: Make character nauseous when he's too full
                {
                    HungerState = HungerState.Full;
                }
                else if (nutritionLevel > 75)
                {
                    HungerState = HungerState.Normal;
                }
                else if (nutritionLevel > 25)
                {
                    HungerState = HungerState.Hungry;
                }
                else if (nutritionLevel > 0)
                {
                    HungerState = HungerState.Malnourished;
                }
                else
                {
                    HungerState = HungerState.Starving;
                }

                if (oldState != this.HungerState)                 //HungerState was altered, send new one to player
                {
                    UpdateHungerStateMessage.Send(this.gameObject, HungerState);
                }

                tick = 0;
            }
        }

        //Client and server
        if (HungerState == HungerState.Starving)
        {
            playerMove.RunSpeed = playerMove.WalkSpeed;
        }
        else
        {
            playerMove.RunSpeed = playerMove.InitialRunSpeed;
        }
    }