]> git.lizzy.rs Git - mt.git/blobdiff - toolcaps.go
Add WaitGroup to SerializePkt
[mt.git] / toolcaps.go
index 7bf6c09afe9c100908cdc3f2261347dc330af8cb..7684de2b6a83a54a99d16c2c718abebd355125ad 100644 (file)
@@ -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
+}