/// <summary> /// Remember to call ship.SetPlayer and player.SetShip /// </summary> /// <param name="props"></param> /// <returns></returns> public IShip CreateShip(ShipCreationProperties props) { IShip tempShip = null; switch (props.PilotType) { case PilotTypes.Player: tempShip = new PlayerShip(ShipStatManager.TypeToStats[props.ShipType], _locatorService); break; case PilotTypes.NPC: tempShip = new NPCShip(ShipStatManager.TypeToStats[props.ShipType], _locatorService); break; case PilotTypes.Simulator: throw new NotImplementedException("ShipFactory.CreateShip not yet implemented for PilotTypes.Simulator"); } tempShip.Id = _galaxyIdManager.PopFreeID(); _galaxyRegistrationManager.RegisterObject(tempShip); foreach (var w in props.WeaponTypes) { tempShip.SetWeapon(WeaponManager.GetNewWeapon(w)); } tempShip.PosX = props.PosX; tempShip.PosY = props.PosY; tempShip.CurrentEnergy = tempShip.ShipStats.Energy; _warpManager.MoveShipLocal(tempShip, props.AreaId); return(tempShip); }
/// <summary> /// Returns created NPCPlayers /// </summary> /// <param name="galaxyManager"></param> /// <param name="IDManager"></param> /// <param name="rm"></param> /// <param name="pm"></param> /// <param name="npcShips"></param> /// <returns></returns> async Task <IEnumerable <NPCPlayer> > CreateNPCs(GalaxyManager galaxyManager, LocalIDManager IDManager, GalaxyRegistrationManager rm, PlayerManager pm, LocatorService locatorService, CargoSynchronizer cargoSynchronizer, GlobalTeamManager teamManager, LocalIDManager galaxyIDManager) { Random r = new Random(666); var players = new List <NPCPlayer>(); var systems = galaxyManager.Systems; int npcCount = 0; foreach (PSystem s in systems) { List <Player> team1 = new List <Player>(); List <Player> team2 = new List <Player>(); List <Player> team3 = new List <Player>(); for (int i = 0; i < _config.NumNPCsPerSystem; i++) { List <WeaponTypes> weapons = new List <WeaponTypes>(); ShipTypes shipType = ShipTypes.Barge; switch (npcCount % 3) { case 0: shipType = ShipTypes.Penguin; break; case 1: shipType = ShipTypes.Barge; break; case 2: shipType = ShipTypes.Reaper; break; } if (shipType == ShipTypes.Reaper) { weapons.Add(WeaponTypes.LaserWave); weapons.Add(WeaponTypes.PlasmaCannon); } else { weapons.Add(WeaponTypes.AltLaser); weapons.Add(WeaponTypes.LaserWave); } ShipCreationProperties props = new ShipCreationProperties(r.Next(-20, 20), r.Next(-20, 20), (int)galaxyManager.SolAreaID, PilotTypes.NPC, shipType, weapons); IShip tempShip = _dbFillerUtils.ShipFactory.CreateShip(props); tempShip.ShipStats.ShieldType = ShieldTypes.QuickRegen; NPCPlayer p = pm.CreateNPCPlayer(locatorService); pm.RegisterPlayer(p); players.Add(p); tempShip.SetPlayer(p); p.SetActiveShip(tempShip, MockServer.WarpManager); TransactionAddStatelessCargo tr = new TransactionAddStatelessCargo(tempShip, StatelessCargoTypes.AmbassadorMissile, 666666, true); cargoSynchronizer.RequestTransaction(tr); await tr.ResultTask; tr = new TransactionAddStatelessCargo(tempShip, StatelessCargoTypes.Biodome, 666666, true); cargoSynchronizer.RequestTransaction(tr); await tr.ResultTask; Helpers.DebugWarp(s, p, tempShip); ships.Add(tempShip); //Random team assignment switch (npcCount % 2) { case 0: team1.Add(p); break; case 1: team2.Add(p); break; case 2: team3.Add(p); break; } //Give the guy some turrets for (int j = 0; j < _config.NumTurretsPerNPC; j++) { var t = StructureFactory.CreateStructure(StructureTypes.LaserTurret, r.Next(-20, 20), r.Next(-20, 20), p, null, (int)p.CurrentAreaID, locatorService.PlayerLocator, true, dbm); p.GetArea().AddStructure(t); } AddModulesToShip(tempShip, 5, cargoSynchronizer, galaxyIDManager); npcCount++; } foreach (Planet pl in s.GetPlanets()) { npcCount = 0; for (int i = 0; i < _config.NumNpcsPerPlanet; i++) { ShipTypes shipType = ShipTypes.Barge; switch (npcCount % 3) { case 0: shipType = ShipTypes.Penguin; break; case 1: shipType = ShipTypes.Barge; break; case 2: shipType = ShipTypes.Reaper; break; } NPCPlayer p = pm.CreateNPCPlayer(locatorService); pm.RegisterPlayer(p); players.Add(p); IShip tempShip = new NPCShip(ShipStatManager.TypeToStats[shipType], locatorService); tempShip.ShipStats.ShieldType = ShieldTypes.QuickRegen; tempShip.Id = IDManager.PopFreeID(); rm.RegisterObject(tempShip); p.SetActiveShip(tempShip, MockServer.WarpManager); tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.MissileLauncher)); if (shipType == ShipTypes.Reaper) { tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.LaserWave)); tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.PlasmaCannon)); } else { tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.AltLaser)); tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.LaserWave)); } TransactionAddStatelessCargo tr = new TransactionAddStatelessCargo(tempShip, StatelessCargoTypes.AmbassadorMissile, 666666, true); cargoSynchronizer.RequestTransaction(tr); await tr.ResultTask; tr = new TransactionAddStatelessCargo(tempShip, StatelessCargoTypes.Biodome, 666666, true); cargoSynchronizer.RequestTransaction(tr); await tr.ResultTask; tempShip.PosX = r.Next(-20, 20); tempShip.PosY = r.Next(-20, 20); Helpers.DebugWarp(pl, p, tempShip); ships.Add(tempShip); //Random team assignment switch (npcCount % 2) { case 0: team1.Add(p); break; case 1: team2.Add(p); break; case 2: team3.Add(p); break; } AddModulesToShip(tempShip, 5, cargoSynchronizer, galaxyIDManager); npcCount++; } teamManager.DebugCreateNewTeam(team1); teamManager.DebugCreateNewTeam(team2); teamManager.DebugCreateNewTeam(team3); } } return(players); }