Firstborn/Assets/RPG Creation Kit/Scripts/Looting System/Items In Looting UI/WeaponItemInLootingUI_DrawD...
Schaken-Mods 959e80cf72 assets upload
assets upload description.
2023-03-28 12:16:30 -05:00

185 lines
8.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using RPGCreationKit;
using RPGCreationKit.AI;
namespace RPGCreationKit
{
public class WeaponItemInLootingUI_DrawDeposit : WeaponItemInInventoryUI
{
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 = weaponItemInInventory.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.weaponItemInInventory.Amount <= 1)
{
Inventory.PlayerInventory.AddItem(base.weaponItemInInventory.item, base.weaponItemInInventory.metadata, 1, !takeAll);
if (base.weaponItemInInventory.isEquipped)
LootingInventoryUI.instance.curLootingPoint.equipment.Unequip(base.weaponItemInInventory);
// Remove the item from the current loot inventory
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.weaponItemInInventory, 1);
LootingInventoryUI.instance.SelectNextButton();
// Disable this object
pool.usedObjects.Remove(this);
pool.WeaponsPool.usedObjects.Remove(this);
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else if (base.weaponItemInInventory.item.isCumulable && base.weaponItemInInventory.Amount > 1)
{
if (!takeAll)
{
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
LootingInventoryUI.instance.takeDepositItemsPanel.Init(weaponItemInInventory, this);
}
else
{
ConfirmButtonCumulableItem(base.weaponItemInInventory.Amount);
}
}
}
else // we're depositing
{
if (base.weaponItemInInventory.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.weaponItemInInventory.Amount <= 1)
{
// Remove the item from the current loot inventory
LootingInventoryUI.instance.curLootingPoint.inventory.AddItem(base.weaponItemInInventory.item, base.weaponItemInInventory.metadata, 1);
if (base.weaponItemInInventory.isEquipped)
{
Equipment.PlayerEquipment.Unequip(base.weaponItemInInventory);
PlayerCombat.instance.OnEquipmentChanges();
PlayerInInventory.instance.OnEquipmentChangesHands();
}
Inventory.PlayerInventory.RemoveItem(base.weaponItemInInventory, 1);
LootingInventoryUI.instance.SelectNextButton();
// Disable this object
pool.usedObjects.Remove(this);
pool.WeaponsPool.usedObjects.Remove(this);
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else if (base.weaponItemInInventory.item.isCumulable && base.weaponItemInInventory.Amount > 1)
{
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
LootingInventoryUI.instance.takeDepositItemsPanel.Init(weaponItemInInventory, this);
}
}
}
public override void ConfirmButtonCumulableItem(int amount)
{
if (LootingInventoryUI.instance.isDrawing)
{
// Add in PlayerInventory
Inventory.PlayerInventory.AddItem(base.weaponItemInInventory.item, base.weaponItemInInventory.metadata, amount);
if (base.weaponItemInInventory.Amount <= amount)
if (base.weaponItemInInventory.isEquipped)
LootingInventoryUI.instance.curLootingPoint.equipment.Unequip(base.weaponItemInInventory);
// Remove from Loot Inventory
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.weaponItemInInventory, amount);
if (weaponItemInInventory.Amount <= 0)
{
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
LootingInventoryUI.instance.SelectNextButton(true);
//If we've took all the items
pool.usedObjects.Remove(this);
pool.WeaponsPool.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.weaponItemInInventory.item, base.weaponItemInInventory.metadata, amount);
if(base.weaponItemInInventory.Amount <= amount)
if (weaponItemInInventory.isEquipped)
{
Equipment.PlayerEquipment.Unequip(weaponItemInInventory);
PlayerCombat.instance.OnEquipmentChanges();
PlayerInInventory.instance.OnEquipmentChangesHands();
}
// Add in PlayerInventory
Inventory.PlayerInventory.RemoveItem(base.weaponItemInInventory, amount);
if (weaponItemInInventory.Amount <= 0)
{
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
LootingInventoryUI.instance.SelectNextButton(true);
//If we've took all the items
pool.usedObjects.Remove(this);
pool.WeaponsPool.usedObjects.Remove(this);
// Disable this object
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
gameObject.SetActive(false);
}
else
{
// Update the UI
Init();
}
}
}
}
}