Exemplo n.º 1
0
        public static void ProcessTurn(int count)
        {
            for (var i = 0; i < count; i++)
            {
                using (var t = new TransactionScope()) {
                    var db = new DbDataContext();

                    var config = db.GetConfig();
                    config.CombatTurn++;

                    FleetLogic.ProcessTransitTurn(db);

                    foreach (var o in db.CelestialObjects)
                    {
                        o.UpdateIncomeInfo();
                    }

                    foreach (var player in db.Players.Where(x => x.IsActive))
                    {
                        if (config.CombatTurn % config.PopulationTick == 0)
                        {
                            player.ApplyPopulationTick(config.CombatTurn);
                        }
                        player.ApplyResourceTurn(config.CombatTurn);
                    }

                    db.MarkDirty();

                    config.TurnStarted = DateTime.UtcNow;                     // todo synchronize properly when not faking
                    db.SubmitChanges();
                    t.Complete();
                }
            }
        }
Exemplo n.º 2
0
		public static void ProcessTurn(int count)
		{
			for (var i = 0; i < count; i++) {
				using (var t = new TransactionScope()) {
					var db = new DbDataContext();

					var config = db.GetConfig();
					config.CombatTurn++;

					FleetLogic.ProcessTransitTurn(db);

					foreach (var o in db.CelestialObjects) {
						o.UpdateIncomeInfo();
					}

					foreach (var player in db.Players.Where(x => x.IsActive)) {
						if (config.CombatTurn%config.PopulationTick == 0) player.ApplyPopulationTick(config.CombatTurn);
						player.ApplyResourceTurn(config.CombatTurn);
					}

					db.MarkDirty();

					config.TurnStarted = DateTime.UtcNow; // todo synchronize properly when not faking
					db.SubmitChanges();
					t.Complete();
				}
			}
		}
Exemplo n.º 3
0
        public static StarMap GetMapData(string playerName, string password)
        {
            var db = new DbDataContext();

            var ret = new StarMap();

            var lo = new DataLoadOptions();

            lo.LoadWith <CelestialObject>(x => x.CelestialObjectShips);            // todo stealth also in all fleet structures
            lo.LoadWith <CelestialObject>(x => x.CelestialObjectStructures);
            db.LoadOptions       = lo;
            ret.CelestialObjects = db.CelestialObjects.ToList();

            ret.Players = db.Players.Where(x => x.IsActive).ToList();

            ret.StarSystems = db.StarSystems.ToList();

            ret.Transits = FleetLogic.GetTransits(playerName, password);

            ret.Config = db.GetConfig();

            ret.ObjectLinks = db.CelestialObjectLinks.ToList();

            return(ret);
        }
Exemplo n.º 4
0
        public static Tuple <PopulationTransport, CelestialObject> CreatePopulationTransport(string playerName, string password, int fromBodyID, int toBodyID, int count)
        {
            using (var t = new TransactionScope())
            {
                var db     = new DbDataContext();
                var player = db.GetPlayer(playerName, password);
                var from   = player.CelestialObjects.Single(x => x.CelestialObjectID == fromBodyID);
                var target = db.CelestialObjects.Single(x => x.CelestialObjectID == toBodyID);

                if (from.Population < count)
                {
                    throw new ApplicationException("There are not enough people on this planet");
                }
                from.Population -= count;
                from.UpdateIncomeInfo();
                var transport = new PopulationTransport()
                {
                    Count = count, Player = player, Transit = new Transit()
                };
                player.PopulationTransports.Add(transport);

                var transit = transport.Transit;

                transit.SetTransit(target, FleetBaseWarp, db.GetConfig().CombatTurn + 1, db.GetConfig());                  // will start next turn


                db.MarkDirty();
                db.SubmitChanges();
                t.Complete();
                return(new Tuple <PopulationTransport, CelestialObject>(transport, from));
            }
        }
Exemplo n.º 5
0
        public static Tuple <Player, CelestialObject> OrderMothership(string playerName, string password, int toBodyID)
        {
            using (var t = new TransactionScope())
            {
                var db     = new DbDataContext();
                var player = db.GetPlayer(playerName, password);
                if (player.Transit == null)
                {
                    player.Transit = new Transit()
                    {
                        CelestialObject = player.CelestialObject
                    }
                }
                ;
                var originalBody = player.CelestialObject;
                var target       = db.CelestialObjects.Single(x => x.CelestialObjectID == toBodyID);
                var transit      = player.Transit;

                var oldOrbit  = transit.OrbitsObjectID;
                var oldTarget = transit.CelestialObjectByToObjectID;

                transit.SetTransit(target, FleetBaseWarp, db.GetConfig().CombatTurn + 1, db.GetConfig()); // will start next turn

                if (oldOrbit == null && oldTarget != null)                                                // was heading to another planet
                {
                    var ev = db.AddEvent(EventType.Fleet, "{0} changed destination from {1} to {2}, ETA {3}", transit.GetNameWithOwner(), oldTarget.GetNameWithOwner(), transit.CelestialObjectByToObjectID.GetNameWithOwner(), transit.GetEtaString(db.GetConfig().SecondsPerTurn));
                    ev.Connect(transit.Fleets);
                    ev.Connect(transit.GetOwner());
                    ev.Connect(transit.CelestialObjectByToObjectID, oldTarget);
                    ev.Connect(transit.CelestialObjectByToObjectID.Player, oldTarget.Player);
                }

                if (originalBody != null)
                {
                    originalBody.UpdateIncomeInfo();
                }
                db.MarkDirty();
                db.SubmitChanges();
                t.Complete();
                return(new Tuple <Player, CelestialObject>(player, originalBody));
            }
        }
Exemplo n.º 6
0
		public static StarMap GetMapData(string playerName, string password)
		{
			var db = new DbDataContext();

			var ret = new StarMap();

			var lo = new DataLoadOptions();
			lo.LoadWith<CelestialObject>(x => x.CelestialObjectShips); // todo stealth also in all fleet structures
			lo.LoadWith<CelestialObject>(x => x.CelestialObjectStructures);
			db.LoadOptions = lo;
			ret.CelestialObjects = db.CelestialObjects.ToList();

			ret.Players = db.Players.Where(x => x.IsActive).ToList();

			ret.StarSystems = db.StarSystems.ToList();

			ret.Transits = FleetLogic.GetTransits(playerName, password);

			ret.Config = db.GetConfig();

			ret.ObjectLinks = db.CelestialObjectLinks.ToList();

			return ret;
		}
Exemplo n.º 7
0
        public static Fleet OrderFleet(string playerName, string password, int fleetID, int toBodyID, int futureOffset)
        {
            if (futureOffset < 0)
            {
                throw new ApplicationException("Future offset cannot be smaller than 0");
            }
            using (var t = new TransactionScope())
            {
                var db     = new DbDataContext();
                var player = db.GetPlayer(playerName, password);
                var fleet  = player.Fleets.Single(x => x.FleetID == fleetID);
                var target = db.CelestialObjects.Single(x => x.CelestialObjectID == toBodyID);

                var oldOrbit  = fleet.Transit.OrbitsObjectID;
                var oldTarget = fleet.Transit.CelestialObjectByToObjectID;

                fleet.Transit.SetTransit(target, FleetBaseWarp, db.GetConfig().CombatTurn + 1 + futureOffset, db.GetConfig()); // will start next turn

                if (oldOrbit == null && oldTarget != null)                                                                     // was heading to another planet
                {
                    var transit = fleet.Transit;
                    var ev      = db.AddEvent(EventType.Fleet, "{0} changed destination from {1} to {2}, ETA {3}", transit.GetNameWithOwner(), oldTarget.GetNameWithOwner(), transit.CelestialObjectByToObjectID.GetNameWithOwner(), transit.GetEtaString(db.GetConfig().SecondsPerTurn));
                    ev.Connect(transit.Fleets);
                    ev.Connect(transit.GetOwner());
                    ev.Connect(transit.CelestialObjectByToObjectID, oldTarget);
                    ev.Connect(transit.CelestialObjectByToObjectID.Player, oldTarget.Player);
                }


                db.MarkDirty();
                db.SubmitChanges();
                fleet.FleetShips.Load();
                t.Complete();
                return(fleet);
            }
        }
Exemplo n.º 8
0
        public static void ProcessTransitTurn(DbDataContext db)
        {
            var config = db.GetConfig();

            foreach (var transit in db.Transits)
            {
                if (transit.StartBattleTurn >= config.CombatTurn && transit.EndBattleTurn >= config.CombatTurn && transit.OrbitsObjectID != null)
                {
                    // log set sail
                    var owner = transit.GetOwner();
                    var ev    = db.AddEvent(EventType.Fleet,
                                            "{0} set sail from {1} to {2}. It will need {3} to get there",
                                            transit.GetNameWithOwner(),
                                            transit.CelestialObjectByFromObjectID.GetNameWithOwner(),
                                            transit.CelestialObjectByToObjectID.GetNameWithOwner(),
                                            transit.GetEtaString(config.SecondsPerTurn));
                    ev.Connect(transit.Fleets);
                    ev.Connect(owner);
                    if (transit.FromObjectID != null)
                    {
                        ev.Connect(transit.CelestialObjectByFromObjectID);
                        ev.Connect(transit.CelestialObjectByFromObjectID.Player);
                    }
                    ev.Connect(transit.CelestialObjectByToObjectID);
                    ev.Connect(transit.CelestialObjectByToObjectID.Player);

                    // process set sail
                    transit.OrbitsObjectID = null;
                    if (transit.Players.Any())                     // its mothership and it just left homeworld
                    {
                        var p = transit.Players.First();
                        if (p.HomeworldID != null)
                        {
                            var eve = db.AddEvent(EventType.Player, "{0} has lost homeworld {1}", p.Name, p.CelestialObject.GetName());
                            eve.Connect(p);
                            eve.Connect(p.CelestialObject);
                        }
                        p.HomeworldID = null;
                    }
                }
                else if (transit.EndBattleTurn <= config.CombatTurn && transit.OrbitsObjectID == null)
                {
                    // log arrival
                    var owner = transit.GetOwner();
                    var ev    = db.AddEvent(EventType.Fleet, "{0} arrived to {1}", transit.GetNameWithOwner(), transit.CelestialObjectByToObjectID.GetNameWithOwner());
                    ev.Connect(transit.Fleets);
                    ev.Connect(owner);
                    ev.Connect(transit.CelestialObjectByToObjectID);
                    ev.Connect(transit.CelestialObjectByToObjectID.Player);

                    // process arrival
                    transit.CelestialObject = transit.CelestialObjectByToObjectID;
                    transit.FromObjectID    = null;
                    transit.ToObjectID      = null;
                    transit.FromX           = 0;
                    transit.ToX             = 0;
                    transit.FromY           = 0;
                    transit.ToY             = 0;

                    PopulationTransport transport = transit.PopulationTransports;
                    if (transport != null)
                    {
                        if (transit.CelestialObjectByToObjectID.OwnerID == transport.OwnerID)                         // todo handle alliances!!
                        {
                            transit.CelestialObjectByToObjectID.Population += transport.Count;
                            if (transit.CelestialObjectByToObjectID.Population > transit.CelestialObjectByToObjectID.MaxPopulation)
                            {
                                transit.CelestialObjectByToObjectID.Population = transit.CelestialObjectByToObjectID.MaxPopulation;
                            }
                            transit.PopulationTransports = null;
                            db.Transits.DeleteOnSubmit(transit);
                            db.PopulationTransports.DeleteOnSubmit(transport);
                        }
                    }

                    if (transit.Players.Any())
                    {
                        var p = transit.Players.First();
                        p.CelestialObject = transit.CelestialObjectByToObjectID;                         // set homeworld to object where we arrived

                        var eve = db.AddEvent(EventType.Player, "{0} has new homeworld {1}", p.Name, p.CelestialObject.GetName());
                        eve.Connect(p);
                        eve.Connect(p.CelestialObject);
                    }
                }
            }
        }
		public static Tuple<PopulationTransport, CelestialObject> CreatePopulationTransport(string playerName, string password, int fromBodyID, int toBodyID, int count)
		{
			using (var t = new TransactionScope())
			{
				var db = new DbDataContext();
				var player = db.GetPlayer(playerName, password);
				var from = player.CelestialObjects.Single(x => x.CelestialObjectID == fromBodyID);
				var target = db.CelestialObjects.Single(x => x.CelestialObjectID == toBodyID);
				
				if (from.Population < count) throw new ApplicationException("There are not enough people on this planet");
				from.Population -= count;
				from.UpdateIncomeInfo();
				var transport = new PopulationTransport() { Count = count, Player = player, Transit = new Transit() };
				player.PopulationTransports.Add(transport);

				var transit = transport.Transit;

				transit.SetTransit(target, FleetBaseWarp, db.GetConfig().CombatTurn + 1 , db.GetConfig()); // will start next turn
        

				db.MarkDirty();
				db.SubmitChanges();
				t.Complete();
				return new Tuple<PopulationTransport, CelestialObject>(transport, from);
			}

		}
Exemplo n.º 10
0
		public static void ProcessTransitTurn(DbDataContext db)
		{
			var config = db.GetConfig();
			foreach (var transit in db.Transits)
			{
				if (transit.StartBattleTurn >= config.CombatTurn && transit.EndBattleTurn >= config.CombatTurn && transit.OrbitsObjectID != null)
				{
					// log set sail
					var owner = transit.GetOwner();
					var ev = db.AddEvent(EventType.Fleet,
					                     "{0} set sail from {1} to {2}. It will need {3} to get there",
					                     transit.GetNameWithOwner(),
					                     transit.CelestialObjectByFromObjectID.GetNameWithOwner(),
					                     transit.CelestialObjectByToObjectID.GetNameWithOwner(),
					                     transit.GetEtaString(config.SecondsPerTurn));
					ev.Connect(transit.Fleets);
					ev.Connect(owner);
					if (transit.FromObjectID != null)
					{
						ev.Connect(transit.CelestialObjectByFromObjectID);
						ev.Connect(transit.CelestialObjectByFromObjectID.Player);
					}
					ev.Connect(transit.CelestialObjectByToObjectID);
					ev.Connect(transit.CelestialObjectByToObjectID.Player);
          
					// process set sail
					transit.OrbitsObjectID = null;
					if (transit.Players.Any()) // its mothership and it just left homeworld
					{
						var p = transit.Players.First();
						if (p.HomeworldID != null)
						{
							var eve = db.AddEvent(EventType.Player, "{0} has lost homeworld {1}", p.Name, p.CelestialObject.GetName());
							eve.Connect(p);
							eve.Connect(p.CelestialObject);
						}
						p.HomeworldID = null;
					}
				}
				else if (transit.EndBattleTurn <= config.CombatTurn && transit.OrbitsObjectID == null)
				{
					// log arrival
					var owner = transit.GetOwner();
					var ev = db.AddEvent(EventType.Fleet, "{0} arrived to {1}", transit.GetNameWithOwner(), transit.CelestialObjectByToObjectID.GetNameWithOwner());
					ev.Connect(transit.Fleets);
					ev.Connect(owner);
					ev.Connect(transit.CelestialObjectByToObjectID);
					ev.Connect(transit.CelestialObjectByToObjectID.Player);

					// process arrival
					transit.CelestialObject = transit.CelestialObjectByToObjectID;
					transit.FromObjectID = null;
					transit.ToObjectID = null;
					transit.FromX = 0;
					transit.ToX = 0;
					transit.FromY = 0;
					transit.ToY = 0;

					PopulationTransport transport = transit.PopulationTransports;
					if (transport != null)
					{
						if (transit.CelestialObjectByToObjectID.OwnerID == transport.OwnerID) // todo handle alliances!!
						{ 
							transit.CelestialObjectByToObjectID.Population += transport.Count;
							if (transit.CelestialObjectByToObjectID.Population > transit.CelestialObjectByToObjectID.MaxPopulation) transit.CelestialObjectByToObjectID.Population = transit.CelestialObjectByToObjectID.MaxPopulation;
							transit.PopulationTransports = null;
							db.Transits.DeleteOnSubmit(transit);
							db.PopulationTransports.DeleteOnSubmit(transport);
						}
					}

					if (transit.Players.Any())
					{
						var p = transit.Players.First();
						p.CelestialObject = transit.CelestialObjectByToObjectID; // set homeworld to object where we arrived
					
						var eve = db.AddEvent(EventType.Player, "{0} has new homeworld {1}", p.Name, p.CelestialObject.GetName());
						eve.Connect(p);
						eve.Connect(p.CelestialObject);
	
					}
				}
			}
		}
Exemplo n.º 11
0
		public static Tuple<Player, CelestialObject> OrderMothership(string playerName, string password, int toBodyID)
		{
			using (var t = new TransactionScope())
			{
				var db = new DbDataContext();
				var player = db.GetPlayer(playerName, password);
				if (player.Transit == null) player.Transit = new Transit()
				                                             	{
				                                             		CelestialObject = player.CelestialObject
				                                             	};
				var originalBody = player.CelestialObject;
				var target = db.CelestialObjects.Single(x => x.CelestialObjectID == toBodyID);
				var transit = player.Transit;

				var oldOrbit = transit.OrbitsObjectID;
				var oldTarget = transit.CelestialObjectByToObjectID;

				transit.SetTransit(target, FleetBaseWarp, db.GetConfig().CombatTurn + 1, db.GetConfig()); // will start next turn

				if (oldOrbit == null && oldTarget != null) // was heading to another planet
				{
					var ev = db.AddEvent(EventType.Fleet, "{0} changed destination from {1} to {2}, ETA {3}", transit.GetNameWithOwner(), oldTarget.GetNameWithOwner(), transit.CelestialObjectByToObjectID.GetNameWithOwner(), transit.GetEtaString(db.GetConfig().SecondsPerTurn));
					ev.Connect(transit.Fleets);
					ev.Connect(transit.GetOwner());
					ev.Connect(transit.CelestialObjectByToObjectID, oldTarget);
					ev.Connect(transit.CelestialObjectByToObjectID.Player, oldTarget.Player);
				}

				if (originalBody != null) originalBody.UpdateIncomeInfo();
				db.MarkDirty();
				db.SubmitChanges();
				t.Complete();
				return new Tuple<Player, CelestialObject>(player, originalBody);
			}
		}
Exemplo n.º 12
0
		public static Fleet OrderFleet(string playerName, string password, int fleetID, int toBodyID, int futureOffset)
		{
			if (futureOffset < 0) throw new ApplicationException("Future offset cannot be smaller than 0");
			using (var t = new TransactionScope())
			{
				var db = new DbDataContext();
				var player = db.GetPlayer(playerName, password);
				var fleet = player.Fleets.Single(x => x.FleetID == fleetID);
				var target = db.CelestialObjects.Single(x => x.CelestialObjectID == toBodyID);

				var oldOrbit = fleet.Transit.OrbitsObjectID;
				var oldTarget = fleet.Transit.CelestialObjectByToObjectID;

				fleet.Transit.SetTransit(target, FleetBaseWarp, db.GetConfig().CombatTurn + 1 + futureOffset, db.GetConfig()); // will start next turn

				if (oldOrbit == null && oldTarget != null) // was heading to another planet
				{
					var transit = fleet.Transit;
					var ev = db.AddEvent(EventType.Fleet, "{0} changed destination from {1} to {2}, ETA {3}", transit.GetNameWithOwner(), oldTarget.GetNameWithOwner(), transit.CelestialObjectByToObjectID.GetNameWithOwner(), transit.GetEtaString(db.GetConfig().SecondsPerTurn));
					ev.Connect(transit.Fleets);
					ev.Connect(transit.GetOwner());
					ev.Connect(transit.CelestialObjectByToObjectID, oldTarget);
					ev.Connect(transit.CelestialObjectByToObjectID.Player, oldTarget.Player);
				}


				db.MarkDirty();
				db.SubmitChanges();
				fleet.FleetShips.Load();
				t.Complete();
				return fleet;
			}
		}