1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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<CharacterController> 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<ItemContainer>();
- }
- else
- {
- containerName = "Sell Items";
- itemContainer = character.value.GetComponents<ItemContainer>()[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);
- }
- }
- }
|