コード例 #1
0
        private MazeStatus Play_DoTowerMaze(ref Comm.CommFetchOptions opts, int map_stage)
        {
            Utils.LoggerNotifications("<color=#a07000>Running through maze tower " + map_stage.ToString() + "...</color>");

            string maze_tower_basic_data = this.GetGameData(ref this.opts, "maze", "Show", "MapStageId=" + map_stage.ToString(), false);
            JObject maze_tower_basic_data_JSON = JObject.Parse(maze_tower_basic_data);

            bool free_reset = maze_tower_basic_data.Replace(" ", string.Empty).Replace("\"", string.Empty).Contains("FreeReset:1");

            bool tower_is_cleared = true;
            for (int layer_in_mazetower_check = 1; layer_in_mazetower_check <= 10; layer_in_mazetower_check++)
            {
                string current_layer = this.GetGameData(ref this.opts, "maze", "Info", "Layer=" + layer_in_mazetower_check.ToString() + "&MapStageId=" + map_stage.ToString());
                JObject current_layer_JSON = JObject.Parse(current_layer);

                if (Utils.CInt(current_layer_JSON["status"]) > 0)
                {
                    try
                    {
                        if (!current_layer.Replace("\"", "").Replace(" ", "").Contains("IsFinish:true")) tower_is_cleared = false;
                        if ((Utils.True("Game_MazeTowerChests")) && (Utils.CInt(current_layer_JSON["data"]["RemainBoxNum"]) > 0)) tower_is_cleared = false;
                        if ((Utils.True("Game_MazeTowerMonsters")) && (Utils.CInt(current_layer_JSON["data"]["RemainMonsterNum"]) > 0)) tower_is_cleared = false;
                    }
                    catch
                    {
                        break;
                    }
                }
                else
                    break;

                if (!tower_is_cleared)
                    break;
            }

            if (tower_is_cleared)
            {
                if (free_reset)
                    this.GetGameData(ref this.opts, "maze", "Reset", "MapStageId=" + map_stage.ToString(), false);
                else
                {
                    Utils.Logger("<b><color=#ff0000>THIS TOWER MAZE HAS BEEN CLEARED AND NO FREE RESETS ARE AVAILABLE FOR IT!</color></b>");
                    return MazeStatus.Skipped_No_Reset_Available;
                }
            }
            else
                Utils.Logger("<b>TOWER MAZE HAS BEEN STARTED IN A PREVIOUS SESSION -- RESUMING!</b>");

            int max_floor = 100;
            for (int layer_in_mazetower = 1; layer_in_mazetower <= max_floor; layer_in_mazetower++)
            {
                string current_layer_JSON = this.GetGameData(ref this.opts, "maze", "Info", "Layer=" + layer_in_mazetower.ToString() + "&MapStageId=" + map_stage.ToString());
                JObject current_layer_data = JObject.Parse(current_layer_JSON);

                if (Utils.CInt(current_layer_data["status"]) == 0)
                    break;

                max_floor = Utils.CInt(current_layer_data["data"]["TotalLayer"]);

                string[] current_layer_items = Utils.SubStringsDups(Utils.ChopperBlank(current_layer_JSON.Replace(" ", ""), "\"Items\":[", "]"), ",");

                for (int current_item_index = 0; current_item_index < current_layer_items.Length; current_item_index++)
                {
                    int current_item_type = Utils.CInt(current_layer_items[current_item_index]);

                    if ((current_item_type == 2) || (current_item_type == 3))
                    {
                        Utils.Logger("Layer #" + layer_in_mazetower.ToString() + ", slot #" + (current_item_index + 1).ToString() + ", type " + MapType(current_item_type));

                        bool want_to_fight_this_type = true;
                        if ((current_item_type == 2) && (!Utils.True("Game_MazeTowerChests"))) want_to_fight_this_type = false;
                        if ((current_item_type == 3) && (!Utils.True("Game_MazeTowerMonsters"))) want_to_fight_this_type = false;

                        if (want_to_fight_this_type)
                        {
                            string fight_info = this.GetGameData(ref this.opts, "maze", "Battle", "Layer=" + layer_in_mazetower.ToString() + "&ItemIndex=" + current_item_index.ToString() + "&MapStageId=" + map_stage.ToString() + "&manual=1", false);
                            JObject fight_JSON = JObject.Parse(fight_info);

                            string battle_id = "";
                            if (fight_info.Contains("\"BattleId\""))
                                battle_id = fight_JSON["data"]["BattleId"].ToString();

                            if (!Utils.ValidText(battle_id))
                            {
                                if (fight_info.Contains("\"message\":"))
                                {
                                    if (fight_info.ToLower().Contains("not enough energy"))
                                    {
                                        Utils.Logger("<b>RAN OUT OF ENERGY -- TRY AGAIN LATER!</b>");
                                        return MazeStatus.Out_Of_Energy;
                                    }

                                    Utils.LoggerNotifications("<color=#aa0000><b>Problem picking a maze tower fight: " + fight_JSON["message"].ToString() + "</b></color>");
                                    Utils.LoggerNotifications("<color=#aa0000><b>In map " + map_stage.ToString() + ", floor " + layer_in_mazetower.ToString() + ", position " + (current_item_index + 1).ToString() + " (" + MapType(current_item_type) + ")</b></color>");
                                    continue;
                                }

                                Utils.LoggerNotifications("<color=#aa0000><b>Problem picking a maze tower fight: odd server response</b>");
                                Utils.LoggerNotifications("<color=#aa0000><b>" + fight_info + "</b>");
                                Utils.LoggerNotifications("<color=#aa0000><b>In map " + map_stage.ToString() + ", floor " + layer_in_mazetower.ToString() + ", position " + (current_item_index + 1).ToString() + " (" + MapType(current_item_type) + ")</b></color>");
                                //return MazeStatus.Error;
                                continue;
                            }

                            string battle_result_original = this.GetGameData(ref this.opts, "maze", "ManualBattle", "battleid=" + battle_id + "&stage=&manual=0", false, "user_mapfight" + map_stage.ToString() + "_level" + layer_in_mazetower.ToString() + "_" + MapType(current_item_type) + "_at" + current_item_index.ToString());
                            string battle_result = Utils.ChopperBlank(battle_result_original, "\"Award\":", "}") + ",";

                            string reward_gold = Utils.ChopperBlank(battle_result, "\"Coins\":", ",").Replace("\"", "").Trim();
                            string reward_EXP = Utils.ChopperBlank(battle_result, "\"Exp\":", ",").Replace("\"", "").Trim();
                            string reward_card = Utils.ChopperBlank(battle_result, "\"CardId\":", ",").Replace("\"", "").Trim();

                            Utils.Logger();
                            if (Utils.CInt(reward_gold) > 0) Utils.Logger("<b>Gold earned from maze tower fight:</b> " + Utils.CInt(reward_gold).ToString("#,##0"));
                            if (Utils.CInt(reward_EXP) > 0) Utils.Logger("<b>Experience earned from maze tower fight:</b> " + Utils.CInt(reward_EXP).ToString("#,##0"));
                            if (Utils.CInt(reward_card) > 0) Utils.Logger("<b>Card earned from maze tower fight:</b> " + this.FriendlyReplacerInbound("[Card #" + reward_card + "]"));
                            Utils.Logger();

                            Utils.LoggerNotifications("<color=#ffa000>Maze tower " + MapType(current_item_type) + " fight on map " + map_stage.ToString() + ", floor " + layer_in_mazetower.ToString() + ": " + new GameReward(battle_result_original).AllAwards + "</color>");

                            if (battle_result_original.Replace(" ", "").Replace("\"", "").Contains("{IsClear:1,"))
                            {
                                string maze_tower_completed_result = Utils.ChopperBlank(battle_result_original, "{\"IsClear\"", "}") + ",";

                                string completion_reward_gold = Utils.ChopperBlank(maze_tower_completed_result, "\"Coins\":", ",").Replace("\"", "").Trim();
                                string completion_reward_EXP = Utils.ChopperBlank(maze_tower_completed_result, "\"Exp\":", ",").Replace("\"", "").Trim();
                                string completion_reward_card = Utils.ChopperBlank(maze_tower_completed_result, "\"CardId\":", ",").Replace("\"", "").Trim();

                                if (Utils.CInt(completion_reward_gold) > 0) Utils.Logger("<b>Gold earned from maze tower completion:</b> " + Utils.CInt(completion_reward_gold).ToString("#,##0"));
                                if (Utils.CInt(completion_reward_EXP) > 0) Utils.Logger("<b>Experience earned from maze tower completion:</b> " + Utils.CInt(completion_reward_EXP).ToString("#,##0"));
                                if (Utils.CInt(completion_reward_card) > 0) Utils.Logger("<b>Card earned from maze tower completion:</b> " + this.FriendlyReplacerInbound("[Card #" + completion_reward_card + "]"));
                                Utils.Logger();

                                string output_rewards = "";
                                if (Utils.CInt(completion_reward_gold) > 0) output_rewards += ", " + Utils.CInt(completion_reward_gold).ToString("#,##0") + " gold";
                                if (Utils.CInt(completion_reward_EXP) > 0) output_rewards += ", " + Utils.CInt(completion_reward_EXP).ToString("#,##0") + " EXP";
                                if (Utils.CInt(completion_reward_card) > 0) output_rewards += ", " + this.FriendlyReplacerInbound("[Card #" + completion_reward_card + "]");
                                if (output_rewards.Length > 0)
                                    Utils.LoggerNotifications("<color=#ffa000>Maze tower completion rewards for map " + map_stage.ToString() + ": " + output_rewards.Substring(2) + "</color>");
                            }
                        }
                    }
                }

                if (current_layer_JSON.Replace("\"", "").Replace(" ", "").ToLower().Contains("isfinish:true")) continue;

                for (int current_item_index = 0; current_item_index < current_layer_items.Length; current_item_index++)
                {
                    int current_item_type = Utils.CInt(current_layer_items[current_item_index]);

                    if (current_item_type == 5)
                    {
                        string fight_info = this.GetGameData(ref this.opts, "maze", "Battle", "Layer=" + layer_in_mazetower.ToString() + "&ItemIndex=" + current_item_index.ToString() + "&MapStageId=" + map_stage.ToString() + "&manual=1", false);
                        JObject fight_JSON = JObject.Parse(fight_info);

                        string battle_id = "";
                        if (fight_info.Contains("\"BattleId\""))
                            battle_id = fight_JSON["data"]["BattleId"].ToString();

                        if (string.IsNullOrEmpty(battle_id))
                        {
                            if (fight_info.Contains("\"message\":"))
                            {
                                if (fight_info.ToLower().Contains("not enough energy"))
                                {
                                    Utils.Logger("<b>RAN OUT OF ENERGY -- TRY AGAIN LATER!</b>");
                                    return MazeStatus.Out_Of_Energy;
                                }

                                Utils.LoggerNotifications("<color=#aa0000><b>Problem picking a maze tower fight: " + fight_JSON["message"].ToString() + "</b></color>");
                                Utils.LoggerNotifications("<color=#aa0000><b>In map " + map_stage.ToString() + ", floor " + layer_in_mazetower.ToString() + ", position " + (current_item_index + 1).ToString() + " (" + MapType(current_item_type) + ")</b></color>");
                                continue;
                            }

                            Utils.LoggerNotifications("<color=#aa0000><b>Problem picking a maze tower fight: odd server response</b></color>");
                            Utils.LoggerNotifications("<color=#aa0000><b>" + fight_info + "</b></color>");
                            Utils.LoggerNotifications("<color=#aa0000><b>In map " + map_stage.ToString() + ", floor " + layer_in_mazetower.ToString() + ", position " + (current_item_index + 1).ToString() + " (" + MapType(current_item_type) + ")</b></color>");
                            continue;
                            //return MazeStatus.Error;
                        }

                        string battle_result_original = this.GetGameData(ref this.opts, "maze", "ManualBattle", "battleid=" + battle_id + "&stage=&manual=0", false, "user_mapfight" + map_stage.ToString() + "_level" + layer_in_mazetower.ToString() + "_" + MapType(current_item_type) + "_at" + current_item_index.ToString());

                        if (battle_result_original.Replace(" ", "").Replace("\"", "").Contains("{IsClear:1,"))
                        {
                            string maze_tower_completed_result = Utils.ChopperBlank(battle_result_original, "{\"IsClear\"", "}") + ",";

                            string completion_reward_gold = Utils.ChopperBlank(maze_tower_completed_result, "\"Coins\":", ",").Replace("\"", "").Trim();
                            string completion_reward_EXP = Utils.ChopperBlank(maze_tower_completed_result, "\"Exp\":", ",").Replace("\"", "").Trim();
                            string completion_reward_card = Utils.ChopperBlank(maze_tower_completed_result, "\"CardId\":", ",").Replace("\"", "").Trim();

                            Utils.Logger();
                            if (Utils.CInt(completion_reward_gold) > 0) Utils.Logger("<b>Gold earned from maze tower completion:</b> " + Utils.CInt(completion_reward_gold).ToString("#,##0"));
                            if (Utils.CInt(completion_reward_EXP) > 0) Utils.Logger("<b>Experience earned from maze tower completion:</b> " + Utils.CInt(completion_reward_EXP).ToString("#,##0"));
                            if (Utils.CInt(completion_reward_card) > 0) Utils.Logger("<b>Card earned from maze tower completion:</b> " + this.FriendlyReplacerInbound("[Card #" + completion_reward_card + "]"));
                            Utils.Logger();

                            string output_rewards = "";
                            if (Utils.CInt(completion_reward_gold) > 0) output_rewards += ", " + Utils.CInt(completion_reward_gold).ToString("#,##0") + " gold";
                            if (Utils.CInt(completion_reward_EXP) > 0) output_rewards += ", " + Utils.CInt(completion_reward_EXP).ToString("#,##0") + " EXP";
                            if (Utils.CInt(completion_reward_card) > 0) output_rewards += ", " + this.FriendlyReplacerInbound("[Card #" + completion_reward_card + "]");
                            if (output_rewards.Length > 0)
                                Utils.LoggerNotifications("<color=#ffa000>Maze tower completion rewards for map " + map_stage.ToString() + ": " + output_rewards.Substring(2) + "</color>");
                        }

                    }
                }

            }

            return MazeStatus.Completed;
        }
コード例 #2
0
        public string GetGameData__internal(ref Comm.CommFetchOptions opts, string page, string action, string post_data = "", bool log = false, string log_to = "", bool only_if_valid = true)
        {
            opts.POST_Data = post_data;

            //log = true;

            Utils.Logger();

            string result = Utils.CStr(Comm.Download(this.GAME_URL + page + ".php?do=" + action + "&v=" + this.seq_id.ToString() + GameTagToUse, opts));
            Utils.Logger("<b>HTTP request:</b> " + this.GAME_URL + page + ".php?do=" + action + "&v=" + this.seq_id.ToString() + GameTagToUse);
            if (post_data.Trim().Length > 0)
                Utils.Logger("<b>POST'ing:</b> " + opts.POST_Data);
            this.seq_id++;
            frmMain.AuthSerial++;

            try
            {
                // converts \u0123 into actual unicode characters
                if (result.Contains("\\u"))
                    result = this.regex_unicode_replacer.Replace(result, match => ((char)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString());
            }
            catch { }

            if (Want_Debug && log /* && (!only_if_valid || result.Contains("\"status\":1,")) */)
            {
                try
                {
                    if (!System.IO.Directory.Exists(Utils.AppFolder + "\\Game Data"))
                        System.IO.Directory.CreateDirectory(Utils.AppFolder + "\\Game Data");

                    string request_info = string.Empty;

                    request_info += "Data requested:  " + DateTime.Now.ToString() + "  (local time)\r\n";
                    request_info += "Data from server page:   " + page + ".php?do=" + action + "&v=" + this.seq_id.ToString() + GameTagToUse + "\r\n";
                    if (Utils.ValidText(post_data))
                        request_info += "Data POST'ed to this page:  " + post_data + "\r\n";

                    Utils.FileOverwrite(Utils.AppFolder + "\\Game Data\\" + GameAbbreviation(Service) + ", " + RequestMeaning(page, action, log_to) + " (" + Utils.GetAppSetting("Login_Account").Trim().Replace("@", ".").Replace(":", ".") + "), request.txt", request_info);
                    Utils.FileOverwrite(Utils.AppFolder + "\\Game Data\\" + GameAbbreviation(Service) + ", " + RequestMeaning(page, action, log_to) + " (" + Utils.GetAppSetting("Login_Account").Trim().Replace("@", ".").Replace(":", ".") + "), data.json", JSBeautifyLib.JSBeautify.BeautifyMe(result));
                }
                catch (Exception ex)
                {
                    Utils.Chatter(Errors.GetShortErrorDetails(ex));
                }
            }

            Utils.Logger(result);
            Utils.Logger();

            return result;
        }
コード例 #3
0
        public string GetGameData(ref Comm.CommFetchOptions opts, string page, string action, string post_data = "", bool log = false, string log_to = "", bool only_if_valid = true)
        {
            string result = string.Empty;

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    result = this.GetGameData__internal(ref opts, page, action, post_data, log, log_to, only_if_valid);

                    if (!string.IsNullOrEmpty(result) && !result.StartsWith("[")) // automatic retries on connection failures
                        break;
                }
                catch { }
            }

            return result;
        }
コード例 #4
0
 public string GetGameData(ref Comm.CommFetchOptions opts, string page, string action, bool log = false, string log_to = "", bool only_if_valid = true)
 {
     return this.GetGameData(ref opts, page, action, "", log, log_to, only_if_valid);
 }
コード例 #5
0
ファイル: GameClient.cs プロジェクト: boffrey/EKUnleashed
        public string GetGameData__internal(ref Comm.CommFetchOptions opts, string page, string action, string post_data = "", bool log = false, string log_to = "", bool only_if_valid = true)
        {
            // Add global throttle to all connections
            if (Want_Throttle && (Connection_Throttle_MS > 1))
            {
                if (GetGameData_dtLastRequest != DateTime.MinValue)
                {
                    if ((DateTime.Now - GetGameData_dtLastRequest).TotalMilliseconds < Connection_Throttle_MS)
                    {
                        Utils.StartMethodMultithreadedAndWait(() =>
                        {
                            System.Threading.Thread.Sleep((int)Connection_Throttle_MS - 1);
                            return;
                        }, (double)Connection_Throttle_MS);
                    }
                }

                this.GetGameData_dtLastRequest = DateTime.Now;
            }

            opts.POST_Data = post_data;

            //log = true;

            Utils.Logger();

            string result = Utils.CStr(Comm.Download(this.GAME_URL + page + ".php?do=" + action + "&v=" + this.seq_id.ToString() + GameTagToUse, opts));
            Utils.Logger("<b>HTTP request:</b> " + this.GAME_URL + page + ".php?do=" + action + "&v=" + this.seq_id.ToString() + GameTagToUse);
            if (post_data.Trim().Length > 0)
                Utils.Logger("<b>POST'ing:</b> " + opts.POST_Data);
            this.seq_id++;
            frmMain.AuthSerial++;

            try
            {
                // converts \u0123 into actual unicode characters
                if (result.Contains("\\u"))
                    result = this.regex_unicode_replacer.Replace(result, match => ((char)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString());
            }
            catch { }

            if (Want_Debug && log /* && (!only_if_valid || result.Contains("\"status\":1,")) */)
            {
                try
                {
                    if (!System.IO.Directory.Exists(Utils.AppFolder + "\\Game Data"))
                        System.IO.Directory.CreateDirectory(Utils.AppFolder + "\\Game Data");

                    string request_info = string.Empty;

                    request_info += "Data requested:  " + DateTime.Now.ToString() + "  (local time)\r\n";
                    request_info += "Data from server page:   " + page + ".php?do=" + action + "&v=" + this.seq_id.ToString() + GameTagToUse + "\r\n";
                    if (Utils.ValidText(post_data))
                        request_info += "Data POST'ed to this page:  " + post_data + "\r\n";

                    Utils.FileOverwrite(Utils.AppFolder + "\\Game Data\\" + GameAbbreviation(Service) + ", " + RequestMeaning(page, action, log_to) + " (" + Utils.GetAppSetting("Login_Account").Trim().Replace("@", ".").Replace(":", ".") + "), request.txt", request_info);
                    Utils.FileOverwrite(Utils.AppFolder + "\\Game Data\\" + GameAbbreviation(Service) + ", " + RequestMeaning(page, action, log_to) + " (" + Utils.GetAppSetting("Login_Account").Trim().Replace("@", ".").Replace(":", ".") + "), data.json", JSBeautifyLib.JSBeautify.BeautifyMe(result));
                }
                catch (Exception ex)
                {
                    Utils.Chatter(Errors.GetShortErrorDetails(ex));
                }
            }
            
            // PSIV: moved to a setting, with constant overwrites this could lead to potentially heavy IO, bad news for SSD wear/tear
            if (StoreReplays)
                this.StoreReplay(page + action, result);

            Utils.Logger(result);
            Utils.Logger();

            return result;
        }
コード例 #6
0
ファイル: Comm.cs プロジェクト: boffrey/EKUnleashed
 public static string PageFetch(string sURL, Comm.CommFetchOptions options)
 {
     options.WantCookies = true;
     return Utils.CStr(Comm.Download(sURL, options));
 }