diff options
Diffstat (limited to 'toolcaps.go')
-rw-r--r-- | toolcaps.go | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/toolcaps.go b/toolcaps.go index 7bf6c09..7684de2 100644 --- a/toolcaps.go +++ b/toolcaps.go @@ -1,5 +1,10 @@ package mt +import ( + "math" + "time" +) + type ToolCaps struct { //mt:if _ = %s; false NonNil bool @@ -18,12 +23,13 @@ type ToolCaps struct { MaxDropLvl int16 //mt:len32 - GroupCaps []ToolGroupCaps + GroupCaps []ToolGroupCap //mt:len32 DmgGroups []Group - AttackUses uint16 + //mt:32tou16 + PunchUses int32 //mt:end //mt:end @@ -31,9 +37,12 @@ type ToolCaps struct { //mt:end } -type ToolGroupCaps struct { - Name string - Uses int16 +type ToolGroupCap struct { + Name string + + //mt:32to16 + Uses int32 + MaxLvl int16 //mt:len32 @@ -44,3 +53,44 @@ 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 +} |