/// <summary> /// This method should receive the Universe to add Ships to and a set of ShipDefaultSettings /// /// Default values are handled in ShipCreation.AddShips /// </summary> /// <param name="universe"></param> /// <param name="shipDefaultSettings"></param> /// <returns> /// Return the newly edited Universe /// </returns> /// <exception cref="FileNotFoundException"></exception> public Universe CreateShips(Universe universe, ShipDefaultSettings shipDefaultSettings) { // If there are no Planets for the Ships to be tied to then throw an exception if (universe.Planets == null || universe.Planets.Count == 0) { throw new FileNotFoundException("No planets have been created for the universe"); } // Set the Universe to the Universe returned from CharCreation.AddCharacters and serialize/return it universe = new ShipCreation().AddShips(universe, shipDefaultSettings, ShipData, _charData, CharacterNameGenerations); SerializeData(universe); return(universe); }
public Logger(IDataService dataService, IGameProvider provider, NavalBase navalBase) { this.dataService = dataService; this.navalBase = navalBase; provider.EquipmentCreated += (t, m) => { using (var context = CreateContext()) { context.EquipmentCreationTable.Add(new EquipmentCreation { TimeStamp = t, Consumption = m.Consumption, EquipmentCreated = m.SelectedEquipentInfoId, IsSuccess = m.IsSuccess, 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 ShipCreation { 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, EmptyDockCount = navalBase.BuildingDocks.Count(x => x.State == BuildingDockState.Empty) }; lastBuildingDock = m.BuildingDockId; }; provider.BuildingDockUpdated += (t, m) => { if (shipCreation != null) { using (var context = CreateContext()) { shipCreation.ShipBuilt = m.Single(x => x.Id == lastBuildingDock).BuiltShipId.Value; context.ShipCreationTable.Add(shipCreation); shipCreation = null; lastBuildingDock = default; context.SaveChanges(); } } }; provider.ExpeditionCompleted += (t, m) => { using (var context = CreateContext()) { context.ExpeditionCompletionTable.Add(new ExpeditionCompletion { TimeStamp = t, ExpeditionId = this.navalBase.Fleets[m.FleetId].Expedition.Id, ExpeditionName = m.ExpeditionName, Result = m.Result, MaterialsAcquired = m.MaterialsAcquired, RewardItem1 = m.RewardItem1, RewardItem2 = m.RewardItem2 }); context.SaveChanges(); } }; }