Browse Source

Quest class constructor mgmt, don't need to always create the quest

Image 3 years ago
parent
commit
6304430e3a

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

@@ -1330,9 +1330,9 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 						if(item->GetItemScript() && lua_interface)
 							lua_interface->RunItemScript(item->GetItemScript(), "examined", item, client->GetPlayer());
 						else if(item->generic_info.offers_quest_id > 0){ //leave the current functionality in place if it doesnt have an item script
-							Quest* quest = master_quest_list.GetQuest(item->generic_info.offers_quest_id);
+							Quest* quest = master_quest_list.GetQuest(item->generic_info.offers_quest_id, false);
 							if(quest && client->GetPlayer()->GetCompletedQuest(item->generic_info.offers_quest_id) == 0 && client->GetPlayer()->GetQuest(item->generic_info.offers_quest_id) == 0)
-								client->AddPendingQuest(quest);
+								client->AddPendingQuest(new Quest(quest)); // copy quest since we pulled the master quest to see if it existed or not
 						}
 					}
 					else

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

@@ -2248,14 +2248,14 @@ void Item::serialize(PacketStruct* packet, bool show_name, Player* player, int16
 	packet->setSubstructDataByName("footer", "collection_needed", player->GetCollectionList()->NeedsItem(this) ? 1 : 0);
 
 	if(generic_info.offers_quest_id > 0){
-		Quest* quest = master_quest_list.GetQuest(generic_info.offers_quest_id);
+		Quest* quest = master_quest_list.GetQuest(generic_info.offers_quest_id, false);
 		if(quest){
 			packet->setSubstructDataByName("footer", "offers_quest", quest->GetName());
 			packet->setSubstructDataByName("footer", "quest_color", player->GetArrowColor(quest->GetQuestLevel()));
 		}
 	}
 	if(generic_info.part_of_quest_id > 0){
-		Quest* quest = master_quest_list.GetQuest(generic_info.part_of_quest_id);
+		Quest* quest = master_quest_list.GetQuest(generic_info.part_of_quest_id, false);
 		if(quest){
 			packet->setSubstructDataByName("footer", "part_of_quest", quest->GetName());
 			packet->setSubstructDataByName("footer", "quest_color", player->GetArrowColor(quest->GetQuestLevel()));

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

@@ -3311,7 +3311,7 @@ int EQ2Emu_lua_OfferQuest(lua_State* state) {
 
 	/* NPC is allowed to be null */
 	if (player && player->IsPlayer() && quest_id > 0) {
-		Quest* master_quest = master_quest_list.GetQuest(quest_id);
+		Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
 		if (master_quest) {
 			Client* client = player->GetZone()->GetClientBySpawn(player);
 			if (!client) {

+ 2 - 4
EQ2/source/WorldServer/Player.cpp

@@ -4498,7 +4498,7 @@ int8 Player::CheckQuestFlag(Spawn* spawn){
 			MPlayerQuests.unlock();
 			if (CanReceiveQuest(quests->at(i))){
 				MPlayerQuests.lock();
-				quest = master_quest_list.GetQuest(quests->at(i));
+				quest = master_quest_list.GetQuest(quests->at(i), false);
 				MPlayerQuests.unlock();
 				if(quest){
 					int8 color = quest->GetFeatherColor();
@@ -4514,7 +4514,6 @@ int8 Player::CheckQuestFlag(Spawn* spawn){
 					// normal
 					else
 						ret = 1;
-					safe_delete(quest);
 					break;
 				}
 			}
@@ -4536,7 +4535,7 @@ bool Player::CanReceiveQuest(int32 quest_id){
 	bool passed = true;
 	int32 x;
 	MPlayerQuests.lock();
-	Quest* quest = master_quest_list.GetQuest(quest_id);
+	Quest* quest = master_quest_list.GetQuest(quest_id, false);
 	MPlayerQuests.unlock();
 	if (!quest)
 		passed = false;
@@ -4644,7 +4643,6 @@ bool Player::CanReceiveQuest(int32 quest_id){
 		}
 	}
 
-	safe_delete(quest);
 	return passed;
 }
 

+ 7 - 2
EQ2/source/WorldServer/Quests.h

@@ -384,9 +384,14 @@ protected:
 class MasterQuestList{
 public:
 	MasterQuestList();
-	Quest* GetQuest(int32 id){
+	Quest* GetQuest(int32 id, bool copyQuest = true){
 		if(quests.count(id) > 0)
-			return new Quest(quests[id]);
+		{
+			if(copyQuest)
+				return new Quest(quests[id]);
+			else
+				return quests[id];
+		}
 		else
 			return 0;
 	}

+ 3 - 0
EQ2/source/WorldServer/WorldDatabase.cpp

@@ -2485,7 +2485,10 @@ void WorldDatabase::LoadCharacterQuests(Client* client){
 					// If given timestamp is greater then completed then this is a repeatable quest we are working on
 					// so get a fresh quest object to add as an active quest
 					if (given_timestamp > completed_timestamp)
+					{
+						safe_delete(quest);
 						quest = master_quest_list.GetQuest(atoul(row[0]));
+					}
 					else
 						addQuest = false;