From 555045cbe20c50026273f08813c6bca80e82de62 Mon Sep 17 00:00:00 2001 From: Emagi Date: Tue, 10 Sep 2024 09:14:40 -0400 Subject: [PATCH] reload spells now works with the lua state redesign and we delete spell in the spell_scripts instead of other places (casttimer, active_spells, so on) --- source/WorldServer/Commands/Commands.cpp | 9 +++++---- source/WorldServer/LuaInterface.cpp | 11 +++-------- source/WorldServer/LuaInterface.h | 3 +-- source/WorldServer/SpellProcess.cpp | 1 - source/WorldServer/WorldDatabase.cpp | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/source/WorldServer/Commands/Commands.cpp b/source/WorldServer/Commands/Commands.cpp index 349f019..c433bc8 100644 --- a/source/WorldServer/Commands/Commands.cpp +++ b/source/WorldServer/Commands/Commands.cpp @@ -1948,10 +1948,11 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie else { client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Reloading Spells & NPC Spell Lists (Note: Must Reload Spawns/Repop to reset npc spells)..."); world.SetReloadingSubsystem("Spells"); + zone_list.DeleteSpellProcess(); - master_spell_list.Reload(); if (lua_interface) - lua_interface->ReloadSpells(); + lua_interface->DestroySpells(); + master_spell_list.Reload(); zone_list.LoadSpellProcess(); world.RemoveReloadingSubSystem("Spells"); world.PurgeNPCSpells(); @@ -3081,9 +3082,9 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie } zone_list.DeleteSpellProcess(); - master_spell_list.Reload(); if (lua_interface) - lua_interface->ReloadSpells(); + lua_interface->DestroySpells(); + master_spell_list.Reload(); zone_list.LoadSpellProcess(); if(lua_interface){ map debug_clients = lua_interface->GetDebugClients(); diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index ce6c7c8..5fd41cc 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -151,9 +151,9 @@ void LuaInterface::DestroySpells() { LuaSpell* cur_spell = inner_itr->second; MSpellDelete.lock(); RemoveCurrentSpell(inner_itr->first, inner_itr->second, false, true, false); - MSpellDelete.unlock(); lua_close(inner_itr->first); safe_delete(cur_spell); + MSpellDelete.unlock(); } Mutex* mutex = GetSpellScriptMutex(spell_script_itr->first.c_str()); @@ -260,11 +260,6 @@ void LuaInterface::DestroyRegionScripts() { MRegionScripts.releasewritelock(__FUNCTION__, __LINE__); } -void LuaInterface::ReloadSpells() { - DestroySpells(); - database.LoadSpellScriptData(); -} - bool LuaInterface::LoadItemScript(string name) { return LoadItemScript(name.c_str()); } @@ -2357,8 +2352,8 @@ LuaSpell* LuaInterface::CreateSpellScript(const char* name, lua_State* existStat return new_spell; } -LuaSpell* LuaInterface::GetSpell(const char* name) { - return GetSpellScript(name, true); +LuaSpell* LuaInterface::GetSpell(const char* name, bool use) { + return GetSpellScript(name, true, use); } bool LuaInterface::RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn, Spawn* target, sint64* returnValue) { diff --git a/source/WorldServer/LuaInterface.h b/source/WorldServer/LuaInterface.h index 66ae196..155e066 100644 --- a/source/WorldServer/LuaInterface.h +++ b/source/WorldServer/LuaInterface.h @@ -236,7 +236,7 @@ public: LuaSpell* GetCurrentSpell(lua_State* state, bool needsLock = true); void RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock = true, bool removeCurSpell = true, bool removeSpellScript = true); bool CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string functionCalled); - LuaSpell* GetSpell(const char* name); + LuaSpell* GetSpell(const char* name, bool use = true); void UseItemScript(const char* name, lua_State* state, bool val); void UseSpawnScript(const char* name, lua_State* state, bool val); void UseZoneScript(const char* name, lua_State* state, bool val); @@ -269,7 +269,6 @@ public: void DestroySpells(); void DestroySpawnScripts(); void DestroyItemScripts(); - void ReloadSpells(); void DestroyQuests(bool reload = false); void DestroyZoneScripts(); void DestroyRegionScripts(); diff --git a/source/WorldServer/SpellProcess.cpp b/source/WorldServer/SpellProcess.cpp index 2d08c38..57c0176 100644 --- a/source/WorldServer/SpellProcess.cpp +++ b/source/WorldServer/SpellProcess.cpp @@ -83,7 +83,6 @@ void SpellProcess::RemoveAllSpells(bool reload_spells){ MutexList::iterator cast_timers_itr = cast_timers.begin(); while(cast_timers_itr.Next()){ safe_delete(cast_timers_itr->value->timer); - safe_delete(cast_timers_itr->value->spell); cast_timers.Remove(cast_timers_itr->value, true); } cast_timers.clear(); diff --git a/source/WorldServer/WorldDatabase.cpp b/source/WorldServer/WorldDatabase.cpp index 98aadd1..665c199 100644 --- a/source/WorldServer/WorldDatabase.cpp +++ b/source/WorldServer/WorldDatabase.cpp @@ -4508,7 +4508,7 @@ int32 WorldDatabase::LoadSpellScriptData() { while (result && (row = mysql_fetch_row(result))) { if (row[0] && strlen(row[0]) > 0) { - if (lua_interface->GetSpell(row[0])) + if (lua_interface->GetSpell(row[0], false)) LogWrite(SPELL__DEBUG, 5, "Spells", "SpellScript: %s loaded.", row[0]); } }