2023-03-28 13:16:30 -04:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using RPGCreationKit;
|
|
|
|
|
using RPGCreationKit.AI;
|
|
|
|
|
|
|
|
|
|
namespace RPGCreationKit
|
|
|
|
|
{
|
2023-05-11 01:27:44 -04:00
|
|
|
|
public class BookItemInLootingUI_DrawDeposit : BookItemInInventoryUI
|
|
|
|
|
{
|
|
|
|
|
public override void OnClick(bool takeAll = false)
|
|
|
|
|
{
|
|
|
|
|
if (LootingInventoryUI.instance.curIsPickPocket && LootingInventoryUI.instance.curLootingPoint != null)
|
|
|
|
|
{
|
|
|
|
|
// Player is attempting to pickpocket
|
|
|
|
|
|
|
|
|
|
Vector3 forward = Inventory.PlayerInventory.transform.TransformDirection(Vector3.forward);
|
|
|
|
|
Vector3 toOther = LootingInventoryUI.instance.curLootingPoint.transform.position - transform.position;
|
|
|
|
|
|
|
|
|
|
float A = (1f - ((float)bookItemInInventory.item.Value / 100f));
|
|
|
|
|
float B = (float)EntityAttributes.PlayerAttributes.attributes.Dexterity / 100f;
|
|
|
|
|
float C = (1f - ((float)bookItemInInventory.item.Weight / 100f));
|
|
|
|
|
float D = (((Vector3.Dot(forward, toOther)) + 360) / 720);
|
|
|
|
|
|
|
|
|
|
float ChanceForSuccess = ((A+B+C+D)/4);
|
|
|
|
|
if (base.bookItemInInventory.isEquipped)
|
|
|
|
|
ChanceForSuccess = (ChanceForSuccess/2);
|
|
|
|
|
|
|
|
|
|
float RandomChance = (Random.value);
|
|
|
|
|
if (ChanceForSuccess < RandomChance) {
|
|
|
|
|
RckAI ai = LootingInventoryUI.instance.curLootingPoint.inventory.gameObject.GetComponent<RckAI>();
|
|
|
|
|
ai.TryEngageWithPlayer(); // Engage with player - Lets get faction instead of every fucker in the area.
|
|
|
|
|
LootingInventoryUI.instance.CloseUI();
|
|
|
|
|
return;
|
|
|
|
|
} else { // Reward Player
|
|
|
|
|
EntityAttributes.PlayerAttributes.attributes.DexterityPoints += 1;
|
|
|
|
|
A = (float)EntityAttributes.PlayerAttributes.attributes.DexterityPoints;
|
|
|
|
|
B = (float)EntityAttributes.PlayerAttributes.attributes.Dexterity;
|
|
|
|
|
while (A >= (B*3)) {
|
|
|
|
|
EntityAttributes.PlayerAttributes.attributes.Dexterity += 1;
|
|
|
|
|
float E = (A-(B*3f));
|
|
|
|
|
EntityAttributes.PlayerAttributes.attributes.DexterityPoints = (int)D;
|
|
|
|
|
A = (float)EntityAttributes.PlayerAttributes.attributes.DexterityPoints;
|
|
|
|
|
B = (float)EntityAttributes.PlayerAttributes.attributes.Dexterity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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.bookItemInInventory.Amount <= 1)
|
|
|
|
|
{
|
|
|
|
|
Inventory.PlayerInventory.AddItem(base.bookItemInInventory.item, base.bookItemInInventory.metadata, 1, !takeAll);
|
|
|
|
|
|
|
|
|
|
// Remove the item from the current loot inventory
|
|
|
|
|
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.bookItemInInventory, 1);
|
|
|
|
|
|
|
|
|
|
LootingInventoryUI.instance.SelectNextButton();
|
|
|
|
|
|
|
|
|
|
// Disable this object
|
|
|
|
|
pool.usedObjects.Remove(this);
|
|
|
|
|
pool.BooksPool.usedObjects.Remove(this);
|
|
|
|
|
|
|
|
|
|
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
else if (base.bookItemInInventory.item.isCumulable && base.bookItemInInventory.Amount > 1)
|
|
|
|
|
{
|
|
|
|
|
if (!takeAll)
|
|
|
|
|
{
|
|
|
|
|
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
|
|
|
|
|
LootingInventoryUI.instance.takeDepositItemsPanel.Init(bookItemInInventory, this);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ConfirmButtonCumulableItem(base.bookItemInInventory.Amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // we're depositing
|
|
|
|
|
{
|
|
|
|
|
if (base.bookItemInInventory.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.bookItemInInventory.Amount <= 1)
|
|
|
|
|
{
|
|
|
|
|
// Remove the item from the current loot inventory
|
|
|
|
|
LootingInventoryUI.instance.curLootingPoint.inventory.AddItem(base.bookItemInInventory.item, base.bookItemInInventory.metadata, 1);
|
|
|
|
|
|
|
|
|
|
Inventory.PlayerInventory.RemoveItem(base.bookItemInInventory, 1);
|
|
|
|
|
|
|
|
|
|
LootingInventoryUI.instance.SelectNextButton();
|
|
|
|
|
|
|
|
|
|
// Disable this object
|
|
|
|
|
pool.usedObjects.Remove(this);
|
|
|
|
|
pool.BooksPool.usedObjects.Remove(this);
|
|
|
|
|
|
|
|
|
|
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
else if (base.bookItemInInventory.item.isCumulable && base.bookItemInInventory.Amount > 1)
|
|
|
|
|
{
|
|
|
|
|
LootingInventoryUI.instance.takeDepositItemsPanel.gameObject.SetActive(true);
|
|
|
|
|
LootingInventoryUI.instance.takeDepositItemsPanel.Init(bookItemInInventory, this);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConfirmButtonCumulableItem(int amount)
|
|
|
|
|
{
|
|
|
|
|
if (LootingInventoryUI.instance.isDrawing)
|
|
|
|
|
{
|
|
|
|
|
// Add in PlayerInventory
|
|
|
|
|
Inventory.PlayerInventory.AddItem(base.bookItemInInventory.item, base.bookItemInInventory.metadata, amount);
|
|
|
|
|
|
|
|
|
|
// Remove from Loot Inventory
|
|
|
|
|
LootingInventoryUI.instance.curLootingPoint.inventory.RemoveItem(base.bookItemInInventory, amount);
|
|
|
|
|
|
|
|
|
|
if (bookItemInInventory.Amount <= 0)
|
|
|
|
|
{
|
|
|
|
|
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
|
|
|
|
|
LootingInventoryUI.instance.SelectNextButton(true);
|
|
|
|
|
|
|
|
|
|
//If we've took all the items
|
|
|
|
|
pool.usedObjects.Remove(this);
|
|
|
|
|
pool.BooksPool.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.bookItemInInventory.item, base.bookItemInInventory.metadata, amount);
|
|
|
|
|
|
|
|
|
|
// Add in PlayerInventory
|
|
|
|
|
Inventory.PlayerInventory.RemoveItem(base.bookItemInInventory, amount);
|
|
|
|
|
|
|
|
|
|
if (bookItemInInventory.Amount <= 0)
|
|
|
|
|
{
|
|
|
|
|
LootingInventoryUI.instance.takeDepositItemsPanel.SetPreviousSelected();
|
|
|
|
|
LootingInventoryUI.instance.SelectNextButton(true);
|
|
|
|
|
|
|
|
|
|
//If we've took all the items
|
|
|
|
|
pool.usedObjects.Remove(this);
|
|
|
|
|
pool.BooksPool.usedObjects.Remove(this);
|
|
|
|
|
|
|
|
|
|
// Disable this object
|
|
|
|
|
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Update the UI
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-28 13:16:30 -04:00
|
|
|
|
}
|