(cmd string, rest string, userId int, mobInstanceId int, buffId int)
| 73 | } |
| 74 | |
| 75 | func TryBuffCommand(cmd string, rest string, userId int, mobInstanceId int, buffId int) (bool, error) { |
| 76 | |
| 77 | vmw, err := getBuffVM(buffId) |
| 78 | if err != nil { |
| 79 | return false, err |
| 80 | } |
| 81 | |
| 82 | sActor := GetActor(userId, mobInstanceId) |
| 83 | sRoom := GetRoom(sActor.GetRoomId()) |
| 84 | |
| 85 | timestart := time.Now() |
| 86 | defer func() { |
| 87 | mudlog.Debug("TryBuffCommand()", "cmd", cmd, "buffId", buffId, "time", time.Since(timestart)) |
| 88 | }() |
| 89 | |
| 90 | if onCommandFunc, ok := vmw.GetFunction(`onCommand_` + cmd); ok { |
| 91 | |
| 92 | res, err := runCallable(vmw, scriptBuffTimeout, onCommandFunc, |
| 93 | vmw.VM.ToValue(rest), |
| 94 | vmw.VM.ToValue(sActor), |
| 95 | vmw.VM.ToValue(sRoom), |
| 96 | ) |
| 97 | if err != nil { |
| 98 | return false, fmt.Errorf("onCommand_%s(): %w", cmd, err) |
| 99 | } |
| 100 | |
| 101 | if boolVal, ok := res.Export().(bool); ok { |
| 102 | return boolVal, nil |
| 103 | } |
| 104 | |
| 105 | } else if onCommandFunc, ok := vmw.GetFunction(`onCommand`); ok { |
| 106 | |
| 107 | res, err := runCallable(vmw, scriptBuffTimeout, onCommandFunc, |
| 108 | vmw.VM.ToValue(cmd), |
| 109 | vmw.VM.ToValue(rest), |
| 110 | vmw.VM.ToValue(sActor), |
| 111 | vmw.VM.ToValue(sRoom), |
| 112 | ) |
| 113 | if err != nil { |
| 114 | return false, fmt.Errorf("onCommand(): %w", err) |
| 115 | } |
| 116 | |
| 117 | if boolVal, ok := res.Export().(bool); ok { |
| 118 | return boolVal, nil |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return false, ErrEventNotFound |
| 123 | } |
| 124 | |
| 125 | func getBuffVM(buffId int) (*VMWrapper, error) { |
| 126 |
no test coverage detected