mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-18 02:16:23 -05:00
Composite work (#536)
* Quit using ObjectLookupRecord in composite * Unexport SetMode in map entities * Get rid of weaponClass from MapEntity * Pass ObjectType to composite instead of string * Use layer weaponclass from cof * Manage more stuff directly in composite * Explicitly index when picking equipment
This commit is contained in:
parent
4c3ff12cba
commit
6269726316
@ -4,6 +4,7 @@ package d2enum
|
|||||||
type ObjectType int
|
type ObjectType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ObjectTypeCharacter ObjectType = iota + 1
|
ObjectTypePlayer ObjectType = iota
|
||||||
|
ObjectTypeCharacter
|
||||||
ObjectTypeItem
|
ObjectTypeItem
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
@ -14,14 +13,19 @@ import (
|
|||||||
|
|
||||||
// Composite is a composite entity animation
|
// Composite is a composite entity animation
|
||||||
type Composite struct {
|
type Composite struct {
|
||||||
object *d2datadict.ObjectLookupRecord
|
baseType d2enum.ObjectType
|
||||||
|
basePath string
|
||||||
|
token string
|
||||||
palettePath string
|
palettePath string
|
||||||
|
direction int
|
||||||
|
equipment [d2enum.CompositeTypeMax]string
|
||||||
mode *compositeMode
|
mode *compositeMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateComposite creates a Composite from a given ObjectLookupRecord and palettePath.
|
// CreateComposite creates a Composite from a given ObjectLookupRecord and palettePath.
|
||||||
func CreateComposite(object *d2datadict.ObjectLookupRecord, palettePath string) *Composite {
|
func CreateComposite(baseType d2enum.ObjectType, token, palettePath string) *Composite {
|
||||||
return &Composite{object: object, palettePath: palettePath}
|
return &Composite{baseType: baseType, basePath: baseString(baseType),
|
||||||
|
token: token, palettePath: palettePath}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance moves the composite animation forward for a given elapsed time in nanoseconds.
|
// Advance moves the composite animation forward for a given elapsed time in nanoseconds.
|
||||||
@ -54,7 +58,8 @@ func (c *Composite) Render(target d2interface.Surface) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, layerIndex := range c.mode.drawOrder[c.mode.frameIndex] {
|
direction := d2cof.Dir64ToCof(c.direction, c.mode.cof.NumberOfDirections)
|
||||||
|
for _, layerIndex := range c.mode.cof.Priority[direction][c.mode.frameIndex] {
|
||||||
layer := c.mode.layers[layerIndex]
|
layer := c.mode.layers[layerIndex]
|
||||||
if layer != nil {
|
if layer != nil {
|
||||||
if err := layer.RenderFromOrigin(target); err != nil {
|
if err := layer.RenderFromOrigin(target); err != nil {
|
||||||
@ -67,17 +72,22 @@ func (c *Composite) Render(target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAnimationMode returns the animation mode the Composite should render with.
|
// GetAnimationMode returns the animation mode the Composite should render with.
|
||||||
func (c Composite) GetAnimationMode() string {
|
func (c *Composite) GetAnimationMode() string {
|
||||||
return c.mode.animationMode
|
return c.mode.animationMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWeaponClass returns the currently loaded weapon class
|
||||||
|
func (c *Composite) GetWeaponClass() string {
|
||||||
|
return c.mode.weaponClass
|
||||||
|
}
|
||||||
|
|
||||||
// SetMode sets the Composite's animation mode weapon class and direction
|
// SetMode sets the Composite's animation mode weapon class and direction
|
||||||
func (c *Composite) SetMode(animationMode, weaponClass string, direction int) error {
|
func (c *Composite) SetMode(animationMode, weaponClass string) error {
|
||||||
if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass && c.mode.cofDirection == direction {
|
if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, err := c.createMode(animationMode, weaponClass, direction)
|
mode, err := c.createMode(animationMode, weaponClass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -88,8 +98,26 @@ func (c *Composite) SetMode(animationMode, weaponClass string, direction int) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSpeed sets the speed at which the Composite's animation should advance through its frames
|
// Equip changes the current layer configuration
|
||||||
func (c *Composite) SetSpeed(speed int) {
|
func (c *Composite) Equip(equipment *[d2enum.CompositeTypeMax]string) error {
|
||||||
|
c.equipment = *equipment
|
||||||
|
if c.mode == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, err := c.createMode(c.mode.animationMode, c.mode.weaponClass)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.mode = mode
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAnimSpeed sets the speed at which the Composite's animation should advance through its frames
|
||||||
|
func (c *Composite) SetAnimSpeed(speed int) {
|
||||||
c.mode.animationSpeed = 1.0 / ((float64(speed) * 25.0) / 256.0)
|
c.mode.animationSpeed = 1.0 / ((float64(speed) * 25.0) / 256.0)
|
||||||
for layerIdx := range c.mode.layers {
|
for layerIdx := range c.mode.layers {
|
||||||
layer := c.mode.layers[layerIdx]
|
layer := c.mode.layers[layerIdx]
|
||||||
@ -99,13 +127,20 @@ func (c *Composite) SetSpeed(speed int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDirectionCount returns the Composites number of available animated directions
|
// SetDirection sets the direction of the composite and its layers
|
||||||
func (c *Composite) GetDirectionCount() int {
|
func (c *Composite) SetDirection(direction int) {
|
||||||
if c.mode == nil {
|
c.direction = direction
|
||||||
return 0
|
for layerIdx := range c.mode.layers {
|
||||||
|
layer := c.mode.layers[layerIdx]
|
||||||
|
if layer != nil {
|
||||||
|
layer.SetDirection(c.direction)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return c.mode.directionCount
|
// Direction returns the current direction the composite is facing
|
||||||
|
func (c *Composite) GetDirection() int {
|
||||||
|
return c.direction
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPlayedCount returns the number of times the current animation mode has completed all its distinct frames
|
// GetPlayedCount returns the number of times the current animation mode has completed all its distinct frames
|
||||||
@ -124,14 +159,12 @@ func (c *Composite) resetPlayedCount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type compositeMode struct {
|
type compositeMode struct {
|
||||||
|
cof *d2cof.COF
|
||||||
animationMode string
|
animationMode string
|
||||||
weaponClass string
|
weaponClass string
|
||||||
cofDirection int
|
|
||||||
directionCount int
|
|
||||||
playedCount int
|
playedCount int
|
||||||
|
|
||||||
layers []*Animation
|
layers []*Animation
|
||||||
drawOrder [][]d2enum.CompositeType
|
|
||||||
|
|
||||||
frameCount int
|
frameCount int
|
||||||
frameIndex int
|
frameIndex int
|
||||||
@ -139,8 +172,8 @@ type compositeMode struct {
|
|||||||
lastFrameTime float64
|
lastFrameTime float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Composite) createMode(animationMode, weaponClass string, direction int) (*compositeMode, error) {
|
func (c *Composite) createMode(animationMode, weaponClass string) (*compositeMode, error) {
|
||||||
cofPath := fmt.Sprintf("%s/%s/COF/%s%s%s.COF", c.object.Base, c.object.Token, c.object.Token, animationMode, weaponClass)
|
cofPath := fmt.Sprintf("%s/%s/COF/%s%s%s.COF", c.basePath, c.token, c.token, animationMode, weaponClass)
|
||||||
if exists, _ := FileExists(cofPath); !exists {
|
if exists, _ := FileExists(cofPath); !exists {
|
||||||
return nil, errors.New("composite not found")
|
return nil, errors.New("composite not found")
|
||||||
}
|
}
|
||||||
@ -150,7 +183,7 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
animationKey := strings.ToLower(c.object.Token + animationMode + weaponClass)
|
animationKey := strings.ToLower(c.token + animationMode + weaponClass)
|
||||||
|
|
||||||
animationData := d2data.AnimationData[animationKey]
|
animationData := d2data.AnimationData[animationKey]
|
||||||
if len(animationData) == 0 {
|
if len(animationData) == 0 {
|
||||||
@ -158,62 +191,23 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mode := &compositeMode{
|
mode := &compositeMode{
|
||||||
|
cof: cof,
|
||||||
animationMode: animationMode,
|
animationMode: animationMode,
|
||||||
weaponClass: weaponClass,
|
weaponClass: weaponClass,
|
||||||
directionCount: cof.NumberOfDirections,
|
|
||||||
cofDirection: d2cof.Dir64ToCof(direction, cof.NumberOfDirections),
|
|
||||||
layers: make([]*Animation, d2enum.CompositeTypeMax),
|
layers: make([]*Animation, d2enum.CompositeTypeMax),
|
||||||
frameCount: animationData[0].FramesPerDirection,
|
frameCount: animationData[0].FramesPerDirection,
|
||||||
animationSpeed: 1.0 / ((float64(animationData[0].AnimationSpeed) * 25.0) / 256.0),
|
animationSpeed: 1.0 / ((float64(animationData[0].AnimationSpeed) * 25.0) / 256.0),
|
||||||
}
|
}
|
||||||
|
|
||||||
mode.drawOrder = make([][]d2enum.CompositeType, mode.frameCount)
|
|
||||||
for frame := 0; frame < mode.frameCount; frame++ {
|
|
||||||
mode.drawOrder[frame] = cof.Priority[mode.cofDirection][frame]
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, cofLayer := range cof.CofLayers {
|
for _, cofLayer := range cof.CofLayers {
|
||||||
var layerValue string
|
layerValue := c.equipment[cofLayer.Type]
|
||||||
|
if layerValue == "" {
|
||||||
switch cofLayer.Type {
|
layerValue = "lit"
|
||||||
case d2enum.CompositeTypeHead:
|
|
||||||
layerValue = c.object.HD
|
|
||||||
case d2enum.CompositeTypeTorso:
|
|
||||||
layerValue = c.object.TR
|
|
||||||
case d2enum.CompositeTypeLegs:
|
|
||||||
layerValue = c.object.LG
|
|
||||||
case d2enum.CompositeTypeRightArm:
|
|
||||||
layerValue = c.object.RA
|
|
||||||
case d2enum.CompositeTypeLeftArm:
|
|
||||||
layerValue = c.object.LA
|
|
||||||
case d2enum.CompositeTypeRightHand:
|
|
||||||
layerValue = c.object.RH
|
|
||||||
case d2enum.CompositeTypeLeftHand:
|
|
||||||
layerValue = c.object.LH
|
|
||||||
case d2enum.CompositeTypeShield:
|
|
||||||
layerValue = c.object.SH
|
|
||||||
case d2enum.CompositeTypeSpecial1:
|
|
||||||
layerValue = c.object.S1
|
|
||||||
case d2enum.CompositeTypeSpecial2:
|
|
||||||
layerValue = c.object.S2
|
|
||||||
case d2enum.CompositeTypeSpecial3:
|
|
||||||
layerValue = c.object.S3
|
|
||||||
case d2enum.CompositeTypeSpecial4:
|
|
||||||
layerValue = c.object.S4
|
|
||||||
case d2enum.CompositeTypeSpecial5:
|
|
||||||
layerValue = c.object.S5
|
|
||||||
case d2enum.CompositeTypeSpecial6:
|
|
||||||
layerValue = c.object.S6
|
|
||||||
case d2enum.CompositeTypeSpecial7:
|
|
||||||
layerValue = c.object.S7
|
|
||||||
case d2enum.CompositeTypeSpecial8:
|
|
||||||
layerValue = c.object.S8
|
|
||||||
default:
|
|
||||||
return nil, errors.New("unknown layer type")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blend := false
|
blend := false
|
||||||
transparency := 255
|
transparency := 255
|
||||||
|
|
||||||
if cofLayer.Transparent {
|
if cofLayer.Transparent {
|
||||||
switch cofLayer.DrawEffect {
|
switch cofLayer.DrawEffect {
|
||||||
case d2enum.DrawEffectPctTransparency25:
|
case d2enum.DrawEffectPctTransparency25:
|
||||||
@ -227,14 +221,17 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layer, err := loadCompositeLayer(c.object, cofLayer.Type.String(), layerValue, animationMode, weaponClass, c.palettePath, transparency)
|
layer, err := c.loadCompositeLayer(cofLayer.Type.String(), layerValue, animationMode,
|
||||||
|
cofLayer.WeaponClass.String(), c.palettePath, transparency)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
layer.SetPlaySpeed(mode.animationSpeed)
|
layer.SetPlaySpeed(mode.animationSpeed)
|
||||||
layer.PlayForward()
|
layer.PlayForward()
|
||||||
layer.SetBlend(blend)
|
layer.SetBlend(blend)
|
||||||
if err := layer.SetDirection(direction); err != nil {
|
|
||||||
|
if err := layer.SetDirection(c.direction); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mode.layers[cofLayer.Type] = layer
|
mode.layers[cofLayer.Type] = layer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,12 +239,11 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
|
|||||||
return mode, nil
|
return mode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadCompositeLayer(object *d2datadict.ObjectLookupRecord, layerKey, layerValue, animationMode, weaponClass, palettePath string, transparency int) (*Animation, error) {
|
func (c *Composite) loadCompositeLayer(layerKey, layerValue, animationMode, weaponClass,
|
||||||
|
palettePath string, transparency int) (*Animation, error) {
|
||||||
animationPaths := []string{
|
animationPaths := []string{
|
||||||
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, weaponClass),
|
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", c.basePath, c.token, layerKey, c.token, layerKey, layerValue, animationMode, weaponClass),
|
||||||
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, "HTH"),
|
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dc6", c.basePath, c.token, layerKey, c.token, layerKey, layerValue, animationMode, weaponClass),
|
||||||
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dc6", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, weaponClass),
|
|
||||||
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dc6", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, "HTH"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, animationPath := range animationPaths {
|
for _, animationPath := range animationPaths {
|
||||||
@ -261,3 +257,16 @@ func loadCompositeLayer(object *d2datadict.ObjectLookupRecord, layerKey, layerVa
|
|||||||
|
|
||||||
return nil, errors.New("animation not found")
|
return nil, errors.New("animation not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func baseString(baseType d2enum.ObjectType) string {
|
||||||
|
switch baseType {
|
||||||
|
case d2enum.ObjectTypePlayer:
|
||||||
|
return "/data/global/chars"
|
||||||
|
case d2enum.ObjectTypeCharacter:
|
||||||
|
return "/data/global/monsters"
|
||||||
|
case d2enum.ObjectTypeItem:
|
||||||
|
return "/data/global/objects"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ package d2asset
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dat"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dat"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
@ -121,8 +121,8 @@ func LoadAnimationWithTransparency(animationPath, palettePath string, transparen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadComposite creates a composite object from a ObjectLookupRecord and palettePath describing it
|
// LoadComposite creates a composite object from a ObjectLookupRecord and palettePath describing it
|
||||||
func LoadComposite(object *d2datadict.ObjectLookupRecord, palettePath string) (*Composite, error) {
|
func LoadComposite(baseType d2enum.ObjectType, token, palettePath string) (*Composite, error) {
|
||||||
return CreateComposite(object, palettePath), nil
|
return CreateComposite(baseType, token, palettePath), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFont loads a font the resource files
|
// LoadFont loads a font the resource files
|
||||||
|
@ -26,7 +26,6 @@ type mapEntity struct {
|
|||||||
LocationY float64
|
LocationY float64
|
||||||
TileX, TileY int // Coordinates of the tile the unit is within
|
TileX, TileY int // Coordinates of the tile the unit is within
|
||||||
subcellX, subcellY float64 // Subcell coordinates within the current tile
|
subcellX, subcellY float64 // Subcell coordinates within the current tile
|
||||||
weaponClass string
|
|
||||||
offsetX, offsetY int
|
offsetX, offsetY int
|
||||||
TargetX float64
|
TargetX float64
|
||||||
TargetY float64
|
TargetY float64
|
||||||
|
@ -21,8 +21,6 @@ type NPC struct {
|
|||||||
path int
|
path int
|
||||||
isDone bool
|
isDone bool
|
||||||
repetitions int
|
repetitions int
|
||||||
direction int
|
|
||||||
objectLookup *d2datadict.ObjectLookupRecord
|
|
||||||
monstatRecord *d2datadict.MonStatsRecord
|
monstatRecord *d2datadict.MonStatsRecord
|
||||||
monstatEx *d2datadict.MonStats2Record
|
monstatEx *d2datadict.MonStats2Record
|
||||||
name string
|
name string
|
||||||
@ -36,29 +34,32 @@ func CreateNPC(x, y int, monstat *d2datadict.MonStatsRecord, direction int) *NPC
|
|||||||
monstatEx: d2datadict.MonStats2[monstat.ExtraDataKey],
|
monstatEx: d2datadict.MonStats2[monstat.ExtraDataKey],
|
||||||
}
|
}
|
||||||
|
|
||||||
object := &d2datadict.ObjectLookupRecord{
|
equipment := &[d2enum.CompositeTypeMax]string{
|
||||||
Base: "/Data/Global/Monsters",
|
d2enum.CompositeTypeHead: selectEquip(result.monstatEx.HDv),
|
||||||
Token: monstat.AnimationDirectoryToken,
|
d2enum.CompositeTypeTorso: selectEquip(result.monstatEx.TRv),
|
||||||
Mode: result.monstatEx.ResurrectMode.String(),
|
d2enum.CompositeTypeLegs: selectEquip(result.monstatEx.LGv),
|
||||||
Class: result.monstatEx.BaseWeaponClass,
|
d2enum.CompositeTypeRightArm: selectEquip(result.monstatEx.Rav),
|
||||||
TR: selectEquip(result.monstatEx.TRv),
|
d2enum.CompositeTypeLeftArm: selectEquip(result.monstatEx.Lav),
|
||||||
LG: selectEquip(result.monstatEx.LGv),
|
d2enum.CompositeTypeRightHand: selectEquip(result.monstatEx.RHv),
|
||||||
RH: selectEquip(result.monstatEx.RHv),
|
d2enum.CompositeTypeLeftHand: selectEquip(result.monstatEx.LHv),
|
||||||
SH: selectEquip(result.monstatEx.SHv),
|
d2enum.CompositeTypeShield: selectEquip(result.monstatEx.SHv),
|
||||||
RA: selectEquip(result.monstatEx.Rav),
|
d2enum.CompositeTypeSpecial1: selectEquip(result.monstatEx.S1v),
|
||||||
LA: selectEquip(result.monstatEx.Lav),
|
d2enum.CompositeTypeSpecial2: selectEquip(result.monstatEx.S2v),
|
||||||
LH: selectEquip(result.monstatEx.LHv),
|
d2enum.CompositeTypeSpecial3: selectEquip(result.monstatEx.S3v),
|
||||||
HD: selectEquip(result.monstatEx.HDv),
|
d2enum.CompositeTypeSpecial4: selectEquip(result.monstatEx.S4v),
|
||||||
|
d2enum.CompositeTypeSpecial5: selectEquip(result.monstatEx.S5v),
|
||||||
|
d2enum.CompositeTypeSpecial6: selectEquip(result.monstatEx.S6v),
|
||||||
|
d2enum.CompositeTypeSpecial7: selectEquip(result.monstatEx.S7v),
|
||||||
|
d2enum.CompositeTypeSpecial8: selectEquip(result.monstatEx.S8v),
|
||||||
}
|
}
|
||||||
result.objectLookup = object
|
|
||||||
composite, err := d2asset.LoadComposite(object, d2resource.PaletteUnits)
|
composite, _ := d2asset.LoadComposite(d2enum.ObjectTypeCharacter, monstat.AnimationDirectoryToken,
|
||||||
|
d2resource.PaletteUnits)
|
||||||
result.composite = composite
|
result.composite = composite
|
||||||
|
|
||||||
if err != nil {
|
composite.SetMode("NU", result.monstatEx.BaseWeaponClass)
|
||||||
panic(err)
|
composite.Equip(equipment)
|
||||||
}
|
|
||||||
|
|
||||||
result.SetMode(object.Mode, object.Class, direction)
|
|
||||||
result.mapEntity.directioner = result.rotate
|
result.mapEntity.directioner = result.rotate
|
||||||
|
|
||||||
if result.monstatRecord != nil && result.monstatRecord.IsInteractable {
|
if result.monstatRecord != nil && result.monstatRecord.IsInteractable {
|
||||||
@ -76,7 +77,6 @@ func selectEquip(slice []string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (v *NPC) Render(target d2interface.Surface) {
|
func (v *NPC) Render(target d2interface.Surface) {
|
||||||
target.PushTranslation(
|
target.PushTranslation(
|
||||||
v.offsetX+int((v.subcellX-v.subcellY)*16),
|
v.offsetX+int((v.subcellX-v.subcellY)*16),
|
||||||
@ -148,7 +148,7 @@ func (v *NPC) next() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v.composite.GetAnimationMode() != newAnimationMode.String() {
|
if v.composite.GetAnimationMode() != newAnimationMode.String() {
|
||||||
v.SetMode(newAnimationMode.String(), v.weaponClass, v.direction)
|
v.composite.SetMode(newAnimationMode.String(), v.composite.GetWeaponClass())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,23 +160,14 @@ func (v *NPC) rotate(direction int) {
|
|||||||
} else {
|
} else {
|
||||||
newMode = d2enum.AnimationModeMonsterNeutral
|
newMode = d2enum.AnimationModeMonsterNeutral
|
||||||
}
|
}
|
||||||
if newMode.String() != v.composite.GetAnimationMode() || direction != v.direction {
|
|
||||||
v.SetMode(newMode.String(), v.weaponClass, direction)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMode changes the graphical mode of this animated entity
|
if newMode.String() != v.composite.GetAnimationMode() {
|
||||||
func (v *NPC) SetMode(animationMode, weaponClass string, direction int) error {
|
v.composite.SetMode(newMode.String(), v.composite.GetWeaponClass())
|
||||||
v.direction = direction
|
|
||||||
v.weaponClass = weaponClass
|
|
||||||
|
|
||||||
err := v.composite.SetMode(animationMode, weaponClass, direction)
|
|
||||||
if err != nil {
|
|
||||||
err = v.composite.SetMode(animationMode, "HTH", direction)
|
|
||||||
v.weaponClass = "HTH"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
if v.composite.GetDirection() != direction {
|
||||||
|
v.composite.SetDirection(direction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NPC) Selectable() bool {
|
func (m *NPC) Selectable() bool {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,32 +29,8 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
|
|||||||
// nameLabel: d2ui.CreateLabel(renderer, d2resource.FontFormal11, d2resource.PaletteStatic),
|
// nameLabel: d2ui.CreateLabel(renderer, d2resource.FontFormal11, d2resource.PaletteStatic),
|
||||||
}
|
}
|
||||||
|
|
||||||
object := &d2datadict.ObjectLookupRecord{
|
composite, err := d2asset.LoadComposite(d2enum.ObjectTypeItem, entity.objectType.Token,
|
||||||
Base: "/Data/Global/Objects",
|
d2resource.PaletteUnits)
|
||||||
Token: entity.objectType.Token,
|
|
||||||
Mode: "NU",
|
|
||||||
Class: "HTH",
|
|
||||||
HD: "LIT",
|
|
||||||
TR: "LIT",
|
|
||||||
LG: "LIT",
|
|
||||||
RA: "LIT",
|
|
||||||
LA: "LIT",
|
|
||||||
RH: "LIT",
|
|
||||||
LH: "LIT",
|
|
||||||
SH: "LIT",
|
|
||||||
S1: "LIT",
|
|
||||||
S2: "LIT",
|
|
||||||
S3: "LIT",
|
|
||||||
S4: "LIT",
|
|
||||||
S5: "LIT",
|
|
||||||
S6: "LIT",
|
|
||||||
S7: "LIT",
|
|
||||||
S8: "LIT",
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.objectLookup = object
|
|
||||||
|
|
||||||
composite, err := d2asset.LoadComposite(object, palettePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -63,36 +40,35 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
|
|||||||
entity.mapEntity.directioner = entity.rotate
|
entity.mapEntity.directioner = entity.rotate
|
||||||
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
|
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
|
||||||
|
|
||||||
entity.SetMode(object.Mode, object.Class, 0)
|
entity.setMode("NU", 0)
|
||||||
|
|
||||||
// stop torches going crazy for now
|
// stop torches going crazy for now
|
||||||
// need initFunc handling to set objects up properly
|
// need initFunc handling to set objects up properly
|
||||||
if objectRec.HasAnimationMode[d2enum.AnimationModeObjectOpened] {
|
if objectRec.HasAnimationMode[d2enum.AnimationModeObjectOpened] {
|
||||||
entity.SetMode("ON", "HTH", 0)
|
entity.setMode("ON", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity, nil
|
return entity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMode changes the graphical mode of this animated entity
|
// setMode changes the graphical mode of this animated entity
|
||||||
func (ob *Object) SetMode(animationMode, weaponClass string, direction int) error {
|
func (ob *Object) setMode(animationMode string, direction int) error {
|
||||||
ob.composite.SetMode(animationMode, weaponClass, direction)
|
|
||||||
ob.direction = direction
|
ob.direction = direction
|
||||||
ob.weaponClass = weaponClass
|
|
||||||
|
|
||||||
err := ob.composite.SetMode(animationMode, weaponClass, direction)
|
err := ob.composite.SetMode(animationMode, "HTH")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = ob.composite.SetMode(animationMode, "HTH", direction)
|
return err
|
||||||
ob.weaponClass = "HTH"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ob.composite.SetDirection(direction)
|
||||||
|
|
||||||
mode := d2enum.ObjectAnimationModeFromString(animationMode)
|
mode := d2enum.ObjectAnimationModeFromString(animationMode)
|
||||||
ob.mapEntity.drawLayer = ob.objectRecord.OrderFlag[mode]
|
ob.mapEntity.drawLayer = ob.objectRecord.OrderFlag[mode]
|
||||||
|
|
||||||
// For objects their txt record entry overrides animationdata
|
// For objects their txt record entry overrides animationdata
|
||||||
speed := ob.objectRecord.FrameDelta[mode]
|
speed := ob.objectRecord.FrameDelta[mode]
|
||||||
if speed != 0 {
|
if speed != 0 {
|
||||||
ob.composite.SetSpeed(speed)
|
ob.composite.SetAnimSpeed(speed)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -18,7 +18,6 @@ type Player struct {
|
|||||||
Stats d2hero.HeroStatsState
|
Stats d2hero.HeroStatsState
|
||||||
Class d2enum.Hero
|
Class d2enum.Hero
|
||||||
Id string
|
Id string
|
||||||
direction int
|
|
||||||
name string
|
name string
|
||||||
// nameLabel d2ui.Label
|
// nameLabel d2ui.Label
|
||||||
lastPathSize int
|
lastPathSize int
|
||||||
@ -34,23 +33,19 @@ var baseWalkSpeed = 6.0
|
|||||||
var baseRunSpeed = 9.0
|
var baseRunSpeed = 9.0
|
||||||
|
|
||||||
func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero, stats d2hero.HeroStatsState, equipment d2inventory.CharacterEquipment) *Player {
|
func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero, stats d2hero.HeroStatsState, equipment d2inventory.CharacterEquipment) *Player {
|
||||||
object := &d2datadict.ObjectLookupRecord{
|
layerEquipment := &[d2enum.CompositeTypeMax]string{
|
||||||
Mode: d2enum.AnimationModePlayerTownNeutral.String(),
|
d2enum.CompositeTypeHead: equipment.Head.GetArmorClass(),
|
||||||
Base: "/data/global/chars",
|
d2enum.CompositeTypeTorso: equipment.Torso.GetArmorClass(),
|
||||||
Token: heroType.GetToken(),
|
d2enum.CompositeTypeLegs: equipment.Legs.GetArmorClass(),
|
||||||
Class: equipment.RightHand.GetWeaponClass(),
|
d2enum.CompositeTypeRightArm: equipment.RightArm.GetArmorClass(),
|
||||||
SH: equipment.Shield.GetItemCode(),
|
d2enum.CompositeTypeLeftArm: equipment.LeftArm.GetArmorClass(),
|
||||||
// TODO: Offhand class?
|
d2enum.CompositeTypeRightHand: equipment.RightHand.GetItemCode(),
|
||||||
HD: equipment.Head.GetArmorClass(),
|
d2enum.CompositeTypeLeftHand: equipment.LeftHand.GetItemCode(),
|
||||||
TR: equipment.Torso.GetArmorClass(),
|
d2enum.CompositeTypeShield: equipment.Shield.GetItemCode(),
|
||||||
LG: equipment.Legs.GetArmorClass(),
|
|
||||||
RA: equipment.RightArm.GetArmorClass(),
|
|
||||||
LA: equipment.LeftArm.GetArmorClass(),
|
|
||||||
RH: equipment.RightHand.GetItemCode(),
|
|
||||||
LH: equipment.LeftHand.GetItemCode(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
composite, err := d2asset.LoadComposite(object, d2resource.PaletteUnits)
|
composite, err := d2asset.LoadComposite(d2enum.ObjectTypePlayer, heroType.GetToken(),
|
||||||
|
d2resource.PaletteUnits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -64,7 +59,6 @@ func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero
|
|||||||
composite: composite,
|
composite: composite,
|
||||||
Equipment: equipment,
|
Equipment: equipment,
|
||||||
Stats: stats,
|
Stats: stats,
|
||||||
direction: direction,
|
|
||||||
name: name,
|
name: name,
|
||||||
Class: heroType,
|
Class: heroType,
|
||||||
//nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
|
//nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
|
||||||
@ -77,10 +71,13 @@ func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero
|
|||||||
//result.nameLabel.Alignment = d2ui.LabelAlignCenter
|
//result.nameLabel.Alignment = d2ui.LabelAlignCenter
|
||||||
//result.nameLabel.SetText(name)
|
//result.nameLabel.SetText(name)
|
||||||
//result.nameLabel.Color = color.White
|
//result.nameLabel.Color = color.White
|
||||||
err = result.SetMode(d2enum.AnimationModePlayerTownNeutral.String(), equipment.RightHand.GetWeaponClass(), direction)
|
err = composite.SetMode(d2enum.AnimationModePlayerTownNeutral.String(), equipment.RightHand.GetWeaponClass())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
composite.SetDirection(direction)
|
||||||
|
composite.Equip(layerEquipment)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,20 +139,6 @@ func (v *Player) Render(target d2interface.Surface) {
|
|||||||
//v.nameLabel.Render(target)
|
//v.nameLabel.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Player) SetMode(animationMode, weaponClass string, direction int) error {
|
|
||||||
v.composite.SetMode(animationMode, weaponClass, direction)
|
|
||||||
v.direction = direction
|
|
||||||
v.weaponClass = weaponClass
|
|
||||||
|
|
||||||
err := v.composite.SetMode(animationMode, weaponClass, direction)
|
|
||||||
if err != nil {
|
|
||||||
err = v.composite.SetMode(animationMode, "HTH", direction)
|
|
||||||
v.weaponClass = "HTH"
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Player) GetAnimationMode() d2enum.PlayerAnimationMode {
|
func (v *Player) GetAnimationMode() d2enum.PlayerAnimationMode {
|
||||||
if v.IsRunning() && !v.IsAtTarget() {
|
if v.IsRunning() && !v.IsAtTarget() {
|
||||||
return d2enum.AnimationModePlayerRun
|
return d2enum.AnimationModePlayerRun
|
||||||
@ -181,15 +164,19 @@ func (v *Player) GetAnimationMode() d2enum.PlayerAnimationMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *Player) SetAnimationMode(animationMode string) error {
|
func (v *Player) SetAnimationMode(animationMode string) error {
|
||||||
return v.composite.SetMode(animationMode, v.weaponClass, v.direction)
|
return v.composite.SetMode(animationMode, v.composite.GetWeaponClass())
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate sets direction and changes animation
|
// rotate sets direction and changes animation
|
||||||
func (v *Player) rotate(direction int) {
|
func (v *Player) rotate(direction int) {
|
||||||
newAnimationMode := v.GetAnimationMode().String()
|
newAnimationMode := v.GetAnimationMode().String()
|
||||||
|
|
||||||
if newAnimationMode != v.composite.GetAnimationMode() || direction != v.direction {
|
if newAnimationMode != v.composite.GetAnimationMode() {
|
||||||
v.SetMode(newAnimationMode, v.weaponClass, direction)
|
v.composite.SetMode(newAnimationMode, v.composite.GetWeaponClass())
|
||||||
|
}
|
||||||
|
|
||||||
|
if direction != v.composite.GetDirection() {
|
||||||
|
v.composite.SetDirection(direction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user