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

Function HandlePlayerDrop

internal/hooks/PlayerDrop_HandlePlayerDrop.go:18–66  ·  view source on GitHub ↗

Some clean up

(e events.Event)

Source from the content-addressed store, hash-verified

16//
17
18func HandlePlayerDrop(e events.Event) events.ListenerReturn {
19
20 evt, typeOk := e.(events.PlayerDrop)
21 if !typeOk {
22 mudlog.Error("Event", "Expected Type", "PlayerDrop", "Actual Type", e.Type())
23 return events.Cancel
24 }
25
26 user := users.GetByUserId(evt.UserId)
27 if user == nil {
28 mudlog.Error("HandlePlayerDrop", "error", fmt.Sprintf(`user %d not found`, evt.UserId))
29 return events.Cancel
30 }
31
32 user.SendText(`<ansi fg="red">you drop to the ground!</ansi>`)
33
34 room := rooms.LoadRoom(evt.RoomId)
35 if room == nil {
36 return events.Continue
37 }
38
39 room.SendText(
40 fmt.Sprintf(`<ansi fg="username">%s</ansi> <ansi fg="red">drops to the ground!</ansi>`, user.Character.Name),
41 user.UserId)
42
43 // Loop through all mobs in the room. If any hate the player, try onPlayerDowned()
44 skipMobIds := map[int]struct{}{}
45 for _, mobInstanceId := range room.GetMobs() {
46 mob := mobs.GetInstance(mobInstanceId)
47 if mob == nil {
48 continue
49 }
50
51 if _, ok := skipMobIds[int(mob.MobId)]; ok {
52 continue
53 }
54
55 if !mob.HasAttackedPlayer(user.UserId) {
56 continue
57 }
58
59 if isUnique, _ := scripting.TryPlayerDownedEvent(mobInstanceId, user.UserId); isUnique {
60 skipMobIds[int(mob.MobId)] = struct{}{}
61 }
62
63 }
64
65 return events.Continue
66}

Callers

nothing calls this directly

Calls 9

ErrorFunction · 0.92
GetByUserIdFunction · 0.92
LoadRoomFunction · 0.92
GetInstanceFunction · 0.92
TryPlayerDownedEventFunction · 0.92
HasAttackedPlayerMethod · 0.80
TypeMethod · 0.65
SendTextMethod · 0.45
GetMobsMethod · 0.45

Tested by

no test coverage detected