public void OnSortieStart(MapId mapId, HomeportFleet fleet1, HomeportFleet fleet2) { foreach (var c in Counters) { if (c is SortieStartCounter sc) { sc.OnSortieStart(StatePersist, mapId, fleet1, fleet2); } } UpdateProgress(); }
public void OnExpeditionComplete(HomeportFleet fleet, ExpeditionInfo expedition, ExpeditionResult result) { foreach (var c in Counters) { if (c is ExpeditionCounter ec) { ec.OnExpeditionComplete(StatePersist, fleet, expedition, result); } } UpdateProgress(); }
public void OnMapRouting(MapRouting routing, HomeportFleet fleet, HomeportFleet fleet2) { foreach (var c in Counters) { if (c is MapRoutingCounter rc) { rc.OnMapRouting(StatePersist, routing, fleet, fleet2); } } UpdateProgress(); }
public void OnExerciseComplete(HomeportFleet fleet, BattleResult currentBattleResult) { foreach (var c in Counters) { if (c is ExerciseCounter ec) { ec.OnExerciseComplete(StatePersist, fleet, currentBattleResult); } } UpdateProgress(); }
public void SetExpeditionCompletion(HomeportFleet fleet, DateTimeOffset?timeStamp) { SelectedNotifier.RemoveSchedule("Expedition" + fleet.Id); if (fleet.Expedition != null && timeStamp is DateTimeOffset t) { SelectedNotifier.AddSchedule("Expedition" + fleet.Id, localization.GetLocalized("Notification", "Expedition_Title"), string.Format(localization.GetLocalized("Notification", "Expedition_Content"), fleet.Id, fleet.Name, fleet.Expedition.DisplayId, TryTranslate(fleet.Expedition.Name)), t - TimeSpan.FromMinutes(1)); } }
internal BattleManager(GameProvider listener, NavalBase navalBase) { this.navalBase = navalBase; listener.HomeportReturned += (t, m) => { using (EnterBatchNotifyScope()) { CurrentRouting = null; CurrentBattle = null; sortieFleet = null; sortieFleet2 = null; exerciseFleet = null; } }; listener.ExerciseStarted += (t, m) => { exerciseFleet = this.navalBase.Fleets[m]; CurrentBattle = new Battle(exerciseFleet, null, CombinedFleetType.None, BattleKind.Normal); }; listener.SortieStarting += (t, m) => { sortieFleet = this.navalBase.Fleets[m.FleetId]; if (m.FleetId == 1 && this.navalBase.CombinedFleet != CombinedFleetType.None) { sortieFleet2 = this.navalBase.Fleets[(FleetId)2]; } navalBase.Quests.Knowledges?.OnSortieStart(m.MapId, sortieFleet, sortieFleet2); }; listener.MapRouting += (t, m) => { CurrentRouting = new MapRouting(this.navalBase, m); CurrentBattle = new Battle(sortieFleet, sortieFleet2, this.navalBase.CombinedFleet, m.BattleKind); navalBase.Quests.Knowledges?.OnMapRouting(CurrentRouting, sortieFleet, sortieFleet2); }; listener.BattleStarted += (t, m) => { CurrentBattle.Append(this.navalBase.MasterData, m.Parsed); }; listener.BattleAppended += (t, m) => { CurrentBattle.Append(this.navalBase.MasterData, m.Parsed); }; listener.BattleCompleted += (t, m) => { CurrentBattleResult = new BattleResult(this.navalBase.MasterData, m, CurrentBattle.Ally); if (exerciseFleet is null) { navalBase.Quests.Knowledges?.OnBattleComplete(CurrentRouting, CurrentBattle, CurrentBattleResult); } else { navalBase.Quests.Knowledges?.OnExerciseComplete(exerciseFleet, CurrentBattleResult); } }; }
public Logger(IDataService dataService, GameProvider provider, NavalBase navalBase, IStatePersist statePersist) { this.dataService = dataService; this.navalBase = navalBase; this.statePersist = statePersist; provider.EquipmentCreated += (t, m) => { using var context = CreateContext(); context.EquipmentCreationTable.AddRange(m.Equipment.Select((e, i) => new EquipmentCreationEntity { TimeStamp = t.AddMilliseconds(i), Consumption = m.Consumption, EquipmentCreated = e?.EquipmentInfoId, IsSuccess = e is object, AdmiralLevel = this.navalBase.Admiral.Leveling.Level, Secretary = this.navalBase.Secretary.Info.Id, SecretaryLevel = this.navalBase.Secretary.Leveling.Level })); context.SaveChanges(); }; provider.ShipCreated += (t, m) => { shipCreation = new ShipCreationEntity { TimeStamp = t, Consumption = m.Consumption, IsLSC = m.IsLSC, AdmiralLevel = this.navalBase.Admiral.Leveling.Level, Secretary = this.navalBase.Secretary.Info.Id, SecretaryLevel = this.navalBase.Secretary.Leveling.Level }; lastBuildingDock = m.BuildingDockId; }; provider.BuildingDockUpdated += (t, m) => { if (shipCreation != null) { using var context = CreateContext(); shipCreation.ShipBuilt = m.Single(x => x.Id == lastBuildingDock).BuiltShipId.Value; shipCreation.EmptyDockCount = this.navalBase.BuildingDocks.Count(x => x.State == BuildingDockState.Empty); context.ShipCreationTable.Add(shipCreation); shipCreation = null; lastBuildingDock = default; context.SaveChanges(); } }; provider.ExpeditionCompleted += (t, m) => { using var context = CreateContext(); var fleet = this.navalBase.Fleets[m.FleetId]; context.ExpeditionCompletionTable.Add(new ExpeditionCompletionEntity { TimeStamp = t, ExpeditionId = fleet.Expedition.Id, ExpeditionName = m.ExpeditionName, Result = m.Result, MaterialsAcquired = m.MaterialsAcquired, RewardItem1 = m.RewardItem1, RewardItem2 = m.RewardItem2 }); context.SaveChanges(); foreach (var ship in fleet.HomeportShips) { this.statePersist.ClearLastSortie(ship.Id); } this.statePersist.SaveChanges(); }; #if DEBUG InitializeAdmiral(null); #endif navalBase.AdmiralChanging += (t, _, a) => { if (a != null) { lock (admiralLock) InitializeAdmiral(a); } }; navalBase.MaterialsUpdating += (t, old, @new, reason) => { using var context = CreateContext(); context.MaterialsChangeTable.Add(new MaterialsChangeEntity { TimeStamp = t, Materials = @new, Reason = reason }); context.SaveChanges(); }; navalBase.HomeportUpdated += (t, n) => { if (this.statePersist.LastSortieTime is DateTimeOffset last) { currentBattleContext ??= CreateContext(); var consumption = this.navalBase.Fleets[this.statePersist.LastSortieFleets].Sum(f => f.RepairingCost + f.SupplyingCost); var diff = consumption - this.statePersist.ConsumptionBeforeSortie; var entity = currentBattleContext.BattleConsumptionTable.Find(last); if (diff != default && entity != null) { entity.Consumption = diff; currentBattleContext.BattleConsumptionTable.Update(entity); currentBattleContext.SaveChanges(); } } currentBattle = null; currentExercise = null; currentBattleContext?.Dispose(); currentFleetInBattle = null; currentFleet2InBattle = null; this.statePersist.LastSortieFleets = null; this.statePersist.LastSortieTime = null; this.statePersist.SaveChanges(); }; navalBase.ShipSupplying += (t, s, raw) => { if (this.statePersist.GetLastSortie(s.Id) is DateTimeOffset last) { using var context = CreateContext(); var entity = context.BattleConsumptionTable.Find(last); if (entity is null) { return; } int fuel = raw.CurrentFuel - s.Fuel.Current; int bullet = raw.CurrentBullet - s.Bullet.Current; bool isMarriaged = s.Leveling.Level >= 100; entity.ActualConsumption += new Materials { Fuel = isMarriaged ? (int)(fuel * 0.85) : fuel, Bullet = isMarriaged ? (int)(bullet * 0.85) : bullet, Bauxite = (raw.SlotAircraft.Sum() - s.Slots.Sum(x => x.Aircraft.Current)) * 5 }; context.BattleConsumptionTable.Update(entity); context.SaveChanges(); } }; navalBase.ShipRepairing += (t, s, i) => { if (this.statePersist.GetLastSortie(s.Id) is DateTimeOffset last) { using var context = CreateContext(); var entity = context.BattleConsumptionTable.Find(last); if (entity is null) { return; } entity.ActualConsumption += s.RepairingCost; if (i) { entity.ActualConsumption += new Materials { InstantRepair = 1 } } ; context.BattleConsumptionTable.Update(entity); context.SaveChanges(); } }; navalBase.RepairingDockInstant += (t, d, s) => { if (this.statePersist.GetLastSortie(s.Id) is DateTimeOffset last) { using var context = CreateContext(); var entity = context.BattleConsumptionTable.Find(last); if (entity is null) { return; } entity.ActualConsumption += new Materials { InstantRepair = 1 }; context.BattleConsumptionTable.Update(entity); context.SaveChanges(); } }; provider.SortieStarting += (t, m) => { FleetId[] fleets; currentFleetInBattle = this.navalBase.Fleets[m.FleetId]; currentCombinedFleet = this.navalBase.CombinedFleet; if (currentCombinedFleet != CombinedFleetType.None) { currentFleet2InBattle = this.navalBase.Fleets[(FleetId)2]; fleets = new[] { (FleetId)1, (FleetId)2 }; } else { fleets = new[] { m.FleetId }; } currentBattleContext = CreateContext(); currentBattleContext.BattleConsumptionTable.Add(new BattleConsumptionEntity { TimeStamp = t, MapId = m.MapId }); currentBattleContext.SaveChanges(); this.statePersist.ConsumptionBeforeSortie = currentFleetInBattle.RepairingCost + currentFleetInBattle.SupplyingCost + (currentFleet2InBattle?.RepairingCost ?? default) + (currentFleet2InBattle?.SupplyingCost ?? default); this.statePersist.LastSortieTime = t; this.statePersist.LastSortieFleets = fleets; foreach (var ship in currentFleetInBattle.HomeportShips) { this.statePersist.SetLastSortie(ship.Id, t); } if (currentFleet2InBattle != null) { foreach (var ship in currentFleet2InBattle.HomeportShips) { this.statePersist.SetLastSortie(ship.Id, t); } } this.statePersist.SaveChanges(); }; provider.MapRouting += (t, m) => { var map = this.navalBase.Maps[m.MapId]; currentBattle = new BattleEntity { TimeStamp = t, CompletionTime = t, MapId = m.MapId, MapName = map.Info.Name.Origin, RouteId = m.RouteId, EventKind = m.EventKind, BattleKind = m.BattleKind, CombinedFleetType = this.navalBase.CombinedFleet, MapRank = map.Rank, MapGaugeType = map.GaugeType, MapGaugeNumber = map.GaugeIndex, MapGaugeHP = map.Gauge?.Current, MapGaugeMaxHP = map.Gauge?.Max }; if (m.UnparsedLandBaseDefence != null) { currentBattle.LandBaseDefence = m.UnparsedLandBaseDefence.ToString(Formatting.None); } Materials acquired = default; foreach (var r in m.ItemAcquired) { switch ((KnownUseItem)r.ItemId) { case KnownUseItem.Fuel: acquired.Fuel += r.Count; break; case KnownUseItem.Bullet: acquired.Bullet += r.Count; break; case KnownUseItem.Steel: acquired.Steel += r.Count; break; case KnownUseItem.Bauxite: acquired.Bauxite += r.Count; break; case KnownUseItem.InstantBuild: acquired.InstantBuild += r.Count; break; case KnownUseItem.InstantRepair: acquired.InstantRepair += r.Count; break; case KnownUseItem.Development: acquired.Development += r.Count; break; case KnownUseItem.Improvement: acquired.Improvement += r.Count; break; } } if (acquired != default) { var entity = currentBattleContext.BattleConsumptionTable.Find(this.statePersist.LastSortieTime); if (entity != null) { entity.Acquired += acquired; currentBattleContext.BattleConsumptionTable.Update(entity); } } currentBattleContext.BattleTable.Add(currentBattle); currentBattleContext.SaveChanges(); }; provider.ExerciseCandidateSelected += (t, m) => { currentExercise = new ExerciseEntity { TimeStamp = t, EnemyId = m.AdmiralId, EnemyName = m.Name, EnemyLevel = m.Leveling.Level }; }; provider.ExerciseStarted += (t, m) => { currentFleetInBattle = this.navalBase.Fleets[m]; currentBattleContext = CreateContext(); }; provider.BattleStarted += (t, m) => { if (currentBattle != null) { currentBattle.CompletionTime = t; currentBattle.SortieFleetState = currentFleetInBattle.Ships.Select(x => new ShipInBattleEntity(x)).ToArray(); currentBattle.SortieFleet2State = currentFleet2InBattle?.Ships.Select(x => new ShipInBattleEntity(x)).ToArray(); currentBattle.FirstBattleDetail = m.Unparsed.ToString(Formatting.None); currentBattle.LbasState = m.Parsed.LandBasePhases .Select(x => new AirForceInBattle(this.navalBase.AirForce[(currentBattle.MapId.AreaId, x.GroupId)])) .ToArray(); }