diff options
Diffstat (limited to 'internal/game/action_farm.go')
| -rw-r--r-- | internal/game/action_farm.go | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/internal/game/action_farm.go b/internal/game/action_farm.go index d294c9c..61a66cc 100644 --- a/internal/game/action_farm.go +++ b/internal/game/action_farm.go @@ -6,6 +6,7 @@ import ( "sort" "strings" + "thehouseoficarus/internal/action" "thehouseoficarus/internal/net" "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" @@ -172,9 +173,13 @@ func (g *Game) advancePlant(sess *net.Session, p *player.Player) { if p.Action == nil || p.Action.Data == nil { return } - prefix, _ := p.Action.Data["prefix"].(string) - seedID, _ := p.Action.Data["seed_id"].(string) - xp, _ := p.Action.Data["xp"].(float64) + data, ok := p.Action.Data.(*action.FarmData) + if !ok { + return + } + prefix := data.Prefix + seedID := data.SeedID + xp := data.XP g.ensureFarmState(p, prefix) @@ -204,24 +209,26 @@ func (g *Game) advancePlant(sess *net.Session, p *player.Player) { sess.WriteLine(msg) p.Action = nil - p.ActionState = nil } func (g *Game) advanceHarvest(sess *net.Session, p *player.Player) { if p.Action == nil || p.Action.Data == nil { return } - prefix, _ := p.Action.Data["prefix"].(string) - product, _ := p.Action.Data["product"].(string) - minYield, _ := p.Action.Data["min_yield"].(float64) - maxYield, _ := p.Action.Data["max_yield"].(float64) - xp, _ := p.Action.Data["xp"].(float64) + data, ok := p.Action.Data.(*action.FarmData) + if !ok { + return + } + prefix := data.Prefix + product := data.Product + minYield := data.MinYield + maxYield := data.MaxYield + xp := data.XP ready, _ := p.Flags[prefix+"_ready"].(bool) if !ready { sess.WriteLine("There's nothing ready to harvest here.") p.Action = nil - p.ActionState = nil return } @@ -239,7 +246,6 @@ func (g *Game) advanceHarvest(sess *net.Session, p *player.Player) { if yield <= 0 { sess.WriteLine("Your inventory is too full!") p.Action = nil - p.ActionState = nil return } @@ -297,14 +303,17 @@ func (g *Game) advanceHarvest(sess *net.Session, p *player.Player) { sess.WriteLine(msg) p.Action = nil - p.ActionState = nil } func (g *Game) advanceRake(sess *net.Session, p *player.Player) { if p.Action == nil || p.Action.Data == nil { return } - prefix, _ := p.Action.Data["prefix"].(string) + data, ok := p.Action.Data.(*action.FarmData) + if !ok { + return + } + prefix := data.Prefix p.Flags[prefix+"_weeds"] = false p.Flags[prefix+"_dead"] = false @@ -320,14 +329,17 @@ func (g *Game) advanceRake(sess *net.Session, p *player.Player) { sess.WriteLine(fmt.Sprintf("You rake the %s clean.", patchName)) p.Action = nil - p.ActionState = nil } func (g *Game) advanceWater(sess *net.Session, p *player.Player) { if p.Action == nil || p.Action.Data == nil { return } - prefix, _ := p.Action.Data["prefix"].(string) + data, ok := p.Action.Data.(*action.FarmData) + if !ok { + return + } + prefix := data.Prefix p.Flags[prefix+"_watered"] = true @@ -337,14 +349,17 @@ func (g *Game) advanceWater(sess *net.Session, p *player.Player) { sess.WriteLine(fmt.Sprintf("You water the %s.", patchName)) p.Action = nil - p.ActionState = nil } func (g *Game) advanceCure(sess *net.Session, p *player.Player) { if p.Action == nil || p.Action.Data == nil { return } - prefix, _ := p.Action.Data["prefix"].(string) + data, ok := p.Action.Data.(*action.FarmData) + if !ok { + return + } + prefix := data.Prefix p.RemoveItem("plant_cure", 1) p.Flags[prefix+"_diseased"] = false @@ -354,7 +369,6 @@ func (g *Game) advanceCure(sess *net.Session, p *player.Player) { sess.WriteLine("You apply the plant cure. The patch looks healthy again.") p.Action = nil - p.ActionState = nil } func patchDisplayName(prefix string) string { |
