From 0fee662f5622510f20f3a90a26a1fc3eaab30872 Mon Sep 17 00:00:00 2001 From: Adrienne Walker Date: Sun, 1 Jan 2017 15:44:20 -0800 Subject: [PATCH 1/3] Add relative enmity and time to death Update enmity.js to calculate relative enmity, as that is somewhat easier to read than absolute enmity over long fights. Additionally, keep a history of target health to calculate time until death. This adds two new html overlays to show this info. enmity_relative is an abbreviated enmity list with only relative enmity. targetinfo_mini is a short list of numbers intended for being closer to the middle of the screen. --- EnmityPlugin/resources/enmity.js | 107 ++++++++++++++++++-- EnmityPlugin/resources/enmity_relative.html | 48 +++++++++ EnmityPlugin/resources/targetinfo_mini.html | 39 +++++++ 3 files changed, 188 insertions(+), 6 deletions(-) create mode 100644 EnmityPlugin/resources/enmity_relative.html create mode 100644 EnmityPlugin/resources/targetinfo_mini.html diff --git a/EnmityPlugin/resources/enmity.js b/EnmityPlugin/resources/enmity.js index 95186fa..41c16f7 100644 --- a/EnmityPlugin/resources/enmity.js +++ b/EnmityPlugin/resources/enmity.js @@ -38,7 +38,15 @@ var noTarget = { Distance: '--', EffectiveDistance: '--', HorizontalDistance: '--', -} + TimeToDeath: '', +}; + +var noEntry = { + Enmity: 0, + EnmityString: '--', + RelativeEnmity: 0, + RelativeEnmityString: '--', +}; // フィルタ Vue.filter('jobclass', function (v) { @@ -68,6 +76,7 @@ var enmity = new Vue({ collapsed: false, target: null, entries: null, + myEntry: null, hide: false }, attached: function() { @@ -80,17 +89,103 @@ var enmity = new Vue({ }, methods: { update: function(e) { + var enmity = e.detail.Enmity; + + // Entries sorted by enmity, and keys are integers. + // If only one, show absolute value (otherwise confusingly 0 for !isMe). + var max = 0; + if (Object.keys(enmity.Entries).length > 1) { + max = enmity.Entries[0].isMe ? enmity.Entries[1].Enmity : enmity.Entries[0].Enmity; + } + var foundMe = false; + for (var i = 0; i < enmity.Entries.length; ++i) { + var e = enmity.Entries[i]; + e.RelativeEnmity = e.Enmity - max; + if (e.RelativeEnmity != 0) { + var numStr = (e.RelativeEnmity > 0 ? "+" : "") + e.RelativeEnmity; + e.RelativeEnmityString = numStr.replace(/(\d)(?=(\d{3})+$)/g, '$1,'); + } else { + e.RelativeEnmityString = '--'; + } + if (e.isMe) { + foundMe = true; + this.myEntry = e; + } + } + if (!foundMe) { + this.myEntry = noEntry; + } + if (enmity.Target) { + this.processTarget(enmity.Target); + } + this.updated = true; - this.entries = e.detail.Enmity.Entries; - this.target = e.detail.Enmity.Target ? e.detail.Enmity.Target : noTarget; - this.hide = (hideNoTarget && e.detail.Enmity.Target == null); + this.entries = enmity.Entries; + this.target = enmity.Target ? enmity.Target : noTarget; + this.hide = (hideNoTarget && enmity.Target == null); }, updateState: function(e) { this.locked = e.detail.isLocked; }, toggleCollapse: function() { this.collapsed = !this.collapsed; - } - } + }, + toTimeString: function(time) { + var totalSeconds = Math.floor(time); + var minutes = Math.floor(totalSeconds / 60); + var seconds = totalSeconds % 60; + var str = ""; + if (minutes > 0) { + str = minutes + "m"; + } + str += seconds + "s"; + return str; + }, + processTarget: function(target) { + target.TimeToDeath = ''; + + // Throw away entries older than this. + var keepHistoryMs = 30 * 1000; + // Sample period between recorded entries. + var samplePeriodMs = 60; + + var now = +new Date(); + if (!this.targetHistory) { + this.targetHistory = {}; + } + if (!this.targetHistory[target.ID]) { + this.targetHistory[target.ID] = { + hist: [], + lastUpdated: now, + }; + } + var h = this.targetHistory[target.ID]; + if (now - h.lastUpdated > samplePeriodMs) { + h.lastUpdated = now; + // Don't update if hp is unchanged to keep estimate more stable. + if (h.hist.length == 0 || h.hist[h.hist.length - 1].hp != target.CurrentHP) { + h.hist.push({time: now, hp: target.CurrentHP}); + } + } + + while (h.hist.length > 0 && now - h.hist[0].time > keepHistoryMs) { + h.hist.shift(); + } + + if (h.hist.length < 2) { + return; + } + + var first = h.hist[0]; + var last = h.hist[h.hist.length - 1]; + var totalSeconds = (last.time - first.time) / 1000; + if (first.hp <= last.hp || totalSeconds == 0) { + return; + } + + var dps = (first.hp - last.hp) / totalSeconds; + target.TimeToDeath = this.toTimeString(last.hp / dps); + }, + }, }); diff --git a/EnmityPlugin/resources/enmity_relative.html b/EnmityPlugin/resources/enmity_relative.html new file mode 100644 index 0000000..ec743f6 --- /dev/null +++ b/EnmityPlugin/resources/enmity_relative.html @@ -0,0 +1,48 @@ + + + + + + + + +
+
+
+
+
+ {{target.Name}} +
+
+
+ {{$index + 1}}.{{e | you}} + {{e.RelativeEnmityString}} +
+
+
+
+
+
+ + + diff --git a/EnmityPlugin/resources/targetinfo_mini.html b/EnmityPlugin/resources/targetinfo_mini.html new file mode 100644 index 0000000..9d10315 --- /dev/null +++ b/EnmityPlugin/resources/targetinfo_mini.html @@ -0,0 +1,39 @@ + + + + + + + + + +
+
+
+
+
+ {{target.HPPercent}}% + ({{target.TimeToDeath}}) +
+
{{myEntry.RelativeEnmityString}}
+
{{target.Distance}}m
+
+
+
+
+ + + From 3359fd1dc136187e707660aae663d3409f0363f7 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sat, 1 Jul 2017 11:43:42 -0400 Subject: [PATCH 2/3] Copy the relative enmity resources to the Build output directories --- EnmityPlugin/EnmityPlugin.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/EnmityPlugin/EnmityPlugin.csproj b/EnmityPlugin/EnmityPlugin.csproj index 08f9174..5f16bcf 100644 --- a/EnmityPlugin/EnmityPlugin.csproj +++ b/EnmityPlugin/EnmityPlugin.csproj @@ -166,9 +166,15 @@ Always + + Always + Always + + Always + From aca2297fbeb9cee01bfa58365bdf35dc17c227f1 Mon Sep 17 00:00:00 2001 From: Adrienne Walker Date: Sun, 2 Jul 2017 19:41:55 -0700 Subject: [PATCH 3/3] Fix JS errors from merge --- EnmityPlugin/resources/enmity.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EnmityPlugin/resources/enmity.js b/EnmityPlugin/resources/enmity.js index 6e684d8..dc9e3ed 100644 --- a/EnmityPlugin/resources/enmity.js +++ b/EnmityPlugin/resources/enmity.js @@ -122,9 +122,9 @@ var enmity = new Vue({ } this.updated = true; - this.entries = e.detail.Enmity.Entries; - this.target = e.detail.Enmity.Target ? e.detail.Enmity.Target : noTarget; - this.hide = (hideNoTarget && e.detail.Enmity.Target == null); + this.entries = enmity.Entries; + this.target = enmity.Target ? enmity.Target : noTarget; + this.hide = (hideNoTarget && enmity.Target == null); if(this.hide){ document.getElementById("enmity").style.visibility = "hidden"; }else{