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

Function CallForHelp

internal/mobcommands/callforhelp.go:21–106  ·  view source on GitHub ↗

Should check adjacent rooms for mobs and call them into the room to help if of the same group Format should be: callforhelp blows his horn "blows his horn" will be emoted to the room Other valid formats: callforhelp 5:blows a horn, calling for help callforhelp 5:guard:blows a horn, calling for help

(rest string, mob *mobs.Mob, room *rooms.Room)

Source from the content-addressed store, hash-verified

19// callforhelp 5:guard:blows a horn, calling for help
20// callforhelp guard:blows a horn, calling for help
21func CallForHelp(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error) {
22
23 calledForHelp := false
24
25 maxRange := 1
26 // Can prefix callforhelp string with a number and : to force range.
27 // "callforhelp 5:blows a horn, calling for help"
28 if i := strings.Index(rest, ":"); i >= 0 {
29 newRangeStr := strings.TrimSpace(rest[:i])
30 if newRange, err := strconv.Atoi(newRangeStr); err == nil {
31 maxRange = newRange
32 if i < len(rest)-1 {
33 rest = strings.TrimSpace(rest[i+1:])
34 } else {
35 rest = ``
36 }
37 }
38 }
39
40 mobNameSearch := ``
41 // "callforhelp 5:guard:blows a horn, calling for help"
42 // "callforhelp guard:blows a horn, calling for help"
43 if i := strings.Index(rest, ":"); i >= 0 {
44 mobNameSearch = strings.ToLower(strings.TrimSpace(rest[:i]))
45
46 if i < len(rest)-1 {
47 rest = strings.TrimSpace(rest[i+1:])
48 } else {
49 rest = ``
50 }
51 }
52
53 m := mapper.GetMapper(room.RoomId)
54 if m == nil {
55 return true, nil
56 }
57 roomList := m.FindRoomsInDistance(room.RoomId, maxRange, 0)
58
59 for _, roomId := range roomList {
60 testRoom := rooms.LoadRoom(roomId)
61 if testRoom == nil {
62 continue
63 }
64
65 for _, nearbyMobInstanceId := range testRoom.GetMobs(rooms.FindNeutral, rooms.FindHostile) {
66
67 if mobInfo := mobs.GetInstance(nearbyMobInstanceId); mobInfo != nil {
68
69 if mobNameSearch == `` {
70 if !mobInfo.ConsidersAnAlly(mob) { // Only help allies
71 continue
72 }
73 } else {
74 if mobNameSearch != strings.ToLower(mobInfo.Character.Name) {
75 continue
76 }
77 }
78

Callers

nothing calls this directly

Calls 8

GetMapperFunction · 0.92
LoadRoomFunction · 0.92
GetInstanceFunction · 0.92
FindRoomsInDistanceMethod · 0.80
ConsidersAnAllyMethod · 0.80
GetRandomExitMethod · 0.80
GetMobsMethod · 0.45
CommandMethod · 0.45

Tested by

no test coverage detected