Browse Source

Fixed async query, added new reason string to remove spell function in LUA

- Fixed a async query for npc_appearance on skin_color to use insert param
- spell 'remove' function now has third parameter 'reason', canceled, expired, purged, death and pet_death
image 3 years ago
parent
commit
897df23280

+ 2 - 2
EQ2/source/WorldServer/Commands/Commands.cpp

@@ -875,7 +875,7 @@ bool Commands::SetSpawnCommand(Client* client, Spawn* target, int8 type, const c
 						((Entity*)target)->SetSkinColor(clr);
 						Query replaceSkinQuery;
 						replaceSkinQuery.AddQueryAsync(0, &database, Q_DELETE, "delete from npc_appearance where spawn_id=%u and type='skin_color'", target->GetDatabaseID());
-						replaceSkinQuery.AddQueryAsync(0, &database, Q_DELETE, "insert into npc_appearance set spawn_id=%u, type='skin_color', red=%u, green=%u, blue=%u", target->GetDatabaseID(), clr.red, clr.green, clr.blue);
+						replaceSkinQuery.AddQueryAsync(0, &database, Q_INSERT, "insert into npc_appearance set spawn_id=%u, type='skin_color', red=%u, green=%u, blue=%u", target->GetDatabaseID(), clr.red, clr.green, clr.blue);
 					}
 					safe_delete(skinsep);
 				}
@@ -4577,7 +4577,7 @@ void Commands::Command_CancelMaintained(Client* client, Seperator* sep)
 	//	if (spell && spell->GetSpellData()->friendly_spell)  -- NOTE::You can cancel hostile maintained spells, 
 		                                                     // just not spelleffects/dets - Foof
 		//{
-			if (!client->GetPlayer()->GetZone()->GetSpellProcess()->DeleteCasterSpell(mEffects.spell))
+			if (!client->GetPlayer()->GetZone()->GetSpellProcess()->DeleteCasterSpell(mEffects.spell, "canceled"))
 				client->Message(CHANNEL_COLOR_RED, "The maintained spell could not be cancelled.");
 	//	}
 		//else

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

@@ -1135,7 +1135,7 @@ void Entity::DismissPet(NPC* pet, bool from_death) {
 	// Remove the spell maintained spell
 	Spell* spell = master_spell_list.GetSpell(pet->GetPetSpellID(), pet->GetPetSpellTier());
 	if (spell)
-		GetZone()->GetSpellProcess()->DeleteCasterSpell(this, spell);
+		GetZone()->GetSpellProcess()->DeleteCasterSpell(this, spell, from_death == true ? (string)"pet_death" : (string)"canceled");
 
 	if (pet->GetPetType() == PET_TYPE_CHARMED) {
 		PetOwner->SetCharmedPet(0);
@@ -1292,7 +1292,7 @@ int32 Entity::CheckWards(Entity* attacker, int32 damage, int8 damage_type) {
 			if (!ward->keepWard) {
 				hasSpellBeenRemoved = true;
 				RemoveWard(spell->spell->GetSpellID());
-				GetZone()->GetSpellProcess()->DeleteCasterSpell(spell);
+				GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "purged");
 			}
 		}
 		else {
@@ -1344,7 +1344,7 @@ int32 Entity::CheckWards(Entity* attacker, int32 damage, int8 damage_type) {
 		if (shouldRemoveSpell && !hasSpellBeenRemoved)
 		{
 			RemoveWard(spell->spell->GetSpellID());
-			GetZone()->GetSpellProcess()->DeleteCasterSpell(spell);
+			GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "purged");
 		}
 
 		// Reset ward pointer

+ 1 - 11
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -2844,13 +2844,7 @@ int EQ2Emu_lua_OfferQuest(lua_State* state) {
 		Quest* master_quest = master_quest_list.GetQuest(quest_id);
 		if (master_quest) {
 			Client* client = player->GetZone()->GetClientBySpawn(player);
-			if(!client) {
-				lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
-			}
 			Quest* quest = new Quest(master_quest);
-			if(!quest) {
-				lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
-			}
 			if (client && quest) {
 				client->AddPendingQuest(quest);
 				if (npc)
@@ -2858,11 +2852,7 @@ int EQ2Emu_lua_OfferQuest(lua_State* state) {
 				else
 					quest->SetQuestGiver(0);
 			}
-		} else {
-			lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
 		}
-	} else {
-		lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
 	}
 	return 0;
 }
@@ -9927,4 +9917,4 @@ int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
 		return 1;
 	}
 	return 0;
-}
+}

+ 7 - 2
EQ2/source/WorldServer/LuaInterface.cpp

@@ -606,7 +606,7 @@ lua_State* LuaInterface::LoadLuaFile(const char* name) {
 	return 0;
 }
 
-void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete) {
+void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete, string reason) {
 	if(shutting_down)
 		return;
 
@@ -628,10 +628,15 @@ void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool
 		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, 2, 0, 0);
+		lua_pcall(spell->state, 3, 0, 0);
 	}
 
 	spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);

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

@@ -170,7 +170,7 @@ public:
 	bool			LoadSpawnScript(const char* name);
 	bool			LoadZoneScript(string name);
 	bool			LoadZoneScript(const char* name);
-	void			RemoveSpell(LuaSpell* spell, bool call_remove_function = true, bool can_delete = true);
+	void			RemoveSpell(LuaSpell* spell, bool call_remove_function = true, bool can_delete = true, string reason = "");
 	Spawn*			GetSpawn(lua_State* state, int8 arg_num = 1);
 	Item*			GetItem(lua_State* state, int8 arg_num = 1);
 	Quest*			GetQuest(lua_State* state, int8 arg_num = 1);

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

@@ -132,7 +132,7 @@ void SpellProcess::Process(){
 				if (spell->spell->GetSpellData()->call_frequency > 0 && !ProcessSpell(spell, false))
 					active_spells.Remove(spell, true, 2000);
 				else if ((spell->timer.GetDuration() * spell->num_calls) >= spell->spell->GetSpellData()->duration1 * 100)
-					DeleteCasterSpell(spell);
+					DeleteCasterSpell(spell, "expired");
 			}
 			else
 				CheckRemoveTargetFromSpell(spell);
@@ -151,7 +151,7 @@ void SpellProcess::Process(){
 
 		itr = tmpList.begin();
 		while (itr != tmpList.end()) {
-			DeleteCasterSpell(*itr);
+			DeleteCasterSpell(*itr, "canceled");
 			itr++;
 		}
 	}
@@ -342,7 +342,7 @@ void SpellProcess::CheckInterrupt(InterruptStruct* interrupt){
 		entity->GetZone()->SendSpellFailedPacket(client, interrupt->error_code);
 }
 
-bool SpellProcess::DeleteCasterSpell(Spawn* caster, Spell* spell){
+bool SpellProcess::DeleteCasterSpell(Spawn* caster, Spell* spell, string reason){
 
 	bool ret = false;
 	// need to use size(true) to get pending updates to the list as well
@@ -352,7 +352,7 @@ bool SpellProcess::DeleteCasterSpell(Spawn* caster, Spell* spell){
 		while (itr.Next()){
 			lua_spell = itr->value;
 			if (lua_spell->spell == spell && lua_spell->caster == caster) {
-				ret = DeleteCasterSpell(lua_spell);
+				ret = DeleteCasterSpell(lua_spell, reason);
 				break;
 			}
 		}
@@ -360,7 +360,7 @@ bool SpellProcess::DeleteCasterSpell(Spawn* caster, Spell* spell){
 	return ret;
 }
 
-bool SpellProcess::DeleteCasterSpell(LuaSpell* spell){
+bool SpellProcess::DeleteCasterSpell(LuaSpell* spell, string reason){
 	bool ret = false;
 	Spawn* target = 0;
 	if(spell) {
@@ -403,7 +403,7 @@ bool SpellProcess::DeleteCasterSpell(LuaSpell* spell){
 			ret = true;
 		}
 		if(lua_interface)
-			lua_interface->RemoveSpell(spell, true, SpellScriptTimersHasSpell(spell));	
+			lua_interface->RemoveSpell(spell, true, SpellScriptTimersHasSpell(spell), reason);
 	}
 	return ret;
 }
@@ -848,7 +848,7 @@ void SpellProcess::ProcessSpell(ZoneServer* zone, Spell* spell, Entity* caster,
 		//If this spell is the toggle cast type and is being toggled off, do this now
 		if (spell->GetSpellData()->cast_type == SPELL_CAST_TYPE_TOGGLE)
 		{
-			bool ret_val = DeleteCasterSpell(caster, spell);
+			bool ret_val = DeleteCasterSpell(caster, spell, "purged");
 
 			if (ret_val)
 			{
@@ -1643,7 +1643,7 @@ void SpellProcess::RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, boo
 			if (spell->spell->GetSpellData()->persist_though_death)
 				continue;
 			if(spell->caster == spawn){
-				DeleteCasterSpell(spell);
+				DeleteCasterSpell(spell, "expired");
 				continue;
 			}
 
@@ -2324,7 +2324,7 @@ void SpellProcess::CheckRemoveTargetFromSpell(LuaSpell* spell, bool allow_delete
 		safe_delete(remove_targets);
 		MRemoveTargetList.releasewritelock(__FUNCTION__, __LINE__);
 		if (should_delete)
-			DeleteCasterSpell(spell);
+			DeleteCasterSpell(spell, "purged");
 	}
 }
 

+ 2 - 2
EQ2/source/WorldServer/SpellProcess.h

@@ -254,11 +254,11 @@ public:
 	/// <summary>Remove the given spell for the given caster from the SpellProcess</summary>
 	/// <param name='caster'>The spawn to remove the spell for</param>
 	/// <param name='spell'>The spell to remove</param>
-	bool DeleteCasterSpell(Spawn* caster, Spell* spell);
+	bool DeleteCasterSpell(Spawn* caster, Spell* spell, string reason = "");
 
 	/// <summary>Remove the given spell from the ZpellProcess</summary>
 	/// <param name='spell'>LuaSpell to remove</param>
-	bool DeleteCasterSpell(LuaSpell* spell);
+	bool DeleteCasterSpell(LuaSpell* spell, string reason="");
 
 	/// <summary>Interrupt the spell</summary>
 	/// <param name='interrupt'>InterruptStruct that contains all the info</param>