Beispiel #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);
        }
Beispiel #2
0
        private void DoEvade()
        {
            string sendTroopsUrl = String.Format("build.php?id=39&tt=2&z={0}", tpEvadePoint.Z);
            string sendTroopForm = UpCall.PageQuery(VillageID, sendTroopsUrl);

            if (sendTroopForm == null ||
                !sendTroopForm.Contains("<form method=\"POST\" name=\"snd\" action=\"build.php?id=39&tt=2\">"))
            {
                MinimumDelay = 0;
                return;
            }

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

            postData.Add("c", "2");
            postData.Add("x", tpEvadePoint.X.ToString());
            postData.Add("y", tpEvadePoint.Y.ToString());
            ReinforceToop = RaidQueue.GetMaxTroops(sendTroopForm);
            for (int i = 0; i < this.bTroopFilter.Length; i++)
            {
                if (bTroopFilter[i])
                {
                    continue;
                }

                ReinforceToop[i] = 0;
            }
            for (int i = 0; i < ReinforceToop.Length; i++)
            {
                string troopKey    = String.Format("t{0}", i + 1);
                string troopNumber = ReinforceToop[i] == 0 ? "" : ReinforceToop[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)
            {
                MinimumDelay = 0;
                return;
            }

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

            if (errorMatch.Success)
            {
                string error = String.Format(
                    "Delete village {0}. Error: {1}",
                    tpEvadePoint,
                    errorMatch.Groups[1].Value);
                UpCall.DebugLog("部队未能发出,因为:" + error, DebugLevel.W);
                MinimumDelay = nMinInterval;
                return;
            }

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

            TimeSpan timeCost = RaidQueue.GetOneWayTimeCost(confirmForm);

            if (timeCost == TimeSpan.MinValue)
            {
                MinimumDelay = nMinInterval;
                evade_status = EvadeStatus.NoAtkDetected;
                return;
            }

            postData = RaidQueue.GetHiddenInputValues(confirmForm);

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

            if (result == null)
            {
                MinimumDelay = 0;
                return;
            }

            evade_status      = EvadeStatus.Evaded;
            ReinforceTimeCost = (int)timeCost.TotalSeconds;
            MinimumDelay      = ReinforceTimeCost + RandomDelay(5, 10);

            TTInfo troopInfo = new TTInfo()
            {
                Tribe  = UpCall.TD.Tribe,
                Troops = ReinforceToop
            };
            string message = String.Format(
                "部队回避 {0} ({1}) => {2} {3}",
                this.UpCall.TD.Villages[this.VillageID].Coord,
                this.VillageID,
                this.tpEvadePoint,
                troopInfo.FriendlyName);

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