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

Function TrySpellScriptEvent

internal/scripting/spell.go:35–145  ·  view source on GitHub ↗
(eventName string, sourceUserId int, sourceMobInstanceId int, spellAggro characters.SpellAggroInfo)

Source from the content-addressed store, hash-verified

33}
34
35func TrySpellScriptEvent(eventName string, sourceUserId int, sourceMobInstanceId int, spellAggro characters.SpellAggroInfo) (bool, error) {
36
37 spellInfo := spells.GetSpell(spellAggro.SpellId)
38 if spellInfo == nil {
39 return false, fmt.Errorf("spell %s not found", spellAggro.SpellId)
40 }
41
42 timestart := time.Now()
43 defer func() {
44 mudlog.Debug("TrySpellScriptEvent()", "eventName", eventName, "spellId", spellAggro.SpellId, "spellRest", spellAggro.SpellRest, "TargetUsers", spellAggro.TargetUserIds, "TargetMobs", spellAggro.TargetMobInstanceIds, "time", time.Since(timestart))
45 }()
46
47 vmw, err := getSpellVM(spellAggro.SpellId)
48 if err != nil {
49 mudlog.Debug("TrySpellScriptEvent()", "error", err)
50 return false, err
51 }
52
53 sourceActor := GetActor(sourceUserId, sourceMobInstanceId)
54
55 if eventName != `onCast` && eventName != `onWait` && eventName != `onMagic` && eventName != `onFail` {
56 return false, err
57 }
58
59 var stringArg string = ""
60 var singleTargetArg *ScriptActor = nil
61 var multiTargetArg []*ScriptActor = nil
62
63 if spellInfo.Type == spells.Neutral {
64
65 // arg is just whatever the user entered after the spell casting command
66 stringArg = spellAggro.SpellRest
67
68 } else if spellInfo.Type == spells.HelpSingle || spellInfo.Type == spells.HarmSingle {
69
70 // arg is a single actor
71 if len(spellAggro.TargetUserIds) > 0 {
72 singleTargetArg = GetActor(spellAggro.TargetUserIds[0], 0)
73 } else if len(spellAggro.TargetMobInstanceIds) > 0 {
74 singleTargetArg = GetActor(0, spellAggro.TargetMobInstanceIds[0])
75 }
76
77 // If no longer in the same room, notify the user
78 if singleTargetArg == nil || (sourceActor.GetRoomId() != singleTargetArg.GetRoomId()) {
79 sourceActor.SendText(`Your target cannot be found.`)
80 return true, nil
81 }
82
83 } else if spellInfo.Type == spells.HelpMulti || spellInfo.Type == spells.HarmMulti {
84
85 // arg is a list of actors
86 multiTargetArg = []*ScriptActor{}
87 for _, targetUserId := range spellAggro.TargetUserIds {
88 if uActor := GetActor(targetUserId, 0); uActor != nil {
89 if uActor.GetRoomId() == sourceActor.GetRoomId() {
90 multiTargetArg = append(multiTargetArg, uActor)
91 }
92 }

Callers 7

CastFunction · 0.92
AidFunction · 0.92
handlePlayerCombatFunction · 0.92
handleMobCombatFunction · 0.92
CastFunction · 0.92
TameFunction · 0.92
AidFunction · 0.92

Calls 10

GetRoomIdMethod · 0.95
GetSpellFunction · 0.92
DebugFunction · 0.92
getSpellVMFunction · 0.85
GetActorFunction · 0.85
runCallableFunction · 0.85
GetFunctionMethod · 0.80
SetMethod · 0.65
SendTextMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected