revert and check if "remove" function exists in script
This commit is contained in:
parent
727040d2dd
commit
950b8e1564
@ -288,8 +288,7 @@ bool LuaInterface::LoadLuaSpell(const char* name) {
|
|||||||
spell->restored = false;
|
spell->restored = false;
|
||||||
spell->initial_caster_char_id = 0;
|
spell->initial_caster_char_id = 0;
|
||||||
spell->initial_target_char_id = 0;
|
spell->initial_target_char_id = 0;
|
||||||
spell->spell_deleting = false;
|
|
||||||
|
|
||||||
MSpells.lock();
|
MSpells.lock();
|
||||||
if (spells.count(lua_script) > 0) {
|
if (spells.count(lua_script) > 0) {
|
||||||
|
|
||||||
@ -855,36 +854,43 @@ lua_State* LuaInterface::LoadLuaFile(const char* name) {
|
|||||||
void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete, string reason, bool removing_all_spells) {
|
void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete, string reason, bool removing_all_spells) {
|
||||||
if(call_remove_function){
|
if(call_remove_function){
|
||||||
lua_getglobal(spell->state, "remove");
|
lua_getglobal(spell->state, "remove");
|
||||||
LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
|
if (!lua_isfunction(spell->state, lua_gettop(spell->state))){
|
||||||
spawn_wrapper->spawn = spell->caster;
|
lua_pop(spell->state, 1);
|
||||||
AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
|
}
|
||||||
lua_pushlightuserdata(spell->state, spawn_wrapper);
|
else {
|
||||||
if(spell->caster && (spell->initial_target || spell->caster->GetTarget())){
|
lua_getglobal(spell->state, "remove");
|
||||||
spawn_wrapper = new LUASpawnWrapper();
|
LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
|
||||||
if(!spell->initial_target)
|
spawn_wrapper->spawn = spell->caster;
|
||||||
spawn_wrapper->spawn = spell->caster->GetTarget();
|
|
||||||
else if(spell->caster->GetZone()) {
|
|
||||||
spawn_wrapper->spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
spawn_wrapper->spawn = nullptr; // we need it set to something or else the ptr could be loose
|
|
||||||
}
|
|
||||||
AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
|
AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
|
||||||
lua_pushlightuserdata(spell->state, spawn_wrapper);
|
lua_pushlightuserdata(spell->state, spawn_wrapper);
|
||||||
|
if(spell->caster && (spell->initial_target || spell->caster->GetTarget())){
|
||||||
|
spawn_wrapper = new LUASpawnWrapper();
|
||||||
|
if(!spell->initial_target)
|
||||||
|
spawn_wrapper->spawn = spell->caster->GetTarget();
|
||||||
|
else if(spell->caster->GetZone()) {
|
||||||
|
spawn_wrapper->spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spawn_wrapper->spawn = nullptr; // we need it set to something or else the ptr could be loose
|
||||||
|
}
|
||||||
|
AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
|
||||||
|
lua_pushlightuserdata(spell->state, spawn_wrapper);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pushlightuserdata(spell->state, 0);
|
||||||
|
|
||||||
|
if (spell->caster && !spell->caster->Alive())
|
||||||
|
reason = "dead";
|
||||||
|
|
||||||
|
lua_pushstring(spell->state, (char*)reason.c_str());
|
||||||
|
|
||||||
|
MSpells.lock();
|
||||||
|
current_spells[spell->state] = spell;
|
||||||
|
MSpells.unlock();
|
||||||
|
|
||||||
|
lua_pcall(spell->state, 3, 0, 0);
|
||||||
|
ResetFunctionStack(spell->state);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
lua_pushlightuserdata(spell->state, 0);
|
|
||||||
|
|
||||||
if (spell->caster && !spell->caster->Alive())
|
|
||||||
reason = "dead";
|
|
||||||
|
|
||||||
lua_pushstring(spell->state, (char*)reason.c_str());
|
|
||||||
|
|
||||||
MSpells.lock();
|
|
||||||
current_spells[spell->state] = spell;
|
|
||||||
MSpells.unlock();
|
|
||||||
lua_pcall(spell->state, 3, 0, 0);
|
|
||||||
ResetFunctionStack(spell->state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
|
spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
|
||||||
@ -2079,7 +2085,6 @@ LuaSpell* LuaInterface::GetSpell(const char* name) {
|
|||||||
new_spell->restored = false;
|
new_spell->restored = false;
|
||||||
new_spell->initial_caster_char_id = 0;
|
new_spell->initial_caster_char_id = 0;
|
||||||
new_spell->initial_target_char_id = 0;
|
new_spell->initial_target_char_id = 0;
|
||||||
new_spell->spell_deleting = false;
|
|
||||||
return new_spell;
|
return new_spell;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
#include "Spawn.h"
|
#include "Spawn.h"
|
||||||
#include "Spells.h"
|
#include "Spells.h"
|
||||||
@ -103,7 +102,7 @@ struct LuaSpell{
|
|||||||
Mutex MSpellTargets;
|
Mutex MSpellTargets;
|
||||||
int32 effect_bitmask;
|
int32 effect_bitmask;
|
||||||
bool restored; // restored spell cross zone
|
bool restored; // restored spell cross zone
|
||||||
std::atomic<bool> spell_deleting;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LUAUserData{
|
class LUAUserData{
|
||||||
|
@ -414,12 +414,11 @@ bool SpellProcess::DeleteCasterSpell(LuaSpell* spell, string reason, bool removi
|
|||||||
if(shared_lock_spell && !removing_all_spells) {
|
if(shared_lock_spell && !removing_all_spells) {
|
||||||
MSpellProcess.lock_shared();
|
MSpellProcess.lock_shared();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
Spawn* target = 0;
|
Spawn* target = 0;
|
||||||
bool target_valid = false;
|
bool target_valid = false;
|
||||||
if(spell && !spell->spell_deleting) {
|
if(spell) {
|
||||||
spell->spell_deleting = true;
|
|
||||||
spell->MSpellTargets.writelock(__FUNCTION__, __LINE__);
|
spell->MSpellTargets.writelock(__FUNCTION__, __LINE__);
|
||||||
if(remove_target && spell->targets.size() > 1) {
|
if(remove_target && spell->targets.size() > 1) {
|
||||||
for (int32 i = 0; i < spell->targets.size(); i++) {
|
for (int32 i = 0; i < spell->targets.size(); i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user