summaryrefslogtreecommitdiff
path: root/toolcaps.go
diff options
context:
space:
mode:
authoranon5 <anon5clam@protonmail.com>2021-09-19 12:45:50 +0000
committeranon5 <anon5clam@protonmail.com>2021-09-19 12:45:50 +0000
commitbcc58cb3048faa146ed0f90b330ebbe791d53b5c (patch)
tree2373852a0557ea584a62134159eb646b15619be3 /toolcaps.go
parentd6ba88b091f6c9be3b48ab0fe3f94211ee210700 (diff)
Switch to Minetest 5.4.1 protocol and other changes
Diffstat (limited to 'toolcaps.go')
-rw-r--r--toolcaps.go60
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
+}