179 lines
8.5 KiB
C#
179 lines
8.5 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using RPGCreationKit;
|
|||
|
|
|||
|
namespace RPGCreationKit
|
|||
|
{
|
|||
|
public class AmmoItemInTradeUI : AmmoItemInInventoryUI
|
|||
|
{
|
|||
|
public override void OnClick(bool takeAll = false)
|
|||
|
{
|
|||
|
if (TradeSystemUI.instance.isBuyingOrDrawing)
|
|||
|
{
|
|||
|
Debug.Log("Taking item: " + base.ammoItemInInventory.item.ItemName);
|
|||
|
if (TradeSystemUI.instance.isMerchant)
|
|||
|
{
|
|||
|
// if the amount is 1, add it one time
|
|||
|
if (base.ammoItemInInventory.Amount <= 1)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.confirmTradePanel.gameObject.SetActive(true);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.Init(base.ammoItemInInventory, this, "Are you sure you want to buy 1 " + base.ammoItemInInventory.item.ItemName + " for " + base.ammoItemInInventory.item.Value + " golds?");
|
|||
|
TradeSystemUI.instance.confirmTradePanel.continueButton.onClick.AddListener(() => ConfirmTrade(1, ConfirmTradeAction.BuyFromMerchant));
|
|||
|
}
|
|||
|
else if (base.ammoItemInInventory.item.isCumulable && base.ammoItemInInventory.Amount > 1)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
|
|||
|
TradeSystemUI.instance.takeDepositItemsPanel.Init(ammoItemInInventory, this);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// we're drawing from a friendly npc
|
|||
|
}
|
|||
|
}
|
|||
|
else // we're selling
|
|||
|
{
|
|||
|
// if the amount is 1, add it one time
|
|||
|
if (TradeSystemUI.instance.isMerchant)
|
|||
|
{
|
|||
|
// if the amount is 1, add it one time
|
|||
|
if (base.ammoItemInInventory.Amount <= 1)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.confirmTradePanel.gameObject.SetActive(true);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.Init(base.ammoItemInInventory, this, "Are you sure you want to sell 1 " + base.ammoItemInInventory.item.ItemName + " for " + base.ammoItemInInventory.item.Value + " golds?");
|
|||
|
TradeSystemUI.instance.confirmTradePanel.continueButton.onClick.AddListener(() => ConfirmTrade(1, ConfirmTradeAction.SellToMerchant));
|
|||
|
}
|
|||
|
else if (base.ammoItemInInventory.item.isCumulable && base.ammoItemInInventory.Amount > 1)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
|
|||
|
TradeSystemUI.instance.takeDepositItemsPanel.Init(ammoItemInInventory, this);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void ConfirmButtonCumulableItem(int amount)
|
|||
|
{
|
|||
|
if (TradeSystemUI.instance.isBuyingOrDrawing)
|
|||
|
{
|
|||
|
if (TradeSystemUI.instance.isMerchant)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.takeDepositItemsPanel.CancelButton();
|
|||
|
|
|||
|
TradeSystemUI.instance.confirmTradePanel.gameObject.SetActive(true);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.Init(base.ammoItemInInventory, this, "Are you sure you want to buy " + amount + " " + base.ammoItemInInventory.item.ItemName + " for " + (base.ammoItemInInventory.item.Value * amount) + " golds?", true);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.continueButton.onClick.AddListener(() => ConfirmTrade(amount, ConfirmTradeAction.BuyFromMerchant));
|
|||
|
} else
|
|||
|
{
|
|||
|
// friendly npc
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else // we're selling
|
|||
|
{
|
|||
|
if (TradeSystemUI.instance.isMerchant)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.takeDepositItemsPanel.CancelButton();
|
|||
|
|
|||
|
TradeSystemUI.instance.confirmTradePanel.gameObject.SetActive(true);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.Init(base.ammoItemInInventory, this, "Are you sure you want to sell " + amount + " " + base.ammoItemInInventory.item.ItemName + " for " + (base.ammoItemInInventory.item.Value * amount) + " golds?", true);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.continueButton.onClick.AddListener(() => ConfirmTrade(amount, ConfirmTradeAction.SellToMerchant));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//friendly npc
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void ConfirmTrade(int _amount, ConfirmTradeAction _action)
|
|||
|
{
|
|||
|
int totalGoldsAmount = (base.ammoItemInInventory.item.Value * _amount);
|
|||
|
|
|||
|
if (_action == ConfirmTradeAction.BuyFromMerchant)
|
|||
|
{
|
|||
|
if (Inventory.PlayerInventory.GetItemCount("Gold001") >= totalGoldsAmount)
|
|||
|
{
|
|||
|
Inventory.PlayerInventory.AddItem(base.ammoItemInInventory.item, base.ammoItemInInventory.metadata, _amount);
|
|||
|
|
|||
|
Inventory.PlayerInventory.RemoveItem("Gold001", totalGoldsAmount);
|
|||
|
TradeSystemUI.instance.curMerchant.inventory.AddItem("Gold001", totalGoldsAmount);
|
|||
|
|
|||
|
|
|||
|
// Remove the item from the merchant inventory
|
|||
|
TradeSystemUI.instance.curMerchant.inventory.RemoveItem(base.ammoItemInInventory, _amount);
|
|||
|
|
|||
|
TradeSystemUI.instance.PlaySound(GoldsSounds.Spend);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.CancelButton();
|
|||
|
AlertMessage.instance.InitAlertMessage("Transaction Completed!", 1.5f);
|
|||
|
|
|||
|
|
|||
|
TradeSystemUI.instance.UpdateStatsUI();
|
|||
|
// if the merchant's item is out of stocks, remove the item
|
|||
|
|
|||
|
if (base.ammoItemInInventory.Amount <= 0)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.SelectNextButton();
|
|||
|
|
|||
|
// Disable this object
|
|||
|
pool.usedObjects.Remove(this);
|
|||
|
pool.AmmosPool.usedObjects.Remove(this);
|
|||
|
|
|||
|
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
|
|||
|
gameObject.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Init();
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TradeSystemUI.instance.confirmTradePanel.CancelButton();
|
|||
|
AlertMessage.instance.InitAlertMessage("You don't have enough golds.", 1.5f);
|
|||
|
}
|
|||
|
}
|
|||
|
else if(_action == ConfirmTradeAction.SellToMerchant)
|
|||
|
{
|
|||
|
if (TradeSystemUI.instance.curMerchant.inventory.GetItemCount("Gold001") >= totalGoldsAmount)
|
|||
|
{
|
|||
|
TradeSystemUI.instance.curMerchant.inventory.AddItem(base.ammoItemInInventory.item, base.ammoItemInInventory.metadata, _amount);
|
|||
|
Inventory.PlayerInventory.RemoveItem(base.ammoItemInInventory, _amount);
|
|||
|
|
|||
|
TradeSystemUI.instance.curMerchant.inventory.RemoveItem("Gold001", totalGoldsAmount);
|
|||
|
Inventory.PlayerInventory.AddItem("Gold001", totalGoldsAmount);
|
|||
|
|
|||
|
TradeSystemUI.instance.PlaySound(GoldsSounds.Gain);
|
|||
|
TradeSystemUI.instance.confirmTradePanel.CancelButton();
|
|||
|
AlertMessage.instance.InitAlertMessage("Transaction Completed!", 1.5f);
|
|||
|
|
|||
|
TradeSystemUI.instance.UpdateStatsUI();
|
|||
|
|
|||
|
// if the merchant's item is out of stocks, remove the item
|
|||
|
|
|||
|
if (base.ammoItemInInventory.Amount <= 0)
|
|||
|
{
|
|||
|
pool.usedObjects.Remove(this);
|
|||
|
// Disable this object
|
|||
|
pool.usedObjects.Remove(this);
|
|||
|
pool.AmmosPool.usedObjects.Remove(this);
|
|||
|
|
|||
|
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
|
|||
|
gameObject.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Init();
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TradeSystemUI.instance.confirmTradePanel.CancelButton();
|
|||
|
AlertMessage.instance.InitAlertMessage("The merchant doesn't have enough golds.", 1.5f);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|