private string EventsUrl(Fight fight, Friendly friend, SummaryEvents prev) { var start = prev != null ? prev.nextPageTimestamp : fight.start_time; var end = fight.end_time; return($"{URL_BASE}/summary-events/{id}/{fight.id}/{start}/{end}/{friend.id}/0/Any/0/-1.0.-1/0"); }
public async Task <SummaryEvents> GetEvents(Fight fight, Friendly friend) { SummaryEvents evts = null; if (id == null || this.fights == null || !this.fights.friendlies.Contains(friend)) { return(null); } try { if (fight.events == null) { fight.events = new Dictionary <Friendly, SummaryEvents>(); } fight.events.TryGetValue(friend, out evts); log.Log("skill download"); while (evts == null || (evts.nextPageTimestamp - fight.start_time) < 3 * 60 * 1000) { log.Log("downloading ..."); var url = EventsUrl(fight, friend, evts); var html = await Download(url); var serializer = new DataContractJsonSerializer(typeof(SummaryEvents)); var ms = new MemoryStream(Encoding.UTF8.GetBytes(html)); SummaryEvents ev = serializer.ReadObject(ms) as SummaryEvents; if (ev.events.Count == 0) { break; } ev.events = ev.events.Where(e => e.sourceID == friend.id && e.type == "cast" && e.ability.guid > 8).ToList(); if (evts != null) { evts.concat(ev); } else { evts = ev; fight.events.Add(friend, evts); } await Task.Delay(500); } log.Log("download ok"); return(evts); } catch (Exception) { return(null); } }
public async Task Play(Friendly friend, SummaryEvents se) { log.Log("start replay"); var events = se.events; if (events.Count == 0) { return; } Stop(); var ct = tokenSource.Token; IsReplay = true; server.AddCombatant(friend); var first = events.First(); var start = DateTime.Now; foreach (var ev in events) { if (ct.IsCancellationRequested || ev == null) { log.Log("stop replay"); IsReplay = false; break; } if (ev.sourceID != friend.id) { continue; } if (ev != first) { var dt = ev.timestamp - first.timestamp; var delay = start + TimeSpan.FromMilliseconds(dt) - DateTime.Now; if (delay > TimeSpan.Zero) { await Task.Delay(delay); } } server.UseAbility(ev.ability); } }
public void concat(SummaryEvents se) { events.AddRange(se.events); nextPageTimestamp = se.nextPageTimestamp; }