Beispiel #1
0
        /// <summary>Claims the worker reward asynchronous.</summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="workType">Type of the work.</param>
        /// <returns></returns>
        public static async Task <string> ClaimWorkerRewardAsync(this HzPluginBase plugin, WorkType workType)
        {
            var content = new PostContent();

            switch (workType)
            {
            case WorkType.Quest:
                var rewards = plugin.Account.Data.ActiveQuest.GetRewards;
                content = plugin.Account.DefaultRequestContent("claimQuestRewards")
                          .AddKeyValue("discard_item", "false")
                          .AddKeyValue("create_new", "true")
                          .AddLog($"[Quest] Claim: XP:{rewards.xp} Coins:{rewards.coins} Premium:{rewards.premium} Honor:{rewards.honor} Item:{rewards.item}");
                content.LogObject.Tooltip = plugin.Account.Data.ActiveQuest.GetItem;
                break;

            case WorkType.Training:
                content = plugin.Account.DefaultRequestContent("claimTrainingRewards")
                          .AddLog($"[Train] Claim Point:{plugin.Account.Data.ActiveTraining.StatType}");
                break;

            case WorkType.WorldbossAttack:
                content = plugin.Account.DefaultRequestContent("finishWorldbossAttack")
                          .AddLog($"[Worldboss] Claim Point:{plugin.Account.Data.ActiveTraining.StatType}");
                break;
            }

            content.AddKeyValue("rct", "2");
            var error = await content.PostToHzAsync();

            return(error);
        }
Beispiel #2
0
        /// <summary>Checks for worker complete asynchronous.</summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="workType">Type of the work.</param>
        /// <returns></returns>
        public static async Task <string> CheckForWorkerCompleteAsync(this HzPluginBase plugin, WorkType workType)
        {
            var content = new PostContent();

            switch (workType)
            {
            case WorkType.Quest:
                content = plugin.Account.DefaultRequestContent("checkForQuestComplete")
                          .AddLog($"[Quest] END: ID:{plugin.Account.Data.ActiveQuest.id} Duration:{plugin.Account.Data.ActiveQuest.duration / 60}")
                          .AddKeyValue("reload_user", "true");
                break;

            case WorkType.Training:
                content = plugin.Account.DefaultRequestContent("checkForTrainingComplete")
                          .AddLog($"[Train] END: TrainStat:{plugin.Account.Data.ActiveTraining.StatType}");
                break;

            case WorkType.WorldbossAttack:
                content = plugin.Account.DefaultRequestContent("checkForWorldbossAttackComplete")
                          .AddLog($"[Worldboss] END: Battle:{plugin.Account.Data.ActiveWorldbossAttack.battle_id}");
                break;
            }

            content.AddKeyValue("rct", 2);
            var error = await content.PostToHzAsync();

            return(error);
        }
Beispiel #3
0
        /// <summary>Adds the log.</summary>
        /// <param name="content">The content.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static PostContent AddLog(this PostContent content, string text)
        {
            content.LogObject.Text = text;
            content.LogObject.Time = DateTime.Now;
            content.Account.Plugins.Log.Add(content.LogObject);

            return(content);
        }
Beispiel #4
0
        /// <summary>Aborts the worker asynchronous.</summary>
        /// <param name="plugin">The plugin.</param>
        /// <returns></returns>
        public static async Task <string> AbortWorkerAsync(this HzPluginBase plugin)
        {
            var content = new PostContent();

            if (plugin.Account.ActiveWorker?.WorkerType == WorkType.Quest)
            {
                content = plugin.Account.DefaultRequestContent("abortQuest")
                          .AddLog($"[Train] Abbort Training");
            }
            else if (plugin.Account.ActiveWorker?.WorkerType == WorkType.Training)
            {
                content = plugin.Account.DefaultRequestContent("abortTraining")
                          .AddLog($"[Train] Abbort Training");
            }

            return(await content.AddKeyValue("rct", "2")
                   .PostToHzAsync());
        }
Beispiel #5
0
        /// <summary>Gets the default HttpRequest content.</summary>
        /// <param name="action">The action.</param>
        /// <param name="account">The account.</param>
        /// <returns></returns>
        public static PostContent DefaultRequestContent(this HzAccount account, string action)
        {
            var UserId        = account.User?.id ?? 0;
            var UserSessionId = account.User?.session_id ?? "0";
            var content       = new PostContent();

            content.Account = account;
            content.Content = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("device_type", "web"),
                new KeyValuePair <string, string>("client_version", $"flash_{account.Config.FlashVersion}"),
                new KeyValuePair <string, string>("user_id", UserId.ToString()),
                new KeyValuePair <string, string>("user_session_id", UserSessionId),
                new KeyValuePair <string, string>("auth", HzConstants.MD5Hash(action, UserId.ToString())),
                new KeyValuePair <string, string>("action", action)
            };

            return(content);
        }
Beispiel #6
0
        /// <summary>Posts the specified content to the server.</summary>
        /// <param name="content">The content.</param>
        /// <returns>The error string or null</returns>
        public static async Task <string> PostToHzAsync(this PostContent content)
        {
            content.Account.Log.AddRequestLog(content.Content.FirstOrDefault(keyval => keyval.Key == "action").Value);
            content.LogObject.RequestState = RequestState.Pending;
            using (var formUrlEncodedContent = new FormUrlEncodedContent(content.Content))
            {
                var response = await client.PostAsync(content.RequestUrl, formUrlEncodedContent);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    var obj   = JObject.Parse(json);
                    var error = obj["error"];
                    if (!string.IsNullOrWhiteSpace(error.ToString()))
                    {
                        content.LogObject.RequestState = RequestState.Error;
                        content.LogObject.Tooltip      = error.Value <string>();
                        content.Account.Log.AddErrorLog(error.Value <string>());
                        await content.Account.Plugins.RaiseOnHandleError(error.Value <string>());

                        // MessageBox.Show(error.Value<string>());
                        return(error.Value <string>());
                    }
                    content.Account.MergeNewData(obj);
                    content.LogObject.RequestState = RequestState.Success;
                    //content.Account.Log.Add($"Action {content.Content.FirstOrDefault(a => a.Key == "action").Value} Success");

                    //   return obj;
                }
                else
                {
                    content.LogObject.RequestState = RequestState.Error;
                }
            }
            return(null);
        }
Beispiel #7
0
 /// <summary>Adds the key value.</summary>
 /// <param name="content">The content.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static PostContent AddKeyValue(this PostContent content, object key, object value)
 {
     content.Content.Add(new KeyValuePair <string, string>(key.ToString(), value.ToString()));
     return(content);
 }