Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / BlackSmith / Blacksmith.cs
  1. using MyCollections.Managers;
  2. using UnityEngine;
  3. public class Blacksmith : InteractableNPC
  4. {
  5. [SerializeField] private GameObject shopObjectPrefab;
  6. [SerializeField] private StoryData storyData;
  7. private GameObject shop;
  8. private bool hasMetPlayer;
  9. public bool hasGreetPlayer;
  10. protected override void Start()
  11. {
  12. base.Start();
  13. currentStory = storyData.GetStory();
  14. currentStory.BindExternalFunction("OpenShop", OpenShop);
  15. }
  16. protected override void Update()
  17. {
  18. base.Update();
  19. }
  20. protected override void AnimationController()
  21. {
  22. base.AnimationController();
  23. if (agentFOV.GetTarget() != null)
  24. {
  25. Vector2 dir = agentFOV.TargetDirection;
  26. animator.SetFloat("TargetDirectionX", dir.x);
  27. animator.SetFloat("TargetDirectionY", dir.y);
  28. }
  29. }
  30. //Opens the shop
  31. private void OpenShop()
  32. {
  33. NotifyObservers(NotificationType.UI, ("UIObject", shopObjectPrefab));
  34. NotifyObservers(NotificationType.Dialogue, ("ExitStory", null));
  35. }
  36. //Closes the upgrade shop
  37. public void CloseShop()
  38. {
  39. if (shop != null)
  40. {
  41. Destroy(shop);
  42. }
  43. }
  44. public void ResetStory()
  45. {
  46. // Store the current value of has_met_player
  47. object hasMetPlayerValue = currentStory.variablesState["has_met_player"];
  48. if (hasMetPlayerValue is bool)
  49. {
  50. hasMetPlayer = (bool)hasMetPlayerValue;
  51. }
  52. // Reset the story state
  53. currentStory.ResetState();
  54. // Restore the has_met_player variable as a new BoolValue
  55. currentStory.variablesState["has_met_player"] = hasMetPlayer;
  56. }
  57. public override void OnInteract()
  58. {
  59. ResetStory();
  60. NotifyObservers(NotificationType.Dialogue, ("Story", currentStory), ("NPCname", npcName));
  61. }
  62. }