Firstborn/Assets/RPG Creation Kit/Scripts/Looting System/Items In Looting UI/MiscItemInLootingUI_DrawDep...

170 lines
7.3 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using RPGCreationKit;
using RPGCreationKit.AI;
namespace RPGCreationKit
{
public class MiscItemInLootingUI_DrawDeposit : MiscItemInInventoryUI
{
public override void OnClick(bool takeAll = false)
{
if (LootingInventoryUI.instance.curIsPickPocket)
{
// Player is attempting to pickpocket
// This is a VERY simple rule, if the weight of the item is over 1 the player will never be able to successfully pickpocket it
// You may want to change/alter this for your own projects
float chanceForFailure = miscItemInInventory.item.Weight;
// Could use Vector3.Dot to make less likely to succeed when infront of the AI
if (chanceForFailure > Random.value)
{
// Failed chance check
RckAI ai = LootingInventoryUI.instance.curLootingPoint.GetComponent<RckAI>();
ai.TryEngageWithPlayer(); // Engage with player
LootingInventoryUI.instance.CloseUI();
return;
}
}
// Some palce in the codebase seems to be calling this method after the CloseUI randomly, not sure why or where yet
// this is a backup in that case
if (LootingInventoryUI.instance.curIsPickPocket && LootingInventoryUI.instance.curLootingPoint == null) {
return;
}
if (LootingInventoryUI.instance.isDrawing)
{
// if the amount is 1, add it one time
if (base.miscItemInInventory.Amount <= 1)
{
Inventory.PlayerInventory.AddItem(base.miscItemInInventory.item, base.miscItemInInventory.metadata, 1, !takeAll);
// Remove the item from the current loot inventory
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.miscItemInInventory, 1);
LootingInventoryUI.instance.SelectNextButton();
// Disable this object
pool.usedObjects.Remove(this);
pool.MiscsPool.usedObjects.Remove(this);
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else if (base.miscItemInInventory.item.isCumulable && base.miscItemInInventory.Amount > 1)
{
if (!takeAll)
{
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
LootingInventoryUI.instance.takeDepositItemsPanel.Init(miscItemInInventory, this);
}
else
{
ConfirmButtonCumulableItem(base.miscItemInInventory.Amount);
}
}
}
else // we're depositing
{
if (base.miscItemInInventory.item.QuestItem)
{
AlertMessage.instance.InitAlertMessage("You can't leave Quest Items", AlertMessage.DEFAULT_MESSAGE_DURATION_MEDIUM);
return;
}
// if the amount is 1, add it one time
if (base.miscItemInInventory.Amount <= 1)
{
// Remove the item from the current loot inventory
LootingInventoryUI.instance.curLootingPoint.inventory.AddItem(base.miscItemInInventory.item, base.miscItemInInventory.metadata, 1);
Inventory.PlayerInventory.RemoveItem(base.miscItemInInventory, 1);
// Call OnDeposit of ItemScript
if (!string.IsNullOrEmpty(base.miscItemInInventory.item.itemScript))
{
ItemScript iScript = (ItemScript)QuestScriptManager.instance.scriptsHolder.AddComponent(System.Type.GetType(base.miscItemInInventory.item.itemScript));
iScript.OnDepositInContainer(LootingInventoryUI.instance.curLootingPoint);
Destroy(iScript);
}
LootingInventoryUI.instance.SelectNextButton();
// Disable this object
pool.usedObjects.Remove(this);
pool.MiscsPool.usedObjects.Remove(this);
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else if (base.miscItemInInventory.item.isCumulable && base.miscItemInInventory.Amount > 1)
{
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
LootingInventoryUI.instance.takeDepositItemsPanel.Init(miscItemInInventory, this);
}
}
}
public override void ConfirmButtonCumulableItem(int amount)
{
if (LootingInventoryUI.instance.isDrawing)
{
// Add in PlayerInventory
Inventory.PlayerInventory.AddItem(base.miscItemInInventory.item, base.miscItemInInventory.metadata, amount);
// Remove from Loot Inventory
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.miscItemInInventory, amount);
if (miscItemInInventory.Amount <= 0)
{
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
LootingInventoryUI.instance.SelectNextButton(true);
//If we've took all the items
pool.usedObjects.Remove(this);
pool.MiscsPool.usedObjects.Remove(this);
// Disable this object
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
this.gameObject.SetActive(false);
}
else
{
// Update the UI
Init();
}
}
else // we're depositing
{
// Remove from Loot Inventory
LootingInventoryUI.instance.curLootingPoint.inventory.AddItem(base.miscItemInInventory.item, base.miscItemInInventory.metadata, 1);
// Add in PlayerInventory
Inventory.PlayerInventory.RemoveItem(base.miscItemInInventory, 1);
if (miscItemInInventory.Amount <= 0)
{
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
LootingInventoryUI.instance.SelectNextButton(true);
//If we've took all the items
pool.usedObjects.Remove(this);
pool.MiscsPool.usedObjects.Remove(this);
// Disable this object
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else
{
// Update the UI
Init();
}
}
}
}
}