1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00

Refactored d2enum (#567)

* Refactored animation mode enum

* More d2enum changes

* Refactored tile enum

* Refactored weapon class enum

* Refactored more enums

* Refactored item event enum

* Fixed init_functions animation mode

* Removed string2enum from MonsterAnimationMode

* Refactored ItemStatCost description

* Last enum lint errors

* Regenerated monster stringer file
This commit is contained in:
Intyre 2020-07-10 05:12:28 +02:00 committed by GitHub
parent 6030f68632
commit 9e58b134e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 604 additions and 885 deletions

View File

@ -1,6 +1,7 @@
package d2datadict
import (
"fmt"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
@ -35,9 +36,6 @@ type ItemStatCostRecord struct {
// entire op stuff.
Stuff string
DescFn interface{} // the sprintf func
DescGroupFn interface{} // group sprintf func
Index int
// path_d2.mpq version doesnt have Ranged columne, excluding for now
@ -75,7 +73,7 @@ type ItemStatCostRecord struct {
EventFuncID2 d2enum.ItemEventFuncID
DescPriority int // determines order when displayed
DescFnID d2enum.DescFuncID
DescFnID int
// Controls whenever and if so in what way the stat value is shown
// 0 = doesn't show the value of the stat
@ -87,7 +85,7 @@ type ItemStatCostRecord struct {
// group func for desc (they need to be in the same affix)
DescGroup int
DescGroupVal int
DescGroupFuncID d2enum.DescFuncID
DescGroupFuncID int
CallbackEnabled bool // whether callback fn is called if value changes
Signed bool // whether the stat is signed
@ -103,6 +101,61 @@ type ItemStatCostRecord struct {
DamageRelated bool // prevents stacking of stats while dual wielding
}
//nolint:gochecknoglobals // better for lookup
var itemStatCostRecordLookup = []string{
"+%f %s",
"%f%% %s",
"%f %s",
"+%f%% %s",
"%f%% %s",
"+%f %s %s",
"%f%% %s %s",
"+%f%% %s %s",
"%f %s %s",
"%f %s %s",
"Repairs 1 Durability In %.0f Seconds",
"+%f %s",
"+%.0f to %s Skill Levels",
"+%.0f to %s Skill Levels (%s Only)",
"%.0f%% chance to cast %d %s on %s",
"Level %d %s Aura When Equipped",
"%f %s (Increases near %d)",
"%f%% %s (Increases near %d)",
"",
"%f%% %s",
"%f %s",
"%f%% %s %s",
"",
"%f%% %s %s",
"Level %.0f %s (%d/%d Charges)",
"",
"",
"+%f to %s (%s Only)",
"+%.0f to %s",
}
// DescString return a string based on the DescFnID
func (r *ItemStatCostRecord) DescString(a ...interface{}) string {
if r.DescFnID < 0 || r.DescFnID > len(itemStatCostRecordLookup) {
return ""
}
format := itemStatCostRecordLookup[r.DescFnID]
return fmt.Sprintf(format, a...)
}
// DescGroupString return a string based on the DescGroupFuncID
func (r *ItemStatCostRecord) DescGroupString(a ...interface{}) string {
if r.DescGroupFuncID < 0 || r.DescGroupFuncID > len(itemStatCostRecordLookup) {
return ""
}
format := itemStatCostRecordLookup[r.DescGroupFuncID]
return fmt.Sprintf(format, a...)
}
// ItemStatCosts stores all of the ItemStatCostRecords
//nolint:gochecknoglobals // Currently global by design
var ItemStatCosts map[string]*ItemStatCostRecord
@ -159,20 +212,19 @@ func LoadItemStatCosts(file []byte) {
EventID1: d2enum.GetItemEventType(d.String("itemevent1")),
EventID2: d2enum.GetItemEventType(d.String("itemevent2")),
EventFuncID1: d2enum.GetItemEventFuncID(d.Number("itemeventfunc1")),
EventFuncID2: d2enum.GetItemEventFuncID(d.Number("itemeventfunc2")),
EventFuncID1: d2enum.ItemEventFuncID(d.Number("itemeventfunc1")),
EventFuncID2: d2enum.ItemEventFuncID(d.Number("itemeventfunc2")),
DescPriority: d.Number("descpriority"),
DescFnID: d2enum.DescFuncID(d.Number("descfunc")),
DescFn: d2enum.GetDescFunction(d2enum.DescFuncID(d.Number("descfunc"))),
DescFnID: d.Number("descfunc"),
DescVal: d.Number("descval"),
DescStrPos: d.String("descstrpos"),
DescStrNeg: d.String("descstrneg"),
DescStr2: d.String("descstr2"),
DescGroup: d.Number("dgrp"),
DescGroupFuncID: d2enum.DescFuncID(d.Number("dgrpfunc")),
DescGroupFn: d2enum.GetDescFunction(d2enum.DescFuncID(d.Number("dgrpfunc"))),
DescGroupFuncID: d.Number("dgrpfunc"),
DescGroupVal: d.Number("dgrpval"),
DescGroupStrPos: d.String("dgrpstrpos"),
DescGroupStrNeg: d.String("dgrpstrneg"),

View File

@ -308,7 +308,7 @@ func LoadMonStats2(file []byte) {
InfernoLen: d.Number("InfernoLen"),
InfernoAnim: d.Number("InfernoAnim"),
InfernoRollback: d.Number("InfernoRollback"),
ResurrectMode: d2enum.MonsterAnimationModeFromString(d.String("ResurrectMode")),
ResurrectMode: monsterAnimationModeFromString(d.String("ResurrectMode")),
ResurrectSkill: d.String("ResurrectSkill"),
}
MonStats2[record.Key] = record
@ -320,3 +320,20 @@ func LoadMonStats2(file []byte) {
log.Printf("Loaded %d MonStats2 records", len(MonStats2))
}
//nolint:gochecknoglobals // better for lookup
var monsterAnimationModeLookup = map[string]d2enum.MonsterAnimationMode{
d2enum.MonsterAnimationModeNeutral.String(): d2enum.MonsterAnimationModeNeutral,
d2enum.MonsterAnimationModeSkill1.String(): d2enum.MonsterAnimationModeSkill1,
d2enum.MonsterAnimationModeSequence.String(): d2enum.MonsterAnimationModeSequence,
}
func monsterAnimationModeFromString(s string) d2enum.MonsterAnimationMode {
v, ok := monsterAnimationModeLookup[s]
if !ok {
log.Fatalf("unhandled MonsterAnimationMode %q", s)
return d2enum.MonsterAnimationModeNeutral
}
return v
}

View File

@ -3,19 +3,11 @@ package d2enum
// AnimationFrame represents a single frame of animation.
type AnimationFrame int
// AnimationFrame types
const (
// AnimationFrameNoEvent represents an animation frame with no event
AnimationFrameNoEvent AnimationFrame = iota
// AnimationFrameAttack represents an animation frame with an attack event
AnimationFrameAttack
// AnimationFrameMissile represents an animation frame with a missile event
AnimationFrameMissile
// AnimationFrameSound represents an animation frame with a sound event
AnimationFrameSound
// AnimationFrameSkill represents an animation frame with a skill event
AnimationFrameSkill
)

View File

@ -1,153 +0,0 @@
package d2enum
// PlayerAnimationMode represents player animation modes
type PlayerAnimationMode int
// MonsterAnimationMode represents monster animation modes
type MonsterAnimationMode int
// ObjectAnimationMode represents object animation modes
type ObjectAnimationMode int
const (
// AnimationModePlayerDeath represents DT
AnimationModePlayerDeath PlayerAnimationMode = iota
// AnimationModePlayerNeutral represents NU
AnimationModePlayerNeutral
// AnimationModePlayerWalk represents WL
AnimationModePlayerWalk
// AnimationModePlayerRun represents RN
AnimationModePlayerRun
// AnimationModePlayerGetHit represents GH
AnimationModePlayerGetHit
// AnimationModePlayerTownNeutral represents TN
AnimationModePlayerTownNeutral
// AnimationModePlayerTownWalk represents TW
AnimationModePlayerTownWalk
// AnimationModePlayerAttack1 represents A1
AnimationModePlayerAttack1
// AnimationModePlayerAttack2 represents A2
AnimationModePlayerAttack2
// AnimationModePlayerBlock represents BL
AnimationModePlayerBlock
// AnimationModePlayerCast represents SC
AnimationModePlayerCast
// AnimationModePlayerThrow represents TH
AnimationModePlayerThrow
// AnimationModePlayerKick represents KK
AnimationModePlayerKick
// AnimationModePlayerSkill1 represents S1
AnimationModePlayerSkill1
// AnimationModePlayerSkill2 represents S2
AnimationModePlayerSkill2
// AnimationModePlayerSkill3 represents S3
AnimationModePlayerSkill3
// AnimationModePlayerSkill4 represents S4
AnimationModePlayerSkill4
// AnimationModePlayerDead represents DD
AnimationModePlayerDead
// AnimationModePlayerSequence represents GH
AnimationModePlayerSequence
// AnimationModePlayerKnockBack represents GH
AnimationModePlayerKnockBack
)
const (
// AnimationModeMonsterDeath represents DT
AnimationModeMonsterDeath MonsterAnimationMode = iota
// AnimationModeMonsterNeutral represents NU
AnimationModeMonsterNeutral
// AnimationModeMonsterWalk represents WL
AnimationModeMonsterWalk
// AnimationModeMonsterGetHit represents GH
AnimationModeMonsterGetHit
// AnimationModeMonsterAttack1 represents A1
AnimationModeMonsterAttack1
// AnimationModeMonsterAttack2 represents A2
AnimationModeMonsterAttack2
// AnimationModeMonsterBlock represents BL
AnimationModeMonsterBlock
// AnimationModeMonsterCast represents SC
AnimationModeMonsterCast
// AnimationModeMonsterSkill1 represents S1
AnimationModeMonsterSkill1
// AnimationModeMonsterSkill2 represents S2
AnimationModeMonsterSkill2
// AnimationModeMonsterSkill3 represents S3
AnimationModeMonsterSkill3
// AnimationModeMonsterSkill4 represents S4
AnimationModeMonsterSkill4
// AnimationModeMonsterDead represents DD
AnimationModeMonsterDead
// AnimationModeMonsterKnockback represents GH
AnimationModeMonsterKnockback
// AnimationModeMonsterSequence represents xx
AnimationModeMonsterSequence
// AnimationModeMonsterRun represents RN
AnimationModeMonsterRun
)
const (
// AnimationModeObjectNeutral represents NU
AnimationModeObjectNeutral ObjectAnimationMode = iota
// AnimationModeObjectOperating represents OP
AnimationModeObjectOperating
// AnimationModeObjectOpened represents ON
AnimationModeObjectOpened
// AnimationModeObjectSpecial1 represents S1
AnimationModeObjectSpecial1
// AnimationModeObjectSpecial2 represents S2
AnimationModeObjectSpecial2
// AnimationModeObjectSpecial3 represents S3
AnimationModeObjectSpecial3
// AnimationModeObjectSpecial4 represents S4
AnimationModeObjectSpecial4
// AnimationModeObjectSpecial5 represents S5
AnimationModeObjectSpecial5
)
//go:generate stringer -linecomment -type PlayerAnimationMode
//go:generate stringer -linecomment -type MonsterAnimationMode
//go:generate stringer -linecomment -type ObjectAnimationMode
//go:generate string2enum -samepkg -linecomment -type ObjectAnimationMode

View File

@ -1,60 +1,27 @@
package d2enum
//go:generate stringer -linecomment -type CompositeType -output composite_type_string.go
// CompositeType represents a composite type
type CompositeType int
// Composite types
const (
// CompositeTypeHead is a composite type for heads
CompositeTypeHead CompositeType = iota // HD
// CompositeTypeTorso is a composite type for torsos
CompositeTypeTorso // TR
// CompositeTypeLegs is a composite type for legs
CompositeTypeLegs // LG
// CompositeTypeRightArm is a composite type for right arms
CompositeTypeRightArm // RA
// CompositeTypeLeftArm is a composite type for left arms
CompositeTypeLeftArm // LA
// CompositeTypeRightHand is a composite type for right hands
CompositeTypeRightHand // RH
// CompositeTypeLeftHand is a composite type for left hands
CompositeTypeLeftHand // LH
// CompositeTypeShield is a composite type for shields
CompositeTypeShield // SH
// CompositeTypeSpecial1 is a composite type for special type 1s
CompositeTypeSpecial1 // S1
// CompositeTypeSpecial2 is a composite type for special type 2s
CompositeTypeSpecial2 // S2
// CompositeTypeSpecial3 is a composite type for special type 3s
CompositeTypeSpecial3 // S3
// CompositeTypeSpecial4 is a composite type for special type 4s
CompositeTypeSpecial4 // S4
// CompositeTypeSpecial5 is a composite type for special type 5s
CompositeTypeSpecial5 // S5
// CompositeTypeSpecial6 is a composite type for special type 6s
CompositeTypeSpecial6 // S6
// CompositeTypeSpecial7 is a composite type for special type 7s
CompositeTypeSpecial7 // S7
// CompositeTypeSpecial8 is a composite type for special type 8s
CompositeTypeSpecial8 // S8
// CompositeTypeMax is used to determine the max number of composite types
CompositeTypeMax
)
//go:generate stringer -linecomment -type CompositeType

View File

@ -1,4 +1,4 @@
// Code generated by "stringer -linecomment -type CompositeType"; DO NOT EDIT.
// Code generated by "stringer -linecomment -type CompositeType -output composite_type_string.go"; DO NOT EDIT.
package d2enum

View File

@ -1,58 +0,0 @@
// Code generated by "string2enum -samepkg -linecomment -type CompositeType"; DO NOT EDIT.
package d2enum
import "fmt"
// CompositeTypeFromString returns the CompositeType enum corresponding to s.
func CompositeTypeFromString(s string) CompositeType {
if len(s) == 0 {
return 0
}
for i := range _CompositeType_index[:len(_CompositeType_index)-1] {
if s == _CompositeType_name[_CompositeType_index[i]:_CompositeType_index[i+1]] {
return CompositeType(i)
}
}
panic(fmt.Errorf("unable to locate CompositeType enum corresponding to %q", s))
}
func _(s string) {
// Check for duplicate string values in type "CompositeType".
switch s {
// 0
case "HD":
// 1
case "TR":
// 2
case "LG":
// 3
case "RA":
// 4
case "LA":
// 5
case "RH":
// 6
case "LH":
// 7
case "SH":
// 8
case "S1":
// 9
case "S2":
// 10
case "S3":
// 11
case "S4":
// 12
case "S5":
// 13
case "S6":
// 14
case "S7":
// 15
case "S8":
// 16
case "CompositeTypeMax":
}
}

View File

@ -1,194 +0,0 @@
package d2enum
import (
"fmt"
)
type DescFuncID int
func Format1(value float64, string1 string) string {
// +[value] [string1]
return fmt.Sprintf("+%f %s", value, string1)
}
func Format2(value float64, string1 string) string {
// [value]% [string1]
return fmt.Sprintf("%f%% %s", value, string1)
}
func Format3(value float64, string1 string) string {
// [value] [string1]
return fmt.Sprintf("%f %s", value, string1)
}
func Format4(value float64, string1 string) string {
// +[value]% [string1]
return fmt.Sprintf("+%f%% %s", value, string1)
}
func Format5(value float64, string1 string) string {
// [value*100/128]% [string1]
return fmt.Sprintf("%f%% %s", (value*100.0)/128.0, string1)
}
func Format6(value float64, string1, string2 string) string {
// +[value] [string1] [string2]
return fmt.Sprintf("+%f %s %s", value, string1, string2)
}
func Format7(value float64, string1, string2 string) string {
// [value]% [string1] [string2]
return fmt.Sprintf("%f%% %s %s", value, string1, string2)
}
func Format8(value float64, string1, string2 string) string {
// +[value]% [string1] [string2]
return fmt.Sprintf("+%f%% %s %s", value, string1, string2)
}
func Format9(value float64, string1, string2 string) string {
// [value] [string1] [string2]
return fmt.Sprintf("%f %s %s", value, string1, string2)
}
func Format10(value float64, string1, string2 string) string {
// [value*100/128]% [string1] [string2]
return fmt.Sprintf("%f%% %s %s", (value*100.0)/128.0, string1, string2)
}
func Format11(value float64) string {
// Repairs 1 Durability In [100 / value] Seconds
return fmt.Sprintf("Repairs 1 Durability In %.0f Seconds", 100.0/value)
}
func Format12(value float64, string1 string) string {
// +[value] [string1]
return fmt.Sprintf("+%f %s", value, string1)
}
func Format13(value float64, class string) string {
// +[value] to [class] Skill Levels
return fmt.Sprintf("+%.0f to %s Skill Levels", value, class)
}
func Format14(value float64, skilltab, class string) string {
// +[value] to [skilltab] Skill Levels ([class] Only)
fmtStr := "+%.0f to %s Skill Levels (%s Only)"
return fmt.Sprintf(fmtStr, value, skilltab, class)
}
func Format15(value float64, slvl int, skill, event string) string {
// [value]% chance to cast [slvl] [skill] on [event]
fmtStr := "%.0f%% chance to cast %d %s on %s"
return fmt.Sprintf(fmtStr, value, slvl, skill, event)
}
func Format16(slvl int, skill string) string {
// Level [sLvl] [skill] Aura When Equipped
return fmt.Sprintf("Level %d %s Aura When Equipped", slvl, skill)
}
func Format17(value float64, string1 string, time int) string {
// [value] [string1] (Increases near [time])
return fmt.Sprintf("%f %s (Increases near %d)", value, string1, time)
}
func Format18(value float64, string1 string, time int) string {
// [value]% [string1] (Increases near [time])
return fmt.Sprintf("%f%% %s (Increases near %d)", value, string1, time)
}
func Format19(value float64, string1 string) string {
// this is used by stats that use Blizzard's sprintf implementation
// (if you don't know what that is, it won't be of interest to you
// eitherway I guess), look at how prismatic is setup, the string is
// the format that gets passed to their sprintf spinoff.
return "" // TODO
}
func Format20(value float64, string1 string) string {
// [value * -1]% [string1]
return fmt.Sprintf("%f%% %s", value*-1.0, string1)
}
func Format21(value float64, string1 string) string {
// [value * -1] [string1]
return fmt.Sprintf("%f %s", value*-1.0, string1)
}
func Format22(value float64, string1, montype string) string {
// [value]% [string1] [montype]
return fmt.Sprintf("%f%% %s %s", value, string1, montype)
}
func Format23(value float64, string1 string) string {
// (warning: this is bugged in vanilla and doesn't work properly
// see CE forum)
return "" // TODO
}
func Format24(value float64, string1, monster string) string {
// [value]% [string1] [monster]
return fmt.Sprintf("%f%% %s %s", value, string1, monster)
}
func Format25(slvl float64, skill string, charges, maxCharges int) string {
// Level [slvl] [skill] ([charges]/[maxCharges] Charges)
fmtStr := "Level %.0f %s (%d/%d Charges)"
return fmt.Sprintf(fmtStr, slvl, skill, charges, maxCharges)
}
func Format26(value float64, string1 string) string {
// not used by vanilla, present in the code but I didn't test it yet
return "" // TODO
}
func Format27(value float64, string1 string) string {
// not used by vanilla, present in the code but I didn't test it yet
return "" // TODO
}
func Format28(value float64, skill, class string) string {
// +[value] to [skill] ([class] Only)
return fmt.Sprintf("+%f to %s (%s Only)", value, skill, class)
}
func Format29(value float64, skill string) string {
// +[value] to [skill]
return fmt.Sprintf("+%.0f to %s", value, skill)
}
func GetDescFunction(n DescFuncID) interface{} {
m := map[DescFuncID]interface{}{
DescFuncID(0): Format1,
DescFuncID(1): Format2,
DescFuncID(2): Format3,
DescFuncID(3): Format4,
DescFuncID(4): Format5,
DescFuncID(5): Format6,
DescFuncID(6): Format7,
DescFuncID(7): Format8,
DescFuncID(8): Format9,
DescFuncID(9): Format10,
DescFuncID(10): Format11,
DescFuncID(11): Format12,
DescFuncID(12): Format13,
DescFuncID(13): Format14,
DescFuncID(14): Format15,
DescFuncID(15): Format16,
DescFuncID(16): Format17,
DescFuncID(17): Format18,
DescFuncID(18): Format19,
DescFuncID(19): Format20,
DescFuncID(20): Format21,
DescFuncID(21): Format22,
DescFuncID(22): Format23,
DescFuncID(23): Format24,
DescFuncID(24): Format25,
DescFuncID(25): Format26,
DescFuncID(26): Format27,
DescFuncID(27): Format28,
DescFuncID(28): Format29,
}
return m[n]
}

View File

@ -5,7 +5,6 @@ type DrawEffect int
// Names courtesy of Necrolis
const (
// DrawEffectPctTransparency25 is a draw effect that implements the following function:
// GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 25 % transparency (colormaps 49-304 in a .pl2)
DrawEffectPctTransparency25 DrawEffect = iota

View File

@ -1,7 +1,9 @@
package d2enum
// EncodingType represents a encoding type
type EncodingType int
// Encoding types
const (
EncodeDefault EncodingType = iota
)

View File

@ -2,19 +2,25 @@ package d2enum
import "log"
//go:generate stringer -linecomment -type Hero
//go:generate string2enum -samepkg -linecomment -type Hero
// Hero is used for different types of hero's
type Hero int
// Heroes
const (
HeroNone Hero = 0 //
HeroBarbarian Hero = 1 // Barbarian
HeroNecromancer Hero = 2 // Necromancer
HeroPaladin Hero = 3 // Paladin
HeroAssassin Hero = 4 // Assassin
HeroSorceress Hero = 5 // Sorceress
HeroAmazon Hero = 6 // Amazon
HeroDruid Hero = 7 // Druid
HeroNone Hero = iota //
HeroBarbarian // Barbarian
HeroNecromancer // Necromancer
HeroPaladin // Paladin
HeroAssassin // Assassin
HeroSorceress // Sorceress
HeroAmazon // Amazon
HeroDruid // Druid
)
// GetToken returns a 2 letter token
func (h Hero) GetToken() string {
switch h {
case HeroBarbarian:
@ -34,8 +40,6 @@ func (h Hero) GetToken() string {
default:
log.Fatalf("Unknown hero token: %d", h)
}
return ""
}
//go:generate stringer -linecomment -type Hero
//go:generate string2enum -samepkg -linecomment -type Hero

View File

@ -1,11 +1,13 @@
package d2enum
// HeroStance used to render hero stance
type HeroStance int
// HeroStance types
const (
HeroStanceIdle HeroStance = 0
HeroStanceIdleSelected HeroStance = 1
HeroStanceApproaching HeroStance = 2
HeroStanceSelected HeroStance = 3
HeroStanceRetreating HeroStance = 4
HeroStanceIdle HeroStance = iota
HeroStanceIdleSelected
HeroStanceApproaching
HeroStanceSelected
HeroStanceRetreating
)

View File

@ -22,9 +22,9 @@ const _Hero_name = "BarbarianNecromancerPaladinAssassinSorceressAmazonDruid"
var _Hero_index = [...]uint8{0, 0, 9, 20, 27, 35, 44, 50, 55}
func (h Hero) String() string {
if h < 0 || h >= Hero(len(_Hero_index)-1) {
return "Hero(" + strconv.FormatInt(int64(h), 10) + ")"
func (i Hero) String() string {
if i < 0 || i >= Hero(len(_Hero_index)-1) {
return "Hero(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Hero_name[_Hero_index[h]:_Hero_index[h+1]]
return _Hero_name[_Hero_index[i]:_Hero_index[i+1]]
}

View File

@ -16,3 +16,25 @@ func HeroFromString(s string) Hero {
}
panic(fmt.Errorf("unable to locate Hero enum corresponding to %q", s))
}
func _(s string) {
// Check for duplicate string values in type "Hero".
switch s {
// 0
case "":
// 1
case "Barbarian":
// 2
case "Necromancer":
// 3
case "Paladin":
// 4
case "Assassin":
// 5
case "Sorceress":
// 6
case "Amazon":
// 7
case "Druid":
}
}

View File

@ -3,12 +3,9 @@ package d2enum
// Priority of the event handler
type Priority int
//noinspection GoUnusedConst // nothing is low priority yet
// Priorities
const (
// PriorityLow is a low priority handler
PriorityLow Priority = iota
// PriorityDefault is a default priority handler
PriorityDefault
// PriorityHigh is a high priority handler
PriorityHigh
)

View File

@ -1,9 +1,11 @@
package d2enum
// InventoryItemType represents a inventory item type
type InventoryItemType int
// Inventry item types
const (
InventoryItemTypeItem InventoryItemType = 0 // Item
InventoryItemTypeWeapon InventoryItemType = 1 // Weapon
InventoryItemTypeArmor InventoryItemType = 2 // Armor
InventoryItemTypeItem InventoryItemType = iota
InventoryItemTypeWeapon
InventoryItemTypeArmor
)

View File

@ -1,13 +1,18 @@
package d2enum
// ItemAffixSuperType represents a item affix super type
type ItemAffixSuperType int
type ItemAffixSubType int
// Super types
const (
ItemAffixPrefix ItemAffixSuperType = iota
ItemAffixSuffix
)
// ItemAffixSubType represents a item affix sub type
type ItemAffixSubType int
// Sub types
const (
ItemAffixCommon ItemAffixSubType = iota
ItemAffixMagic

View File

@ -1,11 +1,13 @@
package d2enum
// ItemEventFuncID represents a item event function
type ItemEventFuncID int
// Item event functions
const (
// shoots a missile at the owner of a missile that has just hit you
// (Chilling Armor uses this)
ReflectMissile = ItemEventFuncID(iota)
ReflectMissile ItemEventFuncID = iota
// freezes the attacker for a set duration the attacker
// (Frozen Armor uses this)
@ -102,42 +104,3 @@ const (
// reanimate the target as the specified monster
ReanimateTargetAsMonster
)
func GetItemEventFuncID(n int) ItemEventFuncID {
m := map[int]ItemEventFuncID{
0: ReflectMissile,
1: FreezeAttacker,
2: FreezeChillAttacker,
3: ReflectPercentDamage,
4: DamageDealtToHealth,
5: AttackerTakesPhysical,
6: Knockback,
7: InduceFear,
8: BlindTarget,
9: AttackerTakesLightning,
10: AttackerTakesFire,
11: AttackerTakesCold,
12: DamageTakenToMana,
13: FreezeTarget,
14: OpenWounds,
15: CrushingBlow,
16: ManaOnKillMonster,
17: LifeOnKillDemon,
18: SlowTarget,
19: CastSkillAgainstDefender,
20: CastSkillAgainstAttacker,
21: AbsorbPhysical,
22: TakeSummonDamage,
23: ManaAbsorbsDamage,
24: AbsorbElementalDamage,
25: TakeSummonDamage2,
26: TargetSlowsTarget,
27: LifeOnKillMonster,
28: RestInPeace,
29: CastSkillWithoutTarget,
30: ReanimateTargetAsMonster,
}
return m[n]
}
//? do i need to do this ? //go:generate stringer -linecomment -type AnimationMode

View File

@ -1,39 +1,52 @@
package d2enum
// used in ItemStatCost
// ItemEventType used in ItemStatCost
type ItemEventType int
// Item event types
const (
HitByMissile = ItemEventType(iota) // hit By a Missile
DamagedInMelee // Damaged in Melee
DamagedByMissile // Damaged By Missile
AttackedInMelee // melee Attack atttempt
DoActive // do active state skill
DoMeleeDamage // do damage in melee
DoMissileDamage // do missile damage
DoMeleeAttack // do melee attack
DoMissileAttack // do missile attack
Kill // killed something
Killed // killed By something
AbsorbDamage // dealt damage
LevelUp // gain a level
ItemEventNone ItemEventType = iota
ItemEventHitByMissile // hit By a Missile
ItemEventDamagedInMelee // Damaged in Melee
ItemEventDamagedByMissile // Damaged By Missile
ItemEventAttackedInMelee // melee Attack atttempt
ItemEventDoActive // do active state skill
ItemEventDoMeleeDamage // do damage in melee
ItemEventDoMissileDamage // do missile damage
ItemEventDoMeleeAttack // do melee attack
ItemEventDoMissileAttack // do missile attack
ItemEventKill // killed something
ItemEventKilled // killed By something
ItemEventAbsorbDamage // dealt damage
ItemEventLevelUp // gain a level
)
//nolint:gochecknoglobals // better for lookup
var itemEventsLookup = map[string]ItemEventType{
"hitbymissile": ItemEventHitByMissile,
"damagedinmelee": ItemEventDamagedInMelee,
"damagedbymissile": ItemEventDamagedByMissile,
"attackedinmelee": ItemEventAttackedInMelee,
"doactive": ItemEventDoActive,
"domeleedamage": ItemEventDoMeleeDamage,
"domissiledamage": ItemEventDoMissileDamage,
"domeleeattack": ItemEventDoMeleeAttack,
"domissileattack": ItemEventDoMissileAttack,
"kill": ItemEventKill,
"killed": ItemEventKilled,
"absorbdamage": ItemEventAbsorbDamage,
"levelup": ItemEventLevelUp,
}
// GetItemEventType returns the ItemEventType from string, expects lowercase input
func GetItemEventType(s string) ItemEventType {
strLookupTable := map[string]ItemEventType{
"HitByMissile": HitByMissile,
"DamagedInMelee": DamagedInMelee,
"DamagedByMissile": DamagedByMissile,
"AttackedInMelee": AttackedInMelee,
"DoActive": DoActive,
"DoMeleeDamage": DoMeleeDamage,
"DoMissileDamage": DoMissileDamage,
"DoMeleeAttack": DoMeleeAttack,
"DoMissileAttack": DoMissileAttack,
"Kill": Kill,
"Killed": Killed,
"AbsorbDamage": AbsorbDamage,
"LevelUp": LevelUp,
if s == "" {
return ItemEventNone
}
return strLookupTable[s]
if v, ok := itemEventsLookup[s]; ok {
return v
}
return ItemEventNone
}

View File

@ -1,18 +1,20 @@
package d2enum
// LayerStreamType represents a layer stream type
type LayerStreamType int
// Layer stream types
const (
LayerStreamWall1 LayerStreamType = 0
LayerStreamWall2 LayerStreamType = 1
LayerStreamWall3 LayerStreamType = 2
LayerStreamWall4 LayerStreamType = 3
LayerStreamOrientation1 LayerStreamType = 4
LayerStreamOrientation2 LayerStreamType = 5
LayerStreamOrientation3 LayerStreamType = 6
LayerStreamOrientation4 LayerStreamType = 7
LayerStreamFloor1 LayerStreamType = 8
LayerStreamFloor2 LayerStreamType = 9
LayerStreamShadow LayerStreamType = 10
LayerStreamSubstitute LayerStreamType = 11
LayerStreamWall1 LayerStreamType = iota
LayerStreamWall2
LayerStreamWall3
LayerStreamWall4
LayerStreamOrientation1
LayerStreamOrientation2
LayerStreamOrientation3
LayerStreamOrientation4
LayerStreamFloor1
LayerStreamFloor2
LayerStreamShadow
LayerStreamSubstitute
)

View File

@ -3,13 +3,13 @@ package d2enum
// from levels.txt, field `DrlgType`
// https://d2mods.info/forum/kb/viewarticle?a=301
// Setting for Level Generation: You have 3 possibilities here:
// LevelGenerationType Setting for Level Generation: You have 3 possibilities here:
// 1 Random Maze
// 2 Preset Area
// 3 Wilderness level
type LevelGenerationType int
// Level generation types
const (
LevelTypeRandomMaze LevelGenerationType = iota
LevelTypePreset

View File

@ -3,14 +3,14 @@ package d2enum
// from levels.txt, field `Teleport`
// https://d2mods.info/forum/kb/viewarticle?a=301
// Controls if teleport is allowed in that level.
// TeleportFlag Controls if teleport is allowed in that level.
// 0 = Teleport not allowed
// 1 = Teleport allowed
// 2 = Teleport allowed, but not able to use teleport throu walls/objects
// (maybe for objects)
type TeleportFlag int
// Teleport flag types
const (
TeleportDisabled TeleportFlag = iota
TeleportEnabled

View File

@ -0,0 +1,26 @@
package d2enum
//go:generate stringer -linecomment -type MonsterAnimationMode -output monster_animation_mode_string.go
// MonsterAnimationMode represents monster animation modes
type MonsterAnimationMode int
// Monster animation modes
const (
MonsterAnimationModeDeath MonsterAnimationMode = iota // DT
MonsterAnimationModeNeutral // NU
MonsterAnimationModeWalk // WL
MonsterAnimationModeGetHit // GH
MonsterAnimationModeAttack1 // A1
MonsterAnimationModeAttack2 // A2
MonsterAnimationModeBlock // BL
MonsterAnimationModeCast // SC
MonsterAnimationModeSkill1 // S1
MonsterAnimationModeSkill2 // S2
MonsterAnimationModeSkill3 // S3
MonsterAnimationModeSkill4 // S4
MonsterAnimationModeDead // DD
MonsterAnimationModeKnockback // GH
MonsterAnimationModeSequence // xx
MonsterAnimationModeRun // RN
)

View File

@ -1,4 +1,4 @@
// Code generated by "stringer -linecomment -type MonsterAnimationMode"; DO NOT EDIT.
// Code generated by "stringer -linecomment -type MonsterAnimationMode -output monster_animation_mode_string.go"; DO NOT EDIT.
package d2enum
@ -8,22 +8,22 @@ func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[AnimationModeMonsterDeath-0]
_ = x[AnimationModeMonsterNeutral-1]
_ = x[AnimationModeMonsterWalk-2]
_ = x[AnimationModeMonsterGetHit-3]
_ = x[AnimationModeMonsterAttack1-4]
_ = x[AnimationModeMonsterAttack2-5]
_ = x[AnimationModeMonsterBlock-6]
_ = x[AnimationModeMonsterCast-7]
_ = x[AnimationModeMonsterSkill1-8]
_ = x[AnimationModeMonsterSkill2-9]
_ = x[AnimationModeMonsterSkill3-10]
_ = x[AnimationModeMonsterSkill4-11]
_ = x[AnimationModeMonsterDead-12]
_ = x[AnimationModeMonsterKnockback-13]
_ = x[AnimationModeMonsterSequence-14]
_ = x[AnimationModeMonsterRun-15]
_ = x[MonsterAnimationModeDeath-0]
_ = x[MonsterAnimationModeNeutral-1]
_ = x[MonsterAnimationModeWalk-2]
_ = x[MonsterAnimationModeGetHit-3]
_ = x[MonsterAnimationModeAttack1-4]
_ = x[MonsterAnimationModeAttack2-5]
_ = x[MonsterAnimationModeBlock-6]
_ = x[MonsterAnimationModeCast-7]
_ = x[MonsterAnimationModeSkill1-8]
_ = x[MonsterAnimationModeSkill2-9]
_ = x[MonsterAnimationModeSkill3-10]
_ = x[MonsterAnimationModeSkill4-11]
_ = x[MonsterAnimationModeDead-12]
_ = x[MonsterAnimationModeKnockback-13]
_ = x[MonsterAnimationModeSequence-14]
_ = x[MonsterAnimationModeRun-15]
}
const _MonsterAnimationMode_name = "DTNUWLGHA1A2BLSCS1S2S3S4DDGHxxRN"

View File

@ -1,57 +0,0 @@
// Manually edited to remove duplicate
// If you generate it again you need fix it up
// Code generated by "string2enum -samepkg -linecomment -type MonsterAnimationMode ."; DO NOT EDIT.
package d2enum
import "fmt"
// MonsterAnimationModeFromString returns the MonsterAnimationMode enum corresponding to s.
func MonsterAnimationModeFromString(s string) MonsterAnimationMode {
if len(s) == 0 {
return 0
}
for i := range _MonsterAnimationMode_index[:len(_MonsterAnimationMode_index)-1] {
if s == _MonsterAnimationMode_name[_MonsterAnimationMode_index[i]:_MonsterAnimationMode_index[i+1]] {
return MonsterAnimationMode(i)
}
}
panic(fmt.Errorf("unable to locate MonsterAnimationMode enum corresponding to %q", s))
}
func _(s string) {
// Check for duplicate string values in type "MonsterAnimationMode".
switch s {
// 0
case "DT":
// 1
case "NU":
// 2
case "WL":
// 3
case "GH":
// 4
case "A1":
// 5
case "A2":
// 6
case "BL":
// 7
case "SC":
// 8
case "S1":
// 9
case "S2":
// 10
case "S3":
// 11
case "S4":
// 12
case "DD":
// 14
case "xx":
// 15
case "RN":
}
}

View File

@ -0,0 +1,19 @@
package d2enum
//go:generate stringer -linecomment -type ObjectAnimationMode -output object_animation_mode_string.go
//go:generate string2enum -samepkg -linecomment -type ObjectAnimationMode -output object_animation_mode_string2enum.go
// ObjectAnimationMode represents object animation modes
type ObjectAnimationMode int
// Object animation modes
const (
ObjectAnimationModeNeutral ObjectAnimationMode = iota // NU
ObjectAnimationModeOperating // OP
ObjectAnimationModeOpened // ON
ObjectAnimationModeSpecial1 // S1
ObjectAnimationModeSpecial2 // S2
ObjectAnimationModeSpecial3 // S3
ObjectAnimationModeSpecial4 // S4
ObjectAnimationModeSpecial5 // S5
)

View File

@ -1,4 +1,4 @@
// Code generated by "stringer -linecomment -type ObjectAnimationMode"; DO NOT EDIT.
// Code generated by "stringer -linecomment -type ObjectAnimationMode -output object_animation_mode_string.go"; DO NOT EDIT.
package d2enum
@ -8,14 +8,14 @@ func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[AnimationModeObjectNeutral-0]
_ = x[AnimationModeObjectOperating-1]
_ = x[AnimationModeObjectOpened-2]
_ = x[AnimationModeObjectSpecial1-3]
_ = x[AnimationModeObjectSpecial2-4]
_ = x[AnimationModeObjectSpecial3-5]
_ = x[AnimationModeObjectSpecial4-6]
_ = x[AnimationModeObjectSpecial5-7]
_ = x[ObjectAnimationModeNeutral-0]
_ = x[ObjectAnimationModeOperating-1]
_ = x[ObjectAnimationModeOpened-2]
_ = x[ObjectAnimationModeSpecial1-3]
_ = x[ObjectAnimationModeSpecial2-4]
_ = x[ObjectAnimationModeSpecial3-5]
_ = x[ObjectAnimationModeSpecial4-6]
_ = x[ObjectAnimationModeSpecial5-7]
}
const _ObjectAnimationMode_name = "NUOPONS1S2S3S4S5"

View File

@ -1,4 +1,4 @@
// Code generated by "string2enum -samepkg -linecomment -type ObjectAnimationMode"; DO NOT EDIT.
// Code generated by "string2enum -samepkg -linecomment -type ObjectAnimationMode -output object_animation_mode_string2enum.go"; DO NOT EDIT.
package d2enum

View File

@ -3,6 +3,7 @@ package d2enum
// ObjectType is the type of an object
type ObjectType int
// Object types
const (
ObjectTypePlayer ObjectType = iota
ObjectTypeCharacter

View File

@ -0,0 +1,30 @@
package d2enum
//go:generate stringer -linecomment -type PlayerAnimationMode -output player_animation_mode_string.go
// PlayerAnimationMode represents player animation modes
type PlayerAnimationMode int
// Player animation modes
const (
PlayerAnimationModeDeath PlayerAnimationMode = iota // DT
PlayerAnimationModeNeutral // NU
PlayerAnimationModeWalk // WL
PlayerAnimationModeRun // RN
PlayerAnimationModeGetHit // GH
PlayerAnimationModeTownNeutral // TN
PlayerAnimationModeTownWalk // TW
PlayerAnimationModeAttack1 // A1
PlayerAnimationModeAttack2 // A2
PlayerAnimationModeBlock // BL
PlayerAnimationModeCast // SC
PlayerAnimationModeThrow // TH
PlayerAnimationModeKick // KK
PlayerAnimationModeSkill1 // S1
PlayerAnimationModeSkill2 // S2
PlayerAnimationModeSkill3 // S3
PlayerAnimationModeSkill4 // S4
PlayerAnimationModeDead // DD
PlayerAnimationModeSequence // GH
PlayerAnimationModeKnockBack // GH
)

View File

@ -0,0 +1,42 @@
// Code generated by "stringer -linecomment -type PlayerAnimationMode -output player_animation_mode_string.go"; DO NOT EDIT.
package d2enum
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[PlayerAnimationModeDeath-0]
_ = x[PlayerAnimationModeNeutral-1]
_ = x[PlayerAnimationModeWalk-2]
_ = x[PlayerAnimationModeRun-3]
_ = x[PlayerAnimationModeGetHit-4]
_ = x[PlayerAnimationModeTownNeutral-5]
_ = x[PlayerAnimationModeTownWalk-6]
_ = x[PlayerAnimationModeAttack1-7]
_ = x[PlayerAnimationModeAttack2-8]
_ = x[PlayerAnimationModeBlock-9]
_ = x[PlayerAnimationModeCast-10]
_ = x[PlayerAnimationModeThrow-11]
_ = x[PlayerAnimationModeKick-12]
_ = x[PlayerAnimationModeSkill1-13]
_ = x[PlayerAnimationModeSkill2-14]
_ = x[PlayerAnimationModeSkill3-15]
_ = x[PlayerAnimationModeSkill4-16]
_ = x[PlayerAnimationModeDead-17]
_ = x[PlayerAnimationModeSequence-18]
_ = x[PlayerAnimationModeKnockBack-19]
}
const _PlayerAnimationMode_name = "DTNUWLRNGHTNTWA1A2BLSCTHKKS1S2S3S4DDGHGH"
var _PlayerAnimationMode_index = [...]uint8{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40}
func (i PlayerAnimationMode) String() string {
if i < 0 || i >= PlayerAnimationMode(len(_PlayerAnimationMode_index)-1) {
return "PlayerAnimationMode(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _PlayerAnimationMode_name[_PlayerAnimationMode_index[i]:_PlayerAnimationMode_index[i+1]]
}

View File

@ -1,42 +0,0 @@
// Code generated by "stringer -linecomment -type PlayerAnimationMode"; DO NOT EDIT.
package d2enum
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[AnimationModePlayerDeath-0]
_ = x[AnimationModePlayerNeutral-1]
_ = x[AnimationModePlayerWalk-2]
_ = x[AnimationModePlayerRun-3]
_ = x[AnimationModePlayerGetHit-4]
_ = x[AnimationModePlayerTownNeutral-5]
_ = x[AnimationModePlayerTownWalk-6]
_ = x[AnimationModePlayerAttack1-7]
_ = x[AnimationModePlayerAttack2-8]
_ = x[AnimationModePlayerBlock-9]
_ = x[AnimationModePlayerCast-10]
_ = x[AnimationModePlayerThrow-11]
_ = x[AnimationModePlayerKick-12]
_ = x[AnimationModePlayerSkill1-13]
_ = x[AnimationModePlayerSkill2-14]
_ = x[AnimationModePlayerSkill3-15]
_ = x[AnimationModePlayerSkill4-16]
_ = x[AnimationModePlayerDead-17]
_ = x[AnimationModePlayerSequence-18]
_ = x[AnimationModePlayerKnockBack-19]
}
const _PlayerAnimationMode_name = "DTNUWLRNGHTNTWA1A2BLSCTHKKS1S2S3S4DDGHGH"
var _PlayerAnimationMode_index = [...]uint8{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40}
func (i PlayerAnimationMode) String() string {
if i < 0 || i >= PlayerAnimationMode(len(_PlayerAnimationMode_index)-1) {
return "PlayerAnimationMode(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _PlayerAnimationMode_name[_PlayerAnimationMode_index[i]:_PlayerAnimationMode_index[i+1]]
}

View File

@ -1,42 +1,44 @@
package d2enum
type RegionIdType int
// RegionIdType represents a region Id
type RegionIdType int //nolint:golint,stylecheck // many changed needed when changing to ID
// Regions
const (
RegionNone RegionIdType = 0
RegionAct1Town RegionIdType = 1
RegionAct1Wilderness RegionIdType = 2
RegionAct1Cave RegionIdType = 3
RegionAct1Crypt RegionIdType = 4
RegionAct1Monestary RegionIdType = 5
RegionAct1Courtyard RegionIdType = 6
RegionAct1Barracks RegionIdType = 7
RegionAct1Jail RegionIdType = 8
RegionAct1Cathedral RegionIdType = 9
RegionAct1Catacombs RegionIdType = 10
RegionAct1Tristram RegionIdType = 11
RegionAct2Town RegionIdType = 12
RegionAct2Sewer RegionIdType = 13
RegionAct2Harem RegionIdType = 14
RegionAct2Basement RegionIdType = 15
RegionAct2Desert RegionIdType = 16
RegionAct2Tomb RegionIdType = 17
RegionAct2Lair RegionIdType = 18
RegionAct2Arcane RegionIdType = 19
RegionAct3Town RegionIdType = 20
RegionAct3Jungle RegionIdType = 21
RegionAct3Kurast RegionIdType = 22
RegionAct3Spider RegionIdType = 23
RegionAct3Dungeon RegionIdType = 24
RegionAct3Sewer RegionIdType = 25
RegionAct4Town RegionIdType = 26
RegionAct4Mesa RegionIdType = 27
RegionAct4Lava RegionIdType = 28
RegonAct5Town RegionIdType = 29
RegionAct5Siege RegionIdType = 30
RegionAct5Barricade RegionIdType = 31
RegionAct5Temple RegionIdType = 32
RegionAct5IceCaves RegionIdType = 33
RegionAct5Baal RegionIdType = 34
RegionAct5Lava RegionIdType = 35
RegionNone RegionIdType = iota
RegionAct1Town
RegionAct1Wilderness
RegionAct1Cave
RegionAct1Crypt
RegionAct1Monestary
RegionAct1Courtyard
RegionAct1Barracks
RegionAct1Jail
RegionAct1Cathedral
RegionAct1Catacombs
RegionAct1Tristram
RegionAct2Town
RegionAct2Sewer
RegionAct2Harem
RegionAct2Basement
RegionAct2Desert
RegionAct2Tomb
RegionAct2Lair
RegionAct2Arcane
RegionAct3Town
RegionAct3Jungle
RegionAct3Kurast
RegionAct3Spider
RegionAct3Dungeon
RegionAct3Sewer
RegionAct4Town
RegionAct4Mesa
RegionAct4Lava
RegonAct5Town
RegionAct5Siege
RegionAct5Barricade
RegionAct5Temple
RegionAct5IceCaves
RegionAct5Baal
RegionAct5Lava
)

View File

@ -1,9 +1,11 @@
package d2enum
// RegionLayerType represents a region layer
type RegionLayerType int
// Region layer types
const (
RegionLayerTypeFloors RegionLayerType = 0
RegionLayerTypeWalls RegionLayerType = 1
RegionLayerTypeShadows RegionLayerType = 2
RegionLayerTypeFloors RegionLayerType = iota
RegionLayerTypeWalls
RegionLayerTypeShadows
)

View File

@ -3,7 +3,7 @@ package d2enum
// RenderType defines the type of rendering engine to use
type RenderType int
// Render types
const (
// Ebiten is the render type of ebiten
Ebiten = RenderType(1)
Ebiten RenderType = iota + 1
)

71
d2common/d2enum/tile.go Normal file
View File

@ -0,0 +1,71 @@
package d2enum
// TileType represents a tile type
type TileType byte
// Tile types
const (
TileFloor TileType = iota
TileLeftWall
TileRightWall
TileRightPartOfNorthCornerWall
TileLeftPartOfNorthCornerWall
TileLeftEndWall
TileRightEndWall
TileSouthCornerWall
TileLeftWallWithDoor
TileRightWallWithDoor
TileSpecialTile1
TileSpecialTile2
TilePillarsColumnsAndStandaloneObjects
TileShadow
TileTree
TileRoof
TileLowerWallsEquivalentToLeftWall
TileLowerWallsEquivalentToRightWall
TileLowerWallsEquivalentToRightLeftNorthCornerWall
TileLowerWallsEquivalentToSouthCornerwall
)
// LowerWall checks for lower wall tiles
func (tile TileType) LowerWall() bool {
switch tile {
case TileLowerWallsEquivalentToLeftWall,
TileLowerWallsEquivalentToRightWall,
TileLowerWallsEquivalentToRightLeftNorthCornerWall,
TileLowerWallsEquivalentToSouthCornerwall:
return true
}
return false
}
// UpperWall checks for upper wall tiles
func (tile TileType) UpperWall() bool {
switch tile {
case TileLeftWall,
TileRightWall,
TileRightPartOfNorthCornerWall,
TileLeftPartOfNorthCornerWall,
TileLeftEndWall,
TileRightEndWall,
TileSouthCornerWall,
TileLeftWallWithDoor,
TileRightWallWithDoor,
TilePillarsColumnsAndStandaloneObjects,
TileTree:
return true
}
return false
}
// Special checks for special tiles
func (tile TileType) Special() bool {
switch tile {
case TileSpecialTile1, TileSpecialTile2:
return true
}
return false
}

View File

@ -1,53 +0,0 @@
package d2enum
type TileType byte
const (
Floor TileType = 0
LeftWall TileType = 1
RightWall TileType = 2
RightPartOfNorthCornerWall TileType = 3
LeftPartOfNorthCornerWall TileType = 4
LeftEndWall TileType = 5
RightEndWall TileType = 6
SouthCornerWall TileType = 7
LeftWallWithDoor TileType = 8
RightWallWithDoor TileType = 9
SpecialTile1 TileType = 10
SpecialTile2 TileType = 11
PillarsColumnsAndStandaloneObjects TileType = 12
Shadow TileType = 13
Tree TileType = 14
Roof TileType = 15
LowerWallsEquivalentToLeftWall TileType = 16
LowerWallsEquivalentToRightWall TileType = 17
LowerWallsEquivalentToRightLeftNorthCornerWall TileType = 18
LowerWallsEquivalentToSouthCornerwall TileType = 19
)
func (tile TileType) LowerWall() bool {
switch tile {
case 16, 17, 18, 19:
return true
default:
return false
}
}
func (tile TileType) UpperWall() bool {
switch tile {
case 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 14:
return true
default:
return false
}
}
func (tile TileType) Special() bool {
switch tile {
case 10, 11:
return true
default:
return false
}
}

View File

@ -1,24 +1,26 @@
package d2enum
//go:generate stringer -linecomment -type WeaponClass -output weapon_class_string.go
//go:generate string2enum -samepkg -linecomment -type WeaponClass -output weapon_class_string2enum.go
// WeaponClass represents a weapon class
type WeaponClass int
// Weapon classes
const (
WeaponClassNone WeaponClass = 0 //
WeaponClassHandToHand WeaponClass = 1 // hth
WeaponClassBow WeaponClass = 2 // bow
WeaponClassOneHandSwing WeaponClass = 3 // 1hs
WeaponClassOneHandThrust WeaponClass = 4 // 1ht
WeaponClassStaff WeaponClass = 5 // stf
WeaponClassTwoHandSwing WeaponClass = 6 // 2hs
WeaponClassTwoHandThrust WeaponClass = 7 // 2ht
WeaponClassCrossbow WeaponClass = 8 // xbw
WeaponClassLeftJabRightSwing WeaponClass = 9 // 1js
WeaponClassLeftJabRightThrust WeaponClass = 10 // 1jt
WeaponClassLeftSwingRightSwing WeaponClass = 11 // 1ss
WeaponClassLeftSwingRightThrust WeaponClass = 12 // 1st
WeaponClassOneHandToHand WeaponClass = 13 // ht1
WeaponClassTwoHandToHand WeaponClass = 14 // ht2
WeaponClassNone WeaponClass = iota //
WeaponClassHandToHand // hth
WeaponClassBow // bow
WeaponClassOneHandSwing // 1hs
WeaponClassOneHandThrust // 1ht
WeaponClassStaff // stf
WeaponClassTwoHandSwing // 2hs
WeaponClassTwoHandThrust // 2ht
WeaponClassCrossbow // xbw
WeaponClassLeftJabRightSwing // 1js
WeaponClassLeftJabRightThrust // 1jt
WeaponClassLeftSwingRightSwing // 1ss
WeaponClassLeftSwingRightThrust // 1st
WeaponClassOneHandToHand // ht1
WeaponClassTwoHandToHand // ht2
)
//go:generate stringer -linecomment -type WeaponClass
//go:generate string2enum -samepkg -linecomment -type WeaponClass

View File

@ -1,4 +1,4 @@
// Code generated by "stringer -linecomment -type WeaponClass"; DO NOT EDIT.
// Code generated by "stringer -linecomment -type WeaponClass -output weapon_class_string.go"; DO NOT EDIT.
package d2enum

View File

@ -1,4 +1,4 @@
// Code generated by "string2enum -samepkg -linecomment -type WeaponClass"; DO NOT EDIT.
// Code generated by "string2enum -samepkg -linecomment -type WeaponClass -output weapon_class_string2enum.go"; DO NOT EDIT.
package d2enum
@ -16,3 +16,39 @@ func WeaponClassFromString(s string) WeaponClass {
}
panic(fmt.Errorf("unable to locate WeaponClass enum corresponding to %q", s))
}
func _(s string) {
// Check for duplicate string values in type "WeaponClass".
switch s {
// 0
case "":
// 1
case "hth":
// 2
case "bow":
// 3
case "1hs":
// 4
case "1ht":
// 5
case "stf":
// 6
case "2hs":
// 7
case "2ht":
// 8
case "xbw":
// 9
case "1js":
// 10
case "1jt":
// 11
case "1ss":
// 12
case "1st":
// 13
case "ht1":
// 14
case "ht2":
}
}

View File

@ -71,9 +71,14 @@ func (c *Composite) Render(target d2interface.Surface) error {
return nil
}
// ObjectAnimationMode returns the object animation mode
func (c *Composite) ObjectAnimationMode() d2enum.ObjectAnimationMode {
return c.mode.animationMode.(d2enum.ObjectAnimationMode)
}
// GetAnimationMode returns the animation mode the Composite should render with.
func (c *Composite) GetAnimationMode() string {
return c.mode.animationMode
return c.mode.animationMode.String()
}
// GetWeaponClass returns the currently loaded weapon class
@ -82,8 +87,8 @@ func (c *Composite) GetWeaponClass() string {
}
// SetMode sets the Composite's animation mode weapon class and direction
func (c *Composite) SetMode(animationMode, weaponClass string) error {
if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass {
func (c *Composite) SetMode(animationMode animationMode, weaponClass string) error {
if c.mode != nil && c.mode.animationMode.String() == animationMode.String() && c.mode.weaponClass == weaponClass {
return nil
}
@ -188,10 +193,13 @@ func (c *Composite) resetPlayedCount() {
}
}
type animationMode interface {
String() string
}
type compositeMode struct {
cof *d2cof.COF
animationMode string
animationMode animationMode
weaponClass string
playedCount int
@ -203,7 +211,7 @@ type compositeMode struct {
lastFrameTime float64
}
func (c *Composite) createMode(animationMode, weaponClass string) (*compositeMode, error) {
func (c *Composite) createMode(animationMode animationMode, weaponClass string) (*compositeMode, error) {
cofPath := fmt.Sprintf("%s/%s/COF/%s%s%s.COF", c.basePath, c.token, c.token, animationMode, weaponClass)
if exists, _ := FileExists(cofPath); !exists {
return nil, errors.New("composite not found")
@ -214,7 +222,7 @@ func (c *Composite) createMode(animationMode, weaponClass string) (*compositeMod
return nil, err
}
animationKey := strings.ToLower(c.token + animationMode + weaponClass)
animationKey := strings.ToLower(c.token + animationMode.String() + weaponClass)
animationData := d2data.AnimationData[animationKey]
if len(animationData) == 0 {
@ -242,7 +250,7 @@ func (c *Composite) createMode(animationMode, weaponClass string) (*compositeMod
drawEffect = cofLayer.DrawEffect
}
layer, err := c.loadCompositeLayer(cofLayer.Type.String(), layerValue, animationMode,
layer, err := c.loadCompositeLayer(cofLayer.Type.String(), layerValue, animationMode.String(),
cofLayer.WeaponClass.String(), c.palettePath, drawEffect)
if err == nil {
layer.SetPlaySpeed(mode.animationSpeed)

View File

@ -19,7 +19,7 @@ func (m *MapEngine) RegenerateWalkPaths() {
isBlocked := false
for _, floor := range tile.Floors {
tileData := m.GetTileData(int32(floor.Style), int32(floor.Sequence), d2enum.Floor)
tileData := m.GetTileData(int32(floor.Style), int32(floor.Sequence), d2enum.TileFloor)
if tileData == nil {
continue
}

View File

@ -47,7 +47,7 @@ func CreateNPC(x, y int, monstat *d2datadict.MonStatsRecord, direction int) *NPC
d2resource.PaletteUnits)
result.composite = composite
composite.SetMode("NU", result.monstatEx.BaseWeaponClass)
composite.SetMode(d2enum.MonsterAnimationModeNeutral, result.monstatEx.BaseWeaponClass)
composite.Equip(&equipment)
result.SetSpeed(float64(monstat.SpeedBase))
@ -133,24 +133,24 @@ func (v *NPC) wait() bool {
func (v *NPC) next() {
v.isDone = true
v.repetitions = 3 + rand.Intn(5)
newAnimationMode := d2enum.AnimationModeMonsterNeutral
newAnimationMode := d2enum.MonsterAnimationModeNeutral
// TODO: Figure out what 1-3 are for, 4 is correct.
switch v.action {
case 1:
newAnimationMode = d2enum.AnimationModeMonsterNeutral
newAnimationMode = d2enum.MonsterAnimationModeNeutral
case 2:
newAnimationMode = d2enum.AnimationModeMonsterNeutral
newAnimationMode = d2enum.MonsterAnimationModeNeutral
case 3:
newAnimationMode = d2enum.AnimationModeMonsterNeutral
newAnimationMode = d2enum.MonsterAnimationModeNeutral
case 4:
newAnimationMode = d2enum.AnimationModeMonsterSkill1
newAnimationMode = d2enum.MonsterAnimationModeSkill1
v.repetitions = 0
default:
v.repetitions = 0
}
if v.composite.GetAnimationMode() != newAnimationMode.String() {
v.composite.SetMode(newAnimationMode.String(), v.composite.GetWeaponClass())
v.composite.SetMode(newAnimationMode, v.composite.GetWeaponClass())
}
}
@ -158,13 +158,13 @@ func (v *NPC) next() {
func (v *NPC) rotate(direction int) {
var newMode d2enum.MonsterAnimationMode
if !v.IsAtTarget() {
newMode = d2enum.AnimationModeMonsterWalk
newMode = d2enum.MonsterAnimationModeWalk
} else {
newMode = d2enum.AnimationModeMonsterNeutral
newMode = d2enum.MonsterAnimationModeNeutral
}
if newMode.String() != v.composite.GetAnimationMode() {
v.composite.SetMode(newMode.String(), v.composite.GetWeaponClass())
v.composite.SetMode(newMode, v.composite.GetWeaponClass())
}
if v.composite.GetDirection() != direction {

View File

@ -73,8 +73,7 @@ func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero
//result.nameLabel.Alignment = d2ui.LabelAlignCenter
//result.nameLabel.SetText(name)
//result.nameLabel.Color = color.White
err = composite.SetMode(d2enum.AnimationModePlayerTownNeutral.String(), equipment.RightHand.GetWeaponClass())
err = composite.SetMode(d2enum.PlayerAnimationModeTownNeutral, equipment.RightHand.GetWeaponClass())
if err != nil {
panic(err)
}
@ -130,7 +129,7 @@ func (v *Player) Advance(tickTime float64) {
if v.IsCasting() && v.composite.GetPlayedCount() >= 1 {
v.isCasting = false
v.SetAnimationMode(v.GetAnimationMode().String())
v.SetAnimationMode(v.GetAnimationMode())
}
v.composite.Advance(tickTime)
@ -159,38 +158,37 @@ func (v *Player) Render(target d2interface.Surface) {
// GetAnimationMode returns the current animation mode based on what the player is doing and where they are.
func (v *Player) GetAnimationMode() d2enum.PlayerAnimationMode {
if v.IsRunning() && !v.IsAtTarget() {
return d2enum.AnimationModePlayerRun
return d2enum.PlayerAnimationModeRun
}
if v.IsInTown() {
if !v.IsAtTarget() {
return d2enum.AnimationModePlayerTownWalk
return d2enum.PlayerAnimationModeTownWalk
}
return d2enum.AnimationModePlayerTownNeutral
return d2enum.PlayerAnimationModeTownNeutral
}
if !v.IsAtTarget() {
return d2enum.AnimationModePlayerWalk
return d2enum.PlayerAnimationModeWalk
}
if v.IsCasting() {
return d2enum.AnimationModePlayerCast
return d2enum.PlayerAnimationModeCast
}
return d2enum.AnimationModePlayerNeutral
return d2enum.PlayerAnimationModeNeutral
}
// SetAnimationMode sets the animation mode for this entity's animated composite.
func (v *Player) SetAnimationMode(animationMode string) error {
func (v *Player) SetAnimationMode(animationMode d2enum.PlayerAnimationMode) error {
return v.composite.SetMode(animationMode, v.composite.GetWeaponClass())
}
// rotate sets direction and changes animation
func (v *Player) rotate(direction int) {
newAnimationMode := v.GetAnimationMode().String()
newAnimationMode := v.GetAnimationMode()
if newAnimationMode != v.composite.GetAnimationMode() {
if newAnimationMode.String() != v.composite.GetAnimationMode() {
v.composite.SetMode(newAnimationMode, v.composite.GetWeaponClass())
}
@ -213,7 +211,7 @@ func (v *Player) IsCasting() bool {
// sets the animation mode to the casting animation.
func (v *Player) SetCasting() {
v.isCasting = true
v.SetAnimationMode(d2enum.AnimationModePlayerCast.String())
v.SetAnimationMode(d2enum.PlayerAnimationModeCast)
}
// Selectable returns true if the player is in town.

View File

@ -229,7 +229,7 @@ func (mr *MapRenderer) renderTilePass2(tile *d2ds1.TileRecord, target d2interfac
func (mr *MapRenderer) renderTilePass3(tile *d2ds1.TileRecord, target d2interface.Surface) {
for _, wall := range tile.Walls {
if wall.Type == d2enum.Roof {
if wall.Type == d2enum.TileRoof {
mr.renderWall(wall, mr.viewport, target)
}
}

View File

@ -27,15 +27,15 @@ func initObject(ob *Object) bool {
// Initializes torch/brazier type objects
func initTorch(ob *Object) {
if ob.objectRecord.HasAnimationMode[d2enum.AnimationModeObjectOperating] {
ob.setMode("ON", 0, true)
if ob.objectRecord.HasAnimationMode[d2enum.ObjectAnimationModeOpened] {
ob.setMode(d2enum.ObjectAnimationModeOpened, 0, true)
}
}
func initWaypoint(ob *Object) {
// Turn these on unconditionally for now, they look nice :)
if ob.objectRecord.HasAnimationMode[d2enum.AnimationModeObjectOperating] {
ob.setMode("ON", 0, true)
if ob.objectRecord.HasAnimationMode[d2enum.ObjectAnimationModeOpened] {
ob.setMode(d2enum.ObjectAnimationModeOpened, 0, true)
}
}
@ -44,8 +44,8 @@ func initTorchRnd(ob *Object) {
n := rand.Intn(2)
if n > 0 {
ob.setMode("NU", 0, true)
ob.setMode(d2enum.ObjectAnimationModeNeutral, 0, true)
} else {
ob.setMode("OP", 0, true)
ob.setMode(d2enum.ObjectAnimationModeOperating, 0, true)
}
}

View File

@ -50,7 +50,7 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
entity.composite = composite
entity.setMode("NU", 0, false)
entity.setMode(d2enum.ObjectAnimationModeNeutral, 0, false)
initObject(entity)
@ -58,7 +58,7 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
}
// setMode changes the graphical mode of this animated entity
func (ob *Object) setMode(animationMode string, direction int, randomFrame bool) error {
func (ob *Object) setMode(animationMode d2enum.ObjectAnimationMode, direction int, randomFrame bool) error {
err := ob.composite.SetMode(animationMode, "HTH")
if err != nil {
return err
@ -66,23 +66,23 @@ func (ob *Object) setMode(animationMode string, direction int, randomFrame bool)
ob.composite.SetDirection(direction)
mode := d2enum.ObjectAnimationModeFromString(animationMode)
ob.drawLayer = ob.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
// mode := d2enum.ObjectAnimationModeFromString(animationMode)
ob.drawLayer = ob.objectRecord.OrderFlag[d2enum.ObjectAnimationModeNeutral]
// For objects their txt record entry overrides animationdata
speed := ob.objectRecord.FrameDelta[mode]
speed := ob.objectRecord.FrameDelta[animationMode]
if speed != 0 {
ob.composite.SetAnimSpeed(speed)
}
frameCount := ob.objectRecord.FrameCount[mode]
frameCount := ob.objectRecord.FrameCount[animationMode]
if frameCount != 0 {
ob.composite.SetSubLoop(0, frameCount)
}
ob.composite.SetPlayLoop(ob.objectRecord.CycleAnimation[mode])
ob.composite.SetCurrentFrame(ob.objectRecord.StartFrame[mode])
ob.composite.SetPlayLoop(ob.objectRecord.CycleAnimation[animationMode])
ob.composite.SetCurrentFrame(ob.objectRecord.StartFrame[animationMode])
if randomFrame {
n := rand.Intn(frameCount)
@ -98,7 +98,7 @@ func (ob *Object) Highlight() {
}
func (ob *Object) Selectable() bool {
mode := d2enum.ObjectAnimationModeFromString(ob.composite.GetAnimationMode())
mode := ob.composite.ObjectAnimationMode()
return ob.objectRecord.Selectable[mode]
}

View File

@ -114,7 +114,7 @@ func (g *GameClient) OnPacketReceived(packet d2netpacket.NetPacket) error {
} else {
player.SetIsInTown(false)
}
err := player.SetAnimationMode(player.GetAnimationMode().String())
err := player.SetAnimationMode(player.GetAnimationMode())
if err != nil {
log.Printf("GameClient: error setting animation mode for player %s: %s", player.Id, err)
}