-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathFightLogEntry.java
More file actions
342 lines (301 loc) · 10.8 KB
/
FightLogEntry.java
File metadata and controls
342 lines (301 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* Copyright (c) 2021, Matsyir <https://github.com/matsyir>
* Copyright (c) 2020, Mazhar <https://twitter.com/maz_rs>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package matsyir.pvpperformancetracker.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.awt.Color;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.time.Instant;
import lombok.Getter;
import lombok.Setter;
import matsyir.pvpperformancetracker.controllers.PvpDamageCalc;
import static matsyir.pvpperformancetracker.PvpPerformanceTrackerPlugin.PLUGIN;
import net.runelite.api.GraphicID;
import net.runelite.api.HeadIcon;
import net.runelite.api.Player;
import net.runelite.client.chat.ChatMessageBuilder;
import org.apache.commons.text.WordUtils;
import matsyir.pvpperformancetracker.utils.PvpPerformanceTrackerUtils;
// A fight log entry for a single Fighter. Will be saved in a List of FightLogEntries in the Fighter class.
@Getter
public class FightLogEntry implements Comparable<FightLogEntry>
{
public static final NumberFormat nf;
static
{
nf = NumberFormat.getInstance();
nf.setRoundingMode(RoundingMode.HALF_UP);
nf.setMaximumFractionDigits(2);
}
// general data
// don't expose attacker name since it is present in the parent class (Fighter), so it is
// redundant use of storage
public String attackerName;
@Expose
@SerializedName("t")
private long time;
@Setter
@Expose
@SerializedName("T")
private int tick;
// this boolean represents if this is a "complete" fight log entry or not.
// if a fight log entry is full/complete, then it has all attack data.
// an "incomplete" fight log entry means it's only holding the current attacker's defensive stats to be used with
// an opposing attack, to be matched up with fight analysis/data merging
// very rough way to do this but itll work
@Expose
@SerializedName("f")
private boolean isFullEntry;
// attacker data
@Expose
@SerializedName("G")
// current attacker's gear. The attacker is not necessarily the competitor.
// Set using PlayerComposition::getEquipmentIds
private int[] attackerGear;
@Expose
@SerializedName("O")
private HeadIcon attackerOverhead;
@Expose
@SerializedName("m") // m because movement?
private AnimationData animationData;
@Setter
@Expose
@SerializedName("d")
private double expectedDamage; // NOTE: previously referred to as "Deserved damage"
@Expose
@SerializedName("a")
private double accuracy;
@Setter
@Expose
@SerializedName("h") // h for highest hit
private int maxHit;
@Setter
@Expose
@SerializedName("l") // l for lowest hit
private int minHit;
@Expose
@SerializedName("s")
private boolean splash; // true if it was a magic attack and it splashed
@Expose
@SerializedName("E")
@Setter
private boolean elyProc = false;
@Expose
@SerializedName("S")
@Setter
private boolean staffMeleeReductionProc = false;
@Expose
@SerializedName("C")
private CombatLevels attackerLevels; // CAN BE NULL
@Getter
@Setter
@Expose
@SerializedName("k") // k for ko chance
private Double koChance = null;
@Getter // Added Getter for isKoChanceCalculated
@Setter
private transient boolean koChanceCalculated = false; // Flag to track if KO chance was processed for this entry
@Getter
@Setter
@Expose
@SerializedName("eH") // Estimated Hp before hit
private Integer estimatedHpBeforeHit = null;
@Getter
@Setter
@Expose
@SerializedName("oH") // Opponent max Hp used for calc
private Integer opponentMaxHp = null;
@Expose
@Getter
@Setter
@SerializedName("mC") // matched hits count so far
private int matchedHitsCount;
@Expose
@Getter
@Setter
@SerializedName("aD") // actual Damage Sum
private Integer actualDamageSum;
// defender data
@Expose
@SerializedName("g")
private int[] defenderGear;
@Expose
@SerializedName("o")
private HeadIcon defenderOverhead;
@Expose
@SerializedName("p")
private int attackerOffensivePray; // offensive pray saved as SpriteID since that's all we use it for.
@Expose
@Getter
private int expectedHits; // Declare expectedHits field
@Expose
@SerializedName("GMS")
@Getter
@Setter
private boolean isGmaulSpecial = false;
// Recorded opponent health ratio and scale at the moment of the hitsplat
private int recordedHealthRatio = -1;
private int recordedHealthScale = -1;
// Get the recorded hitsplat landing tick, or -1 if not recorded
// Set the tick when the hitsplat landed
// The tick at which the first hitsplat for this entry landed
@Getter
@Setter
private int hitsplatTick = -1;
// Display/Transient fields calculated during post-processing in onGameTick
@Expose
@Getter @Setter
private Integer displayHpBefore = null;
@Expose
@Getter @Setter
private Integer displayHpAfter = null;
@Expose
@Getter @Setter
private Double displayKoChance = null;
@Expose
@Getter @Setter
private boolean isPartOfTickGroup = false;
public FightLogEntry(Player attacker, Player defender, PvpDamageCalc pvpDamageCalc, int attackerOffensivePray, CombatLevels levels, AnimationData animationData)
{
this.isFullEntry = true;
// general
this.attackerName = attacker.getName();
this.time = Instant.now().toEpochMilli();
this.tick = PLUGIN.getClient().getTickCount();
this.animationData = animationData;
// attacker data
this.attackerGear = attacker.getPlayerComposition().getEquipmentIds();
this.attackerOverhead = attacker.getOverheadIcon();
this.expectedDamage = pvpDamageCalc.getAverageHit();
this.accuracy = pvpDamageCalc.getAccuracy();
this.minHit = pvpDamageCalc.getMinHit();
this.maxHit = pvpDamageCalc.getMaxHit();
this.splash = animationData.attackStyle == AnimationData.AttackStyle.MAGIC && defender.getGraphic() == GraphicID.SPLASH;
this.attackerLevels = levels; // CAN BE NULL
// defender data
this.defenderGear = defender.getPlayerComposition().getEquipmentIds();
this.defenderOverhead = defender.getOverheadIcon();
this.attackerOffensivePray = attackerOffensivePray;
this.expectedHits = PvpPerformanceTrackerUtils.getExpectedHits(animationData);
this.matchedHitsCount = 0;
this.actualDamageSum = 0;
}
// create incomplete entry to save competitor's defensive stats which are only client side
// in this context, the "attacker" is not attacking, only defending.
public FightLogEntry(String attackerName, CombatLevels levels, int attackerOffensivePray)
{
this.isFullEntry = false;
this.attackerName = attackerName;
this.time = Instant.now().toEpochMilli();
this.tick = PLUGIN.getClient().getTickCount();
this.attackerLevels = levels;
this.attackerOffensivePray = attackerOffensivePray;
this.actualDamageSum = 0;
}
// create new fightlogentry based on existing entry but new damage calcs (for fight analysis/stat merging)
public FightLogEntry(FightLogEntry e, PvpDamageCalc pvpDamageCalc)
{
this.isFullEntry = true;
// general
this.attackerName = e.attackerName;
this.time = e.time;
this.tick = e.tick;
// attacker data
this.attackerGear = e.attackerGear;
this.attackerOverhead = e.attackerOverhead;
this.animationData = e.animationData;
this.expectedDamage = pvpDamageCalc.getAverageHit();
this.accuracy = pvpDamageCalc.getAccuracy();
this.minHit = pvpDamageCalc.getMinHit();
this.maxHit = pvpDamageCalc.getMaxHit();
this.splash = e.splash;
this.elyProc = e.elyProc;
this.staffMeleeReductionProc = e.staffMeleeReductionProc;
this.attackerLevels = e.attackerLevels;
// defender data
this.defenderGear = e.defenderGear;
this.defenderOverhead = e.defenderOverhead;
this.attackerOffensivePray = e.attackerOffensivePray;
this.expectedHits = PvpPerformanceTrackerUtils.getExpectedHits(e.animationData);
this.matchedHitsCount = 0;
this.actualDamageSum = 0;
}
// randomized entry used for testing
public FightLogEntry(int [] attackerGear, int expectedDamage, double accuracy, int minHit, int maxHit, int [] defenderGear, String attackerName)
{
this.attackerName = attackerName;
this.attackerGear = attackerGear;
this.attackerOverhead = HeadIcon.MAGIC;
this.animationData = Math.random() <= 0.5 ? AnimationData.MELEE_DAGGER_SLASH : AnimationData.MAGIC_ANCIENT_MULTI_TARGET;
this.expectedDamage = expectedDamage;
this.accuracy = accuracy;
this.minHit = minHit;
this.maxHit = maxHit;
this.splash = Math.random() >= 0.5;
this.time = Instant.now().toEpochMilli();
this.defenderGear = defenderGear;
this.defenderOverhead = HeadIcon.MAGIC;
this.actualDamageSum = 0;
}
public boolean success()
{
return animationData.attackStyle.getProtection() != defenderOverhead;
}
public String toChatMessage()
{
Color darkRed = new Color(127, 0, 0); // same color as default clan chat color
return new ChatMessageBuilder()
.append(darkRed, attackerName + ": ")
.append(Color.BLACK, "Style: ")
.append(darkRed, WordUtils.capitalizeFully(animationData.attackStyle.toString()))
.append(Color.BLACK, " Hit: ")
.append(darkRed, getHitRange())
.append(Color.BLACK, " Acc: ")
.append(darkRed, nf.format(accuracy))
.append(Color.BLACK, " AvgHit: ")
.append(darkRed, nf.format(expectedDamage))
.append(Color.BLACK, " Spec?: ")
.append(darkRed, animationData.isSpecial ? "Y" : "N")
.append(Color.BLACK, " OffP?:")
.append(darkRed, success() ? "Y" : "N")
.build();
}
public String getHitRange()
{
return minHit + "-" + maxHit;
}
// use to sort by last fight time, to sort fights by date/time.
@Override
public int compareTo(FightLogEntry o)
{
long diff = tick - o.tick;
// if diff = 0, return 0. Otherwise, divide diff by its absolute value. This will result in
// -1 for negative numbers, and 1 for positive numbers, keeping the sign and a safely small int.
return diff == 0 ? 0 :
(int)(diff / Math.abs(diff));
}
}