using System; using System.IO; using UFS2.Gameplay; using UnityEngine; public class FishingLogs : MonoBehaviour { [Space(15f)] [SerializeField] public new bool enabled = true; [Space(5f)] [SerializeField] private string fileExtension = ".log"; [Space(5f)] [TextArea(50, 100)] public string Logs = ""; private static FishingLogs instance; public static FishingLogs Instance => instance; private void Awake() { UnityEngine.Object.DontDestroyOnLoad(this); if (instance == null) { instance = this; } else if (instance != this) { UnityEngine.Object.Destroy(base.gameObject); } } public void OnEnable() { if (enabled) { FRod.OnFishStrike = (Action)Delegate.Combine(FRod.OnFishStrike, new Action(AddFishStrikeLog)); FRod.OnEquipmentBreak = (Action)Delegate.Combine(FRod.OnEquipmentBreak, new Action(AddBreakEquipmentLog)); GameManager.OnCheckFishPersonalRecord = (Action)Delegate.Combine(GameManager.OnCheckFishPersonalRecord, new Action(AddNewPersonalRecordLog)); FRod.OnRodTakeOut = (Action)Delegate.Combine(FRod.OnRodTakeOut, new Action(AddChangeEquipmentLog)); FRod.OnLureCast = (Action)Delegate.Combine(FRod.OnLureCast, new Action(AddCastThrowLog)); } } public void OnDisable() { if (enabled) { FRod.OnFishStrike = (Action)Delegate.Remove(FRod.OnFishStrike, new Action(AddFishStrikeLog)); FRod.OnEquipmentBreak = (Action)Delegate.Remove(FRod.OnEquipmentBreak, new Action(AddBreakEquipmentLog)); GameManager.OnCheckFishPersonalRecord = (Action)Delegate.Remove(GameManager.OnCheckFishPersonalRecord, new Action(AddNewPersonalRecordLog)); FRod.OnRodTakeOut = (Action)Delegate.Remove(FRod.OnRodTakeOut, new Action(AddChangeEquipmentLog)); FRod.OnLureCast = (Action)Delegate.Remove(FRod.OnLureCast, new Action(AddCastThrowLog)); } } public void GetCurrentDrag(FReel reel) { Logs = Logs + "------- Player Reel Drag Information -------\r\n" + $"Current Reel Drag: {reel.reelingDrag * 100f} %\r\n" + "===============================================\r\n"; } public void AddChangeEquipmentLog(FRod rod) { string text = rod.name; float maxRodStrength = rod.maxRodStrength; string text2 = rod.currentReel.name; float maxReelStrength = rod.currentReel.maxReelStrength; string text3 = rod.currentLine.name; float strength = rod.currentLine.strength; Logs = Logs + "------- Current Player Equipment Details -------\r\nRod: " + text + "\r\n" + $" - Durability: {maxRodStrength} KG\r\n" + "Reel: " + text2 + "\r\n" + $" - Durability: {maxReelStrength} KG\r\n" + "Fishing Line: " + text3 + "\r\n" + $" - Durability: {strength} KG\r\n" + "===============================================\r\n"; SaveFile(); } public void AddCastThrowLog(FRod.LureCastArgs lure) { Logs = Logs + "------- Lure Casting Location -------\r\nMap: " + lure.mapName + "\r\nLocation (Coordinates): x:" + lure.playerPosition.x.ToString("F0") + " y:" + lure.playerPosition.y.ToString("F0") + " z: " + lure.playerPosition.z.ToString("F0") + "\r\nCast Location (Coordinates): x:" + lure.LurePosition.x.ToString("F0") + " y:" + lure.LurePosition.y.ToString("F0") + " z: " + lure.LurePosition.z.ToString("F0") + "\r\n===============================================\r\n"; SaveFile(); } public void AddBreakEquipmentLog(FRod rod) { string text = ((FishEntity.CurrentFishInFight != null) ? FishEntity.CurrentFishInFight.Data.Species.ToString() : "null fish"); float num = ((FishEntity.CurrentFishInFight != null) ? FishEntity.CurrentFishInFight.Data.Weight : 0f); Logs = Logs + "------- Equipment Break Information -------\r\nFish that broke equipment: \r\n - Name: " + text + "\r\n - Weight: " + num.ToString("F2") + " KG\r\n" + $"Reel ID: {Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[rod.indexOfslot].reel.ID}\r\n" + $" - Current Reel Drag Ratio: {rod.currentReel.reelingDrag * 100f} %\r\n" + $" - Durability in KG: {rod.currentReel.maxReelStrength}\r\n" + " - Is broken: " + rod.currentReel.isDamaged.ToString().ToUpper() + "\r\n" + $"Rod ID: {Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[rod.indexOfslot].rod.ID}\r\n" + $" - Durability in KG: {rod.maxRodStrength}\r\n" + " - Is broken: " + rod.isDamaged.ToString().ToUpper() + "\r\n" + $"Fishing Line ID: {Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[rod.indexOfslot].line.ID}\r\n" + $" - Durability in KG: {rod.currentLine.strength}\r\n" + "===============================================\r\n"; SaveFile(); } public void AddChangeWeatherLog(LocationMap locationMap) { Logs = Logs + "------- Current Time & Weather -------\r\n" + $"Map time: {(TimeOfDay)locationMap.TimeOfDayDropDown.value}\r\n" + $"Map weahter: {(Weather)locationMap.WeatherDropDown.value}\r\n" + "===============================================\r\n"; SaveFile(); } public void AddFishStrikeLog(FRod rod) { string text = ((!(rod.currentLure == null)) ? rod.currentLure.gameID.ToString() : "None"); string text2 = ((!(rod.currentHook == null)) ? rod.currentHook.gameID.ToString() : "None"); string text3 = ((!(rod.currentBait == null)) ? rod.currentBait.gameID.ToString() : "None"); Logs = Logs + "------- Fish Strike Information -------\r\n" + $"Fish Name: {rod.currentFish.fishSpecies}\r\n" + "Fish Weight: " + rod.currentFish.fishWeight.ToString("F2") + " KG\r\nLure Type: " + text + "\r\nHook Size: " + text2 + "\r\nBait Type: " + text3 + "\r\n===============================================\r\n"; SaveFile(); } public void AddNewPersonalRecordLog(GameManager.PersonalRecordArgs personalRecord) { Logs = Logs + "------- Personal Best Information -------\r\n" + $"Specimen: {personalRecord.fishSpecies}\r\n" + "Current Biggest Caught: " + personalRecord.biggestFishWeight.ToString("F2") + " KG\r\nCurrent Catch Weight: " + personalRecord.currentFishWeight.ToString("F2") + " KG\r\n===============================================\r\n"; SaveFile(); } private void Start() { if (enabled) { Logs += "====== GAME FISHING LOG FILE ======\r\n"; } } public void OnDestroy() { if (enabled) { Logs += "====== END OF LOG ENTRY ======"; SaveFile(); } } private void SaveFile() { string path = Application.persistentDataPath + "/catch" + fileExtension; if (File.Exists(path)) { File.Delete(path); } StreamWriter streamWriter = File.CreateText(path); streamWriter.WriteLine(Logs); streamWriter.Close(); } }