diff options
Diffstat (limited to 'internal/game/action_identify.go')
| -rw-r--r-- | internal/game/action_identify.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/internal/game/action_identify.go b/internal/game/action_identify.go new file mode 100644 index 0000000..3f63e62 --- /dev/null +++ b/internal/game/action_identify.go @@ -0,0 +1,80 @@ +package game + +import ( + "fmt" + + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func (g *Game) advanceIdentify(sess *net.Session, p *player.Player) { + junkID := p.Action.Data["junk_id"].(string) + xpPer := p.Action.Data["xp_per"].(int) + + scrapCount := p.CountItem("scrap_metal") + if scrapCount == 0 { + sess.WriteLine("You don't have any scrap metal.") + 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_metal" { + 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 = def.Name + } + + msg := fmt.Sprintf("The altar hums. You identify %d scrap metal into %d %s.", scrapCount, totalJunk, junkName) + + if newLevel := p.AddSkillXP(player.Scavenging, totalXP); newLevel > 0 { + sess.WriteLine(g.colorize(sess, "level_up", + fmt.Sprintf("*** You are now level %d scavenging! ***", newLevel))) + } + + if p.OptionBool("xp_drops") && totalXP > 0 { + msg += g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp scv)", totalXP)) + } + sess.WriteLine(msg) + + g.AccountStore.SaveCharacter(p) + g.CancelAction(p) +} |
