mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-17 18:06:03 -05:00
fixed 'dupl' lint errors (#845)
* removed dupl lint errors in d2compression/huffman.go * remove duplicate code for set/unique item properties This is a more involved edit. I've added a `PropertyDescriptor` which is a common struct that should have existed already. The `PropertyDescriptor` is used to generate property instances, and is common to item affixes, set items, sets, unique items, and runewords. This was all to remove duplicate code in d2item/ * removed duplicate code for rare item affixes
This commit is contained in:
parent
815cfa09cb
commit
622186e350
@ -88,7 +88,7 @@ func (v *linkedNode) insert(other *linkedNode) *linkedNode {
|
||||
return v
|
||||
}
|
||||
|
||||
//nolint:funlen // Makes no sense to split
|
||||
//nolint:funlen,dupl // it's ok to have duplicates and a long func here
|
||||
func getPrimes() [][]byte {
|
||||
return [][]byte{
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
||||
@ -544,7 +545,12 @@ func (i *Item) generateAffixProperties(pool PropertyPool) []*Property {
|
||||
for modIdx := range affix.Modifiers {
|
||||
mod := affix.Modifiers[modIdx]
|
||||
|
||||
prop := i.factory.NewProperty(mod.Code, mod.Parameter, mod.Min, mod.Max)
|
||||
paramInt, err := strconv.Atoi(mod.Parameter)
|
||||
if err != nil {
|
||||
paramInt = 0
|
||||
}
|
||||
|
||||
prop := i.factory.NewProperty(mod.Code, paramInt, mod.Min, mod.Max)
|
||||
if prop == nil {
|
||||
continue
|
||||
}
|
||||
@ -557,48 +563,26 @@ func (i *Item) generateAffixProperties(pool PropertyPool) []*Property {
|
||||
}
|
||||
|
||||
func (i *Item) generateUniqueProperties() []*Property {
|
||||
if i.UniqueRecord() == nil {
|
||||
if record := i.UniqueRecord(); record != nil {
|
||||
return i.generateItemProperties(record.Properties[:])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]*Property, 0)
|
||||
|
||||
for propIdx := range i.UniqueRecord().Properties {
|
||||
propInfo := i.UniqueRecord().Properties[propIdx]
|
||||
|
||||
// sketchy ass unique records, the param should be an int but sometimes it's the name
|
||||
// of a skill, which needs to be converted to the skill index
|
||||
paramStr := getStringComponent(propInfo.Parameter)
|
||||
paramInt := getNumericComponent(propInfo.Parameter)
|
||||
|
||||
if paramStr != "" {
|
||||
for skillID := range i.factory.asset.Records.Skill.Details {
|
||||
if i.factory.asset.Records.Skill.Details[skillID].Skill == paramStr {
|
||||
paramInt = skillID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prop := i.factory.NewProperty(propInfo.Code, paramInt, propInfo.Min, propInfo.Max)
|
||||
if prop == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, prop)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (i *Item) generateSetItemProperties() []*Property {
|
||||
if i.SetItemRecord() == nil {
|
||||
return nil
|
||||
if record := i.SetItemRecord(); record != nil {
|
||||
return i.generateItemProperties(record.Properties[:])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Item) generateItemProperties(properties []*d2records.PropertyDescriptor) []*Property {
|
||||
result := make([]*Property, 0)
|
||||
|
||||
for propIdx := range i.SetItemRecord().Properties {
|
||||
setProp := i.SetItemRecord().Properties[propIdx]
|
||||
for propIdx := range properties {
|
||||
setProp := properties[propIdx]
|
||||
|
||||
// like with unique records, the property param is sometimes a skill name
|
||||
// as a string, not an integer index
|
||||
|
@ -113,7 +113,7 @@ func createItemAffixRecords(
|
||||
maxKey := fmt.Sprintf("mod%dmax", i)
|
||||
modifier := &ItemAffixCommonModifier{
|
||||
Code: d.String(codeKey),
|
||||
Parameter: d.Number(paramKey),
|
||||
Parameter: d.String(paramKey),
|
||||
Min: d.Number(minKey),
|
||||
Max: d.Number(maxKey),
|
||||
}
|
||||
|
@ -14,12 +14,7 @@ type ItemAffixGroups map[int]*ItemAffixCommonGroup
|
||||
// ItemAffixCommonModifier is the generic modifier form that prefix/suffix shares
|
||||
// modifiers are like dynamic properties, they have a key that points to a property
|
||||
// a parameter for the property, and a min/max value
|
||||
type ItemAffixCommonModifier struct {
|
||||
Code string
|
||||
Parameter int
|
||||
Min int
|
||||
Max int
|
||||
}
|
||||
type ItemAffixCommonModifier = PropertyDescriptor
|
||||
|
||||
// ItemAffixCommonGroup is a grouping that is common between prefix/suffix
|
||||
type ItemAffixCommonGroup struct {
|
||||
|
27
d2core/d2records/property_descriptor.go
Normal file
27
d2core/d2records/property_descriptor.go
Normal file
@ -0,0 +1,27 @@
|
||||
package d2records
|
||||
|
||||
// PropertyDescriptor is a generic description of a property, used to create properties.
|
||||
// Sets, SetItems, UniqueItems will all use this generic form of a property
|
||||
type PropertyDescriptor struct {
|
||||
// Code is an ID pointer of a property from Properties.txt,
|
||||
// these columns control each of the eight different full set modifiers a set item can grant you
|
||||
// at most.
|
||||
Code string
|
||||
|
||||
// Param is the passed on to the associated property, this is used to pass skill IDs, state IDs,
|
||||
// monster IDs, montype IDs and the like on to the properties that require them,
|
||||
// these fields support calculations.
|
||||
Parameter string
|
||||
|
||||
// Min value to assign to the associated property.
|
||||
// Certain properties have special interpretations based on stat encoding (e.g.
|
||||
// chance-to-cast and charged skills). See the File Guides for Properties.txt and ItemStatCost.
|
||||
// txt for further details.
|
||||
Min int
|
||||
|
||||
// Max value to assign to the associated property.
|
||||
// Certain properties have special interpretations based on stat encoding (e.g.
|
||||
// chance-to-cast and charged skills). See the File Guides for Properties.txt and ItemStatCost.
|
||||
// txt for further details.
|
||||
Max int
|
||||
}
|
8
d2core/d2records/rare_affix.go
Normal file
8
d2core/d2records/rare_affix.go
Normal file
@ -0,0 +1,8 @@
|
||||
package d2records
|
||||
|
||||
// RareItemAffix described both rare prefixes and suffixes
|
||||
type RareItemAffix struct {
|
||||
Name string
|
||||
IncludedTypes []string
|
||||
ExcludedTypes []string
|
||||
}
|
45
d2core/d2records/rare_affix_loader.go
Normal file
45
d2core/d2records/rare_affix_loader.go
Normal file
@ -0,0 +1,45 @@
|
||||
package d2records
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
||||
)
|
||||
|
||||
const (
|
||||
numRareAffixInclude = 7
|
||||
fmtRareAffixInclude = "itype%d"
|
||||
|
||||
numRareAffixExclude = 4
|
||||
fmtRareAffixExclude = "etype%d"
|
||||
)
|
||||
|
||||
func rareItemAffixLoader(d *d2txt.DataDictionary) ([]*RareItemAffix, error) {
|
||||
records := make([]*RareItemAffix, 0)
|
||||
|
||||
for d.Next() {
|
||||
record := &RareItemPrefixRecord{
|
||||
Name: d.String("name"),
|
||||
IncludedTypes: make([]string, 0),
|
||||
ExcludedTypes: make([]string, 0),
|
||||
}
|
||||
|
||||
for idx := 1; idx <= numRareAffixInclude; idx++ {
|
||||
column := fmt.Sprintf(fmtRareAffixInclude, idx)
|
||||
if typeCode := d.String(column); typeCode != "" {
|
||||
record.IncludedTypes = append(record.IncludedTypes, typeCode)
|
||||
}
|
||||
}
|
||||
|
||||
for idx := 1; idx <= numRareAffixExclude; idx++ {
|
||||
column := fmt.Sprintf(fmtRareAffixExclude, idx)
|
||||
if typeCode := d.String(column); typeCode != "" {
|
||||
record.ExcludedTypes = append(record.ExcludedTypes, typeCode)
|
||||
}
|
||||
}
|
||||
|
||||
records = append(records, record)
|
||||
}
|
||||
|
||||
return records, d.Err
|
||||
}
|
@ -1,49 +1,15 @@
|
||||
package d2records
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
||||
)
|
||||
|
||||
const (
|
||||
numRarePrefixInclude = 7
|
||||
fmtRarePrefixInclude = "itype%d"
|
||||
|
||||
numRarePrefixExclude = 4
|
||||
fmtRarePrefixExclude = "etype%d"
|
||||
)
|
||||
|
||||
func rareItemPrefixLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
records := make(RarePrefixes, 0)
|
||||
|
||||
for d.Next() {
|
||||
record := &RareItemPrefixRecord{
|
||||
Name: d.String("name"),
|
||||
IncludedTypes: make([]string, 0),
|
||||
ExcludedTypes: make([]string, 0),
|
||||
}
|
||||
|
||||
for idx := 1; idx <= numRarePrefixInclude; idx++ {
|
||||
column := fmt.Sprintf(fmtRarePrefixInclude, idx)
|
||||
if typeCode := d.String(column); typeCode != "" {
|
||||
record.IncludedTypes = append(record.IncludedTypes, typeCode)
|
||||
}
|
||||
}
|
||||
|
||||
for idx := 1; idx <= numRarePrefixExclude; idx++ {
|
||||
column := fmt.Sprintf(fmtRarePrefixExclude, idx)
|
||||
if typeCode := d.String(column); typeCode != "" {
|
||||
record.ExcludedTypes = append(record.ExcludedTypes, typeCode)
|
||||
}
|
||||
}
|
||||
|
||||
records = append(records, record)
|
||||
}
|
||||
|
||||
if d.Err != nil {
|
||||
return d.Err
|
||||
records, err := rareItemAffixLoader(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.Item.Rare.Prefix = records
|
||||
|
@ -4,8 +4,4 @@ package d2records
|
||||
type RarePrefixes []*RareItemPrefixRecord
|
||||
|
||||
// RareItemPrefixRecord is a name prefix for rare items (items with more than 2 affixes)
|
||||
type RareItemPrefixRecord struct {
|
||||
Name string
|
||||
IncludedTypes []string
|
||||
ExcludedTypes []string
|
||||
}
|
||||
type RareItemPrefixRecord = RareItemAffix
|
||||
|
@ -1,49 +1,15 @@
|
||||
package d2records
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
||||
)
|
||||
|
||||
const (
|
||||
numRareSuffixInclude = 7
|
||||
fmtRareSuffixInclude = "itype%d"
|
||||
|
||||
numRareSuffixExclude = 4
|
||||
fmtRareSuffixExclude = "etype%d"
|
||||
)
|
||||
|
||||
func rareItemSuffixLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
records := make([]*RareItemSuffixRecord, 0)
|
||||
|
||||
for d.Next() {
|
||||
record := &RareItemSuffixRecord{
|
||||
Name: d.String("name"),
|
||||
IncludedTypes: make([]string, 0),
|
||||
ExcludedTypes: make([]string, 0),
|
||||
}
|
||||
|
||||
for idx := 1; idx <= numRareSuffixInclude; idx++ {
|
||||
column := fmt.Sprintf(fmtRareSuffixInclude, idx)
|
||||
if typeCode := d.String(column); typeCode != "" {
|
||||
record.IncludedTypes = append(record.IncludedTypes, typeCode)
|
||||
}
|
||||
}
|
||||
|
||||
for idx := 1; idx <= numRareSuffixExclude; idx++ {
|
||||
column := fmt.Sprintf(fmtRareSuffixExclude, idx)
|
||||
if typeCode := d.String(column); typeCode != "" {
|
||||
record.ExcludedTypes = append(record.ExcludedTypes, typeCode)
|
||||
}
|
||||
}
|
||||
|
||||
records = append(records, record)
|
||||
}
|
||||
|
||||
if d.Err != nil {
|
||||
return d.Err
|
||||
records, err := rareItemAffixLoader(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Loaded %d RareSuffix records", len(records))
|
||||
|
@ -4,8 +4,4 @@ package d2records
|
||||
type RareSuffixes []*RareItemSuffixRecord
|
||||
|
||||
// RareItemSuffixRecord is a name suffix for rare items (items with more than 2 affixes)
|
||||
type RareItemSuffixRecord struct {
|
||||
Name string
|
||||
IncludedTypes []string
|
||||
ExcludedTypes []string
|
||||
}
|
||||
type RareItemSuffixRecord = RareItemAffix
|
||||
|
@ -25,16 +25,4 @@ type RunesRecord struct {
|
||||
}
|
||||
|
||||
// RunewordProperty is a representation of a stat possessed by this runeword
|
||||
type RunewordProperty struct {
|
||||
// Code is the property code
|
||||
Code string
|
||||
|
||||
// Param is either string or int, parameter for the property
|
||||
Param string
|
||||
|
||||
// Min is the minimum value for the property
|
||||
Min int
|
||||
|
||||
// Max is the maximum value for the property
|
||||
Max int
|
||||
}
|
||||
type RunewordProperty = PropertyDescriptor
|
||||
|
@ -23,12 +23,7 @@ const (
|
||||
)
|
||||
|
||||
// SetItemProperty is describes a property of a set item
|
||||
type SetItemProperty struct {
|
||||
Code string
|
||||
Parameter string // depending on the property, this may be an int (usually), or a string
|
||||
Min int
|
||||
Max int
|
||||
}
|
||||
type SetItemProperty = PropertyDescriptor
|
||||
|
||||
// Loadrecords loads all of the SetItemRecords from records.txt
|
||||
func setItemLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
|
@ -56,7 +56,7 @@ func setLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
|
||||
propA := &SetProperty{
|
||||
Code: codeA,
|
||||
Param: d.String(paramColumn),
|
||||
Parameter: d.String(paramColumn),
|
||||
Min: d.Number(minColumn),
|
||||
Max: d.Number(maxColumn),
|
||||
}
|
||||
@ -71,7 +71,7 @@ func setLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
|
||||
propB := &SetProperty{
|
||||
Code: codeB,
|
||||
Param: d.String(paramColumn),
|
||||
Parameter: d.String(paramColumn),
|
||||
Min: d.Number(minColumn),
|
||||
Max: d.Number(maxColumn),
|
||||
}
|
||||
@ -90,7 +90,7 @@ func setLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
if code := d.String(codeColumn); code != "" {
|
||||
prop := &SetProperty{
|
||||
Code: code,
|
||||
Param: d.String(paramColumn),
|
||||
Parameter: d.String(paramColumn),
|
||||
Min: d.Number(minColumn),
|
||||
Max: d.Number(maxColumn),
|
||||
}
|
||||
|
@ -31,26 +31,4 @@ type SetRecord struct {
|
||||
}
|
||||
|
||||
// SetProperty represents a property possessed by the set
|
||||
type SetProperty struct {
|
||||
// Code is an ID pointer of a property from Properties.txt,
|
||||
// these columns control each of the eight different full set modifiers a set item can grant you
|
||||
// at most.
|
||||
Code string
|
||||
|
||||
// Param is the passed on to the associated property, this is used to pass skill IDs, state IDs,
|
||||
// monster IDs, montype IDs and the like on to the properties that require them,
|
||||
// these fields support calculations.
|
||||
Param string
|
||||
|
||||
// Min value to assign to the associated property.
|
||||
// Certain properties have special interpretations based on stat encoding (e.g.
|
||||
// chance-to-cast and charged skills). See the File Guides for Properties.txt and ItemStatCost.
|
||||
// txt for further details.
|
||||
Min int
|
||||
|
||||
// Max value to assign to the associated property.
|
||||
// Certain properties have special interpretations based on stat encoding (e.g.
|
||||
// chance-to-cast and charged skills). See the File Guides for Properties.txt and ItemStatCost.
|
||||
// txt for further details.
|
||||
Max int
|
||||
}
|
||||
type SetProperty = PropertyDescriptor
|
||||
|
@ -38,76 +38,76 @@ func uniqueItemsLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
||||
DropSfxFrame: d.Number("dropsfxframe"),
|
||||
UseSound: d.String("usesound"),
|
||||
|
||||
Properties: [12]UniqueItemProperty{
|
||||
UniqueItemProperty{
|
||||
Properties: [12]*UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop1"),
|
||||
Parameter: d.String("par1"),
|
||||
Min: d.Number("min1"),
|
||||
Max: d.Number("max1"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop2"),
|
||||
Parameter: d.String("par2"),
|
||||
Min: d.Number("min2"),
|
||||
Max: d.Number("max2"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop3"),
|
||||
Parameter: d.String("par3"),
|
||||
Min: d.Number("min3"),
|
||||
Max: d.Number("max3"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop4"),
|
||||
Parameter: d.String("par4"),
|
||||
Min: d.Number("min4"),
|
||||
Max: d.Number("max4"),
|
||||
},
|
||||
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop5"),
|
||||
Parameter: d.String("par5"),
|
||||
Min: d.Number("min5"),
|
||||
Max: d.Number("max5"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
|
||||
{
|
||||
Code: d.String("prop6"),
|
||||
Parameter: d.String("par6"),
|
||||
Min: d.Number("min6"),
|
||||
Max: d.Number("max6"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop7"),
|
||||
Parameter: d.String("par7"),
|
||||
Min: d.Number("min7"),
|
||||
Max: d.Number("max7"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop8"),
|
||||
Parameter: d.String("par8"),
|
||||
Min: d.Number("min8"),
|
||||
Max: d.Number("max8"),
|
||||
},
|
||||
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop9"),
|
||||
Parameter: d.String("par9"),
|
||||
Min: d.Number("min9"),
|
||||
Max: d.Number("max9"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop10"),
|
||||
Parameter: d.String("par10"),
|
||||
Min: d.Number("min10"),
|
||||
Max: d.Number("max10"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop11"),
|
||||
Parameter: d.String("par11"),
|
||||
Min: d.Number("min11"),
|
||||
Max: d.Number("max11"),
|
||||
},
|
||||
UniqueItemProperty{
|
||||
{
|
||||
Code: d.String("prop12"),
|
||||
Parameter: d.String("par12"),
|
||||
Min: d.Number("min12"),
|
||||
|
@ -5,7 +5,7 @@ type UniqueItems map[string]*UniqueItemRecord
|
||||
|
||||
// UniqueItemRecord is a representation of a row from uniqueitems.txt
|
||||
type UniqueItemRecord struct {
|
||||
Properties [12]UniqueItemProperty
|
||||
Properties [12]*UniqueItemProperty
|
||||
|
||||
Name string
|
||||
Code string // three letter code, points to a record in Weapons, Armor, or Misc
|
||||
@ -37,9 +37,4 @@ type UniqueItemRecord struct {
|
||||
}
|
||||
|
||||
// UniqueItemProperty is describes a property of a unique item
|
||||
type UniqueItemProperty struct {
|
||||
Code string
|
||||
Parameter string // depending on the property, this may be an int (usually), or a string
|
||||
Min int
|
||||
Max int
|
||||
}
|
||||
type UniqueItemProperty = PropertyDescriptor
|
||||
|
Loading…
Reference in New Issue
Block a user