projectEli/Assets/Inventory System/ICWM Assets/Inventory/Scripts/DragAndDrop/Slot.cs

1163 lines
64 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//********************************************************//
// //
// Copyright © All rights reserved. MyNameIsVoo. 2020. //
// //
// COPYING FORBIDEN //
// //
//********************************************************//
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using ItemsClassList;
using ICWM.Loot;
using ICWM.Enemy;
using ICWM.InventoryHotbar;
using ICWM.IconSystem;
using ICWM.HelperSystem;
using ICWM.ItemSystem;
using ICWM.RenderSystem;
using ICWM.SaveSystem;
using ICWM.StoreSystem;
using ICWM.WeaponSystem;
/// <summary>
/// The script attaches to GameObjects in those places where it is necessary to create the ability to attach an icon
/// </summary>
namespace ICWM
{
namespace DragAndDrop
{
public class Slot : MonoBehaviour, IDropHandler
{
#region Attributes
[Header("HOTBAR")]
[SerializeField] private int IDHotbarSlot = -1;
[Header("ATTRIBUTES")]
[SerializeField] private bool IsBackpackSlot = false;
[Header("ITEM TAG")]
// I made it here specially, because It will be necessary to check the basis of the icon (that is, the basis is the foundation, for example, weapons - WEAPON tag)
public ItemList.TagItems TagItem = new ItemList.TagItems();
public ItemList.TagItems[] AdditionalTagsItem; // Additional tags ()
[Header("ITEM SIZE")]
[SerializeField] private bool IsAllItemsSize = false;
public ItemList.SizeIconInventory[] TagSize = new ItemList.SizeIconInventory[0];
private bool isPlayerSlot, isStashInventory, isTacticalRig, isInventoryToBackpack;
#endregion
private void Start()
{
if (IsAllItemsSize)
{
TagSize = new ItemList.SizeIconInventory[ItemList.SizeIconInventory.NONE.GetHashCode()]; // Without NONE
for (int i = 0; i < TagSize.Length; i++)
TagSize[i] = InventoryBase.instance.allItemsSize[i];
}
}
#region PUBLIC
#region On Drop
public void OnDrop(PointerEventData eventData)
{
if (!DragHandler.itemIcon)
{
Debug.Log("ERROR - OnDrop->(DragHandler.itemIcon == null)");
return;
}
// If Store Mode
if (DragHandler.itemIcon.GetComponentInParent<MouseEnterStoreInventory>() && DragHandler.itemIcon.GetComponentInParent<MouseEnterStoreInventory>().isActive)
return;
if (InventoryBase.instance.m_Hotbar.isActiveHotbar && PointerEnterInventoryHotbar.instance && PointerEnterInventoryHotbar.instance.isActive) // Если внутри области
{
InventoryBase.instance.m_Hotbar.UpdateHotbarOnDragAndDropItems(DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL, IDHotbarSlot, 0);
return;
}
if (CheckingWasItemRotatedAndPlacedToSlotFromSlot())
return;
// If there is no one, we attach our icon to it and reset the settings
if (!GetItem)
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
// If the tag, from the one we chose is equal to the tag to which we drop it
if (TagItem == itemCL.tagItem || CheckAdditionSlotItemTags(itemCL))
{
if (DragHandler.itemIcon.GetComponentInParent<Mask>())
DragHandler.itemIcon.GetComponentInParent<Mask>().enabled = true;
bool isDropOnEnemySlots = false;
if ((MouseEnterPlayerInventory.instance && MouseEnterPlayerInventory.instance.isActive) || (MouseEnterBackpack.instance && MouseEnterBackpack.instance.IsActive)) // Куда
{
if (DragHandler.isEnemyBackpack || DragHandler.isEnemy) // От куда
{
ChangeRootItem(itemCL);
}
}
else if ((MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) || (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive)) // Куда
{
isDropOnEnemySlots = true;
if (TagItem != ItemList.TagItems.ITEMS)
{
// Я думаю можно убрать if
if (DragHandler.isPlayerBackpack || DragHandler.isPlayer || DragHandler.isEnemyBackpack) // От куда
ChangeRootItem(itemCL, 1);
}
}
// Slots
if (TagItem != ItemList.TagItems.ITEMS || !IsBackpackSlot)
{
ResetIconLocation();
if(PlayerEnemySystem.instance)
PlayerEnemySystem.instance.UpdateEnemyIDWeaponSlots();
}
if (InventoryBase.instance.m_Hotbar.isActiveHotbar && !isDropOnEnemySlots)
InventoryBase.instance.m_Hotbar.UpdateHotbarOnDragAndDropItems(itemCL, IDHotbarSlot, 1);
}
else
{
return;
}
}
}
#endregion
#endregion
#region PRIVATE
#region Set, Get, etc
private GameObject GetItem
{
get
{
if (DragHandler.itemIcon) // If the tags are equal, then you can swap them
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
if (CheckAdditionSlotItemTags(itemCL) || TagItem == itemCL.tagItem)// Сначала проверяем по тэгу
{
if (CheckSelfDropping())
return null;
// If we drop item on inactive backpack/tactical rig/ pockets
if ((TagItem == ItemList.TagItems.BODYBACKPACK || TagItem == ItemList.TagItems.BODYTACTICALRIG || TagItem == ItemList.TagItems.BODYPOCKETS) && transform.GetComponentInChildren<ButtonOptions>() && !transform.GetComponentInChildren<ButtonOptions>().CL.isPutOn)
{
if (StoreBase.instance && !StoreBase.instance.isActive)
{
if (!AddItemToBackpack())
{
DragHandler.canNotBeMoved = true;
return transform.gameObject;
}
else
return null;
}
else
{
DragHandler.canNotBeMoved = true;
return transform.gameObject;
}
}
int isReturn = DropItemOnSlots(itemCL);
if (isReturn == 1)
return transform.GetChild(0).gameObject;
else if (isReturn == 2)
return null;
//
// При переносе на другой предмет
//
DropItemToAnotherItem();
return transform.gameObject; // Do nothing
}
else if (IsWeDroppedItemOnWeapon(itemCL)) // ITEMS on WEAPON
{
if (DropAttachmentOnWeapon(itemCL))
return transform.gameObject;
}
else // Onto backpack
{
if (StoreBase.instance && !StoreBase.instance.isActive)
{
if (BackpackSystem.instance.RE4_IsActive() || BackpackSystem.instance.RE4O_IsActive())
{
if (!AddItemToRE4Backpack())
{
DragHandler.canNotBeMoved = true;
return transform.gameObject;
}
}
else
{
if (!AddItemToBackpack())
{
DragHandler.canNotBeMoved = true;
return transform.gameObject;
}
}
}
}
}
return null;
}
}
private void SetSlotPosition(ItemList.SizeIconInventory tagSize)
{
if (isStashInventory) // If in inventory
{
if (DragHandler.itemIcon.transform.parent == transform.parent) // If from inventory to inventory
transform.localPosition = DragHandler.itemIcon.transform.localPosition;
else // other cases
transform.localPosition = Vector3.zero;
}
else if (isPlayerSlot)
{
transform.localPosition = DragHandler.itemIcon.transform.localPosition;
}
else if (isTacticalRig) // It was a backpack slot
{
if (isInventoryToBackpack) // Dragging out of inventory
{
transform.localPosition = DragHandler.itemIcon.transform.localPosition;
}
else // From a backpack
{
if (tagSize == ItemList.SizeIconInventory.Size1x1)
transform.localPosition = Vector3.zero;
else if (tagSize == ItemList.SizeIconInventory.Size1x2)
transform.localPosition = new Vector3(0f, BackpackBase.CELL_SIZE, 0f);
}
}
}
#endregion
#region Helpers
private bool AddItemToBackpack()
{
if (TagItem == ItemList.TagItems.BODYBACKPACK || TagItem == ItemList.TagItems.BODYTACTICALRIG || TagItem == ItemList.TagItems.BODYPOCKETS)
{
if (transform.childCount == 0)
return false;
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
if (transform.GetComponentInChildren<ButtonOptions>().CL.isPutOn || transform.GetComponentInChildren<ButtonOptions>().CL.isOpen) // Если переносим на активный рюкзак или если рюкзак открыт и мы переносим предмет на
{
//
// Maybe need to do something but for now we do nothing
//
return false;
}
else
{
if (BackpackSystem.instance.SaveItemToBackpack(transform.GetComponentInChildren<ButtonOptions>().CL, itemCL, DragHandler.itemIcon, DragHandler.isEnemyBackpack)) // Try to add a new item to the backpack (if false we did not find a free place)
{
DragHandler.itemIcon.GetComponent<DragHandler>().deleteVSP = true; // We need to destroy the base icon
DragHandler.isDeleteIcon = true;
if ((MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) || (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive) || DragHandler.isEnemyBackpack || DragHandler.isEnemy) // Если мы переносим в область енеми
InventoryBase.instance.inventoryEnemy.DestroyItem(itemCL);
if (DragHandler.itemDragged == DragHandler.BackpackItemDragged.STASH && LootBase.instance.isLootWindowMode)
{
if (itemCL.IsRenderItem())
itemCL.SetItemModdingParameters(false, InventoryBase.instance.RootSpawnWeaponModding.transform);
if (itemCL.destroyItemDrop)
Destroy(itemCL.destroyItemDrop);
}
}
else
{
return false;
}
}
}
return true;
}
private bool AddItemToRE4Backpack()
{
if (TagItem == ItemList.TagItems.BODYBACKPACK || TagItem == ItemList.TagItems.BODYTACTICALRIG || TagItem == ItemList.TagItems.BODYPOCKETS)
{
if (transform.childCount == 0)
return false;
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
if (transform.GetComponentInChildren<ButtonOptions>().CL.isPutOn) // Если переносим на активный рюкзак или если рюкзак открыт и мы переносим предмет на
{
//
// Maybe need to do something but for now we do nothing
//
return false;
}
else
{
if (BackpackSystem.instance.SaveItemToBackpack(transform.GetComponentInChildren<ButtonOptions>().CL, itemCL, DragHandler.itemIcon, DragHandler.isEnemyBackpack)) // Try to add a new item to the backpack (if false we did not find a free place)
{
DragHandler.itemIcon.GetComponent<DragHandler>().deleteVSP = true; // We need to destroy the base icon
DragHandler.isDeleteIcon = true;
if ((MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) || (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive) || DragHandler.isEnemyBackpack || DragHandler.isEnemy) // Если мы переносим в область енеми
InventoryBase.instance.inventoryEnemy.DestroyItem(itemCL);
}
else
{
return false;
}
}
}
return true;
}
// Меняем директорию
private void ChangeRootItem(ItemList itemCL, int mode = 0)
{
if (mode == 0) // Player
{
if (itemCL.IsRenderItem())
itemCL.SetItemModdingParameters(false, InventoryBase.instance.RootSpawnWeaponModding.transform);
if (itemCL.destroyItemDrop)
{
Destroy(itemCL.destroyItemDrop);
itemCL.destroyItemDrop = null;
}
}
else // Enemy
{
if (DragHandler.isEnemy)
return;
if (itemCL.destroyItemDrop)
Destroy(itemCL.destroyItemDrop);
itemCL.destroyItemDrop = Instantiate(InventoryBase.instance.ItemsDropPrefab, InventoryBase.instance.inventoryEnemy.m_SpawnEnemyDropItems);
itemCL.destroyItemDrop.name = itemCL.id.ToString();
itemCL.destroyItemDrop.transform.localPosition = Vector3.zero;
itemCL.SetItemModdingParameters(false, itemCL.destroyItemDrop.transform);
Helper.SetParameters(itemCL.destroyItemDrop, itemCL);
// Если в рюкзаке что то есть нужно создать префабы
if (itemCL.insertCL.Length > 0)
{
if (itemCL.IsBackpackItemSlot())
{
for (int i = 0; i < itemCL.insertCL.Length; i++)
{
if (itemCL.insertCL[i] == null)
break;
itemCL.insertCL[i].destroyItemDrop = Instantiate(InventoryBase.instance.ItemsDropPrefab);
itemCL.insertCL[i].destroyItemDrop.name = itemCL.insertCL[i].id.ToString();
if (itemCL.tagItem == ItemList.TagItems.BODYBACKPACK)
itemCL.insertCL[i].destroyItemDrop.transform.SetParent(InventoryBase.instance.inventoryEnemy.m_SpawnEnemyBackpackItems);
else
itemCL.insertCL[i].destroyItemDrop.transform.SetParent(InventoryBase.instance.inventoryEnemy.m_SpawnEnemyTacticalRigItems);
itemCL.insertCL[i].destroyItemDrop.transform.localPosition = Vector3.zero;
Helper.SetParameters(itemCL.insertCL[i].destroyItemDrop, itemCL.insertCL[i]);
itemCL.insertCL[i].SetItemModdingParameters(false, itemCL.insertCL[i].destroyItemDrop.transform);
// Нужно найти иконки и ее позицию
if (itemCL.tagItem == ItemList.TagItems.BODYBACKPACK)
{
Component[] p = BackpackSystem.instance.rootBackpack.GetComponentsInChildren(typeof(ButtonOptions), true);
if (p != null)
{
foreach (ButtonOptions n in p)
{
if (n.CL.id == itemCL.insertCL[i].id)
itemCL.insertCL[i].destroyItemDrop.GetComponent<ItemsDrop>().CL.startPositionInInventory = n.transform.parent.gameObject.transform.localPosition; // From DragAndDrop - Icon position in the backpack
}
}
}
}
}
}
}
}
private void SaveWeaponParameters(ItemList itemCL)
{
//
// If we have a magazine
//
Component[] p = itemCL.itemModding.GetComponentsInChildren(typeof(AttachIdentity), true);
if (p != null)
{
// turn flag
if (itemCL.isMagazineAttached == true)
itemCL.isMagazineAttached = false;
// Find the magazine (if it is)
foreach (AttachIdentity n in p)
{
// find
if (n.CL.tagAttach == ItemList.TagAttchments.ATTACH_MAGAZINE)
{
itemCL.isMagazineAttached = true;
itemCL.insertCL[0] = n.CL; // Remember the data magazine (to have access to them)
break;
}
}
}
//
// Before rendering a picture, save our model
//
string filename = itemCL.id.ToString();
SaveWeaponModdingButton.instance.SaveButtonParameters(filename);
itemCL.itemModding.GetComponentInChildren<SaveWeaponModding>().SaveParameters(filename, true);
WeaponRender.instance.SetWeaponParameters(itemCL.itemModding, itemCL);
if (!InventoryBase.instance.isActiveScreenShot)
StartCoroutine(InventoryBase.instance.CreateScreenShot());
if (BackpackSystem.instance.RE4_IsActive())
{
BackpackSystem.instance.SetActivePlayerInspect(true); // close
BackpackSystem.instance.SetActivePlayerInspect(false); // Activate
}
//
// After quitting the modding mode, we need to update the model of the weapon in the hands
//
if (InventoryBase.instance.selectWeapon.indexActiveWeapon != -1) // (-1) - Indicates that we do not have anything in our hands
{
if (InventoryBase.instance.selectWeapon.weapons[InventoryBase.instance.selectWeapon.indexActiveWeapon])
{
InventoryBase.instance.selectWeapon.weapons[InventoryBase.instance.selectWeapon.indexActiveWeapon].GetComponentInChildren<WeaponRootSetActive>().loadStart = true;
InventoryBase.instance.selectWeapon.UpdateStatistics(); // update weapon statistics
}
}
}
#endregion
#region Drop Item
private void DropItemToAnotherItem()
{
if (transform.GetComponentInChildren<ButtonOptions>())
{
if (CanPutBulletsInMagazine())
PutBulletsInMagazine();
else if (CanCombineBullets())
CombineBullets();
else if (CanPutItemsInItem())
PutItemsInItem();
else if (CanCombineItems())
CombineItems();
}
}
private int DropItemOnSlots(ItemList itemCL)
{
int count = 0;
foreach (ItemList.SizeIconInventory ts in TagSize)
{
if (transform.GetComponentInChildren<ButtonOptions>()) // If this is a bullet - we can not exchange
if (transform.GetComponentInChildren<ButtonOptions>().CL.isBullet == true || itemCL.isBullet == true || itemCL.isStack == true)
break;
// then by size
if (ts == itemCL.tagSize)
{
Component[] p = GetComponentsInChildren(typeof(DragHandler), true);
// If the object (on which the Slot component is attached) is someone inside (icon), swapping
if (p.Length > 0)
{
// Swapping places
if (DragHandler.itemIcon)
{
// It is impossible to change places with a backpack or in a backpack
if (DragHandler.itemDragged == DragHandler.BackpackItemDragged.BACKPACK || transform.GetComponent<DragHandler>().isBackpackSlot)
{
DragHandler.canNotBeMoved = true;
return 1;
}
// We can not swap backpacks, tactical rig, etc.
// Remove the backpack and put in its place another
if (transform.GetComponentInChildren<ButtonOptions>().CL.IsBackpackItemSlot() || transform.GetComponentInChildren<ButtonOptions>().CL.IsRenderItem())
return 1;
Transform slotParent = transform.parent; // remember the parent of the one to whom we drop the icon
Vector3 newItemPos = Vector3.zero;
if (slotParent.GetComponent<PlayerInventorySlot>() && slotParent.GetComponent<PlayerInventorySlot>().IsPlayerSlot) // If we transfer to the player's slot
{
// We say that we transfer from inventory to slots
DragHandler.isExchangePlayerSlot = true;
isPlayerSlot = true;
}
else if (slotParent.GetComponent<StashInventorySlot>() && slotParent.GetComponent<StashInventorySlot>().IsStashInventory) // if we transfer to Stash
{
DragHandler.isExchangeInventory = true; // we say that we change places in the inventory
isStashInventory = true;
newItemPos = transform.localPosition;
if (DragHandler.itemDragged == DragHandler.BackpackItemDragged.TACTICALRIG_OR_POCKETS) // With a backpack
{
transform.GetComponentInChildren<ButtonOptions>().CL.idSlotBackpack = itemCL.idSlotBackpack;
itemCL.idSlotBackpack = -1;
if (DragHandler.isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
else if (DragHandler.isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
}
}
else if (slotParent.GetComponent<TacticRigSlot>() && slotParent.GetComponent<TacticRigSlot>().IsTacticalRigSlot) // if we transfer to tactical rig // This is a backpack slot?
{
if (DragHandler.itemDragged == DragHandler.BackpackItemDragged.STASH) // If originally taken from the inventory and placed in a backpack
{
isInventoryToBackpack = true;
newItemPos = transform.localPosition;
// Toggle the parameter we need when swapping (this is the cell ID)
itemCL.idSlotBackpack = transform.GetComponentInChildren<ButtonOptions>().CL.idSlotBackpack;
transform.GetComponentInChildren<ButtonOptions>().CL.idSlotBackpack = -1; // We say that he is no longer in a backpack
// We need to close the place under the icon, because we opened it before dragging it
StashSystem.instance.CloseIndicesBackpackByIconPosition(itemCL.indexPos60x60, DragHandler.itemIcon.transform.localPosition);
transform.GetComponentInChildren<ButtonOptions>().CL.startPositionInInventory = DragHandler.itemIcon.transform.localPosition;
}
else if (DragHandler.itemDragged == DragHandler.BackpackItemDragged.TACTICALRIG_OR_POCKETS) // If initially we took from a backpack
{
if (ts == ItemList.SizeIconInventory.Size1x2) // Because attach to the second cell
newItemPos = new Vector3(0f, BackpackBase.CELL_SIZE, 0f);
int id = itemCL.idSlotBackpack; // Exchange position indices
itemCL.idSlotBackpack = transform.GetComponentInChildren<ButtonOptions>().CL.idSlotBackpack;
transform.GetComponentInChildren<ButtonOptions>().CL.idSlotBackpack = id;
if (DragHandler.isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL); // We need to close the old position (because we opened it when dragging)
else if (DragHandler.isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
}
DragHandler.isExchangeInventory = true; // we say that we change places
isTacticalRig = true; // This is a backpack slot
}
//
// Where drop
//
transform.SetParent(DragHandler.itemIcon.transform.parent);
SetSlotPosition(ts);
//
// From where
//
DragHandler.itemIcon.transform.SetParent(slotParent);
DragHandler.itemIcon.transform.localPosition = newItemPos;
isStashInventory = false;
isPlayerSlot = false;
isTacticalRig = false;
}
return 1; // We need to return something (so as not to go below in the condition)
}
else // if no one is there then turn off the background and return null - a sign that you can move our icon there
{
// When they drop the icon to a new place, turn off the background at this place
if (TagItem != ItemList.TagItems.ITEMS)
{
if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive)
{
if (TagItem == ItemList.TagItems.BODYHEADSET)
PlayerEnemySystem.instance.isActiveHeadset = true;
else if (TagItem == ItemList.TagItems.BODYGOGGLES)
PlayerEnemySystem.instance.isActiveGoggles = true;
else if (TagItem == ItemList.TagItems.BODYHELMET)
PlayerEnemySystem.instance.isActiveHelmet = true;
else if (TagItem == ItemList.TagItems.BODYARMOR)
PlayerEnemySystem.instance.isActiveBodyArmor = true;
else if (TagItem == ItemList.TagItems.PISTOL)
PlayerEnemySystem.instance.isActiveHolster = true;
else if (TagItem == ItemList.TagItems.KNIFE)
PlayerEnemySystem.instance.isActiveScarbbard = true;
if (!BackpackSystem.instance.RE4O_IsActive())
{
foreach (GameObject gg in PlayerEnemySystem.instance.enemySlots)
{
if (gg.name == transform.name)
{
gg.GetComponent<Image>().enabled = false;
break;
}
}
}
}
else
{
if (TagItem == ItemList.TagItems.BODYHEADSET)
PlayerSystem.instance.isActiveHeadset = true;
else if (TagItem == ItemList.TagItems.BODYGOGGLES)
PlayerSystem.instance.isActiveGoggles = true;
else if (TagItem == ItemList.TagItems.BODYHELMET)
PlayerSystem.instance.isActiveHelmet = true;
else if (TagItem == ItemList.TagItems.BODYARMOR)
PlayerSystem.instance.isActiveBodyArmor = true;
if (!BackpackSystem.instance.RE4O_IsActive())
{
foreach (GameObject gg in PlayerSystem.instance.weaponSlots)
{
if (gg.name == transform.name)
{
gg.GetComponent<Image>().enabled = false;
break;
}
}
}
}
}
else
{
if (IsBackpackSlot)
{
if (DragHandler.isPlayer)
{
// From player's slot
if (itemCL.tagItem == ItemList.TagItems.PISTOL)
{
if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive)
{
PlayerEnemySystem.instance.isActiveHolster = false;
PlayerEnemySystem.instance.enemySlots[PlayerEnemySystem.EnemySlots.HOLSTER.GetHashCode()].GetComponent<Image>().enabled = true;
}
}
else if (itemCL.tagItem == ItemList.TagItems.KNIFE)
{
if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive)
{
PlayerEnemySystem.instance.isActiveScarbbard = false;
PlayerEnemySystem.instance.enemySlots[PlayerEnemySystem.EnemySlots.SCABBARD.GetHashCode()].GetComponent<Image>().enabled = true;
}
}
}
itemCL.newIDSlotBackpack = GetComponent<TacticRigSlot>().ID + 1;
}
}
return 2;
}
}
//
// Если не нашли подходящий размер в списке то не перемещаем
// Например - мы пытаемся перенести большой предмет в слоты разгрузки
//
if (count == TagSize.Length)
{
DragHandler.canNotBeMoved = true;
}
count++;
}
return -1;
}
private bool IsWeDroppedItemOnWeapon(ItemList itemCL)
{
if ((TagItem == ItemList.TagItems.WEAPON || TagItem == ItemList.TagItems.PISTOL || TagItem == ItemList.TagItems.KNIFE) && itemCL.tagItem == ItemList.TagItems.ITEMS && StoreBase.instance && !StoreBase.instance.isActive)
return true;
return false;
}
private bool DropAttachmentOnWeapon(ItemList itemCL)
{
if (!InventoryBase.instance.ActivateDynamicAttachingMods)
return true;
if (transform.childCount > 0)
{
// We need to find a tag that we can to attach the item
Component[] h = transform.GetComponentInChildren<ButtonOptions>().CL.itemModding.transform.GetComponentsInChildren(typeof(Helpers), true); // Collect all helpers
if (h != null)
{
foreach (Helpers g in h)
{
if (g.TagAttach == DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.tagAttach)
{
if (!CanWeAttachItemToWeapon(itemCL))
return true;
if (g.GetComponentInChildren<AttachIdentity>()) // If we have one on the weapon we need to replace it for the new one
{
StartCoroutine(InventoryBase.instance.CreateItemAttachmentsInInventory(g.GetComponentInChildren<AttachIdentity>().CL, false));
g.GetComponentInChildren<AttachIdentity>().gameObject.transform.SetParent(InventoryBase.instance.RootSpawnItemsAttach.transform);
}
//
//
//
itemCL.SetItemModdingParameters(true, g.transform);
g.AddParametersToHelper(itemCL, g.GetComponentInChildren<Helpers>().GetOriginalAttachmentID());
DragHandler.itemIcon.GetComponent<DragHandler>().deleteVSP = true; // We need to destroy the base icon
DragHandler.itemIcon.GetComponent<DragHandler>().isAttached = true;
//if (InventoryBase.instance.hideStash || BackpackSystem.instance.RE4_IsActive() || BackpackSystem.instance.RE4O_IsActive())
DragHandler.isDeleteIcon = true;
//
// Save parameters
//
transform.GetComponentInChildren<ButtonOptions>().isActiveUpdateImg = true; // We need to update the weapon icon
SaveWeaponParameters(transform.GetComponentInChildren<ButtonOptions>().CL);
break;
}
}
}
}
return false;
}
private bool CanWeAttachItemToWeapon(ItemList itemCL)
{
bool canAttachToTool = false;
for (int i = 0; i < DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.id_Attach.Length; i++)
{
if (DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.id_Attach[i] == transform.GetComponentInChildren<ButtonOptions>().CL.id_Weapon) // Если хоть один ID совпадает
{
canAttachToTool = true;
break;
}
}
return canAttachToTool;
}
#endregion
#region Put item on item
private bool CanPutBulletsInMagazine()
{
if (transform.GetComponentInChildren<ButtonOptions>().CL.isMagazine == true && DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.isBullet == true)
return true;
return false;
}
private void PutBulletsInMagazine()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
if (transform.GetComponentInChildren<ButtonOptions>().CL.typeOfBullet == itemCL.typeOfBullet)
{
int amount = transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet + itemCL.amountBullet;
if (amount <= transform.GetComponentInChildren<ButtonOptions>().CL.clipSize)
{
DragHandler.isDeleteIcon = true;
transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet = amount;
if (itemCL.itemModding)
Destroy(itemCL.itemModding); // we need to destroy object
}
else
{
itemCL.amountBullet = itemCL.amountBullet - (transform.GetComponentInChildren<ButtonOptions>().CL.clipSize - transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet);
transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet = transform.GetComponentInChildren<ButtonOptions>().CL.clipSize;
DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().SetTextParameters(itemCL);
}
transform.GetComponentInChildren<ButtonOptions>().SetTextParameters(transform.GetComponentInChildren<ButtonOptions>().CL);
}
}
private bool CanPutItemsInItem()
{
if (transform.GetComponentInChildren<ButtonOptions>().CL.isPurse == true && DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.isMoney == true && transform.GetComponentInChildren<ButtonOptions>().CL.moneyType == DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.moneyType)
return true;
return false;
}
private void PutItemsInItem()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
int amount = transform.GetComponentInChildren<ButtonOptions>().CL.amountStack + itemCL.amountStack;
if (amount <= transform.GetComponentInChildren<ButtonOptions>().CL.maxAmountStack)
{
DragHandler.isDeleteIcon = true;
transform.GetComponentInChildren<ButtonOptions>().CL.amountStack = amount;
Destroy(itemCL.itemModding); // we need to destroy object
if (itemCL.destroyItemDrop)
Destroy(itemCL.destroyItemDrop);
}
else
{
itemCL.amountStack = itemCL.amountStack - (transform.GetComponentInChildren<ButtonOptions>().CL.maxAmountStack - transform.GetComponentInChildren<ButtonOptions>().CL.amountStack);
transform.GetComponentInChildren<ButtonOptions>().CL.amountStack = transform.GetComponentInChildren<ButtonOptions>().CL.maxAmountStack;
DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().SetTextParameters(itemCL);
}
transform.GetComponentInChildren<ButtonOptions>().SetTextParameters(transform.GetComponentInChildren<ButtonOptions>().CL);
}
#endregion
#region Combine
private bool CanCombineBullets()
{
if (transform.GetComponentInChildren<ButtonOptions>().CL.isBullet == true && DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.isBullet == true)
return true;
return false;
}
private void CombineBullets()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
if (transform.GetComponentInChildren<ButtonOptions>().CL.typeOfBullet == itemCL.typeOfBullet)
{
int amount = transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet + itemCL.amountBullet;
if (amount <= InventoryBase.instance.MaxAmountStackBullet)
{
DragHandler.isDeleteIcon = true;
transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet = amount;
if (itemCL.itemModding)
Destroy(itemCL.itemModding);
}
else
{
itemCL.amountBullet = itemCL.amountBullet - (InventoryBase.instance.MaxAmountStackBullet - transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet);
transform.GetComponentInChildren<ButtonOptions>().CL.amountBullet = InventoryBase.instance.MaxAmountStackBullet;
DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().SetTextParameters(itemCL);
}
transform.GetComponentInChildren<ButtonOptions>().SetTextParameters(transform.GetComponentInChildren<ButtonOptions>().CL);
}
}
private bool CanCombineItems()
{
if (transform.GetComponentInChildren<ButtonOptions>().CL.isStack == true && DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.isStack == true && transform.GetComponentInChildren<ButtonOptions>().CL.stackID == DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.stackID)
return true;
return false;
}
private void CombineItems()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
// Total amount of items that we have
int totalAmountOfItems = transform.GetComponentInChildren<ButtonOptions>().CL.amountStack + itemCL.amountStack;
if (totalAmountOfItems <= itemCL.maxAmountStack)
{
if (!CombineTwoItemsByDestroyOne(totalAmountOfItems))
{
if (totalAmountOfItems != itemCL.maxAmountStack)
transform.GetComponentInChildren<ButtonOptions>().CL.amountStack = totalAmountOfItems;
Destroy(itemCL.itemModding);
}
}
else // Создаем новую иконку и оставляет одну с остатком
{
if (!CombineTwoItemsBySaveOne(totalAmountOfItems))
{
//itemCL.amountStack = itemCL.amountStack - (itemCL.maxAmountStack - transform.GetComponentInChildren<ButtonOptions>().CL.amountStack);
//transform.GetComponentInChildren<ButtonOptions>().CL.amountStack = itemCL.maxAmountStack;
}
DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().SetTextParameters(itemCL);
}
transform.GetComponentInChildren<ButtonOptions>().SetTextParameters(transform.GetComponentInChildren<ButtonOptions>().CL);
}
private bool CombineTwoItemsByDestroyOne(int amountItems)
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
DragHandler.isDeleteIcon = true;
if (amountItems == itemCL.maxAmountStack && transform.GetComponentInChildren<ButtonOptions>().CL.isCombine == true && itemCL.isCombine == true)
{
// Create a new prefab (then we need to delete it)
GameObject vspCombine = Instantiate(transform.GetComponentInChildren<ButtonOptions>().CL.combineResultPrefab, InventoryBase.instance.RootItemsSpawnInWorld.transform);
vspCombine.GetComponent<ItemsDrop>().CL.destroyItemDrop = vspCombine;
vspCombine.GetComponent<ItemsDrop>().CL = Helper.SetParameters(vspCombine.GetComponent<ItemsDrop>().CL, vspCombine, false);
bool isEnemyBackpack = false; // We will work with Enemy backpack
bool isCreatedInBackpackWindow = false;
int indexFreePlace = -1;
// Free space under item
if ((MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) || (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive)) // Enemy inv
{
if (transform.GetComponent<DragHandler>().isBackpackSlot) // Проверяем предмет (тот на кого перенесли) - где он - освобождаем под ним место
BackpackEnemyBase.instance.OpenIndicesBackpackByIconPosition(transform.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, transform.GetComponent<PlayerIconPlaneInventory>().startPos);
else //
BackpackEnemyBase.instance.OpenIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
isEnemyBackpack = true;
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive)
{
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().OpenIndicesBackpackByIconPosition(transform.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, transform.GetComponent<PlayerIconPlaneInventory>().startPos);
if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().IsHaveFreeSlotBackpack(vspCombine.GetComponent<ItemsDrop>().CL.indexPos60x60))
{
indexFreePlace = 0;
isCreatedInBackpackWindow = true;
}
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive)
{
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().OpenIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
indexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().GetFreeSlotTacticRigPockets(vspCombine.GetComponent<ItemsDrop>().CL.tagSize);
if (indexFreePlace != -1)
isCreatedInBackpackWindow = true;
}
else // Player inv
{
if (transform.GetComponent<DragHandler>().isBackpackSlot)
BackpackSystem.instance.OpenIndicesBackpackByIconPosition(transform.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, transform.GetComponent<PlayerIconPlaneInventory>().startPos);
else
BackpackSystem.instance.OpenIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
}
// If we did not found free space we need to check base backpack
if (indexFreePlace == -1)
{
bool isLootWindow = false;
if (transform.GetComponentInChildren<ButtonOptions>().CL.lootID != -1 && StashSystem.instance.referenceToOpenedLootBox) // Loot Window
isLootWindow = true;
indexFreePlace = Helper.GetFreeSlotIndexPlayerInventory(vspCombine.GetComponent<ItemsDrop>().CL.indexPos60x60, vspCombine.GetComponent<ItemsDrop>().CL.tagSize, false, isEnemyBackpack, isLootWindow);
}
if (indexFreePlace != -1)
{
itemCL.amountStack = itemCL.amountStack - (itemCL.maxAmountStack - transform.GetComponentInChildren<ButtonOptions>().CL.amountStack);
// StartCoroutine - we need to wait until vspCombine is created
// transform.gameObject - we need to open slots and delete it
Debug.Log("transform.gameObject.GetComponent<Slot>().transform.localPosition = " + transform.gameObject.GetComponent<Slot>().transform.localPosition);
StartCoroutine(Helper.CreateNewIconInInventoryNextFrame(indexFreePlace, vspCombine.GetComponent<ItemsDrop>().CL, transform.gameObject, isEnemyBackpack, isCreatedInBackpackWindow));
DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().SetTextParameters(itemCL);
if (itemCL.destroyItemDrop && itemCL.lootID != -1)
Destroy(itemCL.destroyItemDrop);
if (transform.GetComponentInChildren<ButtonOptions>().CL.destroyItemDrop && transform.GetComponentInChildren<ButtonOptions>().CL.lootID != -1)
Destroy(transform.GetComponentInChildren<ButtonOptions>().CL.destroyItemDrop);
if (transform.GetComponentInChildren<ButtonOptions>().CL.itemModding)
Destroy(transform.GetComponentInChildren<ButtonOptions>().CL.itemModding);
if (itemCL.itemModding)
Destroy(itemCL.itemModding);
return true;
}
else
{
DragHandler.isDeleteIcon = false;
if (isEnemyBackpack)
{
if (transform.GetComponent<DragHandler>().isBackpackSlot)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(transform.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, transform.GetComponent<PlayerIconPlaneInventory>().startPos);
else
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
}
else if (transform.GetComponent<DragHandler>().isStashSlot)
{
StashSystem.instance.CloseIndicesBackpackByIconPosition(transform.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, transform.GetComponent<PlayerIconPlaneInventory>().startPos);
}
else
{
if (transform.GetComponent<DragHandler>().isBackpackSlot)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(transform.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, transform.GetComponent<PlayerIconPlaneInventory>().startPos);
else
BackpackSystem.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren<ButtonOptions>().CL);
}
Destroy(vspCombine.GetComponent<ItemsDrop>().CL.itemModding);
Destroy(vspCombine);
InventoryBase.instance.isActiveNoPlacePane = true;
return false;
}
}
return false;
}
private bool CombineTwoItemsBySaveOne(int amountItems)
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL;
if (transform.GetComponentInChildren<ButtonOptions>().CL.isCombine == true && itemCL.isCombine == true)
{
// Create a new prefab (then we need to delete it)
GameObject vspCombine = (GameObject)Instantiate(transform.GetComponentInChildren<ButtonOptions>().CL.combineResultPrefab, InventoryBase.instance.RootItemsSpawnInWorld.transform);
vspCombine.GetComponent<ItemsDrop>().CL.destroyItemDrop = vspCombine;
vspCombine.GetComponent<ItemsDrop>().CL = Helper.SetParameters(vspCombine.GetComponent<ItemsDrop>().CL, vspCombine, false);
bool isCreateInBackpackWindow = false;
bool isEnemyBackpack = false;
int indexFreePlace = -1;
// Освобождаем место под иконкой, на которую наводим
if ((MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) || (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive)) // Enemy inv
{
isEnemyBackpack = true;
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive)
{
if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().IsHaveFreeSlotBackpack(vspCombine.GetComponent<ItemsDrop>().CL.indexPos60x60))
{
indexFreePlace = 0;
isCreateInBackpackWindow = true;
}
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive)
{
indexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().GetFreeSlotTacticRigPockets(vspCombine.GetComponent<ItemsDrop>().CL.tagSize);
if (indexFreePlace != -1)
isCreateInBackpackWindow = true;
}
if (indexFreePlace == -1)
{
bool isWindowLoot = false;
if (transform.GetComponentInChildren<ButtonOptions>().CL.lootID != -1 && StashSystem.instance.referenceToOpenedLootBox) // Loot Window
isWindowLoot = true;
indexFreePlace = Helper.GetFreeSlotIndexPlayerInventory(vspCombine.GetComponent<ItemsDrop>().CL.indexPos60x60, vspCombine.GetComponent<ItemsDrop>().CL.tagSize, false, isEnemyBackpack, isWindowLoot);
}
if (indexFreePlace != -1)
{
itemCL.amountStack = itemCL.amountStack - (itemCL.maxAmountStack - transform.GetComponentInChildren<ButtonOptions>().CL.amountStack);
StartCoroutine(Helper.CreateNewIconInInventoryNextFrame(indexFreePlace, vspCombine.GetComponent<ItemsDrop>().CL, transform.gameObject, isEnemyBackpack, isCreateInBackpackWindow));
if (transform.GetComponentInChildren<ButtonOptions>().CL.destroyItemDrop && transform.GetComponentInChildren<ButtonOptions>().CL.lootID != -1)
Destroy(transform.GetComponentInChildren<ButtonOptions>().CL.destroyItemDrop);
return true;
}
else
{
Destroy(vspCombine.GetComponent<ItemsDrop>().CL.itemModding);
Destroy(vspCombine);
InventoryBase.instance.isActiveNoPlacePane = true;
return false;
}
}
return false;
}
#endregion
#region Checking
private bool CheckAdditionSlotItemTags(ItemList itemCL)
{
// Because The slot may have additional requirements first go through them and see if the icon corresponds to them
// (for example, in Tactical Rig the main requirement is (ClassList.TagItems == ITEMS) but you can also add a 1x2 gun or a 1x2 knife)
if (AdditionalTagsItem.Length > 0)
{
if (AdditionalTagsItem[0] == ItemList.TagItems.ALL)
return true;
else
{
foreach (ItemList.TagItems ti in AdditionalTagsItem)
{
if (ti == itemCL.tagItem)
return true;
}
}
}
return false;
}
private bool CheckSelfDropping()
{
// We cannot drop the item to ourselves on
if (transform.GetComponentInChildren<ButtonOptions>() && DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>())
{
if (transform.GetComponentInChildren<ButtonOptions>().CL.id == DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.id)
return true;
}
return false;
}
private bool CheckingWasItemRotatedAndPlacedToSlotFromSlot()
{
if (DragHandler.itemIcon && DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60 != DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.GetIndexPos60x60ByTag(DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().CL.baseTagSize)) // Was Rotated
{
if (DragHandler.isPlayer && MouseEnterPlayerInventory.instance && MouseEnterPlayerInventory.instance.isActive)
{
Debug.Log("Hey you try to put item on slot from slot and as seen the item was rotated");
return true;
}
}
return false;
}
#endregion
#region Close, Reset, Destroy
private void ResetIconLocation()
{
DragHandler.itemIcon.transform.SetParent(transform);
DragHandler.itemIcon.transform.localScale = Vector3.one;
DragHandler.itemIcon.transform.localPosition = Vector3.zero;
DragHandler.itemIcon.GetComponentInChildren<ButtonOptions>().transform.localPosition = Vector3.zero;
}
#endregion
#endregion
}
}
}