forked from lologarithm/wowsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
147 lines (129 loc) · 4.68 KB
/
web.go
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
package main
import (
"io/ioutil"
"log"
"net/http"
"strconv"
"strings"
"gitlab.com/lologarithm/wowsim/elesim"
"gitlab.com/lologarithm/wowsim/tbc"
)
func init() {
fs := http.FileServer(http.Dir("."))
http.HandleFunc("/ui/", func(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("Cache-Control", "no-cache")
if strings.HasSuffix(req.URL.Path, ".wasm") {
resp.Header().Set("content-type", "application/wasm")
}
log.Printf("Serving: %s", req.URL.String())
fs.ServeHTTP(resp, req)
})
http.HandleFunc("/tui/", func(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("Cache-Control", "no-cache")
if strings.HasSuffix(req.URL.Path, ".wasm") {
resp.Header().Set("content-type", "application/wasm")
}
log.Printf("Serving: %s", req.URL.String())
fs.ServeHTTP(resp, req)
})
http.HandleFunc("/sim", simPage)
http.HandleFunc("/simtbc", simTBCPage)
}
func simPage(w http.ResponseWriter, r *http.Request) {
fileData, err := ioutil.ReadFile("elesim/ui/index.html")
if err != nil {
log.Fatalf("Failed to read file: %s", err)
}
if r.ContentLength > 0 {
// parse form.
r.ParseForm()
intv, _ := strconv.Atoi(r.FormValue("int"))
sph, _ := strconv.ParseFloat(r.FormValue("spellhit"), 64)
spc, _ := strconv.ParseFloat(r.FormValue("spellcrit"), 64)
spd, _ := strconv.ParseFloat(r.FormValue("spelldmg"), 64)
mp5, _ := strconv.ParseFloat(r.FormValue("mp5"), 64)
spp, _ := strconv.ParseFloat(r.FormValue("spellpen"), 64)
stats := elesim.Stats{
elesim.StatInt: float64(intv) + 86, // Add base stats
elesim.StatSpellCrit: spc/100 + 0.022 + .11, // Add base+talents to gear
elesim.StatSpellHit: sph/100 + 0.03, // Add talent hit
elesim.StatSpellDmg: spd, // gear
elesim.StatMP5: mp5, // gear
elesim.StatMana: 1240, // Base Mana L60 Troll Shaman
elesim.StatSpellPen: spp, //
}
// stats := elesim.Stats{
// elesim.StatInt: 86 + 191, // base + gear
// elesim.StatSpellCrit: 0.022 + 0.04 + .11, // base crit + gear + talents
// elesim.StatSpellHit: 0.03 + 0.03, // talents + gear
// elesim.StatSpellDmg: 474, // gear
// elesim.StatMP5: 31 + 4 + 110, //
// elesim.StatMana: 1240,
// elesim.StatSpellPen: 0,
// }
buffs := elesim.Stats{
// elesim.StatSpellCrit: 0.18, // world buffs DMT+Ony+Songflower
// elesim.StatInt: 15, // songflower
}
// buffs[elesim.StatInt] += 31 // arcane brill
// buffs[elesim.StatInt] += 12 // GOTW
// buffs[elesim.StatInt] += 10 // runn tum tuber
for i, v := range buffs {
// ZG Buff
// if elesim.Stat(i) == elesim.StatInt {
// stats[i] = stats[i] * 1.15
// }
// I believe ZG buff applies before other buffs
stats[i] += v
}
stats[elesim.StatSpellCrit] += (stats[elesim.StatInt] / 59.5) / 100 // 1% crit per 59.5 int
stats[elesim.StatMana] += stats[elesim.StatInt] * 15
stats.Print()
results := runSim(stats, 60, 5000)
fileData = append(fileData, "<pre>"...)
for _, res := range results {
fileData = append(fileData, res...)
fileData = append(fileData, "\n"...)
}
fileData = append(fileData, "</pre>"...)
}
w.Write(fileData)
}
func simTBCPage(w http.ResponseWriter, r *http.Request) {
fileData, err := ioutil.ReadFile("tbc/ui/index.html")
if err != nil {
log.Fatalf("Failed to read file: %s", err)
}
if r.ContentLength > 0 {
// parse form.
r.ParseForm()
intv, _ := strconv.Atoi(r.FormValue("int"))
sph, _ := strconv.ParseFloat(r.FormValue("spellhit"), 64)
spc, _ := strconv.ParseFloat(r.FormValue("spellcrit"), 64)
spd, _ := strconv.ParseFloat(r.FormValue("spelldmg"), 64)
mp5, _ := strconv.ParseFloat(r.FormValue("mp5"), 64)
haste, _ := strconv.ParseFloat(r.FormValue("haste"), 64)
spp, _ := strconv.ParseFloat(r.FormValue("spellpen"), 64)
stats := tbc.Stats{
tbc.StatInt: float64(intv) + 86, // Add base stats
tbc.StatSpellCrit: spc + 151, // Add base+talents to gear
tbc.StatSpellHit: sph/100 + 0.03, // Add talent hit
tbc.StatSpellDmg: spd, // gear
tbc.StatMP5: mp5, // gear
tbc.StatHaste: haste,
tbc.StatMana: 1240, // Base Mana L60 Troll Shaman
tbc.StatSpellPen: spp, //
}
stats[tbc.StatSpellCrit] += (stats[tbc.StatInt] / 59.5) / 100 // 1% crit per 59.5 int
stats[tbc.StatMana] += stats[tbc.StatInt] * 15
stats.Print()
results := runTBCSim(stats, 300, 500)
fileData = append(fileData, "<pre>"...)
for _, res := range results {
fileData = append(fileData, res...)
fileData = append(fileData, "\n"...)
}
fileData = append(fileData, "</pre>"...)
}
w.Write(fileData)
}