Example #1
0
        public static PowerDetail Parse(JToken token)
        {
            var result = new PowerDetail();

            var armies = new List <Army>();

            if (token["army"] == null)
            {
                return(null);
            }
            foreach (var subToken in token["army"])
            {
                armies.Add(Army.Parse(subToken));
            }
            result.Armies = armies;
            var power = token["power"];

            result.Attackable = (bool)power["attackable"];
            result.Campaign   = (string)power["campaign"];
            result.Id         = (int)power["powerid"];
            result.Name       = (string)power["powername"];

            var previousPowers = new List <Power>();
            var prepower       = power["prepower"];

            if (prepower == null)
            {
                // Giặc Khăn Vàng, etc...
            }
            else
            {
                foreach (var subToken in prepower)
                {
                    previousPowers.Add(Power.Parse(subToken));
                }
            }
            result.PreviousPowers = previousPowers;

            var nextPowers = new List <Power>();
            var nextpower  = power["nextpower"];

            if (nextpower == null)
            {
                // TQQA, etc...
            }
            else
            {
                foreach (var subToken in nextpower)
                {
                    nextPowers.Add(Power.Parse(subToken));
                }
            }
            result.NextPowers = nextPowers;

            return(result);
        }
Example #2
0
        private async Task RefreshArmiesAsync()
        {
            try {
                Enabled = false;
                armies.Clear();

                var packet = await packetWriter.RefreshPowerAreaAsync(1);

                if (packet == null)
                {
                    return;
                }
                Debug.Assert(packet.CommandId == "33201");

                var powerIds      = new Queue <int>(Parse33201(packet));
                var addedPowerIds = powerIds.ToList();
                while (powerIds.Count > 0)
                {
                    var powerId     = powerIds.Dequeue();
                    var powerPacket = await packetWriter.RefreshPowerAsync(powerId);

                    if (powerPacket == null)
                    {
                        return;
                    }
                    Debug.Assert(powerPacket.CommandId == "33100");

                    var token = JToken.Parse(powerPacket.Message);
                    var power = PowerDetail.Parse(token);
                    if (power == null)
                    {
                        return;
                    }
                    var powerArmy = power.Armies.FirstOrDefault(army => army.Type == ArmyType.Army);
                    if (powerArmy != null)
                    {
                        armies.Add(powerArmy);
                    }
                    foreach (var nextPower in power.NextPowers)
                    {
                        if (addedPowerIds.Contains(nextPower.Id))
                        {
                            continue;
                        }
                        if (nextPower.Attackable)
                        {
                            addedPowerIds.Add(nextPower.Id);
                            powerIds.Enqueue(nextPower.Id);
                        }
                    }
                }
            } finally {
                Enabled = true;
            }
        }