1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-09 01:56:47 -05:00

d2core: fix part of remaining lint errors

This commit is contained in:
gucio321 2021-06-13 17:22:13 +02:00
parent baf573f53d
commit bbea424b22
10 changed files with 136 additions and 134 deletions

View File

@ -18,11 +18,11 @@ const (
// Button is a user actionable drawable toggle switch
type Button struct {
widgetBase
surfaces []d2interface.Surface
width int
height int
state buttonState
widgetBase
width int
height int
state buttonState
}
func (b *Button) onMouseButtonDown(_ d2interface.MouseEvent) bool {

View File

@ -21,12 +21,12 @@ const (
// Label is renderable text
type Label struct {
blinkTimer time.Time
renderer d2interface.Renderer
surface d2interface.Surface
font *d2font.Font
text string
widgetBase
blinkTimer time.Time
renderer d2interface.Renderer
surface d2interface.Surface
font *d2font.Font
text string
color color.RGBA
hoverColor color.RGBA
isHovered bool

View File

@ -57,10 +57,10 @@ var _ widget = &Layout{}
// Layout is a gui element container which will automatically position/align gui elements.
// Layouts are gui elements as well, so they can be nested in other layouts.
type Layout struct {
renderer d2interface.Renderer
assetManager *d2asset.AssetManager
entries []*layoutEntry
widgetBase
renderer d2interface.Renderer
assetManager *d2asset.AssetManager
entries []*layoutEntry
width int
height int
verticalAlign VerticalAlign

View File

@ -22,8 +22,8 @@ var _ widget = &Sprite{}
// Sprite is an image
type Sprite struct {
animation d2interface.Animation
widgetBase
animation d2interface.Animation
segmentsX int
segmentsY int
frameOffset int

View File

@ -55,66 +55,56 @@ var _ d2item.Item = &Item{}
// Item is a representation of a diablo2 item
// nolint:structcheck,unused // WIP
type Item struct {
factory *ItemFactory
name string
Seed int64
rand *rand.Rand // non-global rand instance for re-generating the item
slotType d2enum.EquippedSlot
TypeCode string
CommonCode string
UniqueCode string
SetCode string
SetItemCode string
PrefixCodes []string
SuffixCodes []string
properties map[PropertyPool][]*Property
statContext d2item.StatContext
statList d2stats.StatList
uniqueStatList d2stats.StatList
setItemStatList d2stats.StatList
attributes *itemAttributes
GridX int
GridY int
sockets []*d2item.Item // there will be checks for handling the craziness this might entail
statContext d2item.StatContext
uniqueStatList d2stats.StatList
statList d2stats.StatList
rand *rand.Rand
properties map[PropertyPool][]*Property
attributes *itemAttributes
factory *ItemFactory
TypeCode string
SetCode string
SetItemCode string
CommonCode string
name string
UniqueCode string
SuffixCodes []string
PrefixCodes []string
sockets []*d2item.Item
slotType d2enum.EquippedSlot
Seed int64
GridX int
GridY int
}
// nolint:structcheck,unused // WIP
type itemAttributes struct {
worldSprite *d2ui.Sprite
inventorySprite *d2ui.Sprite
damageOneHand minMaxEnhanceable
damageTwoHand minMaxEnhanceable
damageMissile minMaxEnhanceable
stackSize minMaxEnhanceable
durability minMaxEnhanceable
personalization string
quality int
worldSprite *d2ui.Sprite
inventorySprite *d2ui.Sprite
personalization string
damageOneHand minMaxEnhanceable
damageTwoHand minMaxEnhanceable
damageMissile minMaxEnhanceable
stackSize minMaxEnhanceable
durability minMaxEnhanceable
classSpecific d2enum.Hero
defense int
currentStackSize int
currentDurability int
baseItemLevel int
quality int
requiredLevel int
numSockets int
requirementsEnhancement int
requiredStrength int
requiredDexterity int
classSpecific d2enum.Hero
identitified bool
crafted bool
durable bool // some items specify that they have no durability
indestructable bool
ethereal bool
throwable bool
baseItemLevel int
identitified bool
crafted bool
durable bool
indestructable bool
ethereal bool
throwable bool
}
type minMaxEnhanceable struct {

View File

@ -75,12 +75,8 @@ type Property struct {
factory *ItemFactory
record *d2records.PropertyRecord
stats []d2stats.Stat
inputParams []int
PropertyType PropertyType
// the inputValues that were passed initially when calling `NewProperty`
inputParams []int
// some properties are statless and used only for computing a value
computedInt int
computedBool bool
}

View File

@ -443,122 +443,122 @@ func TestNewProperty(t *testing.T) { //nolint:funlen // it's mostly test-case de
tests := []struct {
propKey string
inputValues []int
expectNumStats int
expectStr []string
expectNumStats int
}{
{ // fnId 1 + 3
"allstats",
[]int{1, 10},
4,
[]string{
"+# to Strength",
"+# to Dexterity",
"+# to Vitality",
"+# to Energy",
},
4,
},
{ // fnId 2
"ac%",
[]int{1, 10},
1,
[]string{"+#% Enhanced Defense"},
1,
},
{ // fnId 5
// dmg-min, dmg-max, dmg%, indestructable, and ethereal dont have stats!
"dmg-min",
[]int{1, 10},
0,
[]string{""},
0,
},
{ // fnId 6
// dmg-min, dmg-max, dmg%, indestructable, and ethereal dont have stats!
"dmg-max",
[]int{1, 10},
0,
[]string{""},
0,
},
{ // fnId 7
// dmg-min, dmg-max, dmg%, indestructable, and ethereal dont have stats!
"dmg%",
[]int{1, 10},
0,
[]string{""},
0,
},
{ // fnId 8
"cast1",
[]int{1, 10},
1,
[]string{"+#% Faster Cast Rate"},
1,
},
{
"indestruct",
[]int{0, 1},
0,
[]string{""},
0,
},
{
"ethereal",
[]int{0, 1},
0,
[]string{""},
0,
},
{ // fnId 10
"skilltab",
[]int{10, 1, 3},
1,
[]string{"+# to Offensive Auras (Paladin Only)"},
1,
},
{ // fnId 11
"levelup-skill",
[]int{64, 100, 3},
1,
[]string{"#% Chance to cast level # Frozen Orb when you Level-Up"},
1,
},
{ // fnId 12
"skill-rand",
[]int{10, 64, 64},
1,
[]string{"+# to Frozen Orb"},
1,
},
{ // fnId 13
"dur%",
[]int{1, 10},
1,
[]string{"Increase Maximum Durability +#%"},
1,
},
{ // fnId 14
"sock",
[]int{0, 6},
1,
[]string{""},
1,
},
{ // fnId 15, 16, 17
"dmg-pois",
[]int{100, 5, 10},
3,
[]string{
"+# to Minimum Poison Damage",
"+# to Maximum Poison Damage",
"", // length, non-printing
},
3,
},
{ // fnId 19
"charged",
[]int{64, 20, 10},
1,
[]string{"Level # Frozen Orb (#/# Charges)"},
1,
},
{ // fnId 21
"pal",
[]int{1, 5},
1,
[]string{"+# to Paladin Skill Levels"},
1,
},
{ // fnId 22
"oskill",
[]int{64, 1, 5},
1,
[]string{"+# to Frozen Orb"},
1,
},
}

View File

@ -18,9 +18,9 @@ type NPC struct {
monstatRecord *d2records.MonStatRecord
monstatEx *d2records.MonStat2Record
composite *d2asset.Composite
name string
Paths []d2path.Path
mapEntity
name string
Paths []d2path.Path
action int
path int
repetitions int

View File

@ -13,24 +13,24 @@ import (
// Player is the player character entity.
type Player struct {
onFinishedCasting func()
Skills map[int]*d2hero.HeroSkill
LeftSkill *d2hero.HeroSkill
RightSkill *d2hero.HeroSkill
composite *d2asset.Composite
Equipment *d2inventory.CharacterEquipment
Stats *d2hero.HeroStatsState
Skills map[int]*d2hero.HeroSkill
onFinishedCasting func()
name string
animationMode string
mapEntity
name string
animationMode string
Gold int
lastPathSize int
Class d2enum.Hero
Act int
isRunToggled bool
isRunning bool
isCasting bool
isInTown bool
Gold int
lastPathSize int
Class d2enum.Hero
Act int
isRunToggled bool
isRunning bool
isCasting bool
isInTown bool
}
// run speed should be walkspeed * 1.5, since in the original game it is 6 yards walk and 9 yards run.

View File

@ -301,86 +301,102 @@ func TestStat_Clone(t *testing.T) {
func TestStat_Descriptions(t *testing.T) {
tests := []struct {
recordKey string
vals []float64
expect string
vals []float64
}{
// DescFn1
{"strength", []float64{31}, "+31 to Strength"},
{"hpregen", []float64{20}, "Replenish Life +20"},
{"hpregen", []float64{-8}, "Drain Life -8"},
{"strength", "+31 to Strength", []float64{31}},
{"hpregen", "Replenish Life +20", []float64{20}},
{"hpregen", "Drain Life -8", []float64{-8}},
// DescFn2
{"toblock", []float64{16}, "+16% Increased Chance of Blocking"},
{"item_absorblight_percent", []float64{10}, "Lightning Absorb +10%"},
{"toblock", "+16% Increased Chance of Blocking", []float64{16}},
{"item_absorblight_percent", "Lightning Absorb +10%", []float64{10}},
// DescFn3
{"normal_damage_reduction", []float64{25}, "Damage Reduced by 25"},
{"item_restinpeace", []float64{25}, "Slain Monsters Rest in Peace"},
{"normal_damage_reduction", "Damage Reduced by 25", []float64{25}},
{"item_restinpeace", "Slain Monsters Rest in Peace", []float64{25}},
// DescFn4
{"poisonresist", []float64{25}, "Poison Resist +25%"},
{"item_fastermovevelocity", []float64{25}, "+25% Faster Run/Walk"},
{"poisonresist", "Poison Resist +25%", []float64{25}},
{"item_fastermovevelocity", "+25% Faster Run/Walk", []float64{25}},
// DescFn5
{"item_howl", []float64{25}, "Hit Causes Monster to Flee 25%"},
{"item_howl", "Hit Causes Monster to Flee 25%", []float64{25}},
// DescFn6
{"item_hp_perlevel", []float64{25}, "+25 to Life (Based on Character Level)"},
{"item_hp_perlevel", "+25 to Life (Based on Character Level)", []float64{25}},
// DescFn7
{"item_resist_ltng_perlevel", []float64{25},
"Lightning Resist +25% (Based on Character Level)"},
{"item_find_magic_perlevel", []float64{25}, "+25% Better Chance of Getting Magic Items (" +
"Based on Character Level)"},
{
"item_resist_ltng_perlevel",
"Lightning Resist +25% (Based on Character Level)",
[]float64{25},
},
{
"item_find_magic_perlevel", "+25% Better Chance of Getting Magic Items (Based on Character Level)",
[]float64{25},
},
// DescFn8
{"item_armorpercent_perlevel", []float64{25},
"+25% Enhanced Defense (Based on Character Level)"},
{"item_regenstamina_perlevel", []float64{25},
"Heal Stamina Plus +25% (Based on Character Level)"},
{
"item_armorpercent_perlevel",
"+25% Enhanced Defense (Based on Character Level)",
[]float64{25},
},
{
"item_regenstamina_perlevel",
"Heal Stamina Plus +25% (Based on Character Level)",
[]float64{25},
},
// DescFn9
{"item_thorns_perlevel", []float64{25}, "Attacker Takes Damage of 25 (" +
"Based on Character Level)"},
{
"item_thorns_perlevel", "Attacker Takes Damage of 25 (Based on Character Level)",
[]float64{25},
},
// DescFn11
{"item_replenish_durability", []float64{2}, "Repairs 2 durability per second"},
{"item_replenish_durability", "Repairs 2 durability per second", []float64{2}},
// DescFn12
{"item_stupidity", []float64{5}, "Hit Blinds Target +5"},
{"item_stupidity", "Hit Blinds Target +5", []float64{5}},
// DescFn13
{"item_addclassskills", []float64{5, 3}, "+5 to Paladin Skill Levels"},
{"item_addclassskills", "+5 to Paladin Skill Levels", []float64{5, 3}},
// DescFn14
{"item_addskill_tab", []float64{5, 3, 0}, "+5 to Combat Skills (Paladin Only)"},
{"item_addskill_tab", []float64{5, 3, 1}, "+5 to Offensive Auras (Paladin Only)"},
{"item_addskill_tab", []float64{5, 3, 2}, "+5 to Defensive Auras (Paladin Only)"},
{"item_addskill_tab", "+5 to Combat Skills (Paladin Only)", []float64{5, 3, 0}},
{"item_addskill_tab", "+5 to Offensive Auras (Paladin Only)", []float64{5, 3, 1}},
{"item_addskill_tab", "+5 to Defensive Auras (Paladin Only)", []float64{5, 3, 2}},
// DescFn15
{"item_skillonattack", []float64{5, 7, 64},
"5% Chance to cast level 7 Frozen Orb on attack"},
{
"item_skillonattack",
"5% Chance to cast level 7 Frozen Orb on attack",
[]float64{5, 7, 64},
},
// DescFn16
{"item_aura", []float64{3, 37}, "Level 3 Warmth Aura When Equipped"},
{"item_aura", "Level 3 Warmth Aura When Equipped", []float64{3, 37}},
// DescFn20
{"item_fractionaltargetac", []float64{-25}, "-25% Target Defense"},
{"item_fractionaltargetac", "-25% Target Defense", []float64{-25}},
// DescFn22
{"attack_vs_montype", []float64{25, 40}, "25% to Attack Rating versus Specter"},
{"attack_vs_montype", "25% to Attack Rating versus Specter", []float64{25, 40}},
// DescFn23
{"item_reanimate", []float64{25, 40}, "25% Reanimate as: Specter"},
{"item_reanimate", "25% Reanimate as: Specter", []float64{25, 40}},
// DescFn24
{"item_charged_skill", []float64{25, 64, 20, 19}, "Level 25 Frozen Orb (19/20 Charges)"},
{"item_charged_skill", "Level 25 Frozen Orb (19/20 Charges)", []float64{25, 64, 20, 19}},
// DescFn27
{"item_singleskill", []float64{25, 64, 3}, "+25 to Frozen Orb (Paladin Only)"},
{"item_singleskill", "+25 to Frozen Orb (Paladin Only)", []float64{25, 64, 3}},
// DescFn28
{"item_nonclassskill", []float64{25, 64}, "+25 to Frozen Orb"},
{"item_nonclassskill", "+25 to Frozen Orb", []float64{25, 64}},
}
for idx := range tests {