void handle_player_death(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data, std::vector<void*> *extra_pointers) { Seperator sep(data.c_str()); Mob *o = entity_list.GetMobID(std::stoi(sep.arg[0])); Lua_Mob l_mob(o); luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); l_mob_o.push(L); lua_setfield(L, -2, "other"); lua_pushinteger(L, std::stoi(sep.arg[1])); lua_setfield(L, -2, "damage"); int spell_id = std::stoi(sep.arg[2]); if(IsValidSpell(spell_id)) { Lua_Spell l_spell(&spells[spell_id]); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); lua_setfield(L, -2, "spell"); } else { Lua_Spell l_spell(nullptr); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); lua_setfield(L, -2, "spell"); } lua_pushinteger(L, std::stoi(sep.arg[3])); lua_setfield(L, -2, "skill"); }
void handle_npc_death(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector<void*> *extra_pointers) { Lua_Mob l_mob(init); luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); l_mob_o.push(L); lua_setfield(L, -2, "other"); Seperator sep(data.c_str()); lua_pushinteger(L, std::stoi(sep.arg[0])); lua_setfield(L, -2, "damage"); int spell_id = std::stoi(sep.arg[1]); if(IsValidSpell(spell_id)) { Lua_Spell l_spell(&spells[spell_id]); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); lua_setfield(L, -2, "spell"); } else { Lua_Spell l_spell(nullptr); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); lua_setfield(L, -2, "spell"); } lua_pushinteger(L, std::stoi(sep.arg[2])); lua_setfield(L, -2, "skill_id"); }
void handle_player_cast(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data, std::vector<void*> *extra_pointers) { int spell_id = std::stoi(data); if(IsValidSpell(spell_id)) { Lua_Spell l_spell(&spells[spell_id]); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); } else { Lua_Spell l_spell(nullptr); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); } lua_setfield(L, -2, "spell"); }
void handle_item_proc(QuestInterface *parse, lua_State* L, Client* client, ItemInst* item, Mob *mob, std::string data, uint32 extra_data, std::vector<void*> *extra_pointers) { Lua_Mob l_mob(mob); luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); l_mob_o.push(L); lua_setfield(L, -2, "target"); if(IsValidSpell(extra_data)) { Lua_Spell l_spell(&spells[extra_data]); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); lua_setfield(L, -2, "spell"); } else { Lua_Spell l_spell(nullptr); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); lua_setfield(L, -2, "spell"); } }
int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, std::vector<void*> *extra_pointers, luabind::adl::object *l_func) { const char *sub_name = LuaEvents[evt]; int start = lua_gettop(L); try { int npop = 1; if(l_func != nullptr) { l_func->push(L); } else { lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str()); lua_getfield(L, -1, sub_name); npop = 2; } lua_createtable(L, 0, 0); //always push self even if invalid if(IsValidSpell(spell_id)) { Lua_Spell l_spell(&spells[spell_id]); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); } else { Lua_Spell l_spell(nullptr); luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); l_spell_o.push(L); } lua_setfield(L, -2, "self"); auto arg_function = SpellArgumentDispatch[evt]; arg_function(this, L, npc, client, spell_id, extra_data, extra_pointers); quest_manager.StartQuest(npc, client, nullptr); if(lua_pcall(L, 1, 1, 0)) { std::string error = lua_tostring(L, -1); AddError(error); quest_manager.EndQuest(); return 0; } quest_manager.EndQuest(); if(lua_isnumber(L, -1)) { int ret = static_cast<int>(lua_tointeger(L, -1)); lua_pop(L, npop); return ret; } lua_pop(L, npop); } catch(std::exception &ex) { std::string error = "Lua Exception: "; error += std::string(ex.what()); AddError(error); //Restore our stack to the best of our ability int end = lua_gettop(L); int n = end - start; if(n > 0) { lua_pop(L, n); } } return 0; }