Some clean up
(e events.Event)
| 16 | // |
| 17 | |
| 18 | func 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 | } |
nothing calls this directly
no test coverage detected