using System; using System.Linq; using System.Threading.Tasks; public class ControlSlice { public bool isActiveAndEnabled=true; public int Continues,LegacyCalls; public FishingData fishingData=new(); public Tables _tables=new(); public game.PlayerDataStorage.PlayerKVGameplayLoop.FishingAction kvFishingAction=new(); public void Run()=>ConsumeBait(); public Task RunAwaited()=>ConsumeBaitOnKVAsync(); void WaitForFishBiteED()=>Continues++; void DoConsumeBait()=>LegacyCalls++; bool KVFishingCurrent() { if(!game.PlayerDataStorage.PlayerKVGameplayLoop.Enabled) return true; return this!=null && isActiveAndEnabled && game.PlayerDataStorage.PlayerKVGameplayLoop.FishingCurrent(kvFishingAction); } async Task ConsumeBaitOnKVAsync() { try { if(!KVFishingCurrent()) return; if(!game.PlayerDataStorage.PlayerKVGameplayLoop.ClaimFishingConsumption(kvFishingAction)) return; if(fishingData.fishItem==null || !fishingData.IsGeneralFish() || fishingData.IsFree || fishingData.IsRetry || fishingData.IsDuel || fishingData.IsPackItemFish() || fishingData.curFishData==null) throw game.PlayerDataStorage.PlayerKVGameplayLoop.Stop("Only one ordinary paid fishing action is permitted."); if(Application.internetReachability==NetworkReachability.NotReachable) throw game.PlayerDataStorage.PlayerKVGameplayLoop.Stop("Fishing stopped before consumption: offline."); if(_tables.TbFishingEvent.DataList.Any(e=>e.ConditionList.Any(c=>c.Condition==ConditionType.ConsumeEnergy))) throw game.PlayerDataStorage.PlayerKVGameplayLoop.Stop("ConsumeEnergy activity activation requires separate review."); var player=GContext.container.Resolve(); int mag=player.magnification; if(mag<0 || mag>=_tables.TbEnergyDef.DataList.Count) throw game.PlayerDataStorage.PlayerKVGameplayLoop.Stop("Invalid fishing magnification."); int fish=fishingData.curFishData.ID, rod=fishingData.RodId, map=player.lastMapId; int cost=_tables.TbEnergyDef.DataList[mag].Mag; await player.ConsumeEnergyForKVLoopAsync(cost,kvFishingAction); if(!KVFishingCurrent()) return; if(fishingData.curFishData==null || fishingData.curFishData.ID!=fish || fishingData.RodId!=rod || player.lastMapId!=map || (int)player.magnification!=mag || fishingData.IsFree || fishingData.IsRetry || fishingData.IsDuel) throw game.PlayerDataStorage.PlayerKVGameplayLoop.Stop("Fishing context changed during confirmation."); game.PlayerDataStorage.PlayerKVGameplayLoop.ContinueFishing(kvFishingAction,WaitForFishBiteED); } catch(Exception e) { game.PlayerDataStorage.PlayerKVGameplayLoop.Fault(e.Message); } } private void ConsumeBait() { #if UNITY_EDITOR && !SERVICE_HOST if(game.PlayerDataStorage.PlayerKVGameplayLoop.Enabled) { _=ConsumeBaitOnKVAsync(); return; } #endif if (fishingData.IsFree) { WaitForFishBiteED(); } else { DoConsumeBait(); } } }