Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using TheForest.Utils;
- using UnityEngine;
- [global::DoNotSerializePublic]
- [Serializable]
- public class CaloriesSystemData
- {
- [Header("Calories")]
- public float JumpingCaloriesPerSecond = 0.5f;
- public float FightActionCalories = 3.5f;
- public float StationnaryCaloriesPerSecond = 0.03f;
- public float WalkingCaloriesPerSecond = 0.25f;
- public float RunningCaloriesPerSecond = 0.5f;
- public float SwimmingCaloriesPerSecond = 1.5f;
- public float CarryLogCaloriesPerSecond = 1f;
- [Header("Weight")]
- public float WeightGainPerExcessCalory = 0.0005f;
- public float WeightLossPerMissingCalory = 0.00015f;
- public float StrengthLossPerMissingCalory = 0.0001f;
- [Header("Strength")]
- public float StrengthGainPerEatenCalory = 0.001f;
- public float FightActionStrength = 0.001f;
- [global::SerializeThis, Header("Runtime data")]
- public float CurrentCaloriesBurntCount;
- [global::SerializeThis]
- public float CurrentCaloriesEatenCount;
- private int NextResolutionTime;
- public void Initialize()
- {
- if (TheForest.Utils.LocalPlayer.Stats.DaySurvived < 0.01f)
- {
- }
- this.NextResolutionTime = this.GetNextResolutionTime();
- }
- public void Refresh()
- {
- if (Time.timeScale > 0f)
- {
- if (TheForest.Utils.LocalPlayer.FpCharacter.jumping && !TheForest.Utils.LocalPlayer.FpCharacter.Sitting)
- {
- this.CaloriesBurntChange(this.JumpingCaloriesPerSecond * Time.deltaTime);
- }
- if (TheForest.Utils.LocalPlayer.FpCharacter.swimming && TheForest.Utils.LocalPlayer.Stats.Stamina > 0f && TheForest.Utils.LocalPlayer.Rigidbody.velocity.sqrMagnitude > 1f)
- {
- this.CaloriesBurntChange((this.SwimmingCaloriesPerSecond + ((!TheForest.Utils.LocalPlayer.FpCharacter.running) ? 0f : this.RunningCaloriesPerSecond)) * Time.deltaTime);
- }
- else if (TheForest.Utils.LocalPlayer.FpCharacter.running && TheForest.Utils.LocalPlayer.Stats.Stamina > 0f && TheForest.Utils.LocalPlayer.Rigidbody.velocity.sqrMagnitude > 1f)
- {
- this.CaloriesBurntChange((this.RunningCaloriesPerSecond + (float)TheForest.Utils.LocalPlayer.Inventory.Logs.Amount * 1.5f * this.CarryLogCaloriesPerSecond) * Time.deltaTime);
- }
- else if (TheForest.Utils.LocalPlayer.FpCharacter.Grounded && TheForest.Utils.LocalPlayer.Rigidbody.velocity.sqrMagnitude > 0.3f)
- {
- this.CaloriesBurntChange((this.WalkingCaloriesPerSecond + (float)TheForest.Utils.LocalPlayer.Inventory.Logs.Amount * this.CarryLogCaloriesPerSecond) * Time.deltaTime);
- }
- else if (TheForest.Utils.LocalPlayer.FpCharacter.Grounded)
- {
- this.CaloriesBurntChange(this.StationnaryCaloriesPerSecond * Time.deltaTime);
- }
- if (this.NextResolutionTime == -1)
- {
- this.NextResolutionTime = this.GetNextResolutionTime();
- }
- else if (global::FMOD_StudioEventEmitter.HoursSinceMidnight > (float)this.NextResolutionTime)
- {
- this.NextResolutionTime = this.GetNextResolutionTime();
- this.Resolve();
- }
- }
- }
- public int GetRawExcessCalories()
- {
- return Mathf.RoundToInt(this.CurrentCaloriesEatenCount - this.CurrentCaloriesBurntCount);
- }
- public int GetExcessCaloriesFinal()
- {
- return this.GetRawExcessCalories();
- }
- public int GetStrengthTrend()
- {
- return this.GetRawExcessCalories();
- }
- public int GetWeightTrend()
- {
- return this.GetExcessCaloriesFinal();
- }
- public void OnFighting()
- {
- this.CaloriesBurntChange(this.FightActionCalories);
- this.StrengthChange(this.FightActionStrength);
- }
- public void OnAteFood(int calories)
- {
- if (this.GetRawExcessCalories() <= 0)
- {
- this.StrengthChange((float)calories * this.StrengthGainPerEatenCalory);
- }
- this.CaloriesEatenChange((float)calories);
- }
- public void OnAttacked()
- {
- if ((TheForest.Utils.LocalPlayer.ScriptSetup.treeHit.atStump || TheForest.Utils.LocalPlayer.ScriptSetup.treeHit.atTree) && (TheForest.Utils.LocalPlayer.Animator.GetBool("axeHeld") || TheForest.Utils.LocalPlayer.Animator.GetBool("chainSawHeld")))
- {
- this.CaloriesBurntChange(1f);
- }
- }
- private void CaloriesEatenChange(float value)
- {
- this.CurrentCaloriesEatenCount += value;
- }
- private void CaloriesBurntChange(float value)
- {
- this.CurrentCaloriesBurntCount += value;
- }
- private void WeightChange(float value)
- {
- TheForest.Utils.LocalPlayer.Stats.PhysicalStrength.WeightChange(value);
- }
- private void StrengthChange(float value)
- {
- TheForest.Utils.LocalPlayer.Stats.PhysicalStrength.StrengthChange(value);
- }
- public float TimeToNextResolution()
- {
- if (global::FMOD_StudioEventEmitter.HoursSinceMidnight < 21f)
- {
- return (float)this.NextResolutionTime - global::FMOD_StudioEventEmitter.HoursSinceMidnight;
- }
- return 24f - global::FMOD_StudioEventEmitter.HoursSinceMidnight + 8f;
- }
- private int GetNextResolutionTime()
- {
- if (global::FMOD_StudioEventEmitter.HoursSinceMidnight < 8f)
- {
- return 8;
- }
- if (global::FMOD_StudioEventEmitter.HoursSinceMidnight < 13f)
- {
- return 13;
- }
- if (global::FMOD_StudioEventEmitter.HoursSinceMidnight < 21f)
- {
- return 21;
- }
- return -1;
- }
- private void Resolve()
- {
- int excessCaloriesFinal = this.GetExcessCaloriesFinal();
- if (excessCaloriesFinal > 0)
- {
- this.WeightChange((float)excessCaloriesFinal * this.WeightGainPerExcessCalory);
- }
- else
- {
- this.WeightChange((float)excessCaloriesFinal * this.WeightLossPerMissingCalory);
- this.StrengthChange((float)excessCaloriesFinal * this.StrengthLossPerMissingCalory);
- }
- this.CurrentCaloriesBurntCount = 0f;
- this.CurrentCaloriesEatenCount = 0f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement