aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_id.go
blob: 6514463e1abb86bab55ce74637c6e45e4c363a99 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/action"
	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
)

type altarConfig struct {
	AltarID      string
	IdentifierID string
	JunkID       string
	LevelReq     int
	XPPer        int
}

var altarConfigs = []altarConfig{
	{"solar_altar", "solar_identifier", "solarjunk", 1, 5},
	{"hydro_altar", "hydro_identifier", "hydrojunk", 14, 8},
	{"cosmic_altar", "cosmic_identifier", "cosmicjunk", 27, 10},
	{"eco_altar", "eco_identifier", "ecojunk", 28, 12},
	{"chaos_altar", "chaos_identifier", "chaosjunk", 35, 11},
	{"bio_altar", "bio_identifier", "biojunk", 44, 16},
	{"nature_altar", "nature_identifier", "naturejunk", 44, 16},
	{"law_altar", "law_identifier", "lawjunk", 54, 18},
	{"death_altar", "death_identifier", "deathjunk", 65, 22},
	{"blood_altar", "blood_identifier", "bloodjunk", 77, 28},
}

type junkMultiplierEntry struct {
	Level      int
	Multiplier int
}

var junkMultipliers = map[string][]junkMultiplierEntry{
	"solarjunk": {
		{1, 1}, {22, 2}, {44, 3}, {66, 4}, {88, 5}, {99, 6},
	},
	"hydrojunk": {
		{14, 1}, {36, 2}, {66, 3}, {88, 4},
	},
	"cosmicjunk": {
		{27, 1}, {56, 2}, {78, 3},
	},
	"ecojunk": {
		{28, 1}, {56, 2}, {78, 3},
	},
	"chaosjunk": {
		{35, 1}, {66, 2}, {88, 3},
	},
	"biojunk": {
		{44, 1}, {78, 2}, {99, 3},
	},
	"naturejunk": {
		{44, 1}, {78, 2}, {99, 3},
	},
	"lawjunk": {
		{54, 1}, {88, 2},
	},
	"deathjunk": {
		{65, 1}, {99, 2},
	},
	"bloodjunk": {
		{77, 1}, {99, 2},
	},
}

func junkMultiplier(junkID string, level int) int {
	entries, ok := junkMultipliers[junkID]
	if !ok {
		return 1
	}
	mult := 1
	for _, e := range entries {
		if level >= e.Level {
			mult = e.Multiplier
		}
	}
	return mult
}

func (g *Game) executeIdentify(sess *net.Session, args []string, rawInput string) {
	g.doIdentify(sess, strings.Join(args, " "))
}

func (g *Game) doIdentify(sess *net.Session, input string) {
	p := sess.Player
	g.cancelAction(p)

	var found altarConfig
	foundAny := false
	for _, ac := range altarConfigs {
		if defID, _ := g.findStation(p.RoomID, []string{ac.AltarID}); defID != "" {
			found = ac
			foundAny = true
			break
		}
	}
	if !foundAny {
		sess.WriteLine("There is no altar here.")
		return
	}

	identifierName := found.IdentifierID
	if def, err := g.ItemStore.Load(found.IdentifierID); err == nil {
		identifierName = def.Name
	}
	if !p.HasItem(found.IdentifierID) {
		sess.WriteLine(fmt.Sprintf("You need a %s to use this altar.", identifierName))
		return
	}

	scrapCount := p.CountItem("scrap")
	if scrapCount == 0 {
		sess.WriteLine("You don't have any scrap.")
		return
	}

	scavLevel := p.Level(player.Scavenging)
	if scavLevel < found.LevelReq {
		junkName := found.JunkID
		if def, err := g.ItemStore.Load(found.JunkID); err == nil {
			junkName = def.Name
		}
		sess.WriteLine(fmt.Sprintf("You need level %d scavenging to identify %s.", found.LevelReq, junkName))
		return
	}

	altarName := found.AltarID
	if def, err := g.ObjectStore.Load(found.AltarID); err == nil {
		altarName = def.Name
	}

	p.Action = &action.Action{
		Type:       "identify",
		TargetID:   found.AltarID,
		TargetName: altarName,
		WaitLeft:   1,
		Data: map[string]any{
			"junk_id":   found.JunkID,
			"xp_per":    found.XPPer,
			"level_req": found.LevelReq,
		},
	}
	p.ActionState = &ActionState{Type: ActionIdentifying, TargetName: altarName}
}