示例#1
0
        internal async Task LastKnownInfoForHunt(ushort id)
        {
            World  world;
            string e;
            HttpResponseMessage r = await Http.GetAsync(baseUrl + "api/worlds/" + Program.mem.GetWorldId().ToString());

            if (r.IsSuccessStatusCode)
            {
                e = await r.Content.ReadAsStringAsync();
            }
            else
            {
                return;
            }
            world = JsonConvert.DeserializeObject <World>(e);
            Hunt result = world.Hunts.First(x => x.Id == id);

            if (result == null)
            {
                return;
            }
            TimeSpan timeSinceLastReport = ServerTimeUtc.Subtract(result.LastReported);

            if (timeSinceLastReport < TimeSpan.Zero)
            {
                timeSinceLastReport = TimeSpan.Zero;
            }
            ChatMessage cm         = new ChatMessage();
            double      TotalHours = Math.Floor(timeSinceLastReport.TotalHours);

            if (!result.LastAlive)
            {
                cm.MessageString = string.Format(Resources.LKIHuntKilled, result.Name);
                if (Resources.LKIHuntKilled.Contains("<time>"))//japanese case
                {
                    cm.MessageString += cm.MessageString.Replace("<time>", string.Format(Resources.LKIHoursMinutes, TotalHours, timeSinceLastReport.Minutes));
                }
                else if (timeSinceLastReport.TotalDays > 90)
                {
                    cm.MessageString = string.Format(Resources.LKIHuntNotReported, result.Name);
                }
                else if (timeSinceLastReport.TotalHours > 72)
                {
                    cm.MessageString += string.Format(Resources.LKIHours, TotalHours);
                }
                else if (timeSinceLastReport.TotalHours < 1)
                {
                    cm.MessageString += string.Format(Resources.LKIMinutes, Math.Floor(timeSinceLastReport.TotalMinutes));
                }
                else
                {
                    cm.MessageString += string.Format(Resources.LKIHoursMinutes, TotalHours, timeSinceLastReport.Minutes);
                }
            }
            else
            {
                ushort zid = GetZoneId(result.Id);
                cm = ChatMessage.MakePosChatMessage(string.Format(Resources.LKILastSeenAt, result.Name), zid, result.LastX, result.LastY, string.Format(Resources.LKIHoursMinutes, TotalHours, timeSinceLastReport.Minutes));
            }
            await Program.mem.WriteChatMessage(cm);
        }