Ejemplo n.º 1
0
        /// <summary>
        /// Creates a structure
        /// </summary>
        /// <param name="type"></param>
        /// <param name="health"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="owner"></param>
        /// <param name="commandCenter"></param>
        /// <returns></returns>
        public static IStructure CreateStructure(StructureTypes type, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl)
        {
            IStructure s;

            switch (type)
            {
            case (StructureTypes.LaserTurret):
                s = new Turret(_localIDManager.PopFreeID(), xPos, yPos, owner, commandCenter, currentAreaID, pl);
                break;

            case (StructureTypes.Biodome):
                s = new Biodome(xPos, yPos, _localIDManager.PopFreeID(), owner, currentAreaID);
                break;

            case (StructureTypes.PowerPlant):
                s = new PowerPlant(xPos, yPos, _localIDManager.PopFreeID(), owner, currentAreaID);
                break;

            case (StructureTypes.Silo):
                s = new Silo(xPos, yPos, _localIDManager.PopFreeID(), owner, currentAreaID);
                break;


            default:
                throw new Exception("CreateStructure not implemented for structure type " + type.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            return(s);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a structure
        /// </summary>
        /// <param name="type"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="owner"></param>
        /// <param name="commandCenter"></param>
        /// <param name="currentAreaID"></param>
        /// <param name="pl"></param>
        /// <param name="writeToDB">If true, must specify dbm</param>
        /// <param name="dbm">must be specified if writeToDB is true</param>
        /// <returns></returns>
        public static IStructure CreateStructure(StructureTypes type, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl, bool writeToDB = false, IDatabaseManager dbm = null)
        {
            IStructure s;

            switch (type)
            {
            case (StructureTypes.LaserTurret):
                TurretTypes t = owner.GetArea().AreaType == AreaTypes.Planet ? TurretTypes.Planet : TurretTypes.Space;
                s = new Turret(_localIDManager.PopFreeID(), xPos, yPos, owner.Id, currentAreaID, t, pl);

                break;

            case (StructureTypes.Biodome):
                return(CreateBiodome(xPos, yPos, owner, currentAreaID));

            case (StructureTypes.PowerPlant):
                s = new PowerPlant(xPos, yPos, _localIDManager.PopFreeID(), owner.Id, currentAreaID);
                break;

            case (StructureTypes.Silo):
                s = new Silo(xPos, yPos, _localIDManager.PopFreeID(), owner.Id, currentAreaID);
                break;

            case (StructureTypes.CommandCenter):
                return(CreateCommandCenter(xPos, yPos, owner, currentAreaID));

            case (StructureTypes.Factory):
                s = new Factory(xPos, yPos, _localIDManager.PopFreeID(), owner.Id, currentAreaID);
                break;

            default:
                throw new Exception("CreateStructure not implemented for structure type " + type.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            if (writeToDB)
            {
                if (dbm == null)
                {
                    throw new Exception("Error: must specify IDatabaseManager dbm if writeToDB is true.");
                }
                else
                {
                    dbm.SaveAsync(s);
                }
            }

            return(s);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates and registers a colony and all associated structures. Links colony to planet appropriately.
        /// </summary>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="owner"></param>
        /// <param name="area"></param>
        /// <param name="ls"></param>
        /// <returns></returns>
        public static Colony CreateColony(float xPos, float yPos, Player owner, Planet planet, LocatorService ls)
        {
            Colony c = new Colony(_localIDManager.PopFreeID(), owner, planet, ls);

            c.Name = "Colony " + planet.AreaName;
            c.AddStructure(StructureFactory.CreateCommandCenter(xPos, yPos, owner, planet.Id));
            Biodome b = StructureFactory.CreateBiodome(-9999999, -9999999, owner, planet.Id);

            c.AddStructure(b);
            b.Stats      = new SmallBiodomeStats();
            b.Population = 10;


            _galaxyRegistrationManager.RegisterObject(c);

            planet.SetColony(c);
            planet.GetOwner().ColonizedPlanetIDs.Add(planet.Id);
            planet.IsColonized = true;
            planet.AddStructure(c.CommandCenter);
            planet.AddStructure(b);



            return(c);
        }
Ejemplo n.º 4
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.º 5
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.º 6
0
        public static PSystem GenerateStarsystem(int numberOfPlanets, int ID, GalaxyManager galaxyManager, LocalIDManager idManager, GalaxyRegistrationManager rm, LocatorService ls)
        {
            bool hasPort = false;

            // Add sun

            float size         = r.Next(100, 255) / 100f;
            float mass         = r.Next(50, 255) / 10f;
            float innerGravity = mass / 1875f;
            float outerGravity = innerGravity / 6f;

            var s    = (SunTypes[])Enum.GetValues(typeof(SunTypes));
            int type = r.Next(0, s.Length);

            var star = new Star(size, mass, innerGravity, outerGravity, s[type]);

            var system = new PSystem(star, ID, ls);

            system.AreaSize = baseBorder + r.Next(0, borderVariation);


            // Add Name
            system.AreaName = NameProvider.GetRandomName();


            rm.RegisterObject(system);


            for (int i = 0; i < numberOfPlanets; i++)
            {
                Planet planet;
                bool   SatisfiedWithResults = false;
                int    numAttempts          = MaxAttempts;
                system.IsCluster = false;
                int clusterType = 0;



                planet = new Planet(system, 0, ls);

                planet.AreaName = system.AreaName + " " + ToRoman(i + 1);

                if (r.Next(0, 101) > (100 - chanceOfCluster)) // Chance for planets to cluster
                {
                    system.IsCluster = true;
                    clusterType      = r.Next(0, clusterRadii.Count()); // Get which type of cluster
                }

                planet.Init(i, moonChance, minDistance, incrementOfOrbit, variationOfOrbit, 0,
                            r.Next());
                SatisfiedWithResults = !CheckForCollisions(system, planet); // True if we find any collisions.



                while (!SatisfiedWithResults)// While we're not content with the generation
                {
                    planet.Init(i, moonChance, minDistance, incrementOfOrbit, variationOfOrbit, 0,
                                r.Next());

                    SatisfiedWithResults = !CheckForCollisions(system, planet); // True if we find any collisions.

                    if (SatisfiedWithResults && system.IsCluster && i > 0)
                    {
                        SatisfiedWithResults = CheckForCollisions(system, planet, clusterRadii[clusterType]); // Cluster planets
                    }

                    numAttempts++;

                    if (numAttempts >= MaxAttempts && !system.IsCluster)
                    {
                        break; // Breaks out of infinite pass if it ever occurs
                    }
                    else if (numAttempts >= MaxAttempts && system.IsCluster)
                    {
                        i = 0; // Reset the whole operation because there's a bad system being generated.
                        foreach (Planet pll in system.GetPlanets())
                        {
                            system.RemovePlanet(pll);
                            rm.DeRegisterObject(pll);
                        }
                        break;
                    }
                }

                if (SatisfiedWithResults == false) // Don't add a colliding planet!
                {
                    //Logger.log(Log_Type.WARNING, "Skipped adding a planet due to MaxAttempts being too much");
                    continue;
                }
                planet.Id = idManager.PopFreeID();
                system.AddPlanet(planet);
                planet.ParentAreaID = system.Id;
                rm.RegisterObject(planet);

                if (system.AreaSize < planet.Distance - baseBorder) // If we're skinny, throw in a little extra space
                {
                    system.AreaSize = planet.Distance + baseBorder + r.Next(0, borderVariation);
                }
            }


            foreach (Planet p in system.GetPlanets())
            {
                _generateMoons(system, p, galaxyManager, idManager, rm, ls);
            }

            foreach (Planet m in system.GetMoons())
            {
                if (system.AreaSize < ls.AreaLocator.GetArea(m.IDToOrbit).Distance + m.Distance + baseBorder)
                {
                    // If we're skinny, throw in a little extra space
                    system.AreaSize = ls.AreaLocator.GetArea(m.IDToOrbit).Distance + m.Distance + baseBorder + r.Next(0, borderVariation);
                }
            }

            // Port Generation
            if (r.Next(0, 100) > 100 - portChance && !hasPort)
            {
                if (system.MoonCount > 0)
                {
                    for (int i = 0; i < system.MoonCount; i++)
                    {
                    }
                    int cr          = r.Next(0, system.MoonCount + 1); // Finds moon to turn into port.
                    int currentMoon = 0;                               // Used to get the moon

                    foreach (Planet m in system.GetMoons())
                    {
                        if (currentMoon == cr)
                        {
                            Planet moonToPort = m;
                            moonToPort.ParentAreaID = system.Id;
                            system.RemoveMoon(m);
                            rm.DeRegisterObject(m);

                            Port por = new Port(idManager.PopFreeID(), moonToPort, system.AreaName, ShipStatManager.StatShipList.ToList <ShipStats>(), ls); // Converts a moon into a port.
                            system.AddPort(por);
                            rm.RegisterObject(por);

                            hasPort = true;
                            break;
                        }
                        currentMoon++;
                    }
                }
            }


            return(system);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Generates n moons for a single planet, where n is divined from some mystical voodoo black magic related to planet.Scale
        /// </summary>
        /// <param name="system"></param>
        /// <param name="planet"></param>
        /// <param name="galaxyManager"></param>
        /// <param name="idManager"></param>
        /// <param name="rm"></param>
        /// <param name="pl"></param>
        /// <param name="al"></param>
        /// <param name="sl"></param>
        /// <param name="tl"></param>
        /// <param name="mem"></param>
        static void _generateMoons(PSystem system, Planet planet, GalaxyManager galaxyManager, LocalIDManager idManager, GalaxyRegistrationManager rm, LocatorService ls)
        {
            // If any moons, add them
            if (planet.HasMoons)
            {
                int parentID = planet.Id;

                int numMoons = 0;

                // Creates moon based on scale of size
                switch (planet.Scale)
                {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    planet.PlanetType = (PlanetTypes)r.Next(0, (int)PlanetTypes.OceanicSmall + 1);
                    planet.Scale     += 3; // Makes the small sprites scale better
                    break;

                case 6:
                case 7:
                    planet.PlanetType = (PlanetTypes)r.Next(0, (int)PlanetTypes.OceanicSmall + 1);
                    if (planet.PlanetType >= PlanetTypes.Crystalline &&
                        planet.PlanetType < PlanetTypes.Port)
                    {
                        planet.Scale += 3;     // Makes the small sprites scale better
                    }
                    numMoons = r.Next(3) + 2;
                    break;

                case 8:
                case 9:
                    numMoons = r.Next(2) + 3;
                    break;

                case 10:
                case 11:
                case 12:
                    numMoons = r.Next(3) + 3;
                    break;
                }

                for (int m = 0; m < numMoons; m++)
                {
                    Planet moon;

                    moon = new Planet(planet, idManager.PopFreeID(), ls);
                    InitializeMoon(moon, m, moonMinimumDistance, moonIncrementOfOrbit * m, moonVariationOfOrbit, planet, planet.Id,
                                   r.Next());


                    if (moon.PlanetType >= PlanetTypes.Crystalline &&
                        moon.PlanetType < PlanetTypes.Port)
                    {
                        moon.Scale += 3; // Makes the small sprites scale better
                    }
                    // #Yolo
                    moon.AreaName = planet.AreaName + "abcdefghijklmnopqrstuvwxyz"[m];

                    bool SatisfiedWithResults = false;
                    int  maxAttempts          = 200;
                    int  numAttempts          = 0;

                    while (!SatisfiedWithResults)// While we're not content with the generation
                    {
                        // Add moons
                        moon = new Planet(planet, moon.Id, ls);
                        InitializeMoon(moon, m, moonMinimumDistance, moonIncrementOfOrbit * m, moonVariationOfOrbit, planet, planet.Id,
                                       r.Next());
                        // Add another while here to check for maxDistance, as well as an If for if the system should follow that path of generation

                        SatisfiedWithResults = !CheckForCollisions(system, planet, moon, galaxyManager); // True if we find any collisions.
                        numAttempts++;

                        if (numAttempts >= maxAttempts)
                        {
                            break; // Breaks out of infinite pass if it ever occurs
                        }
                    }

                    if (!SatisfiedWithResults) // Don't add a colliding planet!
                    {
                        //Logger.log(Log_Type.ERROR, "Skipped adding a moon due to MaxAttempts being too much");
                        idManager.PushFreeID(moon.Id);

                        continue;
                    }


                    moon.IsMoon = true;
                    rm.RegisterObject(moon);
                    system.AddMoon(moon);
                    moon.ParentAreaID = system.Id;
                }
            }
        }