From 35d936ac4e6d557fa9ec753cb645a14f6952b599 Mon Sep 17 00:00:00 2001 From: Huw Griffiths Date: Tue, 28 Jul 2020 21:53:32 +1000 Subject: [PATCH] d2datadict: Add runes.txt loader (#635) --- d2app/app.go | 1 + d2common/d2data/d2datadict/runes.go | 146 ++++++++++++++++++++++++++ d2common/d2resource/resource_paths.go | 1 + 3 files changed, 148 insertions(+) create mode 100644 d2common/d2data/d2datadict/runes.go diff --git a/d2app/app.go b/d2app/app.go index 6de375ce..7769303e 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -230,6 +230,7 @@ func (a *App) loadDataDict() error { {d2resource.Experience, d2datadict.LoadExperienceBreakpoints}, {d2resource.Gems, d2datadict.LoadGems}, {d2resource.QualityItems, d2datadict.LoadQualityItems}, + {d2resource.Runes, d2datadict.LoadRunes}, {d2resource.DifficultyLevels, d2datadict.LoadDifficultyLevels}, {d2resource.AutoMap, d2datadict.LoadAutoMaps}, {d2resource.LevelDetails, d2datadict.LoadLevelDetails}, diff --git a/d2common/d2data/d2datadict/runes.go b/d2common/d2data/d2datadict/runes.go new file mode 100644 index 00000000..58c8fbb7 --- /dev/null +++ b/d2common/d2data/d2datadict/runes.go @@ -0,0 +1,146 @@ +package d2datadict + +import ( + "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" +) + +// RunesRecord is a representation of a single row of runes.txt. It defines +// runewords available in the game. +type RunesRecord struct { + Name string + RuneName string // More of a note - the actual name should be read from the TBL files. + Complete bool // An enabled/disabled flag. Only "Complete" runewords work in game. + Server bool // Marks a runeword as only available on ladder, not single player or tcp/ip. + + // IType1-6 include item types into the list of item types that this runeword works in. + IType1 string + IType2 string + IType3 string + IType4 string + IType5 string + IType6 string + + // EType1-3 exclude item types from the list of item types that this runeword works in. + EType1 string + EType2 string + EType3 string + + Runes string // The runes as they would appear in the finished runeword. Note field only. + + // Rune1-6 are ID pointers from Misc.txt. The fields control what runes are + // required to make the rune word and in what order they are to be socketed. + Rune1 string + Rune2 string + Rune3 string + Rune4 string + Rune5 string + Rune6 string + + T1Code1 string + T1Param1 string + T1Min1 int + T1Max1 int + + T1Code2 string + T1Param2 string + T1Min2 int + T1Max2 int + + T1Code3 string + T1Param3 string + T1Min3 int + T1Max3 int + + T1Code4 string + T1Param4 string + T1Min4 int + T1Max4 int + + T1Code5 string + T1Param5 string + T1Min5 int + T1Max5 int + + T1Code6 string + T1Param6 string + T1Min6 int + T1Max6 int + + T1Code7 string + T1Param7 string + T1Min7 int + T1Max7 int + + // EOL int // not loaded +} + +// Runes stores all of the RunesRecords +var Runes map[string]*RunesRecord //nolint:gochecknoglobals // Currently global by design, only written once + +// LoadRunes loads runes records into a map[string]*RunesRecord +func LoadRunes(file []byte) { + Runes = make(map[string]*RunesRecord) + + d := d2common.LoadDataDictionary(file) + for d.Next() { + record := &RunesRecord{ + Name: d.String("name"), + RuneName: d.String("Rune Name"), + Complete: d.Bool("complete"), + Server: d.Bool("server"), + IType1: d.String("itype1"), + IType2: d.String("itype2"), + IType3: d.String("itype3"), + IType4: d.String("itype4"), + IType5: d.String("itype5"), + IType6: d.String("itype6"), + EType1: d.String("etype1"), + EType2: d.String("etype2"), + EType3: d.String("etype3"), + Runes: d.String("*runes"), + Rune1: d.String("Rune1"), + Rune2: d.String("Rune2"), + Rune3: d.String("Rune3"), + Rune4: d.String("Rune4"), + Rune5: d.String("Rune5"), + Rune6: d.String("Rune6"), + T1Code1: d.String("T1Code1"), + T1Param1: d.String("T1Param1"), + T1Min1: d.Number("T1Min1"), + T1Max1: d.Number("T1Max1"), + T1Code2: d.String("T1Code2"), + T1Param2: d.String("T1Param2"), + T1Min2: d.Number("T1Min2"), + T1Max2: d.Number("T1Max2"), + T1Code3: d.String("T1Code3"), + T1Param3: d.String("T1Param3"), + T1Min3: d.Number("T1Min3"), + T1Max3: d.Number("T1Max3"), + T1Code4: d.String("T1Code4"), + T1Param4: d.String("T1Param4"), + T1Min4: d.Number("T1Min4"), + T1Max4: d.Number("T1Max4"), + T1Code5: d.String("T1Code5"), + T1Param5: d.String("T1Param5"), + T1Min5: d.Number("T1Min5"), + T1Max5: d.Number("T1Max5"), + T1Code6: d.String("T1Code6"), + T1Param6: d.String("T1Param6"), + T1Min6: d.Number("T1Min6"), + T1Max6: d.Number("T1Max6"), + T1Code7: d.String("T1Code7"), + T1Param7: d.String("T1Param7"), + T1Min7: d.Number("T1Min7"), + T1Max7: d.Number("T1Max7"), + } + Runes[record.Name] = record + } + + if d.Err != nil { + panic(d.Err) + } + + log.Printf("Loaded %d Runes records", len(Runes)) +} diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 2087abda..413d6db0 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -182,6 +182,7 @@ const ( ItemStatCost = "/data/global/excel/ItemStatCost.txt" ItemTypes = "/data/global/excel/ItemTypes.txt" QualityItems = "/data/global/excel/qualityitems.txt" + Runes = "/data/global/excel/runes.txt" Sets = "/data/global/excel/Sets.txt" SetItems = "/data/global/excel/SetItems.txt" AutoMagic = "/data/global/excel/automagic.txt"