-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
155 lines (131 loc) · 4.03 KB
/
worker.js
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
const Ability = {
Judgement: "Judgement",
CrusaderStrike: "CrusaderStrike",
DivineStorm: "DivineStorm",
HammerOfWrath: "HammerOfWrath",
Exorcism: "Exorcism",
Consecration: "Consecration",
HolyWrath: "HolyWrath"
}
const GCDType = {
Melee: "Melee",
Spell: "Spell"
}
const SpellGCDType = {
Additive: "Additive",
Multiplicative: "Multiplicative"
}
const ms = 1
const s = 1000
const gcd = 1500
onmessage = function(e) {
const abilitys = e.data[0];
const startTime = e.data[1];
const endTime = e.data[2];
const timeStep = e.data[3];
const spellCDs = e.data[4];
const spellDmgs = e.data[5];
const gcdTypes = e.data[6];
const spellHaste = e.data[7];
const hasteModifiers = e.data[8];
results = []
for (const prio of permutator(abilitys)) {
let avrPrioDmg = 0;
let runs = 0;
for (let i = startTime; i <= endTime; i+=timeStep) {
avrPrioDmg += runRotation(prio, spellCDs, spellDmgs, gcdTypes, spellHaste, i, hasteModifiers);
runs++;
}
results.push([avrPrioDmg / runs, prio])
}
results.sort(function(a, b){return b[0] - a[0]});
resultString = ""
for (const result of results){
resultString += result[0].toFixed(4) + ": [" + result[1].toString() + "]\n";
}
postMessage(resultString);
}
function runRotation(prio, spellCDs, spellDmgs, gcdTypes, spellHaste, fightTime, hasteModifiers) {
const currentSpellCds = new Map();
const spellUsedCount = new Map();
const spellLastCastAt = new Map();
for (const ability of prio) {
currentSpellCds.set(ability, 0)
spellUsedCount.set(ability, 0)
spellLastCastAt.set(ability, 0)
}
if(prio.includes(Ability.HammerOfWrath)){
currentSpellCds.set(Ability.HammerOfWrath, Math.trunc((fightTime * (1 - 0.2))));
}
currentTime = 0;
while(currentTime < fightTime){
let spellCast = null;
for (const ability of prio) {
if(currentSpellCds.get(ability) <= 0) {
spellUsedCount.set(ability, spellUsedCount.get(ability) + 1)
spellLastCastAt.set(ability, currentTime)
currentSpellCds.set(ability, spellCDs.get(ability))
spellCast = ability
break;
}
}
if(spellCast != null){
let currentGCD = 0
if(gcdTypes.get(spellCast) === GCDType.Melee){
currentGCD = gcd
}else{
let spellCastingSpeed = 1.05 * 1.03
let currentSpellHasteRating = spellHaste
for (const hasteModifier of hasteModifiers) {
if(currentTime > hasteModifier[0] && currentTime <= hasteModifier[0] + hasteModifier[1]){
if(hasteModifier[2] === SpellGCDType.Multiplicative){
spellCastingSpeed *= hasteModifier[3]
}else {
currentSpellHasteRating += hasteModifier[3]
}
}
}
spellCastingSpeed *= (1 + currentSpellHasteRating / 3279)
currentGCD = Math.max(gcd / spellCastingSpeed, 1 * s)
}
currentTime += currentGCD
subtractTimeFromCDs(currentSpellCds, currentGCD)
}else{
let lowestCd = Math.min(...currentSpellCds.values())
if(lowestCd > 0){
currentTime += lowestCd
subtractTimeFromCDs(currentSpellCds, lowestCd)
}
}
}
if(prio.includes(Ability.Consecration) && spellLastCastAt.get(Ability.Consecration) + spellCDs.get(Ability.Consecration) > fightTime){
let reduceCast = spellUsedCount.get(Ability.Consecration) - (1 - (fightTime - spellLastCastAt.get(Ability.Consecration)) / spellCDs.get(Ability.Consecration))
spellUsedCount.set(Ability.Consecration, reduceCast)
}
let damage = 0
for (let ability of spellUsedCount.keys()) {
damage += spellUsedCount.get(ability) * spellDmgs.get(ability)
}
return damage / (fightTime / s)
}
function subtractTimeFromCDs (currentSpellCds, time) {
for (let ability of currentSpellCds.keys()) {
currentSpellCds.set(ability, currentSpellCds.get(ability) - time)
}
}
function permutator(inputArr) {
var results = [];
function permute(arr, memo) {
var cur, memo = memo || [];
for (var i = 0; i < arr.length; i++) {
cur = arr.splice(i, 1);
if (arr.length === 0) {
results.push(memo.concat(cur));
}
permute(arr.slice(), memo.concat(cur));
arr.splice(i, 0, cur[0]);
}
return results;
}
return permute(inputArr);
}