-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoolcaps.go
96 lines (72 loc) · 1.29 KB
/
toolcaps.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
package mt
import (
"math"
"time"
)
type ToolCaps struct {
//mt:if _ = %s; false
NonNil bool
//mt:end
//mt:lenhdr 16
//mt:ifde
//mt:if r.N > 0 { %s.NonNil = true}; /**/
//mt:if %s.NonNil
// Version.
//mt:const uint8(5)
AttackCooldown float32
MaxDropLvl int16
//mt:len32
GroupCaps []ToolGroupCap
//mt:len32
DmgGroups []Group
//mt:32tou16
PunchUses int32
//mt:end
//mt:end
//mt:end
}
type ToolGroupCap struct {
Name string
//mt:32to16
Uses int32
MaxLvl int16
//mt:len32
Times []DigTime
}
type DigTime struct {
Rating int16
Time float32
}
func (tc ToolCaps) DigTime(groups map[string]int16) (time.Duration, bool) {
immDig := groups["dig_immediate"]
minTime := float32(math.Inf(1))
lvl := groups["level"]
for _, gc := range tc.GroupCaps {
if gc.Name == "dig_immediate" {
immDig = 0
}
if lvl > gc.MaxLvl {
continue
}
r := groups[gc.Name]
for _, dt := range gc.Times {
t := dt.Time
if lvl < gc.MaxLvl {
t /= float32(gc.MaxLvl - lvl)
}
if dt.Rating == r && t < minTime {
minTime = t
}
}
}
switch immDig {
case 2:
return time.Second / 2, true
case 3:
return 0, true
}
if math.IsInf(float64(minTime), 1) {
return 0, false
}
return time.Duration(math.Ceil(float64(minTime) * float64(time.Second))), true
}