2019-11-14 22:20:01 -05:00
|
|
|
package d2core
|
|
|
|
|
|
|
|
import (
|
2019-11-17 00:16:33 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2common/d2enum"
|
2019-12-24 01:48:45 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2common/d2resource"
|
2019-11-17 00:16:33 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2data/d2datadict"
|
2019-11-14 22:20:01 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render"
|
2019-12-28 16:46:08 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2surface"
|
2019-11-14 22:20:01 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Hero struct {
|
2019-12-24 01:48:45 -05:00
|
|
|
AnimatedEntity *d2render.AnimatedEntity
|
2019-11-14 22:20:01 -05:00
|
|
|
Equipment CharacterEquipment
|
|
|
|
mode d2enum.AnimationMode
|
|
|
|
direction int
|
|
|
|
}
|
|
|
|
|
2019-12-21 20:53:18 -05:00
|
|
|
func CreateHero(x, y int32, direction int, heroType d2enum.Hero, equipment CharacterEquipment) *Hero {
|
2019-12-24 01:48:45 -05:00
|
|
|
object := &d2datadict.ObjectLookupRecord{
|
|
|
|
Mode: d2enum.AnimationModePlayerNeutral.String(),
|
|
|
|
Base: "/data/global/chars",
|
|
|
|
Token: heroType.GetToken(),
|
|
|
|
Class: equipment.RightHand.GetWeaponClass(),
|
|
|
|
SH: equipment.Shield.GetItemCode(),
|
|
|
|
// TODO: Offhand class?
|
|
|
|
HD: equipment.Head.GetArmorClass(),
|
|
|
|
TR: equipment.Torso.GetArmorClass(),
|
|
|
|
LG: equipment.Legs.GetArmorClass(),
|
|
|
|
RA: equipment.RightArm.GetArmorClass(),
|
|
|
|
LA: equipment.LeftArm.GetArmorClass(),
|
|
|
|
RH: equipment.RightHand.GetItemCode(),
|
|
|
|
LH: equipment.LeftHand.GetItemCode(),
|
2019-11-14 22:20:01 -05:00
|
|
|
}
|
2019-12-24 01:48:45 -05:00
|
|
|
|
|
|
|
entity, err := d2render.CreateAnimatedEntity(x, y, object, d2resource.PaletteUnits)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
result := &Hero{AnimatedEntity: entity, Equipment: equipment, mode: d2enum.AnimationModePlayerTownNeutral, direction: direction}
|
2019-11-14 22:20:01 -05:00
|
|
|
result.AnimatedEntity.SetMode(result.mode.String(), equipment.RightHand.GetWeaponClass(), direction)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-12-13 00:33:11 -05:00
|
|
|
func (v *Hero) Advance(tickTime float64) {
|
|
|
|
// TODO: Pathfinding
|
|
|
|
if v.AnimatedEntity.LocationX != v.AnimatedEntity.TargetX ||
|
|
|
|
v.AnimatedEntity.LocationY != v.AnimatedEntity.TargetY {
|
|
|
|
v.AnimatedEntity.Step(tickTime)
|
|
|
|
}
|
2019-12-24 01:48:45 -05:00
|
|
|
|
|
|
|
v.AnimatedEntity.Advance(tickTime)
|
2019-12-13 00:33:11 -05:00
|
|
|
}
|
|
|
|
|
2019-12-28 16:46:08 -05:00
|
|
|
func (v *Hero) Render(target *d2surface.Surface) {
|
|
|
|
v.AnimatedEntity.Render(target)
|
2019-11-14 22:20:01 -05:00
|
|
|
}
|
2019-12-13 00:33:11 -05:00
|
|
|
|
|
|
|
func (v *Hero) GetPosition() (float64, float64) {
|
|
|
|
return v.AnimatedEntity.GetPosition()
|
|
|
|
}
|