MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / handleWaypoints

Method handleWaypoints

modules/zombiemode/command.zombie.go:333–415  ·  view source on GitHub ↗
(args []string, user *users.UserRecord, cfg ZombieConfig)

Source from the content-addressed store, hash-verified

331}
332
333func (m *ZombieModule) handleWaypoints(args []string, user *users.UserRecord, cfg ZombieConfig) (bool, error) {
334
335 if len(args) == 0 {
336 if len(cfg.Waypoints) == 0 {
337 user.SendText(`No waypoints defined. Use <ansi fg="command">zombie waypoints add</ansi> to add your current room.`)
338 return true, nil
339 }
340 user.SendText(fmt.Sprintf(`<ansi fg="black-bold">.:.</ansi> <ansi fg="magenta">Zombie Waypoints</ansi> [<ansi fg="yellow">%d</ansi>]`, len(cfg.Waypoints)))
341 user.SendText(``)
342 for i, roomId := range cfg.Waypoints {
343 roomName := `unknown`
344 if r := rooms.LoadRoom(roomId); r != nil {
345 roomName = r.Title
346 }
347 marker := ``
348 if roomId == user.Character.RoomId {
349 marker = ` <ansi fg="green">(here)</ansi>`
350 }
351 user.SendText(fmt.Sprintf(` <ansi fg="yellow">%d.</ansi> <ansi fg="white">Room %d</ansi> - %s%s`, i+1, roomId, roomName, marker))
352 }
353 return true, nil
354 }
355
356 switch args[0] {
357 case `add`:
358 maxWaypoints := 10
359 if maxWP, ok := m.plug.Config.Get(`MaxWaypoints`).(int); ok && maxWP > 0 {
360 maxWaypoints = maxWP
361 }
362 if len(cfg.Waypoints) >= maxWaypoints {
363 user.SendText(fmt.Sprintf(`Cannot add more than <ansi fg="yellow">%d</ansi> waypoints.`, maxWaypoints))
364 return true, nil
365 }
366
367 currentRoomId := user.Character.RoomId
368
369 for _, wp := range cfg.Waypoints {
370 if wp == currentRoomId {
371 user.SendText(`This room is already a waypoint.`)
372 return true, nil
373 }
374 }
375
376 if len(cfg.Waypoints) > 0 {
377 lastWP := cfg.Waypoints[len(cfg.Waypoints)-1]
378 if _, err := mapper.GetPath(lastWP, currentRoomId); err != nil {
379 user.SendText(fmt.Sprintf(`No valid path from the previous waypoint (room %d) to here. Cannot add.`, lastWP))
380 return true, nil
381 }
382 }
383
384 cfg.Waypoints = append(cfg.Waypoints, currentRoomId)
385 m.configs[user.UserId] = cfg
386
387 roomName := `unknown`
388 if r := rooms.LoadRoom(currentRoomId); r != nil {
389 roomName = r.Title
390 }

Callers 1

zombieCommandMethod · 0.95

Calls 4

LoadRoomFunction · 0.92
GetPathFunction · 0.92
SendTextMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected