bool Action::executeUse(Player* player, Item* item, const PositionEx& fromPos, const PositionEx& toPos, bool extendedUse, uint32_t, bool isHotkey) { //onUse(player, item, fromPosition, itemEx, toPosition, isHotkey) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - Action::executeUse] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); LuaScriptInterface::pushUserdata<Player>(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); LuaScriptInterface::pushThing(L, item, env->addThing(item)); LuaScriptInterface::pushPosition(L, fromPos, fromPos.stackpos); Thing* thing = g_game.internalGetThing(player, toPos, toPos.stackpos); if (thing && (!extendedUse || thing != item)) { LuaScriptInterface::pushThing(L, thing, env->addThing(thing)); LuaScriptInterface::pushPosition(L, toPos, toPos.stackpos); } else { LuaScriptInterface::pushThing(L, nullptr, 0); Position posEx; LuaScriptInterface::pushPosition(L, posEx); } LuaScriptInterface::pushBoolean(L, isHotkey); return m_scriptInterface->callFunction(6); }
uint32_t MoveEvent::executeAddRemItem(Item* item, Item* tileItem, const Position& pos) { //onAddItem(moveitem, tileitem, pos) //onRemoveItem(moveitem, tileitem, pos) if (m_scriptInterface->reserveScriptEnv()) { ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(pos); uint32_t itemidMoved = env->addThing(item); uint32_t itemidTile = env->addThing(tileItem); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); LuaScriptInterface::pushThing(L, item, itemidMoved); LuaScriptInterface::pushThing(L, tileItem, itemidTile); LuaScriptInterface::pushPosition(L, pos, 0); bool result = m_scriptInterface->callFunction(3); m_scriptInterface->releaseScriptEnv(); return result; } else { std::cout << "[Error] Call stack overflow. MoveEvent::executeAddRemItem" << std::endl; return 0; } }
bool Action::executeUse(Player* player, Item* item, const PositionEx& fromPos, const PositionEx& toPos, bool extendedUse, uint32_t creatureId) { //onUse(cid, item, fromPosition, itemEx, toPosition) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - Action::executeUse] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, player->getID()); LuaScriptInterface::pushThing(L, item, env->addThing(item)); LuaScriptInterface::pushPosition(L, fromPos, fromPos.stackpos); Thing* thing = g_game.internalGetThing(player, toPos, toPos.stackpos); if (thing && (!extendedUse || thing != item)) { LuaScriptInterface::pushThing(L, thing, env->addThing(thing)); LuaScriptInterface::pushPosition(L, toPos, toPos.stackpos); } else { LuaScriptInterface::pushThing(L, nullptr, 0); Position posEx; LuaScriptInterface::pushPosition(L, posEx, 0); } return m_scriptInterface->callFunction(5); }
bool Action::executeUse(Player* player, Item* item, const PositionEx& fromPos, const PositionEx& toPos, bool extendedUse, uint32_t creatureId) { //onUse(cid, item, fromPosition, itemEx, toPosition) if(m_scriptInterface->reserveScriptEnv()) { ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); #ifdef __DEBUG_LUASCRIPTS__ std::ostringstream desc; desc << player->getName() << " - " << item->getID() << " " << fromPos << "|" << toPos; env->setEventDesc(desc.str()); #endif env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(player->getPosition()); uint32_t cid = env->addThing(player); uint32_t itemid1 = env->addThing(item); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, cid); LuaScriptInterface::pushThing(L, item, itemid1); LuaScriptInterface::pushPosition(L, fromPos, fromPos.stackpos); //std::cout << "posTo" << (Position)posTo << " stack" << (int32_t)posTo.stackpos <<std::endl; Thing* thing = g_game.internalGetThing(player, toPos, toPos.stackpos); if(thing && (!extendedUse || thing != item)) { uint32_t thingId2 = env->addThing(thing); LuaScriptInterface::pushThing(L, thing, thingId2); LuaScriptInterface::pushPosition(L, toPos, toPos.stackpos); } else { LuaScriptInterface::pushThing(L, NULL, 0); Position posEx; LuaScriptInterface::pushPosition(L, posEx, 0); } bool result = m_scriptInterface->callFunction(5); m_scriptInterface->releaseScriptEnv(); return result; } else { std::cout << "[Error] Call stack overflow. Action::executeUse" << std::endl; return false; } }
uint32_t MoveEvent::executeStep(Creature* creature, Item* item, const Position& pos) { //onStepIn(cid, item, pos, fromPosition) //onStepOut(cid, item, pos, fromPosition) if (m_scriptInterface->reserveScriptEnv()) { ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(creature->getPosition()); uint32_t itemid = env->addThing(item); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, creature->getID()); LuaScriptInterface::pushThing(L, item, itemid); LuaScriptInterface::pushPosition(L, pos, 0); LuaScriptInterface::pushPosition(L, creature->getLastPosition(), 0); bool result = m_scriptInterface->callFunction(4); m_scriptInterface->releaseScriptEnv(); return result; } else { std::cout << "[Error] Call stack overflow. MoveEvent::executeStep" << std::endl; return 0; } }
uint32_t MoveEvent::executeEquip(Player* player, Item* item, slots_t slot) { //onEquip(cid, item, slot) //onDeEquip(cid, item, slot) if (m_scriptInterface->reserveScriptEnv()) { ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(player->getPosition()); uint32_t itemid = env->addThing(item); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, player->getID()); LuaScriptInterface::pushThing(L, item, itemid); lua_pushnumber(L, slot); bool result = m_scriptInterface->callFunction(3); m_scriptInterface->releaseScriptEnv(); return result; } else { std::cout << "[Error] Call stack overflow. MoveEvent::executeEquip" << std::endl; return 0; } }
bool Weapon::executeUseWeapon(Player* player, const LuaVariant& var) const { //onUseWeapon(cid, var) if(m_scriptInterface->reserveScriptEnv()) { ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); #ifdef __DEBUG_LUASCRIPTS__ std::ostringstream ss; ss << "onUseWeapon - " << player->getName(); env->setEventDesc(ss.str()); #endif env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(player->getPosition()); lua_State* L = m_scriptInterface->getLuaState(); uint32_t cid = env->addThing(player); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, cid); m_scriptInterface->pushVariant(L, var); bool result = m_scriptInterface->callFunction(2); m_scriptInterface->releaseScriptEnv(); return result; } else { std::cout << "[Error] Call stack overflow. Weapon::executeUseWeapon" << std::endl; return false; } }
int32_t TalkAction::executeSay(Creature* creature, const std::string& words, const std::string& param) { //onSay(cid, words, param) if(m_scriptInterface->reserveScriptEnv()) { ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); #ifdef __DEBUG_LUASCRIPTS__ std::ostringstream; ss << creature->getName() << " - " << words << "- " << param; env->setEventDesc(ss.str()); #endif env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(creature->getPosition()); uint32_t cid = env->addThing(creature); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, cid); lua_pushstring(L, words.c_str()); lua_pushstring(L, param.c_str()); bool result = m_scriptInterface->callFunction(3); m_scriptInterface->releaseScriptEnv(); return result; } else { std::cout << "[Error - Talkaction::executeSay] Call stack overflow." << std::endl; return 0; } }
bool MoveEvent::executeAddRemItem(Item* item, Item* tileItem, const Position& pos) { //onAddItem(moveitem, tileitem, pos) //onRemoveItem(moveitem, tileitem, pos) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - MoveEvent::executeAddRemItem] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); LuaScriptInterface::pushThing(L, item, env->addThing(item)); LuaScriptInterface::pushThing(L, tileItem, env->addThing(tileItem)); LuaScriptInterface::pushPosition(L, pos, 0); return m_scriptInterface->callFunction(3); }
bool CreatureEvent::executeTextEdit(Player* player, Item* item, const std::string& text) { //onTextEdit(cid, item, text) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - CreatureEvent::executeTextEdit] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); LuaScriptInterface::pushNumber(L, player->getID()); LuaScriptInterface::pushThing(L, item, env->addThing(item)); LuaScriptInterface::pushString(L, text); return m_scriptInterface->callFunction(3); }
bool MoveEvent::executeEquip(Player* player, Item* item, slots_t slot) { //onEquip(cid, item, slot) //onDeEquip(cid, item, slot) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - MoveEvent::executeEquip] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, player->getID()); LuaScriptInterface::pushThing(L, item, env->addThing(item)); lua_pushnumber(L, slot); return m_scriptInterface->callFunction(3); }
bool CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* killer, Creature* mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) { //onDeath(cid, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - CreatureEvent::executeOnDeath] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); uint32_t corpseid = env->addThing(corpse); uint32_t killercid; if (killer) { killercid = killer->getID(); } else { killercid = 0; } uint32_t mostdamagekillercid; if (mostDamageKiller) { mostdamagekillercid = mostDamageKiller->getID(); } else { mostdamagekillercid = 0; } lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, creature->getID()); lua_pushnumber(L, corpseid); lua_pushnumber(L, killercid); lua_pushnumber(L, mostdamagekillercid); lua_pushnumber(L, lastHitUnjustified); lua_pushnumber(L, mostDamageUnjustified); return m_scriptInterface->callFunction(6); }
bool MoveEvent::executeStep(Creature* creature, Item* item, const Position& pos) { //onStepIn(cid, item, pos, fromPosition) //onStepOut(cid, item, pos, fromPosition) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - MoveEvent::executeStep] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, creature->getID()); LuaScriptInterface::pushThing(L, item, env->addThing(item)); LuaScriptInterface::pushPosition(L, pos, 0); LuaScriptInterface::pushPosition(L, creature->getLastPosition(), 0); return m_scriptInterface->callFunction(4); }
bool CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* killer, Creature* mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) { //onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified) if (!m_scriptInterface->reserveScriptEnv()) { std::cout << "[Error - CreatureEvent::executeOnDeath] Call stack overflow" << std::endl; return false; } ScriptEnvironment* env = m_scriptInterface->getScriptEnv(); env->setScriptId(m_scriptId, m_scriptInterface); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); LuaScriptInterface::pushUserdata<Creature>(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); lua_pushnumber(L, env->addThing(corpse)); if (killer) { LuaScriptInterface::pushUserdata<Creature>(L, killer); LuaScriptInterface::setCreatureMetatable(L, -1, killer); } else { lua_pushnil(L); } if (mostDamageKiller) { LuaScriptInterface::pushUserdata<Creature>(L, mostDamageKiller); LuaScriptInterface::setCreatureMetatable(L, -1, mostDamageKiller); } else { lua_pushnil(L); } lua_pushboolean(L, lastHitUnjustified); lua_pushboolean(L, mostDamageUnjustified); return m_scriptInterface->callFunction(6); }