sleep increase the energy

This commit is contained in:
Vladimir Koshevarov
2023-03-14 13:36:24 +02:00
parent f6a8ca9d9d
commit dbd1d16a24
9 changed files with 60 additions and 76 deletions
+10 -10
View File
@@ -1863,7 +1863,7 @@ PrefabInstance:
- target: {fileID: 808129671576928264, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 20
value: 0
objectReference: {fileID: 0}
- target: {fileID: 808129671576928264, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
@@ -1888,7 +1888,7 @@ PrefabInstance:
- target: {fileID: 896272491191485165, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 182.005
value: 0
objectReference: {fileID: 0}
- target: {fileID: 896272491191485165, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
@@ -2013,22 +2013,22 @@ PrefabInstance:
- target: {fileID: 4307980429506515175, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307980429506515175, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307980429506515175, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 250
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307980429506515175, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -90
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4537241548631189332, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
@@ -2123,7 +2123,7 @@ PrefabInstance:
- target: {fileID: 6551138445549304010, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 182.005
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6551138445549304010, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
@@ -2248,7 +2248,7 @@ PrefabInstance:
- target: {fileID: 7883991513978601488, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 182.005
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7883991513978601488, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
@@ -2268,12 +2268,12 @@ PrefabInstance:
- target: {fileID: 7949779033593405736, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_SizeDelta.x
value: 364.01
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7949779033593405736, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 182.005
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7949779033593405736, guid: 8939548f67eb43c4fa321f112c45f83b,
type: 3}
-1
View File
@@ -18,7 +18,6 @@ namespace Assets.Scripts.Actions
}
public void ApplyAction(Player playerController)
{
playerController.WorkPlace = this;
}
}
}
-20
View File
@@ -1,20 +0,0 @@
using Assets.Scripts.Actions.Interfaces;
namespace Assets.Scripts.Actions
{
public class Relax : IPlayerAction
{
private int _energyPerTick;
public Relax(int duration, int energyPerTick)
{
_energyPerTick = energyPerTick;
}
public string Description => throw new System.NotImplementedException();
public void ApplyAction(Player playerController)
{
playerController.Stats[StatsId.Energy].increase(_energyPerTick);
}
}
}
+2
View File
@@ -1,5 +1,7 @@
using System.Runtime.Serialization;
public enum PlayerStates { Awake, Sleeping, Eating }
public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job, }
public enum Tasks { Move, Interact, Rotate };
public enum TaskStatus { Waiting, InProgress, Complete };
@@ -12,11 +12,13 @@ public class Bed : BaseInteractableObject
private void OnAnimationFinished()
{
_player.SetPlayerActing(PlayerStates.Sleeping);
TimeManager.Instance.FastForward(TimeSpan.FromHours(8), OnFastForwardEnd);
}
private void OnFastForwardEnd()
{
_player.SetPlayerActing(PlayerStates.Awake);
_player.SetPlayerAnimation(AnimationStates.Standing);
}
}
+15 -42
View File
@@ -1,9 +1,5 @@
using Assets.Scripts.Actions.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using UnityEngine;
using UnityEngine.AI;
@@ -21,10 +17,10 @@ public class Player : MonoBehaviour
[SerializeField]
private Transform _holdPoint;
private PlayerStates _currentActing;
private AnimationStates _currentAnimation;
public Dictionary<StatsId, Stat> Stats;
public IWorkPlace WorkPlace { get; set; }
private readonly Queue<PlayerTasks> _tasks = new Queue<PlayerTasks>();
private PlayerTasks _currentTask;
@@ -47,12 +43,14 @@ public class Player : MonoBehaviour
Instance = this;
DontDestroyOnLoad(gameObject);
}
private void Start()
{
TimeManager.OnMinuteChanged += UpdateStatsByClock;
_animator.applyRootMotion = true;
_navAgent.updatePosition = false;
Stats = PlayerStats.CreateInitialStats();
_currentActing = PlayerStates.Awake;
}
private void OnDestroy()
@@ -62,7 +60,7 @@ public class Player : MonoBehaviour
private void Update()
{
if (IsBlockingAnimation(_currentAnimation))
if (PlayerHelper.IsBlockingAnimation(_currentAnimation))
{
if (IsAnimationStatePlaying(0))
{
@@ -116,7 +114,6 @@ public class Player : MonoBehaviour
{
_navAgent.Warp(desiredPosition);
_navAgent.updatePosition = false;
}
private TaskStatus MoveToPoint()
@@ -176,20 +173,20 @@ public class Player : MonoBehaviour
_OnAnimationFinish = onAnimationFinish;
SetPlayerAnimation(newState);
}
public void SetPlayerAnimation(AnimationStates newState)
{
if (newState == _currentAnimation)
{
return;
}
_animator.Play(GetEnumMemberValue(newState));
_animator.Play(PlayerHelper.GetEnumMemberValue(newState));
_currentAnimation = newState;
}
public bool IsAnimationStatePlaying(int animLayer)
{
string stateName = GetEnumMemberValue(_currentAnimation);
string stateName = PlayerHelper.GetEnumMemberValue(_currentAnimation);
var stateInfo = _animator.GetCurrentAnimatorStateInfo(animLayer);
return stateInfo.IsName(stateName) && stateInfo.normalizedTime < 1.0f;
@@ -200,17 +197,21 @@ public class Player : MonoBehaviour
_tasks.Enqueue(task);
}
public void SetPlayerActing(PlayerStates state)
{
_currentActing = state;
}
public void UpdateStatsByClock()
{
Stats[StatsId.Food].deduct(0.034f); // 48 hours it's 100, 100/2880=~0.034 per minute
if (_currentAnimation != AnimationStates.Sleeping)
if (_currentActing != PlayerStates.Sleeping)
{
Stats[StatsId.Energy].deduct(0.1f); // 24 hours it's 100, 100/1440=~0.096 per minute
}
else
{
Stats[StatsId.Energy].increase(1f);
Stats[StatsId.Energy].increase(0.2f);
}
}
@@ -218,41 +219,13 @@ public class Player : MonoBehaviour
{
Stats[StatsId.Money].deduct(amount);
}
public float Eat()
{
Stats[StatsId.Food].increase(10);
return Stats[StatsId.Food].Value;
}
private static string GetEnumMemberValue<T>(T value)
where T : struct, IConvertible
{
return typeof(T)
.GetTypeInfo()
.DeclaredMembers
.SingleOrDefault(x => x.Name == value.ToString())
?.GetCustomAttribute<EnumMemberAttribute>(false)
?.Value;
}
private static bool IsBlockingAnimation<T>(T value)
where T : struct, IConvertible
{
var enumType = typeof(T);
var memInfo = enumType.GetMember(value.ToString());
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<BlockingAnimation>().FirstOrDefault();
return attr != null;
}
public void SetContainerItem(ContainerItem containerItem)
{
containerItem.transform.parent = _holdPoint;
containerItem.transform.localPosition = Vector3.zero;
_containerItem = containerItem;
}
public ContainerItem GetContainerItem()
{
return _containerItem;
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
public static class PlayerHelper
{
public static string GetEnumMemberValue<T>(T value)
where T : struct, IConvertible
{
return typeof(T)
.GetTypeInfo()
.DeclaredMembers
.SingleOrDefault(x => x.Name == value.ToString())
?.GetCustomAttribute<EnumMemberAttribute>(false)
?.Value;
}
public static bool IsBlockingAnimation<T>(T value)
where T : struct, IConvertible
{
var enumType = typeof(T);
var memInfo = enumType.GetMember(value.ToString());
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<BlockingAnimation>().FirstOrDefault();
return attr != null;
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 986e2b29060766347a43dc46e30a648e
guid: 1e0c9736e301f4f4d89a127e9efde6c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
+2 -2
View File
@@ -9,8 +9,8 @@ public class PlayerStats
{
{StatsId.Money, new Stat("Money", 100.0f,10000000f)},
{StatsId.RentAccount, new Stat("Rent Account", 0,10f)},
{StatsId.Food, new Stat("Food Energy", 50,100f) },
{StatsId.Energy,new Stat("Energy", 100,100f) },
{StatsId.Food, new Stat("Food Energy", 50f,100f) },
{StatsId.Energy,new Stat("Energy", 50f,100f) },
//{StatsId.BankAccount,new Stat("Bank Account", 0) },
{StatsId.Job, new Stat("Unemployed", 0, 100f) },
};