-
Notifications
You must be signed in to change notification settings - Fork 9
/
data.go
275 lines (232 loc) · 5.46 KB
/
data.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
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
package data
import (
"math"
"strings"
"github.com/hectorgimenez/d2go/pkg/data/quest"
"github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/d2go/pkg/data/skill"
"github.com/hectorgimenez/d2go/pkg/data/stat"
"github.com/hectorgimenez/d2go/pkg/data/state"
)
const (
goldPerLevel = 10000
// Monster Types
MonsterTypeNone MonsterType = "None"
MonsterTypeChampion MonsterType = "Champion"
MonsterTypeMinion MonsterType = "Minion"
MonsterTypeUnique MonsterType = "Unique"
MonsterTypeSuperUnique MonsterType = "SuperUnique"
)
type Data struct {
AreaOrigin Position
Corpse Corpse
Monsters Monsters
// First slice represents X and second Y
CollisionGrid [][]bool
PlayerUnit PlayerUnit
NPCs NPCs
Inventory Inventory
Objects Objects
AdjacentLevels []Level
Rooms []Room
OpenMenus OpenMenus
Roster Roster
HoverData HoverData
TerrorZones []area.ID
Quests quest.Quests
KeyBindings KeyBindings
}
type Room struct {
Position
Width int
Height int
}
type HoverData struct {
IsHovered bool
UnitID
UnitType int
}
func (r Room) GetCenter() Position {
return Position{
X: r.Position.X + r.Width/2,
Y: r.Position.Y + r.Height/2,
}
}
func (r Room) IsInside(p Position) bool {
if p.X >= r.X && p.X <= r.X+r.Width {
return p.Y >= r.Y && p.Y <= r.Y+r.Height
}
return false
}
func (d Data) MercHPPercent() int {
for _, m := range d.Monsters {
if m.IsMerc() {
// Hacky thing to read merc life properly
maxLife := m.Stats[stat.MaxLife] >> 8
life := float64(m.Stats[stat.Life] >> 8)
if m.Stats[stat.Life] <= 32768 {
life = float64(m.Stats[stat.Life]) / 32768.0 * float64(maxLife)
}
return int(life / float64(maxLife) * 100)
}
}
return 0
}
type RosterMember struct {
Name string
Area area.ID
Position Position
}
type Roster []RosterMember
func (r Roster) FindByName(name string) (RosterMember, bool) {
for _, rm := range r {
if strings.EqualFold(rm.Name, name) {
return rm, true
}
}
return RosterMember{}, false
}
type Level struct {
Area area.ID
Position Position
IsEntrance bool // This means the area can not be accessed just walking through it, needs to be clicked
}
type Class uint
const (
Amazon Class = iota
Sorceress
Necromancer
Paladin
Barbarian
Druid
Assassin
)
type Corpse struct {
Found bool
IsHovered bool
Position Position
}
type Position struct {
X int
Y int
}
type PlayerUnit struct {
Address uintptr
Name string
ID UnitID
Area area.ID
Position Position
Stats stat.Stats
BaseStats stat.Stats
Skills map[skill.ID]skill.Points
States state.States
Class Class
LeftSkill skill.ID
RightSkill skill.ID
AvailableWaypoints []area.ID // Is only filled when WP menu is open and only for the specific selected tab
}
func (pu PlayerUnit) FindStat(id stat.ID, layer int) (stat.Data, bool) {
st, found := pu.Stats.FindStat(id, layer)
if found {
return st, true
}
return pu.BaseStats.FindStat(id, layer)
}
func (pu PlayerUnit) MaxGold() int {
lvl, _ := pu.FindStat(stat.Level, 0)
return goldPerLevel * lvl.Value
}
// TotalPlayerGold returns the amount of gold, including inventory and player stash (excluding shared stash)
func (pu PlayerUnit) TotalPlayerGold() int {
gold, _ := pu.FindStat(stat.Gold, 0)
stashGold, _ := pu.FindStat(stat.StashGold, 0)
return gold.Value + stashGold.Value
}
func (pu PlayerUnit) HPPercent() int {
life, _ := pu.FindStat(stat.Life, 0)
maxLife, _ := pu.FindStat(stat.MaxLife, 0)
return int((float64(life.Value) / float64(maxLife.Value)) * 100)
}
func (pu PlayerUnit) MPPercent() int {
mana, _ := pu.FindStat(stat.Mana, 0)
maxMana, _ := pu.FindStat(stat.MaxMana, 0)
return int((float64(mana.Value) / float64(maxMana.Value)) * 100)
}
func (pu PlayerUnit) CastingFrames() int {
// Formula detailed here: https://diablo.fandom.com/wiki/Faster_Cast_Rate
fcr, _ := pu.FindStat(stat.FasterCastRate, 0)
baseAnimation := pu.getCastingBaseSpeed()
ecfr := math.Floor(float64(fcr.Value*120) / float64(fcr.Value+120))
if ecfr > 75 {
ecfr = 75
}
// Animation speed for druids is different
cf := math.Ceil(256*baseAnimation/math.Floor(float64(256*(100+ecfr))/100.0)) - 1
return int(cf)
}
func (pu PlayerUnit) getCastingBaseSpeed() float64 {
// TODO: Implement logic for Lightning?
switch pu.Class {
case Amazon:
return 20
case Assassin:
return 17
case Barbarian:
return 14
case Necromancer, Paladin:
return 16
case Druid:
return 15
case Sorceress:
return 14
}
return 16
}
func (pu PlayerUnit) HasDebuff() bool {
debuffs := []state.State{
state.Amplifydamage,
state.Attract,
state.Confuse,
state.Conversion,
state.Decrepify,
state.Dimvision,
state.Ironmaiden,
state.Lifetap,
state.Lowerresist,
state.Terror,
state.Weaken,
state.Convicted,
state.Poison,
state.Cold,
state.Slowed,
state.BloodMana,
state.DefenseCurse,
}
for _, s := range pu.States {
for _, d := range debuffs {
if s == d {
return true
}
}
}
return false
}
type PointOfInterest struct {
Name string
Position Position
}
type OpenMenus struct {
Inventory bool
LoadingScreen bool
NPCInteract bool
NPCShop bool
Stash bool
Waypoint bool
MapShown bool
SkillTree bool
Character bool
QuitMenu bool
Cube bool
SkillSelect bool
Anvil bool
}