diff options
-rw-r--r-- | client_conn.go | 7 | ||||
-rw-r--r-- | server_conn.go | 25 | ||||
-rw-r--r-- | toolcaps.go | 117 |
3 files changed, 2 insertions, 147 deletions
diff --git a/client_conn.go b/client_conn.go index 0014cf4..8eb5dcd 100644 --- a/client_conn.go +++ b/client_conn.go @@ -437,12 +437,7 @@ func handleClt(cc *clientConn) { }) cc.SendCmd(&mt.ToCltNodeDefs{Defs: cc.nodeDefs}) - for i, def := range cc.itemDefs { - cc.itemDefs[i] = mt.ItemDef{ - Name: def.Name, - ToolCaps: def.ToolCaps, - } - } + cc.itemDefs = []mt.ItemDef{} cc.nodeDefs = []mt.NodeDef{} var files []struct{ Name, Base64SHA1 string } diff --git a/server_conn.go b/server_conn.go index d74cb03..ad64976 100644 --- a/server_conn.go +++ b/server_conn.go @@ -212,32 +212,9 @@ func handleSrv(sc *serverConn) { sc.inv.Deserialize(strings.NewReader(cmd.Inv)) sc.prependInv(sc.inv) - var t mt.ToolCaps - for _, iDef := range sc.client().itemDefs { - if iDef.Name == sc.name+"_hand" { - t = iDef.ToolCaps - break - } - } - - var tc ToolCaps - tc.fromMT(t) - - b := &strings.Builder{} - tc.SerializeJSON(b) - - fields := []mt.Field{ - { - Name: "tool_capabilities", - Value: b.String(), - }, - } - meta := mt.NewItemMeta(fields) - handStack := mt.Stack{ Item: mt.Item{ Name: sc.name + "_hand", - ItemMeta: meta, }, Count: 1, } @@ -256,7 +233,7 @@ func handleSrv(sc *serverConn) { hand.Stacks = []mt.Stack{handStack} } - b = &strings.Builder{} + b := &strings.Builder{} sc.inv.SerializeKeep(b, oldInv) sc.client().SendCmd(&mt.ToCltInv{Inv: b.String()}) diff --git a/toolcaps.go b/toolcaps.go deleted file mode 100644 index 11818a2..0000000 --- a/toolcaps.go +++ /dev/null @@ -1,117 +0,0 @@ -package main - -import ( - "encoding/json" - "io" - "strings" - - "github.com/anon55555/mt" -) - -type ToolGroupCaps struct { - Uses int16 `json:"uses"` - MaxLvl int16 `json:"maxlevel"` - - Times []float32 `json:"times"` -} - -type ToolCaps struct { - NonNil bool `json:"-"` - - AttackCooldown float32 `json:"full_punch_interval"` - MaxDropLvl int16 `json:"max_drop_level"` - - GroupCaps map[string]ToolGroupCaps `json:"groupcaps"` - - DmgGroups map[string]int16 `json:"damage_groups"` - - AttackUses uint16 `json:"punch_attack_uses"` -} - -func (t ToolCaps) toMT() mt.ToolCaps { - tc := mt.ToolCaps{ - NonNil: t.NonNil, - AttackCooldown: t.AttackCooldown, - MaxDropLvl: t.MaxDropLvl, - AttackUses: t.AttackUses, - } - - for k, v := range t.GroupCaps { - gc := mt.ToolGroupCaps{ - Name: k, - Uses: v.Uses, - MaxLvl: v.MaxLvl, - } - - for k2, v2 := range v.Times { - gc.Times = append(gc.Times, mt.DigTime{ - Rating: int16(k2), - Time: v2, - }) - } - - tc.GroupCaps = append(tc.GroupCaps, gc) - } - - for k, v := range t.DmgGroups { - tc.DmgGroups = append(tc.DmgGroups, mt.Group{ - Name: k, - Rating: v, - }) - } - - return tc -} - -func (t *ToolCaps) fromMT(tc mt.ToolCaps) { - t.NonNil = tc.NonNil - t.AttackCooldown = tc.AttackCooldown - t.MaxDropLvl = tc.MaxDropLvl - t.GroupCaps = make(map[string]ToolGroupCaps) - t.DmgGroups = make(map[string]int16) - t.AttackUses = tc.AttackUses - - for _, gc := range tc.GroupCaps { - g := ToolGroupCaps{ - Uses: gc.Uses, - MaxLvl: gc.MaxLvl, - } - - var max int16 - for _, dt := range gc.Times { - if dt.Rating > max { - max = dt.Rating - } - } - - g.Times = make([]float32, max+1) - for i := range g.Times { - g.Times[i] = -1 - } - - for _, dt := range gc.Times { - g.Times[dt.Rating] = dt.Time - } - - t.GroupCaps[gc.Name] = g - } - - for _, g := range tc.DmgGroups { - t.DmgGroups[g.Name] = g.Rating - } -} - -func (t ToolCaps) SerializeJSON(w io.Writer) error { - b := &strings.Builder{} - encoder := json.NewEncoder(b) - err := encoder.Encode(t) - - s := strings.ReplaceAll(b.String(), "-1", "null") - io.WriteString(w, s) - return err -} - -func (t *ToolCaps) DeserializeJSON(r io.Reader) error { - decoder := json.NewDecoder(r) - return decoder.Decode(t) -} |