コード例 #1
0
        private void handleSystemDelta(JObject json)
        {
            // Fetch guaranteed information
            string  systemname = (string)json["systemname"];
            decimal x          = (decimal)(double)json["x"];
            decimal y          = (decimal)(double)json["y"];
            decimal z          = (decimal)(double)json["z"];

            // Fetch delta information
            string oldfaction = (string)json["oldfaction"];
            string newfaction = (string)json["newfaction"];

            string oldstate = (string)json["oldstate"];
            string newstate = (string)json["newstate"];

            string oldallegiance = (string)json["oldallegiance"];
            string newallegiance = (string)json["newallegiance"];

            string oldgovernment = (string)json["oldgovernment"];
            string newgovernment = (string)json["newgovernment"];

            string oldeconomy = (string)json["oldeconomy"];
            string neweconomy = (string)json["neweconomy"];

            string oldsecurity = (string)json["oldsecurity"];
            string newsecurity = (string)json["newsecurity"];

            // See if this matches our parameters
            string matchname = match(systemname, null, x, y, z, oldfaction, newfaction, oldstate, newstate);

            if (matchname != null)
            {
                // Fetch the system from our local repository (but don't create it if it doesn't exist)
                StarSystem system = StarSystemSqLiteRepository.Instance.GetStarSystem(systemname);
                if (system != null)
                {
                    // Update our local copy of the system
                    if (newfaction != null)
                    {
                        system.faction = newfaction;
                    }
                    if (newstate != null)
                    {
                        system.state = newstate;
                    }
                    if (newallegiance != null)
                    {
                        system.allegiance = newallegiance;
                    }
                    if (newgovernment != null)
                    {
                        system.government = newgovernment;
                    }
                    if (neweconomy != null)
                    {
                        system.primaryeconomy = neweconomy;
                    }
                    if (newsecurity != null)
                    {
                        system.security = newsecurity;
                    }
                    system.lastupdated = DateTime.Now;
                    StarSystemSqLiteRepository.Instance.SaveStarSystem(system);
                }

                // Send an appropriate event
                Event @event = null;
                if (newfaction != null)
                {
                    @event = new SystemFactionChangedEvent(DateTime.Now, matchname, systemname, oldfaction, newfaction);
                }
                else if (newstate != null)
                {
                    @event = new SystemStateChangedEvent(DateTime.Now, matchname, systemname, oldstate, newstate);
                }
                if (@event != null)
                {
                    EDDI.Instance.eventHandler(@event);
                }
            }
        }
コード例 #2
0
        private void handleSystemDelta(JObject json)
        {
            // Fetch guaranteed information
            string  systemname = (string)json["systemname"];
            decimal x          = (decimal)(double)json["x"];
            decimal y          = (decimal)(double)json["y"];
            decimal z          = (decimal)(double)json["z"];

            // Fetch delta information
            string oldfaction = (string)json["oldfaction"];
            string newfaction = (string)json["newfaction"];

            FactionState oldstate = FactionState.FromName((string)json["oldstate"]);
            FactionState newstate = FactionState.FromName((string)json["newstate"]);

            string oldallegiance = (string)json["oldallegiance"];
            string newallegiance = (string)json["newallegiance"];

            string oldgovernment = (string)json["oldgovernment"];
            string newgovernment = (string)json["newgovernment"];

            string oldeconomy = (string)json["oldeconomy"];
            string neweconomy = (string)json["neweconomy"];

            // EDDP does not report currently changes to secondary economies.

            string oldsecurity = (string)json["oldsecurity"];
            string newsecurity = (string)json["newsecurity"];

            // See if this matches our parameters
            string matchname = match(systemname, null, x, y, z, oldfaction, newfaction, oldstate, newstate);

            if (matchname != null)
            {
                // Fetch the system from our local repository (but don't create it if it doesn't exist)
                StarSystem system = StarSystemSqLiteRepository.Instance.GetStarSystem(systemname);
                if (system != null)
                {
                    // Update our local copy of the system
                    if (system.Faction is null)
                    {
                        system.Faction = new Faction();
                    }
                    if (newfaction != null)
                    {
                        system.Faction.name = newfaction;
                    }
                    if (newallegiance != null)
                    {
                        system.Faction.Allegiance = Superpower.FromName(newallegiance);
                    }
                    if (newgovernment != null)
                    {
                        system.Faction.Government = Government.FromName(newgovernment);
                    }
                    if (newstate != null)
                    {
                        system.Faction.FactionState = newstate;
                    }
                    if (newsecurity != null)
                    {
                        system.securityLevel = SecurityLevel.FromName(newsecurity);
                    }
                    if (neweconomy != null)
                    {
                        // EDDP uses invariant English economy names and does not report changes to secondary economies.
                        system.Economies = new List <Economy>()
                        {
                            Economy.FromName(neweconomy), system.Economies[1]
                        };
                    }
                    system.lastupdated = DateTime.UtcNow;
                    StarSystemSqLiteRepository.Instance.SaveStarSystem(system);
                }

                // Send an appropriate event
                Event @event = null;
                if (newfaction != null)
                {
                    @event = new SystemFactionChangedEvent(DateTime.UtcNow, matchname, systemname, oldfaction, newfaction);
                }
                else if (newstate != null)
                {
                    @event = new SystemStateChangedEvent(DateTime.UtcNow, matchname, systemname, oldstate, newstate);
                }
                if (@event != null)
                {
                    EDDI.Instance.enqueueEvent(@event);
                }
            }
        }