using System; using System.Collections; using UnityEngine; public class InventoryManager : MonoBehaviour { private static float lastInventoryChangeTime; private FPlayer playerMain; private int currentShowSlotIndex = -1; [HideInInspector] public int nextShowSlotIndex = -1; public bool reAssignRod; public int assignAccesoryId = -1; public int assignAccesoryUniqueID = -1; public GameObject currentAccesory; public static bool IsInventoryChanging => Time.time - lastInventoryChangeTime < 2f; public static event Action OnRodInHandChange; private void Start() { playerMain = FScriptsHandler.Instance.m_PlayerMain; if ((bool)playerMain) { GameObject.Find("MasterAudio").transform.position = FScriptsHandler.Instance.PlayerTransformPoint.position; } } private void Update() { if (!playerMain) { playerMain = FScriptsHandler.Instance.m_PlayerMain; return; } if (playerMain != FScriptsHandler.Instance.m_PlayerMain) { playerMain = FScriptsHandler.Instance.m_PlayerMain; } if (InputManager.isShowSlot0) { if ((bool)playerMain.currentRod && playerMain.currentRod.CheckIsInUse()) { return; } nextShowSlotIndex = 0; } if (InputManager.isShowSlot1) { if ((bool)playerMain.currentRod && playerMain.currentRod.CheckIsInUse()) { return; } nextShowSlotIndex = 1; } if (InputManager.isShowSlot2) { if ((bool)playerMain.currentRod && playerMain.currentRod.CheckIsInUse()) { return; } nextShowSlotIndex = 2; } if (InputManager.isShowSlot3) { if ((bool)playerMain.currentRod && playerMain.currentRod.CheckIsInUse()) { return; } nextShowSlotIndex = 3; } if (InputManager.isShowSlot4) { if ((bool)playerMain.currentRod && playerMain.currentRod.CheckIsInUse()) { return; } nextShowSlotIndex = 4; } if (RodSupport.IsRodSupportChanging || BoatRodSupport.IsBoatRodSupportChanging) { nextShowSlotIndex = -1; return; } if (nextShowSlotIndex >= 0 && (bool)Singleton.Instance && (bool)Singleton.Instance.currentPlayerCharacter && Singleton.Instance.currentSitPointIndex == 1) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("ROD_BLOCK_DURING_BOAT_STEERING"), FScriptsHandler.Instance.m_Canvas.transform); nextShowSlotIndex = -1; return; } if (reAssignRod && currentShowSlotIndex > -1) { reAssignRod = false; StartCoroutine(ReAssignRod()); } if (nextShowSlotIndex != -1) { int num = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[nextShowSlotIndex].CheckSlotAndRod(); if (num != -1) { Debug.Log("statusId: " + num); if (num == 2) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_EMPTY"), FScriptsHandler.Instance.m_Canvas.transform); } if (num == 0 || num == 1) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_DAMAGED"), FScriptsHandler.Instance.m_Canvas.transform); } nextShowSlotIndex = -1; return; } if (GameManager.Instance.currentSceneLoadedType == GameManager.SceneLoadedType.Tournament && TournamentManager.Instance.currentPlayTournament.tournamentType == TournamentManager.TournamentContentType.Players) { GameManager.PlayerData.CSlots cSlots = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[nextShowSlotIndex]; Array values = Enum.GetValues(typeof(GameManager.ItemType)); Vector2 levelRange = TournamentManager.Instance.currentPlayTournament.levelRange; foreach (GameManager.ItemType item in values) { int equipmentLevel = cSlots.GetEquipmentLevel(item); if (equipmentLevel != -1 && ((float)equipmentLevel < levelRange.x || (float)equipmentLevel > levelRange.y)) { string text = LanguageManager.Instance.GetText(item.ToString().ToUpper()); text = ((!((float)equipmentLevel < levelRange.x)) ? (LanguageManager.Instance.GetText("EQUIPMENT_LEVEL_TOO_HIGH") + " - " + text) : (LanguageManager.Instance.GetText("EQUIPMENT_LEVEL_TOO_LOW") + " - " + text)); GameManager.Instance.ShowMessagePopup(text, FScriptsHandler.Instance.m_Canvas.transform); nextShowSlotIndex = -1; return; } } } if (currentShowSlotIndex == nextShowSlotIndex) { HideRod(); nextShowSlotIndex = -1; } else if (currentShowSlotIndex != -1) { HideRod(); } else { GetRodInHand(nextShowSlotIndex); } } if (assignAccesoryId > -1) { ShowAccesoriesOnScene(assignAccesoryId, assignAccesoryUniqueID); } } private void OnEnable() { OnRodInHandChange += InventoryManager_OnRodInHandChange; } private void OnDisable() { OnRodInHandChange -= InventoryManager_OnRodInHandChange; } private void OnDestroy() { for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip.Count; i++) { Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[i].rod.status = GameManager.PlayerData.CRods.Status.InEquip; } InputManager.isCastFar = false; InputManager.isCastNear = false; UnUseAccesories(); } private void InventoryManager_OnRodInHandChange(FRod rod) { lastInventoryChangeTime = Time.time; } private void ShowAccesoriesOnScene(int gameAccesoryID, int assignAccesoryUniqueID) { if ((bool)playerMain.currentRod) { return; } int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Accesories, gameAccesoryID); if (GameManager.Instance.gameAccesories[indexByItemId].type == GameManager.GameAccesories.Type.RodSupport) { if ((bool)currentAccesory) { currentAccesory.GetComponent().DestroySupport(); } currentAccesory = UnityEngine.Object.Instantiate(GameManager.Instance.gameAccesories[indexByItemId].GetModelPrefab()); currentAccesory.GetComponent().indexId = GameManager.Instance._playerData.GetPlayerItemIndexByUniqueId(GameManager.ItemType.Accesories, assignAccesoryUniqueID); } assignAccesoryId = -1; } private void UnUseAccesories() { for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerAccessories.Count; i++) { Singleton.Instance.GetCurrentPlayerData().PlayerAccessories[i].isUse = false; Singleton.Instance.GetCurrentPlayerData().PlayerAccessories[i].signalizerSlotUniqid_1 = -1; Singleton.Instance.GetCurrentPlayerData().PlayerAccessories[i].signalizerSlotUniqid_2 = -1; Singleton.Instance.GetCurrentPlayerData().PlayerAccessories[i].signalizerSlotUniqid_3 = -1; } } private IEnumerator ReAssignRod() { playerMain.FullBodyAvatar.HideRod(); InventoryManager.OnRodInHandChange?.Invoke(null); yield return new WaitForSeconds(1.5f); if (Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].status == GameManager.PlayerData.CSlots.Status.Completed) { GetRodInHand(currentShowSlotIndex); } else { currentShowSlotIndex = -1; } Debug.Log("Reassign rod"); } private void GetRodInHand(int slot_id) { if (playerMain.currentRod != null) { Debug.Log("rod error"); currentShowSlotIndex = -1; nextShowSlotIndex = slot_id; return; } currentShowSlotIndex = slot_id; nextShowSlotIndex = -1; if (CreateRodInHand()) { InventoryManager.OnRodInHandChange?.Invoke(playerMain.assignRod); } else { currentShowSlotIndex = -1; } } private bool CreateRodInHand() { Debug.Log("CreateRodInHand index:" + currentShowSlotIndex); if (currentShowSlotIndex == -1) { return false; } GameObject prefabModel = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Rod); if (prefabModel == null) { return false; } FRod component = UnityEngine.Object.Instantiate(prefabModel, playerMain.FullBodyAvatar.RodJoiner.position, playerMain.FullBodyAvatar.RodJoiner.rotation, base.transform).GetComponent(); if ((bool)component) { playerMain.assignRod = component; playerMain.FullBodyAvatar.ShowRod(); component.indexOfslot = currentShowSlotIndex; int gameItemIndexByItemId = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Rod, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].rod.ID); component.maxRodStrength = GameManager.Instance.gameRods[gameItemIndexByItemId].strength; component.action = GameManager.Instance.gameRods[gameItemIndexByItemId].action; component.throwForceMaxPower = GameManager.Instance.gameRods[gameItemIndexByItemId].maxRange; component.throwForceMaxNearPower = (float)GameManager.Instance.gameRods[gameItemIndexByItemId].maxRange * 0.7f; switch (Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].method) { case GameManager.PlayerData.CSlots.Method.Float: component.rodType = FRod.RodType.Float; break; case GameManager.PlayerData.CSlots.Method.Spinning: component.rodType = FRod.RodType.Spinning; break; case GameManager.PlayerData.CSlots.Method.Feeder: component.rodType = FRod.RodType.Feeder; break; } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.isNull) { FReel component2 = UnityEngine.Object.Instantiate(Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Reel), component.reelContainer.position, component.reelContainer.rotation, base.transform).GetComponent(); int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Reel, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.ID); component2.maxReelStrength = GameManager.Instance.gameReels[indexByItemId].strength; component2.reelingSpeed = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.currentSpeed; component2.reelingDrag = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.currentDrag; component.assignReel = component2; Debug.Log("Create reel index:" + indexByItemId); } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.isNull) { GameObject prefabModel2 = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Float); if (UnityEngine.Object.Instantiate(prefabModel2, base.transform).TryGetComponent(out var component3)) { int indexByItemId2 = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Float, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.ID); component3.floatDisplacement = GameManager.Instance.gameFloats[indexByItemId2].displacement; if ((double)Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.lastSetGroundValue > 0.2) { component3.newDeepth = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.lastSetGroundValue; } component.assignFloat = component3; Debug.Log("Create float " + prefabModel2.name); } } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].feeder.isNull) { FFeeder component4 = UnityEngine.Object.Instantiate(Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Feeder), base.transform).GetComponent(); component.assignFeeder = component4; Debug.Log("Create feeder"); } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].hook.isNull) { FHook component5 = UnityEngine.Object.Instantiate(Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Hook), base.transform).GetComponent(); component5.gameID = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].hook.ID; component.assignHook = component5; Debug.Log("Create hook"); } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].bait.isNull) { GameObject obj = UnityEngine.Object.Instantiate(Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Bait), base.transform); int iD = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].bait.ID; if (obj.TryGetComponent(out var component6)) { component6.gameID = iD; component.assignLure = component6; } if (obj.TryGetComponent(out var component7)) { component7.gameID = iD; component.assignBait = component7; } Debug.Log("Create bait"); } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].line.isNull) { GameObject obj2 = UnityEngine.Object.Instantiate(Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Line), component.transform); obj2.transform.position = Vector3.zero; if (obj2.TryGetComponent(out var component8)) { int gameItemIndexByItemId2 = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Line, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].line.ID); component8.strength = GameManager.Instance.gameLines[gameItemIndexByItemId2].strength; component.assignLine = component8; Debug.Log("Create line"); } } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].weight.isNull) { FWeight component9 = UnityEngine.Object.Instantiate(Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Weight), base.transform).GetComponent(); int indexByItemId3 = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Weight, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].weight.ID); component9.weight = GameManager.Instance.gameWeights[indexByItemId3].weight; component.assignWeight = component9; Debug.Log("Create weight"); } return true; } return false; } public FRod DropRod(Transform newParent) { if (playerMain.currentRod == null) { return null; } Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].rod.status = GameManager.PlayerData.CRods.Status.InOut; playerMain.currentRod.transform.SetParent(newParent); playerMain.currentRod.transform.localPosition = Vector3.zero; playerMain.currentRod.transform.localEulerAngles = Vector3.zero; currentShowSlotIndex = -1; FRod currentRod = playerMain.currentRod; playerMain.currentRod.currentPlayer = null; playerMain.currentRod = null; Debug.Log("Drop Rod on " + newParent.name); Action onRodInHandChange = InventoryManager.OnRodInHandChange; if (onRodInHandChange != null) { onRodInHandChange(null); return currentRod; } return currentRod; } public void GetRodToHand(FRod newRod) { if (!(playerMain.currentRod != null)) { playerMain.assignRod = newRod; currentShowSlotIndex = newRod.indexOfslot; Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].rod.status = GameManager.PlayerData.CRods.Status.InHand; InventoryManager.OnRodInHandChange?.Invoke(playerMain.assignRod); } } public void HideRod() { if (!(playerMain.currentRod == null) && !(playerMain.currentRod.fishingLine == null) && !(playerMain.currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 0f) && !playerMain.firstPersonController.frezzeRotation) { Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].rod.status = GameManager.PlayerData.CRods.Status.InEquip; playerMain.FullBodyAvatar.HideRod(); currentShowSlotIndex = -1; InventoryManager.OnRodInHandChange?.Invoke(null); Debug.Log("Hide Rod"); } } public void SetIndexSlotOfRod(int slot_id) { currentShowSlotIndex = slot_id; } public void CutItems() { Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].SubLastLeaderItemsByCut(); } }