void PythonSpellIntegration::SpellTrigger(int spellId, SpellEvent evt) { bool cancelled = 0; SpellPacketBody spellPktBody; spellSys.GetSpellPacketBody(spellId, &spellPktBody); if (evt == SpellEvent::SpellEffect && spellPktBody.targetListNumItems > 0) { for (uint32_t i = 0; i < spellPktBody.targetListNumItems; i++) { auto tgtObj = spellPktBody.targetListHandles[i]; // TODO: Verify attachee vs. target here if (!pythonObjIntegration.ExecuteObjectScript(spellPktBody.objHndCaster, tgtObj, spellId, ObjScriptEvent::SpellCast)) { cancelled = 1; } } if (cancelled) { return; } } auto pySpell = PySpell_Create(spellId); auto args = Py_BuildValue("(O)", pySpell); auto spellEnum = spellSys.GetSpellEnumFromSpellId(spellId); auto result = RunScript(spellEnum, (EventId)evt, args); Py_DECREF(args); // Result of RunScript is a bit different here if (result == 0 || result == -1) { PySpell_UpdatePacket(pySpell); addresses.SpellSoundPlay(&spellPktBody, evt); } Py_DECREF(pySpell); }
static int RunPythonObjScript(ObjScriptInvocation* invoc) { // This seems to be primarily used by the CounterArray pythonObjIntegration.SetCounterContext(invoc->attachee, invoc->script->scriptId, invoc->evt); pythonObjIntegration.SetInObjInvocation(true); PyObject* args; auto triggerer = PyObjHndl_Create(invoc->triggerer); // Expected arguments depend on the event type if (invoc->evt == ObjScriptEvent::SpellCast) { auto attachee = PyObjHndl_Create(invoc->attachee); auto spell = PySpell_Create(invoc->spellId); args = Py_BuildValue("OOO", attachee, triggerer, spell); Py_DECREF(spell); Py_DECREF(attachee); } else if (invoc->evt == ObjScriptEvent::Trap) { auto attachee = PyTrap_Create(invoc->attachee); args = Py_BuildValue("OO", attachee, triggerer); Py_DECREF(attachee); } else { if (invoc->evt == ObjScriptEvent::FirstHeartbeat){ int dumy = 1; } auto attachee = PyObjHndl_Create(invoc->attachee); args = Py_BuildValue("OO", attachee, triggerer); Py_DECREF(attachee); } auto result = pythonObjIntegration.RunScript(invoc->script->scriptId, (PythonIntegration::EventId) invoc->evt, args); Py_DECREF(args); auto newSid = pythonObjIntegration.GetNewSid(); if (newSid != -1 && newSid != invoc->script->scriptId) { invoc->script->scriptId = newSid; } pythonObjIntegration.SetInObjInvocation(false); return result; }
void PythonSpellIntegration::SpellTriggerProjectile(int spellId, SpellEvent evt, objHndl projectile, int targetIdx) { auto pySpell = PySpell_Create(spellId); auto projectileObj = PyObjHndl_Create(projectile); auto args = Py_BuildValue("(OOi)", pySpell, projectileObj, targetIdx); Py_DECREF(projectileObj); auto spellEnum = spellSys.GetSpellEnumFromSpellId(spellId); auto result = RunScript(spellEnum, (EventId)evt, args); Py_DECREF(args); // The meaning of the results is different from obj scripts if (result == -1 || result == 0) { PySpell_UpdatePacket(pySpell); SpellPacketBody spellPktBody; spellSys.GetSpellPacketBody(spellId, &spellPktBody); addresses.SpellProjectileSoundPlay(&spellPktBody, evt, projectile); } Py_DECREF(pySpell); }