aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_gather.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/action_gather.go')
-rw-r--r--internal/game/action_gather.go54
1 files changed, 27 insertions, 27 deletions
diff --git a/internal/game/action_gather.go b/internal/game/action_gather.go
index fe3d2a9..1d685be 100644
--- a/internal/game/action_gather.go
+++ b/internal/game/action_gather.go
@@ -93,41 +93,41 @@ func (g *Game) startGather(sess *net.Session, p *player.Player, obj *object.Obje
case "woodcutting":
verb = "chopping"
}
- p.ActionState = &ActionState{Type: ActionGathering, TargetName: obj.Name, ToolName: toolName, Verb: verb}
g.broadcastAction(sess, "\n%s starts %s the %s.", p.Name, verb, obj.Name)
- data := map[string]any{
- "obj_def_id": obj.ID,
- "instance_key": g.World.ObjStateKey(st.RoomID, st.DefID, st.Index),
- "instance_idx": st.Index + 1,
- "effective_wait": wait,
- "step": 0,
+ d := &action.GatherData{
+ ObjDefID: obj.ID,
+ InstanceKey: g.World.ObjStateKey(st.RoomID, st.DefID, st.Index),
+ InstanceIdx: st.Index + 1,
+ EffectiveWait: wait,
+ Verb: verb,
+ ToolName: toolName,
}
if cfg.DepleteTimer > 0 {
- data["deplete_timer"] = true
+ d.DepleteTimer = true
}
p.Action = &action.Action{
- Type: "gather",
+ Type: action.TypeGather,
TargetID: st.DefID,
TargetName: obj.Name,
WaitLeft: 0,
- Data: data,
+ Data: d,
}
}
func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
- objDefID := p.Action.Data["obj_def_id"].(string)
- cfg := loadGatherConfig(g, objDefID)
+ d := p.Action.Data.(*action.GatherData)
+ cfg := loadGatherConfig(g, d.ObjDefID)
if cfg == nil {
g.cancelAction(p)
return
}
- step := p.Action.Data["step"].(int)
- wait := p.Action.Data["effective_wait"].(float64)
- instanceKey := p.Action.Data["instance_key"].(string)
- _, shared := p.Action.Data["deplete_timer"]
+ step := d.Step
+ wait := d.EffectiveWait
+ instanceKey := d.InstanceKey
+ shared := d.DepleteTimer
if step == 0 {
if p.FirstFreeSlot() == -1 {
@@ -147,7 +147,7 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
}
}
sess.WriteLine(fmt.Sprintf("%s", cfg.GatherMsg))
- p.Action.Data["step"] = 1
+ d.Step = 1
p.Action.WaitLeft = engine.ToTicks(wait)
return
}
@@ -158,7 +158,7 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
p.Action.WaitLeft = engine.ToTicks(3)
return
}
- p.Action.Data["step"] = 0
+ d.Step = 0
p.Action.WaitLeft = engine.ToTicks(wait)
return
}
@@ -229,11 +229,11 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
if st != nil && st.SharedTimer <= 0 {
g.pendingDepletions = append(g.pendingDepletions, pendingDepletion{
instanceKey: instanceKey,
- objDefID: objDefID,
+ objDefID: d.ObjDefID,
targetName: p.Action.TargetName,
playerNames: []string{p.Name},
})
- p.Action.Data["step"] = 2
+ d.Step = 2
p.Action.WaitLeft = engine.ToTicks(1)
return
}
@@ -255,17 +255,17 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
continue
}
op := other.Player
- if op == nil || op.Action == nil || op.Action.Type != "gather" {
+ if op == nil || op.Action == nil || op.Action.Type != action.TypeGather {
continue
}
- if op.Action.Data["instance_key"] == instanceKey {
+ if gd, ok := op.Action.Data.(*action.GatherData); ok && gd.InstanceKey == instanceKey {
other.WriteLine(fmt.Sprintf("\nThe %s was depleted by %s!", g.colorize(sess, "item", p.Action.TargetName), g.colorize(sess, "player_name", p.Name)))
g.cancelAction(op)
g.writePrompt(other)
}
}
- p.Action.Data["step"] = 2
+ d.Step = 2
p.Action.WaitLeft = engine.ToTicks(1)
return
}
@@ -275,7 +275,7 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
g.cancelAction(p)
return
}
- p.Action.Data["step"] = 0
+ d.Step = 0
p.Action.WaitLeft = engine.ToTicks(wait)
return
}
@@ -287,7 +287,7 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
g.cancelAction(p)
return
}
- p.Action.Data["step"] = 0
+ d.Step = 0
p.Action.WaitLeft = engine.ToTicks(wait)
}
@@ -316,10 +316,10 @@ func (g *Game) depleteSharedTree(st *world.ObjState, cfg *action.GatherConfig, t
for _, sess := range g.Hub.PlayersInRoom(st.RoomID) {
op := sess.Player
- if op == nil || op.Action == nil || op.Action.Type != "gather" {
+ if op == nil || op.Action == nil || op.Action.Type != action.TypeGather {
continue
}
- if op.Action.Data["instance_key"] != g.World.ObjStateKey(st.RoomID, st.DefID, st.Index) {
+ if gd, ok := op.Action.Data.(*action.GatherData); !ok || gd.InstanceKey != g.World.ObjStateKey(st.RoomID, st.DefID, st.Index) {
continue
}
isDepleter := false