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

Function TryBuffScriptEvent

internal/scripting/buff.go:34–73  ·  view source on GitHub ↗
(eventName string, userId int, mobInstanceId int, buffId int)

Source from the content-addressed store, hash-verified

32}
33
34func TryBuffScriptEvent(eventName string, userId int, mobInstanceId int, buffId int) (bool, error) {
35
36 vmw, err := getBuffVM(buffId)
37 if err != nil {
38 return false, err
39 }
40
41 actorInfo := GetActor(userId, mobInstanceId)
42 buffTriggersLeft := actorInfo.characterRecord.Buffs.TriggersLeft(buffId)
43
44 timestart := time.Now()
45 defer func() {
46 mudlog.Debug("TryBuffScriptEvent()", "eventName", eventName, "buffId", buffId, "time", time.Since(timestart))
47 }()
48 if onCommandFunc, ok := vmw.GetFunction(eventName); ok {
49
50 // Set forced ansi tag wrappers
51 userTextWrap.Set(`buff-text`, ``, `cyan`, colorpatterns.Stretch)
52 roomTextWrap.Set(`buff-text`, ``, `cyan`, colorpatterns.Stretch)
53
54 res, err := runCallable(vmw, scriptBuffTimeout, onCommandFunc,
55 vmw.VM.ToValue(actorInfo),
56 vmw.VM.ToValue(buffTriggersLeft),
57 )
58
59 // Reset forced ansi tag wrappers
60 userTextWrap.Reset()
61 roomTextWrap.Reset()
62
63 if err != nil {
64 return false, fmt.Errorf("%s(): %w", eventName, err)
65 }
66
67 if boolVal, ok := res.Export().(bool); ok {
68 return boolVal, nil
69 }
70 }
71
72 return false, ErrEventNotFound
73}
74
75func TryBuffCommand(cmd string, rest string, userId int, mobInstanceId int, buffId int) (bool, error) {
76

Callers 5

UserRoundTickFunction · 0.92
MobRoundTickFunction · 0.92
PruneBuffsFunction · 0.92
ApplyBuffsFunction · 0.92
EquipFunction · 0.92

Calls 8

DebugFunction · 0.92
getBuffVMFunction · 0.85
GetActorFunction · 0.85
runCallableFunction · 0.85
TriggersLeftMethod · 0.80
GetFunctionMethod · 0.80
SetMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected