2020-07-31 18:24:47 -04:00
|
|
|
package d2datadict
|
|
|
|
|
|
|
|
import (
|
2020-08-04 11:16:06 -04:00
|
|
|
"fmt"
|
2020-07-31 18:24:47 -04:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
|
|
)
|
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
const (
|
|
|
|
numMonEquippedItems = 3
|
|
|
|
fmtLocation = "loc%d"
|
|
|
|
fmtQuality = "mod%d"
|
|
|
|
fmtCode = "item%d"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MonsterEquipmentRecord represents a single line in monequip.txt
|
|
|
|
// Information gathered from [https://d2mods.info/forum/kb/viewarticle?a=365]
|
2020-07-31 18:24:47 -04:00
|
|
|
type MonsterEquipmentRecord struct {
|
2020-08-04 11:16:06 -04:00
|
|
|
// Name of monster, pointer to MonStats.txt
|
|
|
|
Name string
|
2020-07-31 18:24:47 -04:00
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
// If true, monster is created by level, otherwise created by skill
|
2020-07-31 18:24:47 -04:00
|
|
|
OnInit bool
|
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
// Not written in description, only appear on monsters with OnInit false,
|
|
|
|
// Level of skill for which this equipment row can be used?
|
2020-07-31 18:24:47 -04:00
|
|
|
Level int
|
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
Equipment []*monEquip
|
|
|
|
}
|
2020-07-31 18:24:47 -04:00
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
type monEquip struct {
|
|
|
|
// Code of item, probably from ItemCommonRecords
|
|
|
|
Code string
|
2020-07-31 18:24:47 -04:00
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
// Location the body location of the item
|
|
|
|
Location string
|
2020-07-31 18:24:47 -04:00
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
// Quality of the item
|
|
|
|
Quality int
|
2020-07-31 18:24:47 -04:00
|
|
|
}
|
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
// MonsterEquipment stores the MonsterEquipmentRecords
|
2020-07-31 18:24:47 -04:00
|
|
|
var MonsterEquipment map[string][]*MonsterEquipmentRecord //nolint:gochecknoglobals // Currently global by design
|
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
// LoadMonsterEquipment loads MonsterEquipmentRecords into MonsterEquipment
|
2020-07-31 18:24:47 -04:00
|
|
|
func LoadMonsterEquipment(file []byte) {
|
|
|
|
MonsterEquipment = make(map[string][]*MonsterEquipmentRecord)
|
|
|
|
|
|
|
|
d := d2common.LoadDataDictionary(file)
|
|
|
|
for d.Next() {
|
|
|
|
record := &MonsterEquipmentRecord{
|
2020-08-04 11:16:06 -04:00
|
|
|
Name: d.String("monster"),
|
2020-07-31 18:24:47 -04:00
|
|
|
OnInit: d.Bool("oninit"),
|
|
|
|
Level: d.Number("level"),
|
2020-08-04 11:16:06 -04:00
|
|
|
Equipment: make([]*monEquip, 0),
|
2020-07-31 18:24:47 -04:00
|
|
|
}
|
|
|
|
|
2020-08-04 11:16:06 -04:00
|
|
|
for idx := 0; idx < numMonEquippedItems; idx++ {
|
|
|
|
num := idx + 1
|
|
|
|
code := d.String(fmt.Sprintf(fmtCode, num))
|
|
|
|
location := d.String(fmt.Sprintf(fmtLocation, num))
|
|
|
|
quality := d.Number(fmt.Sprintf(fmtQuality, num))
|
|
|
|
|
|
|
|
if code == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
equip := &monEquip{code, location, quality}
|
|
|
|
|
|
|
|
record.Equipment = append(record.Equipment, equip)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := MonsterEquipment[record.Name]; !ok {
|
|
|
|
MonsterEquipment[record.Name] = make([]*MonsterEquipmentRecord, 0)
|
2020-07-31 18:24:47 -04:00
|
|
|
}
|
2020-08-04 11:16:06 -04:00
|
|
|
|
|
|
|
MonsterEquipment[record.Name] = append(MonsterEquipment[record.Name], record)
|
2020-07-31 18:24:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if d.Err != nil {
|
|
|
|
panic(d.Err)
|
|
|
|
}
|
|
|
|
|
|
|
|
length := 0
|
|
|
|
for k := range MonsterEquipment {
|
|
|
|
length += len(MonsterEquipment[k])
|
|
|
|
}
|
2020-08-04 11:16:06 -04:00
|
|
|
|
2020-07-31 18:24:47 -04:00
|
|
|
log.Printf("Loaded %d MonsterEquipment records", length)
|
|
|
|
}
|