Add qualityitems.txt loader (#622)

This commit is contained in:
Huw Griffiths 2020-07-25 23:37:43 +10:00 committed by GitHub
parent 259c6e7e76
commit 5e395092e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 0 deletions

View File

@ -228,6 +228,7 @@ func (a *App) loadDataDict() error {
{d2resource.Hireling, d2datadict.LoadHireling},
{d2resource.Experience, d2datadict.LoadExperienceBreakpoints},
{d2resource.Gems, d2datadict.LoadGems},
{d2resource.QualityItems, d2datadict.LoadQualityItems},
{d2resource.DifficultyLevels, d2datadict.LoadDifficultyLevels},
{d2resource.AutoMap, d2datadict.LoadAutoMaps},
{d2resource.LevelDetails, d2datadict.LoadLevelDetails},

View File

@ -0,0 +1,85 @@
package d2datadict
import (
"log"
"strconv"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
// QualityRecord represents a single row of QualityItems.txt, which controls
// properties for superior quality items
type QualityRecord struct {
NumMods int
Mod1Code string
Mod1Param int
Mod1Min int
Mod1Max int
Mod2Code string
Mod2Param int
Mod2Min int
Mod2Max int
// The following fields determine this row's applicability to
// categories of item.
Armor bool
Weapon bool
Shield bool
Thrown bool
Scepter bool
Wand bool
Staff bool
Bow bool
Boots bool
Gloves bool
Belt bool
Level int
Multiply int
Add int
}
// QualityItems stores all of the QualityRecords
var QualityItems map[string]*QualityRecord //nolint:gochecknoglobals // Currently global by design, only written once
// LoadQualityItems loads QualityItem records into a map[string]*QualityRecord
func LoadQualityItems(file []byte) {
QualityItems = make(map[string]*QualityRecord)
d := d2common.LoadDataDictionary(file)
for d.Next() {
qual := &QualityRecord{
NumMods: d.Number("nummods"),
Mod1Code: d.String("mod1code"),
Mod1Param: d.Number("mod1param"),
Mod1Min: d.Number("mod1min"),
Mod1Max: d.Number("mod1max"),
Mod2Code: d.String("mod2code"),
Mod2Param: d.Number("mod2param"),
Mod2Min: d.Number("mod2min"),
Mod2Max: d.Number("mod2max"),
Armor: d.Bool("armor"),
Weapon: d.Bool("weapon"),
Shield: d.Bool("shield"),
Thrown: d.Bool("thrown"),
Scepter: d.Bool("scepter"),
Wand: d.Bool("wand"),
Staff: d.Bool("staff"),
Bow: d.Bool("bow"),
Boots: d.Bool("boots"),
Gloves: d.Bool("gloves"),
Belt: d.Bool("belt"),
Level: d.Number("level"),
Multiply: d.Number("multiply"),
Add: d.Number("add"),
}
QualityItems[strconv.Itoa(len(QualityItems))] = qual
}
if d.Err != nil {
panic(d.Err)
}
log.Printf("Loaded %d QualityItems records", len(QualityItems))
}

View File

@ -181,6 +181,7 @@ const (
SoundSettings = "/data/global/excel/Sounds.txt"
ItemStatCost = "/data/global/excel/ItemStatCost.txt"
ItemTypes = "/data/global/excel/ItemTypes.txt"
QualityItems = "/data/global/excel/qualityitems.txt"
Sets = "/data/global/excel/Sets.txt"
SetItems = "/data/global/excel/SetItems.txt"
AutoMagic = "/data/global/excel/automagic.txt"