aboutsummaryrefslogtreecommitdiff
path: root/internal/game/core_production.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/core_production.go
parent15b7e221b799ef107dec44ecdb294026dfd3d059 (diff)
downloadthehouseoficarus-94a06fbbe682701ca4d4bd2a70cd74d8df29c932.tar.gz
refactor: replaced map[string]any with typed structs for Data
Diffstat (limited to 'internal/game/core_production.go')
-rw-r--r--internal/game/core_production.go73
1 files changed, 38 insertions, 35 deletions
diff --git a/internal/game/core_production.go b/internal/game/core_production.go
index dd36885..56d1ccc 100644
--- a/internal/game/core_production.go
+++ b/internal/game/core_production.go
@@ -75,7 +75,7 @@ func (g *Game) resolveCraftMessage(sess *net.Session, itemMsg, defaultMsg string
return g.resolveCraftVar(sess, msg, craft, outputID, byproducts, hasItem)
}
-func (g *Game) startProduction(sess *net.Session, p *player.Player, item *object.ItemDef, craft *object.CraftDef, actionType, displayVerb, startMsg, endMsg string, count int) {
+func (g *Game) startProduction(sess *net.Session, p *player.Player, item *object.ItemDef, craft *object.CraftDef, actionType action.ActionType, displayVerb, startMsg, endMsg string, count int) {
g.cancelAction(p)
g.cancelBgAction(p)
@@ -111,19 +111,17 @@ func (g *Game) startProduction(sess *net.Session, p *player.Player, item *object
Type: actionType,
TargetID: item.ID,
TargetName: outputName,
- Data: map[string]any{
- "item_id": item.ID,
- "phase": 0,
- "wait": wait,
- "start_msg": startMsg,
- "end_msg": endMsg,
- "remaining": count,
+ Data: &action.ProductionData{
+ ItemID: item.ID,
+ Phase: 0,
+ Wait: wait,
+ StartMsg: startMsg,
+ EndMsg: endMsg,
+ Remaining: count,
},
WaitLeft: engine.ToTicks(1),
}
- p.ActionState = &ActionState{Type: ActionProducing, TargetName: outputName, Verb: displayVerb}
-
g.broadcastAction(sess, "%s starts %s.", p.Name, displayVerb)
}
@@ -141,7 +139,7 @@ func (g *Game) startProductionFromItem(sess *net.Session, p *player.Player, item
info, ok := productionTypes[craft.Type]
if !ok {
info = productionTypeInfo{
- ActionType: craft.Type,
+ ActionType: action.ActionType(craft.Type),
DisplayVerb: craft.Type,
StartMessage: "You start " + craft.Type + " %i1.",
SuccessMessage: "You produce %n.",
@@ -168,12 +166,17 @@ func (g *Game) loadCraftItem(itemID string) *object.ItemDef {
}
func (g *Game) advanceProduction(sess *net.Session, p *player.Player) bool {
- itemID := p.Action.Data["item_id"].(string)
- phase := p.Action.Data["phase"].(int)
- wait := p.Action.Data["wait"].(float64)
- startMsg, _ := p.Action.Data["start_msg"].(string)
- endMsg, _ := p.Action.Data["end_msg"].(string)
- remaining, _ := p.Action.Data["remaining"].(int)
+ d, ok := p.Action.Data.(*action.ProductionData)
+ if !ok {
+ g.cancelAction(p)
+ return false
+ }
+ itemID := d.ItemID
+ phase := d.Phase
+ wait := d.Wait
+ startMsg := d.StartMsg
+ endMsg := d.EndMsg
+ remaining := d.Remaining
item := g.loadCraftItem(itemID)
if item == nil {
@@ -187,22 +190,22 @@ func (g *Game) advanceProduction(sess *net.Session, p *player.Player) bool {
sess.WriteLine(startMsg)
}
if len(craft.Steps) > 0 {
- p.Action.Data["next_step_index"] = 0
- p.Action.Data["steps_accumulated_ticks"] = float64(0)
+ d.NextStepIndex = 0
+ d.StepsAccumulatedTicks = 0
}
- p.Action.Data["phase"] = 1
+ d.Phase = 1
p.Action.WaitLeft = engine.ToTicks(wait)
return true
}
- if stepsIdx, ok := p.Action.Data["next_step_index"].(int); ok && stepsIdx < len(craft.Steps) {
- accTicks, _ := p.Action.Data["steps_accumulated_ticks"].(float64)
+ if stepsIdx := d.NextStepIndex; stepsIdx < len(craft.Steps) {
+ accTicks := d.StepsAccumulatedTicks
accTicks += wait
- p.Action.Data["steps_accumulated_ticks"] = accTicks
+ d.StepsAccumulatedTicks = accTicks
for i := stepsIdx; i < len(craft.Steps); i++ {
if accTicks >= craft.Steps[i].Tick {
sess.WriteLine(g.resolveCraftVar(sess, craft.Steps[i].Message, craft, item.ID, nil, p.HasItem))
- p.Action.Data["next_step_index"] = i + 1
+ d.NextStepIndex = i + 1
}
}
}
@@ -291,7 +294,7 @@ func (g *Game) advanceProduction(sess *net.Session, p *player.Player) bool {
if remaining > 0 {
remaining--
- p.Action.Data["remaining"] = remaining
+ d.Remaining = remaining
if remaining <= 0 {
if endMsg != "" {
sess.WriteLine(endMsg)
@@ -646,7 +649,7 @@ func (g *Game) hasToolType(p *player.Player, toolType string) bool {
}
type productionTypeInfo struct {
- ActionType string
+ ActionType action.ActionType
DisplayVerb string
StartMessage string
SuccessMessage string
@@ -656,7 +659,7 @@ type productionTypeInfo struct {
var productionTypes = map[string]productionTypeInfo{
"cooking": {
- ActionType: "cook",
+ ActionType: action.TypeCook,
DisplayVerb: "cooking",
StartMessage: "You start cooking %i1.",
SuccessMessage: "Cooked to perfection. %n looks great!",
@@ -664,7 +667,7 @@ var productionTypes = map[string]productionTypeInfo{
FailMessage: "You accidentally burn the %i1.",
},
"smelting": {
- ActionType: "smelt",
+ ActionType: action.TypeSmelt,
DisplayVerb: "smelting",
StartMessage: "You place the %i1 into the furnace.",
SuccessMessage: "You remove a white hot %n!",
@@ -672,42 +675,42 @@ var productionTypes = map[string]productionTypeInfo{
FailMessage: "The %i1 is consumed by the flames.",
},
"smithing": {
- ActionType: "smith",
+ ActionType: action.TypeSmith,
DisplayVerb: "smithing",
StartMessage: "You begin smithing %i1.",
SuccessMessage: "You smith a %n.",
EndMessage: "You've finished smithing.",
},
"crafting": {
- ActionType: "craft",
+ ActionType: action.TypeCraft,
DisplayVerb: "crafting",
StartMessage: "You begin crafting %i1.",
SuccessMessage: "You craft a %n.",
EndMessage: "You've finished crafting.",
},
"combine": {
- ActionType: "combine",
+ ActionType: action.TypeCombine,
DisplayVerb: "combining",
StartMessage: "You start combining %i1.",
SuccessMessage: "You produce %n.",
EndMessage: "You've finished combining.",
},
"fletching": {
- ActionType: "fletch",
+ ActionType: action.TypeFletch,
DisplayVerb: "fletching",
StartMessage: "You begin fletching %i1.",
SuccessMessage: "You fletch a %n.",
EndMessage: "You've finished fletching.",
},
"pharmacy": {
- ActionType: "mix",
+ ActionType: action.TypeMix,
DisplayVerb: "mixing",
StartMessage: "You start mixing %i1.",
SuccessMessage: "You mix a %n.",
EndMessage: "You've finished mixing.",
},
"construction": {
- ActionType: "construct",
+ ActionType: action.TypeConstruct,
DisplayVerb: "constructing",
StartMessage: "You begin constructing %i1.",
SuccessMessage: "You construct a %n.",
@@ -720,7 +723,7 @@ var productionActionTypes map[string]bool
func init() {
productionActionTypes = make(map[string]bool)
for _, pt := range productionTypes {
- productionActionTypes[pt.ActionType] = true
+ productionActionTypes[string(pt.ActionType)] = true
}
}