//********************************************************// // // // Copyright © All rights reserved. MyNameIsVoo. 2020. // // // // REPRODUCTION FORBIDEN // // // //********************************************************// using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using ItemsClassList; using ICWM.DragAndDrop; using ICWM.Enemy; using ICWM.IconSystem; using ICWM.ItemSystem; using ICWM.RenderSystem; using ICWM.SaveSystem; using ICWM.UISystem; using ICWM.WindowSystem; namespace ICWM { namespace HelperSystem { public static class Helper { #region Render Helper public static void AddItemToRenderList(GameObject itemSlot, ItemList cl) // in RenderWeaponScreenIcon { InventoryBase.instance.WeaponRenderScreen.GetComponent().listMassiveRenderCL.Add(cl); InventoryBase.instance.WeaponRenderScreen.GetComponent().listMassiveRenderGO.Add(itemSlot); InventoryBase.instance.WeaponRenderScreen.GetComponent().isRenderTextures = true; } public static Material CreateRenderMaterial(ItemList cl) { Material vspMatIcon; vspMatIcon = Material.Instantiate(InventoryBase.instance.WeaponRenderScreen.GetComponent().MatIcon); vspMatIcon.name = "Mat_" + cl.id.ToString(); RenderTexture vspRTIcon; vspRTIcon = RenderTexture.Instantiate(InventoryBase.instance.WeaponRenderScreen.GetComponent().RTIcon); vspRTIcon.name = "RT_" + vspMatIcon.name; if (cl.itWasRotated) { vspRTIcon.height = (int)(cl.indexPos60x60.x * BackpackBase.CELL_SIZE); vspRTIcon.width = (int)(cl.indexPos60x60.y * BackpackBase.CELL_SIZE); } else { vspRTIcon.height = (int)(cl.indexPos60x60.y * BackpackBase.CELL_SIZE); vspRTIcon.width = (int)(cl.indexPos60x60.x * BackpackBase.CELL_SIZE); } vspRTIcon.antiAliasing = 8; vspMatIcon.mainTexture = vspRTIcon; return vspMatIcon; } #endregion #region Set Item Parameters // // From ClassList to ClassList // Create a new item // public static ItemList SetParameters(ItemList clNew, ItemList clOrigin, bool isStoreItem = false) { clNew.id = InventoryBase.instance.idWeaponNames; // InventoryBase.instance.idWeaponNames++; if (clOrigin.isStack) { clNew.isStack = clOrigin.isStack; clNew.stackID = clOrigin.stackID; } clNew.amountStack = clOrigin.amountStack; if (clOrigin.isMoney) { clNew.isMoney = clOrigin.isMoney; clNew.moneyType = clOrigin.moneyType; clNew.isPurse = clOrigin.isPurse; if (clOrigin.isPurse) clNew.maxAmountStack = clOrigin.maxAmountStack; else clNew.maxAmountStack = InventoryBase.instance.PlayerStatistics.MaxMoneyStack; } else clNew.maxAmountStack = clOrigin.maxAmountStack; if (clOrigin.isCombine) { clNew.isCombine = clOrigin.isCombine; clNew.combineResultPrefab = clOrigin.combineResultPrefab; } if (clOrigin.isResultCombine) { clNew.isResultCombine = clOrigin.isResultCombine; clNew.combineResultPrefab = clOrigin.combineResultPrefab; clNew.maxStackCombine = clOrigin.maxStackCombine; } clNew.isEnemyItem = clOrigin.isEnemyItem; clNew.tagAttach = clOrigin.tagAttach; clNew.typeOfBullet = clOrigin.typeOfBullet; clNew.isLatchkey = clOrigin.isLatchkey; clNew.isBullet = clOrigin.isBullet; clNew.isMagazine = clOrigin.isMagazine; clNew.clipSize = clOrigin.clipSize; clNew.amountBullet = clOrigin.amountBullet; clNew.separatePrefab = clOrigin.separatePrefab; clNew.itHasMagazine = clOrigin.itHasMagazine; clNew.sortingType = clOrigin.sortingType; clNew.tagItem = clOrigin.tagItem; clNew.tagSize = clOrigin.tagSize; clNew.baseTagSize = clOrigin.baseTagSize; clNew.indexPos60x60 = clNew.GetIndexPos60x60(); clNew.id_Weapon = clOrigin.id_Weapon; clNew.id_Attach = clOrigin.id_Attach; clNew.isLockRotate = clOrigin.isLockRotate; clNew.isBackpack = clOrigin.isBackpack; clNew.isTacticalRig = clOrigin.isTacticalRig; clNew.isPockets = clOrigin.isPockets; clNew.statisticList = clOrigin.statisticList; clNew.baseStatisticsList = clOrigin.statisticList; clNew.baseColliderSize = clOrigin.baseColliderSize; clNew.isPutOn = clOrigin.isPutOn; clNew.itemIcon = clOrigin.itemIcon; clNew.startPositionInInventory = clOrigin.startPositionInInventory; if (clNew.isPockets) { clNew.pocketSlots = clOrigin.pocketSlots; if (clNew.pocketSlots > 1) clNew.insertCL = new ItemList[clNew.pocketSlots]; else clNew.insertCL = new ItemList[BackpackBase.MAX_POCKETS_CELLS]; } else if (clNew.isTacticalRig) { clNew.insertCL = new ItemList[BackpackBase.MAX_TACTICAL_RIG_CELLS]; clNew.typeTRStyle = clOrigin.typeTRStyle; } else { clNew.insertCL = new ItemList[1]; } if (clOrigin.itemModding) { if (!isStoreItem) clNew.itemModding = GameObject.Instantiate(clOrigin.itemModding); else clNew.itemModding = clOrigin.itemModding; } else if (clOrigin.vspItemModdingPrefab) clNew.itemModding = GameObject.Instantiate(clOrigin.vspItemModdingPrefab); clNew.vspItemModdingPrefab = clOrigin.vspItemModdingPrefab; if (clOrigin.weaponPlayerRig) clNew.weaponPlayerRig = clOrigin.weaponPlayerRig; if (clOrigin.spriteTextureItemInventory) clNew.spriteTextureItemInventory = clOrigin.spriteTextureItemInventory; if (clOrigin.spriteTextureItemModding) clNew.spriteTextureItemModding = clOrigin.spriteTextureItemModding; clNew.isDefaultRenderParams = clOrigin.isDefaultRenderParams; clNew.modelRenderPosition = clOrigin.modelRenderPosition; clNew.modelRenderRotation = clOrigin.modelRenderRotation; clNew.modelRenderScale = clOrigin.modelRenderScale; return clNew; } // // From ItemDrop to ClassList // Create a new item // public static ItemList SetParameters(ItemList clNew, GameObject idOrigin, bool isCreateItemModding = false, bool isCreateNewId = true, GameObject DestroyObj = null, bool IsNotEnemyItem = false) { if (isCreateNewId) { clNew.id = InventoryBase.instance.idWeaponNames; // InventoryBase.instance.idWeaponNames++; } else { clNew.id = idOrigin.GetComponent().id; } if (DestroyObj != null) clNew.destroyItemDrop = DestroyObj; else clNew.destroyItemDrop = idOrigin.GetComponent().gameObject; if (idOrigin.GetComponent().IsStack) { clNew.isStack = idOrigin.GetComponent().IsStack; clNew.stackID = idOrigin.GetComponent().StackID; } clNew.amountStack = idOrigin.GetComponent().AmountStack; if (idOrigin.GetComponent().IsMoney) { clNew.isMoney = idOrigin.GetComponent().IsMoney; clNew.moneyType = idOrigin.GetComponent().MoneyType; clNew.isPurse = idOrigin.GetComponent().IsPurse; if (idOrigin.GetComponent().IsPurse) clNew.maxAmountStack = idOrigin.GetComponent().MaxAmountStack; else clNew.maxAmountStack = InventoryBase.instance.PlayerStatistics.MaxMoneyStack; } else clNew.maxAmountStack = idOrigin.GetComponent().MaxAmountStack; if (idOrigin.GetComponent().IsCombine) { clNew.isCombine = idOrigin.GetComponent().IsCombine; clNew.combineResultPrefab = idOrigin.GetComponent().CombineResultPrefab; } if (idOrigin.GetComponent().IsResultCombine) { clNew.isResultCombine = idOrigin.GetComponent().IsResultCombine; clNew.combineResultPrefab = idOrigin.GetComponent().CombineResultPrefab; clNew.maxStackCombine = idOrigin.GetComponent().MaxStackCombine; } clNew.tagAttach = idOrigin.GetComponent().AttachTag; clNew.typeOfBullet = idOrigin.GetComponent().TypeOfBullet; clNew.isLatchkey = idOrigin.GetComponent().IsLatchkey; clNew.isBullet = idOrigin.GetComponent().IsBullet; clNew.isMagazine = idOrigin.GetComponent().IsMagazine; clNew.clipSize = idOrigin.GetComponent().ClipSize; clNew.amountBullet = idOrigin.GetComponent().AmountBullet; clNew.separatePrefab = idOrigin.GetComponent().SeparatePrefab; clNew.itHasMagazine = idOrigin.GetComponent().ItHasMagazine; clNew.sortingType = idOrigin.GetComponent().SortingType; clNew.tagItem = idOrigin.GetComponent().ItemTag; clNew.tagSize = idOrigin.GetComponent().SizeTag; clNew.baseTagSize = clNew.tagSize; clNew.indexPos60x60 = clNew.GetIndexPos60x60(); clNew.id_Weapon = idOrigin.GetComponent().ID_Weapon; clNew.id_Attach = idOrigin.GetComponent().ID_Attachments; clNew.isLockRotate = idOrigin.GetComponent().IsLockRotate; clNew.isBackpack = idOrigin.GetComponent().IsBackpack; clNew.isTacticalRig = idOrigin.GetComponent().IsTacticalRig; clNew.isPockets = idOrigin.GetComponent().IsPockets; clNew.statisticList = idOrigin.GetComponent().StatList; clNew.baseStatisticsList = idOrigin.GetComponent().StatList; clNew.baseColliderSize = idOrigin.GetComponent().size; // clNew.startPositionInInventory = idOrigin.GetComponent().StartPositionInInventory; if (IsNotEnemyItem == false) { if (idOrigin.GetComponent().CL.insertCL != null && idOrigin.GetComponent().CL.insertCL.Length != 0) { clNew.insertCL = new ItemList[idOrigin.GetComponent().CL.insertCL.Length]; clNew.startPositionInBackpack = new Vector2[idOrigin.GetComponent().CL.insertCL.Length]; for (int i = 0; i < idOrigin.GetComponent().CL.insertCL.Length; i++) { if (idOrigin.GetComponent().CL.insertCL[i] == null) break; clNew.startPositionInBackpack[i] = idOrigin.GetComponent().CL.insertCL[i].startPositionInInventory; clNew.insertCL[i] = idOrigin.GetComponent().CL.insertCL[i]; clNew.insertCL[i] = SetParameters(clNew.insertCL[i], idOrigin.GetComponent().CL.insertCL[i]); } } } clNew.isPutOn = idOrigin.GetComponent().IsPutOn; if (clNew.isPockets) { clNew.pocketSlots = idOrigin.GetComponent().PocketSlots; if (clNew.pocketSlots > 1) clNew.insertCL = new ItemList[clNew.pocketSlots]; else clNew.insertCL = new ItemList[BackpackBase.MAX_POCKETS_CELLS]; } else if (clNew.isTacticalRig) { clNew.insertCL = new ItemList[BackpackBase.MAX_TACTICAL_RIG_CELLS]; clNew.typeTRStyle = idOrigin.GetComponent().TypeTRStyle; } else if (clNew.isBackpack) { clNew.tagSizeBackpack = idOrigin.GetComponent().SizeBackpack; clNew.insertCL = new ItemList[clNew.GetMasSizeBackpack()]; clNew.startPositionInBackpack = new Vector2[clNew.GetMasSizeBackpack()]; } else { clNew.insertCL = new ItemList[1]; } if (idOrigin.GetComponent().itemModding) { clNew.vspItemModdingPrefab = idOrigin.GetComponent().itemModding; clNew.SetItemModdingParameters(true, null); } else Debug.Log("id_Original.GetComponent().itemModding == null"); if (idOrigin.GetComponent().WeaponPlayerRig) clNew.weaponPlayerRig = idOrigin.GetComponent().WeaponPlayerRig; if (idOrigin.GetComponent().SpriteTextureItemInventory) clNew.spriteTextureItemInventory = idOrigin.GetComponent().SpriteTextureItemInventory; if (idOrigin.GetComponent().SpriteTextureItemModding) clNew.spriteTextureItemModding = idOrigin.GetComponent().SpriteTextureItemModding; clNew.isDefaultRenderParams = idOrigin.GetComponent().ByDefaultRenderParams; clNew.modelRenderPosition = idOrigin.GetComponent().WeaponPosition; clNew.modelRenderRotation = idOrigin.GetComponent().WeaponRotation; clNew.modelRenderScale = idOrigin.GetComponent().WeaponScale; return clNew; } // // From ClassList to ItemDrop // We do not create a new item // public static void SetParameters(GameObject idNew, ItemList idOrigin) { idNew.GetComponent().id = idOrigin.id; if (idOrigin.isStack) { idNew.GetComponent().IsStack = idOrigin.isStack; idNew.GetComponent().StackID = idOrigin.stackID; } idNew.GetComponent().AmountStack = idOrigin.amountStack; if (idOrigin.isMoney) { idNew.GetComponent().IsMoney = idOrigin.isMoney; idNew.GetComponent().MoneyType = idOrigin.moneyType; idNew.GetComponent().IsPurse = idOrigin.isPurse; if (idNew.GetComponent().IsPurse) idNew.GetComponent().MaxAmountStack = idOrigin.maxAmountStack; else InventoryBase.instance.PlayerStatistics.MaxMoneyStack = idOrigin.maxAmountStack; } else idNew.GetComponent().MaxAmountStack = idOrigin.maxAmountStack; if (idOrigin.isCombine) { idNew.GetComponent().IsCombine = idOrigin.isCombine; idNew.GetComponent().CombineResultPrefab = idOrigin.combineResultPrefab; } if (idOrigin.isResultCombine) { idNew.GetComponent().IsResultCombine = idOrigin.isResultCombine; idNew.GetComponent().CombineResultPrefab = idOrigin.combineResultPrefab; idNew.GetComponent().MaxStackCombine = idOrigin.maxStackCombine; } idNew.GetComponent().AttachTag = idOrigin.tagAttach; idNew.GetComponent().TypeOfBullet = idOrigin.typeOfBullet; idNew.GetComponent().IsLatchkey = idOrigin.isLatchkey; idNew.GetComponent().IsBullet = idOrigin.isBullet; idNew.GetComponent().IsMagazine = idOrigin.isMagazine; idNew.GetComponent().ClipSize = idOrigin.clipSize; idNew.GetComponent().AmountBullet = idOrigin.amountBullet; idNew.GetComponent().SeparatePrefab = idOrigin.separatePrefab; idNew.GetComponent().ItHasMagazine = idOrigin.itHasMagazine; idNew.GetComponent().SortingType = idOrigin.sortingType; idNew.GetComponent().ItemTag = idOrigin.tagItem; idNew.GetComponent().SizeTag = idOrigin.baseTagSize; idNew.GetComponent().ID_Weapon = idOrigin.id_Weapon; idNew.GetComponent().ID_Attachments = idOrigin.id_Attach; idNew.GetComponent().IsLockRotate = idOrigin.isLockRotate; idNew.GetComponent().IsBackpack = idOrigin.isBackpack; idNew.GetComponent().IsTacticalRig = idOrigin.isTacticalRig; idNew.GetComponent().IsPockets = idOrigin.isPockets; // idNew.GetComponent().StartPositionInInventory = idOrigin.startPositionInInventory; if (idOrigin.insertCL != null && idOrigin.insertCL != null && idOrigin.insertCL.Length != 0) { if (idNew.GetComponent().CL == null) idNew.GetComponent().CL = new ItemList(); idNew.GetComponent().CL.insertCL = new ItemList[idOrigin.insertCL.Length]; for (int i = 0; i < idOrigin.insertCL.Length; i++) { if (idOrigin.insertCL[i] == null) break; idNew.GetComponent().CL.insertCL[i] = idOrigin.insertCL[i]; idNew.GetComponent().CL.insertCL[i] = SetParameters(idNew.GetComponent().CL.insertCL[i], idOrigin.insertCL[i]); } } idNew.GetComponent().IsPutOn = idOrigin.isPutOn; // ? idNew.GetComponent().StatList = idOrigin.statisticList; idNew.GetComponent().StatList = idOrigin.baseStatisticsList; idNew.GetComponent().size = idOrigin.baseColliderSize; if (idNew.GetComponent().IsBackpack) idNew.GetComponent().SizeBackpack = idOrigin.tagSizeBackpack; if (idOrigin.vspItemModdingPrefab) idNew.GetComponent().itemModding = idOrigin.vspItemModdingPrefab; else if (idOrigin.itemModding) idNew.GetComponent().itemModding = idOrigin.itemModding; if (idOrigin.weaponPlayerRig) idNew.GetComponent().WeaponPlayerRig = idOrigin.weaponPlayerRig; if (idOrigin.spriteTextureItemInventory) idNew.GetComponent().SpriteTextureItemInventory = idOrigin.spriteTextureItemInventory; if (idOrigin.spriteTextureItemModding) idNew.GetComponent().SpriteTextureItemModding = idOrigin.spriteTextureItemModding; idNew.GetComponent().CL = idOrigin; idNew.GetComponent().ByDefaultRenderParams = idOrigin.isDefaultRenderParams; idNew.GetComponent().WeaponPosition = idOrigin.modelRenderPosition; idNew.GetComponent().WeaponRotation = idOrigin.modelRenderRotation; idNew.GetComponent().WeaponScale = idOrigin.modelRenderScale; } // // From ItemDrop to ClassList // public static ItemList SetParameters(ItemList clNew, ItemsDrop idOrigin, int lootID) { clNew.id = InventoryBase.instance.idWeaponNames; InventoryBase.instance.idWeaponNames++; clNew.lootID = lootID; if (idOrigin.IsStack) { clNew.isStack = idOrigin.IsStack; clNew.stackID = idOrigin.StackID; } clNew.amountStack = idOrigin.AmountStack; if (idOrigin.IsMoney) { clNew.isMoney = idOrigin.IsMoney; clNew.isPurse = idOrigin.IsPurse; clNew.moneyType = idOrigin.MoneyType; if (idOrigin.IsPurse) clNew.maxAmountStack = idOrigin.MaxAmountStack; else clNew.maxAmountStack = InventoryBase.instance.PlayerStatistics.MaxMoneyStack; } else clNew.maxAmountStack = idOrigin.MaxAmountStack; if (idOrigin.IsCombine) { clNew.isCombine = idOrigin.IsCombine; clNew.combineResultPrefab = idOrigin.CombineResultPrefab; } if (idOrigin.IsResultCombine) { clNew.isResultCombine = idOrigin.IsResultCombine; clNew.combineResultPrefab = idOrigin.CombineResultPrefab; clNew.maxStackCombine = idOrigin.MaxStackCombine; } clNew.tagAttach = idOrigin.AttachTag; clNew.typeOfBullet = idOrigin.TypeOfBullet; clNew.isBullet = idOrigin.IsBullet; clNew.isMagazine = idOrigin.IsMagazine; clNew.clipSize = idOrigin.ClipSize; clNew.amountBullet = idOrigin.AmountBullet; clNew.separatePrefab = idOrigin.SeparatePrefab; clNew.sortingType = idOrigin.SortingType; clNew.isLatchkey = idOrigin.IsLatchkey; clNew.tagItem = idOrigin.ItemTag; clNew.tagSize = idOrigin.SizeTag; clNew.id_Weapon = idOrigin.ID_Weapon; clNew.id_Attach = idOrigin.ID_Attachments; clNew.isLockRotate = idOrigin.IsLockRotate; clNew.isBackpack = idOrigin.IsBackpack; clNew.isTacticalRig = idOrigin.IsTacticalRig; clNew.isPockets = idOrigin.IsPockets; clNew.statisticList = idOrigin.StatList; clNew.baseStatisticsList = idOrigin.StatList; clNew.indexPos60x60 = clNew.GetIndexPos60x60(); clNew.baseTagSize = idOrigin.SizeTag; clNew.baseColliderSize = idOrigin.GetComponent().size; if (clNew.isBackpack) { clNew.tagSizeBackpack = idOrigin.SizeBackpack; clNew.insertCL = new ItemList[clNew.GetMasSizeBackpack()]; clNew.startPositionInBackpack = new Vector2[clNew.GetMasSizeBackpack()]; } else if (clNew.isTacticalRig) { clNew.insertCL = new ItemList[BackpackBase.MAX_TACTICAL_RIG_CELLS]; } else if (clNew.isPockets) { clNew.pocketSlots = idOrigin.PocketSlots; if (clNew.pocketSlots > 1) clNew.insertCL = new ItemList[clNew.pocketSlots]; else clNew.insertCL = new ItemList[BackpackBase.MAX_POCKETS_CELLS]; } if (idOrigin.WeaponPlayerRig) clNew.weaponPlayerRig = idOrigin.WeaponPlayerRig; if (idOrigin.itemModding) { clNew.vspItemModdingPrefab = idOrigin.itemModding; clNew.itemModding = GameObject.Instantiate(clNew.vspItemModdingPrefab); } else Debug.Log("id_Original.GetComponent().itemModding == null"); if (idOrigin.SpriteTextureItemInventory) clNew.spriteTextureItemInventory = idOrigin.SpriteTextureItemInventory; if (idOrigin.SpriteTextureItemModding) clNew.spriteTextureItemModding = idOrigin.SpriteTextureItemModding; clNew.isDefaultRenderParams = idOrigin.ByDefaultRenderParams; clNew.modelRenderPosition = idOrigin.WeaponPosition; clNew.modelRenderRotation = idOrigin.WeaponRotation; clNew.modelRenderScale = idOrigin.WeaponScale; return clNew; } #endregion #region Set, Get, Reset public static void ResetTransform(Transform itemTransform) { itemTransform.localScale = Vector3.one; itemTransform.localRotation = Quaternion.Euler(Vector3.zero); itemTransform.localPosition = Vector3.zero; } #endregion #region Inventory Slots public static bool IsHaveFreeSlotInInventory(ItemList cl) { if (cl == null) return false; bool isFoundFreeSlot = false; if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) isFoundFreeSlot = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(cl.indexPos60x60); if (!isFoundFreeSlot) { if (BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.tagSize) != -1) isFoundFreeSlot = true; if (StashSystem.instance && InventoryBase.instance.hideStash) isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(cl.indexPos60x60); } if (isFoundFreeSlot) return true; else return false; } // Return: // -1 - No place // 0 - Backpack / Backpack Window // 1 - TacticalRig / TacticalRig Window // 2 - Pockets / Pockets Window // 3 - Stash // IsEnemyBackpack - значит будем искать в инвентаре Енеми public static int GetFreeSlotIndexPlayerInventoryForSeparateAction(ItemList cl, bool storeMode = false, bool isEnemyBackpack = false, bool stashMode = false, bool isFromBackpackWindow = false, bool isFromTacticalRigPocketsWindow = false) { Vector2 indexPos60x60 = cl.indexPos60x60; if (cl.IsProbablyDifferentSeparateItem() && cl.separatePrefab != null) indexPos60x60 = cl.GetIndexPos60x60ByTag(cl.separatePrefab.GetComponent().SizeTag); bool isFoundFreeSlot = false; if (!isEnemyBackpack) // Player inventory { if (stashMode) { isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60); if (isFoundFreeSlot) return 3; else return -1; } else if (isFromBackpackWindow) { if (BackpackSystem.instance.m_vspBackpackWindow) { int vsp = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, 2, cl); if (vsp == 2 && cl.isResultCombine) // 2 - так как делим предмет на 2 части return 0; else if (vsp != 0 && !cl.isResultCombine) // 2 - так как делим предмет на 2 части return 0; } } else if (isFromTacticalRigPocketsWindow) { if (BackpackSystem.instance.m_vspBackpackWindow) { int IndexFreePlace = -1; if (cl.separatePrefab) IndexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().GetFreeSlotTacticRigPockets(cl.separatePrefab.GetComponent().SizeTag); else IndexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().GetBackpackInfo().GetFreeSlotTacticRigPockets(cl.tagSize); // Itself if (IndexFreePlace != -1) return IndexFreePlace; } } else { if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot { int vsp = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, 2, cl); if (vsp == 2 && cl.isResultCombine) // 2 - так как делим предмет на 2 части return 0; else if (vsp != 0 && !cl.isResultCombine) // 2 - так как делим предмет на 2 части return 0; else isFoundFreeSlot = false; } if (!isFoundFreeSlot) { int IndexFreePlace = 0; if (BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig || BackpackSystem.instance.GetBackpackInfo().isActivePockets) { if (cl.separatePrefab) IndexFreePlace = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.separatePrefab.GetComponent().SizeTag); else IndexFreePlace = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.tagSize); // Itself if (IndexFreePlace != -1) return IndexFreePlace; } } } } else // Enemy inventory { if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot { int vsp = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, 2, cl); if (vsp == 2 && cl.isResultCombine) // 2 - так как делим предмет на 2 части return 0; else if (vsp != 0 && !cl.isResultCombine) // 2 - так как делим предмет на 2 части return 0; else isFoundFreeSlot = false; } if (!isFoundFreeSlot) { int IndexFreePlace = 0; if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveTacticalRig || BackpackEnemyBase.instance.GetBackpackInfo().isActivePockets) { if (cl.separatePrefab) IndexFreePlace = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.separatePrefab.GetComponent().SizeTag); else IndexFreePlace = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.tagSize); // Itself if (IndexFreePlace != -1) return IndexFreePlace; } } } return -1; } public static int GetFreeSlotIndexPlayerInventory(Vector2 indexPos60x60, ItemList.SizeIconInventory tagSize, bool storeMode = false, bool isEnemyBackpack = false, bool isLootWindow = false) { bool isFoundFreeSlot = false; if (!isEnemyBackpack) { if (isLootWindow) // For loot window only one iteration { isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60); if (isFoundFreeSlot) return 3; return -1; } if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot { isFoundFreeSlot = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60); } if (isFoundFreeSlot) return 0; else { if (BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig || BackpackSystem.instance.GetBackpackInfo().isActivePockets) { int IndexFreePlace = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(tagSize); if (IndexFreePlace != -1) return IndexFreePlace; } else if (StashSystem.instance && InventoryBase.instance.hideStash && !storeMode) { isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60); if (isFoundFreeSlot) return 3; } } } else { if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot { isFoundFreeSlot = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60); } if (isFoundFreeSlot) return 0; else { if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveTacticalRig || BackpackEnemyBase.instance.GetBackpackInfo().isActivePockets) { int IndexFreePlace = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(tagSize); if (IndexFreePlace != -1) return IndexFreePlace; } } } return -1; } // Not used public static bool IsFreeSlotIndexForMoney(Vector2 indexPos60x60, ItemList.SizeIconInventory tagSize, int amountItems, bool storeMode = false) { int countFreeCells = 0; if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot countFreeCells = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, amountItems, null); if (countFreeCells == amountItems) return true; else { if (BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig || BackpackSystem.instance.GetBackpackInfo().isActivePockets) { countFreeCells += BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotTacticRigPocketsMassive(tagSize, amountItems); if (countFreeCells == amountItems) return true; } } return false; } #endregion #region Save public static void SaveWeapon(ItemList itemCL) { string filename = itemCL.id.ToString(); InventoryBase.instance.RenderRoot.GetComponentInChildren().SaveButtonParameters(filename); itemCL.itemModding.GetComponentInChildren().SaveParameters(filename, true); } #endregion #region Helper script public static bool AddAttachmentsToItem(GameObject[] weaponAttachments, ItemList weaponCL, Transform spawnPoint) { if (weaponAttachments != null && weaponAttachments.Length != 0) { // Для начала создадим в корне эти аттачи (чтобы не иметь дело с префабами) GameObject[] vspWeaponAttachments = new GameObject[weaponAttachments.Length]; weaponCL.insertCL = new ItemList[weaponAttachments.Length]; int i = 0; for (; i < weaponAttachments.Length; i++) { vspWeaponAttachments[i] = GameObject.Instantiate(weaponAttachments[i], spawnPoint); vspWeaponAttachments[i].SetActive(false); } // // // int count = 0; do { List attachments = new List(); i = 0; foreach (GameObject n in vspWeaponAttachments) { ItemList cl = new ItemList(); cl = SetParameters(cl, n, true); cl.itemModding.GetComponent().CL = cl; weaponCL.insertCL[i] = cl; if (AttachAttachmentToItemHelper(cl, weaponCL, true)) GameObject.Destroy(n); else { attachments.Add(n); // добавляем в список аттач, которому якобы не нашлось место if (cl.itemModding) GameObject.Destroy(cl.itemModding); } i++; } if (attachments.Count == 0) break; else { vspWeaponAttachments = null; vspWeaponAttachments = new GameObject[attachments.Count]; for (int j = 0; j < vspWeaponAttachments.Length; j++) vspWeaponAttachments[j] = attachments[j]; } count++; } while (count < 5); FindMagazineInTheWeapon(weaponCL); } return false; } public static bool AttachAttachmentToItemHelper(ItemList attachmentCL, ItemList itemCL, bool setActiveAttachment) { Component[] p = itemCL.itemModding.GetComponentsInChildren(typeof(Helpers), true); if (p != null) { foreach (Helpers n in p) { if (n.TagAttach == attachmentCL.tagAttach) { attachmentCL.SetItemModdingParameters(setActiveAttachment, n.transform); n.AddParametersToHelper(attachmentCL, n.GetOriginalAttachmentID()); n.openHelper = 1; return true; } } } return false; } public static void FindMagazineInTheWeapon(ItemList weaponCL) { Component[] p = weaponCL.itemModding.GetComponentsInChildren(typeof(AttachIdentity), true); if (p != null) { // turn flag weaponCL.isMagazineAttached = false; // Seraching the magazine foreach (AttachIdentity n in p) { // found if (n.CL.tagAttach == ItemList.TagAttchments.ATTACH_MAGAZINE) { weaponCL.isMagazineAttached = true; if (weaponCL.insertCL == null) weaponCL.insertCL = new ItemList[1]; weaponCL.insertCL[0] = n.CL; // Remember the data magazine (to have access to them) break; } } } } #endregion #region Icon item public static void SetItemComponentsParameters(GameObject item, ItemList cl) { item.GetComponent().TagItem = cl.tagItem; item.GetComponent().TagSize[0] = cl.tagSize; item.GetComponentInChildren().CL = cl; item.GetComponentInChildren().SetTextParameters(cl); } #endregion #region Image/Text Alpha public static void SetImageAlpha(Image icon, float alpha) { Color _a = icon.color; _a.a = alpha; icon.color = _a; } public static void SetTextAlpha(Text text, float alpha) { Color _a = text.color; _a.a = alpha; text.color = _a; } #endregion #region Get new Icon public static IEnumerator CreateNewIconInInventoryNextFrame(int returnIndex, ItemList returnCL, GameObject destroyOriginal, bool isEnemyBackpack, bool isCreateInBackpackWindow) { int index = returnIndex; ItemList cl = returnCL; GameObject originalItem = destroyOriginal; yield return new WaitForEndOfFrame(); if (isEnemyBackpack) { if (index == 0) { //BackpackEnemyBase.instance.OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren().CL.indexPos60x60, originalItem.GetComponent().transform.localPosition); BackpackEnemyBase.instance.CreateItemInBackpack(cl, BackpackEnemyBase.instance.rootBackpackIconsSpawn.transform); } else if (index == 1 || index == 2) { //BackpackEnemyBase.instance.OpenIndicesTacticalRigPockets(originalItem.GetComponentInChildren().CL); BackpackEnemyBase.instance.CreateItemInTacticalRigOrPockets(cl); } } else { if (index == 0) { if (isCreateInBackpackWindow) { BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren().CL.indexPos60x60, originalItem.GetComponent().transform.localPosition); BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().CreateItemInBackpack(cl, BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().rootIconsSpawn.transform); } else { //BackpackSystem.instance.OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren().CL.indexPos60x60, originalItem.GetComponent().transform.localPosition); BackpackSystem.instance.CreateItemInBackpack(cl, BackpackSystem.instance.rootIconItemsBackpackSpawn.transform); } } else if (index == 1 || index == 2) { if (isCreateInBackpackWindow) { //BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren().CL.indexPos60x60, originalItem.GetComponent().transform.localPosition); BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren().CreateItemInTacticalRigOrPockets(cl); } else { //BackpackSystem.instance.OpenIndicesTacticalRigPockets(originalItem.GetComponentInChildren().CL); BackpackSystem.instance.CreateItemInTacticalRigOrPockets(cl); } } else if (index == 3) { //StashSystem.instance.OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren().CL.indexPos60x60, originalItem.GetComponent().transform.localPosition); StashSystem.instance.CreateItemInStashNextFrame(cl); } } GameObject.Destroy(originalItem.GetComponentInChildren().CL.itemModding); GameObject.Destroy(originalItem); } #endregion #region Calculation // Возвращает коэффциент масштаба экрана в зависимости от области, в котороый мы работаем (инвентарь или юи) public static Vector2 CalculateScreenCoefficient() { Vector2 coeff; // First, we calculate the difference between the sizes of the canvas and the screen window if (InventoryBase.instance.isActive) { coeff.x = InventoryBase.instance.CanvasRoot.GetComponent().rect.width - Screen.width; coeff.y = InventoryBase.instance.CanvasRoot.GetComponent().rect.height - Screen.height; } else { coeff.x = UI.instance.GetComponent().rect.width - Screen.width; coeff.y = UI.instance.GetComponent().rect.height - Screen.height; } // Then we find what percentage is the screen window relative to the canvas coeff.x /= Screen.width; coeff.y /= Screen.height; return coeff; } #endregion #region Clamp public static void ClampWindowRE4Position(Vector2 windowPosition, Vector2 windowRoot) { // Top if (windowPosition.y >= InventoryBase.instance.CanvasRoot.GetComponent().rect.height - 10.0f) { BackpackSystem.instance.SetAmountCreatedWindows(0); return; } // Down if (windowPosition.y - windowRoot.y <= 0.0f) { BackpackSystem.instance.SetAmountCreatedWindows(0); return; } // Left if (windowPosition.x - windowRoot.x / 2.0f <= 0.0f) { BackpackSystem.instance.SetAmountCreatedWindows(0); return; } //Right if (windowPosition.x + windowRoot.x / 2.0f >= InventoryBase.instance.CanvasRoot.GetComponent().rect.width) { BackpackSystem.instance.SetAmountCreatedWindows(0); return; } } public static Quaternion ClampRotationAroundAxis(Quaternion q, Vector2 limitRotation, int axisIndex) { q.x /= q.w; q.y /= q.w; q.z /= q.w; q.w = 1.0f; float angle = 0f; if (axisIndex == 0) // X { angle = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x); angle = Mathf.Clamp(angle, limitRotation.x, limitRotation.y); q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angle); } else if (axisIndex == 1) // Y { angle = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.y); angle = Mathf.Clamp(angle, limitRotation.x, limitRotation.y); q.y = Mathf.Tan(0.5f * Mathf.Deg2Rad * angle); } else if (axisIndex == 2) // Z { angle = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.z); angle = Mathf.Clamp(angle, limitRotation.x, limitRotation.y); q.z = Mathf.Tan(0.5f * Mathf.Deg2Rad * angle); } return q; } #endregion #region Random public static float GetRandomIndex(Vector2 vector) { return Random.Range((int)vector.x, (int)vector.y); } public static int GetRandomIndex(int maxAmount) { return Random.Range(0, maxAmount); } #endregion #region Layer public static void SetItemLayerGroup(GameObject item, string layerGroupName) { Component[] p = item.GetComponentsInChildren(typeof(Transform), true); if (p != null) { foreach (Transform g in p) g.gameObject.layer = LayerMask.NameToLayer(layerGroupName); } } #endregion } [SerializeField] public class Scavenger { List vspDestroyObjects = new List(); // Сюда сохраняются все объекты, которые после закрытия инвентаря будут удалены GameObject[] vspInspectWindow; public Scavenger(int limitOfWindows) { vspInspectWindow = new GameObject[limitOfWindows]; } public void AddNewComponentToDestroyList(GameObject obj) { if (!vspDestroyObjects.Contains(obj)) vspDestroyObjects.Add(obj); } public void AddNewInspectWindowToDestroyList(int index, GameObject window) { vspInspectWindow[index] = window; } public GameObject GetInspectWindowByIndex(int index) { return vspInspectWindow[index]; } public void FreeObjects() { if (vspDestroyObjects != null) { for (int i = 0; i < vspDestroyObjects.Count; i++) { if (vspDestroyObjects[i]) { if (vspDestroyObjects[i].GetComponentInChildren()) vspDestroyObjects[i].GetComponentInChildren().CloseWindow(true); GameObject.Destroy(vspDestroyObjects[i]); } } } vspDestroyObjects.Clear(); for (int i = 0; i < vspInspectWindow.Length; i++) { if (vspInspectWindow[i] && vspInspectWindow[i].GetComponentInChildren()) vspInspectWindow[i].GetComponentInChildren().CloseWindow(true); vspInspectWindow[i] = null; } } } } }