aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client_conn.go2
-rw-r--r--server_conn.go36
-rw-r--r--toolcaps.go98
3 files changed, 134 insertions, 2 deletions
diff --git a/client_conn.go b/client_conn.go
index 77f1da9..02e5445 100644
--- a/client_conn.go
+++ b/client_conn.go
@@ -50,8 +50,6 @@ type clientConn struct {
media []mediaFile
playerCAO, currentCAO mt.AOID
-
- inv mt.Inv
}
func (cc *clientConn) server() *serverConn { return cc.srv }
diff --git a/server_conn.go b/server_conn.go
index f50a079..a3c1653 100644
--- a/server_conn.go
+++ b/server_conn.go
@@ -24,6 +24,8 @@ type serverConn struct {
method mt.AuthMethods
salt, srpA, a, srpK []byte
}
+
+ inv mt.Inv
}
func (sc *serverConn) client() *clientConn { return sc.clt }
@@ -174,6 +176,40 @@ func handleSrv(sc *serverConn) {
sc.state++
close(sc.initCh)
}
+ case *mt.ToCltInv:
+ var inv mt.Inv
+ inv.Deserialize(strings.NewReader(cmd.Inv))
+
+ fields := []mt.Field{
+ mt.Field{
+ Name: "
+ },
+ }
+ meta := mt.NewItemMeta(fields)
+
+ handStack := mt.Stack{
+ Name: sc.name + "_hand",
+ ItemMeta: meta,
+ Count: 1,
+ }
+
+ hand := inv.List("hand")
+ if hand == nil {
+ inv = append(inv, mt.NamedInvList{
+ Name: "hand",
+ Width: 1,
+ Stacks: []mt.Stack{handStack},
+ })
+ } else if len(hand.Stacks) == 0 {
+ hand.Width = 1
+ hand.Stacks = []mt.Stack{handStack}
+ }
+
+ b := &strings.Builder{}
+ inv.SerializeKeep(b, sc.inv)
+ sc.inv = inv
+
+ sc.client().SendCmd(&mt.ToCltInv{Inv: b.String()})
}
}
}
diff --git a/toolcaps.go b/toolcaps.go
new file mode 100644
index 0000000..7a059cf
--- /dev/null
+++ b/toolcaps.go
@@ -0,0 +1,98 @@
+package main
+
+import (
+ "encoding/json"
+
+ "github.com/anon55555/mt"
+)
+
+type ToolGroupCaps struct {
+ Uses int16 `json:"uses"`
+ MaxLvl int16 `json:"maxlevel"`
+
+ Times map[int16]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: 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,
+ }
+
+ 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 {
+ encoder := json.NewEncoder(w)
+ return encoder.Encode(t)
+}
+
+func (t *ToolCaps) DeserializeJSON(r io.Reader) error {
+ decoder := json.NewDecoder(r)
+ return decoder.Decode(t)
+}