(e events.Event)
| 76 | } |
| 77 | |
| 78 | func (w *World) HandleInputEvents(e events.Event) events.ListenerReturn { |
| 79 | |
| 80 | input, typeOk := e.(events.Input) |
| 81 | if !typeOk { |
| 82 | mudlog.Error("Event", "Expected Type", "Input", "Actual Type", e.Type()) |
| 83 | return events.Continue |
| 84 | } |
| 85 | |
| 86 | var turnCt uint64 = util.GetTurnCount() |
| 87 | |
| 88 | //mudlog.Debug(`Event`, `type`, input.Type(), `UserId`, input.UserId, `MobInstanceId`, input.MobInstanceId, `WaitTurns`, input.WaitTurns, `InputText`, input.InputText) |
| 89 | |
| 90 | // If it's a mob |
| 91 | if input.MobInstanceId > 0 { |
| 92 | |
| 93 | // If an event was already processed for this user this turn, skip |
| 94 | // We put this first, so that any delayed command for a mob will block |
| 95 | // the command pipeline for the mob until executed. |
| 96 | if _, ok := w.mobInputEventTracker[input.MobInstanceId]; ok { |
| 97 | return events.CancelAndRequeue |
| 98 | } |
| 99 | |
| 100 | // 0 and below, process immediately and don't count towards limit |
| 101 | if input.ReadyTurn <= 0 { |
| 102 | w.processMobInput(input.MobInstanceId, input.InputText) |
| 103 | return events.Continue |
| 104 | } |
| 105 | |
| 106 | // This will cause any pending command to block all further pending commands |
| 107 | // This is important, otherwise we issue a command with a delay, but other commands |
| 108 | // Get executed while we wait. |
| 109 | w.mobInputEventTracker[input.MobInstanceId] = struct{}{} |
| 110 | |
| 111 | if input.ReadyTurn > turnCt { |
| 112 | return events.CancelAndRequeue |
| 113 | } |
| 114 | |
| 115 | w.processMobInput(input.MobInstanceId, input.InputText) |
| 116 | |
| 117 | return events.Continue |
| 118 | } |
| 119 | |
| 120 | // 0 and below, process immediately and don't count towards limit |
| 121 | if input.ReadyTurn <= 0 { |
| 122 | |
| 123 | // If this command was potentially blocking input, unblock it now. |
| 124 | if input.Flags.Has(events.CmdUnBlockInput) { |
| 125 | |
| 126 | if _, ok := w.ignoreInput[input.UserId]; ok { |
| 127 | delete(w.ignoreInput, input.UserId) |
| 128 | if user := users.GetByUserId(input.UserId); user != nil { |
| 129 | user.UnblockInput() |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | |
| 135 | w.processInput(input.UserId, input.InputText, input.Flags) |
nothing calls this directly
no test coverage detected