1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-24 08:05:24 +00:00
OpenDiablo2/d2core/npc.go

49 lines
1.2 KiB
Go
Raw Normal View History

2019-11-10 13:51:02 +00:00
package d2core
2019-11-10 08:36:53 +00:00
import (
"github.com/OpenDiablo2/D2Shared/d2common"
"github.com/OpenDiablo2/D2Shared/d2common/d2enum"
"github.com/OpenDiablo2/D2Shared/d2common/d2interface"
"github.com/OpenDiablo2/D2Shared/d2data/d2datadict"
2019-11-10 13:51:02 +00:00
"github.com/OpenDiablo2/OpenDiablo2/d2render"
2019-11-10 08:36:53 +00:00
"github.com/hajimehoshi/ebiten"
)
type NPC struct {
2019-11-10 15:44:13 +00:00
AnimatedEntity d2render.AnimatedEntity
HasPaths bool
2019-11-10 08:36:53 +00:00
Paths []d2common.Path
path int
2019-11-10 08:36:53 +00:00
}
func CreateNPC(x, y int32, object *d2datadict.ObjectLookupRecord, fileProvider d2interface.FileProvider, direction int) *NPC {
2019-11-10 08:36:53 +00:00
result := &NPC{
AnimatedEntity: d2render.CreateAnimatedEntity(x, y, object, fileProvider, d2enum.Units),
HasPaths: false,
2019-11-10 08:36:53 +00:00
}
2019-11-15 03:20:01 +00:00
result.AnimatedEntity.SetMode(object.Mode, object.Class, direction)
2019-11-10 08:36:53 +00:00
return result
}
func (v *NPC) Path() d2common.Path {
return v.Paths[v.path]
}
func (v *NPC) NextPath() d2common.Path {
v.path++
if v.path == len(v.Paths) {
v.path = 0
}
return v.Paths[v.path]
}
func (v *NPC) SetPaths(paths []d2common.Path) {
v.Paths = paths
v.HasPaths = len(paths) > 0
}
2019-11-10 08:36:53 +00:00
func (v *NPC) Render(target *ebiten.Image, offsetX, offsetY int) {
v.AnimatedEntity.Render(target, offsetX, offsetY)
}