aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_burn.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-25 00:44:47 -0400
committerhistoria <[not public]>2026-06-25 00:44:47 -0400
commit94a06fbbe682701ca4d4bd2a70cd74d8df29c932 (patch)
treeeb49fb1893e61092138164d419e863ee3fe0d1e2 /internal/game/action_burn.go
parent15b7e221b799ef107dec44ecdb294026dfd3d059 (diff)
downloadthehouseoficarus-94a06fbbe682701ca4d4bd2a70cd74d8df29c932.tar.gz
refactor: replaced map[string]any with typed structs for Data
Diffstat (limited to 'internal/game/action_burn.go')
-rw-r--r--internal/game/action_burn.go57
1 files changed, 26 insertions, 31 deletions
diff --git a/internal/game/action_burn.go b/internal/game/action_burn.go
index e86887b..e1872ed 100644
--- a/internal/game/action_burn.go
+++ b/internal/game/action_burn.go
@@ -118,22 +118,20 @@ func (g *Game) startBurn(sess *net.Session, p *player.Player, itemID string, fro
phase = 0
}
- p.ActionState = &ActionState{Type: ActionBurning}
-
g.broadcastAction(sess, "\n%s starts building a fire.", p.Name)
p.Action = &action.Action{
- Type: "burn",
+ Type: action.TypeBurn,
TargetID: itemID,
TargetName: logDef.Name,
WaitLeft: 0,
- Data: map[string]any{
- "item_id": itemID,
- "tool_speed": toolSpeed,
- "level": logDef.FireLevel,
- "xp": logDef.FireXP,
- "burn_ticks": logDef.BurnTicks,
- "phase": phase,
+ Data: &action.BurnData{
+ ItemID: itemID,
+ ToolSpeed: toolSpeed,
+ Level: logDef.FireLevel,
+ XP: logDef.FireXP,
+ BurnTicks: logDef.BurnTicks,
+ Phase: phase,
},
}
}
@@ -158,29 +156,26 @@ func (g *Game) startStoke(sess *net.Session, p *player.Player, itemID string) {
sess.WriteLine("You begin to tend to the fire.")
- p.ActionState = &ActionState{Type: ActionStoking}
-
g.broadcastAction(sess, "\n%s tends to the fire.", p.Name)
p.Action = &action.Action{
- Type: "stoke",
+ Type: action.TypeStoke,
TargetID: itemID,
TargetName: logDef.Name,
WaitLeft: engine.ToTicks(10),
- Data: map[string]any{
- "item_id": itemID,
- "fire_key": fireKey,
- "burn_ticks": logDef.BurnTicks,
- "xp": logDef.FireXP,
+ Data: &action.BurnData{
+ ItemID: itemID,
+ BurnTicks: logDef.BurnTicks,
+ XP: logDef.FireXP,
},
}
}
func (g *Game) advanceBurn(sess *net.Session, p *player.Player) {
- data := p.Action.Data
- itemID := data["item_id"].(string)
- toolSpeed := data["tool_speed"].(float64)
- phase := data["phase"].(int)
+ d := p.Action.Data.(*action.BurnData)
+ itemID := d.ItemID
+ toolSpeed := d.ToolSpeed
+ phase := d.Phase
logDef, err := g.ItemStore.Load(itemID)
if err != nil {
@@ -201,7 +196,7 @@ func (g *Game) advanceBurn(sess *net.Session, p *player.Player) {
sess.WriteLine(g.colorize(sess, "fire", fmt.Sprintf("You drop the %s and begin to make a fire...", g.itemColorize(sess, logDef, logDef.Name))))
g.broadcastDrop(p, itemID, logDef.Name)
- data["phase"] = 1
+ d.Phase = 1
p.Action.WaitLeft = engine.ToTicks(toolSpeed)
return
}
@@ -215,7 +210,7 @@ func (g *Game) advanceBurn(sess *net.Session, p *player.Player) {
if phase == 1 {
sess.WriteLine(g.colorize(sess, "fire", fmt.Sprintf("You try burning the %s on the ground...", g.itemColorize(sess, logDef, logDef.Name))))
- data["phase"] = 2
+ d.Phase = 2
p.Action.WaitLeft = engine.ToTicks(toolSpeed)
return
}
@@ -253,17 +248,17 @@ func (g *Game) advanceBurn(sess *net.Session, p *player.Player) {
}
sess.WriteLine("You can't seem to get a fire going.")
- data["phase"] = 1
+ d.Phase = 1
p.Action.WaitLeft = engine.ToTicks(toolSpeed)
}
}
func (g *Game) advanceStoke(sess *net.Session, p *player.Player) {
- data := p.Action.Data
- itemID := data["item_id"].(string)
- fireKey := data["fire_key"].(string)
- burnTicks := data["burn_ticks"].(float64)
- xp := data["xp"].(int)
+ d := p.Action.Data.(*action.BurnData)
+ itemID := d.ItemID
+ fireKey := g.findFireObjectKey(p.RoomID)
+ burnTicks := d.BurnTicks
+ xp := d.XP
st := g.World.GetObjStateByKey(fireKey)
if st == nil || st.Quality <= 0 {
@@ -437,7 +432,7 @@ func (g *Game) FireTick() {
func (g *Game) cancelStokers(roomID int) {
for _, other := range g.Hub.PlayersInRoom(roomID) {
op := other.Player
- if op != nil && op.Action != nil && op.Action.Type == "stoke" {
+ if op != nil && op.Action != nil && op.Action.Type == action.TypeStoke {
other.WriteLine("The fire went out!")
g.cancelAction(op)
g.writePrompt(other)