216 lines
10 KiB
C#
216 lines
10 KiB
C#
|
//********************************************************//
|
|||
|
// //
|
|||
|
// Copyright © All rights reserved. MyNameIsVoo. 2020. //
|
|||
|
// //
|
|||
|
// REPRODUCTION FORBIDEN //
|
|||
|
// //
|
|||
|
//********************************************************//
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
using ItemsClassList;
|
|||
|
using ICWM.ItemSystem;
|
|||
|
|
|||
|
namespace ICWM
|
|||
|
{
|
|||
|
namespace HelperSystem
|
|||
|
{
|
|||
|
public class StartStuff : MonoBehaviour
|
|||
|
{
|
|||
|
#region Attributes
|
|||
|
|
|||
|
[Header("ATTRIBUTES")]
|
|||
|
[Space(5)]
|
|||
|
[SerializeField] private GameObject m_SpawnPointItems;
|
|||
|
|
|||
|
[Header("PLAYER ITEMS")]
|
|||
|
[Space(5)]
|
|||
|
[SerializeField] private GameObject[] m_PlayerItems;
|
|||
|
|
|||
|
[Header("ITEMS")]
|
|||
|
[Space(5)]
|
|||
|
[SerializeField] private GameObject[] m_Items;
|
|||
|
|
|||
|
private List<GameObject> playerItems;
|
|||
|
private bool isStop = false;
|
|||
|
private bool isCreatedItems = false;
|
|||
|
private float deltaTime = 0.0f;
|
|||
|
private int count = 0;
|
|||
|
|
|||
|
const float waitSeconds = 0.15f;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
playerItems = new List<GameObject>();
|
|||
|
|
|||
|
for (int i = 0; i < m_PlayerItems.Length; i++)
|
|||
|
playerItems.Add(CreateItem(m_PlayerItems[i]));
|
|||
|
|
|||
|
for (int i = 0; i < m_Items.Length; i++)
|
|||
|
playerItems.Add(CreateItem(m_Items[i]));
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (!isCreatedItems)
|
|||
|
{
|
|||
|
// We need to create ClassList and then deactivate items (unhide)
|
|||
|
if (deltaTime >= 4f * waitSeconds) // Wait
|
|||
|
{
|
|||
|
isCreatedItems = true;
|
|||
|
deltaTime = 0.0f;
|
|||
|
}
|
|||
|
}
|
|||
|
else // Then we transfer to Inventory
|
|||
|
{
|
|||
|
if (deltaTime >= waitSeconds && !isStop)
|
|||
|
{
|
|||
|
if (count < playerItems.Count)
|
|||
|
{
|
|||
|
deltaTime = 0.0f;
|
|||
|
playerItems[count].GetComponent<ItemsDrop>().CL.destroyItemDrop = playerItems[count];
|
|||
|
if (count < m_PlayerItems.Length)
|
|||
|
TransferItemToPlayerSlots(playerItems[count].GetComponent<ItemsDrop>().CL, playerItems[count]);
|
|||
|
else
|
|||
|
TransferItemToPlayerBackpack(playerItems[count].GetComponent<ItemsDrop>().CL, playerItems[count]);
|
|||
|
++count;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
isStop = true;
|
|||
|
deltaTime = 0.0f;
|
|||
|
count = 0;
|
|||
|
playerItems = null;
|
|||
|
this.enabled = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
deltaTime += Time.deltaTime;
|
|||
|
}
|
|||
|
|
|||
|
#region PRIVATE
|
|||
|
|
|||
|
private void TransferItemToPlayerSlots(ItemList itemCL, GameObject item)
|
|||
|
{
|
|||
|
if (!itemCL.IsBackpackItemSlot() && BackpackSystem.instance.RE4O_IsActive())
|
|||
|
return;
|
|||
|
|
|||
|
if (itemCL.tagItem == ItemList.TagItems.WEAPON)
|
|||
|
{
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnSling && InventoryBase.instance.selectWeapon.OnSling.transform.childCount == 0)
|
|||
|
{
|
|||
|
PlayerSystem.instance.isActiveSpawnOnSling = true;
|
|||
|
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnHolster && !InventoryBase.instance.selectWeapon.IsActiveOnBack && !InventoryBase.instance.selectWeapon.IsActiveOnScabbard) // Если у нас нет оружия, то берем его в руки
|
|||
|
PlayerSystem.instance.takeWeapon = true;
|
|||
|
|
|||
|
PlayerSystem.instance.CreateWeaponSlots(itemCL, null);
|
|||
|
}
|
|||
|
else if (!InventoryBase.instance.selectWeapon.IsActiveOnBack && InventoryBase.instance.selectWeapon.OnBack.transform.childCount == 0)
|
|||
|
{
|
|||
|
PlayerSystem.instance.isActiveSpawnOnBack = true;
|
|||
|
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnHolster && !InventoryBase.instance.selectWeapon.IsActiveOnSling && !InventoryBase.instance.selectWeapon.IsActiveOnScabbard) // Если у нас нет оружия, то берем его в руки
|
|||
|
PlayerSystem.instance.takeWeapon = true;
|
|||
|
|
|||
|
PlayerSystem.instance.CreateWeaponSlots(itemCL, null);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (itemCL.tagItem == ItemList.TagItems.PISTOL)
|
|||
|
{
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnHolster && InventoryBase.instance.selectWeapon.Holster.transform.childCount == 0)
|
|||
|
{
|
|||
|
PlayerSystem.instance.isActiveSpawnOnHolster = true;
|
|||
|
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnSling && !InventoryBase.instance.selectWeapon.IsActiveOnBack && !InventoryBase.instance.selectWeapon.IsActiveOnScabbard) // Если у нас нет оружия, то берем его в руки
|
|||
|
PlayerSystem.instance.takeWeapon = true;
|
|||
|
|
|||
|
PlayerSystem.instance.CreateWeaponSlots(itemCL, null);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (itemCL.tagItem == ItemList.TagItems.KNIFE)
|
|||
|
{
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnScabbard && InventoryBase.instance.selectWeapon.Scabbard.transform.childCount == 0)
|
|||
|
{
|
|||
|
PlayerSystem.instance.isActiveSpawnOnScabbard = true;
|
|||
|
|
|||
|
if (!InventoryBase.instance.selectWeapon.IsActiveOnSling && !InventoryBase.instance.selectWeapon.IsActiveOnBack && !InventoryBase.instance.selectWeapon.IsActiveOnHolster) // Если у нас нет оружия, то берем его в руки
|
|||
|
PlayerSystem.instance.takeWeapon = true;
|
|||
|
|
|||
|
PlayerSystem.instance.CreateWeaponSlots(itemCL, null);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (itemCL.tagItem == ItemList.TagItems.BODYHEADSET && !PlayerSystem.instance.isActiveHeadset)
|
|||
|
PlayerSystem.instance.SpawnBodyItems(itemCL);
|
|||
|
else if (itemCL.tagItem == ItemList.TagItems.BODYGOGGLES && !PlayerSystem.instance.isActiveGoggles)
|
|||
|
PlayerSystem.instance.SpawnBodyItems(itemCL);
|
|||
|
else if (itemCL.tagItem == ItemList.TagItems.BODYHELMET && !PlayerSystem.instance.isActiveHelmet)
|
|||
|
PlayerSystem.instance.SpawnBodyItems(itemCL);
|
|||
|
else if (itemCL.tagItem == ItemList.TagItems.BODYARMOR && !PlayerSystem.instance.isActiveBodyArmor)
|
|||
|
PlayerSystem.instance.SpawnBodyItems(itemCL);
|
|||
|
else if ((itemCL.tagItem == ClassList.TagItems.BODYPOCKETS && !BackpackSystem.instance.GetBackpackInfo().isActivePockets)
|
|||
|
|| (itemCL.tagItem == ClassList.TagItems.BODYTACTICALRIG && !BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig)
|
|||
|
|| (itemCL.tagItem == ClassList.TagItems.BODYBACKPACK && !BackpackSystem.instance.GetBackpackInfo().isActiveBackpack))
|
|||
|
{
|
|||
|
BackpackSystem.instance.SpawnBodySet(itemCL);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (item && InventoryBase.instance.m_Hotbar.isActiveHotbar)
|
|||
|
InventoryBase.instance.m_Hotbar.UpdateHotbarSlots(item.GetComponent<ItemsDrop>().CL);
|
|||
|
}
|
|||
|
|
|||
|
private void TransferItemToPlayerBackpack(ItemList itemCL, GameObject item)
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(itemCL.tagSize) != -1)
|
|||
|
{
|
|||
|
BackpackSystem.instance.CreateItemInTacticalRigOrPockets(itemCL);
|
|||
|
UpdatePlayerStatistics(itemCL);
|
|||
|
}
|
|||
|
else if (BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(itemCL.indexPos60x60))
|
|||
|
{
|
|||
|
BackpackSystem.instance.CreateItemInBackpack(itemCL, BackpackSystem.instance.rootIconItemsBackpackSpawn.transform);
|
|||
|
UpdatePlayerStatistics(itemCL);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void UpdatePlayerStatistics(ItemList itemCL)
|
|||
|
{
|
|||
|
if (itemCL.isBullet)
|
|||
|
{
|
|||
|
InventoryBase.instance.RE4_amountOfBullet += itemCL.amountBullet;
|
|||
|
}
|
|||
|
else if (itemCL.isLatchkey)
|
|||
|
{
|
|||
|
InventoryBase.instance.PlayerStatistics.AmountMultools += itemCL.amountStack;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private GameObject CreateItem(GameObject originalItem)
|
|||
|
{
|
|||
|
GameObject playerItem;
|
|||
|
playerItem = Instantiate(originalItem, m_SpawnPointItems.transform);
|
|||
|
playerItem.transform.localScale = Vector3.one;
|
|||
|
playerItem.transform.localPosition = m_SpawnPointItems.transform.localPosition;
|
|||
|
playerItem.SetActive(true);
|
|||
|
|
|||
|
playerItem.GetComponent<ItemsDrop>().CL = Helper.SetParameters(playerItem.GetComponent<ItemsDrop>().CL, playerItem);
|
|||
|
playerItem.GetComponent<ItemsDrop>().CL.SetItemModdingParameters(false, playerItem.transform);
|
|||
|
|
|||
|
if (playerItem.GetComponent<ItemsDrop>().CL.IsRenderItem() && playerItem.GetComponent<ItemsDrop>().WithAttachments)
|
|||
|
Helper.AddAttachmentsToItem(playerItem.GetComponent<ItemsDrop>().WeaponAttachments, playerItem.GetComponent<ItemsDrop>().CL, transform);
|
|||
|
|
|||
|
return playerItem;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
}
|