@@ -3,6 +3,7 @@ package hooks
33
44import (
55 "fmt"
6+ "strconv"
67 "time"
78
89 "github.com/GoMudEngine/GoMud/internal/configs"
@@ -78,6 +79,54 @@ func IdleMobs(e events.Event) events.ListenerReturn {
7879 continue
7980 }
8081
82+ // Check whether they are currently in the middle of a path, or have one waiting to start.
83+ if currentStep := mob .Path .Current (); currentStep != nil || mob .Path .Len () > 0 {
84+
85+ if currentStep == nil {
86+ //mob.Command(`say I'm beginning a new path.`)
87+ } else {
88+
89+ // If their currentStep isnt' actually the room they are in
90+ // They've somehow been moved. Reclaculate a new path.
91+ if currentStep .RoomId () != mob .Character .RoomId {
92+ //mob.Command(`say I seem to have wandered off my path.`)
93+
94+ reDoWaypoints := mob .Path .Waypoints ()
95+ if len (reDoWaypoints ) > 0 {
96+ newCommand := `pathto`
97+ for _ , wpInt := range reDoWaypoints {
98+ newCommand += ` ` + strconv .Itoa (wpInt )
99+ }
100+ mob .Command (newCommand )
101+ continue
102+ }
103+
104+ mob .Command (`pathto home` )
105+ continue
106+ }
107+
108+ if currentStep .Waypoint () {
109+ //mob.Command(`say I've reached a waypoint.`)
110+ }
111+ }
112+
113+ if nextStep := mob .Path .Next (); nextStep != nil {
114+
115+ if room := rooms .LoadRoom (mob .Character .RoomId ); room != nil {
116+ if exitInfo , ok := room .Exits [nextStep .ExitName ()]; ok {
117+ if exitInfo .RoomId == nextStep .RoomId () {
118+ mob .Command (nextStep .ExitName ())
119+ continue
120+ }
121+ }
122+ }
123+
124+ }
125+
126+ //mob.Command(`say I'm.... done.`)
127+ mob .Path .Clear ()
128+ }
129+
81130 if mob .InConversation () {
82131 mob .Converse ()
83132 continue
0 commit comments