Working on fixing up QuestInterface to make multiple parsers work together in harmony, need to fix up Embperl parser next

This commit is contained in:
KimLS 2013-05-05 23:36:15 -07:00
parent e1c2657b11
commit 6e9e81a890
10 changed files with 678 additions and 605 deletions

View File

@ -113,6 +113,7 @@ OPTION(EQEMU_BUILD_LOGIN "Build the login server." OFF)
OPTION(EQEMU_BUILD_AZONE "Build azone utility." OFF)
OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
OPTION(EQEMU_BUILD_LUA "Build Lua parser." OFF)
#C++11 stuff
IF(NOT MSVC)
@ -133,6 +134,10 @@ IF(EQEMU_BUILD_PERL)
ADD_DEFINITIONS(-DEMBPERL)
ADD_DEFINITIONS(-DEMBPERL_PLUGIN)
ENDIF(EQEMU_BUILD_PERL)
IF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DLUA_EQEMU)
ENDIF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DEQDEBUG=${EQEMU_DEBUG_LEVEL})
ADD_DEFINITIONS(-DINVERSEXY)
ADD_DEFINITIONS(-DFIELD_ITEMS)
@ -145,6 +150,12 @@ IF(EQEMU_BUILD_PERL)
FIND_PACKAGE(PerlLibs REQUIRED)
INCLUDE_DIRECTORIES("${PERL_INCLUDE_PATH}")
ENDIF(EQEMU_BUILD_PERL)
IF(EQEMU_BUILD_LUA)
FIND_PACKAGE(Lua51 REQUIRED)
INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}")
ENDIF(EQEMU_BUILD_LUA)
INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${MySQL_INCLUDE_DIR}")
IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS)

View File

@ -30,6 +30,7 @@ SET(zone_sources
horse.cpp
inventory.cpp
loottables.cpp
lua_parser.cpp
Map.cpp
merc.cpp
mob.cpp
@ -109,6 +110,7 @@ SET(zone_headers
guild_mgr.h
hate_list.h
horse.h
lua_parser.h
map.h
masterentity.h
maxskill.h
@ -155,7 +157,7 @@ ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers})
ADD_DEFINITIONS(-DZONE)
TARGET_LINK_LIBRARIES(zone Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(zone Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} ${LUA_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(zone PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
@ -175,6 +177,4 @@ IF(UNIX)
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
INCLUDE_DIRECTORIES(${VLD_INCLUDE_DIR})
SET(EXECUTABLE_OUTPUT_PATH ../Bin)

View File

@ -24,6 +24,13 @@ public:
virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname) { return false; }
virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname) { return false; }
virtual void LoadNPCScript(std::string filename, int npc_id) { }
//virtual void LoadGlobalNPCScript(std::string filename) { }
virtual void LoadPlayerScript(std::string filename) { }
//virtual void LoadGlobalPlayerScript(std::string filename) { }
virtual void LoadItemScript(std::string filename, std::string item_script) { }
virtual void LoadSpellScript(std::string filename, uint32 spell_id) { }
virtual void AddVar(std::string name, std::string val) { }
virtual void ReloadQuests(bool reset_timers = true) { }
virtual uint32 GetIdentifier() { return 0; }

View File

@ -14,8 +14,8 @@ extern Zone* zone;
QuestParserCollection::QuestParserCollection() {
_player_quest_status = QuestUnloaded;
_global_player_quest_status = QuestUnloaded;
_global_npc_quest_status = QuestUnloaded;
//_global_player_quest_status = QuestUnloaded;
//_global_npc_quest_status = QuestUnloaded;
}
QuestParserCollection::~QuestParserCollection() {
@ -38,8 +38,8 @@ void QuestParserCollection::AddVar(std::string name, std::string val) {
void QuestParserCollection::ReloadQuests(bool reset_timers) {
_npc_quest_status.clear();
_player_quest_status = QuestUnloaded;
_global_player_quest_status = QuestUnloaded;
_global_npc_quest_status = QuestUnloaded;
//_global_player_quest_status = QuestUnloaded;
//_global_npc_quest_status = QuestUnloaded;
_spell_quest_status.clear();
_item_quest_status.clear();
std::list<QuestInterface*>::iterator iter = _load_precedence.begin();
@ -61,9 +61,12 @@ bool QuestParserCollection::HasQuestSub(uint32 npcid, const char *subname) {
}
}
} else {
QuestInterface *qi = GetQIByNPCQuest(npcid);
std::string filename;
QuestInterface *qi = GetQIByNPCQuest(npcid, filename);
if(qi) {
_npc_quest_status[npcid] = qi->GetIdentifier();
qi->LoadNPCScript(filename, npcid);
if(qi->HasQuestSub(npcid, subname)) {
return true;
}
@ -72,40 +75,45 @@ bool QuestParserCollection::HasQuestSub(uint32 npcid, const char *subname) {
}
}
if(_global_npc_quest_status == QuestUnloaded){
QuestInterface *qi = GetQIByGlobalNPCQuest();
if(qi) {
_global_npc_quest_status = qi->GetIdentifier();
if(qi->HasGlobalQuestSub(subname)) {
return true;
}
}
} else {
if(_global_npc_quest_status != QuestFailedToLoad) {
std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(_global_npc_quest_status);
if(qiter->second->HasGlobalQuestSub(subname)) {
return true;
}
}
}
//if(_global_npc_quest_status == QuestUnloaded){
// std::string filename;
// QuestInterface *qi = GetQIByGlobalNPCQuest(filename);
// if(qi) {
// qi->LoadGlobalNPCScript(filename);
// _global_npc_quest_status = qi->GetIdentifier();
// if(qi->HasGlobalQuestSub(subname)) {
// return true;
// }
// }
//} else {
// if(_global_npc_quest_status != QuestFailedToLoad) {
// std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(_global_npc_quest_status);
// if(qiter->second->HasGlobalQuestSub(subname)) {
// return true;
// }
// }
//}
return false;
}
bool QuestParserCollection::PlayerHasQuestSub(const char *subname) {
if(_player_quest_status == QuestUnloaded) {
QuestInterface *qi = GetQIByGlobalPlayerQuest();
if(qi) {
_global_player_quest_status = qi->GetIdentifier();
}
std::string filename;
//QuestInterface *qi = GetQIByGlobalPlayerQuest(filename);
//if(qi) {
// _global_player_quest_status = qi->GetIdentifier();
// qi->LoadGlobalPlayerScript(filename);
//}
qi = GetQIByPlayerQuest();
QuestInterface *qi = GetQIByPlayerQuest(filename);
if(qi) {
_player_quest_status = qi->GetIdentifier();
return qi->PlayerHasQuestSub(subname) || qi->GlobalPlayerHasQuestSub(subname);
qi->LoadPlayerScript(filename);
return qi->PlayerHasQuestSub(subname); // || qi->GlobalPlayerHasQuestSub(subname);
}
} else if(_player_quest_status != QuestFailedToLoad) {
std::map<uint32, QuestInterface*>::iterator iter = _interfaces.find(_player_quest_status);
return iter->second->PlayerHasQuestSub(subname) || iter->second->GlobalPlayerHasQuestSub(subname);
return iter->second->PlayerHasQuestSub(subname); // || iter->second->GlobalPlayerHasQuestSub(subname);
}
return false;
}
@ -119,9 +127,11 @@ bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, const char *subnam
return qiter->second->SpellHasQuestSub(spell_id, subname);
}
} else {
QuestInterface *qi = GetQIBySpellQuest(spell_id);
std::string filename;
QuestInterface *qi = GetQIBySpellQuest(spell_id, filename);
if(qi) {
_spell_quest_status[spell_id] = qi->GetIdentifier();
qi->LoadSpellScript(filename, spell_id);
return qi->SpellHasQuestSub(spell_id, subname);
} else {
_spell_quest_status[spell_id] = QuestFailedToLoad;
@ -149,9 +159,11 @@ bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, const char *subname)
return qiter->second->ItemHasQuestSub(itm, subname);
}
} else {
QuestInterface *qi = GetQIByItemQuest(item_script);
std::string filename;
QuestInterface *qi = GetQIByItemQuest(item_script, filename);
if(qi) {
_item_quest_status[item_script] = qi->GetIdentifier();
qi->LoadItemScript(filename, item_script);
return qi->ItemHasQuestSub(itm, subname);
} else {
_item_quest_status[item_script] = QuestFailedToLoad;
@ -169,50 +181,58 @@ void QuestParserCollection::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std:
qiter->second->EventNPC(evt, npc, init, data, extra_data);
}
} else {
QuestInterface *qi = GetQIByNPCQuest(npc->GetNPCTypeID());
std::string filename;
QuestInterface *qi = GetQIByNPCQuest(npc->GetNPCTypeID(), filename);
if(qi) {
_npc_quest_status[npc->GetNPCTypeID()] = qi->GetIdentifier();
qi->LoadNPCScript(filename, npc->GetNPCTypeID());
qi->EventNPC(evt, npc, init, data, extra_data);
} else {
_npc_quest_status[npc->GetNPCTypeID()] = QuestFailedToLoad;
}
}
// K, lets also parse templates/global_npc.pl
if(_global_npc_quest_status != QuestUnloaded && _global_npc_quest_status != QuestFailedToLoad) {
std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(_global_npc_quest_status);
qiter->second->EventGlobalNPC(evt, npc, init, data, extra_data);
} else {
QuestInterface *qi = GetQIByGlobalNPCQuest();
if(qi) {
_global_npc_quest_status = qi->GetIdentifier();
qi->EventGlobalNPC(evt, npc, init, data, extra_data);
} else {
_global_npc_quest_status = QuestFailedToLoad;
}
}
//// K, lets also parse templates/global_npc.pl
//if(_global_npc_quest_status != QuestUnloaded && _global_npc_quest_status != QuestFailedToLoad) {
// std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(_global_npc_quest_status);
// qiter->second->EventGlobalNPC(evt, npc, init, data, extra_data);
//} else {
// std::string filename;
// QuestInterface *qi = GetQIByGlobalNPCQuest(filename);
// if(qi) {
// _global_npc_quest_status = qi->GetIdentifier();
// qi->LoadGlobalNPCScript(filename);
// qi->EventGlobalNPC(evt, npc, init, data, extra_data);
// } else {
// _global_npc_quest_status = QuestFailedToLoad;
// }
//}
}
void QuestParserCollection::EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
if(_player_quest_status == QuestUnloaded) {
QuestInterface *qi = GetQIByGlobalPlayerQuest();
if(qi) {
_global_player_quest_status = qi->GetIdentifier();
qi->EventGlobalPlayer(evt, client, data, extra_data);
}
std::string filename;
//QuestInterface *qi = GetQIByGlobalPlayerQuest(filename);
//if(qi) {
// _global_player_quest_status = qi->GetIdentifier();
// qi->LoadGlobalPlayerScript(filename);
// qi->EventGlobalPlayer(evt, client, data, extra_data);
//}
qi = GetQIByPlayerQuest();
QuestInterface *qi = GetQIByPlayerQuest(filename);
if(qi) {
_player_quest_status = qi->GetIdentifier();
qi->LoadPlayerScript(filename);
qi->EventPlayer(evt, client, data, extra_data);
}
} else {
if(_global_player_quest_status != QuestFailedToLoad) {
std::map<uint32, QuestInterface*>::iterator iter = _interfaces.find(_global_player_quest_status);
if(iter != _interfaces.end())
iter->second->EventGlobalPlayer(evt, client, data, extra_data);
}
//if(_global_player_quest_status != QuestFailedToLoad) {
// std::map<uint32, QuestInterface*>::iterator iter = _interfaces.find(_global_player_quest_status);
// if(iter != _interfaces.end())
// iter->second->EventGlobalPlayer(evt, client, data, extra_data);
//}
if(_player_quest_status != QuestFailedToLoad) {
std::map<uint32, QuestInterface*>::iterator iter = _interfaces.find(_player_quest_status);
iter->second->EventPlayer(evt, client, data, extra_data);
@ -239,9 +259,11 @@ void QuestParserCollection::EventItem(QuestEventID evt, Client *client, ItemInst
qiter->second->EventItem(evt, client, item, objid, extra_data);
}
} else {
QuestInterface *qi = GetQIByItemQuest(item_script);
std::string filename;
QuestInterface *qi = GetQIByItemQuest(item_script, filename);
if(qi) {
_item_quest_status[item_script] = qi->GetIdentifier();
qi->LoadItemScript(filename, item_script);
qi->EventItem(evt, client, item, objid, extra_data);
} else {
_item_quest_status[item_script] = QuestFailedToLoad;
@ -258,9 +280,11 @@ void QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *clien
qiter->second->EventSpell(evt, npc, client, spell_id, extra_data);
}
} else {
QuestInterface *qi = GetQIBySpellQuest(spell_id);
std::string filename;
QuestInterface *qi = GetQIBySpellQuest(spell_id, filename);
if(qi) {
_spell_quest_status[spell_id] = qi->GetIdentifier();
qi->LoadSpellScript(filename, spell_id);
qi->EventSpell(evt, npc, client, spell_id, extra_data);
} else {
_spell_quest_status[spell_id] = QuestFailedToLoad;
@ -268,9 +292,9 @@ void QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *clien
}
}
QuestInterface *QuestParserCollection::GetQIByNPCQuest(uint32 npcid) {
QuestInterface *QuestParserCollection::GetQIByNPCQuest(uint32 npcid, std::string &filename) {
//first look for /quests/zone/npcid.ext (precedence)
std::string filename = "quests/";
filename = "quests/";
filename += zone->GetShortName();
filename += "/";
filename += itoa(npcid);
@ -408,13 +432,13 @@ QuestInterface *QuestParserCollection::GetQIByNPCQuest(uint32 npcid) {
return NULL;
}
QuestInterface *QuestParserCollection::GetQIByPlayerQuest() {
QuestInterface *QuestParserCollection::GetQIByPlayerQuest(std::string &filename) {
if(!zone)
return NULL;
//first look for /quests/zone/player_v[instance_version].ext (precedence)
std::string filename = "quests/";
filename = "quests/";
filename += zone->GetShortName();
filename += "/";
filename += "player_v";
@ -481,9 +505,9 @@ QuestInterface *QuestParserCollection::GetQIByPlayerQuest() {
return NULL;
}
QuestInterface *QuestParserCollection::GetQIByGlobalNPCQuest(){
QuestInterface *QuestParserCollection::GetQIByGlobalNPCQuest(std::string &filename) {
// simply look for templates/global_npc.pl
std::string filename = "quests/";
filename = "quests/";
filename += QUEST_TEMPLATES_DIRECTORY;
filename += "/";
filename += "global_npc";
@ -508,9 +532,9 @@ QuestInterface *QuestParserCollection::GetQIByGlobalNPCQuest(){
return NULL;
}
QuestInterface *QuestParserCollection::GetQIByGlobalPlayerQuest() {
QuestInterface *QuestParserCollection::GetQIByGlobalPlayerQuest(std::string &filename) {
//first look for /quests/templates/player.ext (precedence)
std::string filename = "quests/";
filename = "quests/";
filename += QUEST_TEMPLATES_DIRECTORY;
filename += "/";
filename += "global_player";
@ -535,9 +559,9 @@ QuestInterface *QuestParserCollection::GetQIByGlobalPlayerQuest() {
return NULL;
}
QuestInterface *QuestParserCollection::GetQIBySpellQuest(uint32 spell_id) {
QuestInterface *QuestParserCollection::GetQIBySpellQuest(uint32 spell_id, std::string &filename) {
//first look for /quests/spells/spell_id.ext (precedence)
std::string filename = "quests/spells/";
filename = "quests/spells/";
filename += itoa(spell_id);
std::string tmp;
FILE *f = NULL;
@ -560,9 +584,9 @@ QuestInterface *QuestParserCollection::GetQIBySpellQuest(uint32 spell_id) {
return NULL;
}
QuestInterface *QuestParserCollection::GetQIByItemQuest(std::string item_script) {
QuestInterface *QuestParserCollection::GetQIByItemQuest(std::string item_script, std::string &filename) {
//first look for /quests/items/item_script.ext (precedence)
std::string filename = "quests/items/";
filename = "quests/items/";
filename += item_script;
std::string tmp;
FILE *f = NULL;
@ -580,7 +604,7 @@ QuestInterface *QuestParserCollection::GetQIByItemQuest(std::string item_script)
}
iter++;
}
}
return NULL;
}
}

View File

@ -35,12 +35,12 @@ public:
void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
private:
QuestInterface *GetQIByNPCQuest(uint32 npcid);
QuestInterface *GetQIByGlobalNPCQuest();
QuestInterface *GetQIByPlayerQuest();
QuestInterface *GetQIByGlobalPlayerQuest();
QuestInterface *GetQIBySpellQuest(uint32 spell_id);
QuestInterface *GetQIByItemQuest(std::string item_script);
QuestInterface *GetQIByNPCQuest(uint32 npcid, std::string &filename);
QuestInterface *GetQIByGlobalNPCQuest(std::string &filename);
QuestInterface *GetQIByPlayerQuest(std::string &filename);
QuestInterface *GetQIByGlobalPlayerQuest(std::string &filename);
QuestInterface *GetQIBySpellQuest(uint32 spell_id, std::string &filename);
QuestInterface *GetQIByItemQuest(std::string item_script, std::string &filename);
std::map<uint32, QuestInterface*> _interfaces;
std::map<uint32, std::string> _extensions;

File diff suppressed because it is too large Load Diff

View File

@ -118,12 +118,19 @@ public:
virtual void AddVar(std::string name, std::string val) { Parser::AddVar(name, val); };
virtual uint32 GetIdentifier() { return 0xf8b05c11; }
int LoadScript(int npcid, const char * zone, Mob* activater=0);
int LoadGlobalNPCScript();
int LoadPlayerScript(const char *zone);
int LoadGlobalPlayerScript();
int LoadItemScript(ItemInst* iteminst, string packagename, itemQuestMode Qtype);
int LoadSpellScript(uint32 id);
virtual void LoadNPCScript(std::string filename, int npc_id);
virtual void LoadGlobalNPCScript(std::string filename);
virtual void LoadPlayerScript(std::string filename);
virtual void LoadGlobalPlayerScript(std::string filename);
virtual void LoadItemScript(std::string filename, std::string item_script);
virtual void LoadSpellScript(std::string filename, uint32 spell_id);
//int LoadScript(int npcid, const char * zone, Mob* activater=0);
//int LoadGlobalNPCScript();
//int LoadPlayerScript(const char *zone);
//int LoadGlobalPlayerScript();
//int LoadItemScript(ItemInst* iteminst, string packagename, itemQuestMode Qtype);
//int LoadSpellScript(uint32 id);
//expose a var to the script (probably parallels addvar))
//i.e. exportvar("qst1234", "name", "somemob");

4
zone/lua_parser.cpp Normal file
View File

@ -0,0 +1,4 @@
#ifdef LUA_EQEMU
#include "lua_parser.h"
#endif

40
zone/lua_parser.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef _EQE_LUA_PARSER_H
#define _EQE_LUA_PARSER_H
#ifdef LUA_EQEMU
#include <lua.hpp>
#include "QuestParserCollection.h"
#include "QuestInterface.h"
class ItemInst;
class Client;
class NPC;
class LuaParser {
public:
virtual void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
virtual void EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
virtual void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
virtual void EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
virtual void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
virtual void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
virtual bool HasQuestSub(uint32 npcid, const char *subname);
virtual bool HasGlobalQuestSub(const char *subname);
virtual bool PlayerHasQuestSub(const char *subname);
virtual bool GlobalPlayerHasQuestSub(const char *subname);
virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname);
virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname);
virtual void AddVar(std::string name, std::string val);
virtual void ReloadQuests(bool reset_timers = true);
virtual uint32 GetIdentifier() { return 0xb0712acc; }
private:
lua_State* L;
};
#endif
#endif

View File

@ -77,6 +77,7 @@ extern volatile bool ZoneLoaded;
#include "parser.h"
#include "embparser.h"
#include "perlparser.h"
#include "lua_parser.h"
#include "client_logs.h"
#include "questmgr.h"
#include "titles.h"
@ -288,6 +289,12 @@ int main(int argc, char** argv) {
PerlXSParser *pxs = new PerlXSParser();
parse->RegisterQuestInterface(pxs, "pl");
#endif
#ifdef LUA_EQEMU
LuaParser *lua_parser = new LuaParser();
parse->RegisterQuestInterface(lua_parser, "lua");
#endif
Parser *ps = new Parser();
//parse->RegisterQuestInterface(ps, "qst");
@ -478,6 +485,11 @@ int main(int argc, char** argv) {
#ifdef EMBPERL
safe_delete(pxs);
#endif
#ifdef LUA_EQEMU
safe_delete(lua_parser);
#endif
safe_delete(ps);
safe_delete(mmf);