public static void ExcelSave(ExportType exportType, EncounterBase data, TeraData teraData) { if ((exportType & (ExportType.Excel | ExportType.ExcelTemp)) == 0) { return; } lock (Savelock) //can't save 2 excel files at one time { NpcInfo boss = teraData.NpcDatabase.GetOrPlaceholder(ushort.Parse(data.areaId), uint.Parse(data.bossId)); var dir = Path.Combine( exportType.HasFlag(ExportType.Excel)//if regular export, save in documents, otherwise temp ? SettingsHelper.Instance.GetDocumentsPath() : SettingsHelper.Instance.GetTempFolderPath(), $"exports/{boss.Area.Replace(":", "-")}"); Directory.CreateDirectory(dir); var fname = Path.Combine(dir, $"{boss.Name.Replace(":", "-")} {DateTimeTools.UnixTimeStampToDateTime(data.encounterUnixEpoch).ToString("yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture)}.xlsx"); FileInfo file = new FileInfo(fname); if (!file.Exists) { using (ExcelPackage package = new ExcelPackage(file)) { ExcelWorksheet ws = package.Workbook.Worksheets.Add("Boss"); var linkStyle = package.Workbook.Styles.CreateNamedStyle("HyperLink"); //This one is language dependent linkStyle.Style.Font.UnderLine = true; linkStyle.Style.Font.Color.SetColor(Color.Blue); ws.DefaultRowHeight = 30; ws.Cells.Style.Font.Size = 14; ws.Cells.Style.Font.Name = "Arial"; ws.Cells[1, 1].Value = $"{boss.Area}: {boss.Name} {TimeSpan.FromSeconds(double.Parse(data.fightDuration)).ToString(@"mm\:ss")}"; ws.Cells[1, 1, 1, 6].Merge = true; ws.Cells[1, 1, 1, 8].Style.Font.Bold = true; ws.Cells[1, 7].Value = long.Parse(data.partyDps); ws.Cells[1, 7].Style.Numberformat.Format = @"#,#00,\k\/\s"; ws.Cells[2, 1].Value = "Ic"; ws.Cells[2, 1].Style.Font.Color.SetColor(Color.Transparent); ws.Cells[2, 2].Value = "Name"; ws.Cells[2, 3].Value = "Deaths"; ws.Cells[2, 4].Value = "Death time"; ws.Cells[2, 5].Value = "Damage %"; ws.Cells[2, 6].Value = "Crit %"; ws.Cells[2, 7].Value = "DPS"; ws.Cells[2, 8].Value = "Damage"; int i = 2; foreach (var user in data.members.OrderByDescending(x => long.Parse(x.playerTotalDamage))) { i++; ws.Cells[i, 1].Value = i - 2; AddImage(ws, i, 1, Invert( new Bitmap( SettingsHelper.Instance.GetImage( (PlayerClass)Enum.Parse(typeof(PlayerClass), user.playerClass))))); ws.Cells[i, 2].Value = $"{user.playerServer}: {user.playerName}"; ws.Cells[i, 2].Hyperlink = CreateUserSheet(package.Workbook, user, teraData); ws.Cells[i, 3].Value = long.Parse(user.playerDeaths); ws.Cells[i, 4].Value = long.Parse(user.playerDeathDuration); ws.Cells[i, 4].Style.Numberformat.Format = @"0\s"; ws.Cells[i, 5].Value = double.Parse(user.playerTotalDamagePercentage) / 100; ws.Cells[i, 5].Style.Numberformat.Format = "0.0%"; ws.Cells[i, 6].Value = double.Parse(user.playerAverageCritRate) / 100; ws.Cells[i, 6].Style.Numberformat.Format = "0.0%"; ws.Cells[i, 7].Value = long.Parse(user.playerDps); ws.Cells[i, 7].Style.Numberformat.Format = @"#,#0,\k\/\s"; ws.Cells[i, 8].Value = long.Parse(user.playerTotalDamage); ws.Cells[i, 8].Style.Numberformat.Format = @"#,#0,\k"; } ws.Cells[1, 8].Formula = $"SUM(H3:H{i})"; ws.Cells[1, 8].Style.Numberformat.Format = @"#,#0,\k"; var border = ws.Cells[1, 1, i, 8].Style.Border; border.Bottom.Style = border.Top.Style = border.Left.Style = border.Right.Style = ExcelBorderStyle.Thick; ws.Cells[2, 1, i, 8].AutoFilter = true; int j = i + 3; ws.Cells[j, 1].Value = "Ic"; ws.Cells[j, 1].Style.Font.Color.SetColor(Color.Transparent); ws.Cells[j, 2].Value = "Debuff name"; ws.Cells[j, 2, j, 7].Merge = true; ws.Cells[j, 8].Value = "%"; ws.Cells[j, 2, j, 8].Style.Font.Bold = true; foreach (var buf in data.debuffUptime) { j++; var hotdot = teraData.HotDotDatabase.Get(int.Parse(buf.Key)); ws.Cells[j, 1].Value = j - i - 3; AddImage(ws, j, 1, BTD.Icons.GetBitmap(hotdot.IconName)); ws.Cells[j, 2].Value = hotdot.Name; if (!string.IsNullOrEmpty(hotdot.Tooltip)) { ws.Cells[j, 2].AddComment("" + hotdot.Tooltip, "info"); } ws.Cells[j, 2, j, 7].Merge = true; ws.Cells[j, 8].Value = double.Parse(buf.Value) / 100; ws.Cells[j, 8].Style.Numberformat.Format = "0%"; } border = ws.Cells[i + 3, 1, j, 8].Style.Border; border.Bottom.Style = border.Top.Style = border.Left.Style = border.Right.Style = ExcelBorderStyle.Thick; ws.Column(1).Width = 5.6; ws.Column(2).AutoFit(); ws.Column(3).AutoFit(); ws.Column(4).AutoFit(); ws.Column(5).AutoFit(); ws.Column(6).AutoFit(); ws.Column(7).AutoFit(); ws.Column(8).Width = 17; ws.Column(2).Width = GetTrueColumnWidth(ws.Column(2).Width); ws.Column(3).Width = GetTrueColumnWidth(ws.Column(3).Width); ws.Column(4).Width = GetTrueColumnWidth(ws.Column(4).Width); ws.Column(5).Width = GetTrueColumnWidth(ws.Column(5).Width); ws.Column(6).Width = GetTrueColumnWidth(ws.Column(6).Width); ws.Column(7).Width = GetTrueColumnWidth(ws.Column(7).Width); ws.Cells[1, 1, j, 8].Style.VerticalAlignment = ExcelVerticalAlignment.Center; ws.Cells[1, 1, j, 8].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; ws.PrinterSettings.FitToPage = true; package.Workbook.Properties.Title = boss.Name; package.Workbook.Properties.Author = "CasualMeter"; package.Workbook.Properties.Company = "github.com/lunyx github.com/Gl0 github.com/neowutran"; package.Save(); } } if (exportType == ExportType.ExcelTemp && File.Exists(fname)) { Process.Start(fname); } } }
public static void ToTeraDpsApi(ExportType exportType, DamageTracker damageTracker, TeraData teraData) { if (exportType == ExportType.None) { return; } //if we want to upload, primary target must be dead if (exportType.HasFlag(ExportType.Upload) && !damageTracker.IsPrimaryTargetDead) { return; } var exportToExcel = (exportType & (ExportType.Excel | ExportType.ExcelTemp)) != 0; //if we're not exporting to excel and credentials aren't fully entered, return //if (!exportToExcel // && (string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsToken) // || string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsUser))) // return; //ignore if not a boss var entity = damageTracker.PrimaryTarget; if (!(entity?.Info.Boss ?? false)) { return; } var abnormals = damageTracker.Abnormals; bool timedEncounter = false; //Nightmare desolarus if (entity.Info.HuntingZoneId == 759 && entity.Info.TemplateId == 1003) { timedEncounter = true; } var firstHit = damageTracker.StatsByUser.SelectMany(x => x.SkillLog).Where(x => x.Target == entity).Min(x => x.Time as DateTime?) ?? new DateTime(0); var lastHit = damageTracker.StatsByUser.SelectMany(x => x.SkillLog).Where(x => x.Target == entity).Max(x => x.Time as DateTime?) ?? new DateTime(0); var firstTick = firstHit.Ticks; var lastTick = lastHit.Ticks; var interval = lastTick - firstTick; var seconds = interval / TimeSpan.TicksPerSecond; if (seconds == 0) { return; } long totaldamage; if (timedEncounter) { totaldamage = damageTracker.StatsByUser.SelectMany(x => x.SkillLog) .Where(x => x.Time >= firstHit && x.Time <= lastHit) .Sum(x => (long)x.Damage); } else { totaldamage = damageTracker.StatsByUser.SelectMany(x => x.SkillLog) .Where(x => x.Target == entity) .Sum(x => (long)x.Damage); } var partyDps = TimeSpan.TicksPerSecond * totaldamage / interval; var teradpsData = new EncounterBase { encounterUnixEpoch = DateTimeTools.DateTimeToUnixTimestamp(damageTracker.LastAttack?.ToUniversalTime() ?? DateTime.UtcNow), areaId = entity.Info.HuntingZoneId + "", bossId = entity.Info.TemplateId + "", fightDuration = seconds + "", partyDps = partyDps + "" }; foreach (var debuff in abnormals.Get(entity).OrderByDescending(x => x.Value.Duration(firstTick, lastTick))) { long percentage = debuff.Value.Duration(firstTick, lastTick) * 100 / interval; if (percentage == 0) { continue; } teradpsData.debuffUptime.Add(new KeyValuePair <string, string>( debuff.Key.Id + "", percentage + "" )); } foreach (var user in damageTracker.StatsByUser.OrderByDescending(x => x.Dealt.Damage)) { var filteredSkillog = timedEncounter ? user.SkillLog.Where(x => x.Time >= firstHit && x.Time <= lastHit).ToList() : user.SkillLog.Where(x => x.Target == entity).ToList(); long damage = filteredSkillog.Sum(x => x.Damage); if (damage <= 0) { continue; } var teradpsUser = new Members(); teradpsUser.playerTotalDamage = damage + ""; var buffs = abnormals.Get(user.Player); teradpsUser.playerClass = user.Class.ToString(); teradpsUser.playerName = user.Name; teradpsUser.playerServer = SettingsHelper.Instance.BasicTeraData.Servers.GetServerName(user.Player.ServerId); teradpsUser.playerAverageCritRate = Math.Round(100 * (double)filteredSkillog.Count(x => x.IsCritical && x.Damage > 0) / filteredSkillog.Count(x => x.Damage > 0)) + ""; teradpsUser.healCrit = user.Player.IsHealer ? Math.Round(100 * (double)filteredSkillog.Count(x => x.IsCritical && x.Heal > 0) / filteredSkillog.Count(x => x.Heal > 0)) + "" : null; teradpsUser.playerDps = TimeSpan.TicksPerSecond * damage / interval + ""; teradpsUser.playerTotalDamagePercentage = damage * 100 / totaldamage + ""; var death = buffs.Death; teradpsUser.playerDeaths = death.Count(firstTick, lastTick) + ""; teradpsUser.playerDeathDuration = death.Duration(firstTick, lastTick) / TimeSpan.TicksPerSecond + ""; var aggro = buffs.Aggro(entity); teradpsUser.aggro = 100 * aggro.Duration(firstTick, lastTick) / interval + ""; foreach (var buff in buffs.Times.OrderByDescending(x => x.Value.Duration(firstTick, lastTick))) { long percentage = (buff.Value.Duration(firstTick, lastTick) * 100 / interval); if (percentage == 0) { continue; } teradpsUser.buffUptime.Add(new KeyValuePair <string, string>( buff.Key.Id + "", percentage + "" )); } var aggregated = new List <AggregatedSkillResult>(); var collection = new SynchronizedObservableCollection <SkillResult>(); foreach (var skill in filteredSkillog) { collection.Add(skill); if (aggregated.All(asr => !skill.IsSameSkillAs(asr))) { aggregated.Add(new AggregatedSkillResult(skill.SkillShortName, skill.IsHeal, AggregationType.Name, collection)); } } foreach (var skill in aggregated.OrderByDescending(x => x.Damage)) { var skillLog = new SkillLog(); var skilldamage = skill.Damage; if (skilldamage == 0) { continue; } skillLog.skillAverageCrit = skill.AverageCrit + ""; skillLog.skillAverageWhite = skill.AverageWhite + ""; skillLog.skillCritRate = Math.Round(skill.CritRate * 100) + ""; skillLog.skillDamagePercent = Math.Round(skill.DamagePercent * 100) + ""; skillLog.skillHighestCrit = skill.HighestCrit + ""; skillLog.skillHits = skill.Hits + ""; skillLog.skillId = teraData.SkillDatabase.GetSkillByPetName(skill.NpcInfo?.Name, user.Player.RaceGenderClass)?.Id.ToString() ?? skill.SkillId.ToString(); skillLog.skillLowestCrit = skill.LowestCrit + ""; skillLog.skillTotalDamage = skilldamage + ""; teradpsUser.skillLog.Add(skillLog); } teradpsData.members.Add(teradpsUser); } //export to excel if specified if (exportToExcel) { Task.Run(() => ExcelExport.ExcelSave(exportType, teradpsData, teraData)); } //return if we don't need to upload if (!exportType.HasFlag(ExportType.Upload)) { return; } /* * Validation, without that, the server cpu will be burning \o */ var areaId = int.Parse(teradpsData.areaId); if ( //areaId != 886 && //areaId != 467 && //areaId != 767 && //areaId != 768 && //areaId != 468 && areaId != 770 && areaId != 769 && areaId != 916 && areaId != 969 && areaId != 970 && areaId != 950 ) { return; } try { using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(40); var response = client.GetAsync("http://moongourd.com/shared/servertime"); var timediff = (response.Result.Headers.Date.Value.UtcDateTime.Ticks - DateTime.UtcNow.Ticks) / TimeSpan.TicksPerSecond; teradpsData.encounterUnixEpoch += timediff; } } catch (Exception) { Debug.WriteLine("Get server time error"); return; } var json = JsonConvert.SerializeObject(teradpsData, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Task.Run(() => Send(entity, json, 3)); }
public static void ExcelSave(ExportType exportType, EncounterBase data, TeraData teraData) { if ((exportType & (ExportType.Excel | ExportType.ExcelTemp)) == 0) return; lock (Savelock) //can't save 2 excel files at one time { NpcInfo boss = teraData.NpcDatabase.GetOrPlaceholder(ushort.Parse(data.areaId), uint.Parse(data.bossId)); var dir = Path.Combine( exportType.HasFlag(ExportType.Excel)//if regular export, save in documents, otherwise temp ? SettingsHelper.Instance.GetDocumentsPath() : SettingsHelper.Instance.GetTempFolderPath(), $"exports/{boss.Area.Replace(":", "-")}"); Directory.CreateDirectory(dir); var fname = Path.Combine(dir, $"{boss.Name.Replace(":", "-")} {DateTimeTools.UnixTimeStampToDateTime(data.encounterUnixEpoch).ToString("yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture)}.xlsx"); FileInfo file = new FileInfo(fname); if (!file.Exists) { using (ExcelPackage package = new ExcelPackage(file)) { ExcelWorksheet ws = package.Workbook.Worksheets.Add("Boss"); var linkStyle = package.Workbook.Styles.CreateNamedStyle("HyperLink"); //This one is language dependent linkStyle.Style.Font.UnderLine = true; linkStyle.Style.Font.Color.SetColor(Color.Blue); ws.DefaultRowHeight = 30; ws.Cells.Style.Font.Size = 14; ws.Cells.Style.Font.Name = "Arial"; ws.Cells[1, 1].Value = $"{boss.Area}: {boss.Name} {TimeSpan.FromSeconds(double.Parse(data.fightDuration)).ToString(@"mm\:ss")}"; ws.Cells[1, 1, 1, 6].Merge = true; ws.Cells[1, 1, 1, 8].Style.Font.Bold = true; ws.Cells[1, 7].Value = long.Parse(data.partyDps); ws.Cells[1, 7].Style.Numberformat.Format = @"#,#00,\k\/\s"; ws.Cells[2, 1].Value = "Ic"; ws.Cells[2, 1].Style.Font.Color.SetColor(Color.Transparent); ws.Cells[2, 2].Value = "Name"; ws.Cells[2, 3].Value = "Deaths"; ws.Cells[2, 4].Value = "Death time"; ws.Cells[2, 5].Value = "Damage %"; ws.Cells[2, 6].Value = "Crit %"; ws.Cells[2, 7].Value = "DPS"; ws.Cells[2, 8].Value = "Damage"; int i = 2; foreach (var user in data.members.OrderByDescending(x => long.Parse(x.playerTotalDamage))) { i++; ws.Cells[i, 1].Value = i - 2; AddImage(ws, i, 1, Invert( new Bitmap( SettingsHelper.Instance.GetImage( (PlayerClass) Enum.Parse(typeof (PlayerClass), user.playerClass))))); ws.Cells[i, 2].Value = $"{user.playerServer}: {user.playerName}"; ws.Cells[i, 2].Hyperlink = CreateUserSheet(package.Workbook, user, teraData); ws.Cells[i, 3].Value = long.Parse(user.playerDeaths); ws.Cells[i, 4].Value = long.Parse(user.playerDeathDuration); ws.Cells[i, 4].Style.Numberformat.Format = @"0\s"; ws.Cells[i, 5].Value = double.Parse(user.playerTotalDamagePercentage)/100; ws.Cells[i, 5].Style.Numberformat.Format = "0.0%"; ws.Cells[i, 6].Value = double.Parse(user.playerAverageCritRate)/100; ws.Cells[i, 6].Style.Numberformat.Format = "0.0%"; ws.Cells[i, 7].Value = long.Parse(user.playerDps); ws.Cells[i, 7].Style.Numberformat.Format = @"#,#0,\k\/\s"; ws.Cells[i, 8].Value = long.Parse(user.playerTotalDamage); ws.Cells[i, 8].Style.Numberformat.Format = @"#,#0,\k"; } ws.Cells[1, 8].Formula = $"SUM(H3:H{i})"; ws.Cells[1, 8].Style.Numberformat.Format = @"#,#0,\k"; var border = ws.Cells[1, 1, i, 8].Style.Border; border.Bottom.Style = border.Top.Style = border.Left.Style = border.Right.Style = ExcelBorderStyle.Thick; ws.Cells[2, 1, i, 8].AutoFilter = true; int j = i + 3; ws.Cells[j, 1].Value = "Ic"; ws.Cells[j, 1].Style.Font.Color.SetColor(Color.Transparent); ws.Cells[j, 2].Value = "Debuff name"; ws.Cells[j, 2, j, 7].Merge = true; ws.Cells[j, 8].Value = "%"; ws.Cells[j, 2, j, 8].Style.Font.Bold = true; foreach (var buf in data.debuffUptime) { j++; var hotdot = teraData.HotDotDatabase.Get(int.Parse(buf.Key)); ws.Cells[j, 1].Value = j - i - 3; AddImage(ws, j, 1, BTD.Icons.GetBitmap(hotdot.IconName)); ws.Cells[j, 2].Value = hotdot.Name; if (!string.IsNullOrEmpty(hotdot.Tooltip)) ws.Cells[j, 2].AddComment("" + hotdot.Tooltip, "info"); ws.Cells[j, 2, j, 7].Merge = true; ws.Cells[j, 8].Value = double.Parse(buf.Value)/100; ws.Cells[j, 8].Style.Numberformat.Format = "0%"; } border = ws.Cells[i + 3, 1, j, 8].Style.Border; border.Bottom.Style = border.Top.Style = border.Left.Style = border.Right.Style = ExcelBorderStyle.Thick; ws.Column(1).Width = 5.6; ws.Column(2).AutoFit(); ws.Column(3).AutoFit(); ws.Column(4).AutoFit(); ws.Column(5).AutoFit(); ws.Column(6).AutoFit(); ws.Column(7).AutoFit(); ws.Column(8).Width = 17; ws.Column(2).Width = GetTrueColumnWidth(ws.Column(2).Width); ws.Column(3).Width = GetTrueColumnWidth(ws.Column(3).Width); ws.Column(4).Width = GetTrueColumnWidth(ws.Column(4).Width); ws.Column(5).Width = GetTrueColumnWidth(ws.Column(5).Width); ws.Column(6).Width = GetTrueColumnWidth(ws.Column(6).Width); ws.Column(7).Width = GetTrueColumnWidth(ws.Column(7).Width); ws.Cells[1, 1, j, 8].Style.VerticalAlignment = ExcelVerticalAlignment.Center; ws.Cells[1, 1, j, 8].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; ws.PrinterSettings.FitToPage = true; package.Workbook.Properties.Title = boss.Name; package.Workbook.Properties.Author = "CasualMeter"; package.Workbook.Properties.Company = "github.com/lunyx github.com/Gl0 github.com/neowutran"; package.Save(); } } if (exportType == ExportType.ExcelTemp && File.Exists(fname)) Process.Start(fname); } }
public static void ToTeraDpsApi(SDespawnNpc despawnNpc, DamageTracker damageTracker, EntityTracker entityTracker, TeraData teraData) { if (!despawnNpc.Dead) { return; } var entity = entityTracker.GetOrPlaceholder(despawnNpc.Npc) as NpcEntity; if (!(entity?.Info.Boss ?? false)) { return; } if (!SettingsHelper.Instance.Settings.ExcelExport && (string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsToken) || string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsUser) || !SettingsHelper.Instance.Settings.SiteExport) ) { return; } var abnormals = damageTracker.Abnormals; bool timedEncounter = false; //Nightmare desolarus if (entity.Info.HuntingZoneId == 759 && entity.Info.TemplateId == 1003) { timedEncounter = true; } var firstHit = damageTracker.StatsByUser.SelectMany(x => x.SkillLog).Where(x => x.Target == entity).Min(x => x.Time as DateTime?) ?? new DateTime(0); var lastHit = damageTracker.StatsByUser.SelectMany(x => x.SkillLog).Where(x => x.Target == entity).Max(x => x.Time as DateTime?) ?? new DateTime(0); var firstTick = firstHit.Ticks; var lastTick = lastHit.Ticks; var interval = lastTick - firstTick; var seconds = interval / TimeSpan.TicksPerSecond; if (seconds == 0) { return; } long totaldamage; if (timedEncounter) { totaldamage = damageTracker.StatsByUser.SelectMany(x => x.SkillLog) .Where(x => x.Time >= firstHit && x.Time <= lastHit) .Sum(x => x.Damage); } else { totaldamage = damageTracker.StatsByUser.SelectMany(x => x.SkillLog) .Where(x => x.Target == entity) .Sum(x => x.Damage); } var partyDps = TimeSpan.TicksPerSecond * totaldamage / interval; var teradpsData = new EncounterBase { areaId = entity.Info.HuntingZoneId + "", bossId = entity.Info.TemplateId + "", fightDuration = seconds + "", partyDps = partyDps + "" }; foreach (var debuff in abnormals.Get(entity)) { long percentage = debuff.Value.Duration(firstTick, lastTick) * 100 / interval; if (percentage == 0) { continue; } teradpsData.debuffUptime.Add(new KeyValuePair <string, string>( debuff.Key.Id + "", percentage + "" )); } foreach (var user in damageTracker.StatsByUser) { var filteredSkillog = timedEncounter ? user.SkillLog.Where(x => x.Time >= firstHit && x.Time <= lastHit).ToList() : user.SkillLog.Where(x => x.Target == entity).ToList(); long damage = filteredSkillog.Sum(x => x.Damage); if (damage <= 0) { continue; } var teradpsUser = new Members(); teradpsUser.playerTotalDamage = damage + ""; var buffs = abnormals.Get(user.Player); teradpsUser.playerClass = user.Class.ToString(); teradpsUser.playerName = user.Name; teradpsUser.playerServer = SettingsHelper.Instance.BasicTeraData.Servers.GetServerName(user.Player.ServerId); teradpsUser.playerAverageCritRate = Math.Round(100 * (double)filteredSkillog.Count(x => x.IsCritical && x.Damage > 0) / filteredSkillog.Count(x => x.Damage > 0), 1) + ""; teradpsUser.healCrit = user.Player.IsHealer ? Math.Round(100 * (double)filteredSkillog.Count(x => x.IsCritical && x.Heal > 0) / filteredSkillog.Count(x => x.Heal > 0), 1) + "" : null; teradpsUser.playerDps = TimeSpan.TicksPerSecond * damage / interval + ""; teradpsUser.playerTotalDamagePercentage = damage * 100 / totaldamage + ""; var death = buffs.Death; teradpsUser.playerDeaths = death.Count(firstTick, lastTick) + ""; teradpsUser.playerDeathDuration = death.Duration(firstTick, lastTick) / TimeSpan.TicksPerSecond + ""; var aggro = buffs.Aggro(entity); teradpsUser.aggro = 100 * aggro.Duration(firstTick, lastTick) / interval + ""; foreach (var buff in buffs.Times) { long percentage = (buff.Value.Duration(firstTick, lastTick) * 100 / interval); if (percentage == 0) { continue; } teradpsUser.buffUptime.Add(new KeyValuePair <string, string>( buff.Key.Id + "", percentage + "" )); } var aggregated = new List <AggregatedSkillResult>(); var collection = new ThreadSafeObservableCollection <SkillResult>(); foreach (var skill in filteredSkillog) { collection.Add(skill); if (aggregated.All(asr => !skill.IsSameSkillAs(asr))) { aggregated.Add(new AggregatedSkillResult(skill.SkillShortName, skill.IsHeal, AggregationType.Name, collection)); } } foreach (var skill in aggregated) { var skillLog = new SkillLog(); var skilldamage = skill.Damage; if (skilldamage == 0) { continue; } skillLog.skillAverageCrit = skill.AverageCrit + ""; skillLog.skillAverageWhite = skill.AverageWhite + ""; skillLog.skillCritRate = Math.Round(skill.CritRate * 100, 1) + ""; skillLog.skillDamagePercent = Math.Round(skill.DamagePercent * 100, 1) + ""; skillLog.skillHighestCrit = skill.HighestCrit + ""; skillLog.skillHits = skill.Hits + ""; skillLog.skillId = teraData.SkillDatabase.GetSkillByPetName(skill.NpcInfo?.Name, user.Player.RaceGenderClass)?.Id.ToString() ?? skill.SkillId.ToString(); skillLog.skillLowestCrit = skill.LowestCrit + ""; skillLog.skillTotalDamage = skilldamage + ""; teradpsUser.skillLog.Add(skillLog); } teradpsData.members.Add(teradpsUser); } if (SettingsHelper.Instance.Settings.ExcelExport) { Task.Run(() => ExcelExport.ExcelSave(teradpsData, teraData)); } if (string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsToken) || string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsUser) || !SettingsHelper.Instance.Settings.SiteExport) { return; } /* * Validation, without that, the server cpu will be burning \o */ var areaId = int.Parse(teradpsData.areaId); if ( areaId != 886 && areaId != 467 && areaId != 767 && areaId != 768 && areaId != 470 && areaId != 468 ) { return; } if (int.Parse(teradpsData.partyDps) < 2000000 && areaId != 468) { return; } string json = JsonConvert.SerializeObject(teradpsData, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Task.Run(() => Send(entity, json, 3)); }
public static void ToTeraDpsApi(ExportType exportType, DamageTracker damageTracker, TeraData teraData) { if (exportType == ExportType.None) return; //if we want to upload, primary target must be dead if (exportType.HasFlag(ExportType.Upload) && !damageTracker.IsPrimaryTargetDead) return; var exportToExcel = (exportType & (ExportType.Excel | ExportType.ExcelTemp)) != 0; //if we're not exporting to excel and credentials aren't fully entered, return //if (!exportToExcel // && (string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsToken) // || string.IsNullOrEmpty(SettingsHelper.Instance.Settings.TeraDpsUser))) // return; //ignore if not a boss var entity = damageTracker.PrimaryTarget; if (!(entity?.Info.Boss ?? false)) return; var abnormals = damageTracker.Abnormals; bool timedEncounter = false; //Nightmare desolarus if (entity.Info.HuntingZoneId == 759 && entity.Info.TemplateId == 1003) { timedEncounter = true; } var firstHit = damageTracker.StatsByUser.SelectMany(x => x.SkillLog).Where(x => x.Target == entity).Min(x => x.Time as DateTime?) ?? new DateTime(0); var lastHit = damageTracker.StatsByUser.SelectMany(x => x.SkillLog).Where(x => x.Target == entity).Max(x => x.Time as DateTime?) ?? new DateTime(0); var firstTick = firstHit.Ticks; var lastTick = lastHit.Ticks; var interval = lastTick - firstTick; var seconds = interval/TimeSpan.TicksPerSecond; if (seconds == 0) return; long totaldamage; if (timedEncounter) totaldamage = damageTracker.StatsByUser.SelectMany(x => x.SkillLog) .Where(x => x.Time >= firstHit && x.Time <= lastHit) .Sum(x => x.Damage); else totaldamage = damageTracker.StatsByUser.SelectMany(x => x.SkillLog) .Where(x => x.Target == entity) .Sum(x => x.Damage); var partyDps = TimeSpan.TicksPerSecond * totaldamage / interval; var teradpsData = new EncounterBase { encounterUnixEpoch = DateTimeTools.DateTimeToUnixTimestamp(damageTracker.LastAttack?.ToUniversalTime() ?? DateTime.UtcNow), areaId = entity.Info.HuntingZoneId + "", bossId = entity.Info.TemplateId + "", fightDuration = seconds + "", partyDps = partyDps + "" }; foreach (var debuff in abnormals.Get(entity).OrderByDescending(x=>x.Value.Duration(firstTick, lastTick))) { long percentage = debuff.Value.Duration(firstTick, lastTick) * 100 / interval; if(percentage == 0) { continue; } teradpsData.debuffUptime.Add(new KeyValuePair<string, string>( debuff.Key.Id+"", percentage+"" )); } foreach (var user in damageTracker.StatsByUser.OrderByDescending(x=>x.Dealt.Damage)) { var filteredSkillog = timedEncounter ? user.SkillLog.Where(x => x.Time >= firstHit && x.Time <= lastHit).ToList() : user.SkillLog.Where(x => x.Target == entity).ToList(); long damage=filteredSkillog.Sum(x => x.Damage); if (damage <= 0) continue; var teradpsUser = new Members(); teradpsUser.playerTotalDamage = damage + ""; var buffs = abnormals.Get(user.Player); teradpsUser.playerClass = user.Class.ToString(); teradpsUser.playerName = user.Name; teradpsUser.playerServer = SettingsHelper.Instance.BasicTeraData.Servers.GetServerName(user.Player.ServerId); teradpsUser.playerAverageCritRate = Math.Round(100 * (double)filteredSkillog.Count(x => x.IsCritical && x.Damage > 0) / filteredSkillog.Count(x => x.Damage > 0)) + ""; teradpsUser.healCrit = user.Player.IsHealer ? Math.Round(100 * (double)filteredSkillog.Count(x => x.IsCritical && x.Heal > 0) / filteredSkillog.Count(x => x.Heal > 0)) + "" : null; teradpsUser.playerDps = TimeSpan.TicksPerSecond * damage / interval + ""; teradpsUser.playerTotalDamagePercentage = damage * 100 / totaldamage + ""; var death = buffs.Death; teradpsUser.playerDeaths = death.Count(firstTick, lastTick) + ""; teradpsUser.playerDeathDuration = death.Duration(firstTick, lastTick)/TimeSpan.TicksPerSecond + ""; var aggro = buffs.Aggro(entity); teradpsUser.aggro = 100 * aggro.Duration(firstTick, lastTick) / interval + ""; foreach (var buff in buffs.Times.OrderByDescending(x => x.Value.Duration(firstTick, lastTick))) { long percentage = (buff.Value.Duration(firstTick, lastTick) * 100 / interval); if (percentage == 0) { continue; } teradpsUser.buffUptime.Add(new KeyValuePair<string, string>( buff.Key.Id + "", percentage + "" )); } var aggregated = new List<AggregatedSkillResult>(); var collection = new List<SkillResult>(); foreach (var skill in filteredSkillog) { collection.Add(skill); if (aggregated.All(asr => !skill.IsSameSkillAs(asr))) aggregated.Add(new AggregatedSkillResult(skill.SkillShortName, skill.IsHeal, AggregationType.Name, CollectionHelper.Instance.CreateSyncedCollection(collection))); } foreach (var skill in aggregated.OrderByDescending(x=>x.Damage)) { var skillLog = new SkillLog(); var skilldamage = skill.Damage; if (skilldamage == 0) continue; skillLog.skillAverageCrit = skill.AverageCrit + ""; skillLog.skillAverageWhite = skill.AverageWhite + ""; skillLog.skillCritRate = Math.Round(skill.CritRate * 100) + ""; skillLog.skillDamagePercent = Math.Round(skill.DamagePercent * 100) + ""; skillLog.skillHighestCrit = skill.HighestCrit + ""; skillLog.skillHits = skill.Hits + ""; skillLog.skillId = teraData.SkillDatabase.GetSkillByPetName(skill.NpcInfo?.Name,user.Player.RaceGenderClass)?.Id.ToString() ?? skill.SkillId.ToString(); skillLog.skillLowestCrit = skill.LowestCrit + ""; skillLog.skillTotalDamage = skilldamage + ""; teradpsUser.skillLog.Add(skillLog); } teradpsData.members.Add(teradpsUser); } //export to excel if specified if (exportToExcel) Task.Run(() => ExcelExport.ExcelSave(exportType, teradpsData, teraData)); //return if we don't need to upload if (!exportType.HasFlag(ExportType.Upload)) return; /* Validation, without that, the server cpu will be burning \o */ var areaId = int.Parse(teradpsData.areaId); if ( //areaId != 886 && //areaId != 467 && //areaId != 767 && //areaId != 768 && //areaId != 468 && areaId != 770 && areaId != 769 && areaId != 916 && areaId != 969 && areaId != 970 && areaId != 950 ) { return; } //if (int.Parse(teradpsData.partyDps) < 2000000 && areaId != 468) //{ // return; //} try { using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(40); var response = client.GetAsync("http://moongourd.com/shared/servertime"); var timediff = (response.Result.Headers.Date.Value.UtcDateTime.Ticks - DateTime.UtcNow.Ticks) / TimeSpan.TicksPerSecond; teradpsData.encounterUnixEpoch += timediff; } } catch (Exception e) { Debug.WriteLine("Get server time error"); return; } var json = JsonConvert.SerializeObject(teradpsData, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Task.Run(() => Send(entity, json, 3)); }