Skip to content

Commit 7ad4472

Browse files
committed
Refactored ItemLookData to use string-based type comparisons
Changed: - Replaced boolean fields (IsWeapon, IsReadable, etc.) with Type and Subtype strings - Replaced IsCursed/IsEnchanted booleans with extensible Adjectives map - Updated templates to use string equality checks (e.g., {{if eq .Type "readable"}}) Fixed: - Corrected TimeoutMods YAML formatting from multi-line to single-line
1 parent e84b47f commit 7ad4472

File tree

4 files changed

+36
-44
lines changed

4 files changed

+36
-44
lines changed

_datafiles/config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,8 @@ Network:
420420
# - TimeoutMods -
421421
# Whether Admin/Mod users get timed out when reaching MaxIdleSeconds
422422
# If set to false, Admins & Mods never get force disconnected.
423-
TimeoutMods:
424-
false
425-
# - ZombieSeconds -
423+
TimeoutMods: false
424+
# - ZombieSeconds -
426425
# How many seconds a character stays active/in game after a network connection
427426
# is lost. Set to 0 to instantly log out characters (exploitable).
428427
ZombieSeconds: 60

_datafiles/world/default/templates/descriptions/look-item.screenreader.template

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
You look at the {{ .Item.Name }} {{ .Location }}:
33

44
{{ .ItemSpec.Description }}
5-
{{- if .IsReadable }}
5+
{{- if eq .Type "readable" }}
66
You should probably read this.
7-
{{- else if .IsDrinkable }}
7+
{{- else if eq .Subtype "drinkable" }}
88
You could probably drink this.
9-
{{- else if .IsEdible }}
9+
{{- else if eq .Subtype "edible" }}
1010
You could probably eat this.
11-
{{- else if .IsLockpicks }}
11+
{{- else if eq .Type "lockpicks" }}
1212
These are used with the picklock command.
13-
{{- else if .IsKey }}
13+
{{- else if eq .Type "key" }}
1414
When you find the right door, keys are added to your keyring automatically.
15-
{{- else if .IsWearable }}
15+
{{- else if eq .Subtype "wearable" }}
1616
It looks like wearable {{ .ItemSpec.Type }} equipment.
1717
{{- end }}
18-
{{- if .IsWeapon }}
18+
{{- if eq .Type "weapon" }}
1919
It looks like a {{ .WeaponHands }}-Handed weapon.
2020
{{- if eq .WeaponType "claws" }}
2121
It looks like a claws weapon. These can be dual wielded without training.
@@ -29,9 +29,9 @@ It requires an extra {{ .WaitRounds }} round(s) between attacks.
2929
{{- if .HasUses }}
3030
It has {{ .UsesRemaining }}/{{ .MaxUses }} uses remaining.
3131
{{- end }}
32-
{{- if .IsCursed }}
32+
{{- if index .Adjectives "cursed" }}
3333
It's CURSED! Once equipped, it cannot be removed without magical help.
3434
{{- end }}
35-
{{- if .IsEnchanted }}
35+
{{- if index .Adjectives "enchanted" }}
3636
It glows with a magical aura (enchantment level {{ .EnchantLevel }}).
3737
{{- end }}

_datafiles/world/default/templates/descriptions/look-item.template

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
You look at the <ansi fg="item">{{ .Item.DisplayName }}</ansi> {{ .Location }}:
33

44
{{ .ItemSpec.Description }}
5-
{{- if .IsReadable }}
5+
{{- if eq .Type "readable" }}
66
- You should probably <ansi fg="command">read</ansi> this.
7-
{{- else if .IsDrinkable }}
7+
{{- else if eq .Subtype "drinkable" }}
88
- You could probably <ansi fg="command">drink</ansi> this.
9-
{{- else if .IsEdible }}
9+
{{- else if eq .Subtype "edible" }}
1010
- You could probably <ansi fg="command">eat</ansi> this.
11-
{{- else if .IsLockpicks }}
11+
{{- else if eq .Type "lockpicks" }}
1212
- These are used with the <ansi fg="command">picklock</ansi> command.
13-
{{- else if .IsKey }}
13+
{{- else if eq .Type "key" }}
1414
- When you find the right door, keys are added to your keyring automatically.
15-
{{- else if .IsWearable }}
15+
{{- else if eq .Subtype "wearable" }}
1616
- It looks like wearable <ansi fg="magenta">{{ .ItemSpec.Type }}</ansi> equipment.
1717
{{- end }}
18-
{{- if .IsWeapon }}
18+
{{- if eq .Type "weapon" }}
1919
- It looks like a <ansi fg="yellow">{{ .WeaponHands }}-Handed</ansi> weapon.
2020
{{- if eq .WeaponType "claws" }}
2121
- It looks like a <ansi fg="yellow">claws</ansi> weapon. These can be dual wielded without training.
@@ -29,9 +29,9 @@ You look at the <ansi fg="item">{{ .Item.DisplayName }}</ansi> {{ .Location }}:
2929
{{- if .HasUses }}
3030
- It has <ansi fg="yellow">{{ .UsesRemaining }}/{{ .MaxUses }}</ansi> uses remaining.
3131
{{- end }}
32-
{{- if .IsCursed }}
32+
{{- if index .Adjectives "cursed" }}
3333
- It's <ansi fg="red-bold">CURSED!</ansi> Once equipped, it cannot be removed without magical help.
3434
{{- end }}
35-
{{- if .IsEnchanted }}
35+
{{- if index .Adjectives "enchanted" }}
3636
- It glows with a <ansi fg="enchanted">magical aura</ansi> (enchantment level {{ .EnchantLevel }}).
3737
{{- end }}

internal/items/items.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,16 @@ func (i *Item) Validate() {
172172
type ItemLookData struct {
173173
Item *Item
174174
ItemSpec ItemSpec
175-
Location string // "in your backpack", "you are wearing"
176-
IsWeapon bool
177-
IsReadable bool
178-
IsDrinkable bool
179-
IsEdible bool
180-
IsLockpicks bool
181-
IsKey bool
182-
IsWearable bool
183-
IsUsable bool
175+
Location string // "in your backpack", "you are wearing"
176+
Type string // Item type for template comparisons
177+
Subtype string // Item subtype for template comparisons
178+
Adjectives map[string]bool // Extensible flags (cursed, enchanted, etc)
184179
WeaponHands int
185180
WeaponType string // "claws", "shooting", etc.
186181
WaitRounds int
187182
HasUses bool
188183
UsesRemaining int
189184
MaxUses int
190-
IsCursed bool
191-
IsEnchanted bool
192185
EnchantLevel int
193186
}
194187

@@ -197,7 +190,10 @@ func (i *Item) GetLookData(location string) ItemLookData {
197190
// Defensive check for nil item
198191
if i == nil {
199192
return ItemLookData{
200-
Location: location,
193+
Location: location,
194+
Type: "",
195+
Subtype: "",
196+
Adjectives: make(map[string]bool),
201197
}
202198
}
203199

@@ -207,23 +203,20 @@ func (i *Item) GetLookData(location string) ItemLookData {
207203
Item: i,
208204
ItemSpec: iSpec,
209205
Location: location,
210-
IsWeapon: iSpec.Type == Weapon,
211-
IsReadable: iSpec.Type == Readable,
212-
IsDrinkable: iSpec.Subtype == Drinkable,
213-
IsEdible: iSpec.Subtype == Edible,
214-
IsLockpicks: iSpec.Type == Lockpicks,
215-
IsKey: iSpec.Type == Key,
216-
IsWearable: iSpec.Subtype == Wearable,
217-
IsUsable: iSpec.Subtype == Usable,
206+
Type: string(iSpec.Type),
207+
Subtype: string(iSpec.Subtype),
208+
Adjectives: make(map[string]bool),
218209
HasUses: iSpec.Uses > 0,
219210
UsesRemaining: i.Uses,
220211
MaxUses: iSpec.Uses,
221-
IsCursed: i.IsCursed(),
222-
IsEnchanted: i.Enchantments > 0,
223212
EnchantLevel: int(i.Enchantments),
224213
}
225214

226-
if data.IsWeapon {
215+
// Set adjectives for extensibility
216+
data.Adjectives["cursed"] = i.IsCursed()
217+
data.Adjectives["enchanted"] = i.Enchantments > 0
218+
219+
if iSpec.Type == Weapon {
227220
data.WeaponHands = iSpec.Hands
228221
data.WaitRounds = iSpec.WaitRounds
229222

0 commit comments

Comments
 (0)