DialogueTradeTaskAction.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using NodeCanvas.Framework;
  5. using ParadoxNotion.Design;
  6. using KairoEngine.Core;
  7. using KairoEngine.Inventory;
  8. namespace KairoEngine.CharacterSystem
  9. {
  10. public enum TradeType
  11. {
  12. Buy,
  13. Sell
  14. }
  15. public class DialogueTradeTaskAction : ActionTask
  16. {
  17. [BlackboardOnly] public BBParameter<CharacterController> character;
  18. public TradeType tradeType = TradeType.Buy;
  19. private bool closed = false;
  20. private string containerName;
  21. private ItemContainer itemContainer;
  22. protected override string info
  23. {
  24. get
  25. {
  26. if(tradeType == TradeType.Buy) return "Buy Items";
  27. else return "Sell Items";
  28. }
  29. }
  30. protected override void OnExecute()
  31. {
  32. containerName = "";
  33. if(tradeType == TradeType.Buy)
  34. {
  35. containerName = "Buy Items";
  36. itemContainer = character.value.GetComponent<ItemContainer>();
  37. }
  38. else
  39. {
  40. containerName = "Sell Items";
  41. itemContainer = character.value.GetComponents<ItemContainer>()[1];
  42. }
  43. ICommand openItemContainerCommand = new OpenItemContainerCommand(containerName, itemContainer);
  44. CommandInvoker.AddCommand(openItemContainerCommand);
  45. GenericEvents.StartListening("TradeFinished", OnTradeFinish);
  46. }
  47. protected override void OnStop()
  48. {
  49. GenericEvents.StopListening("TradeFinished", OnTradeFinish);
  50. if(closed == false)
  51. {
  52. ICommand closeItemContainerCommand = new CloseItemContainerCommand(containerName);
  53. CommandInvoker.AddCommand(closeItemContainerCommand);
  54. }
  55. }
  56. void OnTradeFinish()
  57. {
  58. GenericEvents.StopListening("TradeFinished", OnTradeFinish);
  59. closed = true;
  60. EndAction(true);
  61. }
  62. }
  63. }