mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-02 02:50:26 +00:00
Lua fixes, need to get perl working again D=
This commit is contained in:
+2
-2
@@ -1066,8 +1066,8 @@ void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID
|
|||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENT_SAY: {
|
case EVENT_SAY: {
|
||||||
if(npc && mob) {
|
if(npcmob && mob) {
|
||||||
npc->DoQuestPause(mob);
|
npcmob->DoQuestPause(mob);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExportVar(package_name.c_str(), "data", objid);
|
ExportVar(package_name.c_str(), "data", objid);
|
||||||
|
|||||||
+36
-38
@@ -220,7 +220,8 @@ XS(XS__spawn)
|
|||||||
float y = (float)SvNV(ST(4));
|
float y = (float)SvNV(ST(4));
|
||||||
float z = (float)SvNV(ST(5));
|
float z = (float)SvNV(ST(5));
|
||||||
|
|
||||||
RETVAL = quest_manager.spawn2(npc_type, grid, unused, x, y, z, 0);
|
Mob *r = quest_manager.spawn2(npc_type, grid, unused, x, y, z, 0);
|
||||||
|
RETVAL = (r != nullptr) ? r->GetID() : 0;
|
||||||
XSprePUSH; PUSHu((UV)RETVAL);
|
XSprePUSH; PUSHu((UV)RETVAL);
|
||||||
|
|
||||||
XSRETURN(1);
|
XSRETURN(1);
|
||||||
@@ -244,7 +245,8 @@ XS(XS__spawn2)
|
|||||||
float z = (float)SvNV(ST(5));
|
float z = (float)SvNV(ST(5));
|
||||||
float heading = (float)SvNV(ST(6));
|
float heading = (float)SvNV(ST(6));
|
||||||
|
|
||||||
RETVAL = quest_manager.spawn2(npc_type, grid, unused, x, y, z, heading);
|
Mob *r = quest_manager.spawn2(npc_type, grid, unused, x, y, z, heading);
|
||||||
|
RETVAL = (r != nullptr) ? r->GetID() : 0;
|
||||||
XSprePUSH; PUSHu((UV)RETVAL);
|
XSprePUSH; PUSHu((UV)RETVAL);
|
||||||
|
|
||||||
XSRETURN(1);
|
XSRETURN(1);
|
||||||
@@ -270,7 +272,9 @@ XS(XS__unique_spawn)
|
|||||||
if(items == 7)
|
if(items == 7)
|
||||||
heading = (float)SvNV(ST(6));
|
heading = (float)SvNV(ST(6));
|
||||||
|
|
||||||
RETVAL = quest_manager.unique_spawn(npc_type, grid, unused, x, y, z, heading);
|
Mob *r = quest_manager.unique_spawn(npc_type, grid, unused, x, y, z, heading);
|
||||||
|
RETVAL = (r != nullptr) ? r->GetID() : 0;
|
||||||
|
|
||||||
XSprePUSH; PUSHu((UV)RETVAL);
|
XSprePUSH; PUSHu((UV)RETVAL);
|
||||||
|
|
||||||
XSRETURN(1);
|
XSRETURN(1);
|
||||||
@@ -288,7 +292,9 @@ XS(XS__spawn_from_spawn2)
|
|||||||
|
|
||||||
int spawn2_id = (int)SvIV(ST(0));
|
int spawn2_id = (int)SvIV(ST(0));
|
||||||
|
|
||||||
RETVAL = quest_manager.spawn_from_spawn2(spawn2_id);
|
Mob *r = quest_manager.spawn_from_spawn2(spawn2_id);
|
||||||
|
RETVAL = (r != nullptr) ? r->GetID() : 0;
|
||||||
|
|
||||||
XSprePUSH; PUSHu((UV)RETVAL);
|
XSprePUSH; PUSHu((UV)RETVAL);
|
||||||
|
|
||||||
XSRETURN(1);
|
XSRETURN(1);
|
||||||
@@ -1557,6 +1563,30 @@ XS(XS__clear_proximity)
|
|||||||
XSRETURN_EMPTY;
|
XSRETURN_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XS(XS__enable_proximity_say);
|
||||||
|
XS(XS__enable_proximity_say)
|
||||||
|
{
|
||||||
|
dXSARGS;
|
||||||
|
if (items != 0)
|
||||||
|
Perl_croak(aTHX_ "Usage: enable_proximity_say()");
|
||||||
|
|
||||||
|
quest_manager.enable_proximity_say();
|
||||||
|
|
||||||
|
XSRETURN_EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
XS(XS__disable_proximity_say);
|
||||||
|
XS(XS__disable_proximity_say)
|
||||||
|
{
|
||||||
|
dXSARGS;
|
||||||
|
if (items != 0)
|
||||||
|
Perl_croak(aTHX_ "Usage: disable_proximity_say()");
|
||||||
|
|
||||||
|
quest_manager.disable_proximity_say();
|
||||||
|
|
||||||
|
XSRETURN_EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
XS(XS__setanim);
|
XS(XS__setanim);
|
||||||
XS(XS__setanim) //Cisyouc: mob->setappearance() addition
|
XS(XS__setanim) //Cisyouc: mob->setappearance() addition
|
||||||
{
|
{
|
||||||
@@ -1581,38 +1611,6 @@ XS(XS__showgrid)
|
|||||||
XSRETURN_EMPTY;
|
XSRETURN_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
XS(XS__showpath);
|
|
||||||
XS(XS__showpath)
|
|
||||||
{
|
|
||||||
dXSARGS;
|
|
||||||
if (items != 3)
|
|
||||||
Perl_croak(aTHX_ "Usage: showpath(x, y, z)");
|
|
||||||
|
|
||||||
float x = (float)SvNV(ST(0));
|
|
||||||
float y = (float)SvNV(ST(1));
|
|
||||||
float z = (float)SvNV(ST(2));
|
|
||||||
|
|
||||||
quest_manager.showpath(x, y, z);
|
|
||||||
|
|
||||||
XSRETURN_EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
XS(XS__pathto);
|
|
||||||
XS(XS__pathto)
|
|
||||||
{
|
|
||||||
dXSARGS;
|
|
||||||
if (items != 3)
|
|
||||||
Perl_croak(aTHX_ "Usage: pathto(x, y, z)");
|
|
||||||
|
|
||||||
float x = (float)SvNV(ST(0));
|
|
||||||
float y = (float)SvNV(ST(1));
|
|
||||||
float z = (float)SvNV(ST(2));
|
|
||||||
|
|
||||||
quest_manager.pathto(x, y, z);
|
|
||||||
|
|
||||||
XSRETURN_EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
XS(XS__spawn_condition);
|
XS(XS__spawn_condition);
|
||||||
XS(XS__spawn_condition)
|
XS(XS__spawn_condition)
|
||||||
{
|
{
|
||||||
@@ -3421,10 +3419,10 @@ EXTERN_C XS(boot_quest)
|
|||||||
newXS(strcpy(buf, "ChooseRandom"), XS__ChooseRandom, file);
|
newXS(strcpy(buf, "ChooseRandom"), XS__ChooseRandom, file);
|
||||||
newXS(strcpy(buf, "set_proximity"), XS__set_proximity, file);
|
newXS(strcpy(buf, "set_proximity"), XS__set_proximity, file);
|
||||||
newXS(strcpy(buf, "clear_proximity"), XS__clear_proximity, file);
|
newXS(strcpy(buf, "clear_proximity"), XS__clear_proximity, file);
|
||||||
|
newXS(strcpy(buf, "enable_proximity_say"), XS__enable_proximity_say, file);
|
||||||
|
newXS(strcpy(buf, "disable_proximity_say"), XS__disable_proximity_say, file);
|
||||||
newXS(strcpy(buf, "setanim"), XS__setanim, file);
|
newXS(strcpy(buf, "setanim"), XS__setanim, file);
|
||||||
newXS(strcpy(buf, "showgrid"), XS__showgrid, file);
|
newXS(strcpy(buf, "showgrid"), XS__showgrid, file);
|
||||||
newXS(strcpy(buf, "showpath"), XS__showpath, file);
|
|
||||||
newXS(strcpy(buf, "pathto"), XS__pathto, file);
|
|
||||||
newXS(strcpy(buf, "spawn_condition"), XS__spawn_condition, file);
|
newXS(strcpy(buf, "spawn_condition"), XS__spawn_condition, file);
|
||||||
newXS(strcpy(buf, "get_spawn_condition"), XS__get_spawn_condition, file);
|
newXS(strcpy(buf, "get_spawn_condition"), XS__get_spawn_condition, file);
|
||||||
newXS(strcpy(buf, "toggle_spawn_event"), XS__toggle_spawn_event, file);
|
newXS(strcpy(buf, "toggle_spawn_event"), XS__toggle_spawn_event, file);
|
||||||
|
|||||||
+187
-16
@@ -7,7 +7,11 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "lua_parser.h"
|
#include "lua_parser.h"
|
||||||
|
#include "lua_item.h"
|
||||||
|
#include "lua_iteminst.h"
|
||||||
|
#include "lua_mob.h"
|
||||||
#include "QuestParserCollection.h"
|
#include "QuestParserCollection.h"
|
||||||
|
#include "questmgr.h"
|
||||||
|
|
||||||
struct Events { };
|
struct Events { };
|
||||||
|
|
||||||
@@ -27,35 +31,202 @@ void unload_encounter(std::string name) {
|
|||||||
parse->EventEncounter(EVENT_ENCOUNTER_UNLOAD, name, 0);
|
parse->EventEncounter(EVENT_ENCOUNTER_UNLOAD, name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void register_event(std::string package_name, std::string name, int evt, luabind::object func) {
|
||||||
|
lua_registered_event e;
|
||||||
|
e.encounter_name = name;
|
||||||
|
e.lua_reference = func;
|
||||||
|
e.event_id = static_cast<QuestEventID>(evt);
|
||||||
|
|
||||||
|
auto liter = lua_encounter_events_registered.find(package_name);
|
||||||
|
if(liter == lua_encounter_events_registered.end()) {
|
||||||
|
std::list<lua_registered_event> elist;
|
||||||
|
elist.push_back(e);
|
||||||
|
lua_encounter_events_registered[package_name] = elist;
|
||||||
|
} else {
|
||||||
|
std::list<lua_registered_event> elist = liter->second;
|
||||||
|
auto iter = elist.begin();
|
||||||
|
while(iter != elist.end()) {
|
||||||
|
if(iter->event_id == evt && iter->encounter_name.compare(name) == 0) {
|
||||||
|
//already registered this event for this encounter
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
elist.push_back(e);
|
||||||
|
lua_encounter_events_registered[package_name] = elist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister_event(std::string package_name, std::string name, int evt) {
|
||||||
|
auto liter = lua_encounter_events_registered.find(package_name);
|
||||||
|
if(liter != lua_encounter_events_registered.end()) {
|
||||||
|
std::list<lua_registered_event> elist = liter->second;
|
||||||
|
auto iter = elist.begin();
|
||||||
|
while(iter != elist.end()) {
|
||||||
|
if(iter->event_id == evt && iter->encounter_name.compare(name) == 0) {
|
||||||
|
iter = elist.erase(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lua_encounter_events_registered[package_name] = elist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void register_npc_event(std::string name, int evt, int npc_id, luabind::object func) {
|
void register_npc_event(std::string name, int evt, int npc_id, luabind::object func) {
|
||||||
if(luabind::type(func) == LUA_TFUNCTION) {
|
if(luabind::type(func) == LUA_TFUNCTION) {
|
||||||
std::stringstream package_name;
|
std::stringstream package_name;
|
||||||
package_name << "npc_" << npc_id;
|
package_name << "npc_" << npc_id;
|
||||||
|
|
||||||
lua_registered_event e;
|
register_event(package_name.str(), name, evt, func);
|
||||||
e.encounter_name = name;
|
|
||||||
e.lua_reference = func;
|
|
||||||
e.event_id = static_cast<QuestEventID>(evt);
|
|
||||||
|
|
||||||
auto liter = lua_encounter_events_registered.find(package_name.str());
|
|
||||||
if(liter == lua_encounter_events_registered.end()) {
|
|
||||||
std::list<lua_registered_event> elist;
|
|
||||||
elist.push_back(e);
|
|
||||||
lua_encounter_events_registered[package_name.str()] = elist;
|
|
||||||
} else {
|
|
||||||
std::list<lua_registered_event> elist = liter->second;
|
|
||||||
elist.push_back(e);
|
|
||||||
lua_encounter_events_registered[package_name.str()] = elist;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unregister_npc_event(std::string name, int evt, int npc_id) {
|
||||||
|
std::stringstream package_name;
|
||||||
|
package_name << "npc_" << npc_id;
|
||||||
|
|
||||||
|
unregister_event(package_name.str(), name, evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_player_event(std::string name, int evt, luabind::object func) {
|
||||||
|
if(luabind::type(func) == LUA_TFUNCTION) {
|
||||||
|
register_event("player", name, evt, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister_player_event(std::string name, int evt) {
|
||||||
|
unregister_event("player", name, evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_item_event(std::string name, int evt, Lua_Item item, luabind::object func) {
|
||||||
|
const Item_Struct *itm = item;
|
||||||
|
if(!itm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream package_name;
|
||||||
|
package_name << "item_";
|
||||||
|
|
||||||
|
std::stringstream item_name;
|
||||||
|
if(EVENT_SCALE_CALC == evt || EVENT_ITEM_ENTER_ZONE == evt)
|
||||||
|
{
|
||||||
|
item_name << itm->CharmFile;
|
||||||
|
}
|
||||||
|
else if(EVENT_ITEM_CLICK == evt || EVENT_ITEM_CLICK_CAST == evt)
|
||||||
|
{
|
||||||
|
item_name << "script_";
|
||||||
|
item_name << itm->ScriptFileID;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item_name << "item_";
|
||||||
|
item_name << itm->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
package_name << item_name;
|
||||||
|
|
||||||
|
if(luabind::type(func) == LUA_TFUNCTION) {
|
||||||
|
register_event(package_name.str(), name, evt, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister_item_event(std::string name, int evt, Lua_Item item) {
|
||||||
|
const Item_Struct *itm = item;
|
||||||
|
if(!itm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream package_name;
|
||||||
|
package_name << "item_";
|
||||||
|
|
||||||
|
std::stringstream item_name;
|
||||||
|
if(EVENT_SCALE_CALC == evt || EVENT_ITEM_ENTER_ZONE == evt)
|
||||||
|
{
|
||||||
|
item_name << itm->CharmFile;
|
||||||
|
}
|
||||||
|
else if(EVENT_ITEM_CLICK == evt || EVENT_ITEM_CLICK_CAST == evt)
|
||||||
|
{
|
||||||
|
item_name << "script_";
|
||||||
|
item_name << itm->ScriptFileID;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item_name << "item_";
|
||||||
|
item_name << itm->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
package_name << item_name;
|
||||||
|
unregister_event(package_name.str(), name, evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_spell_event(std::string name, int evt, int spell_id, luabind::object func) {
|
||||||
|
if(luabind::type(func) == LUA_TFUNCTION) {
|
||||||
|
std::stringstream package_name;
|
||||||
|
package_name << "spell_" << spell_id;
|
||||||
|
|
||||||
|
register_event(package_name.str(), name, evt, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister_spell_event(std::string name, int evt, int spell_id) {
|
||||||
|
std::stringstream package_name;
|
||||||
|
package_name << "spell_" << spell_id;
|
||||||
|
|
||||||
|
unregister_event(package_name.str(), name, evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lua_say(const char *str) {
|
||||||
|
quest_manager.say(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lua_say(const char *str, int language) {
|
||||||
|
quest_manager.say(str, language);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lua_me(const char *str) {
|
||||||
|
quest_manager.me(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lua_summon_item(uint32 itemid, int charges = 0) {
|
||||||
|
quest_manager.summonitem(itemid, charges);
|
||||||
|
}
|
||||||
|
|
||||||
|
Lua_Mob lua_spawn2(int npc_type, int grid, int unused, double x, double y, double z, double heading) {
|
||||||
|
return Lua_Mob(quest_manager.spawn2(npc_type, grid, unused,
|
||||||
|
static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(heading)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Lua_Mob lua_unique_spawn(int npc_type, int grid, int unused, double x, double y, double z, double heading = 0.0) {
|
||||||
|
return Lua_Mob(quest_manager.unique_spawn(npc_type, grid, unused,
|
||||||
|
static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(heading)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Lua_Mob lua_spawn_from_spawn2(uint32 spawn2_id) {
|
||||||
|
return Lua_Mob(quest_manager.spawn_from_spawn2(spawn2_id));
|
||||||
|
}
|
||||||
|
|
||||||
luabind::scope lua_register_general() {
|
luabind::scope lua_register_general() {
|
||||||
return luabind::namespace_("eq")
|
return luabind::namespace_("eq")
|
||||||
[
|
[
|
||||||
luabind::def("load_encounter", &load_encounter),
|
luabind::def("load_encounter", &load_encounter),
|
||||||
luabind::def("unload_encounter", &unload_encounter),
|
luabind::def("unload_encounter", &unload_encounter),
|
||||||
luabind::def("register_npc_event", ®ister_npc_event)
|
luabind::def("register_npc_event", ®ister_npc_event),
|
||||||
|
luabind::def("unregister_npc_event", &unregister_npc_event),
|
||||||
|
luabind::def("register_player_event", ®ister_player_event),
|
||||||
|
luabind::def("unregister_player_event", &unregister_player_event),
|
||||||
|
luabind::def("register_item_event", ®ister_item_event),
|
||||||
|
luabind::def("unregister_item_event", &unregister_item_event),
|
||||||
|
luabind::def("register_spell_event", ®ister_spell_event),
|
||||||
|
luabind::def("unregister_spell_event", &unregister_spell_event),
|
||||||
|
luabind::def("say", (void(*)(const char*))&lua_say),
|
||||||
|
luabind::def("say", (void(*)(const char*, int))&lua_say),
|
||||||
|
luabind::def("me", (void(*)(const char*))&lua_me),
|
||||||
|
luabind::def("summon_item", (void(*)(uint32))&lua_summon_item),
|
||||||
|
luabind::def("summon_item", (void(*)(uint32,int))&lua_summon_item),
|
||||||
|
luabind::def("spawn2", (Lua_Mob(*)(int,int,int,double,double,double,double))&lua_spawn2),
|
||||||
|
luabind::def("unique_spawn", (Lua_Mob(*)(int,int,int,double,double,double))&lua_unique_spawn),
|
||||||
|
luabind::def("unique_spawn", (Lua_Mob(*)(int,int,int,double,double,double,double))&lua_unique_spawn),
|
||||||
|
luabind::def("spawn_from_spawn2", (Lua_Mob(*)(uint32))&lua_spawn_from_spawn2)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-3
@@ -24,6 +24,7 @@
|
|||||||
#include "lua_general.h"
|
#include "lua_general.h"
|
||||||
#include "zone.h"
|
#include "zone.h"
|
||||||
|
|
||||||
|
#include "questmgr.h"
|
||||||
#include "lua_parser.h"
|
#include "lua_parser.h"
|
||||||
|
|
||||||
const char *LuaEvents[_LargestEventID] = {
|
const char *LuaEvents[_LargestEventID] = {
|
||||||
@@ -202,11 +203,15 @@ int LuaParser::_EventNPC(std::string package_name, QuestEventID evt, NPC* npc, M
|
|||||||
auto arg_function = NPCArgumentDispatch[evt];
|
auto arg_function = NPCArgumentDispatch[evt];
|
||||||
arg_function(this, L, npc, init, data, extra_data);
|
arg_function(this, L, npc, init, data, extra_data);
|
||||||
|
|
||||||
|
Client *c = (init && init->IsClient()) ? init->CastToClient() : nullptr;
|
||||||
|
quest_manager.StartQuest(npc, c, nullptr);
|
||||||
if(lua_pcall(L, 1, 1, 0)) {
|
if(lua_pcall(L, 1, 1, 0)) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
AddError(error);
|
AddError(error);
|
||||||
|
quest_manager.EndQuest();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
quest_manager.EndQuest();
|
||||||
|
|
||||||
if(lua_isnumber(L, -1)) {
|
if(lua_isnumber(L, -1)) {
|
||||||
int ret = static_cast<int>(lua_tointeger(L, -1));
|
int ret = static_cast<int>(lua_tointeger(L, -1));
|
||||||
@@ -288,11 +293,14 @@ int LuaParser::_EventPlayer(std::string package_name, QuestEventID evt, Client *
|
|||||||
auto arg_function = PlayerArgumentDispatch[evt];
|
auto arg_function = PlayerArgumentDispatch[evt];
|
||||||
arg_function(this, L, client, data, extra_data);
|
arg_function(this, L, client, data, extra_data);
|
||||||
|
|
||||||
|
quest_manager.StartQuest(nullptr, client, nullptr);
|
||||||
if(lua_pcall(L, 1, 1, 0)) {
|
if(lua_pcall(L, 1, 1, 0)) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
AddError(error);
|
AddError(error);
|
||||||
|
quest_manager.EndQuest();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
quest_manager.EndQuest();
|
||||||
|
|
||||||
if(lua_isnumber(L, -1)) {
|
if(lua_isnumber(L, -1)) {
|
||||||
int ret = static_cast<int>(lua_tointeger(L, -1));
|
int ret = static_cast<int>(lua_tointeger(L, -1));
|
||||||
@@ -379,11 +387,14 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl
|
|||||||
auto arg_function = ItemArgumentDispatch[evt];
|
auto arg_function = ItemArgumentDispatch[evt];
|
||||||
arg_function(this, L, client, item, objid, extra_data);
|
arg_function(this, L, client, item, objid, extra_data);
|
||||||
|
|
||||||
|
quest_manager.StartQuest(nullptr, client, item);
|
||||||
if(lua_pcall(L, 1, 1, 0)) {
|
if(lua_pcall(L, 1, 1, 0)) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
AddError(error);
|
AddError(error);
|
||||||
|
quest_manager.EndQuest();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
quest_manager.EndQuest();
|
||||||
|
|
||||||
if(lua_isnumber(L, -1)) {
|
if(lua_isnumber(L, -1)) {
|
||||||
int ret = static_cast<int>(lua_tointeger(L, -1));
|
int ret = static_cast<int>(lua_tointeger(L, -1));
|
||||||
@@ -450,11 +461,14 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc,
|
|||||||
auto arg_function = SpellArgumentDispatch[evt];
|
auto arg_function = SpellArgumentDispatch[evt];
|
||||||
arg_function(this, L, npc, client, spell_id, extra_data);
|
arg_function(this, L, npc, client, spell_id, extra_data);
|
||||||
|
|
||||||
|
quest_manager.StartQuest(npc, client, nullptr);
|
||||||
if(lua_pcall(L, 1, 1, 0)) {
|
if(lua_pcall(L, 1, 1, 0)) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
AddError(error);
|
AddError(error);
|
||||||
|
quest_manager.EndQuest();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
quest_manager.EndQuest();
|
||||||
|
|
||||||
if(lua_isnumber(L, -1)) {
|
if(lua_isnumber(L, -1)) {
|
||||||
int ret = static_cast<int>(lua_tointeger(L, -1));
|
int ret = static_cast<int>(lua_tointeger(L, -1));
|
||||||
@@ -502,14 +516,18 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std::
|
|||||||
lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str());
|
lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str());
|
||||||
lua_getfield(L, -1, sub_name);
|
lua_getfield(L, -1, sub_name);
|
||||||
|
|
||||||
//For now encounters just call event_encounter_load/event_encounter_unload with no arguments
|
lua_createtable(L, 0, 0);
|
||||||
//So we dont pass anything
|
lua_pushstring(L, encounter_name.c_str());
|
||||||
|
lua_setfield(L, -2, "name");
|
||||||
|
|
||||||
if(lua_pcall(L, 0, 1, 0)) {
|
quest_manager.StartQuest(nullptr, nullptr, nullptr);
|
||||||
|
if(lua_pcall(L, 1, 1, 0)) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
AddError(error);
|
AddError(error);
|
||||||
|
quest_manager.EndQuest();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
quest_manager.EndQuest();
|
||||||
|
|
||||||
if(lua_isnumber(L, -1)) {
|
if(lua_isnumber(L, -1)) {
|
||||||
int ret = static_cast<int>(lua_tointeger(L, -1));
|
int ret = static_cast<int>(lua_tointeger(L, -1));
|
||||||
|
|||||||
+4
-3
@@ -2473,10 +2473,11 @@ uint32 NPC::GetSpawnKillCount()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NPC::DoQuestPause(Mob *other) {
|
void NPC::DoQuestPause(Mob *other) {
|
||||||
if(IsMoving() && !IsOnHatelist(other))
|
if(IsMoving() && !IsOnHatelist(other)) {
|
||||||
PauseWandering(RuleI(NPC, SayPauseTimeInSec));
|
PauseWandering(RuleI(NPC, SayPauseTimeInSec));
|
||||||
|
|
||||||
if(!IsMoving())
|
|
||||||
FaceTarget(other);
|
FaceTarget(other);
|
||||||
|
} else if(!IsMoving()) {
|
||||||
|
FaceTarget(other);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+234
-74
File diff suppressed because it is too large
Load Diff
+22
-30
@@ -18,18 +18,24 @@
|
|||||||
#ifndef __QUEST_MANAGER_H__
|
#ifndef __QUEST_MANAGER_H__
|
||||||
#define __QUEST_MANAGER_H__
|
#define __QUEST_MANAGER_H__
|
||||||
|
|
||||||
#include "../common/Mutex.h"
|
|
||||||
#include "../common/timer.h"
|
#include "../common/timer.h"
|
||||||
#include "tasks.h"
|
#include "tasks.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <stack>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class NPC;
|
class NPC;
|
||||||
class Client;
|
class Client;
|
||||||
|
|
||||||
class QuestManager {
|
class QuestManager {
|
||||||
|
struct running_quest {
|
||||||
|
Mob *owner;
|
||||||
|
Client *initiator;
|
||||||
|
ItemInst* questitem;
|
||||||
|
bool depop_npc;
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
QuestManager();
|
QuestManager();
|
||||||
virtual ~QuestManager();
|
virtual ~QuestManager();
|
||||||
@@ -42,21 +48,20 @@ public:
|
|||||||
void ClearTimers(Mob *who);
|
void ClearTimers(Mob *who);
|
||||||
void ClearAllTimers();
|
void ClearAllTimers();
|
||||||
|
|
||||||
//quest perl functions
|
//quest functions
|
||||||
void echo(int colour, const char *str);
|
void echo(int colour, const char *str);
|
||||||
void say(const char *str);
|
void say(const char *str);
|
||||||
void say(const char *str, uint8 language);
|
void say(const char *str, uint8 language);
|
||||||
void me(const char *str);
|
void me(const char *str);
|
||||||
void summonitem(uint32 itemid, int16 charges = 0);
|
void summonitem(uint32 itemid, int16 charges = 0);
|
||||||
//getZoneID(const char *short_name)
|
|
||||||
void write(const char *file, const char *str);
|
void write(const char *file, const char *str);
|
||||||
uint16 spawn2(int npc_type, int grid, int unused, float x, float y, float z, float heading);
|
Mob* spawn2(int npc_type, int grid, int unused, float x, float y, float z, float heading);
|
||||||
uint16 unique_spawn(int npc_type, int grid, int unused, float x, float y, float z, float heading = 0);
|
Mob* unique_spawn(int npc_type, int grid, int unused, float x, float y, float z, float heading = 0);
|
||||||
uint16 spawn_from_spawn2(uint32 spawn2_id);
|
Mob* spawn_from_spawn2(uint32 spawn2_id);
|
||||||
void enable_spawn2(uint32 spawn2_id);
|
void enable_spawn2(uint32 spawn2_id);
|
||||||
void disable_spawn2(uint32 spawn2_id);
|
void disable_spawn2(uint32 spawn2_id);
|
||||||
void setstat(int stat, int value);
|
void setstat(int stat, int value);
|
||||||
void incstat(int stat, int value); //old setstat command
|
void incstat(int stat, int value);
|
||||||
void castspell(int spell_id, int target_id);
|
void castspell(int spell_id, int target_id);
|
||||||
void selfcast(int spell_id);
|
void selfcast(int spell_id);
|
||||||
void addloot(int item_id, int charges = 0, bool equipitem = true);
|
void addloot(int item_id, int charges = 0, bool equipitem = true);
|
||||||
@@ -133,10 +138,10 @@ public:
|
|||||||
void respawn(int npc_type, int grid);
|
void respawn(int npc_type, int grid);
|
||||||
void set_proximity(float minx, float maxx, float miny, float maxy, float minz=-999999, float maxz=999999);
|
void set_proximity(float minx, float maxx, float miny, float maxy, float minz=-999999, float maxz=999999);
|
||||||
void clear_proximity();
|
void clear_proximity();
|
||||||
|
void enable_proximity_say();
|
||||||
|
void disable_proximity_say();
|
||||||
void setanim(int npc_type, int animnum);
|
void setanim(int npc_type, int animnum);
|
||||||
void showgrid(int gridid);
|
void showgrid(int gridid);
|
||||||
void showpath(float x, float y, float z);
|
|
||||||
void pathto(float x, float y, float z);
|
|
||||||
void spawn_condition(const char *zone_short, uint32 instance_id, uint16 condition_id, short new_value);
|
void spawn_condition(const char *zone_short, uint32 instance_id, uint16 condition_id, short new_value);
|
||||||
short get_spawn_condition(const char *zone_short, uint32 instance_id, uint16 condition_id);
|
short get_spawn_condition(const char *zone_short, uint32 instance_id, uint16 condition_id);
|
||||||
void toggle_spawn_event(int event_id, bool enable, bool reset_base);
|
void toggle_spawn_event(int event_id, bool enable, bool reset_base);
|
||||||
@@ -195,15 +200,12 @@ public:
|
|||||||
void enabletitle(int titleset);
|
void enabletitle(int titleset);
|
||||||
bool checktitle(int titlecheck);
|
bool checktitle(int titlecheck);
|
||||||
void removetitle(int titlecheck);
|
void removetitle(int titlecheck);
|
||||||
|
|
||||||
uint16 CreateGroundObject(uint32 itemid, float x, float y, float z, float heading, uint32 decay_time = 300000);
|
uint16 CreateGroundObject(uint32 itemid, float x, float y, float z, float heading, uint32 decay_time = 300000);
|
||||||
uint16 CreateGroundObjectFromModel(const char* model, float x, float y, float z, float heading, uint8 type = 0x00, uint32 decay_time = 0);
|
uint16 CreateGroundObjectFromModel(const char* model, float x, float y, float z, float heading, uint8 type = 0x00, uint32 decay_time = 0);
|
||||||
void ModifyNPCStat(const char *identifier, const char *newValue);
|
void ModifyNPCStat(const char *identifier, const char *newValue);
|
||||||
void UpdateSpawnTimer(uint32 id, uint32 newTime);
|
void UpdateSpawnTimer(uint32 id, uint32 newTime);
|
||||||
|
|
||||||
void MerchantSetItem(uint32 NPCid, uint32 itemid, uint32 quantity = 0);
|
void MerchantSetItem(uint32 NPCid, uint32 itemid, uint32 quantity = 0);
|
||||||
uint32 MerchantCountItem(uint32 NPCid, uint32 itemid);
|
uint32 MerchantCountItem(uint32 NPCid, uint32 itemid);
|
||||||
|
|
||||||
uint16 CreateInstance(const char *zone, int16 version, uint32 duration);
|
uint16 CreateInstance(const char *zone, int16 version, uint32 duration);
|
||||||
void DestroyInstance(uint16 instance_id);
|
void DestroyInstance(uint16 instance_id);
|
||||||
uint16 GetInstanceID(const char *zone, int16 version);
|
uint16 GetInstanceID(const char *zone, int16 version);
|
||||||
@@ -213,7 +215,6 @@ public:
|
|||||||
void MovePCInstance(int zone_id, int instance_id, float x, float y, float z, float heading);
|
void MovePCInstance(int zone_id, int instance_id, float x, float y, float z, float heading);
|
||||||
void FlagInstanceByGroupLeader(uint32 zone, int16 version);
|
void FlagInstanceByGroupLeader(uint32 zone, int16 version);
|
||||||
void FlagInstanceByRaidLeader(uint32 zone, int16 version);
|
void FlagInstanceByRaidLeader(uint32 zone, int16 version);
|
||||||
|
|
||||||
const char* varlink(char* perltext, int item_id);
|
const char* varlink(char* perltext, int item_id);
|
||||||
const char* saylink(char* Phrase, bool silent, char* LinkName);
|
const char* saylink(char* Phrase, bool silent, char* LinkName);
|
||||||
const char* getguildnamebyid(int guild_id);
|
const char* getguildnamebyid(int guild_id);
|
||||||
@@ -228,20 +229,16 @@ public:
|
|||||||
uint16 CreateDoor( const char* model, float x, float y, float z, float heading, uint8 opentype, uint16 size);
|
uint16 CreateDoor( const char* model, float x, float y, float z, float heading, uint8 opentype, uint16 size);
|
||||||
int32 GetZoneID(const char *zone);
|
int32 GetZoneID(const char *zone);
|
||||||
const char *GetZoneLongName(const char *zone);
|
const char *GetZoneLongName(const char *zone);
|
||||||
|
|
||||||
//not in here because it retains perl types
|
|
||||||
//thing ChooseRandom(array_of_things)
|
|
||||||
|
|
||||||
inline Client *GetInitiator() const { return(initiator); }
|
|
||||||
inline NPC *GetNPC() const { return(owner->IsNPC()?owner->CastToNPC():nullptr); }
|
|
||||||
inline Mob *GetOwner() const { return(owner); }
|
|
||||||
inline ItemInst *GetQuestItem() const {return questitem; }
|
|
||||||
inline bool ProximitySayInUse() { return HaveProximitySays; }
|
|
||||||
|
|
||||||
void CrossZoneSignalPlayerByCharID(int charid, uint32 data);
|
void CrossZoneSignalPlayerByCharID(int charid, uint32 data);
|
||||||
void CrossZoneSignalPlayerByName(const char *CharName, uint32 data);
|
void CrossZoneSignalPlayerByName(const char *CharName, uint32 data);
|
||||||
void CrossZoneMessagePlayerByName(uint32 Type, const char *CharName, const char *Message);
|
void CrossZoneMessagePlayerByName(uint32 Type, const char *CharName, const char *Message);
|
||||||
|
|
||||||
|
Client *GetInitiator() const;
|
||||||
|
NPC *GetNPC() const;
|
||||||
|
Mob *GetOwner() const;
|
||||||
|
ItemInst *GetQuestItem() const;
|
||||||
|
inline bool ProximitySayInUse() { return HaveProximitySays; }
|
||||||
|
|
||||||
#ifdef BOTS
|
#ifdef BOTS
|
||||||
int createbotcount();
|
int createbotcount();
|
||||||
int spawnbotcount();
|
int spawnbotcount();
|
||||||
@@ -251,14 +248,9 @@ public:
|
|||||||
|
|
||||||
inline uint16 GetMana(uint32 spell_id) { return( spells[spell_id].mana); }
|
inline uint16 GetMana(uint32 spell_id) { return( spells[spell_id].mana); }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
Mob *owner; //NPC is never nullptr when functions are called.
|
std::stack<running_quest> quests_running_;
|
||||||
Client *initiator; //this can be null.
|
|
||||||
ItemInst* questitem; // this is usually nullptr.
|
|
||||||
|
|
||||||
bool depop_npc; //true if EndQuest should depop the NPC
|
|
||||||
|
|
||||||
Mutex quest_mutex;
|
|
||||||
bool HaveProximitySays;
|
bool HaveProximitySays;
|
||||||
|
|
||||||
int QGVarDuration(const char *fmt);
|
int QGVarDuration(const char *fmt);
|
||||||
|
|||||||
Reference in New Issue
Block a user