Repository navigation
Expand file tree
/
Copy pathtypes.go
More file actions
345 lines (308 loc) · 8.09 KB
/
Copy pathtypes.go
File metadata and controls
345 lines (308 loc) · 8.09 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
343
344
345
package pokemonbattlelib
import (
"fmt"
"math"
"math/bits"
"strings"
)
// Constants for looking up Pokemon stats
const (
// Base stats
StatHP = iota
StatAtk
StatDef
StatSpAtk
StatSpDef
StatSpeed
// Fighting stats
StatCritChance
StatAccuracy
StatEvasion
)
// Table of critical hit chances (denominator of 1/X)
var CritChances = [5]int{16, 8, 4, 3, 2}
// Table for accuracy/evasion multiplier
var AccuracyEvasionMultiplier = map[int]uint{
-6: 300,
-5: 266,
-4: 250,
-3: 200,
-2: 166,
-1: 133,
0: 100,
1: 75,
2: 60,
3: 50,
4: 43,
5: 36,
6: 33,
}
// The min and max number of stages that a stat can be modified is [-6, 6]
const (
MaxStatModifier = 6
MinStatModifier = -6
)
// Represents a bit mask of all elemental types
type Type uint32
const (
TypeNormal Type = 1 << iota
TypeFighting
TypeFlying
TypePoison
TypeGround
TypeRock
TypeBug
TypeGhost
TypeSteel
TypeFire
TypeWater
TypeGrass
TypeElectric
TypePsychic
TypeIce
TypeDragon
TypeDark
)
var typeStrings = map[Type]string{
TypeNormal: "Normal",
TypeFighting: "Fighting",
TypeFlying: "Flying",
TypePoison: "Poison",
TypeGround: "Ground",
TypeRock: "Rock",
TypeBug: "Bug",
TypeGhost: "Ghost",
TypeSteel: "Steel",
TypeFire: "Fire",
TypeWater: "Water",
TypeGrass: "Grass",
TypeElectric: "Electric",
TypePsychic: "Psychic",
TypeIce: "Ice",
TypeDragon: "Dragon",
TypeDark: "Dark",
}
// Represents effectiveness of an elemental type matchup.
type Effectiveness int8
const NoEffect Effectiveness = math.MinInt8 + 1 // separate because it fucks up the iota
const (
VeryIneffective Effectiveness = iota - 2
Ineffective
NormalEffect
SuperEffective
VerySuperEffective
)
var noEffect = map[Type]Type{
TypeNormal: TypeGhost,
TypeFighting: TypeGhost,
TypePoison: TypeSteel,
TypeGround: TypeFlying,
TypeGhost: TypeNormal,
TypeElectric: TypeGround,
TypePsychic: TypeDark,
}
var halfEffect = map[Type]Type{
TypeNormal: TypeRock | TypeSteel,
TypeFighting: TypeFlying | TypePoison | TypeBug | TypePsychic,
TypeFlying: TypeRock | TypeSteel | TypeElectric,
TypePoison: TypePoison | TypeGround | TypeRock | TypeGhost,
TypeGround: TypeBug | TypeGrass,
TypeRock: TypeFighting | TypeGround | TypeSteel,
TypeBug: TypeFighting | TypeFlying | TypePoison | TypeGhost | TypeSteel | TypeFire,
TypeGhost: TypeSteel | TypeDark,
TypeSteel: TypeSteel | TypeFire | TypeWater | TypeElectric,
TypeFire: TypeRock | TypeFire | TypeWater | TypeDragon,
TypeWater: TypeWater | TypeGrass | TypeDragon,
TypeGrass: TypeFlying | TypePoison | TypeBug | TypeSteel | TypeFire | TypeGrass | TypeDragon,
TypeElectric: TypeGrass | TypeElectric | TypeDragon,
TypePsychic: TypeSteel | TypePsychic,
TypeIce: TypeSteel | TypeFire | TypeWater | TypeIce,
TypeDragon: TypeSteel,
TypeDark: TypeFighting | TypeSteel | TypeDark,
}
var doubleEffect = map[Type]Type{
TypeFighting: TypeNormal | TypeRock | TypeSteel | TypeIce | TypeDark,
TypeFlying: TypeFighting | TypeBug | TypeGrass,
TypePoison: TypeGrass,
TypeGround: TypePoison | TypeRock | TypeSteel | TypeFire | TypeElectric,
TypeRock: TypeFlying | TypeBug | TypeFire | TypeIce,
TypeBug: TypeGrass | TypePsychic | TypeDark,
TypeGhost: TypeGhost | TypePsychic,
TypeSteel: TypeRock | TypeIce,
TypeFire: TypeBug | TypeSteel | TypeGrass | TypeIce,
TypeWater: TypeGround | TypeRock | TypeFire,
TypeGrass: TypeGround | TypeRock | TypeWater,
TypeElectric: TypeFlying | TypeWater,
TypePsychic: TypeFighting | TypePoison,
TypeIce: TypeFlying | TypeGround | TypeGrass | TypeDragon,
TypeDragon: TypeDragon,
TypeDark: TypeGhost | TypePsychic,
}
// Get effectiveness of a given elemental type matchup.
func GetElementalEffect(move, def Type) Effectiveness {
reduce := bits.OnesCount32(uint32(halfEffect[move] & def))
increase := bits.OnesCount32(uint32(doubleEffect[move] & def))
effect := increase - reduce
if noEffect[move]&def > 0 {
return NoEffect
}
return Effectiveness(effect)
}
func (t Type) String() string {
result := ""
for i := TypeNormal; i <= TypeDark; i <<= 1 {
if t&i > 0 {
result += fmt.Sprintf("[%s]", typeStrings[i])
}
}
return result
}
type Gender uint8
const (
GenderGenderless Gender = iota
GenderFemale
GenderMale
)
func (g Gender) String() string {
if g == GenderGenderless {
return ""
} else if g == GenderFemale {
return "♀"
} else if g == GenderMale {
return "♂"
} else {
panic("Stringing gender reached unhandled condition")
}
}
// Represents volatile and non-volatile status conditions on a pokemon.
type StatusCondition uint32
const (
StatusNone StatusCondition = 0
// Non volatile - first 3 bits
StatusBurn StatusCondition = iota
StatusFreeze
StatusParalyze
StatusPoison
StatusBadlyPoison
StatusSleep
)
const (
// volatile - the rest of the bits
StatusBound StatusCondition = 1 << (iota + 3)
StatusCantEscape
StatusConfusion
StatusCursed
StatusEmbargo
StatusFlinch
StatusHealBlock
StatusIdentified
StatusInfatuation
StatusLeechSeed
StatusNightmare
StatusPerishSong
StatusTaunt
StatusTorment
)
// Status effect strings in past tense. Mostly for use in battle log.
var statusStrings = map[StatusCondition]string{
StatusNone: "",
StatusBurn: "burned",
StatusFreeze: "frozen",
StatusParalyze: "paralyzed",
StatusPoison: "poisoned",
StatusBadlyPoison: "badly poisoned",
StatusSleep: "asleep",
StatusBound: "bound",
StatusCantEscape: "can't escape",
StatusConfusion: "confused",
StatusCursed: "cursed",
StatusEmbargo: "embargoed",
StatusFlinch: "flinched",
StatusHealBlock: "heal blocked",
StatusInfatuation: "infatuated",
StatusIdentified: "identified",
StatusLeechSeed: "leeched",
StatusNightmare: "nightmared",
StatusPerishSong: "perished",
StatusTaunt: "taunted",
StatusTorment: "tormented",
}
const (
StatusNonvolatileMask StatusCondition = 0b111
StatusVolatileMask StatusCondition = math.MaxUint32 ^ StatusNonvolatileMask
)
func (s *StatusCondition) check(c StatusCondition) bool {
vCheck := (*s&StatusVolatileMask)&(c&StatusVolatileMask) == c&StatusVolatileMask
if c&StatusNonvolatileMask > 0 {
nvCheck := (*s&StatusNonvolatileMask)^(c&StatusNonvolatileMask) == 0
return nvCheck && vCheck
} else {
return vCheck
}
}
// Applies the given status conditions to this status condition. Non-volatile status conditions are overwritten.
func (s *StatusCondition) apply(c StatusCondition) {
nv := c & StatusNonvolatileMask
if nv == 0 {
nv = *s & StatusNonvolatileMask
}
v := StatusVolatileMask & (*s | c)
*s = nv | v
}
// Clears the given status conditions from this status condition.
func (s *StatusCondition) clear(c StatusCondition) {
if c != StatusNonvolatileMask && *s&StatusNonvolatileMask != c&StatusNonvolatileMask {
c &= StatusVolatileMask
}
*s &= ^c
}
func (s StatusCondition) String() string {
// fast path
if val, ok := statusStrings[s]; ok {
return val
}
// slower path
result := []string{}
for c := StatusBurn; c <= StatusSleep; c++ {
if s.check(c) {
result = append(result, statusStrings[c])
}
}
for c := StatusBound; c <= StatusTorment; c <<= 1 {
if s.check(c) {
result = append(result, statusStrings[c])
}
}
return strings.Join(result, ", ")
}
type Ability uint16
// Natures can affect a Pokemon's stats, increasing one and decreasing another.
// *Constants, GetStatModifiers(), and String() are auto-generated.*
type Nature uint8
// Deprecated: getNatureModifers is deprecated. Use Nature.GetStatModifiers() instead.
func (n Nature) getNatureModifers() [6]float64 {
up, down := n.GetStatModifiers()
natureModifiers := [6]float64{-1, 1, 1, 1, 1, 1} // hp is not affected by nature
// tried to multiply natureModifiers by both 1.1 and 0.9, caused rounding errors
if up != down {
natureModifiers[up] = 1.1
natureModifiers[down] = 0.9
}
return natureModifiers
}
// Weather effects
type Weather int
const (
WeatherClearSkies Weather = iota
WeatherHarshSunlight
WeatherRain
WeatherSandstorm
WeatherHail
WeatherFog
)
type MoveFailReason uint8
const (
FailOther MoveFailReason = iota
FailMiss
FailDodge
)