aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_search.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/action_search.go')
-rw-r--r--internal/game/action_search.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/internal/game/action_search.go b/internal/game/action_search.go
index 5cb8644..0f755a5 100644
--- a/internal/game/action_search.go
+++ b/internal/game/action_search.go
@@ -26,43 +26,43 @@ func (g *Game) startSearch(sess *net.Session, p *player.Player, itemID string, s
TargetID: itemID,
TargetName: def.Name,
WaitLeft: engine.ToTicks(ticks),
- Data: map[string]any{
- "item_id": itemID,
- "slot_idx": slotIdx,
- "started": false,
+ Data: &action.SearchData{
+ ItemID: itemID,
+ SlotIdx: slotIdx,
+ Started: false,
},
}
- p.ActionState = &ActionState{Type: ActionSearching, TargetName: def.Name}
-
g.broadcastAction(sess, "\n%s searches a %s.", p.Name, def.Name)
}
func (g *Game) advanceSearch(sess *net.Session, p *player.Player) {
- data := p.Action.Data
- itemID := data["item_id"].(string)
- slotIdx := data["slot_idx"].(int)
- started := data["started"].(bool)
+ d, ok := p.Action.Data.(*action.SearchData)
+ if !ok || d == nil {
+ sess.WriteLine("Something went wrong.")
+ g.cancelAction(p)
+ return
+ }
- def, err := g.ItemStore.Load(itemID)
+ def, err := g.ItemStore.Load(d.ItemID)
if err != nil {
sess.WriteLine("Something went wrong.")
g.cancelAction(p)
return
}
- if !started {
+ if !d.Started {
msg := def.SearchMessage
if msg == "" {
msg = fmt.Sprintf("digging through the %s", def.Name)
}
sess.WriteLine(fmt.Sprintf("You begin %s.", msg))
- data["started"] = true
+ d.Started = true
return
}
- slot := p.InvSlot(slotIdx)
- if slot == nil || slot.ItemID != itemID || slot.Quantity <= 0 {
+ slot := p.InvSlot(d.SlotIdx)
+ if slot == nil || slot.ItemID != d.ItemID || slot.Quantity <= 0 {
sess.WriteLine("The item is gone.")
g.cancelAction(p)
return
@@ -71,7 +71,7 @@ func (g *Game) advanceSearch(sess *net.Session, p *player.Player) {
if slot.Quantity > 1 {
slot.Quantity--
} else {
- p.SetInvSlot(slotIdx, nil)
+ p.SetInvSlot(d.SlotIdx, nil)
}
dt, err := action.LoadDropTable(g.DataDir, def.SearchTable)