| 759 | } |
| 760 | |
| 761 | int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, Mob* mob, Client *client, uint32 spell_id, std::string data, uint32 extra_data, |
| 762 | std::vector<std::any> *extra_pointers, luabind::adl::object *l_func) { |
| 763 | const char *sub_name = LuaEvents[evt]; |
| 764 | |
| 765 | int start = lua_gettop(L); |
| 766 | |
| 767 | try { |
| 768 | int npop = 2; |
| 769 | PushErrorHandler(L); |
| 770 | if(l_func != nullptr) { |
| 771 | l_func->push(L); |
| 772 | } else { |
| 773 | lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str()); |
| 774 | lua_getfield(L, -1, sub_name); |
| 775 | npop = 3; |
| 776 | } |
| 777 | |
| 778 | lua_createtable(L, 0, 0); |
| 779 | |
| 780 | //always push self even if invalid |
| 781 | if(IsValidSpell(spell_id)) { |
| 782 | Lua_Spell l_spell(&spells[spell_id]); |
| 783 | luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); |
| 784 | l_spell_o.push(L); |
| 785 | } else { |
| 786 | Lua_Spell l_spell(nullptr); |
| 787 | luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); |
| 788 | l_spell_o.push(L); |
| 789 | } |
| 790 | lua_setfield(L, -2, "self"); |
| 791 | |
| 792 | auto arg_function = SpellArgumentDispatch[evt]; |
| 793 | arg_function(this, L, mob, client, spell_id, data, extra_data, extra_pointers); |
| 794 | |
| 795 | RunningQuest q; |
| 796 | |
| 797 | q.owner = client; |
| 798 | q.initiator = client; |
| 799 | q.questspell = const_cast<SPDat_Spell_Struct*>(&spells[spell_id]); |
| 800 | |
| 801 | quest_manager.StartQuest(q); |
| 802 | |
| 803 | if(lua_pcall(L, 1, 1, start + 1)) { |
| 804 | std::string error = lua_tostring(L, -1); |
| 805 | AddError(error); |
| 806 | quest_manager.EndQuest(); |
| 807 | lua_pop(L, npop); |
| 808 | return 0; |
| 809 | } |
| 810 | quest_manager.EndQuest(); |
| 811 | |
| 812 | if(lua_isnumber(L, -1)) { |
| 813 | int ret = static_cast<int>(lua_tointeger(L, -1)); |
| 814 | lua_pop(L, npop); |
| 815 | return ret; |
| 816 | } |
| 817 | |
| 818 | lua_pop(L, npop); |
nothing calls this directly
no test coverage detected