From abd612c15799f604e671e83dc7c410ed2b44185f Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Thu, 25 Jun 2026 15:40:48 -0400 Subject: slop refactor --- internal/game/act_identify.go | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 internal/game/act_identify.go (limited to 'internal/game/act_identify.go') diff --git a/internal/game/act_identify.go b/internal/game/act_identify.go new file mode 100644 index 0000000..b905494 --- /dev/null +++ b/internal/game/act_identify.go @@ -0,0 +1,83 @@ +package game + +import ( + "fmt" + + "thehouseoficarus/internal/behavior" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func (g *Game) advanceIdentify(sess *net.Session, p *player.Player) { + data, ok := p.Action.Data.(*behavior.IdentifyData) + if !ok { + g.cancelAction(p) + return + } + junkID := data.JunkID + xpPer := data.XPPer + + scrapCount := p.CountItem("scrap") + if scrapCount == 0 { + sess.WriteLine("You don't have any scrap.") + g.cancelAction(p) + return + } + + scavLevel := p.Level(player.Scavenging) + multiplier := junkMultiplier(junkID, scavLevel) + totalJunk := scrapCount * multiplier + + hasExistingStack := false + for i := 0; i < 28; i++ { + slot := p.InvSlot(i) + if slot != nil && slot.ItemID == junkID { + hasExistingStack = true + break + } + } + if !hasExistingStack && p.FirstFreeSlot() == -1 { + sess.WriteLine("Your inventory is too full!") + g.cancelAction(p) + return + } + + for i := 0; i < 28; i++ { + slot := p.InvSlot(i) + if slot != nil && slot.ItemID == "scrap" { + p.SetInvSlot(i, nil) + } + } + + placed := false + for i := 0; i < 28; i++ { + slot := p.InvSlot(i) + if slot != nil && slot.ItemID == junkID { + slot.Quantity += totalJunk + placed = true + break + } + } + if !placed { + freeSlot := p.FirstFreeSlot() + p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: junkID, Quantity: totalJunk}) + } + + totalXP := scrapCount * xpPer + junkName := junkID + if def, err := g.ItemStore.Load(junkID); err == nil { + junkName = g.itemColorize(sess, def, def.Name) + } + + msg := fmt.Sprintf("The altar hums. You identify %d scrap into %d %s.", scrapCount, totalJunk, junkName) + + g.awardSkillXP(sess, p, player.Scavenging, totalXP) + + if p.OptionBool("xp_drops") && totalXP > 0 { + msg += g.formatXpDropSingle(sess, p, player.Scavenging, totalXP) + } + sess.WriteLine(msg) + + g.AccountStore.SaveCharacter(p) + g.cancelAction(p) +} -- cgit v1.2.3