mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 23:58:25 +00:00
Merge branch 'luamod'
This commit is contained in:
+144
-23
@@ -10,8 +10,13 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "masterentity.h"
|
||||
#include "../common/spdat.h"
|
||||
#include "masterentity.h"
|
||||
#include "questmgr.h"
|
||||
#include "zone.h"
|
||||
#include "zone_config.h"
|
||||
|
||||
#include "lua_parser.h"
|
||||
#include "lua_bit.h"
|
||||
#include "lua_entity.h"
|
||||
#include "lua_item.h"
|
||||
@@ -31,11 +36,8 @@
|
||||
#include "lua_spawn.h"
|
||||
#include "lua_packet.h"
|
||||
#include "lua_general.h"
|
||||
#include "questmgr.h"
|
||||
#include "zone.h"
|
||||
#include "zone_config.h"
|
||||
#include "lua_parser.h"
|
||||
#include "lua_encounter.h"
|
||||
#include "lua_stat_bonuses.h"
|
||||
|
||||
const char *LuaEvents[_LargestEventID] = {
|
||||
"event_say",
|
||||
@@ -799,12 +801,14 @@ void LuaParser::Init() {
|
||||
void LuaParser::ReloadQuests() {
|
||||
loaded_.clear();
|
||||
errors_.clear();
|
||||
mods_.clear();
|
||||
lua_encounter_events_registered.clear();
|
||||
lua_encounters_loaded.clear();
|
||||
|
||||
for (auto encounter : lua_encounters) {
|
||||
encounter.second->Depop();
|
||||
}
|
||||
|
||||
lua_encounters.clear();
|
||||
// so the Depop function above depends on the Process being called again so ...
|
||||
// And there is situations where it wouldn't be :P
|
||||
@@ -817,6 +821,8 @@ void LuaParser::ReloadQuests() {
|
||||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
auto top = lua_gettop(L);
|
||||
|
||||
if(luaopen_bit(L) != 1) {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
AddError(error);
|
||||
@@ -830,7 +836,7 @@ void LuaParser::ReloadQuests() {
|
||||
#ifdef SANITIZE_LUA_LIBS
|
||||
//io
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "io");
|
||||
//lua_setglobal(L, "io");
|
||||
|
||||
//some os/debug are okay some are not
|
||||
lua_getglobal(L, "os");
|
||||
@@ -933,24 +939,48 @@ void LuaParser::ReloadQuests() {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
AddError(error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
zone_script = Config->QuestDir;
|
||||
zone_script += "/";
|
||||
zone_script += zone->GetShortName();
|
||||
zone_script += "/script_init.lua";
|
||||
f = fopen(zone_script.c_str(), "r");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
|
||||
zone_script = Config->QuestDir;
|
||||
zone_script += "/";
|
||||
zone_script += zone->GetShortName();
|
||||
zone_script += "/script_init.lua";
|
||||
f = fopen(zone_script.c_str(), "r");
|
||||
if(f) {
|
||||
fclose(f);
|
||||
|
||||
if(luaL_dofile(L, zone_script.c_str())) {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
AddError(error);
|
||||
if (luaL_dofile(L, zone_script.c_str())) {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
AddError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FILE *load_order = fopen("mods/load_order.txt", "r");
|
||||
if (load_order) {
|
||||
char file_name[256] = { 0 };
|
||||
while (fgets(file_name, 256, load_order) != nullptr) {
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
auto c = file_name[i];
|
||||
if (c == '\n' || c == '\r' || c == ' ') {
|
||||
file_name[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LoadScript("mods/" + std::string(file_name), file_name);
|
||||
mods_.push_back(LuaMod(L, this, file_name));
|
||||
}
|
||||
|
||||
fclose(load_order);
|
||||
}
|
||||
|
||||
auto end = lua_gettop(L);
|
||||
int n = end - top;
|
||||
if (n > 0) {
|
||||
lua_pop(L, n);
|
||||
}
|
||||
}
|
||||
|
||||
void LuaParser::LoadScript(std::string filename, std::string package_name) {
|
||||
@@ -959,6 +989,7 @@ void LuaParser::LoadScript(std::string filename, std::string package_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto top = lua_gettop(L);
|
||||
if(luaL_loadfile(L, filename.c_str())) {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
AddError(error);
|
||||
@@ -986,14 +1017,20 @@ void LuaParser::LoadScript(std::string filename, std::string package_name) {
|
||||
std::string error = lua_tostring(L, -1);
|
||||
AddError(error);
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
loaded_[package_name] = true;
|
||||
}
|
||||
|
||||
loaded_[package_name] = true;
|
||||
auto end = lua_gettop(L);
|
||||
int n = end - top;
|
||||
if (n > 0) {
|
||||
lua_pop(L, n);
|
||||
}
|
||||
}
|
||||
|
||||
bool LuaParser::HasFunction(std::string subname, std::string package_name) {
|
||||
std::transform(subname.begin(), subname.end(), subname.begin(), ::tolower);
|
||||
//std::transform(subname.begin(), subname.end(), subname.begin(), ::tolower);
|
||||
|
||||
auto iter = loaded_.find(package_name);
|
||||
if(iter == loaded_.end()) {
|
||||
@@ -1020,12 +1057,18 @@ void LuaParser::MapFunctions(lua_State *L) {
|
||||
luabind::module(L)
|
||||
[
|
||||
lua_register_general(),
|
||||
lua_register_random(),
|
||||
lua_register_events(),
|
||||
lua_register_faction(),
|
||||
lua_register_slot(),
|
||||
lua_register_material(),
|
||||
lua_register_client_version(),
|
||||
lua_register_appearance(),
|
||||
lua_register_classes(),
|
||||
lua_register_skills(),
|
||||
lua_register_bodytypes(),
|
||||
lua_register_filters(),
|
||||
lua_register_message_types(),
|
||||
lua_register_entity(),
|
||||
lua_register_encounter(),
|
||||
lua_register_mob(),
|
||||
@@ -1054,7 +1097,12 @@ void LuaParser::MapFunctions(lua_State *L) {
|
||||
lua_register_door(),
|
||||
lua_register_object(),
|
||||
lua_register_packet(),
|
||||
lua_register_packet_opcodes()
|
||||
lua_register_packet_opcodes(),
|
||||
lua_register_stat_bonuses(),
|
||||
lua_register_rules_const(),
|
||||
lua_register_rulei(),
|
||||
lua_register_ruler(),
|
||||
lua_register_ruleb()
|
||||
];
|
||||
|
||||
} catch(std::exception &ex) {
|
||||
@@ -1251,3 +1299,76 @@ QuestEventID LuaParser::ConvertLuaEvent(QuestEventID evt) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void LuaParser::MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault)
|
||||
{
|
||||
for (auto &mod : mods_) {
|
||||
mod.MeleeMitigation(self, attacker, hit, opts, ignoreDefault);
|
||||
}
|
||||
}
|
||||
|
||||
void LuaParser::ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault)
|
||||
{
|
||||
for (auto &mod : mods_) {
|
||||
mod.ApplyDamageTable(self, hit, ignoreDefault);
|
||||
}
|
||||
}
|
||||
|
||||
bool LuaParser::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool & ignoreDefault)
|
||||
{
|
||||
bool retval = false;
|
||||
for (auto &mod : mods_) {
|
||||
mod.AvoidDamage(self, other, hit, retval, ignoreDefault);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool LuaParser::CheckHitChance(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignoreDefault)
|
||||
{
|
||||
bool retval = false;
|
||||
for (auto &mod : mods_) {
|
||||
mod.CheckHitChance(self, other, hit, retval, ignoreDefault);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void LuaParser::TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault)
|
||||
{
|
||||
for (auto &mod : mods_) {
|
||||
mod.TryCriticalHit(self, defender, hit, opts, ignoreDefault);
|
||||
}
|
||||
}
|
||||
|
||||
void LuaParser::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault)
|
||||
{
|
||||
for (auto &mod : mods_) {
|
||||
mod.CommonOutgoingHitSuccess(self, other, hit, opts, ignoreDefault);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 LuaParser::GetRequiredAAExperience(Client *self, bool &ignoreDefault)
|
||||
{
|
||||
uint32 retval = 0;
|
||||
for (auto &mod : mods_) {
|
||||
mod.GetRequiredAAExperience(self, retval, ignoreDefault);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint32 LuaParser::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault)
|
||||
{
|
||||
uint32 retval = 0;
|
||||
for (auto &mod : mods_) {
|
||||
mod.GetEXPForLevel(self, level, retval, ignoreDefault);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint32 LuaParser::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault)
|
||||
{
|
||||
uint32 retval = 0;
|
||||
for (auto &mod : mods_) {
|
||||
mod.GetExperienceForKill(self, against, retval, ignoreDefault);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user