2020-02-01 18:55:56 -05:00
|
|
|
package d2map
|
2019-11-14 22:20:01 -05:00
|
|
|
|
|
|
|
import (
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
2020-01-26 00:39:13 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
2020-02-01 20:39:28 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2019-11-14 22:20:01 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Hero struct {
|
2020-02-22 20:44:30 -05:00
|
|
|
*AnimatedComposite
|
2020-04-11 14:56:47 -04:00
|
|
|
Equipment d2inventory.CharacterEquipment
|
|
|
|
mode d2enum.AnimationMode
|
|
|
|
direction int
|
2019-11-14 22:20:01 -05:00
|
|
|
}
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
func CreateHero(x, y int, direction int, heroType d2enum.Hero, equipment d2inventory.CharacterEquipment) *Hero {
|
2019-12-24 01:48:45 -05:00
|
|
|
object := &d2datadict.ObjectLookupRecord{
|
|
|
|
Mode: d2enum.AnimationModePlayerNeutral.String(),
|
|
|
|
Base: "/data/global/chars",
|
|
|
|
Token: heroType.GetToken(),
|
2019-12-28 23:32:53 -05:00
|
|
|
Class: equipment.RightHand.WeaponClass(),
|
|
|
|
SH: equipment.Shield.ItemCode(),
|
2019-12-24 01:48:45 -05:00
|
|
|
// TODO: Offhand class?
|
2019-12-28 23:32:53 -05:00
|
|
|
HD: equipment.Head.ArmorClass(),
|
|
|
|
TR: equipment.Torso.ArmorClass(),
|
|
|
|
LG: equipment.Legs.ArmorClass(),
|
|
|
|
RA: equipment.RightArm.ArmorClass(),
|
|
|
|
LA: equipment.LeftArm.ArmorClass(),
|
|
|
|
RH: equipment.RightHand.ItemCode(),
|
|
|
|
LH: equipment.LeftHand.ItemCode(),
|
2019-11-14 22:20:01 -05:00
|
|
|
}
|
2019-12-24 01:48:45 -05:00
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
entity, err := CreateAnimatedComposite(x, y, object, d2resource.PaletteUnits)
|
2019-12-24 01:48:45 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
result := &Hero{
|
|
|
|
AnimatedComposite: entity,
|
|
|
|
Equipment: equipment,
|
|
|
|
mode: d2enum.AnimationModePlayerTownNeutral,
|
|
|
|
direction: direction,
|
|
|
|
}
|
|
|
|
result.SetMode(result.mode.String(), equipment.RightHand.WeaponClass(), direction)
|
2019-11-14 22:20:01 -05:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-12-13 00:33:11 -05:00
|
|
|
func (v *Hero) Advance(tickTime float64) {
|
2020-02-22 20:44:30 -05:00
|
|
|
v.Step(tickTime)
|
|
|
|
v.AnimatedComposite.Advance(tickTime)
|
2019-12-13 00:33:11 -05:00
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:28 -05:00
|
|
|
func (v *Hero) Render(target d2render.Surface) {
|
2020-02-22 20:44:30 -05:00
|
|
|
v.AnimatedComposite.Render(target)
|
2019-11-14 22:20:01 -05:00
|
|
|
}
|
2019-12-13 00:33:11 -05:00
|
|
|
|
|
|
|
func (v *Hero) GetPosition() (float64, float64) {
|
2020-02-22 20:44:30 -05:00
|
|
|
return v.AnimatedComposite.GetPosition()
|
2019-12-13 00:33:11 -05:00
|
|
|
}
|