]> git.lizzy.rs Git - mt.git/blob - toolcaps.go
Add WaitGroup to SerializePkt
[mt.git] / toolcaps.go
1 package mt
2
3 import (
4         "math"
5         "time"
6 )
7
8 type ToolCaps struct {
9         //mt:if _ = %s; false
10         NonNil bool
11         //mt:end
12
13         //mt:lenhdr 16
14
15         //mt:ifde
16         //mt:if r.N > 0 { %s.NonNil = true}; /**/
17         //mt:if %s.NonNil
18
19         // Version.
20         //mt:const uint8(5)
21
22         AttackCooldown float32
23         MaxDropLvl     int16
24
25         //mt:len32
26         GroupCaps []ToolGroupCap
27
28         //mt:len32
29         DmgGroups []Group
30
31         //mt:32tou16
32         PunchUses int32
33
34         //mt:end
35         //mt:end
36
37         //mt:end
38 }
39
40 type ToolGroupCap struct {
41         Name string
42
43         //mt:32to16
44         Uses int32
45
46         MaxLvl int16
47
48         //mt:len32
49         Times []DigTime
50 }
51
52 type DigTime struct {
53         Rating int16
54         Time   float32
55 }
56
57 func (tc ToolCaps) DigTime(groups map[string]int16) (time.Duration, bool) {
58         immDig := groups["dig_immediate"]
59
60         minTime := float32(math.Inf(1))
61
62         lvl := groups["level"]
63         for _, gc := range tc.GroupCaps {
64                 if gc.Name == "dig_immediate" {
65                         immDig = 0
66                 }
67
68                 if lvl > gc.MaxLvl {
69                         continue
70                 }
71
72                 r := groups[gc.Name]
73                 for _, dt := range gc.Times {
74                         t := dt.Time
75                         if lvl < gc.MaxLvl {
76                                 t /= float32(gc.MaxLvl - lvl)
77                         }
78                         if dt.Rating == r && t < minTime {
79                                 minTime = t
80                         }
81                 }
82         }
83
84         switch immDig {
85         case 2:
86                 return time.Second / 2, true
87         case 3:
88                 return 0, true
89         }
90
91         if math.IsInf(float64(minTime), 1) {
92                 return 0, false
93         }
94
95         return time.Duration(math.Ceil(float64(minTime) * float64(time.Second))), true
96 }