Example #1
0
        private DoRaidResult DoRaid()
        {
            if (this.MinimumDelay > 0)
            {
                return(DoRaidResult.Postpone);
            }

            string sendTroopsUrl = String.Format("build.php?id=39&tt=2&z={0}", this.Targets[this.TargetID].Z);
            string sendTroopForm = UpCall.PageQuery(this.VillageID, sendTroopsUrl);

            if (sendTroopForm == null)
            {
                return(DoRaidResult.SkipVillage);
            }

            if (!sendTroopForm.Contains("<form method=\"post\" name=\"snd\" action=\"build.php?id=39&amp;tt=2\">"))
            {
                return(DoRaidResult.SkipVillage);
            }

            if (!UpCall.NoAnimals(VillageID, Targets[this.TargetID].X, Targets[this.TargetID].Y))
            {
                UpCall.DebugLog("跳过有野怪的绿洲", DebugLevel.II);
                return(DoRaidResult.SkipVillage);
            }

            Dictionary <string, string> postData = RaidQueue.GetHiddenInputValues(sendTroopForm);

            postData.Add("c", ((int)this.RaidType).ToString());
            postData.Add("x", this.Targets[this.TargetID].X.ToString());
            postData.Add("y", this.Targets[this.TargetID].Y.ToString());
            int[] maxTroops = RaidQueue.GetMaxTroops(sendTroopForm);
            for (int i = 0; i < this.Troops.Length; i++)
            {
                if (this.Troops[i] > maxTroops[i])
                {
                    return(DoRaidResult.SkipVillage);
                }

                string troopKey    = String.Format("t{0}", i + 1);
                string troopNumber = this.Troops[i] == 0 ? "" : this.Troops[i].ToString();
                postData.Add(troopKey, troopNumber);
            }

            string confirmUrl  = "build.php?id=39&tt=2";
            string confirmForm = UpCall.PageQuery(this.VillageID, confirmUrl, postData);

            if (confirmForm == null)
            {
                return(DoRaidResult.SkipVillage);
            }

            Match errorMatch = Regex.Match(confirmForm, "<p class=\"error\">(.+)</p>");

            if (errorMatch.Success)
            {
                string err_msg = errorMatch.Groups[1].Value;
                err_msg = err_msg.Replace("<span>", "");
                err_msg = err_msg.Replace("</span>", "");
                string error = String.Format(
                    "Delete village {0}. Error: {1}",
                    this.Targets[this.TargetID], err_msg);
                this.UpCall.DebugLog(error, DebugLevel.W);
                return(DoRaidResult.DeleteVillage);
            }

            if (!confirmForm.Contains("<form method=\"post\" action=\"build.php?id=39&amp;tt=2\">"))
            {
                return(DoRaidResult.SkipVillage);
            }

            TimeSpan timeCost = RaidQueue.GetOneWayTimeCost(confirmForm);

            if (timeCost == TimeSpan.MinValue)
            {
                return(DoRaidResult.SkipVillage);
            }

            postData = RaidQueue.GetHiddenInputValues(confirmForm);
            if (RaidQueue.HasRadioInput("spy", confirmForm))
            {
                postData.Add("spy", ((int)this.SpyOption).ToString());
            }

            string result = this.UpCall.PageQuery(this.VillageID, confirmUrl, postData);

            if (result == null)
            {
                return(DoRaidResult.SkipVillage);
            }

            if (!this.MultipeRaids)
            {
                this.MinimumDelay = (int)timeCost.TotalSeconds * 2 + this.RandomDelay(30, 180);
            }

            TTInfo troopInfo = new TTInfo()
            {
                Tribe  = this.UpCall.TD.Tribe,
                Troops = this.Troops
            };
            string message = String.Format(
                "{0} {1} ({2}) => {3} {4}",
                this.RaidType,
                this.UpCall.TD.Villages[this.VillageID].Coord,
                this.VillageID,
                this.Targets[this.TargetID],
                troopInfo.FriendlyName);

            this.UpCall.DebugLog(message, DebugLevel.I);
            return(DoRaidResult.Success);
        }