using System.Collections; using System.Collections.Generic; using UnityEngine; using NodeCanvas.Framework; using ParadoxNotion.Design; using KairoEngine.Core; using KairoEngine.Inventory; namespace KairoEngine.CharacterSystem { public enum TradeType { Buy, Sell } public class DialogueTradeTaskAction : ActionTask { [BlackboardOnly] public BBParameter character; public TradeType tradeType = TradeType.Buy; private bool closed = false; private string containerName; private ItemContainer itemContainer; protected override string info { get { if(tradeType == TradeType.Buy) return "Buy Items"; else return "Sell Items"; } } protected override void OnExecute() { containerName = ""; if(tradeType == TradeType.Buy) { containerName = "Buy Items"; itemContainer = character.value.GetComponent(); } else { containerName = "Sell Items"; itemContainer = character.value.GetComponents()[1]; } ICommand openItemContainerCommand = new OpenItemContainerCommand(containerName, itemContainer); CommandInvoker.AddCommand(openItemContainerCommand); GenericEvents.StartListening("TradeFinished", OnTradeFinish); } protected override void OnStop() { GenericEvents.StopListening("TradeFinished", OnTradeFinish); if(closed == false) { ICommand closeItemContainerCommand = new CloseItemContainerCommand(containerName); CommandInvoker.AddCommand(closeItemContainerCommand); } } void OnTradeFinish() { GenericEvents.StopListening("TradeFinished", OnTradeFinish); closed = true; EndAction(true); } } }