public TrackManager() { var proxy = KanColleClient.Current.Proxy; var MapInfo = new TrackerMapInfo(); var battleTracker = new BattleTracker(); // 연습전 종료 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_practice/battle_result") .TryParse <kcsapi_practice_result>().Subscribe(x => PractiveResultEvent?.Invoke(this, new PracticeResultEventArgs(x.Data)) ); // 근대화 개수 proxy.api_req_kaisou_powerup.TryParse <kcsapi_powerup>().Subscribe(x => PowerUpEvent?.Invoke(this, this.EmptyEventArg) ); // 개수공창 개수 proxy.api_req_kousyou_remodel_slot.TryParse <kcsapi_remodel_slot>().Subscribe(x => ReModelEvent?.Invoke(this, this.EmptyEventArg) ); // 폐기 proxy.api_req_kousyou_destroyitem2.TryParse <kcsapi_destroyitem2>().Subscribe(x => DestoryItemEvent?.Invoke(this, this.EmptyEventArg) ); // 해체 proxy.api_req_kousyou_destroyship.TryParse <kcsapi_destroyship>().Subscribe(x => DestoryShipEvent?.Invoke(this, this.EmptyEventArg) ); // 건조 proxy.api_req_kousyou_createship.TryParse <kcsapi_createship>().Subscribe(x => CreateShipEvent?.Invoke(this, this.EmptyEventArg) ); // 개발 proxy.api_req_kousyou_createitem.TryParse <kcsapi_createitem>().Subscribe(x => CreateItemEvent?.Invoke(this, this.EmptyEventArg) ); // 보급 proxy.api_req_hokyu_charge.TryParse <kcsapi_charge>().Subscribe(x => ChargeEvent?.Invoke(this, this.EmptyEventArg) ); // 입거 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_nyukyo/start") .Subscribe(x => RepairStartEvent?.Invoke(this, this.EmptyEventArg)); // 원정 proxy.api_req_mission_result.TryParse <kcsapi_mission_result>().Subscribe(x => MissionResultEvent?.Invoke(this, new MissionResultEventArgs(x.Data)) ); // 출격 (시작) proxy.api_req_map_start.TryParse <kcsapi_map_start>().Subscribe(x => MapInfo.Reset(x.Data.api_maparea_id)); // 통상 - 주간전 proxy.api_req_sortie_battle.TryParse <kcsapi_sortie_battle>().Subscribe(x => battleTracker.BattleProcess(x.Data)); // 통상 - 야전 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_battle_midnight/battle") .TryParse <kcsapi_battle_midnight_battle>().Subscribe(x => battleTracker.BattleProcess(x.Data)); // 통상 - 개막야전 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_battle_midnight/sp_midnight") .TryParse <kcsapi_battle_midnight_sp_midnight>().Subscribe(x => battleTracker.BattleProcess(x.Data)); // 전투 종료 (연합함대 포함) proxy.api_req_sortie_battleresult.TryParse <kcsapi_battleresult>() .Subscribe(x => BattleResultEvent?.Invoke(this, new BattleResultEventArgs(MapInfo.AfterCombat(), battleTracker.enemyShips, x.Data))); proxy.api_req_combined_battle_battleresult.TryParse <kcsapi_combined_battle_battleresult>() .Subscribe(x => BattleResultEvent?.Invoke(this, new BattleResultEventArgs(MapInfo.AfterCombat(), battleTracker.enemyShips, x.Data))); // Register all trackers trackingAvailable = new ObservableCollection <ITracker>(trackingAvailable.OrderBy(x => x.Id)); trackingAvailable.CollectionChanged += (sender, e) => { if (e.Action != NotifyCollectionChangedAction.Add) { return; } foreach (ITracker tracker in e.NewItems) { tracker.RegisterEvent(this); tracker.ResetQuest(); tracker.ProcessChanged += ((x, y) => { QuestsEventChanged?.Invoke(this, EmptyEventArg); WriteToStorage(KanColleClient.Current.Homeport.Quests); }); } }; Assembly.GetExecutingAssembly().GetTypes() .ToList().Where(x => x.Namespace == "Grabacr07.KanColleViewer.Models.QuestTracker.Tracker" && typeof(ITracker).IsAssignableFrom(x)) .ToList().ForEach(x => trackingAvailable.Add((ITracker)Activator.CreateInstance(x))); ReadFromStorage(); proxy.api_get_member_questlist.Subscribe(x => new System.Threading.Thread(ProcessQuests).Start()); QuestsEventChanged?.Invoke(this, EmptyEventArg); }
public TrackManager(Func <bool> PreprocessCheck) { this.PreprocessCheck = PreprocessCheck; var homeport = KanColleClient.Current.Homeport; var proxy = KanColleClient.Current.Proxy; var MapInfo = new TrackerMapInfo(); var battleTracker = new BattleTracker(); // 편성 변경 homeport.Organization.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(homeport.Organization.Fleets)) { var fleets = homeport.Organization.Fleets.Select(x => x.Value); foreach (var x in fleets) { x.State.Updated += (_, _2) => Preprocess(() => HenseiEvent?.Invoke(this, this.EmptyEventArg)); } } }; // 장비 변경 proxy.api_req_kaisou_slot_exchange_index.TryParse <kcsapi_slot_exchange_index>() .Subscribe(x => Preprocess(() => EquipEvent?.Invoke(this, this.EmptyEventArg))); proxy.api_req_kaisou_slot_deprive.TryParse <kcsapi_slot_deprive>() .Subscribe(x => Preprocess(() => EquipEvent?.Invoke(this, this.EmptyEventArg))); // 연습전 종료 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_practice/battle_result") .TryParse <kcsapi_practice_result>().Subscribe(x => Preprocess(() => PracticeResultEvent?.Invoke(this, new PracticeResultEventArgs(x.Data))) ); // 근대화 개수 proxy.api_req_kaisou_powerup.TryParse <kcsapi_powerup>() .Subscribe(x => Preprocess(() => PowerUpEvent?.Invoke(this, new BaseEventArgs(x.Data.api_powerup_flag != 0)))); // 개수공창 개수 proxy.api_req_kousyou_remodel_slot.TryParse <kcsapi_remodel_slot>() .Subscribe(x => Preprocess(() => ReModelEvent?.Invoke(this, new BaseEventArgs(x.Data.api_remodel_flag != 0)))); // 폐기 proxy.api_req_kousyou_destroyitem2.TryParse <kcsapi_destroyitem2>() .Subscribe(x => Preprocess(() => DestoryItemEvent?.Invoke(this, new DestroyItemEventArgs(x.Request, x.Data)))); // 해체 proxy.api_req_kousyou_destroyship.TryParse <kcsapi_destroyship>() .Subscribe(x => Preprocess(() => DestoryShipEvent?.Invoke(this, this.EmptyEventArg))); // 건조 proxy.api_req_kousyou_createship.TryParse <kcsapi_createship>() .Subscribe(x => Preprocess(() => CreateShipEvent?.Invoke(this, this.EmptyEventArg))); // 개발 proxy.api_req_kousyou_createitem.TryParse <kcsapi_createitem>() .Subscribe(x => Preprocess(() => CreateItemEvent?.Invoke(this, new BaseEventArgs(x.Data.api_create_flag != 0)))); // 보급 proxy.api_req_hokyu_charge.TryParse <kcsapi_charge>() .Subscribe(x => Preprocess(() => ChargeEvent?.Invoke(this, this.EmptyEventArg))); // 입거 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_nyukyo/start") .Subscribe(x => Preprocess(() => RepairStartEvent?.Invoke(this, this.EmptyEventArg))); // 원정 proxy.api_req_mission_result.TryParse <kcsapi_mission_result>() .Subscribe(x => Preprocess(() => MissionResultEvent?.Invoke(this, new MissionResultEventArgs(x.Data)))); // 출격 (시작, 진격) proxy.api_req_map_start.TryParse <kcsapi_map_start>() .Subscribe(x => Preprocess(() => MapInfo.Reset(x.Data.api_maparea_id, x.Data.api_mapinfo_no, x.Data.api_no))); proxy.api_req_map_next.TryParse <kcsapi_map_start>() .Subscribe(x => Preprocess(() => MapInfo.Next(x.Data.api_maparea_id, x.Data.api_mapinfo_no, x.Data.api_no))); // 통상 - 주간전 proxy.api_req_sortie_battle.TryParse <kcsapi_sortie_battle>() .Subscribe(x => Preprocess(() => battleTracker.BattleProcess(x.Data))); // 통상 - 야전 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_battle_midnight/battle") .TryParse <kcsapi_battle_midnight_battle>() .Subscribe(x => Preprocess(() => battleTracker.BattleProcess(x.Data))); // 통상 - 개막야전 proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_battle_midnight/sp_midnight") .TryParse <kcsapi_battle_midnight_sp_midnight>() .Subscribe(x => Preprocess(() => battleTracker.BattleProcess(x.Data))); // 전투 종료 (연합함대 포함) proxy.api_req_sortie_battleresult.TryParse <kcsapi_battleresult>() .Subscribe(x => Preprocess(() => BattleResultEvent?.Invoke(this, new BattleResultEventArgs(MapInfo.AfterCombat(), battleTracker.enemyShips, x.Data)))); proxy.api_req_combined_battle_battleresult.TryParse <kcsapi_combined_battle_battleresult>() .Subscribe(x => Preprocess(() => BattleResultEvent?.Invoke(this, new BattleResultEventArgs(MapInfo.AfterCombat(), battleTracker.enemyShips, x.Data)))); // Register all trackers trackingAvailable = new ObservableCollection <ITracker>(trackingAvailable.OrderBy(x => x.Id)); trackingAvailable.CollectionChanged += (sender, e) => { if (e.Action != NotifyCollectionChangedAction.Add) { return; } foreach (ITracker tracker in e.NewItems) { tracker.RegisterEvent(this); tracker.ResetQuest(); tracker.ProcessChanged += ((x, y) => { try { QuestsEventChanged?.Invoke(this, EmptyEventArg); } catch { } }); } }; }