aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_identify.go
blob: b04bf975af7f10c2f48a4fe06463c46506de6d7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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)

	g.awardSkillXP(sess, p, player.Scavenging, totalXP)

	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)
}