Ejemplo n.º 1
0
        async Task AddCargoToPlayerShips(IEnumerable <IShip> ships, ILocalIDManager galaxyIDManager, GalaxyRegistrationManager registrationManager, CargoSynchronizer cargoSynchronizer)
        {
            //Making this into a grand test of transaction sequences, there's really no reason to put this all into one sequence
            CargoTransactionSequence cs = new CargoTransactionSequence();

            foreach (var s in ships)
            {
                for (int i = 0; i < _config.CARGO_NumTurrets; i++)//Sending ship state over a network might be painful while this is here...
                {
                    CargoLaserTurret            c = new CargoLaserTurret(galaxyIDManager.PopFreeID(), 666, new LaserWeaponStats());
                    TransactionAddStatefulCargo t = new TransactionAddStatefulCargo(s, c, true);
                    cs.Add(t);

                    registrationManager.RegisterObject(c);
                }

                TransactionAddStatelessCargo tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.AmbassadorMissile, _config.CARGO_NumMissiles, true);
                cs.Add(tr);

                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.HellHoundMissile, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType1, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType2, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType3, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType4, _config.CARGO_NumMissiles, true);
                cs.Add(tr);

                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.Biodome, _config.CARGO_NumBiodomes, true);
                cs.Add(tr);
            }
            cargoSynchronizer.RequestAtomicTransactionSequence(cs);
            await cs.ResultTask;

            if (cs.ResultTask.Result != CargoResult.Success)
            {
                ConsoleManager.WriteLine(cs.ResultTask.Result.ToString());
            }
            return;
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        async Task FillPorts(GalaxyManager galaxyManager, LocalIDManager galaxyIDManager, CargoSynchronizer cargoSynchronizer)
        {
            var ports = galaxyManager.GetAllAreas().Where(a => a.AreaType == AreaTypes.Port);
            CargoTransaction lastTransaction = null;

            foreach (var p in ports)
            {
                var port = p as Port;
                foreach (var s in _config.PortConfig.StatefulCargoCounts)
                {
                    StatefulCargo sc;
                    for (int i = 0; i < s.Value; i++)//Yes, this loop is lazy, but it's 11:30PM...
                    {
                        //TODO: make a StatefulCargoFactory
                        switch (s.Key)
                        {
                        case StatefulCargoTypes.Barge:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Barge]);
                            break;
                        }

                        case StatefulCargoTypes.BattleCruiser:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.BattleCruiser]);
                            break;
                        }

                        case StatefulCargoTypes.Penguin:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Penguin]);
                            break;
                        }

                        case StatefulCargoTypes.Reaper:
                        {
                            sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Reaper]);
                            break;
                        }

                        case StatefulCargoTypes.LaserTurret:
                        {
                            sc = new CargoLaserTurret(galaxyIDManager.PopFreeID(), 666, new LaserWeaponStats());
                            break;
                        }

                        default:
                        {
                            sc = new StatefulCargo(galaxyIDManager.PopFreeID(), s.Key);
                            break;
                        }
                        }


                        CargoTransaction tr = new TransactionAddStatefulCargo(port, sc, true);
                        cargoSynchronizer.RequestTransaction(tr);
                        lastTransaction = tr;
                    }
                }

                foreach (var s in _config.PortConfig.StatelessCargoCounts)
                {
                    var tr = new TransactionAddStatelessCargo(port, s.Key, s.Value, true);
                    cargoSynchronizer.RequestTransaction(tr);
                    lastTransaction = tr;
                }

                foreach (var s in _config.PortConfig.ModuleCounts)
                {
                    Module m  = ModuleFactory.CreateModule(s.Key, galaxyIDManager.PopFreeID(), 1);
                    var    tr = new TransactionAddStatefulCargo(port, m, true);
                    cargoSynchronizer.RequestTransaction(tr);
                    lastTransaction = tr;
                }
            }
            if (lastTransaction != null)
            {
                await lastTransaction.ResultTask;
            }
        }