adjustement

This commit is contained in:
guiyomu-dev
2026-02-14 21:10:31 +01:00
parent 285129e47e
commit 48aa3aee66
6 changed files with 39 additions and 24 deletions

7
pkg/data/game/game.go Normal file
View File

@@ -0,0 +1,7 @@
package game
const (
CharClassic uint16 = 1
CharLoD uint16 = 2
CharDLC uint16 = 3
)

View File

@@ -1,18 +1,16 @@
package item
import "strings"
import (
"strings"
"github.com/hectorgimenez/d2go/pkg/data/game"
)
const (
ExpCharItemIDThreshold = 508
ExpCharItemIDOffset = 15
)
var ExpChar uint16
func SetExpChar(expChar uint16) {
ExpChar = expChar
}
const (
ScrollOfTownPortal = "ScrollOfTownPortal"
ScrollOfIdentify = "ScrollOfIdentify"
@@ -21,9 +19,9 @@ const (
Key = "Key"
)
func GetNameByEnum(itemNumber uint) Name {
func GetNameByEnumWithExpChar(expChar uint16, itemNumber uint) Name {
idx := int(itemNumber)
if ExpChar >= 3 && idx >= ExpCharItemIDThreshold {
if expChar >= game.CharDLC && idx >= ExpCharItemIDThreshold {
idx += ExpCharItemIDOffset
}
if idx < 0 || idx >= len(Names) {
@@ -32,17 +30,16 @@ func GetNameByEnum(itemNumber uint) Name {
return Name(Names[idx])
}
func GetIDByName(itemName string) int {
// DescIDByName returns the internal description/index ID for an item name.
// This ID matches the keys used by Desc and the indices in the Names slice.
func DescIDByName(itemName string) (int, bool) {
for i, name := range Names {
if strings.EqualFold(name, itemName) {
if ExpChar >= 3 && i >= ExpCharItemIDThreshold+ExpCharItemIDOffset {
return i - ExpCharItemIDOffset
}
return i
return i, true
}
}
return -1
return -1, false
}
type Name string

View File

@@ -121,11 +121,17 @@ type Drop struct {
}
func (i Item) Desc() item.Description {
id := i.ID
if item.ExpChar >= 3 && id >= item.ExpCharItemIDThreshold {
id += item.ExpCharItemIDOffset
if descID, ok := item.DescIDByName(string(i.Name)); ok {
if desc, found := item.Desc[descID]; found {
return desc
}
}
return item.Desc[id]
if desc, found := item.Desc[i.ID]; found {
return desc
}
return item.Description{}
}
func (i Item) Type() item.Type {