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

Function getBuffVM

internal/scripting/buff.go:125–170  ·  view source on GitHub ↗
(buffId int)

Source from the content-addressed store, hash-verified

123}
124
125func getBuffVM(buffId int) (*VMWrapper, error) {
126
127 if vmw, ok := buffVMCache[buffId]; ok {
128 if vmw == nil {
129 return nil, errNoScript
130 }
131 if scriptHotReload {
132 bSpec := buffs.GetBuffSpec(buffId)
133 if bSpec != nil {
134 if info, err := os.Stat(bSpec.GetScriptPath()); err == nil {
135 if info.ModTime().After(vmw.loadedAt) {
136 delete(buffVMCache, buffId)
137 // fall through to reload
138 } else {
139 return vmw, nil
140 }
141 } else {
142 return vmw, nil
143 }
144 } else {
145 return vmw, nil
146 }
147 } else {
148 return vmw, nil
149 }
150 }
151
152 bSpec := buffs.GetBuffSpec(buffId)
153 if bSpec == nil {
154 return nil, fmt.Errorf("buff spec not found: %T", bSpec)
155 }
156
157 script := bSpec.GetScript()
158 if len(script) == 0 {
159 buffVMCache[buffId] = nil
160 return nil, errNoScript
161 }
162
163 vmw, err := loadVM(fmt.Sprintf(`buff-%d`, buffId), script, nil)
164 if err != nil {
165 return nil, err
166 }
167
168 buffVMCache[buffId] = vmw
169 return vmw, nil
170}

Callers 2

TryBuffScriptEventFunction · 0.85
TryBuffCommandFunction · 0.85

Calls 6

GetBuffSpecFunction · 0.92
deleteFunction · 0.85
loadVMFunction · 0.85
StatMethod · 0.45
GetScriptPathMethod · 0.45
GetScriptMethod · 0.45

Tested by

no test coverage detected