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

Function TryBuffCommand

internal/scripting/buff.go:75–123  ·  view source on GitHub ↗
(cmd string, rest string, userId int, mobInstanceId int, buffId int)

Source from the content-addressed store, hash-verified

73}
74
75func 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
125func getBuffVM(buffId int) (*VMWrapper, error) {
126

Callers 1

TryCommandFunction · 0.92

Calls 7

DebugFunction · 0.92
getBuffVMFunction · 0.85
GetActorFunction · 0.85
GetRoomFunction · 0.85
runCallableFunction · 0.85
GetFunctionMethod · 0.80
GetRoomIdMethod · 0.45

Tested by

no test coverage detected