From 333b8610acfc8bbfc3ed5f08c533e2d9528e127b Mon Sep 17 00:00:00 2001 From: AndrejMijic <44673317+AndrejMijic@users.noreply.github.com> Date: Thu, 30 Jul 2020 17:31:32 +0200 Subject: [PATCH] Add pettype.txt loader (#648) * Add pettype.txt loader * Remove go.mod replace --- d2app/app.go | 1 + d2common/d2data/d2datadict/pettype.go | 108 ++++++++++++++++++++++++++ d2common/d2enum/pet_icon_type.go | 13 ++++ d2common/d2resource/resource_paths.go | 1 + 4 files changed, 123 insertions(+) create mode 100644 d2common/d2data/d2datadict/pettype.go create mode 100644 d2common/d2enum/pet_icon_type.go diff --git a/d2app/app.go b/d2app/app.go index 8f113646..50d52cf7 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -257,6 +257,7 @@ func (a *App) loadDataDict() error { {d2resource.Shrines, d2datadict.LoadShrines}, {d2resource.ElemType, d2datadict.LoadElemTypes}, {d2resource.PlrMode, d2datadict.LoadPlrModes}, + {d2resource.PetType, d2datadict.LoadPetTypes}, } d2datadict.InitObjectRecords() diff --git a/d2common/d2data/d2datadict/pettype.go b/d2common/d2data/d2datadict/pettype.go new file mode 100644 index 00000000..e94b9f4a --- /dev/null +++ b/d2common/d2data/d2datadict/pettype.go @@ -0,0 +1,108 @@ +package d2datadict + +import ( + "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" +) + +//PetTypeRecord represents a single line in PetType.txt +//The information has been gathered from [https://d2mods.info/forum/kb/viewarticle?a=355] +type PetTypeRecord struct { + //Name of the pet type, reffered by "pettype" in skills.txt + PetType string + + //ID number of the pet type + Idx int + + //ID number of the group this pet belongs to + Group int + + BaseMax int + + //If true, the pet warps with the player, otherwise it dies + Warp bool + + //If true, and Warp is false, the pet only die if the distance between the player + //and the pet exceeds 41 sub-tiles. + Range bool + + //Unknown + PartySend bool + + //If true, can be unsummoned + Unsummon bool + + //If true, pet is displayed on the automap + Automap bool + + //String file for the text under the pet icon + Name string + + //If true, the pet's HP will be displayed under the icon + DrawHP bool + + //Pet icon type + IconType int + + //.dc6 file for the pet's icon, located in /data/global/ui/hireables + BaseIcon string + + //Alternative pet index from monstats.txt + MClass1 int + + //Alternative pet icon .dc6 file + MIcon1 string + + //ditto, there can be four alternatives + MClass2 int + MIcon2 string + MClass3 int + MIcon3 string + MClass4 int + MIcon4 string + + //EOL int, not loaded +} + +//PetTypes stores the PetTypeRecords +var PetTypes map[string]*PetTypeRecord //nolint:gochecknoglobals // Currently global by design + +//LoadPetTypes loads PetTypeRecords into PetTypes +func LoadPetTypes(file []byte) { + PetTypes = make(map[string]*PetTypeRecord) + + d := d2common.LoadDataDictionary(file) + for d.Next() { + record := &PetTypeRecord{ + PetType: d.String("pet type"), + Idx: d.Number("idx"), + Group: d.Number("group"), + BaseMax: d.Number("basemax"), + Warp: d.Bool("warp"), + Range: d.Bool("range"), + PartySend: d.Bool("partysend"), + Unsummon: d.Bool("unsummon"), + Automap: d.Bool("automap"), + Name: d.String("name"), + DrawHP: d.Bool("drawhp"), + IconType: d.Number("icontype"), + BaseIcon: d.String("baseicon"), + MClass1: d.Number("mclass1"), + MIcon1: d.String("micon1"), + MClass2: d.Number("mclass2"), + MIcon2: d.String("micon2"), + MClass3: d.Number("mclass3"), + MIcon3: d.String("micon3"), + MClass4: d.Number("mclass4"), + MIcon4: d.String("micon4"), + } + PetTypes[record.PetType] = record + } + + if d.Err != nil { + panic(d.Err) + } + + log.Printf("Loaded %d PetType records", len(PetTypes)) +} diff --git a/d2common/d2enum/pet_icon_type.go b/d2common/d2enum/pet_icon_type.go new file mode 100644 index 00000000..23040587 --- /dev/null +++ b/d2common/d2enum/pet_icon_type.go @@ -0,0 +1,13 @@ +package d2enum + +// PetIconType determines the pet icon type +type PetIconType int + +// Pet icon types +//The information has been gathered from [https://d2mods.info/forum/kb/viewarticle?a=355] +const ( + NoIcon PetIconType = iota + ShowIconOnly + ShowIconAndQuantity //Quantity, such as the number of skeletons + ShowIconOnly2 +) diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 2ca054bf..eaa2d4a5 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -201,6 +201,7 @@ const ( MonProp = "/data/global/excel/Monprop.txt" ElemType = "/data/global/excel/ElemTypes.txt" PlrMode = "/data/global/excel/PlrMode.txt" + PetType = "/data/global/excel/pettype.txt" // --- Animations ---