423 lines
17 KiB
C#
423 lines
17 KiB
C#
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<FRod> 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<Boat>.Instance && (bool)Singleton<Boat>.Instance.currentPlayerCharacter && Singleton<Boat>.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<SaveDataManager>.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<SaveDataManager>.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<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip.Count; i++)
|
|
{
|
|
Singleton<SaveDataManager>.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<RodSupport>().DestroySupport();
|
|
}
|
|
currentAccesory = UnityEngine.Object.Instantiate(GameManager.Instance.gameAccesories[indexByItemId].GetModelPrefab());
|
|
currentAccesory.GetComponent<RodSupport>().indexId = GameManager.Instance._playerData.GetPlayerItemIndexByUniqueId(GameManager.ItemType.Accesories, assignAccesoryUniqueID);
|
|
}
|
|
assignAccesoryId = -1;
|
|
}
|
|
|
|
private void UnUseAccesories()
|
|
{
|
|
for (int i = 0; i < Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerAccessories.Count; i++)
|
|
{
|
|
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerAccessories[i].isUse = false;
|
|
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerAccessories[i].signalizerSlotUniqid_1 = -1;
|
|
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerAccessories[i].signalizerSlotUniqid_2 = -1;
|
|
Singleton<SaveDataManager>.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<SaveDataManager>.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<SaveDataManager>.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<FRod>();
|
|
if ((bool)component)
|
|
{
|
|
playerMain.assignRod = component;
|
|
playerMain.FullBodyAvatar.ShowRod();
|
|
component.indexOfslot = currentShowSlotIndex;
|
|
int gameItemIndexByItemId = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Rod, Singleton<SaveDataManager>.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<SaveDataManager>.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<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.isNull)
|
|
{
|
|
FReel component2 = UnityEngine.Object.Instantiate(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Reel), component.reelContainer.position, component.reelContainer.rotation, base.transform).GetComponent<FReel>();
|
|
int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Reel, Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.ID);
|
|
component2.maxReelStrength = GameManager.Instance.gameReels[indexByItemId].strength;
|
|
component2.reelingSpeed = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.currentSpeed;
|
|
component2.reelingDrag = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].reel.currentDrag;
|
|
component.assignReel = component2;
|
|
Debug.Log("Create reel index:" + indexByItemId);
|
|
}
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.isNull)
|
|
{
|
|
GameObject prefabModel2 = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Float);
|
|
if (UnityEngine.Object.Instantiate(prefabModel2, base.transform).TryGetComponent<FFloat>(out var component3))
|
|
{
|
|
int indexByItemId2 = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Float, Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.ID);
|
|
component3.floatDisplacement = GameManager.Instance.gameFloats[indexByItemId2].displacement;
|
|
if ((double)Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.lastSetGroundValue > 0.2)
|
|
{
|
|
component3.newDeepth = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].ffloat.lastSetGroundValue;
|
|
}
|
|
component.assignFloat = component3;
|
|
Debug.Log("Create float " + prefabModel2.name);
|
|
}
|
|
}
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].feeder.isNull)
|
|
{
|
|
FFeeder component4 = UnityEngine.Object.Instantiate(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Feeder), base.transform).GetComponent<FFeeder>();
|
|
component.assignFeeder = component4;
|
|
Debug.Log("Create feeder");
|
|
}
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].hook.isNull)
|
|
{
|
|
FHook component5 = UnityEngine.Object.Instantiate(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Hook), base.transform).GetComponent<FHook>();
|
|
component5.gameID = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].hook.ID;
|
|
component.assignHook = component5;
|
|
Debug.Log("Create hook");
|
|
}
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].bait.isNull)
|
|
{
|
|
GameObject obj = UnityEngine.Object.Instantiate(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Bait), base.transform);
|
|
int iD = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].bait.ID;
|
|
if (obj.TryGetComponent<FLure>(out var component6))
|
|
{
|
|
component6.gameID = iD;
|
|
component.assignLure = component6;
|
|
}
|
|
if (obj.TryGetComponent<FBait>(out var component7))
|
|
{
|
|
component7.gameID = iD;
|
|
component.assignBait = component7;
|
|
}
|
|
Debug.Log("Create bait");
|
|
}
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].line.isNull)
|
|
{
|
|
GameObject obj2 = UnityEngine.Object.Instantiate(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Line), component.transform);
|
|
obj2.transform.position = Vector3.zero;
|
|
if (obj2.TryGetComponent<FLine>(out var component8))
|
|
{
|
|
int gameItemIndexByItemId2 = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Line, Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].line.ID);
|
|
component8.strength = GameManager.Instance.gameLines[gameItemIndexByItemId2].strength;
|
|
component.assignLine = component8;
|
|
Debug.Log("Create line");
|
|
}
|
|
}
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].weight.isNull)
|
|
{
|
|
FWeight component9 = UnityEngine.Object.Instantiate(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].GetPrefabModel(GameManager.ItemType.Weight), base.transform).GetComponent<FWeight>();
|
|
int indexByItemId3 = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Weight, Singleton<SaveDataManager>.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<SaveDataManager>.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<FRod> 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<SaveDataManager>.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<SaveDataManager>.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<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentShowSlotIndex].SubLastLeaderItemsByCut();
|
|
}
|
|
}
|