Browse Source

persist through (though?) zone naming, spell caster nullptr check to complete spell crash fix

Image 2 years ago
parent
commit
3d553fe80b

+ 11 - 9
EQ2/source/WorldServer/LuaInterface.cpp

@@ -831,16 +831,18 @@ void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool
 		lua_pcall(spell->state, 3, 0, 0); 
 		ResetFunctionStack(spell->state);
 	}
-
+	
 	spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
-	for (int8 i = 0; i < spell->targets.size(); i++) {
-		Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
-		if (!target || !target->IsEntity())
-			continue;
-
-		((Entity*)target)->RemoveProc(0, spell);
-		((Entity*)target)->RemoveSpellEffect(spell);
-		((Entity*)target)->RemoveSpellBonus(spell);
+	if(spell->caster) {
+		for (int8 i = 0; i < spell->targets.size(); i++) {
+			Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
+			if (!target || !target->IsEntity())
+				continue;
+
+			((Entity*)target)->RemoveProc(0, spell);
+			((Entity*)target)->RemoveSpellEffect(spell);
+			((Entity*)target)->RemoveSpellBonus(spell);
+		}
 	}
 
 	multimap<int32,int8>::iterator entries;

+ 3 - 3
EQ2/source/WorldServer/SpellProcess.cpp

@@ -1924,12 +1924,12 @@ void SpellProcess::RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, boo
 			spell = itr->value;
 			if (!spell)
 				continue;
-			//if (spell->spell->GetSpellData()->persist_though_death)
-			//	continue;
 			if(spell->caster == spawn && call_expire_function){
 				DeleteCasterSpell(spell, "expired", remove_all);
 				continue;
 			}
+			if (spell->spell->GetSpellData()->persist_through_death)
+				continue;
 
 			spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
 			for (i = 0; i < spell->targets.size(); i++){
@@ -2665,7 +2665,7 @@ void SpellProcess::CheckRemoveTargetFromSpell(LuaSpell* spell, bool allow_delete
 					for (remove_target_itr = remove_targets->begin(); remove_target_itr != remove_targets->end(); remove_target_itr++){
 						if(!spell->caster || !spell->caster->GetZone())
 							continue;
-							
+
 						remove_spawn = spell->caster->GetZone()->GetSpawnByID((*remove_target_itr));
 						if (remove_spawn) {
 							spell->MSpellTargets.writelock(__FUNCTION__, __LINE__);

+ 6 - 6
EQ2/source/WorldServer/Spells.cpp

@@ -117,7 +117,7 @@ Spell::Spell(Spell* host_spell)
 		spell->name = EQ2_8BitString(host_spell->GetSpellData()->name);
 		spell->not_maintained = host_spell->GetSpellData()->not_maintained;
 		spell->num_levels = host_spell->GetSpellData()->num_levels;
-		spell->persist_though_death = host_spell->GetSpellData()->persist_though_death;
+		spell->persist_through_death = host_spell->GetSpellData()->persist_through_death;
 		spell->power_by_level = host_spell->GetSpellData()->power_by_level;
 		spell->power_req = host_spell->GetSpellData()->power_req;
 		spell->power_req_percent = host_spell->GetSpellData()->power_req_percent;
@@ -1636,9 +1636,9 @@ bool Spell::GetSpellData(lua_State* state, std::string field)
 		lua_interface->SetBooleanValue(state, GetSpellData()->cast_while_moving);
 		valSet = true;
 	}
-	else if (field == "persist_though_death")
+	else if (field == "persist_through_death")
 	{
-		lua_interface->SetBooleanValue(state, GetSpellData()->persist_though_death);
+		lua_interface->SetBooleanValue(state, GetSpellData()->persist_through_death);
 		valSet = true;
 	}
 	else if (field == "not_maintained")
@@ -2057,10 +2057,10 @@ bool Spell::SetSpellData(lua_State* state, std::string field, int8 fieldArg)
 		GetSpellData()->cast_while_moving = cast_while_moving;
 		valSet = true;
 	}
-	else if (field == "persist_though_death")
+	else if (field == "persist_through_death")
 	{
-		bool persist_though_death = lua_interface->GetBooleanValue(state, fieldArg);
-		GetSpellData()->persist_though_death = persist_though_death;
+		bool persist_through_death = lua_interface->GetBooleanValue(state, fieldArg);
+		GetSpellData()->persist_through_death = persist_through_death;
 		valSet = true;
 	}
 	else if (field == "not_maintained")

+ 1 - 1
EQ2/source/WorldServer/Spells.h

@@ -284,7 +284,7 @@ struct SpellData{
 	int8    control_effect_type;
 	int32   casting_flags;
 	bool    cast_while_moving;
-	bool    persist_though_death;
+	bool    persist_through_death;
 	bool    not_maintained;
 	bool    is_aa;
 	int8	savage_bar;

+ 1 - 1
EQ2/source/WorldServer/WorldDatabase.cpp

@@ -4646,7 +4646,7 @@ void WorldDatabase::LoadSpells()
 			data->friendly_spell			= result.GetInt8Str("friendly_spell");
 			data->group_spell				= result.GetInt8Str("group_spell");
 			data->is_active					= result.GetInt8Str("is_active");
-			data->persist_though_death      = ( result.GetInt8Str("persist_through_death") == 1);
+			data->persist_through_death      = ( result.GetInt8Str("persist_through_death") == 1);
 			data->cast_while_moving         = ( result.GetInt8Str("cast_while_moving") == 1);
 			data->not_maintained            = ( result.GetInt8Str("not_maintained") == 1);
 			data->is_aa						= (result.GetInt8Str("is_aa") == 1);