public void CreateNewColony() { Entity faction = FactionFactory.CreateFaction(_game, "Terran"); StarSystemFactory sysfac = new StarSystemFactory(_game); StarSystem sol = sysfac.CreateSol(_game); //Entity starSystem = Entity.Create(_game.GlobalManager); //Entity planet = Entity.Create(starSystem.Manager, new List<BaseDataBlob>()); List <Entity> solBodies = sol.SystemManager.GetAllEntitiesWithDataBlob <NameDB>(_smAuthToken); Entity planet = solBodies.Find(item => item.GetDataBlob <NameDB>().DefaultName == "Earth"); Entity species = SpeciesFactory.CreateSpeciesHuman(faction, _game.GlobalManager); var requiredDataBlobs = new List <Type>() { typeof(ColonyInfoDB), typeof(NameDB), typeof(InstallationsDB) }; //Entity colony = ColonyFactory.CreateColony(faction, planet); ColonyFactory.CreateColony(faction, species, planet); Entity colony = faction.GetDataBlob <FactionInfoDB>().Colonies[0]; ColonyInfoDB colonyInfoDB = colony.GetDataBlob <ColonyInfoDB>(); //NameDB nameDB = colony.GetDataBlob<NameDB>(); //Assert.IsTrue(HasAllRequiredDatablobs(colony, requiredDataBlobs), "Colony Entity doesn't contains all required datablobs"); Assert.IsTrue(colonyInfoDB.PlanetEntity == planet, "ColonyInfoDB.PlanetEntity refs to wrong entity"); }
/// <summary> /// Returns true if colonization succesful /// </summary> /// <param name="colonizingShip"></param> /// <param name="xPos">ref in case positions are modified to accomodate placement (e.g. snap to nearest tile)</param> /// <param name="yPos">ref in case positions are modified to accomodate placement (e.g. snap to nearest tile)</param> /// <returns></returns> public bool TryColonizePlanet(Planet planet, IShip colonizingShip, WarpManager wm, LocatorService ls, float xPos, float yPos, out string resultMessage, IDatabaseManager databaseManager) { if (planet.IsColonized) { resultMessage = "Planet is already colonized!"; return(false); } else if (colonizingShip.CurrentEnergy != colonizingShip.ShipStats.Energy)//Is energy full? { resultMessage = "Not enough energy."; return(false); } else if (!planet.GetValidStructurePosition(new CommandCenterStats(), ref xPos, ref yPos))//Check for wall overlap here { resultMessage = "Invalid placement location."; return(false); } else if (colonizingShip.Cargo.GetCargoAmount(StatelessCargoTypes.Biodome) > 0) {//if everything checks out ColonyFactory.CreateColony(xPos, yPos, colonizingShip.GetPlayer(), planet, ls); List <IShip> ShipsToMove = new List <IShip>(1); //Kick all non-allied players into space foreach (var s in planet.GetShips()) { if (s.Value != colonizingShip) { if (s.Value is NPCShip && !_teamLocator.AreAllied(((NPCShip)s.Value), planet.GetOwner())) { ShipsToMove.Add(s.Value); } else if (s.Value is PlayerShip && !_teamLocator.AreAllied(s.Value.GetPlayer(), planet.GetOwner())) { ShipsToMove.Add(s.Value); } } } foreach (var s in ShipsToMove) { wm.ChangeArea((int)planet.ParentAreaID, s, false, true); } resultMessage = "Colonization Successful."; return(true); } else { resultMessage = "No biodome found in ship cargo."; return(false); } }
public MinimalMockServer(GalacticProperties gp, IDatabaseManager databaseManager, IDbIdIoService dbIdIoService) { Logger.Initialize(); DatabaseManager = databaseManager; DbIdIoService = dbIdIoService; //Minimal initializations GalaxyIDManager = new LocalIDManager(null, IDTypes.GalaxyID); TeamIDManager = new LocalIDManager(null, IDTypes.TeamID); accountIDManager = new LocalIDManager(null, IDTypes.AccountID); InitializeIdData(gp); globalGalaxyIDManager = new GlobalGalaxyIDManager(dbIdIoService, gp); GenerateIDsForLocalIDManager(globalGalaxyIDManager, GalaxyIDManager, gp.IdProperties[IDTypes.GalaxyID].LastIDAdded); globalTeamIDManager = new GlobalTeamIDManager(dbIdIoService, gp); GenerateIDsForLocalIDManager(globalTeamIDManager, TeamIDManager, gp.IdProperties[IDTypes.TeamID].LastIDAdded); globalAccountIDManager = new GlobalAccountIDManager(dbIdIoService, gp); GenerateIDsForLocalIDManager(globalAccountIDManager, accountIDManager, gp.IdProperties[IDTypes.AccountID].LastIDAdded); _redisServer = new RedisServer(Logger.LogRedisError, Logger.LogRedisInfo, new RedisConfig().Address); TeamManager = new GlobalTeamManager(TeamIDManager, null, null, null, DatabaseManager); PlayerManager = new PlayerManager(DatabaseManager, null, _redisServer, GalaxyIDManager, null); GalaxyManager = new GalaxyManager(gp.SolID, TeamManager); shipManager = new ShipManager(null, GalaxyManager, null, null, DatabaseManager); CollisionManager = new CollisionManager(GalaxyManager, null, null, null); GalaxyGenerator = new DebugGalaxyGenerator(PlayerManager, GalaxyManager, shipManager); AccountManager = new AccountManager_MasterServer(accountIDManager, DatabaseManager, false); CargoSynchronizer = new Server.Managers.CargoSynchronizer(); StructureManager = new StructureManager(DatabaseManager, GalaxyManager, GalaxyIDManager, CargoSynchronizer); RegistrationManger = new GalaxyRegistrationManager(GalaxyManager, shipManager, CollisionManager, GalaxyIDManager, PlayerManager, null, CargoSynchronizer, StructureManager); ColonyFactory.Initialize(GalaxyIDManager, RegistrationManger); StructureFactory.Initialize(GalaxyIDManager, RegistrationManger); LocatorService = new LocatorService(RegistrationManger, PlayerManager, GalaxyManager, shipManager, AccountManager, TeamManager, TeamManager, null, StructureManager, null); WarpManager = new WarpManager(GalaxyManager, null, null, _redisServer, AccountManager, null); CargoSynchronizer.Start(10, 4); }
internal TestGame(int numSystems = 10) { GameSettings = new NewGameSettings { GameName = "Unit Test Game", MaxSystems = numSystems, CreatePlayerFaction = false }; Game = new Game(GameSettings); // add a faction: HumanFaction = FactionFactory.CreateFaction(Game, "New Terran Utopian Empire"); // add a species: HumanSpecies = SpeciesFactory.CreateSpeciesHuman(HumanFaction, Game.GlobalManager); // add another faction: GreyAlienFaction = FactionFactory.CreateFaction(Game, "The Grey Empire"); // Add another species: GreyAlienSpecies = SpeciesFactory.CreateSpeciesHuman(GreyAlienFaction, Game.GlobalManager); // Greys Name the Humans. HumanSpecies.GetDataBlob <NameDB>().SetName(GreyAlienFaction.Guid, "Stupid Terrans"); // Humans name the Greys. GreyAlienSpecies.GetDataBlob <NameDB>().SetName(HumanFaction.Guid, "Space bugs"); StarSystemFactory starfac = new StarSystemFactory(Game); Sol = starfac.CreateSol(Game); Earth = NameLookup.GetFirstEntityWithName(Sol, "Earth"); //Sol.Entities[3]; //should be fourth entity created EarthColony = ColonyFactory.CreateColony(HumanFaction, HumanSpecies, Earth); DefaultEngineDesign = DefaultStartFactory.DefaultThrusterDesign(Game, HumanFaction); DefaultWeaponDesign = DefaultStartFactory.DefaultSimpleLaser(Game, HumanFaction); DefaultShipDesign = DefaultStartFactory.DefaultShipDesign(Game, HumanFaction); Vector3 position = Earth.GetDataBlob <PositionDB>().AbsolutePosition_AU; DefaultShip = ShipFactory.CreateShip(DefaultShipDesign, HumanFaction, position, Earth, Sol, "Serial Peacemaker"); Sol.SetDataBlob(DefaultShip.ID, new TransitableDB()); }
private void testPlanetAndSpecies(Entity planet, Entity species) { long[] basePop = new long[] { 0, 5, 10, 100, 999, 1000, 10000, 100000, 10000000 }; long[] infrastructureAmounts = new long[] { 0, 1, 5, 100 }; Dictionary <Entity, long> newPop, returnedPop; int i, j, k; Guid infGUID = new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb"); ComponentTemplateSD infrastructureSD = _game.Game.StaticData.ComponentTemplates[infGUID]; ComponentDesigner infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>()); ComponentDesign infrastructureDesign = infrastructureDesigner.CreateDesign(_game.HumanFaction); Dictionary <Entity, long> pop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population; // Single iteration growth test for (i = 0; i < infrastructureAmounts.Length; i++) { // Create a new colony with this planet and species, add infrastructure item to it _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet); // Add the correct number of infrastructure to the colony for (k = 0; k < infrastructureAmounts[i]; k++) { EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign); } ReCalcProcessor.ReCalcAbilities(_game.EarthColony); for (j = 0; j < basePop.Length; j++) { // set up population and infrastructure for each test newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population; foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray()) { newPop[kvp.Key] = basePop[j]; } //var infrastuctures = _game.EarthColony.GetDataBlob<ComponentInstancesDB>().SpecificInstances[infrastructureEntity].Where(inf => inf.DesignEntity.HasDataBlob<LifeSupportAbilityDB>()); returnedPop = calcGrowthIteration(_game.EarthColony, newPop); PopulationProcessor.GrowPopulation(_game.EarthColony); foreach (KeyValuePair <Entity, long> kvp in pop.ToArray()) { Assert.AreEqual(returnedPop[kvp.Key], pop[kvp.Key]); } } } // Multiple iteration growth test for (i = 0; i < infrastructureAmounts.Length; i++) { // Create a new colony with this planet and species, add infrastructure item to it _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet); // Add the correct number of infrastructure to the colony for (k = 0; k < infrastructureAmounts[i]; k++) { EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign); } ReCalcProcessor.ReCalcAbilities(_game.EarthColony); for (j = 0; j < basePop.Length; j++) { // set up population and infrastructure for each test newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population; foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray()) { newPop[kvp.Key] = basePop[j]; } for (k = 0; k < 10; k++) { newPop = calcGrowthIteration(_game.EarthColony, newPop); PopulationProcessor.GrowPopulation(_game.EarthColony); } foreach (KeyValuePair <Entity, long> kvp in pop.ToArray()) { Assert.AreEqual(newPop[kvp.Key], pop[kvp.Key]); } } } }
/// <summary> /// Initializes the entire server /// </summary> private void Initialize() { for (int i = 0; i < 20; i++) { msgAvgQue.Enqueue(0); } var rand = new Random(3); // Logging Enabled Logger.Initialize(); _synchronizers = new List <ISynchronizer>(); //Load configs ConnectionManagerConfig connectionManagerConfig = new ConnectionManagerConfig(new CoreNetworkConfig()); GalacticProperties galacticProperties = new GalacticProperties(); _consoleManager = new ConsoleManager(); _projectileManager = new ProjectileManager(); ConsoleManager.WriteLine("Starting database...", ConsoleMessageType.Startup); _databaseManager = new MongoDatabaseManager(); ShipStatManager.ReadShipsFromDBSList(_databaseManager.GetStatsFromDBAsync().Result); ConsoleManager.WriteLine("Ship types loaded.", ConsoleMessageType.Startup); RedisConfig rc = new RedisConfig(); _redisServer = new RedisServer(LogRedisError, LogRedisInfo, rc.Address); var slaveId = SlaveServerConfigService.GetFreeSlaveID(_redisServer).Result; _slaveServerConfigService = new SlaveServerConfigService(_redisServer, slaveId); _masterServerManager = new MasterServerManager(new MasterServerConfig(), new GalacticProperties(), _databaseManager, _databaseManager, _redisServer, _slaveServerConfigService); _cargoSynchronizer = new CargoSynchronizer(); _synchronizers.Add(_cargoSynchronizer); connectionManagerConfig.MyConfig.Port = ConnectionManager.GetFreePort(28002, 28010); _connectionManager = new ConnectionManager(); _connectionManager.Initialize(connectionManagerConfig); //Poll to listen to Lidgren until it is ready //LidgrenMessagePoller_Init initializationPoller = new LidgrenMessagePoller_Init(_connectionManager.Server, this); //initializationPoller.Poll(); _galaxyIDManager = new LocalIDManager(_masterServerManager, IDTypes.GalaxyID); _teamIDManager = new LocalIDManager(_masterServerManager, IDTypes.TeamID); _accountIDManager = new LocalIDManager(_masterServerManager, IDTypes.AccountID); _transactionIDManager = new LocalIDManager(_masterServerManager, IDTypes.TransactionID); _accountManager = new AccountManager(_accountIDManager, _databaseManager); _messageManager = new MessageManager(_connectionManager); _clientUpdateManager = new ClientUpdateManager(_playerManager); _playerManager = new PlayerManager(_databaseManager, _connectionManager, _redisServer, _galaxyIDManager, _clientUpdateManager); var chatCommands = new List <IChatCommand>() { new HelpCommand(), new ShoutCommand(_redisServer), new RadioCommand(), new TellCommand(_playerManager) }; var asyncChatCommands = new List <IAsyncChatCommand>() { new AdminWarpCommand(_databaseManager, _redisServer, new Random()) }; _teamManager = new GlobalTeamManager(_teamIDManager, _connectionManager, _redisServer, _playerManager, _databaseManager); _galaxyManager = new GalaxyManager(galacticProperties.SolID, _teamManager); _chatManager = new ChatManager(chatCommands, asyncChatCommands, _playerManager, _messageManager, _redisServer); _warpManager = new WarpManager(_galaxyManager, _messageManager, _chatManager, _redisServer, _accountManager, _databaseManager); _shipManager = new ShipManager(_messageManager, _galaxyManager, _warpManager, _connectionManager, _databaseManager); _structureManager = new StructureManager(_databaseManager, _galaxyManager, _galaxyIDManager, _cargoSynchronizer); loginManager = new LoginManager(_accountManager, _playerManager, _connectionManager, _redisServer); // Todo: Convert everything over to ServerNetworkMessage to propogate full request context. _simulatorManager = new SimulatorManager(new SimulatorConfig(), _redisServer, (sender, container) => ProcessMessage(sender, new ServerNetworkMessage(container, null))); StructureStatManager.Initialize(); ConsoleManager.WriteLine("Completed Initialization", ConsoleMessageType.Startup); _economyManager = new EconomyManager(_transactionIDManager, _playerManager, _galaxyManager, _cargoSynchronizer, _shipManager, _databaseManager, _masterServerManager); _killManager = new KillManager(_cargoSynchronizer, _playerManager, _galaxyManager, _messageManager, _connectionManager, _warpManager, _chatManager, _economyManager); _collisionManager = new CollisionManager(_galaxyManager, _messageManager, _killManager, _projectileManager); _registrationManager = new GalaxyRegistrationManager(_galaxyManager, _shipManager, _collisionManager, _galaxyIDManager, _playerManager, _accountManager, _cargoSynchronizer, _structureManager); _warpManager.SetRegistrationManager(_registrationManager);//Gross, I know. _locatorService = new LocatorService(_registrationManager, _playerManager, _galaxyManager, _shipManager, _accountManager, _teamManager, _teamManager, _messageManager, _structureManager, _masterServerManager); _msMessageHandler = new MasterServerMessageHandler((int)_masterServerManager.SlaveID, _redisServer, _connectionManager, _locatorService, _accountManager, _accountIDManager, _databaseManager, _galaxyManager, _galaxyIDManager, _playerManager, _shipManager, _registrationManager, _teamIDManager, _messageManager, _teamManager, _warpManager, _transactionIDManager, ProcessRoutedMessage); StructureFactory.Initialize(_galaxyIDManager, _registrationManager); ColonyFactory.Initialize(_galaxyIDManager, _registrationManager); dbSyncer = new DBSyncer(_databaseManager, _galaxyManager, _shipManager, _playerManager, _accountManager, _structureManager); #if DEBUG _typesToExcludeIgnore.Add(MessageTypes.PositionUpdateData); _typesToExcludeIgnore.Add(MessageTypes.ShipFireRequest); _typesToExcludeIgnore.Add(MessageTypes.ProjectileCollisionReport); _typesToExcludeIgnore.Add(MessageTypes.StructureFireRequest); _typesToExcludeIgnore.Add(MessageTypes.ObjectPickupRequest); #endif }