Browse Source

Fix for issue #481. Added check to prevent sale of bags with items in them

Devn00b 1 năm trước cách đây
mục cha
commit
d28af745d8

+ 10 - 1
EQ2/source/WorldServer/Items/Items.cpp

@@ -3754,7 +3754,16 @@ vector<Item*>* PlayerItemList::GetItemsFromBagID(sint32 bag_id){
 	}
 	return ret;
 }
-
+int32 PlayerItemList::GetItemCountInBag(Item* bag){
+	MPlayerItems.readlock(__FUNCTION__, __LINE__);
+	if(bag && bag->IsBag() && items.count(bag->details.bag_id) > 0){
+		int32 bagitems = items.count(bag->details.bag_id);
+		MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
+		return bagitems;
+	}
+	MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
+	return 0;
+}
 vector<Item*>* PlayerItemList::GetItemsInBag(Item* bag){
 	vector<Item*>* ret_items = new vector<Item*>;
 	MPlayerItems.readlock(__FUNCTION__, __LINE__);

+ 2 - 0
EQ2/source/WorldServer/Items/Items.h

@@ -1133,6 +1133,8 @@ public:
 
 	int32	CheckSlotConflict(Item* tmp, bool check_lore_only = false, bool lock_mutex = true, int16* lore_stack_count = 0);
 	
+	int32   GetItemCountInBag(Item* bag);
+
 	Mutex MPlayerItems;
 private:
 	void AddItemToPacket(PacketStruct* packet, Player* player, Item* item, int16 i, bool overflow = false);

+ 9 - 0
EQ2/source/WorldServer/client.cpp

@@ -6968,6 +6968,15 @@ void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
 				SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
 				return;
 			}
+			else if (item->IsBag())
+			{
+				int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
+				if (bagitemcount > 0) {
+					SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
+					return;
+				}
+			}
+
 			int32 sell_price = (int32)(master_item->sell_price * multiplier);
 			if (sell_price > item->sell_price)
 				sell_price = item->sell_price;