internal void UpdateAdmiral(RawBasic rpAdmiral) { if (Admiral != null) { Admiral.Update(rpAdmiral); } else { Admiral = new Admiral(rpAdmiral); OnPropertyChanged(nameof(Admiral)); } }
public NavalBase(GameProvider listener, ITimingService timingService, NotificationManager notification, IStatePersist statePersist, IQuestKnowledges questKnowledges) { Notification = notification; StatePersist = statePersist; this.questKnowledges = questKnowledges; MasterData = new MasterDataRoot(listener); Battle = new BattleManager(listener, this); Quests = new QuestManager(listener, questKnowledges, statePersist); _allEquipment = new IdTable <EquipmentId, HomeportEquipment, RawEquipment, NavalBase>(this); _buildingDocks = new IdTable <BuildingDockId, BuildingDock, RawBuildingDock, NavalBase>(this); _repairingDocks = new IdTable <RepairingDockId, RepairingDock, RawRepairingDock, NavalBase>(this); _useItems = new IdTable <UseItemId, UseItemCount, RawUseItemCount, NavalBase>(this); _allShips = new IdTable <ShipId, HomeportShip, RawShip, NavalBase>(this); _fleets = new IdTable <FleetId, HomeportFleet, RawFleet, NavalBase>(this); _maps = new IdTable <MapId, Map, RawMap, NavalBase>(this); _airForce = new IdTable <(MapAreaId MapArea, AirForceGroupId GroupId), AirForceGroup, RawAirForceGroup, NavalBase>(this); listener.AllEquipmentUpdated += (t, msg) => _allEquipment.BatchUpdate(msg, t); listener.BuildingDockUpdated += (t, msg) => _buildingDocks.BatchUpdate(msg, t); listener.UseItemUpdated += (t, msg) => _useItems.BatchUpdate(msg, t); listener.AdmiralUpdated += (t, msg) => { if (Admiral?.Id != msg.Id) { var @new = new Admiral(msg, this, t); AdmiralChanging?.Invoke(t, Admiral, @new); Admiral = @new; NotifyPropertyChanged(nameof(Admiral)); StatePersist?.Initialize(msg.Id); this.questKnowledges.Load(); } else { Admiral.Update(msg, t); } }; listener.MaterialsUpdated += (t, msg) => { var oldMaterials = Materials; var materials = oldMaterials; msg.Apply(ref materials); if (Materials != materials) { Materials = materials; MaterialsUpdating?.Invoke(t, oldMaterials, materials, msg.Reason); } }; listener.HomeportReturned += (t, msg) => { _allShips.BatchUpdate(msg.Ships, t); CombinedFleet = msg.CombinedFleetType; if (StatePersist != null) { StatePersist.LastHomeportUpdate = t; StatePersist.SaveChanges(); } HomeportUpdated?.Invoke(t, this); }; listener.CompositionChanged += (t, msg) => { var fleet = Fleets[msg.FleetId]; if (msg.ShipId is ShipId shipId) { var ship = AllShips[shipId]; fleet.ChangeComposition(msg.Index, ship); } else { fleet.ChangeComposition(msg.Index, null); } }; listener.FleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t); listener.FleetPresetSelected += (t, msg) => Fleets[msg.Id].Update(msg, t); listener.ShipExtraSlotOpened += (t, msg) => AllShips[msg].OpenExtraSlot(); listener.PartialFleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t, removal: false); listener.PartialShipsUpdated += (t, msg) => _allShips.BatchUpdate(msg, t, removal: false); listener.RepairingDockUpdated += (t, msg) => _repairingDocks.BatchUpdate(msg, t); listener.ShipSupplied += (t, msg) => { foreach (var raw in msg) { var ship = AllShips[raw.ShipId]; ShipSupplying?.Invoke(t, ship, raw); ship?.Supply(raw); } questKnowledges.OnSingletonEvent(SingletonEvent.ShipSupply); }; listener.RepairStarted += (t, msg) => { var ship = AllShips[msg.ShipId]; if (ship == null) { return; } ShipRepairing?.Invoke(t, ship, msg.InstantRepair); if (msg.InstantRepair) { ship.SetRepaired(); } var oldMaterials = Materials; var materials = oldMaterials; materials.Fuel -= ship.RepairingCost.Fuel; materials.Steel -= ship.RepairingCost.Steel; Materials = materials; MaterialsUpdating?.Invoke(t, oldMaterials, materials, MaterialsChangeReason.ShipRepair); questKnowledges.OnSingletonEvent(SingletonEvent.ShipRepair); }; listener.InstantRepaired += (t, msg) => { var dock = RepairingDocks[msg]; RepairingDockInstant?.Invoke(t, msg, dock.RepairingShip); dock.Instant(); }; listener.InstantBuilt += (t, msg) => { var dock = BuildingDocks[msg]; dock.Instant(); var oldMaterials = Materials; var materials = oldMaterials; materials.InstantBuild -= dock.IsLSC ? 10 : 1; Materials = materials; MaterialsUpdating?.Invoke(t, oldMaterials, materials, MaterialsChangeReason.InstantBuilt); }; listener.ShipCreated += (t, msg) => questKnowledges.OnSingletonEvent(SingletonEvent.ShipConstruct); listener.ShipBuildCompleted += (t, msg) => { _allEquipment.BatchUpdate(msg.Equipments, t, removal: false); _allShips.Add(msg.Ship, t); }; listener.EquipmentCreated += (t, msg) => { foreach (var e in msg.Equipment) { if (e is object) { _allEquipment.Add(e, t); } questKnowledges.OnSingletonEvent(SingletonEvent.EquipmentCreate); } }; listener.ShipDismantled += (t, msg) => { var removed = RemoveShips(msg.ShipIds, msg.DismantleEquipments); questKnowledges.OnShipDismantle(removed); ShipDismantling?.Invoke(t, removed, msg.DismantleEquipments); }; listener.EquipmentDismantled += (t, msg) => { var removed = RemoveEquipment(msg); questKnowledges.OnEquipmentDismantle(removed); EquipmentDismantling?.Invoke(t, removed); }; listener.EquipmentImproved += (t, msg) => { var consumed = msg.ConsumedEquipmentIds != null?RemoveEquipment(msg.ConsumedEquipmentIds) : null; var original = AllEquipment[msg.EquipmentId]; EquipmentImproving?.Invoke(t, original, msg.UpdatedTo, consumed, msg.IsSuccess); if (msg.IsSuccess) { original.Update(msg.UpdatedTo, t); } questKnowledges?.OnSingletonEvent(SingletonEvent.EquipmentImprove); }; listener.ShipPoweruped += (t, msg) => { var consumed = RemoveShips(msg.ConsumedShipIds, msg.DismantleEquipments); var original = AllShips[msg.ShipId]; questKnowledges.OnShipPowerup(original, consumed, msg.IsSuccess); ShipPoweruping?.Invoke(t, original, msg.UpdatedTo, consumed); original.Update(msg.UpdatedTo, t); }; listener.ExpeditionCompleted += (t, msg) => { var fleet = Fleets[msg.FleetId]; questKnowledges?.OnExpeditionComplete(fleet, fleet.Expedition, msg.Result); }; listener.MapsUpdated += (t, msg) => _maps.BatchUpdate(msg, t); listener.AirForceUpdated += (t, msg) => _airForce.BatchUpdate(msg, t); listener.AirForcePlaneSet += (t, msg) => AirForce[(msg.MapAreaId, msg.GroupId)].SetPlane(t, msg);
public NavalBase(IGameProvider listener, ILocalizationService localization) { Localization = localization; MasterData = new MasterDataRoot(listener, localization); Quests = new QuestManager(listener, localization); _allEquipment = new IdTable<EquipmentId, Equipment, IRawEquipment, NavalBase>(this); _buildingDocks = new IdTable<BuildingDockId, BuildingDock, IRawBuildingDock, NavalBase>(this); _repairingDocks = new IdTable<RepairingDockId, RepairingDock, IRawRepairingDock, NavalBase>(this); _useItems = new IdTable<UseItemId, UseItemCount, IRawUseItemCount, NavalBase>(this); _allShips = new IdTable<ShipId, Ship, IRawShip, NavalBase>(this); _fleets = new IdTable<FleetId, Fleet, IRawFleet, NavalBase>(this); _maps = new IdTable<MapId, Map, IRawMap, NavalBase>(this); _airForce = new IdTable<(MapAreaId MapArea, AirForceGroupId GroupId), AirForceGroup, IRawAirForceGroup, NavalBase>(this); listener.AllEquipmentUpdated += (t, msg) => _allEquipment.BatchUpdate(msg, t); listener.BuildingDockUpdated += (t, msg) => _buildingDocks.BatchUpdate(msg, t); listener.UseItemUpdated += (t, msg) => _useItems.BatchUpdate(msg, t); listener.AdmiralUpdated += (t, msg) => { if (Admiral?.Id != msg.Id) { var @new = new Admiral(msg, this, t); AdmiralChanging?.Invoke(t, Admiral, @new); Admiral = @new; NotifyPropertyChanged(nameof(Admiral)); } else Admiral.Update(msg, t); }; listener.MaterialsUpdated += (t, msg) => { var materials = Materials; msg.Apply(ref materials); if (Materials != materials) { Materials = materials; MaterialsUpdating?.Invoke(t, Materials, materials, msg.Reason); } }; listener.HomeportReturned += (t, msg) => _allShips.BatchUpdate(msg.Ships, t); listener.CompositionChanged += (t, msg) => { var fleet = Fleets[msg.FleetId]; if (msg.ShipId is ShipId shipId) { var ship = AllShips[shipId]; fleet.ChangeComposition(msg.Index, ship, Fleets.FirstOrDefault(x => x.Ships.Contains(ship))); } else fleet.ChangeComposition(msg.Index, null, null); }; listener.FleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t); listener.FleetPresetSelected += (t, msg) => Fleets[msg.Id].Update(msg, t); listener.ShipEquipmentUdated += (t, msg) => AllShips[msg.ShipId].UpdateEquipments(msg.EquipmentIds); listener.ShipExtraSlotOpened += (t, msg) => AllShips[msg].ExtraSlot = new Slot(); listener.PartialFleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t, removal: false); listener.PartialShipsUpdated += (t, msg) => _allShips.BatchUpdate(msg, t, removal: false); listener.RepairingDockUpdated += (t, msg) => _repairingDocks.BatchUpdate(msg, t); listener.ShipSupplied += (t, msg) => { foreach (var raw in msg) AllShips[raw.ShipId]?.Supply(raw); }; listener.RepairStarted += (t, msg) => { if (msg.InstantRepair) AllShips[msg.ShipId]?.SetRepaired(); }; listener.InstantRepaired += (t, msg) => { var dock = RepairingDocks[msg]; dock.State = RepairingDockState.Empty; dock.RepairingShip = null; }; listener.InstantBuilt += (t, msg) => BuildingDocks[msg].State = BuildingDockState.BuildCompleted; listener.ShipBuildCompleted += (t, msg) => { _allEquipment.BatchUpdate(msg.Equipments, t, removal: false); _allShips.Add(msg.Ship, t); }; listener.EquipmentCreated += (t, msg) => { if (msg.IsSuccess) _allEquipment.Add(msg.Equipment, t); }; listener.ShipDismantled += (t, msg) => ShipDismantling?.Invoke(t, RemoveShips(msg.ShipIds, msg.DismantleEquipments, t), msg.DismantleEquipments); listener.EquipmentDismantled += (t, msg) => EquipmentDismantling?.Invoke(t, RemoveEquipments(msg, t)); listener.EquipmentImproved += (t, msg) => { var consumed = RemoveEquipments(msg.ConsumedEquipmentIds, t); var original = AllEquipment[msg.EquipmentId]; EquipmentImproving?.Invoke(t, original, msg.UpdatedTo, consumed, msg.IsSuccess); if (msg.IsSuccess) original.Update(msg.UpdatedTo, t); }; listener.ShipPoweruped += (t, msg) => { var consumed = RemoveShips(msg.ConsumedShipIds, true, t); var original = AllShips[msg.ShipId]; ShipPoweruping?.Invoke(t, original, msg.UpdatedTo, consumed); original.Update(msg.UpdatedTo, t); }; listener.MapsUpdated += (t, msg) => _maps.BatchUpdate(msg, t); listener.AirForceUpdated += (t, msg) => _airForce.BatchUpdate(msg, t); listener.AirForcePlaneSet += (t, msg) => { var group = AirForce[(msg.MapAreaId, msg.GroupId)]; group.Distance = msg.NewDistance; group.squadrons.BatchUpdate(msg.UpdatedSquadrons, t, removal: false); };