示例#1
0
        public static void Process(bool reload = false)
        {
            Dictionary <long, long> ownership = ProcessAsteroidOwnership();
            long owner = 0;
            int  count = 0;



            foreach (KeyValuePair <long, long> p in ownership)
            {
                if (!Instance.Leaderboard.ContainsKey(p.Key))
                {
                    if (owner == 0)
                    {
                        owner = p.Value;
                    }

                    count++;
                }
                else if (Instance.Leaderboard[p.Key] != ownership[p.Key])
                {
                    if (owner == 0)
                    {
                        owner = p.Value;
                    }

                    count++;
                }
            }

            if (count == 1)
            {
                MyObjectBuilder_Checkpoint.PlayerItem item = PlayerMap.Instance.GetPlayerItemFromPlayerId(owner);
                string name = "";
                if (item.Name != null)
                {
                    name = item.Name;
                }

                if (!reload)
                {
                    ChatUtil.SendPublicChat(string.Format("[CONQUEST]: {0} has conquered an asteroid.", name));
                }
            }
            else if (count > 1)
            {
                if (!reload)
                {
                    ChatUtil.SendPublicChat(string.Format("[CONQUEST]: Multiple asteroids have been conquered.  {0} asteroids have been claimed or changed ownership.", count));
                }
            }

            bool change = false;

            foreach (KeyValuePair <long, long> L in Instance.Leaderboard)            // Find if any asteroids are lost
            {
                if (!ownership.ContainsKey(L.Key))
                {
                    Instance.Leaderboard.Remove(L.Key);
                    MyObjectBuilder_Checkpoint.PlayerItem player = PlayerMap.Instance.GetPlayerItemFromPlayerId(L.Value);
                    ChatUtil.SendPublicChat(string.Format("[CONQUEST]: {0} has lost an asteroid.", player.Name));
                    change = true;
                    return;
                }
            }
            foreach (KeyValuePair <long, long> p in ownership)
            {
                if (!Instance.Leaderboard.ContainsKey(p.Key))
                {
                    Instance.Leaderboard.Add(p.Key, p.Value);
                    change = true;
                }
                else if (Instance.Leaderboard.ContainsKey(p.Key) && Instance.Leaderboard[p.Key] != p.Value)
                {
                    Instance.Leaderboard[p.Key] = p.Value;
                    change = true;
                }
            }

            if (change)
            {
                Save();
            }
        }