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

175 lines
7.7 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 ConsumableItemInLootingUI_DrawDeposit : ConsumableItemInInventoryUI
{
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 = consumableItemInInventory.item.Weight;
float ItemValue = consumableItemInInventory.item.Value;
float RandomValue = UnityEngine.Random.value;
float RandomMaxValue = (RandomValue * 10f);
// Could use Vector3.Dot to make less likely to succeed when infront of the AI
Debug.Log("chanceForFailure :"+chanceForFailure);
Debug.Log("Random.value :"+RandomValue);
Debug.Log("RandomMaxValue :"+RandomMaxValue);
if ((chanceForFailure > RandomValue))// && (ItemValue < RandomMaxValue))
{
// Failed chance check
RckAI ai = LootingInventoryUI.instance.curLootingPoint.inventory.gameObject.GetComponent<RckAI>();
if (ai != null) {
ai.TryEngageWithPlayer(); // Engage with player
} else {
Debug.Log("Failed: Could not find AI");
}
LootingInventoryUI.instance.CloseUI();
return;
} else {
// lets build some float levels to increase attributes slowly.
}
}
// 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) {
Debug.Log("Find out why this is called!");
return;
}
if (LootingInventoryUI.instance.isDrawing)
{
// if the amount is 1, add it one time
if (base.consumableItemInInventory.Amount <= 1)
{
Inventory.PlayerInventory.AddItem(base.consumableItemInInventory.item, base.consumableItemInInventory.metadata, 1, !takeAll);
// Remove the item from the current loot inventory
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.consumableItemInInventory, 1);
LootingInventoryUI.instance.SelectNextButton();
// Disable this object
pool.usedObjects.Remove(this);
pool.ConsumablesPool.usedObjects.Remove(this);
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else if (base.consumableItemInInventory.item.isCumulable && base.consumableItemInInventory.Amount > 1)
{
if (!takeAll)
{
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
LootingInventoryUI.instance.takeDepositItemsPanel.Init(consumableItemInInventory, this);
}
else
{
ConfirmButtonCumulableItem(base.consumableItemInInventory.Amount);
}
}
}
else // we're depositing
{
if (base.consumableItemInInventory.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.consumableItemInInventory.Amount <= 1)
{
// Remove the item from the current loot inventory
LootingInventoryUI.instance.curLootingPoint.inventory.AddItem(base.consumableItemInInventory.item, base.consumableItemInInventory.metadata, 1);
Inventory.PlayerInventory.RemoveItem(base.consumableItemInInventory, 1);
LootingInventoryUI.instance.SelectNextButton();
// Disable this object
pool.usedObjects.Remove(this);
pool.ConsumablesPool.usedObjects.Remove(this);
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else if (base.consumableItemInInventory.item.isCumulable && base.consumableItemInInventory.Amount > 1)
{
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
LootingInventoryUI.instance.takeDepositItemsPanel.Init(consumableItemInInventory, this);
}
}
}
public override void ConfirmButtonCumulableItem(int amount)
{
if (LootingInventoryUI.instance.isDrawing)
{
// Add in PlayerInventory
Inventory.PlayerInventory.AddItem(base.consumableItemInInventory.item, base.consumableItemInInventory.metadata, amount);
// Remove from Loot Inventory
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.consumableItemInInventory, amount);
if (consumableItemInInventory.Amount <= 0)
{
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
LootingInventoryUI.instance.SelectNextButton(true);
//If we've took all the items
pool.usedObjects.Remove(this);
pool.ConsumablesPool.usedObjects.Remove(this);
// Disable this object
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else
{
// Update the UI
Init();
}
}
else // we're depositing
{
// Remove from Loot Inventory
LootingInventoryUI.instance.curLootingPoint.inventory.AddItem(base.consumableItemInInventory.item, base.consumableItemInInventory.metadata, amount);
// Add in PlayerInventory
Inventory.PlayerInventory.RemoveItem(base.consumableItemInInventory, amount);
if (consumableItemInInventory.Amount <= 0)
{
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
LootingInventoryUI.instance.SelectNextButton(true);
//If we've took all the items
pool.usedObjects.Remove(this);
pool.ConsumablesPool.usedObjects.Remove(this);
// Disable this object
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else
{
// Update the UI
Init();
}
}
}
}
}