Example #1
0
        private async Task <UseItemResult> UseItem(string itemId, string target = null)
        {
            var url = "/items/use/" + itemId;

            if (target != null)
            {
                url += "?target=" + target;
            }

            var response = await Post(url);

            var result = response.StartsWith("No", StringComparison.Ordinal) || response.Contains("Invalid item GUID") ? null : JsonConvert.DeserializeObject <UseItemResult>(response);

            if (result == null)
            {
                result = UseItemResult.NullObject;
            }
            result.Messages = CthulhuStateProcessor.ProcessMessages(result.Messages).ToList();

            if (result.BonusItems.Any())
            {
                _state.Items.AddRange(result.BonusItems);
            }

            result.LogMessages();

            return(result);
        }
Example #2
0
        public async Task <PollResponse> PostForPoints()
        {
            for (int i = 0; i < 3; i++)
            {
                var result = await Post("/points");

                var response = JsonConvert.DeserializeObject <PollResponse>(result);
                if (response == null)
                {
                    Log.Write("Got empty reponse from /points. Trying again (1/3)");
                    await Task.Delay(100);

                    continue;
                }

                response.Messages = CthulhuStateProcessor.ProcessMessages(response.Messages).ToList();

                response.LogMessages();

                if (response.Item != null)
                {
                    _state.Items.AddRange(response.ExtractItems());
                }

                return(response);
            }

            Log.Write("Could not load points");
            throw new Exception("Could not load points");
        }