From 0f60b41d5848ca0b2021a47fb0ff52a21f572712 Mon Sep 17 00:00:00 2001 From: Vova <3emaster@gmail.com> Date: Tue, 19 Dec 2023 19:22:26 +0200 Subject: [PATCH] implement simple learning process --- Assets/Scripts/Helpers/Enums.cs | 12 +++-- .../BaseInteractableObject.cs | 1 + .../{OfficeTable.cs => JobAgency.cs} | 2 +- ...{OfficeTable.cs.meta => JobAgency.cs.meta} | 0 .../InteractableObjects/SchoolEnroll.cs | 52 +++++++++++++++++++ ...etaryDesk.cs.meta => SchoolEnroll.cs.meta} | 0 .../InteractableObjects/SecretaryDesk.cs | 24 --------- Assets/Scripts/Player/Education.meta | 8 +++ Assets/Scripts/Player/Player.cs | 13 +++++ .../ScriptableObjects/EducationInfoSO.cs | 1 + Assets/Scripts/UIElements/UISystem.cs | 2 +- 11 files changed, 84 insertions(+), 31 deletions(-) rename Assets/Scripts/InteractableObjects/{OfficeTable.cs => JobAgency.cs} (90%) rename Assets/Scripts/InteractableObjects/{OfficeTable.cs.meta => JobAgency.cs.meta} (100%) create mode 100644 Assets/Scripts/InteractableObjects/SchoolEnroll.cs rename Assets/Scripts/InteractableObjects/{SecretaryDesk.cs.meta => SchoolEnroll.cs.meta} (100%) delete mode 100644 Assets/Scripts/InteractableObjects/SecretaryDesk.cs create mode 100644 Assets/Scripts/Player/Education.meta diff --git a/Assets/Scripts/Helpers/Enums.cs b/Assets/Scripts/Helpers/Enums.cs index 107bef47..1c80df3a 100644 --- a/Assets/Scripts/Helpers/Enums.cs +++ b/Assets/Scripts/Helpers/Enums.cs @@ -3,10 +3,10 @@ public enum JobPositions { Unemployed, Cashier, Clerk, ManagerAssistaint, Manager }; public enum EducationSkill { NotEducated, School, HightSchool, University }; public enum PlayerStates { Awake, Sleeping, Eating, Working } -public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job,LocationName } +public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job, LocationName } public enum Tasks { Move, Interact, Rotate }; public enum TaskStatus { Waiting, InProgress, Complete }; -public enum InteractionStatus { None,Complete, WaitForChoose, InProgress, FarFromPlayer }; +public enum InteractionStatus { None, Complete, WaitForChoose, InProgress, FarFromPlayer }; public enum AnimationStates { [EnumMember(Value = "Idle")] @@ -23,7 +23,8 @@ public enum AnimationStates Standing }; -public enum RadialMenuActions { +public enum RadialMenuActions +{ Cancel, Sleep, Eat, @@ -31,7 +32,8 @@ public enum RadialMenuActions { Take, Work, Talk, - Buy , + Buy, Open, - Enter + Enter, + Learn, } \ No newline at end of file diff --git a/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs b/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs index 94fa397a..c32b3e4f 100644 --- a/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs +++ b/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs @@ -28,6 +28,7 @@ public abstract class BaseInteractableObject : MonoBehaviour { RadialMenuActions.Open, new RadialMenuActionDescription() { Description = "Open", IsEnabled = false } }, { RadialMenuActions.Enter, new RadialMenuActionDescription() { Description = "Enter", IsEnabled = false } }, { RadialMenuActions.Cancel, new RadialMenuActionDescription() { Description = "Cancel", IsEnabled = true } }, + { RadialMenuActions.Learn, new RadialMenuActionDescription() { Description = "Learn", IsEnabled = false} }, }; } diff --git a/Assets/Scripts/InteractableObjects/OfficeTable.cs b/Assets/Scripts/InteractableObjects/JobAgency.cs similarity index 90% rename from Assets/Scripts/InteractableObjects/OfficeTable.cs rename to Assets/Scripts/InteractableObjects/JobAgency.cs index 6ed125e3..9fd2f236 100644 --- a/Assets/Scripts/InteractableObjects/OfficeTable.cs +++ b/Assets/Scripts/InteractableObjects/JobAgency.cs @@ -12,7 +12,7 @@ public class OfficeTable : BaseInteractableObject protected override void InteractAction(RadialMenuActions interactAction) { - GameManager.Instance.UI.ShowTabObtionsDialog(_dialogSO, null, OnConfirm); + GameManager.Instance.UI.ShowTabOptionsDialog(_dialogSO, null, OnConfirm); } private void OnConfirm(IDialogOption selectedJob) diff --git a/Assets/Scripts/InteractableObjects/OfficeTable.cs.meta b/Assets/Scripts/InteractableObjects/JobAgency.cs.meta similarity index 100% rename from Assets/Scripts/InteractableObjects/OfficeTable.cs.meta rename to Assets/Scripts/InteractableObjects/JobAgency.cs.meta diff --git a/Assets/Scripts/InteractableObjects/SchoolEnroll.cs b/Assets/Scripts/InteractableObjects/SchoolEnroll.cs new file mode 100644 index 00000000..a5e20b48 --- /dev/null +++ b/Assets/Scripts/InteractableObjects/SchoolEnroll.cs @@ -0,0 +1,52 @@ +using Assets.Scripts.Interfaces; +using System; +using Unity.VisualScripting; +using UnityEngine; + +public class SecretaryDesk : BaseInteractableObject +{ + [SerializeField] + private DialogSO _dialogSO; + + protected override void PrepareMenuActions() + { + _menuActions[RadialMenuActions.Talk].IsEnabled = true; + _menuActions[RadialMenuActions.Learn].IsEnabled = Player.Instance.ActiveCourse != null; + } + + protected override void InteractAction(RadialMenuActions interactAction) + { + switch (interactAction) + { + + case RadialMenuActions.Talk: + GameManager.Instance.UI.ShowTabOptionsDialog(_dialogSO, null, OnConfirm); + break; + case RadialMenuActions.Learn: + GameManager.Instance.UI.ShowTimeSliderDialog("Learn", "learn until", OnCancel, OnLearnConfirm); + break; + } + } + + private void OnLearnConfirm(TimeSpan time) + { + GameManager.Instance.Time.FastForward(time); + GameManager.Instance.Time.OnFastForwardEnd += OnFastForwardEnd; + _player.Learn(time); + } + private void OnCancel() + { + OnFastForwardEnd(); + } + private void OnFastForwardEnd() + { + _player.SetPlayerActing(PlayerStates.Awake); + _player.SetPlayerAnimation(AnimationStates.Standing); + GameManager.Instance.Time.OnFastForwardEnd -= OnFastForwardEnd; + } + private void OnConfirm(IDialogOption selectedOption) + { + _player.ActiveCourse = (selectedOption as EducationInfoSO); + print($"player selected course is {(selectedOption as EducationInfoSO).Description}"); + } +} diff --git a/Assets/Scripts/InteractableObjects/SecretaryDesk.cs.meta b/Assets/Scripts/InteractableObjects/SchoolEnroll.cs.meta similarity index 100% rename from Assets/Scripts/InteractableObjects/SecretaryDesk.cs.meta rename to Assets/Scripts/InteractableObjects/SchoolEnroll.cs.meta diff --git a/Assets/Scripts/InteractableObjects/SecretaryDesk.cs b/Assets/Scripts/InteractableObjects/SecretaryDesk.cs deleted file mode 100644 index 7f0815e2..00000000 --- a/Assets/Scripts/InteractableObjects/SecretaryDesk.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Assets.Scripts.Interfaces; -using UnityEngine; - -public class SecretaryDesk : BaseInteractableObject -{ - [SerializeField] - private DialogSO _dialogSO; - - protected override void PrepareMenuActions() - { - _menuActions[RadialMenuActions.Talk].IsEnabled = true; - } - - protected override void InteractAction(RadialMenuActions interactAction) - { - GameManager.Instance.UI.ShowTabObtionsDialog(_dialogSO, null, OnConfirm); - } - - private void OnConfirm(IDialogOption selectedOption) - { - //_player.JobPosition = (selectedOption as EducationInfoSO).JobPosition; - print($"player selected position is {(selectedOption as EducationInfoSO).Description}"); - } -} diff --git a/Assets/Scripts/Player/Education.meta b/Assets/Scripts/Player/Education.meta new file mode 100644 index 00000000..efd8783d --- /dev/null +++ b/Assets/Scripts/Player/Education.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 64bc13a0b6923c14ab5d87e8338aca0c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs index d8480018..7acbf917 100644 --- a/Assets/Scripts/Player/Player.cs +++ b/Assets/Scripts/Player/Player.cs @@ -16,6 +16,8 @@ public class Player : BaseCharacter public Dictionary Stats; public JobPositions JobPosition { get; set; } + private List _completedCourses=new(); + public EducationInfoSO ActiveCourse { get; set; } public EducationSkill Education { get; set; } private ContainerItem _containerItem; @@ -148,4 +150,15 @@ public class Player : BaseCharacter { return _locationName; } + + internal void Learn(TimeSpan time) + { + ActiveCourse.PlayerProgress+= time.Hours; + if(ActiveCourse.PlayerProgress>=ActiveCourse.Duration) + { + Education++; + print($"Congratulation player finish curse {ActiveCourse.Description} and his education now {Education.ToString()}"); + ActiveCourse =null; + } + } } diff --git a/Assets/Scripts/ScriptableObjects/EducationInfoSO.cs b/Assets/Scripts/ScriptableObjects/EducationInfoSO.cs index a866dc64..58135bec 100644 --- a/Assets/Scripts/ScriptableObjects/EducationInfoSO.cs +++ b/Assets/Scripts/ScriptableObjects/EducationInfoSO.cs @@ -8,4 +8,5 @@ public class EducationInfoSO : IDialogOption public int Duration; public float EnrollPrice; public EducationSkill Skill; + public int PlayerProgress; } diff --git a/Assets/Scripts/UIElements/UISystem.cs b/Assets/Scripts/UIElements/UISystem.cs index db6a81f3..dc0f319a 100644 --- a/Assets/Scripts/UIElements/UISystem.cs +++ b/Assets/Scripts/UIElements/UISystem.cs @@ -28,7 +28,7 @@ public class UISystem : MonoBehaviour timeSlider.ShowTimeSliderDialog(title, description, onCancel, onConfirm); } - public void ShowTabObtionsDialog(DialogSO dialogSO, Action onCancel, Action onConfirm) + public void ShowTabOptionsDialog(DialogSO dialogSO, Action onCancel, Action onConfirm) { var dialog = Instantiate(_DialogUIPrefab, transform); dialog.ShowCategoriesDialog(dialogSO, onCancel, onConfirm);