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