//********************************************************//
// //
// 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;
///
/// The script attaches to GameObjects in those places where it is necessary to create the ability to attach an icon
///
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() && DragHandler.itemIcon.GetComponentInParent().isActive)
return;
if (InventoryBase.instance.m_Hotbar.isActiveHotbar && PointerEnterInventoryHotbar.instance && PointerEnterInventoryHotbar.instance.isActive) // Если внутри области
{
InventoryBase.instance.m_Hotbar.UpdateHotbarOnDragAndDropItems(DragHandler.itemIcon.GetComponentInChildren().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().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())
DragHandler.itemIcon.GetComponentInParent().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().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() && !transform.GetComponentInChildren().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().CL;
if (transform.GetComponentInChildren().CL.isPutOn || transform.GetComponentInChildren().CL.isOpen) // Если переносим на активный рюкзак или если рюкзак открыт и мы переносим предмет на
{
//
// Maybe need to do something but for now we do nothing
//
return false;
}
else
{
if (BackpackSystem.instance.SaveItemToBackpack(transform.GetComponentInChildren().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().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().CL;
if (transform.GetComponentInChildren().CL.isPutOn) // Если переносим на активный рюкзак или если рюкзак открыт и мы переносим предмет на
{
//
// Maybe need to do something but for now we do nothing
//
return false;
}
else
{
if (BackpackSystem.instance.SaveItemToBackpack(transform.GetComponentInChildren().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().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().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().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().loadStart = true;
InventoryBase.instance.selectWeapon.UpdateStatistics(); // update weapon statistics
}
}
}
#endregion
#region Drop Item
private void DropItemToAnotherItem()
{
if (transform.GetComponentInChildren())
{
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()) // If this is a bullet - we can not exchange
if (transform.GetComponentInChildren().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().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().CL.IsBackpackItemSlot() || transform.GetComponentInChildren().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() && slotParent.GetComponent().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() && slotParent.GetComponent().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().CL.idSlotBackpack = itemCL.idSlotBackpack;
itemCL.idSlotBackpack = -1;
if (DragHandler.isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
else if (DragHandler.isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
}
}
else if (slotParent.GetComponent() && slotParent.GetComponent().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().CL.idSlotBackpack;
transform.GetComponentInChildren().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().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().CL.idSlotBackpack;
transform.GetComponentInChildren().CL.idSlotBackpack = id;
if (DragHandler.isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren().CL); // We need to close the old position (because we opened it when dragging)
else if (DragHandler.isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren().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().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().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().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().enabled = true;
}
}
}
itemCL.newIDSlotBackpack = GetComponent().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().CL.itemModding.transform.GetComponentsInChildren(typeof(Helpers), true); // Collect all helpers
if (h != null)
{
foreach (Helpers g in h)
{
if (g.TagAttach == DragHandler.itemIcon.GetComponentInChildren().CL.tagAttach)
{
if (!CanWeAttachItemToWeapon(itemCL))
return true;
if (g.GetComponentInChildren()) // If we have one on the weapon we need to replace it for the new one
{
StartCoroutine(InventoryBase.instance.CreateItemAttachmentsInInventory(g.GetComponentInChildren().CL, false));
g.GetComponentInChildren().gameObject.transform.SetParent(InventoryBase.instance.RootSpawnItemsAttach.transform);
}
//
//
//
itemCL.SetItemModdingParameters(true, g.transform);
g.AddParametersToHelper(itemCL, g.GetComponentInChildren().GetOriginalAttachmentID());
DragHandler.itemIcon.GetComponent().deleteVSP = true; // We need to destroy the base icon
DragHandler.itemIcon.GetComponent().isAttached = true;
//if (InventoryBase.instance.hideStash || BackpackSystem.instance.RE4_IsActive() || BackpackSystem.instance.RE4O_IsActive())
DragHandler.isDeleteIcon = true;
//
// Save parameters
//
transform.GetComponentInChildren().isActiveUpdateImg = true; // We need to update the weapon icon
SaveWeaponParameters(transform.GetComponentInChildren().CL);
break;
}
}
}
}
return false;
}
private bool CanWeAttachItemToWeapon(ItemList itemCL)
{
bool canAttachToTool = false;
for (int i = 0; i < DragHandler.itemIcon.GetComponentInChildren().CL.id_Attach.Length; i++)
{
if (DragHandler.itemIcon.GetComponentInChildren().CL.id_Attach[i] == transform.GetComponentInChildren().CL.id_Weapon) // Если хоть один ID совпадает
{
canAttachToTool = true;
break;
}
}
return canAttachToTool;
}
#endregion
#region Put item on item
private bool CanPutBulletsInMagazine()
{
if (transform.GetComponentInChildren().CL.isMagazine == true && DragHandler.itemIcon.GetComponentInChildren().CL.isBullet == true)
return true;
return false;
}
private void PutBulletsInMagazine()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren().CL;
if (transform.GetComponentInChildren().CL.typeOfBullet == itemCL.typeOfBullet)
{
int amount = transform.GetComponentInChildren().CL.amountBullet + itemCL.amountBullet;
if (amount <= transform.GetComponentInChildren().CL.clipSize)
{
DragHandler.isDeleteIcon = true;
transform.GetComponentInChildren().CL.amountBullet = amount;
if (itemCL.itemModding)
Destroy(itemCL.itemModding); // we need to destroy object
}
else
{
itemCL.amountBullet = itemCL.amountBullet - (transform.GetComponentInChildren().CL.clipSize - transform.GetComponentInChildren().CL.amountBullet);
transform.GetComponentInChildren().CL.amountBullet = transform.GetComponentInChildren().CL.clipSize;
DragHandler.itemIcon.GetComponentInChildren().SetTextParameters(itemCL);
}
transform.GetComponentInChildren().SetTextParameters(transform.GetComponentInChildren().CL);
}
}
private bool CanPutItemsInItem()
{
if (transform.GetComponentInChildren().CL.isPurse == true && DragHandler.itemIcon.GetComponentInChildren().CL.isMoney == true && transform.GetComponentInChildren().CL.moneyType == DragHandler.itemIcon.GetComponentInChildren().CL.moneyType)
return true;
return false;
}
private void PutItemsInItem()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren().CL;
int amount = transform.GetComponentInChildren().CL.amountStack + itemCL.amountStack;
if (amount <= transform.GetComponentInChildren().CL.maxAmountStack)
{
DragHandler.isDeleteIcon = true;
transform.GetComponentInChildren().CL.amountStack = amount;
Destroy(itemCL.itemModding); // we need to destroy object
if (itemCL.destroyItemDrop)
Destroy(itemCL.destroyItemDrop);
}
else
{
itemCL.amountStack = itemCL.amountStack - (transform.GetComponentInChildren().CL.maxAmountStack - transform.GetComponentInChildren().CL.amountStack);
transform.GetComponentInChildren().CL.amountStack = transform.GetComponentInChildren().CL.maxAmountStack;
DragHandler.itemIcon.GetComponentInChildren().SetTextParameters(itemCL);
}
transform.GetComponentInChildren().SetTextParameters(transform.GetComponentInChildren().CL);
}
#endregion
#region Combine
private bool CanCombineBullets()
{
if (transform.GetComponentInChildren().CL.isBullet == true && DragHandler.itemIcon.GetComponentInChildren().CL.isBullet == true)
return true;
return false;
}
private void CombineBullets()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren().CL;
if (transform.GetComponentInChildren().CL.typeOfBullet == itemCL.typeOfBullet)
{
int amount = transform.GetComponentInChildren().CL.amountBullet + itemCL.amountBullet;
if (amount <= InventoryBase.instance.MaxAmountStackBullet)
{
DragHandler.isDeleteIcon = true;
transform.GetComponentInChildren().CL.amountBullet = amount;
if (itemCL.itemModding)
Destroy(itemCL.itemModding);
}
else
{
itemCL.amountBullet = itemCL.amountBullet - (InventoryBase.instance.MaxAmountStackBullet - transform.GetComponentInChildren().CL.amountBullet);
transform.GetComponentInChildren().CL.amountBullet = InventoryBase.instance.MaxAmountStackBullet;
DragHandler.itemIcon.GetComponentInChildren().SetTextParameters(itemCL);
}
transform.GetComponentInChildren().SetTextParameters(transform.GetComponentInChildren().CL);
}
}
private bool CanCombineItems()
{
if (transform.GetComponentInChildren().CL.isStack == true && DragHandler.itemIcon.GetComponentInChildren().CL.isStack == true && transform.GetComponentInChildren().CL.stackID == DragHandler.itemIcon.GetComponentInChildren().CL.stackID)
return true;
return false;
}
private void CombineItems()
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren().CL;
// Total amount of items that we have
int totalAmountOfItems = transform.GetComponentInChildren().CL.amountStack + itemCL.amountStack;
if (totalAmountOfItems <= itemCL.maxAmountStack)
{
if (!CombineTwoItemsByDestroyOne(totalAmountOfItems))
{
if (totalAmountOfItems != itemCL.maxAmountStack)
transform.GetComponentInChildren().CL.amountStack = totalAmountOfItems;
Destroy(itemCL.itemModding);
}
}
else // Создаем новую иконку и оставляет одну с остатком
{
if (!CombineTwoItemsBySaveOne(totalAmountOfItems))
{
//itemCL.amountStack = itemCL.amountStack - (itemCL.maxAmountStack - transform.GetComponentInChildren().CL.amountStack);
//transform.GetComponentInChildren().CL.amountStack = itemCL.maxAmountStack;
}
DragHandler.itemIcon.GetComponentInChildren().SetTextParameters(itemCL);
}
transform.GetComponentInChildren().SetTextParameters(transform.GetComponentInChildren().CL);
}
private bool CombineTwoItemsByDestroyOne(int amountItems)
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren().CL;
DragHandler.isDeleteIcon = true;
if (amountItems == itemCL.maxAmountStack && transform.GetComponentInChildren().CL.isCombine == true && itemCL.isCombine == true)
{
// Create a new prefab (then we need to delete it)
GameObject vspCombine = Instantiate(transform.GetComponentInChildren().CL.combineResultPrefab, InventoryBase.instance.RootItemsSpawnInWorld.transform);
vspCombine.GetComponent().CL.destroyItemDrop = vspCombine;
vspCombine.GetComponent().CL = Helper.SetParameters(vspCombine.GetComponent().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().isBackpackSlot) // Проверяем предмет (тот на кого перенесли) - где он - освобождаем под ним место
BackpackEnemyBase.instance.OpenIndicesBackpackByIconPosition(transform.GetComponentInChildren().CL.indexPos60x60, transform.GetComponent().startPos);
else //
BackpackEnemyBase.instance.OpenIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
isEnemyBackpack = true;
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().isActive)
{
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().OpenIndicesBackpackByIconPosition(transform.GetComponentInChildren().CL.indexPos60x60, transform.GetComponent().startPos);
if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().IsHaveFreeSlotBackpack(vspCombine.GetComponent().CL.indexPos60x60))
{
indexFreePlace = 0;
isCreatedInBackpackWindow = true;
}
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().isActive)
{
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().OpenIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
indexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().GetFreeSlotTacticRigPockets(vspCombine.GetComponent().CL.tagSize);
if (indexFreePlace != -1)
isCreatedInBackpackWindow = true;
}
else // Player inv
{
if (transform.GetComponent().isBackpackSlot)
BackpackSystem.instance.OpenIndicesBackpackByIconPosition(transform.GetComponentInChildren().CL.indexPos60x60, transform.GetComponent().startPos);
else
BackpackSystem.instance.OpenIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
}
// If we did not found free space we need to check base backpack
if (indexFreePlace == -1)
{
bool isLootWindow = false;
if (transform.GetComponentInChildren().CL.lootID != -1 && StashSystem.instance.referenceToOpenedLootBox) // Loot Window
isLootWindow = true;
indexFreePlace = Helper.GetFreeSlotIndexPlayerInventory(vspCombine.GetComponent().CL.indexPos60x60, vspCombine.GetComponent().CL.tagSize, false, isEnemyBackpack, isLootWindow);
}
if (indexFreePlace != -1)
{
itemCL.amountStack = itemCL.amountStack - (itemCL.maxAmountStack - transform.GetComponentInChildren().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().transform.localPosition = " + transform.gameObject.GetComponent().transform.localPosition);
StartCoroutine(Helper.CreateNewIconInInventoryNextFrame(indexFreePlace, vspCombine.GetComponent().CL, transform.gameObject, isEnemyBackpack, isCreatedInBackpackWindow));
DragHandler.itemIcon.GetComponentInChildren().SetTextParameters(itemCL);
if (itemCL.destroyItemDrop && itemCL.lootID != -1)
Destroy(itemCL.destroyItemDrop);
if (transform.GetComponentInChildren().CL.destroyItemDrop && transform.GetComponentInChildren().CL.lootID != -1)
Destroy(transform.GetComponentInChildren().CL.destroyItemDrop);
if (transform.GetComponentInChildren().CL.itemModding)
Destroy(transform.GetComponentInChildren().CL.itemModding);
if (itemCL.itemModding)
Destroy(itemCL.itemModding);
return true;
}
else
{
DragHandler.isDeleteIcon = false;
if (isEnemyBackpack)
{
if (transform.GetComponent().isBackpackSlot)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(transform.GetComponentInChildren().CL.indexPos60x60, transform.GetComponent().startPos);
else
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
}
else if (transform.GetComponent().isStashSlot)
{
StashSystem.instance.CloseIndicesBackpackByIconPosition(transform.GetComponentInChildren().CL.indexPos60x60, transform.GetComponent().startPos);
}
else
{
if (transform.GetComponent().isBackpackSlot)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(transform.GetComponentInChildren().CL.indexPos60x60, transform.GetComponent().startPos);
else
BackpackSystem.instance.CloseIndicesTacticalRigPockets(transform.GetComponentInChildren().CL);
}
Destroy(vspCombine.GetComponent().CL.itemModding);
Destroy(vspCombine);
InventoryBase.instance.isActiveNoPlacePane = true;
return false;
}
}
return false;
}
private bool CombineTwoItemsBySaveOne(int amountItems)
{
ItemList itemCL = DragHandler.itemIcon.GetComponentInChildren().CL;
if (transform.GetComponentInChildren().CL.isCombine == true && itemCL.isCombine == true)
{
// Create a new prefab (then we need to delete it)
GameObject vspCombine = (GameObject)Instantiate(transform.GetComponentInChildren().CL.combineResultPrefab, InventoryBase.instance.RootItemsSpawnInWorld.transform);
vspCombine.GetComponent().CL.destroyItemDrop = vspCombine;
vspCombine.GetComponent().CL = Helper.SetParameters(vspCombine.GetComponent().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() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().isActive)
{
if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().IsHaveFreeSlotBackpack(vspCombine.GetComponent().CL.indexPos60x60))
{
indexFreePlace = 0;
isCreateInBackpackWindow = true;
}
}
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().isActive)
{
indexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().GetFreeSlotTacticRigPockets(vspCombine.GetComponent().CL.tagSize);
if (indexFreePlace != -1)
isCreateInBackpackWindow = true;
}
if (indexFreePlace == -1)
{
bool isWindowLoot = false;
if (transform.GetComponentInChildren().CL.lootID != -1 && StashSystem.instance.referenceToOpenedLootBox) // Loot Window
isWindowLoot = true;
indexFreePlace = Helper.GetFreeSlotIndexPlayerInventory(vspCombine.GetComponent().CL.indexPos60x60, vspCombine.GetComponent().CL.tagSize, false, isEnemyBackpack, isWindowLoot);
}
if (indexFreePlace != -1)
{
itemCL.amountStack = itemCL.amountStack - (itemCL.maxAmountStack - transform.GetComponentInChildren().CL.amountStack);
StartCoroutine(Helper.CreateNewIconInInventoryNextFrame(indexFreePlace, vspCombine.GetComponent().CL, transform.gameObject, isEnemyBackpack, isCreateInBackpackWindow));
if (transform.GetComponentInChildren().CL.destroyItemDrop && transform.GetComponentInChildren().CL.lootID != -1)
Destroy(transform.GetComponentInChildren().CL.destroyItemDrop);
return true;
}
else
{
Destroy(vspCombine.GetComponent().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() && DragHandler.itemIcon.GetComponentInChildren())
{
if (transform.GetComponentInChildren().CL.id == DragHandler.itemIcon.GetComponentInChildren().CL.id)
return true;
}
return false;
}
private bool CheckingWasItemRotatedAndPlacedToSlotFromSlot()
{
if (DragHandler.itemIcon && DragHandler.itemIcon.GetComponentInChildren().CL.indexPos60x60 != DragHandler.itemIcon.GetComponentInChildren().CL.GetIndexPos60x60ByTag(DragHandler.itemIcon.GetComponentInChildren().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().transform.localPosition = Vector3.zero;
}
#endregion
#endregion
}
}
}