diff --git a/d2app/app.go b/d2app/app.go index 5a100683..dce7557f 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -214,6 +214,7 @@ func (a *App) loadDataDict() error { {d2resource.ObjectDetails, d2datadict.LoadObjects}, {d2resource.Weapons, d2datadict.LoadWeapons}, {d2resource.Armor, d2datadict.LoadArmors}, + {d2resource.Books, d2datadict.LoadBooks}, {d2resource.Misc, d2datadict.LoadMiscItems}, {d2resource.UniqueItems, d2datadict.LoadUniqueItems}, {d2resource.Missiles, d2datadict.LoadMissiles}, diff --git a/d2common/d2data/d2datadict/books.go b/d2common/d2data/d2datadict/books.go new file mode 100644 index 00000000..2ef3825f --- /dev/null +++ b/d2common/d2data/d2datadict/books.go @@ -0,0 +1,54 @@ +package d2datadict + +import ( + "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" +) + +// BooksRecord is a representation of a row from books.txt +type BooksRecord struct { + Name string + Namco string // The displayed name, where the string prefix is "Tome" + Completed string + ScrollSpellCode string + BookSpellCode string + pSpell int + SpellIcon int + ScrollSkill string + BookSkill string + BaseCost int + CostPerCharge int +} + +// Books stores all of the BooksRecords +var Books map[string]*BooksRecord //nolint:gochecknoglobals // Currently global by design, only written once + +// LoadBooks loads Books records into a map[string]*BooksRecord +func LoadBooks(file []byte) { + Books = make(map[string]*BooksRecord) + + d := d2common.LoadDataDictionary(file) + for d.Next() { + record := &BooksRecord{ + Name: d.String("Name"), + Namco: d.String("Namco"), + Completed: d.String("Completed"), + ScrollSpellCode: d.String("ScrollSpellCode"), + BookSpellCode: d.String("BooksSpellCode"), + pSpell: d.Number("pSpell"), + SpellIcon: d.Number("SpellIcon"), + ScrollSkill: d.String("ScrollSkill"), + BookSkill: d.String("BookSkill"), + BaseCost: d.Number("BaseCost"), + CostPerCharge: d.Number("CostPerCharge"), + } + Books[record.Namco] = record + } + + if d.Err != nil { + panic(d.Err) + } + + log.Printf("Loaded %d book items", len(Books)) +} diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 134cf550..1fe66a89 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -212,6 +212,7 @@ const ( Inventory = "/data/global/excel/inventory.txt" Weapons = "/data/global/excel/weapons.txt" Armor = "/data/global/excel/armor.txt" + Books = "/data/global/excel/books.txt" Misc = "/data/global/excel/misc.txt" UniqueItems = "/data/global/excel/UniqueItems.txt" Gems = "/data/global/excel/gems.txt"