示例#1
0
void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data )
{
	sLog.outDebug( "WORLD: Received CMSG_QUESTGIVER_ACCEPT_QUEST" );
    if(!_player) return;
	if(!_player->IsInWorld()) return;

	//WorldPacket data;

	uint64 guid;
	uint32 quest_id;

	recv_data >> guid;
	recv_data >> quest_id;

	bool bValid = false;
	bool hasquest = true;
	bool bSkipLevelCheck = false;
	Quest *qst = NULL;
	Object *qst_giver = NULL;
	uint32 guidtype = GET_TYPE_FROM_GUID(guid);

	if(guidtype==HIGHGUID_TYPE_UNIT)
	{
		Creature *quest_giver = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid));
		if(quest_giver)
			qst_giver = (Object*)quest_giver;
		else
			return;
		bValid = quest_giver->isQuestGiver();
		hasquest = quest_giver->HasQuest(quest_id, 1);
		if(bValid)
			qst = QuestStorage.LookupEntry(quest_id);
	} 
	else if(guidtype==HIGHGUID_TYPE_GAMEOBJECT)
	{
		GameObject *quest_giver = _player->GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid));
		if(quest_giver)
			qst_giver = (Object*)quest_giver;
		else
			return;
		//bValid = quest_giver->isQuestGiver();
		//if(bValid)
		bValid = true;
			qst = QuestStorage.LookupEntry(quest_id);
	} 
	else if(guidtype==HIGHGUID_TYPE_ITEM)
	{
		Item *quest_giver = GetPlayer()->GetItemInterface()->GetItemByGUID(guid);
		if(quest_giver)
			qst_giver = (Object*)quest_giver;
		else
			return;
		bValid = true;
		bSkipLevelCheck=true;
		qst = QuestStorage.LookupEntry(quest_id);
	}
	else if(guidtype==HIGHGUID_TYPE_PLAYER)
	{
		Player *quest_giver = _player->GetMapMgr()->GetPlayer((uint32)guid);
		if(quest_giver)
			qst_giver = (Object*)quest_giver;
		else
			return;
		bValid = true;
		qst = QuestStorage.LookupEntry(quest_id);
	}

	if (!qst_giver)
	{
		sLog.outDebug("WORLD: Invalid questgiver GUID.");
		return;
	}

	if( !bValid || qst == NULL )
	{
		sLog.outDebug("WORLD: Creature is not a questgiver.");
		return;
	}

	if( _player->GetQuestLogForEntry( qst->id ) )
		return;

	if( qst_giver->GetTypeId() == TYPEID_UNIT && static_cast< Creature* >( qst_giver )->m_escorter != NULL )
	{
		SystemMessage("You cannot accept this quest at this time.");
		return;
	}

	// Check the player hasn't already taken this quest, or
	// it isn't available.
	uint32 status = sQuestMgr.CalcQuestStatus(qst_giver, _player,qst,3, bSkipLevelCheck);

	if((!sQuestMgr.IsQuestRepeatable(qst) && _player->HasFinishedQuest(qst->id)) || ( status != QMGR_QUEST_AVAILABLE && status != QMGR_QUEST_REPEATABLE && status != QMGR_QUEST_CHAT )
		|| !hasquest)
	{
		// We've got a hacker. Disconnect them.
		//sCheatLog.writefromsession(this, "tried to accept incompatible quest %u from %u.", qst->id, qst_giver->GetEntry());
		//Disconnect();
		return;
	}

	int32 log_slot = GetPlayer()->GetOpenQuestSlot();

	if (log_slot == -1)
	{
		sQuestMgr.SendQuestLogFull(GetPlayer());
		return;
	}

	//FIXME
	/*if(Player Has Timed quest && qst->HasFlag(QUEST_FLAG_TIMED))
		sQuestMgr.SendQuestInvalid(INVALID_REASON_HAVE_TIMED_QUEST);*/

	if(qst->count_receiveitems || qst->srcitem)
	{
		uint32 slots_required = qst->count_receiveitems;

		if(GetPlayer()->GetItemInterface()->CalculateFreeSlots(NULL) < slots_required)
		{
			GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_BAG_FULL);
			sQuestMgr.SendQuestFailed(FAILED_REASON_INV_FULL, qst, GetPlayer());
			return;
		}
	}	
	
/*	if(qst_giver->GetTypeId() == TYPEID_UNIT && !ScriptSystem->OnQuestRequireEvent(qst, static_cast< Creature* >( qst_giver ), _player, QUEST_EVENT_CAN_ACCEPT))
		return;*/

	QuestLogEntry *qle = new QuestLogEntry();
	qle->Init(qst, _player, log_slot);
	qle->UpdatePlayerFields();

	// If the quest should give any items on begin, give them the items.
	for(uint32 i = 0; i < 4; ++i)
	{
		if(qst->receive_items[i])
		{
			Item *item = objmgr.CreateItem( qst->receive_items[i], GetPlayer());
			if(item == NULL)
				continue;
			if(!GetPlayer()->GetItemInterface()->AddItemToFreeSlot(item))
			{
				item->DeleteMe();
			}
			else
				SendItemPushResult(item, false, true, false, true, 
				_player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(),
				1);
		}
	}

	if(qst->srcitem && qst->srcitem != qst->receive_items[0])
	{
		Item * item = objmgr.CreateItem( qst->srcitem, _player );
		if(item)
		{
			item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->srcitemcount ? qst->srcitemcount : 1);
			if(!_player->GetItemInterface()->AddItemToFreeSlot(item))
				item->DeleteMe();
		}
	}

	// Timed quest handler.
	if(qst->time > 0)
	{
		//Start Quest Timer Event Here
		//sEventMgr.AddEvent(GetPlayer(), &Player::EventTimedQuestExpire, qst, qle, static_cast<uint32>(log_slot), EVENT_TIMED_QUEST_EXPIRE, qst->time * 1000, 1);
		//uint32 qtime = static_cast<uint32>(time(NULL) + qst->time);
		//GetPlayer()->SetUInt32Value(log_slot+2, qtime);
		//GetPlayer()->SetUInt32Value(PLAYER_QUEST_LOG_1_01 + (log_slot * 3), qtime);
		//GetPlayer()->timed_quest_slot = log_slot;
	}

	if(qst->count_required_item || qst_giver->GetTypeId() == TYPEID_GAMEOBJECT)	// gameobject quests deactivate
		GetPlayer()->UpdateNearbyGameObjects();

	//ScriptSystem->OnQuestEvent(qst, static_cast< Creature* >( qst_giver ), _player, QUEST_EVENT_ON_ACCEPT);

	sQuestMgr.OnQuestAccepted(_player,qst,qst_giver);

	sLog.outDebug("WORLD: Added new QLE.");
	sHookInterface.OnQuestAccept(_player, qst, qst_giver);
}
示例#2
0
// Charter part
void WorldSession::HandleCharterBuy(WorldPacket & recv_data)
{
	/*
	{CLIENT} Packet: (0x01BD) CMSG_PETITION_BUY PacketSize = 85
	|------------------------------------------------|----------------|
	|00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |0123456789ABCDEF|
	|------------------------------------------------|----------------|
	|50 91 00 00 6E 13 01 F0 00 00 00 00 00 00 00 00 |P...n...........|
	|00 00 00 00 53 74 6F 72 6D 62 72 69 6E 67 65 72 |....Stormbringer|
	|73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |s...............|
	|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
	|00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 |................|
	|00 00 00 00 00								  |.....		   |
	-------------------------------------------------------------------
	*/

	if(!_player->IsInWorld())
		return;

	uint64 creature_guid;
	uint64 crap;
	uint32 crap2;
	string name;
    uint8 error;
	uint32 crap3,crap4,crap5,crap6,crap7,crap8,crap9,crap10,crap11,arena_index,crap12;
	uint16 crap13;
	uint8 crap14;
	uint32 crap15;
	recv_data >> creature_guid >> crap >> crap2 >> name;
	recv_data >> crap3 >> crap4 >> crap5 >> crap6 >> crap7 >> crap8 >> crap9 >> crap10 >> crap11
		>> crap12 >> crap13 >> crap14 >> arena_index >> crap15;

	Creature * crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid));
	if(!crt)
	{
		Disconnect();
		return;
	}

	if(crt->GetEntry()==19861 || crt->GetEntry()==18897 || crt->GetEntry()==19856 || crt->GetEntry()==sWorld.m_CustomCharterGiver )		/* i am lazy! */
	{
		uint32 arena_type = arena_index - 1;
		if(arena_type > 2)
			return;

		if(_player->m_arenaTeams[arena_type] || _player->m_charters[arena_index])
		{
			SendNotification(_player->GetSession()->LocalizedWorldSrv(71));
			return;
		}

		ArenaTeam * t = objmgr.GetArenaTeamByName(name, arena_type);
		if(t != NULL)
		{
			sChatHandler.SystemMessage(this,_player->GetSession()->LocalizedWorldSrv(72));
			return;
		}

		if(objmgr.GetCharterByName(name, (CharterTypes)arena_index))
		{
			sChatHandler.SystemMessage(this,_player->GetSession()->LocalizedWorldSrv(72));
			return;
		}

		if(_player->m_charters[arena_type])
		{
			SendNotification(_player->GetSession()->LocalizedWorldSrv(73));
			return;
		}

		static uint32 item_ids[] = {ARENA_TEAM_CHARTER_2v2, ARENA_TEAM_CHARTER_3v3, ARENA_TEAM_CHARTER_5v5};
		static uint32 costs[] = {ARENA_TEAM_CHARTER_2v2_COST,ARENA_TEAM_CHARTER_3v3_COST,ARENA_TEAM_CHARTER_5v5_COST};

		if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < costs[arena_type])
			return;			// error message needed here

		ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(item_ids[arena_type]);
		ASSERT(ip);
		SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip);
		if(res.Result == 0)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(0, 0, INV_ERR_INVENTORY_FULL);
			return;
		}

		error = _player->GetItemInterface()->CanReceiveItem(ip,1);
		if(error)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULL,NULL,error);
		}
		else
		{
			// Create the item and charter
			Item * i = objmgr.CreateItem(item_ids[arena_type], _player);
			Charter * c = objmgr.CreateCharter(_player->GetLowGUID(), (CharterTypes)arena_index);
			c->GuildName = name;
			c->ItemGuid = i->GetGUID();

			i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
			i->SetUInt32Value(ITEM_FIELD_FLAGS, 1);
			i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, c->GetID());
			i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883);
			if( !_player->GetItemInterface()->AddItemToFreeSlot(i) )
			{
				c->Destroy();
				i->DeleteMe();
				return;
			}

			c->SaveToDB();

			/*WorldPacket data(45);
			BuildItemPushResult(&data, _player->GetGUID(), ITEM_PUSH_TYPE_RECEIVE, 1, item_ids[arena_type], 0);
			SendPacket(&data);*/
			SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1);
			_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)costs[arena_type]);
			_player->m_charters[arena_index] = c;
			_player->SaveToDB(false);
		}
	}
	else
	{
		Guild * g = objmgr.GetGuildByGuildName(name);
		Charter * c = objmgr.GetCharterByName(name, CHARTER_TYPE_GUILD);
		if(g != 0 || c != 0)
		{
			SendNotification(_player->GetSession()->LocalizedWorldSrv(74));
			return;
		}

		if(_player->m_charters[CHARTER_TYPE_GUILD])
		{
			SendNotification(_player->GetSession()->LocalizedWorldSrv(75));
			return;
		}

		ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER);
		assert(ip);
		SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip);
		if(res.Result == 0)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(0, 0, INV_ERR_INVENTORY_FULL);
			return;
		}

		error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1);
		if(error)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULL,NULL,error);
		}
		else
		{
			// Meh...
			WorldPacket data(SMSG_PLAY_OBJECT_SOUND, 12);
			data << uint32(0x000019C2);
			data << creature_guid;
			SendPacket(&data);

			// Create the item and charter
			Item * i = objmgr.CreateItem(ITEM_ENTRY_GUILD_CHARTER, _player);
			c = objmgr.CreateCharter(_player->GetLowGUID(), CHARTER_TYPE_GUILD);
			c->GuildName = name;
			c->ItemGuid = i->GetGUID();


			i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
			i->SetUInt32Value(ITEM_FIELD_FLAGS, 1);
			i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, c->GetID());
			i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883);
			if( !_player->GetItemInterface()->AddItemToFreeSlot(i) )
			{
				c->Destroy();
				i->DeleteMe();
				return;
			}

			c->SaveToDB();

			/*data.clear();
			data.resize(45);
			BuildItemPushResult(&data, _player->GetGUID(), ITEM_PUSH_TYPE_RECEIVE, 1, ITEM_ENTRY_GUILD_CHARTER, 0);
			SendPacket(&data);*/
			SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1);

			_player->m_charters[CHARTER_TYPE_GUILD] = c;
			_player->SaveToDB(false);
		}
	}
}
示例#3
0
// Charter part
void WorldSession::HandleCharterBuy(WorldPacket & recv_data)
{
	uint8 error;
	uint64 creature_guid;
	uint32 crap;
	uint64 crap2;
	string name, unkstr;
	uint32 Data[7];
	uint16 crap10;
	uint32 crap11;
	uint32 crap12, PetitionSignerCount;
	string crap13;
	uint32 arena_index;

	recv_data >> creature_guid;
	recv_data >> crap >> crap2;
	recv_data >> name >> unkstr;
	recv_data >> Data[0] >> Data[1] >> Data[2] >> Data[3] >> Data[4] >> Data[5] >> Data[6];
	recv_data >> crap10;
	recv_data >> crap11 >> crap12 >> PetitionSignerCount;
	for(uint32 s = 0; s < 10; ++s)
		recv_data >> crap13;
	recv_data >> arena_index;

	Creature* crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid));
	if(!crt)
	{
		Disconnect();
		return;
	}

	if( arena_index >= NUM_CHARTER_TYPES )
		return;

	//All arena organizers should be allowed to create arena charter's
	if( !crt->ArenaOrganizersFlags() )
	{
		uint32 arena_type = arena_index - 1;
		if(arena_type > 2)
			return;

		if(_player->m_playerInfo->arenaTeam[arena_type])
		{
			SendNotification("You are already in an arena team.");
			return;
		}

		if(_player->m_playerInfo->charterId[arena_index] != 0)
		{
			SendNotification("You already have an arena charter of this type.");
			return;
		}

		if(!sWorld.VerifyName(name.c_str(), name.length()))
		{
			SendNotification("That name is invalid or contains invalid characters.");
			return;
		}

		ArenaTeam * t = objmgr.GetArenaTeamByName(name, arena_type);
		if(t != NULL)
		{
			sChatHandler.SystemMessage(this,"That name is already in use.");
			return;
		}

		if(objmgr.GetCharterByName(name, (CharterTypes)arena_index))
		{
			sChatHandler.SystemMessage(this,"That name is already in use.");
			return;
		}

		static uint32 item_ids[] = {ARENA_TEAM_CHARTER_2v2, ARENA_TEAM_CHARTER_3v3, ARENA_TEAM_CHARTER_5v5};
		static uint32 costs[] = {ARENA_TEAM_CHARTER_2v2_COST,ARENA_TEAM_CHARTER_3v3_COST,ARENA_TEAM_CHARTER_5v5_COST};

		if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < costs[arena_type])
		{
			sChatHandler.SystemMessage(this,"You don't have enough money!");
			return;			// error message needed here
		}

		ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(item_ids[arena_type]);
		ASSERT(ip);
		SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip);
		if(res.Result == 0)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, INV_ERR_INVENTORY_FULL);
			return;
		}

		error = _player->GetItemInterface()->CanReceiveItem(ip,1, NULL);
		if(error)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM,error);
		}
		else
		{
			// Create the item and charter
			Item* i = objmgr.CreateItem(item_ids[arena_type], _player);
			Charter * c = objmgr.CreateCharter(_player->GetLowGUID(), (CharterTypes)arena_index);
			c->GuildName = name;
			c->ItemGuid = i->GetGUID();

			i->Bind(ITEM_BIND_ON_PICKUP);
			i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
			i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, c->GetID());
			i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883);
			if( !_player->GetItemInterface()->AddItemToFreeSlot(i) )
			{
				c->Destroy();
				c = NULL;
				i->DeleteMe();
				i = NULL;
				return;
			}

			c->SaveToDB();
			SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1);
			_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)costs[arena_type]);
			_player->m_playerInfo->charterId[arena_index] = c->GetID();
			_player->SaveToDB(false);
		}
	}
	else
	{
		if( _player->GetUInt32Value(PLAYER_FIELD_COINAGE) < 1000)
		{
			SendNotification("You don't have enough money.");
			return;
		}
		if(_player->m_playerInfo->charterId[CHARTER_TYPE_GUILD] != 0)
		{
			SendNotification("You already have a guild charter.");
			return;
		}

		if(!sWorld.VerifyName(name.c_str(), name.length()))
		{
			SendNotification("That name is invalid or contains invalid characters.");
			return;
		}

		Guild * g = objmgr.GetGuildByGuildName(name);
		Charter * c = objmgr.GetCharterByName(name, CHARTER_TYPE_GUILD);
		if(g != 0 || c != 0)
		{
			SendNotification("A guild with that name already exists.");
			return;
		}

		ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER);
		assert(ip);
		SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip);
		if(res.Result == 0)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, INV_ERR_INVENTORY_FULL);
			return;
		}

		error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1, NULL);
		if(error)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM,error);
		}
		else
		{
			// Meh...
			WorldPacket data(SMSG_PLAY_OBJECT_SOUND, 12);
			data << uint32(0x000019C2);
			data << creature_guid;
			SendPacket(&data);

			// Create the item and charter
			Item * i = objmgr.CreateItem(ITEM_ENTRY_GUILD_CHARTER, _player);
			c = objmgr.CreateCharter(_player->GetLowGUID(), CHARTER_TYPE_GUILD);
			c->GuildName = name;
			c->ItemGuid = i->GetGUID();

			i->Bind(ITEM_BIND_ON_PICKUP);
			i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
			i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, c->GetID());
			i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883);
			if( !_player->GetItemInterface()->AddItemToFreeSlot(i) )
			{
				c->Destroy();
				c = NULL;
				i->DeleteMe();
				i = NULL;
				return;
			}

			c->SaveToDB();

			SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1);

			_player->m_playerInfo->charterId[CHARTER_TYPE_GUILD] = c->GetID();

			// 10 silver
			_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -1000);
			_player->SaveToDB(false);
		}
	}
}
示例#4
0
void LootRoll::Finalize()
{
	if( !mLootLock.AttemptAcquire() ) // only one finalization, please. players on different maps can roll, too, so this is needed.
	{
		sEventMgr.RemoveEvents(this);
		return;
	}

	sEventMgr.RemoveEvents(this);

	// this we will have to finalize with groups types.. for now
	// we'll just assume need before greed. person with highest roll
	// in need gets the item.

	uint32 highest = 0;
	int8 hightype = -1;
	uint64 player = 0;

	WorldPacket data(34);

	for(std::map<uint32, uint32>::iterator itr = m_NeedRolls.begin(); itr != m_NeedRolls.end(); itr++)
	{
		if(itr->second > highest)
		{
			highest = itr->second;
			player = itr->first;
			hightype = NEED;
		}
	}

	if(!highest)
	{
		for(std::map<uint32, uint32>::iterator itr = m_GreedRolls.begin(); itr != m_GreedRolls.end(); itr++)
		{
			if(itr->second > highest)
			{
				highest = itr->second;
				player = itr->first;
				hightype = GREED;
			}
		}

		for(std::map<uint32, uint32>::iterator itr = m_DisenchantRolls.begin(); itr != m_DisenchantRolls.end(); itr++)
		{
			if(itr->second > highest)
			{
				highest = itr->second;
				player = itr->first;
				hightype = DISENCHANT;
			}
		}
	}


	Loot * pLoot = 0;
	uint32 guidtype = GET_TYPE_FROM_GUID(_guid);
	if( guidtype == HIGHGUID_TYPE_CREATURE )
	{
		Creature* pc = _mgr->GetCreature(GET_LOWGUID_PART(_guid));
		if(pc) pLoot = &pc->m_loot;
	}
	else if( guidtype == HIGHGUID_TYPE_GAMEOBJECT )
	{
		GameObject* go = _mgr->GetGameObject(GET_LOWGUID_PART(_guid));
		if(go) pLoot = &go->m_loot;
	}

	if(!pLoot)
	{
		delete this;
		return;
	}

	if(_slotid >= pLoot->items.size())
	{
		delete this;
		return;
	}

	pLoot->items.at(_slotid).roll = NULLROLL;

	uint32 itemid = pLoot->items.at(_slotid).item.itemproto->ItemId;
	uint32 amt = pLoot->items.at(_slotid).StackSize;
	if(!amt)
	{
		delete this;
		return;
	}

	Player* _player = (player) ? _mgr->GetPlayer((uint32)player) : NULLPLR;
	if(!player || !_player)
	{
		/* all passed */
		data.Initialize(SMSG_LOOT_ALL_PASSED);
		data << _guid << _groupcount << _itemid << _randomsuffixid << _randompropertyid;
		set<uint32>::iterator pitr = m_passRolls.begin();
		while(_player == NULL && pitr != m_passRolls.end())
		{
			_player = _mgr->GetPlayer( (*(pitr)) );
			++pitr;
		}

		if( _player != NULL )
		{
			if(_player->InGroup())
				_player->GetGroup()->SendPacketToAll(&data);
			else
				_player->GetSession()->SendPacket(&data);
		}

		/* item can now be looted by anyone :) */
		pLoot->items.at(_slotid).passed = true;
		delete this;
		return;
	}

	pLoot->items.at(_slotid).roll = 0;
	data.Initialize(SMSG_LOOT_ROLL_WON);
	data << _guid << _slotid << _itemid << _randomsuffixid << _randompropertyid;
	data << _player->GetGUID() << uint8(highest) << uint8(hightype);
	if(_player->InGroup())
		_player->GetGroup()->SendPacketToAll(&data);
	else
		_player->GetSession()->SendPacket(&data);

	if(hightype == DISENCHANT)
	{
		//generate Disenchantingloot
		Item * pItem = objmgr.CreateItem( itemid, _player);
		lootmgr.FillItemLoot(&pItem->m_loot, pItem->GetEntry(), _player->GetTeam());

		//add loot
		for(std::vector<__LootItem>::iterator iter=pItem->m_loot.items.begin();iter != pItem->m_loot.items.end();iter++)
		{
			itemid =iter->item.itemproto->ItemId;
			Item * Titem = objmgr.CreateItem( itemid, _player);
			if( Titem == NULLITEM )
				continue;
			if( !_player->GetItemInterface()->AddItemToFreeSlot(Titem) )
			{
				_player->GetSession()->SendNotification("No free slots were found in your inventory, item has been mailed.");
				sMailSystem.DeliverMessage(MAILTYPE_NORMAL, _player->GetGUID(), _player->GetGUID(), "Loot Roll", "Here is your reward.", 0, 0, itemid, 1, true);
			}
			Titem->DeleteMe();
			Titem = NULLITEM;
		}
		pItem->DeleteMe();
		pItem = NULLITEM;

		// Set a looter, doesn't matter who.
		pLoot->items.at(_slotid).has_looted.insert(_player->GetLowGUID());

		//Send "finish" packet
		data.Initialize(SMSG_LOOT_REMOVED);
		data << uint8(_slotid);
		Player* plr;
		for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); itr++)
		{
			if((plr = _player->GetMapMgr()->GetPlayer(*itr)))
				plr->GetSession()->SendPacket(&data);
		}

		delete this;	//end here and skip the rest
		return;
	}

	ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid);

	int8 error;
	if((error = _player->GetItemInterface()->CanReceiveItem(it, 1, NULL)))
	{
		_player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, error);
		return;
	}

	Item* add = _player->GetItemInterface()->FindItemLessMax(itemid, amt, false);

	if (!add)
	{
		SlotResult slotresult = _player->GetItemInterface()->FindFreeInventorySlot(it);
		if(!slotresult.Result)
		{
			_player->GetSession()->SendNotification("No free slots were found in your inventory, item has been mailed.");
			sMailSystem.DeliverMessage(MAILTYPE_NORMAL, _player->GetGUID(), _player->GetGUID(), "Loot Roll", "Here is your reward.", 0, 0, it->ItemId, 1, true);
			data.Initialize(SMSG_LOOT_REMOVED);
			data << uint8(_slotid);
			Player* plr;
			for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); itr++)
			{
				if((plr = _player->GetMapMgr()->GetPlayer(*itr)))
					plr->GetSession()->SendPacket(&data);
			}
			delete this;
			return;
		}

		DEBUG_LOG("HandleAutostoreItem","AutoLootItem %u",itemid);
		Item* item = objmgr.CreateItem( itemid, _player);

		item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,amt);
		if(pLoot->items.at(_slotid).iRandomProperty!=NULL)
		{
			item->SetRandomProperty(pLoot->items.at(_slotid).iRandomProperty->ID);
			item->ApplyRandomProperties(false);
		}
		else if(pLoot->items.at(_slotid).iRandomSuffix != NULL)
		{
			item->SetRandomSuffix(pLoot->items.at(_slotid).iRandomSuffix->id);
			item->ApplyRandomProperties(false);
		}


		if( _player->GetItemInterface()->SafeAddItem(item,slotresult.ContainerSlot, slotresult.Slot) )
		{
			_player->GetSession()->SendItemPushResult(item,false,true,true,true,slotresult.ContainerSlot,slotresult.Slot,1);
			sQuestMgr.OnPlayerItemPickup(_player,item);
		}
		else
		{
			item->DeleteMe();
			item = NULLITEM;
		}
	}
	else
	{
		add->SetCount(add->GetUInt32Value(ITEM_FIELD_STACK_COUNT) + amt);
		add->m_isDirty = true;
		sQuestMgr.OnPlayerItemPickup(_player,add);
		_player->GetSession()->SendItemPushResult(add, false, true, true, false, _player->GetItemInterface()->GetBagSlotByGuid(add->GetGUID()), 0xFFFFFFFF, 1);
	}

	// Set a looter, doesn't matter who.
	pLoot->items.at(_slotid).has_looted.insert(_player->GetLowGUID());

	// this gets sent to all looters
	data.Initialize(SMSG_LOOT_REMOVED);
	data << uint8(_slotid);
	Player* plr;
	for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); itr++)
	{
		if((plr = _player->GetMapMgr()->GetPlayer(*itr)))
			plr->GetSession()->SendPacket(&data);
	}

	delete this;
}
示例#5
0
void WorldSession::HandleAcceptTrade(WorldPacket & recv_data) 
{
	Player * plr = _player->GetTradeTarget();
	if(_player->mTradeTarget == 0 || !plr)
		return;

	uint32 TradeStatus = TRADE_STATUS_ACCEPTED;
	
	// Tell the other player we're green.
#ifdef USING_BIG_ENDIAN
	swap32(&TradeStatus);
	plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
	_player->mTradeStatus = TradeStatus;
	swap32(&TradeStatus);
#else
	plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
	_player->mTradeStatus = TradeStatus;
#endif

	if(plr->mTradeStatus == TRADE_STATUS_ACCEPTED)
	{
		// Ready!
		uint32 ItemCount = 0;
		uint32 TargetItemCount = 0;
		Player * pTarget = plr;

/*		// Calculate Item Count
		for(uint32 Index = 0; Index < 7; ++Index)
		{
			if(_player->mTradeItems[Index] != 0)	++ItemCount;
			if(pTarget->mTradeItems[Index] != 0)	++TargetItemCount;
		}*/
		

		// Calculate Count
		for(uint32 Index = 0; Index < 6; ++Index) // cebernic: checking for 6items ,untradable item check via others func.
		{
			Item * pItem;

			// safely trade checking
			pItem = _player->mTradeItems[Index];
			if( pItem )
			{
				if( ( pItem->IsContainer() && ((Container*)pItem)->HasItems() )   || ( pItem->GetProto() && pItem->GetProto()->Bonding==ITEM_BIND_ON_PICKUP) )
				{
					ItemCount = 0;
					TargetItemCount = 0;
					break;
				}
				else ++ItemCount;
			}					
			
			pItem = pTarget->mTradeItems[Index];
			if( pItem )
			{
				if( ( pItem->IsContainer() && ((Container*)pItem)->HasItems() )   || ( pItem->GetProto() && pItem->GetProto()->Bonding==ITEM_BIND_ON_PICKUP) )
				{
					ItemCount = 0;
					TargetItemCount = 0;
					break;
				}
				else ++TargetItemCount;
			}					

			//if(_player->mTradeItems[Index] != 0)	++ItemCount;
			//if(pTarget->mTradeItems[Index] != 0)	++TargetItemCount;
		}

		

		if( (_player->m_ItemInterface->CalculateFreeSlots(NULL) + ItemCount) < TargetItemCount ||
			(pTarget->m_ItemInterface->CalculateFreeSlots(NULL) + TargetItemCount) < ItemCount ||
			(ItemCount==0 && TargetItemCount==0 && !pTarget->mTradeGold && !_player->mTradeGold) )	// cebernic added it
		{
			// Not enough slots on one end.
			TradeStatus = TRADE_STATUS_CANCELLED;
		}
		else
		{
			TradeStatus = TRADE_STATUS_COMPLETE;
			uint64 Guid;
			Item * pItem;
			
			// Remove all items from the players inventory
			for(uint32 Index = 0; Index < 6; ++Index)
			{
				Guid = _player->mTradeItems[Index] ? _player->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( _player->mTradeItems[Index]->GetProto()->Bonding == ITEM_BIND_ON_PICKUP ||
						_player->mTradeItems[Index]->GetProto()->Bonding  >=  ITEM_BIND_QUEST  )
					{
						_player->mTradeItems[Index] = NULL;
					}
					else
					{
						if(GetPermissionCount()>0)
						{
							sGMLog.writefromsession(this, "traded item %s to %s", _player->mTradeItems[Index]->GetProto()->Name1, pTarget->GetName());
						}
						pItem = _player->m_ItemInterface->SafeRemoveAndRetreiveItemByGuid(Guid, true);
					}
				}

				Guid = pTarget->mTradeItems[Index] ? pTarget->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( pTarget->mTradeItems[Index]->GetProto()->Bonding == ITEM_BIND_ON_PICKUP ||  
						pTarget->mTradeItems[Index]->GetProto()->Bonding  >=  ITEM_BIND_QUEST )
					{
						pTarget->mTradeItems[Index] = NULL;
					}
					else
					{
						pTarget->m_ItemInterface->SafeRemoveAndRetreiveItemByGuid(Guid, true);
					}
				}
			}

			// Dump all items back into the opposite players inventory
			for(uint32 Index = 0; Index < 6; ++Index)
			{
				pItem = _player->mTradeItems[Index];
				if( pItem != NULL )
				{
					pItem->SetOwner(pTarget); // crash fixed.
					if( !pTarget->m_ItemInterface->AddItemToFreeSlot(pItem) )
						pItem->DeleteMe();
				}

				pItem = pTarget->mTradeItems[Index];
				if( pItem != NULL )
				{
					pItem->SetOwner(_player);
					if( !_player->m_ItemInterface->AddItemToFreeSlot(pItem) )
						pItem->DeleteMe();
				}
			}

			// Trade Gold
			if(pTarget->mTradeGold)
			{
				// Check they don't have more than the max gold
				if(sWorld.GoldCapEnabled && (_player->GetUInt32Value(PLAYER_FIELD_COINAGE) + pTarget->mTradeGold) > sWorld.GoldLimit)
				{
					_player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_TOO_MUCH_GOLD);
				}
				else
				{
					_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, pTarget->mTradeGold);
					pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pTarget->mTradeGold);
				}
			}

			if(_player->mTradeGold)
			{
				// Check they don't have more than the max gold
				if(sWorld.GoldCapEnabled && (pTarget->GetUInt32Value(PLAYER_FIELD_COINAGE) + _player->mTradeGold) > sWorld.GoldLimit)
				{
					pTarget->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_TOO_MUCH_GOLD);
				}
				else
				{
					pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, _player->mTradeGold);
					_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)_player->mTradeGold);
				}
			}

			// Close Window
			TradeStatus = TRADE_STATUS_COMPLETE;
			
		}
					
#ifdef USING_BIG_ENDIAN
            swap32(&TradeStatus);
			OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
			plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
			swap32(&TradeStatus);
#else
			OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
			plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
#endif

			_player->mTradeStatus = TRADE_STATUS_COMPLETE;
			plr->mTradeStatus = TRADE_STATUS_COMPLETE;

			// Reset Trade Vars
			_player->ResetTradeVariables();
			pTarget->ResetTradeVariables();
			
			plr->mTradeTarget = 0;
			_player->mTradeTarget = 0;

			// Save for each other
			plr->SaveToDB(false);
			_player->SaveToDB(false);
	}
}
示例#6
0
void WorldSession::HandleTakeItem(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	uint32 lowguid;
	vector< uint64 >::iterator itr;

	recv_data >> mailbox >> message_id >> lowguid;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_ITEM_TAKEN);
	
	MailMessage * message = _player->m_mailBox.GetMessage(message_id);
	if(message == 0 || message->items.empty())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	for( itr = message->items.begin( ); itr != message->items.end( ); ++itr )
	{
		if ( (*itr) == lowguid )
			break;
	}

	if( itr == message->items.end( ) )
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// check for cod credit
	if(message->cod > 0)
	{
		if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < message->cod)
		{
			data << uint32(MAIL_ERR_NOT_ENOUGH_MONEY);
			SendPacket(&data);
			return;
		}
	}

	// grab the item
	Item * item = objmgr.LoadItem( *itr );
	if(item == 0)
	{
		// doesn't exist
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);
		
		return;
	}

	// find a free bag slot
	SlotResult result = _player->GetItemInterface()->FindFreeInventorySlot(item->GetProto());
	if(result.Result == 0)
	{
		// no free slots left!
		data << uint32(MAIL_ERR_BAG_FULL);
		SendPacket(&data);

		item->DeleteMe();
		return;
	}

	// all is good
	// delete the item (so when its resaved it'll have an association)
	item->DeleteFromDB();

	// add the item to their backpack
	item->m_isDirty = true;

	// send complete packet
	data << uint32(MAIL_OK);
	data << item->GetUInt32Value(OBJECT_FIELD_GUID);
	data << item->GetUInt32Value(ITEM_FIELD_STACK_COUNT);

	if( !_player->GetItemInterface()->AddItemToFreeSlot(item) )
		item->DeleteMe();

	message->items.erase( itr );

	// re-save (update the items field)
	sMailSystem.SaveMessageToSQL( message);
	SendPacket(&data);
	
	if( message->cod > 0 )
	{
		_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -int32(message->cod));
		string subject = "COD Payment: ";
		subject += message->subject;
		sMailSystem.SendAutomatedMessage(NORMAL, message->player_guid, message->sender_guid, subject, "", message->cod, 0, 0, 1);

		message->cod = 0;
		CharacterDatabase.Execute("UPDATE mailbox SET cod = 0 WHERE message_id = %u", message->message_id);
	}

	// prolly need to send an item push here
}
示例#7
0
void WorldSession::HandleSendMail(WorldPacket& recv_data)
{
    CHECK_INWORLD_RETURN

    MailMessage msg;
    ObjectGuid mailbox;
    uint32 unk1, unk2;
    uint64 money, COD;
    uint32 bodyLength, subjectLength, receiverLength;
    std::string receiver, subject, body;

    std::vector< Item* > items;
    std::vector< Item* >::iterator itr;
    Item* pItem;

    recv_data >> unk1;
    recv_data >> unk2;

    recv_data >> COD;
    recv_data >> money;

    bodyLength = recv_data.readBits(12);
    subjectLength = recv_data.readBits(9);

    uint8 items_count = recv_data.readBits(5);              // attached items count

    if (items_count > MAIL_MAX_ITEM_SLOT)
    {
        SendMailError(MAIL_ERR_TOO_MANY_ATTACHMENTS);
        return;
    }

    mailbox[0] = recv_data.readBit();

    ObjectGuid itemGUIDs[MAIL_MAX_ITEM_SLOT];

    for (uint8 i = 0; i < items_count; ++i)
    {
        itemGUIDs[i][2] = recv_data.readBit();
        itemGUIDs[i][6] = recv_data.readBit();
        itemGUIDs[i][3] = recv_data.readBit();
        itemGUIDs[i][7] = recv_data.readBit();
        itemGUIDs[i][1] = recv_data.readBit();
        itemGUIDs[i][0] = recv_data.readBit();
        itemGUIDs[i][4] = recv_data.readBit();
        itemGUIDs[i][5] = recv_data.readBit();
    }

    mailbox[3] = recv_data.readBit();
    mailbox[4] = recv_data.readBit();
    receiverLength = recv_data.readBits(7);
    mailbox[2] = recv_data.readBit();
    mailbox[6] = recv_data.readBit();
    mailbox[1] = recv_data.readBit();
    mailbox[7] = recv_data.readBit();
    mailbox[5] = recv_data.readBit();

    recv_data.ReadByteSeq(mailbox[4]);

    for (uint8 i = 0; i < items_count; ++i)
    {
        recv_data.ReadByteSeq(itemGUIDs[i][6]);
        recv_data.ReadByteSeq(itemGUIDs[i][1]);
        recv_data.ReadByteSeq(itemGUIDs[i][7]);
        recv_data.ReadByteSeq(itemGUIDs[i][2]);
        recv_data.read_skip<uint8>();            // item slot in mail, not used
        recv_data.ReadByteSeq(itemGUIDs[i][3]);
        recv_data.ReadByteSeq(itemGUIDs[i][0]);
        recv_data.ReadByteSeq(itemGUIDs[i][4]);
        recv_data.ReadByteSeq(itemGUIDs[i][5]);
    }

    recv_data.ReadByteSeq(mailbox[7]);
    recv_data.ReadByteSeq(mailbox[3]);
    recv_data.ReadByteSeq(mailbox[6]);
    recv_data.ReadByteSeq(mailbox[5]);

    subject = recv_data.ReadString(subjectLength);
    receiver = recv_data.ReadString(receiverLength);

    recv_data.ReadByteSeq(mailbox[2]);
    recv_data.ReadByteSeq(mailbox[0]);

    body = recv_data.ReadString(bodyLength);

    recv_data.ReadByteSeq(mailbox[1]);

    // packet read complete, now do check

    // Search for the recipient
    PlayerInfo* player = ObjectMgr::getSingleton().GetPlayerInfoByName(receiver.c_str());
    if (player == NULL)
    {
        SendMailError(MAIL_ERR_RECIPIENT_NOT_FOUND);
        return;
    }

    for (uint8 i = 0; i < items_count; ++i)
    {
        pItem = _player->GetItemInterface()->GetItemByGUID(itemGUIDs[i]);
        if (pItem == NULL || pItem->IsSoulbound() || pItem->IsConjured())
        {
            SendMailError(MAIL_ERR_INTERNAL_ERROR);
            return;
        }
        if (pItem->IsAccountbound() && GetAccountId() != player->acct) // don't mail account-bound items to another account
        {
            WorldPacket data(SMSG_SEND_MAIL_RESULT, 16);
            data << uint32(0);
            data << uint32(0);
            data << uint32(MAIL_ERR_BAG_FULL);
            data << uint32(INV_ERR_ARTEFACTS_ONLY_FOR_OWN_CHARACTERS);
            SendPacket(&data);
            return;
        }

        items.push_back(pItem);
    }

    if (receiver.empty())
        return;

    bool interfaction = false;
    if (sMailSystem.MailOption(MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION) || (HasGMPermissions() && sMailSystem.MailOption(MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION_GM)))
    {
        interfaction = true;
    }

    // Check we're sending to the same faction (disable this for testing)
    if (player->team != _player->GetTeam() && !interfaction)
    {
        SendMailError(MAIL_ERR_NOT_YOUR_ALLIANCE);
        return;
    }

    // Check if we're sending mail to ourselves
    if (strcmp(player->name, _player->GetName()) == 0 && !GetPermissionCount())
    {
        SendMailError(MAIL_ERR_CANNOT_SEND_TO_SELF);
        return;
    }

    if (msg.stationery == MAIL_STATIONERY_GM && !HasGMPermissions())
    {
        SendMailError(MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    // Instant delivery time by default.
    msg.delivery_time = (uint32)UNIXTIME;

    // Set up the cost
    uint32 cost = items_count ? 30 * items_count : 30;  // price hardcoded in client

    uint64 reqmoney = cost + money;

    if (!sMailSystem.MailOption(MAIL_FLAG_DISABLE_POSTAGE_COSTS) && !(GetPermissionCount() && sMailSystem.MailOption(MAIL_FLAG_NO_COST_FOR_GM)))
    {
        cost += 30;
    }

    // check that we have enough in our backpack
    if (!_player->HasGold(cost))
    {
        SendMailError(MAIL_ERR_NOT_ENOUGH_MONEY);
        return;
    }

    // Check for the item, and required item.
    if (!items.empty())
    {
        for (itr = items.begin(); itr != items.end(); ++itr)
        {
            pItem = *itr;
            if (_player->GetItemInterface()->SafeRemoveAndRetreiveItemByGuid(pItem->GetGUID(), false) != pItem)
                continue;        // should never be hit.

            pItem->RemoveFromWorld();
            pItem->SetOwner(NULL);
            pItem->SaveToDB(INVENTORY_SLOT_NOT_SET, 0, true, NULL);
            msg.items.push_back(pItem->GetLowGUID());

            if (GetPermissionCount() > 0)
            {
                /* log the message */
                sGMLog.writefromsession(this, "sent mail with item entry %u to %s, with gold %u.", pItem->GetEntry(), player->name, money);
            }

            pItem->DeleteMe();
        }
    }

    if (money != 0 || COD != 0 || (!items.size() && player->acct != _player->GetSession()->GetAccountId()))
    {
        if (!sMailSystem.MailOption(MAIL_FLAG_DISABLE_HOUR_DELAY_FOR_ITEMS))
            msg.delivery_time += 3600;  // 1hr
    }

    // take the money
    _player->ModGold(-cost);

    // Fill in the rest of the info
    msg.player_guid = player->guid;
    msg.sender_guid = _player->GetGUID();
    msg.money = money;
    msg.cod = COD;
    msg.subject = subject;
    msg.body = body;

    // 30 day expiry time for unread mail
    if (!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
        msg.expire_time = (uint32)UNIXTIME + (TIME_DAY * MAIL_DEFAULT_EXPIRATION_TIME);
    else
        msg.expire_time = 0;

    msg.deleted_flag = false;
    msg.message_type = 0;
    msg.checked_flag = msg.body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY;

    // Great, all our info is filled in. Now we can add it to the other players mailbox.
    sMailSystem.DeliverMessage(player->guid, &msg);
    // Save/Update character's gold if they've received gold that is. This prevents a rollback.
    CharacterDatabase.Execute("UPDATE characters SET gold = %u WHERE guid = %u", _player->GetGold(), _player->m_playerInfo->guid);
    // Success packet :)
    SendMailError(MAIL_OK);
}
示例#8
0
void WorldSession::HandleSetTradeItem(WorldPacket & recv_data)
{
#ifdef FORCED_GM_TRAINEE_MODE
	if( CanUseCommand('k') && !HasGMPermissions() )
	{
		GetPlayer()->BroadcastMessage( "You are not allowed to use this feature" );
		return;
	}
#endif
	if(_player->mTradeTarget == 0)
	{ 
		sLog.outDebug("HandleSetTradeItem: missing trade target\n");
		return;
	}

	if(!_player->IsInWorld()) 
	{ 
		sLog.outDebug("HandleSetTradeItem: not in world\n");
		return;
	}
	  
	CHECK_PACKET_SIZE(recv_data, 3);

	uint8 TradeSlot = recv_data.contents()[1];
	uint8 SourceSlot = recv_data.contents()[2];
	uint8 SourceBag = recv_data.contents()[0];
	Player * pTarget = _player->GetTradeTarget();

	Item * pItem = _player->GetItemInterface()->GetInventoryItem(SourceBag, SourceSlot);

	if( pTarget == NULL || pItem == 0 || TradeSlot >= TRADE_TOTAL_TRADE_SLOTS || ( TradeSlot < TRADE_MAX_TRADABLE_ITEMS && pItem->IsSoulbound() ) )
	{ 
		sLog.outDebug("HandleSetTradeItem: target missing or incorect item/slot. target(%u),item(%u),slot(%u))\n",pTarget != NULL,pItem != 0,TradeSlot );
 		return;
	}

	if( TradeSlot < TRADE_MAX_TRADABLE_ITEMS && pItem->IsAccountbound() )
	{
		PlayerInfo* pinfo = ObjectMgr::getSingleton().GetPlayerInfo(_player->mTradeTarget);
		if(pinfo == NULL || GetAccountId() != pinfo->acct) // can't trade account-based items
		{ 
			sLog.outDebug("HandleSetTradeItem: item is account bound\n");
			return;
		}
	}
/*	if( pItem->IsContainer() )
	{
		if(_player->GetItemInterface()->IsBagSlot(SourceSlot))
		return;*/
		
	packetSMSG_TRADE_STATUS data;
	memset( &data, 0, sizeof( data ) );
//	data.trade_status = TRADE_STATUS_STATE_CHANGED;
//	OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);
//	pTarget->m_session->OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);

	pTarget->mTradeStatus = TRADE_STATUS_STATE_CHANGED;
	_player->mTradeStatus = TRADE_STATUS_STATE_CHANGED;


	if( pItem->IsContainer() )
	{
		if( SafeContainerCast(pItem)->HasItems() )
		{
			_player->GetItemInterface()->BuildInventoryChangeError(pItem,0, INV_ERR_CAN_ONLY_DO_WITH_EMPTY_BAGS);

			//--trade cancel
			data.trade_status = TRADE_STATUS_CANCELLED;
			OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);
			
			Player * plr = _player->GetTradeTarget();
			if(plr)
			{
			    if(plr->m_session && plr->m_session->GetSocket())
					plr->m_session->OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);
			    plr->ResetTradeVariables();
			}

			_player->ResetTradeVariables();
			sLog.outDebug("HandleSetTradeItem: Container with items cannot be traded\n");
			return;
		}
	}			
		
	//well that covers all slots i think (MAX_TRADE_TRADABLE_ITEMS is temporal slot)
	if(TradeSlot < TRADE_MAX_TRADABLE_ITEMS)
	{
		if(pItem->IsSoulbound())
		{
			sCheatLog.writefromsession(this, "tried to cheat trade a soulbound item");
			sLog.outDebug("HandleSetTradeItem: Cannot trade soulbound item\n");
			Item *ti = _player->GetItemInterface()->SafeRemoveAndRetreiveItemFromSlot(SourceBag, SourceSlot, false);
			if( ti )
			{
				ti->DeleteFromDB();
				ti->DeleteMe();
				ti = NULL;
			}
			string sReason = "Soulboundtrade 1";
			uint32 uBanTime = (uint32)UNIXTIME + 60*60; //60 minutes ban
			_player->SetBanned( uBanTime, sReason );
			sEventMgr.AddEvent( _player, &Player::_Kick, EVENT_PLAYER_KICK, 7000, 1, 0 );
			return; //item is not valid anymore !
		}
		//this was checked earlier ? How the hack did we get here again ?
		else if(pItem->IsAccountbound() && pTarget->GetSession() && pTarget->GetSession()->GetAccountId() != GetAccountId() )
		{
			PlayerInfo* pinfo = ObjectMgr::getSingleton().GetPlayerInfo(_player->mTradeTarget);
			if(pinfo == NULL || GetAccountId() != pinfo->acct) // can't trade account-based items
			{
				sLog.outDebug("HandleSetTradeItem: Cannot trade account bound item\n");
				sCheatLog.writefromsession(this, "tried to cheat trade an accountbound item");
				Item *ti = _player->GetItemInterface()->SafeRemoveAndRetreiveItemFromSlot(SourceBag, SourceSlot, false);
				if( ti )
				{
					ti->DeleteFromDB();
					ti->DeleteMe();
					ti = NULL;
				}
				string sReason = "Account bound itemtrade";
				uint32 uBanTime = (uint32)UNIXTIME + 60*60; //60 minutes ban
				_player->SetBanned( uBanTime, sReason );
				sEventMgr.AddEvent( _player, &Player::_Kick, EVENT_PLAYER_KICK, 7000, 1, 0 );
				return; //item is not valid anymore !
			}
		}
	}

	for(uint32 i = 0; i < TRADE_TOTAL_TRADE_SLOTS; ++i)
	{
		// duping little shits
		if( TradeSlot != i && ( _player->mTradeItems[i] == pItem || pTarget->mTradeItems[i] == pItem ) )
		{
			sCheatLog.writefromsession(this, "tried to dupe an item through trade");
			Item *ti = _player->GetItemInterface()->SafeRemoveAndRetreiveItemFromSlot(SourceBag, SourceSlot, false);
			if( ti )
			{
				ti->DeleteFromDB();
				ti->DeleteMe();
				ti = NULL;
			}
			GetPlayer()->SoftDisconnect();
			sLog.outDebug("HandleSetTradeItem: item dupe detected\n");
			return;
		}
	}

	if( SourceBag <= INVENTORY_SLOT_NOT_SET && //we are removing from our direct character slot and not from a bag
		SourceSlot >= INVENTORY_SLOT_BAG_START && SourceSlot < INVENTORY_SLOT_BAG_END)
	{
		//More duping woohoo
        Item *ti = _player->GetItemInterface()->SafeRemoveAndRetreiveItemFromSlot(SourceBag, SourceSlot, false);
		if( ti )
		{
			ti->DeleteFromDB();
			ti->DeleteMe();
			ti = NULL;
		}
		sCheatLog.writefromsession(this, "tried to cheat trade a soulbound item");
		string sReason = "trading from bagslot";
		uint32 uBanTime = (uint32)UNIXTIME + 60*60; //60 minutes ban
		_player->SetBanned( uBanTime, sReason );
		sEventMgr.AddEvent( _player, &Player::_Kick, EVENT_PLAYER_KICK, 7000, 1, 0 );
		sLog.outDebug("HandleSetTradeItem: Cannot trade from bagslot\n");
		return; //item is not valid anymore !
	}

	_player->mTradeItems[TradeSlot] = pItem;
	_player->SendTradeUpdate();
}
示例#9
0
void WorldSession::HandleTakeItem(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	uint32 lowguid;
	vector< uint64 >::iterator itr;

	recv_data >> mailbox >> message_id >> lowguid;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_ITEM_TAKEN);

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired() || message->items.empty())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	for( itr = message->items.begin( ); itr != message->items.end( ); itr++ )
	{
		if ( (*itr) == lowguid )
			break;
	}

	if( itr == message->items.end( ) )
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// check for cod credit
	if(message->cod > 0)
	{
		if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < message->cod)
		{
			data << uint32(MAIL_ERR_NOT_ENOUGH_MONEY);
			SendPacket(&data);
			return;
		}
	}

	// grab the item
	Item* item = objmgr.LoadItem( *itr );
	if(item == 0)
	{
		// doesn't exist
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// find a free bag slot
	SlotResult result = _player->GetItemInterface()->FindFreeInventorySlot(item->GetProto());
	if(result.Result == 0)
	{
		// no free slots left!
		data << uint32(MAIL_ERR_BAG_FULL);
		SendPacket(&data);

		item->DeleteMe();
		item = NULLITEM;
		return;
	}

	item->m_isDirty = true;

	if( !_player->GetItemInterface()->SafeAddItem(item, result.ContainerSlot, result.Slot) )
	{
		if( !_player->GetItemInterface()->AddItemToFreeSlot(item) )
		{
			// no free slots left!
			data << uint32(MAIL_ERR_BAG_FULL);
			SendPacket(&data);
			item->DeleteMe();
			item = NULLITEM;
			return;
		}
	}
	else												// true so it waitexecute's
		item->SaveToDB(result.ContainerSlot, result.Slot, true, NULL);

	// send complete packet
	data << uint32(MAIL_OK);
	data << item->GetUInt32Value(OBJECT_FIELD_GUID);
	data << item->GetUInt32Value(ITEM_FIELD_STACK_COUNT);

	message->items.erase( itr );

	if ((message->items.size() == 0) && (message->money == 0))
	{
		// mail now has a 3 day expiry time
		if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
			message->expire_time = (uint32)UNIXTIME + (TIME_DAY * 3);
	}

	if( message->cod > 0 )
	{
		_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -int32(message->cod));
		string subject = "COD Payment: ";
		subject += message->subject;
		sMailSystem.DeliverMessage(MAILTYPE_NORMAL, message->player_guid, message->sender_guid, subject, "", message->cod, 0, 0, 1, true);

		message->cod = 0;
		CharacterDatabase.Execute("UPDATE mailbox SET cod = 0 WHERE message_id = %u", message->message_id);
	}

	// re-save (update the items field)
	message->SaveToDB();// sMailSystem.SaveMessageToSQL( message);
	SendPacket(&data);

	// prolly need to send an item push here
}
示例#10
0
bool EyeOfTheStorm::GivePoints(uint32 team, uint32 points)
{
	uint32 honor;
	//printf("EOTS: Give team %u %u points.\n", team, points);

	m_points[team] += points;
	if( m_points[team] >= 2000 )
	{
		m_points[team] = 2000;

		m_ended = true;
		m_winningteam = team;
		m_nextPvPUpdateTime = 0;

		sEventMgr.RemoveEvents(this);
		sEventMgr.AddEvent(((CBattleground*)this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);

		/* add the marks of honor to all players */
		m_mainLock.Acquire();

		for(uint32 i = 0; i < 2; ++i)
		{
			for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
			{
				(*itr)->Root();
				
				if ( (*itr)==NULL )// never happen?
					continue;

				/* Winning team will gain 2000 / 12 = 166.6 extra honor points */
				/* On weekend 2000 / 8 = 250 (guessing) */
				/* Losing team will also gain the honor from already earned points */
				honor = m_points[i] / extraHonorDiv;
				(*itr)->m_bgScore.BonusHonor += honor;
				HonorHandler::AddHonorPointsToPlayer((*itr), honor);

				if(i == m_winningteam)
				{				
					Item *item;
					item = objmgr.CreateItem( 29024 , *itr);
					item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,3);
					item->SoulBind();
					if(!(*itr)->GetItemInterface()->AddItemToFreeSlot(item))
					{
						(*itr)->GetSession()->SendNotification("No free slots were found in your inventory!");
						item->DeleteMe();
					}
					else
					{
						SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult();
						(*itr)->GetSession()->SendItemPushResult(item,false,true,false,true,lr->ContainerSlot,lr->Slot,3);
					}
				}
				else
				{
					Item *item;
					item = objmgr.CreateItem( 29024 , *itr);
					item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,1);
					item->SoulBind();
					if(!(*itr)->GetItemInterface()->AddItemToFreeSlot(item))
					{
						(*itr)->GetSession()->SendNotification("No free slots were found in your inventory!");
						item->DeleteMe();
					}
					else
					{
						SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult();
						(*itr)->GetSession()->SendItemPushResult(item,false,true,false,true,lr->ContainerSlot,lr->Slot,1);
					}
				}
			}
		}
		m_mainLock.Release();
		SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] );
		UpdatePvPData();
		return true;
	}

	SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] );
	return false;
}
示例#11
0
void WorldSession::HandleSendMail(WorldPacket & recv_data )
{
	MailMessage msg;
	uint64 gameobject;
	uint32 unk2;
	uint8 itemcount;
	uint8 itemslot;
	uint8 i;
	uint64 itemguid;
	vector< Item* > items;
	vector< Item* >::iterator itr;
	string recepient;
	Item* pItem;
	int8 real_item_slot;

	recv_data >> gameobject >> recepient;
	// Search for the recipient
	PlayerInfo* player = ObjectMgr::getSingleton().GetPlayerInfoByName(recepient.c_str());
	if( player == NULL )
	{
		SendMailError(MAIL_ERR_RECIPIENT_NOT_FOUND);
		return;
	}
	msg.player_guid = player->guid;
	msg.sender_guid = _player->GetGUID();

	recv_data >> msg.subject >> msg.body >> msg.stationary;

	// Check attached items
	recv_data >> unk2 >> itemcount;
	for( i = 0; i < itemcount; i++ )
	{
		recv_data >> itemslot;
		recv_data >> itemguid;

		pItem = _player->GetItemInterface()->GetItemByGUID( itemguid );
		real_item_slot = _player->GetItemInterface()->GetInventorySlotByGuid( itemguid );
		if( pItem == NULL || pItem->HasFlag( ITEM_FIELD_FLAGS, ITEM_FLAG_CONJURED ) )
		{
			SendMailError(MAIL_ERR_BAG_FULL, INV_ERR_CANNOT_TRADE_THAT);
			return;
		}

		if( ( pItem->IsContainer() && (TO_CONTAINER( pItem ))->HasItems() ) || real_item_slot >= 0 && real_item_slot < INVENTORY_SLOT_ITEM_START )
		{
			SendMailError(MAIL_ERR_BAG_FULL, INV_ERR_CANT_TRADE_EQUIP_BAGS);
			return;
		}

		if(pItem->IsAccountbound()) // don't mail account-bound items to another account
		{
			if(GetAccountId() != player->acct)
			{
				SendMailError(MAIL_ERR_BAG_FULL, INV_ERR_ACCOUNT_BOUND);
				return;
			}
		}
		else if(pItem->IsSoulbound())
		{
			SendMailError(MAIL_ERR_BAG_FULL, INV_ERR_CANNOT_TRADE_THAT);
			return;
		}

		items.push_back( pItem );
	}

	if( items.size() > 12 || msg.body.find("%") != string::npos || msg.subject.find("%") != string::npos)
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	recv_data >> msg.money;
	recv_data >> msg.cod;
	// left over: (TODO- FIX ME BURLEX!)
	// uint32
	// uint32
	// uint8

	// Check if we're sending mail to ourselves
	if(msg.player_guid == msg.sender_guid && !GetPermissionCount())
	{
		SendMailError(MAIL_ERR_CANNOT_SEND_TO_SELF);
		return;
	}

	// Check stationary
	if(msg.stationary != STATIONERY_GM && HasGMPermissions())
	{
		msg.stationary = STATIONERY_GM; // GM mail always has GM Stationary.
	}

	if( msg.stationary == STATIONERY_GM && !HasGMPermissions())
	{
		msg.stationary = STATIONERY_NORMAL; // Send stationary as normal instead.
	}

	// Set up the cost
	int32 cost = 0;
	if( !sMailSystem.MailOption( MAIL_FLAG_DISABLE_POSTAGE_COSTS ) && !( GetPermissionCount() && sMailSystem.MailOption( MAIL_FLAG_NO_COST_FOR_GM ) ) )
	{
		cost = 30;
	}
	// Check for attached money
	if( msg.money > 0 )
		cost += msg.money;
	if( cost < 0 )
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}
	// check that we have enough in our backpack
	if( (int32)_player->GetUInt32Value( PLAYER_FIELD_COINAGE ) < cost )
	{
		SendMailError( MAIL_ERR_NOT_ENOUGH_MONEY );
		return;
	}

	// Check we're sending to the same faction (disable this for testing)
	bool interfaction = (sMailSystem.MailOption( MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION ) || (HasGMPermissions() && sMailSystem.MailOption( MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION_GM ) ));
	if(!interfaction)
	{
		if(player->team != _player->GetTeam())
		{
			SendMailError( MAIL_ERR_NOT_YOUR_ALLIANCE );
			return;
		}
	}

	msg.message_id = 0;
	msg.message_type = 0;
	msg.copy_made = false;
	msg.read_flag = false;
	msg.deleted_flag = false;
	msg.returned_flag = false;
	msg.delivery_time = (uint32)UNIXTIME;

	if(msg.money != 0 || msg.cod != 0 || !items.size() && player->acct != _player->GetSession()->GetAccountId())
	{
		if(!sMailSystem.MailOption(MAIL_FLAG_DISABLE_HOUR_DELAY_FOR_ITEMS))
			msg.delivery_time += 3600;  // +1hr
	}

	msg.expire_time = 0;
	if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
	{
		msg.expire_time = (uint32)UNIXTIME + (TIME_DAY * 30);
	}

	if (items.empty() && msg.money != 0 && HasGMPermissions())
		sWorld.LogGM(this, "sent mail with %u gold to %s (Acct: %u, Charid: %u).", msg.money, player->name, player->acct, player->guid);

	// Sending Message
	// take the money
	_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -cost);
	// Check for the item, and required item.
	if( !items.empty( ) )
	{
		for( itr = items.begin(); itr != items.end(); itr++ )
		{
			pItem = *itr;
			if( _player->GetItemInterface()->SafeRemoveAndRetreiveItemByGuid(pItem->GetGUID(), false) != pItem )
				continue;		// should never be hit.

			pItem->RemoveFromWorld();
			pItem->SetOwner( NULLPLR );
			pItem->SaveToDB( INVENTORY_SLOT_NOT_SET, 0, true, NULL );
			msg.items.push_back( pItem->GetUInt32Value(OBJECT_FIELD_GUID) );

			if( HasGMPermissions() )
				sWorld.LogGM(this, "sent mail with item entry %u to %s, with gold %u.", pItem->GetEntry(), player->name, msg.money);

			pItem->DeleteMe();
			pItem = NULLITEM;
		}
	}

	// Great, all our info is filled in. Now we can add it to the other players mailbox.
	sMailSystem.DeliverMessage(&msg);

	// Success packet :)
	SendMailError(MAIL_OK);
}
示例#12
0
bool Mailbox::AddMessageToListingPacket(WorldPacket& data,MailMessage *msg)
{
	uint8 i = 0;
	uint32 j;
	size_t pos;
	vector<uint64>::iterator itr;
	Item* pItem;

	// add stuff
	if(msg->deleted_flag || msg->Expired() || (uint32)UNIXTIME < msg->delivery_time)
		return false;

	uint8 guidsize;
	if( msg->message_type )
		guidsize = 4;
	else
		guidsize = 8;

	size_t msize = 2 + 4 + 1 + guidsize + 7 * 4 + ( msg->subject.size() + 1 ) + ( msg->body.size() + 1 ) + 1 + ( msg->items.size() * ( 1 + 2*4 + 7 * ( 3*4 ) + 6*4 + 1 ) );

	data << uint16(msize);
	data << msg->message_id;
	data << uint8(msg->message_type);
	if(msg->message_type)
		data << uint32(msg->sender_guid);
	else
		data << msg->sender_guid;

	data << msg->cod;
	data << uint32(0);
	data << msg->stationary;
	data << msg->money; // money
	data << uint32(0x10);
	data << float((msg->expire_time - uint32(UNIXTIME)) / 86400.0f);
	data << uint32( 0 );	// mail template
	data << msg->subject;
	data << msg->body; // subjectbody
	pos = data.wpos();
	data << uint8(0);		// item count

	if( !msg->items.empty( ) )
	{
		for( itr = msg->items.begin( ); itr != msg->items.end( ); itr++ )
		{
			pItem = objmgr.LoadItem( *itr );
			if( pItem == NULL )
				continue;

			data << uint8(i++);
			data << pItem->GetLowGUID();
			data << pItem->GetEntry();

			for( j = 0; j < 7; ++j )
			{
				data << pItem->GetUInt32Value( ITEM_FIELD_ENCHANTMENT_1_1 + ( j * 3 ) );
				data << pItem->GetUInt32Value( (ITEM_FIELD_ENCHANTMENT_1_1 + 1) + ( j * 3 ) );
				data << pItem->GetUInt32Value( ITEM_FIELD_ENCHANTMENT_1_3 + ( j * 3 ) );
			}

			data << pItem->GetUInt32Value( ITEM_FIELD_RANDOM_PROPERTIES_ID );
			if( ( (int32)pItem->GetUInt32Value( ITEM_FIELD_RANDOM_PROPERTIES_ID ) ) < 0 )
				data << pItem->GetItemRandomSuffixFactor();
			else
				data << uint32( 0 );

			data << uint32( pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT) );
			data << uint32( pItem->GetChargesLeft() );
			data << pItem->GetUInt32Value( ITEM_FIELD_MAXDURABILITY );
			data << pItem->GetUInt32Value( ITEM_FIELD_DURABILITY );
			data << uint8(0);
			pItem->DeleteMe();
			pItem = NULLITEM;
		}
		data.put< uint8 >( pos, i );
	}

	return true;
}
示例#13
0
void LootRoll::Finalize()
{
	sEventMgr.RemoveEvents(this);

	// this we will have to finalize with groups types.. for now
	// we'll just assume need before greed. person with highest roll
	// in need gets the item.

	uint32 highest = 0;
	int8 hightype = -1;
	uint64 player = 0;

	WorldPacket data(34);

	/*
		Player * gplr = NULL;
		for(std::map<uint64, uint32>::iterator itr = NeedRolls.begin(); itr != NeedRolls.end(); ++itr)
		{
			gplr = _mgr->GetPlayer((uint32)itr->first);
			if(gplr) break;
		}

		if(!gplr)
		{
			for(std::map<uint64, uint32>::iterator itr = GreedRolls.begin(); itr != GreedRolls.end(); ++itr)
			{
				gplr = _mgr->GetPlayer((uint32)itr->first);
				if(gplr) break;
			}
		}
	*/
	for(std::map<uint32, uint32>::iterator itr = m_NeedRolls.begin(); itr != m_NeedRolls.end(); ++itr)
	{
		if(itr->second > highest)
		{
			highest = itr->second;
			player = itr->first;
			hightype = NEED;
		}
		/*
		data.Initialize(SMSG_LOOT_ROLL);
		data << _guid << _slotid << itr->first;
		data << _itemid << _randomsuffixid << _randompropertyid;
		data << uint8(itr->second) << uint8(NEED);
		if(gplr && gplr->GetGroup())
			gplr->GetGroup()->SendPacketToAll(&data);
		*/
	}

	if(!highest)
	{
		for(std::map<uint32, uint32>::iterator itr = m_GreedRolls.begin(); itr != m_GreedRolls.end(); ++itr)
		{
			if(itr->second > highest)
			{
				highest = itr->second;
				player = itr->first;
				hightype = GREED;
			}
			/*
			data.Initialize(SMSG_LOOT_ROLL);
			data << _guid << _slotid << itr->first;
			data << _itemid << _randomsuffixid << _randompropertyid;
			data << uint8(itr->second) << uint8(GREED);
			if(gplr && gplr->GetGroup())
				gplr->GetGroup()->SendPacketToAll(&data);
			*/
		}
	}

	Loot* pLoot = 0;
	uint32 guidtype = GET_TYPE_FROM_GUID(_guid);
	if(guidtype == HIGHGUID_TYPE_UNIT)
	{
		Creature* pc = _mgr->GetCreature(GET_LOWGUID_PART(_guid));
		if(pc) pLoot = &pc->loot;
	}
	else if(guidtype == HIGHGUID_TYPE_GAMEOBJECT)
	{
		GameObject* go = _mgr->GetGameObject(GET_LOWGUID_PART(_guid));
		if(go) pLoot = &go->loot;
	}

	if(!pLoot)
	{
		delete this;
		return;
	}

	if(_slotid >= pLoot->items.size())
	{
		delete this;
		return;
	}

	pLoot->items.at(_slotid).roll = NULL;

	uint32 itemid = pLoot->items.at(_slotid).item.itemproto->ItemId;
	uint32 amt = pLoot->items.at(_slotid).iItemsCount;
	if(!amt)
	{
		delete this;
		return;
	}

	Player* _player = (player) ? _mgr->GetPlayer((uint32)player) : 0;
	if(!player || !_player)
	{
		/* all passed */
		data.Initialize(SMSG_LOOT_ALL_PASSED);
		data << _guid << _groupcount << _itemid << _randomsuffixid << _randompropertyid;
		set<uint32>::iterator pitr = m_passRolls.begin();
		while(_player == NULL && pitr != m_passRolls.end())
			_player = _mgr->GetPlayer((*(pitr++)));

		if(_player != NULL)
		{
			if(_player->InGroup())
				_player->GetGroup()->SendPacketToAll(&data);
			else
				_player->GetSession()->SendPacket(&data);
		}

		/* item can now be looted by anyone :) */
		pLoot->items.at(_slotid).passed = true;
		delete this;
		return;
	}

	pLoot->items.at(_slotid).roll = 0;
	data.Initialize(SMSG_LOOT_ROLL_WON);
	data << _guid << _slotid << _itemid << _randomsuffixid << _randompropertyid;
	data << _player->GetGUID() << uint8(highest) << uint8(hightype);
	if(_player->InGroup())
		_player->GetGroup()->SendPacketToAll(&data);
	else
		_player->GetSession()->SendPacket(&data);

	ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid);

	int8 error;
	if((error = _player->GetItemInterface()->CanReceiveItem(it, 1)) != 0)
	{
		_player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, error);
		return;
	}

	Item* add = _player->GetItemInterface()->FindItemLessMax(itemid, amt, false);

	if(!add)
	{
		SlotResult slotresult = _player->GetItemInterface()->FindFreeInventorySlot(it);
		if(!slotresult.Result)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL);
			return;
		}

		LOG_DEBUG("AutoLootItem MISC");
		Item* item = objmgr.CreateItem(itemid, _player);
		if(item == NULL)
			return;

		item->SetStackCount(amt);
		if(pLoot->items.at(_slotid).iRandomProperty != NULL)
		{
			item->SetItemRandomPropertyId(pLoot->items.at(_slotid).iRandomProperty->ID);
			item->ApplyRandomProperties(false);
		}
		else if(pLoot->items.at(_slotid).iRandomSuffix != NULL)
		{
			item->SetRandomSuffix(pLoot->items.at(_slotid).iRandomSuffix->id);
			item->ApplyRandomProperties(false);
		}


		if(_player->GetItemInterface()->SafeAddItem(item, slotresult.ContainerSlot, slotresult.Slot))
		{
			_player->SendItemPushResult(false, true, true, true, slotresult.ContainerSlot, slotresult.Slot, 1, item->GetEntry(), item->GetItemRandomSuffixFactor(), item->GetItemRandomPropertyId(), item->GetStackCount());
			sQuestMgr.OnPlayerItemPickup(_player, item);
#ifdef ENABLE_ACHIEVEMENTS
			_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, item->GetEntry(), 1, 0);
#endif
		}
		else
			item->DeleteMe();
	}
	else
	{
		add->SetStackCount(add->GetStackCount() + amt);
		add->m_isDirty = true;
		sQuestMgr.OnPlayerItemPickup(_player, add);
		_player->SendItemPushResult(false, true, true, false, (uint8)_player->GetItemInterface()->GetBagSlotByGuid(add->GetGUID()), 0xFFFFFFFF, 1, add->GetEntry(), add->GetItemRandomSuffixFactor(), add->GetItemRandomPropertyId(), add->GetStackCount());
#ifdef ENABLE_ACHIEVEMENTS
		_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, add->GetEntry(), 1, 0);
#endif
	}

	pLoot->items.at(_slotid).iItemsCount = 0;
	// this gets sent to all looters
	data.Initialize(SMSG_LOOT_REMOVED);
	data << uint8(_slotid);
	Player* plr;

	for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); ++itr)
	{
		if((plr = _player->GetMapMgr()->GetPlayer(*itr)) != 0)
			plr->GetSession()->SendPacket(&data);
	}

	delete this;
}
示例#14
0
bool ChatHandler::HandleQuestStartCommand(const char * args, WorldSession * m_session)
{
	if(!*args) return false;

	Player *plr = getSelectedChar(m_session, true);
	if(!plr)
	{
		plr = m_session->GetPlayer();
		SystemMessage(m_session, "Auto-targeting self.");
	}

	uint32 quest_id = atol(args);
	if(quest_id== 0)
	{
		quest_id = GetQuestIDFromLink(args);
		if(quest_id== 0)
			return false;
	}
	std::string recout = "|cff00ff00";

	Quest * qst = QuestStorage.LookupEntry(quest_id);
	if(qst)
	{
		if (plr->HasFinishedQuest(quest_id))
			recout += "Player has already completed that quest.";
		else
		{
			QuestLogEntry * IsPlrOnQuest = plr->GetQuestLogForEntry(quest_id);
			if (IsPlrOnQuest)
				recout += "Player is currently on that quest.";
			else
			{
				int32 open_slot = plr->GetOpenQuestSlot();

				if (open_slot == -1)
				{
					sQuestMgr.SendQuestLogFull(plr);
					recout += "Player's quest log is full.";
				}
				else
				{
					sGMLog.writefromsession( m_session, "started quest %u [%s] for player %s", qst->id, qst->title, plr->GetName() );

					QuestLogEntry *qle = new QuestLogEntry();
					qle->Init(qst, plr, (uint32)open_slot);
					qle->UpdatePlayerFields();
		
					// If the quest should give any items on begin, give them the items.
					for(uint32 i = 0; i < 4; ++i)
					{
						if(qst->receive_items[i])
						{
							Item *item = objmgr.CreateItem( qst->receive_items[i], plr);
							if(item== NULL)
								return false;

							if(!plr->GetItemInterface()->AddItemToFreeSlot(item))
								item->DeleteMe();
						}
					}

					if(qst->srcitem && qst->srcitem != qst->receive_items[0])
					{
						Item * item = objmgr.CreateItem( qst->srcitem, plr);
						if(item)
						{
							item->SetStackCount(  qst->srcitemcount ? qst->srcitemcount : 1);
							if(!plr->GetItemInterface()->AddItemToFreeSlot(item))
								item->DeleteMe();
						}
					}
				

					//if(qst->count_required_item || qst_giver->GetTypeId() == TYPEID_GAMEOBJECT)	// gameobject quests deactivate
					//	plr->UpdateNearbyGameObjects();
					//ScriptSystem->OnQuestEvent(qst, static_cast< Creature* >( qst_giver ), _player, QUEST_EVENT_ON_ACCEPT);
				
					sHookInterface.OnQuestAccept( plr, qst, NULL );

					recout += "Quest has been added to the player's quest log.";
				}
			}
		}
	}
	else
	{
		recout += "Quest Id [";
		recout += args;
		recout += "] was not found and unable to add it to the player's quest log.";
	}

	recout += "\n\n";

	SendMultilineMessage(m_session, recout.c_str());

	return true;
}
示例#15
0
bool EyeOfTheStorm::GivePoints(uint32 team, uint32 points)
{
	//printf("EOTS: Give team %u %u points.\n", team, points);

	m_points[team] += points;
	if((m_points[team] - m_lastHonorGainPoints[team]) >= resourcesToGainBH)
	{
		uint32 honorToAdd = m_honorPerKill;
		m_mainLock.Acquire();
		for(set<Player*>::iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
		{
			(*itr)->m_bgScore.BonusHonor += honorToAdd;
			HonorHandler::AddHonorPointsToPlayer((*itr), honorToAdd);
		}

		UpdatePvPData();
		m_mainLock.Release();
		m_lastHonorGainPoints[team] += resourcesToGainBH;
	}

	if( m_points[team] >= 2000 )
	{
		m_points[team] = 2000;

		m_ended = true;
		m_winningteam = static_cast<uint8>( team );
		m_nextPvPUpdateTime = 0;

		sEventMgr.RemoveEvents(this);
		sEventMgr.AddEvent(((CBattleground*)this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);

		/* add the marks of honor to all players */
		uint32 lostHonorToAdd = m_honorPerKill;
		uint32 winHonorToAdd = 2 * lostHonorToAdd;
		m_mainLock.Acquire();

		for(uint32 i = 0; i < 2; ++i)
		{
			for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
			{
				(*itr)->Root();
				
				if ( (*itr)== NULL )
					continue;

				if(i == m_winningteam)
				{
					(*itr)->m_bgScore.BonusHonor += winHonorToAdd;
					HonorHandler::AddHonorPointsToPlayer((*itr), winHonorToAdd);
					Item *item = objmgr.CreateItem( 29024 , *itr );
					if( item != NULL )
					{
						item->SetUInt32Value( ITEM_FIELD_STACK_COUNT, 3 );
						item->SoulBind();
						if( !(*itr)->GetItemInterface()->AddItemToFreeSlot( item ) )
						{
							(*itr)->GetSession()->SendNotification("No free slots were found in your inventory!");
							item->DeleteMe();
						}
						else
						{
							(*itr)->m_bgScore.BonusHonor += lostHonorToAdd;
							HonorHandler::AddHonorPointsToPlayer( (*itr), lostHonorToAdd );
							SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult();
							(*itr)->GetSession()->SendItemPushResult( item, false, true, false, true, lr->ContainerSlot, lr->Slot, 3 );
						}
					}
					if(i && (*itr)->GetQuestLogForEntry(11341))
						(*itr)->GetQuestLogForEntry(11341)->SendQuestComplete();
					else if((*itr)->GetQuestLogForEntry(11337))
						(*itr)->GetQuestLogForEntry(11337)->SendQuestComplete();
				}
				else
				{
					Item *item = objmgr.CreateItem( 29024 , *itr );
					if( item != NULL )
					{
						item->SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
						item->SoulBind();
						if( !(*itr)->GetItemInterface()->AddItemToFreeSlot( item ) )
						{
							(*itr)->GetSession()->SendNotification("No free slots were found in your inventory!");
							item->DeleteMe();
						}
						else
						{
							SlotResult *lr = (*itr)->GetItemInterface()->LastSearchResult();
							(*itr)->GetSession()->SendItemPushResult( item, false, true, false, true, lr->ContainerSlot, lr->Slot, 1 );
						}
					}
				}
			}
		}
		m_mainLock.Release();
		SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] );
		UpdatePvPData();
		return true;
	}

	SetWorldState( EOTS_WORLDSTATE_ALLIANCE_VICTORYPOINTS + team, m_points[team] );
	return false;
}
示例#16
0
bool ChatHandler::HandleQuestFinishCommand(const char * args, WorldSession * m_session)
{
	if(!*args) return false;

	Player *plr = getSelectedChar(m_session, true);
	if(!plr)
	{
		plr = m_session->GetPlayer();
		SystemMessage(m_session, "Auto-targeting self.");
	}

	uint32 quest_id = atol(args);
	// reward_slot is for when quest has choice of rewards (0 is the first choice, 1 is the second choice, ...)
	// reward_slot will default to 0 if none is specified
	uint32 reward_slot;
	if(quest_id== 0)
	{
		quest_id = GetQuestIDFromLink(args);
		if(quest_id== 0)
			return false;
		if(strstr(args,"|r"))
		{
			reward_slot = atol(strstr(args,"|r")+2);
		}
		else
		{
			reward_slot = 0;
		}
	}
	else if(strchr(args,' '))
	{
		reward_slot = atol(strchr(args,' ')+1);
	}
	else
	{
		reward_slot = 0;
	}
	// currently Quest::reward_choiceitem declaration is
	// uint32 reward_choiceitem[6];
	// so reward_slot must be 0 to 5
	if(reward_slot > 5)
	{
		reward_slot = 0;
	}
	std::string recout = "|cff00ff00";

	Quest * qst = QuestStorage.LookupEntry(quest_id);
	if(qst)
	{
		if (plr->HasFinishedQuest(quest_id))
			recout += "Player has already completed that quest.\n\n";
		else
		{
			QuestLogEntry * IsPlrOnQuest = plr->GetQuestLogForEntry(quest_id);
			if (IsPlrOnQuest)
			{	
				uint32 giver_id = 0;
				std::string my_query = "";

				my_query = "SELECT id FROM creature_quest_starter WHERE quest = " + MyConvertIntToString(quest_id);
				QueryResult *creatureResult = WorldDatabase.Query(my_query.c_str());

				if(creatureResult)
				{
					Field *creatureFields = creatureResult->Fetch();
					giver_id = creatureFields[0].GetUInt32();
					delete creatureResult;
				}
				else
				{
					my_query = "SELECT id FROM gameobject_quest_starter WHERE quest = " + MyConvertIntToString(quest_id);
					QueryResult *objectResult = WorldDatabase.Query(my_query.c_str());
					if(objectResult)
					{
						Field *objectFields = objectResult->Fetch();
						giver_id = objectFields[0].GetUInt32();
						delete objectResult;
					}
				}

				if(giver_id == 0)
					SystemMessage(m_session, "Unable to find quest giver creature or object.");
				else
				{
					// I need some way to get the guid without targeting the creature or looking through all the spawns...
					Object *quest_giver = 0;

                    for(uint32 guid=1; guid < plr->GetMapMgr()->CreatureStorage.size(); guid++)
					{
						Creature *pCreature = plr->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid));
						if(pCreature)
						{
							if(pCreature->GetEntry() == giver_id) //found creature
							{
								quest_giver = (Object*)pCreature;
                                guid = plr->GetMapMgr()->CreatureStorage.size();
							}
						}
					}

					if(quest_giver)
					{
						GreenSystemMessage(m_session, "Found a quest_giver creature.");
						sQuestMgr.OnActivateQuestGiver(quest_giver, plr);
						sQuestMgr.GiveQuestRewardReputation(plr, qst, quest_giver);
					}
					else
						RedSystemMessage(m_session, "Unable to find quest_giver object.");
				}

				IsPlrOnQuest->Finish();
				recout += "Player was on that quest, but has now completed it.";
			}
			else
			{
				recout += "The quest has now been completed for that player.";
			}
			
			sGMLog.writefromsession( m_session, "completed quest %u [%s] for player %s", quest_id, qst->title, plr->GetName() );
			sQuestMgr.BuildQuestComplete(plr, qst);
			plr->AddToFinishedQuests(quest_id);

			// Quest Rewards : Copied from QuestMgr::OnQuestFinished()
			// Reputation reward
			for(int z = 0; z < 6; z++)
			{
				if( qst->reward_repfaction[z] )
				{
					int32 amt = 0;
					uint32 fact = qst->reward_repfaction[z];
					if( qst->reward_repvalue[z] )
					{
						amt = qst->reward_repvalue[z];
					}
					if( qst->reward_replimit && (plr->GetStanding(fact) >= (int32)qst->reward_replimit) )
					{
						continue;
					}
					amt = float2int32( float( amt ) * sWorld.getRate( RATE_QUESTREPUTATION ) );
					plr->ModStanding( fact, amt );
				}
			}
			// Static Item reward
			for(uint32 i = 0; i < 4; ++i)
			{
				if(qst->reward_item[i])
				{
					ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(qst->reward_item[i]);
					if(!proto)
					{
						sLog.outError("Invalid item prototype in quest reward! ID %d, quest %d", qst->reward_item[i], qst->id);
					}
					else
					{   
						Item *add;
						SlotResult slotresult;
						add = plr->GetItemInterface()->FindItemLessMax(qst->reward_item[i], qst->reward_itemcount[i], false);
						if (!add)
						{
							slotresult = plr->GetItemInterface()->FindFreeInventorySlot(proto);
							if(!slotresult.Result)
							{
								plr->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL);
							}
							else
							{
								Item *itm = objmgr.CreateItem(qst->reward_item[i], plr);
								if( itm )
								{
									itm->SetStackCount(  uint32(qst->reward_itemcount[i]));
									if( !plr->GetItemInterface()->SafeAddItem(itm,slotresult.ContainerSlot, slotresult.Slot) )
									{
										itm->DeleteMe();
									}
								}
							}
						}
						else
						{
							add->SetStackCount( add->GetStackCount() + qst->reward_itemcount[i]);
							add->m_isDirty = true;
						}
					}
				}
			}
			// Choice Rewards -- Defaulting to choice 0 for ".quest complete" command
			if(qst->reward_choiceitem[reward_slot])
			{
				ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(qst->reward_choiceitem[reward_slot]);
				if(!proto)
				{
					sLog.outError("Invalid item prototype in quest reward! ID %d, quest %d", qst->reward_choiceitem[reward_slot], qst->id);
				}
				else
				{
					Item *add;
					SlotResult slotresult;
					add = plr->GetItemInterface()->FindItemLessMax(qst->reward_choiceitem[reward_slot], qst->reward_choiceitemcount[reward_slot], false);
					if (!add)
					{
						slotresult = plr->GetItemInterface()->FindFreeInventorySlot(proto);
						if(!slotresult.Result)
						{
							plr->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL);
						}
						else
						{
							Item *itm = objmgr.CreateItem(qst->reward_choiceitem[reward_slot], plr);
							if( itm )
							{
								itm->SetStackCount(  uint32(qst->reward_choiceitemcount[reward_slot]));
								if( !plr->GetItemInterface()->SafeAddItem(itm,slotresult.ContainerSlot, slotresult.Slot) )
								{
									itm->DeleteMe();
								}
							}
						}
					}
					else
					{
						add->SetStackCount( add->GetStackCount() + qst->reward_choiceitemcount[reward_slot]);
						add->m_isDirty = true;
					}
				}
			}
			// if daily then append to finished dailies
			if ( qst->is_repeatable == arcemu_QUEST_REPEATABLE_DAILY )
				plr->PushToFinishedDailies( qst->id );
			// Remove quests that are listed to be removed on quest complete.
			set<uint32>::iterator iter = qst->remove_quest_list.begin();
			for(; iter != qst->remove_quest_list.end(); ++iter)
			{
				if( !plr->HasFinishedQuest( (*iter ) ))
					plr->AddToFinishedQuests( (*iter ) );
			}
#ifdef ENABLE_ACHIEVEMENTS
			plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST_COUNT, 1, 0, 0);
			if( qst->reward_money > 0 )
			{
				// Money reward
				// Check they don't have more than the max gold
				if( sWorld.GoldCapEnabled && (plr->GetGold() + qst->reward_money) <= sWorld.GoldLimit )
				{
					plr->ModGold( qst->reward_money );
				}
				plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_QUEST_REWARD_GOLD, qst->reward_money, 0, 0);
			}
			plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE, qst->zone_id, 0, 0);
			plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST, qst->id, 0, 0);
#endif
}
	}
	else
	{
		recout += "Quest Id [";
		recout += args;
		recout += "] was not found and unable to add it to the player's quest log.";
	}

	recout += "\n\n";

	SendMultilineMessage(m_session, recout.c_str());

	return true;
}
示例#17
0
void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data )
{
	DEBUG_LOG( "WORLD"," Received CMSG_QUESTGIVER_ACCEPT_QUEST" );
	CHECK_INWORLD_RETURN;

	//WorldPacket data;

	uint64 guid;
	uint32 quest_id;
	uint32 unk;

	recv_data >> guid;
	recv_data >> quest_id;
	recv_data >> unk;

	bool bValid = false;
	bool hasquest = true;
	bool bSkipLevelCheck = false;
	Quest *qst = NULL;
	Object* qst_giver = NULLOBJ;
	uint32 guidtype = GET_TYPE_FROM_GUID(guid);

	if(guidtype == HIGHGUID_TYPE_CREATURE)
	{
		Creature* quest_giver = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid));
		if(quest_giver)
			qst_giver = TO_OBJECT(quest_giver);
		else
			return;
		bValid = quest_giver->isQuestGiver();
		hasquest = quest_giver->HasQuest(quest_id, 1);
		if(bValid)
			qst = QuestStorage.LookupEntry(quest_id);
	}
	else if(guidtype==HIGHGUID_TYPE_GAMEOBJECT)
	{
		GameObject* quest_giver = _player->GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid));
		if(quest_giver)
			qst_giver = TO_OBJECT(quest_giver);
		else
			return;
		//bValid = quest_giver->isQuestGiver();
		//if(bValid)
		bValid = true;
			qst = QuestStorage.LookupEntry(quest_id);
	}
	else if(guidtype==HIGHGUID_TYPE_ITEM)
	{
		Item* quest_giver = GetPlayer()->GetItemInterface()->GetItemByGUID(guid);
		if(quest_giver)
			qst_giver = TO_OBJECT(quest_giver);
		else
			return;
		bValid = true;
		bSkipLevelCheck=true;
		qst = QuestStorage.LookupEntry(quest_id);
		if( qst && qst->id != quest_giver->GetProto()->QuestId )
			return;
	}
	else if(guidtype==HIGHGUID_TYPE_PLAYER)
	{
		Player* quest_giver = _player->GetMapMgr()->GetPlayer((uint32)guid);
		if(quest_giver)
			qst_giver = TO_OBJECT(quest_giver);
		else
			return;
		bValid = true;
		qst = QuestStorage.LookupEntry(quest_id);
	}

	if (!qst_giver)
	{
		OUT_DEBUG("WORLD: Invalid questgiver GUID.");
		return;
	}

	if( !bValid || qst == NULL )
	{
		OUT_DEBUG("WORLD: Creature is not a questgiver.");
		return;
	}

	if( _player->GetQuestLogForEntry( qst->id ) )
		return;

	if( qst_giver->GetTypeId() == TYPEID_UNIT && TO_CREATURE( qst_giver )->m_escorter != NULL )
	{
		SystemMessage("You cannot accept this quest at this time.");
		return;
	}

	// Check the player hasn't already taken this quest, or
	// it isn't available.
	uint32 status = sQuestMgr.CalcQuestStatus(_player,qst,3, bSkipLevelCheck);

	if((!sQuestMgr.IsQuestRepeatable(qst) && _player->HasFinishedQuest(qst->id)) || ( status != QMGR_QUEST_AVAILABLE && status != QMGR_QUEST_REPEATABLE && status != QMGR_QUEST_CHAT )
		|| !hasquest)
	{
		// We've got a hacker. Disconnect them.
		//sWorld.LogCheater(this, "tried to accept incompatible quest %u from %u.", qst->id, qst_giver->GetEntry());
		//Disconnect();
		return;
	}

	int32 log_slot = _player->GetOpenQuestSlot();

	if (log_slot == -1)
	{
		sQuestMgr.SendQuestLogFull(GetPlayer());
		return;
	}

	//FIXME
	/*if(Player Has Timed quest && qst->HasFlag(QUEST_FLAG_TIMED))
		sQuestMgr.SendQuestInvalid(INVALID_REASON_HAVE_TIMED_QUEST);*/

	if(qst->count_receiveitems || qst->srcitem)
	{
		uint32 slots_required = qst->count_receiveitems;

		if(_player->GetItemInterface()->CalculateFreeSlots(NULL) < slots_required)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM, INV_ERR_BAG_FULL);
			sQuestMgr.SendQuestFailed(FAILED_REASON_INV_FULL, qst, _player);
			return;
		}
	}

/*	if(qst_giver->GetTypeId() == TYPEID_UNIT && !ScriptSystem->OnQuestRequireEvent(qst, TO_CREATURE( qst_giver ), _player, QUEST_EVENT_CAN_ACCEPT))
		return;*/

	QuestLogEntry *qle = new QuestLogEntry();
	qle->Init(qst, _player, log_slot);
	qle->UpdatePlayerFields();

	// If the quest should give any items on begin, give them the items.
	for(uint32 i = 0; i < 4; i++)
	{
		if(qst->receive_items[i])
		{
			Item* item = objmgr.CreateItem( qst->receive_items[i], GetPlayer());
			if(item)
			{
				item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->receive_itemcount[i]);
				if(!_player->GetItemInterface()->AddItemToFreeSlot(item))
				{
					item->DeleteMe();
					item = NULLITEM;
				}
				else
					SendItemPushResult(item, false, true, false, true,
					_player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(),
					1);
			}
		}
	}

	if(qst->srcitem && qst->srcitem != qst->receive_items[0])
	{
		Item* item = objmgr.CreateItem( qst->srcitem, _player );
		if(item)
		{
			item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->srcitemcount ? qst->srcitemcount : 1);
			if(!_player->GetItemInterface()->AddItemToFreeSlot(item))
			{
				item->DeleteMe();
				item = NULLITEM;
			}
		}
	}

	if(qst->count_required_item || qst_giver->GetTypeId() == TYPEID_GAMEOBJECT)	// gameobject quests deactivate
		_player->UpdateNearbyGameObjects();

	CALL_QUESTSCRIPT_EVENT(qst->id, OnQuestStart)(_player, qle);

	sQuestMgr.OnQuestAccepted(_player,qst,qst_giver);

	if(qst->start_phase != 0 )
		_player->SetPhaseMask(qst->start_phase, true);

	sHookInterface.OnQuestAccept(_player, qst, qst_giver);
}
示例#18
0
void WorldSession::HandleAcceptTrade(WorldPacket & recv_data) 
{
#ifdef FORCED_GM_TRAINEE_MODE
	if( CanUseCommand('k') && !HasGMPermissions() )
	{
		GetPlayer()->BroadcastMessage( "You are not allowed to use this feature" );
		return;
	}
#endif
	if( sWorld.getIntRate( INTRATE_DISABLE_TRADE_FEATURE ) )
	{
		GetPlayer()->BroadcastMessage( "Trade feature is disabled right now" );
		return;
	}
	Player * plr = _player->GetTradeTarget();
	if(_player->mTradeTarget == 0 || !plr)
	{ 
		return;
	}

	packetSMSG_TRADE_STATUS data;
	memset( &data, 0, sizeof( data ) );
	data.trade_status = TRADE_STATUS_ACCEPTED;
	OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);
	plr->m_session->OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);
	
	_player->mTradeStatus = TRADE_STATUS_ACCEPTED;	//when both have this status we can close the deal

	bool bag_hack_detected = false;
	if(plr->mTradeStatus == TRADE_STATUS_ACCEPTED)
	{
		// Ready!
		uint32 ItemCount = 0;
		uint32 TargetItemCount = 0;
		Player * pTarget = plr;

/*		// Calculate Item Count
		for(uint32 Index = 0; Index < 7; ++Index)
		{
			if(_player->mTradeItems[Index] != 0)	++ItemCount;
			if(pTarget->mTradeItems[Index] != 0)	++TargetItemCount;
		}*/
		

		// Calculate Count
		for(uint32 Index = 0; Index < TRADE_MAX_TRADABLE_ITEMS; ++Index) // cebernic: checking for MAX_TRADE_TRADABLE_ITEMS items ,untradable item check via others func.
		{
			Item * pItem;

			// safely trade checking
			pItem = _player->mTradeItems[Index];
			if( pItem )
			{
				if( ( pItem->IsContainer() && SafeContainerCast(pItem)->HasItems() )   || ( pItem->GetProto() && pItem->GetProto()->Bonding==ITEM_BIND_ON_PICKUP) )
				{
					ItemCount = 0;
					TargetItemCount = 0;
					bag_hack_detected = true;
					break;
				}
				else ++ItemCount;
			}					
			
			pItem = pTarget->mTradeItems[Index];
			if( pItem )
			{
				if( ( pItem->IsContainer() && SafeContainerCast(pItem)->HasItems() )   || ( pItem->GetProto() && pItem->GetProto()->Bonding==ITEM_BIND_ON_PICKUP) )
				{
					ItemCount = 0;
					TargetItemCount = 0;
					bag_hack_detected = true;
					break;
				}
				else 
					++TargetItemCount;
			}					

			//if(_player->mTradeItems[Index] != 0)	++ItemCount;
			//if(pTarget->mTradeItems[Index] != 0)	++TargetItemCount;
		}

		

		if( (_player->m_ItemInterface->CalculateFreeSlots(NULL) + ItemCount) < TargetItemCount ||
			(pTarget->m_ItemInterface->CalculateFreeSlots(NULL) + TargetItemCount) < ItemCount ||
			bag_hack_detected == true ||
			(ItemCount==0 && TargetItemCount==0 && !pTarget->mTradeGold && !_player->mTradeGold) )	// ceberwow added it
		{
			// Not enough slots on one end.
			data.trade_status = TRADE_STATUS_CANCELLED;
		}
		else
		{
			data.trade_status = TRADE_STATUS_COMPLETE;
			uint64 Guid;
			Item * pItem;
			
			// Remove all items from the players inventory
			for(uint32 Index = 0; Index < TRADE_MAX_TRADABLE_ITEMS; ++Index)
			{
				Guid = _player->mTradeItems[Index] ? _player->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( _player->mTradeItems[Index]->GetProto()->Bonding == ITEM_BIND_ON_PICKUP ||
						_player->mTradeItems[Index]->GetProto()->Bonding  >=  ITEM_BIND_QUEST  )
					{
						_player->mTradeItems[Index] = NULL;
					}
					else
					{
						if(GetPermissionCount()>0)
							sGMLog.writefromsession(this, "traded item %s to %s", _player->mTradeItems[Index]->GetProto()->Name1, pTarget->GetName());
						pItem = _player->m_ItemInterface->SafeRemoveAndRetreiveItemByGuid(Guid, true);
					}
				}

				Guid = pTarget->mTradeItems[Index] ? pTarget->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( pTarget->mTradeItems[Index]->GetProto()->Bonding == ITEM_BIND_ON_PICKUP ||  
						pTarget->mTradeItems[Index]->GetProto()->Bonding  >=  ITEM_BIND_QUEST )
					{
						pTarget->mTradeItems[Index] = NULL;
					}
					else
					{
						if(pTarget->GetSession() && pTarget->GetSession()->GetPermissionCount()>0)
							sGMLog.writefromsession(pTarget->GetSession(), "traded item %s to %s", pTarget->mTradeItems[Index]->GetProto()->Name1, _player->GetName());
						pTarget->m_ItemInterface->SafeRemoveAndRetreiveItemByGuid(Guid, true);
					}
				}
			}

			// Dump all items back into the opposite players inventory
			for(uint32 Index = 0; Index < TRADE_MAX_TRADABLE_ITEMS; ++Index)
			{
				pItem = _player->mTradeItems[Index];
				if(pItem != 0 && pTarget)
				{
					pItem->SetOwner(pTarget); // crash fixed.
					if( !pTarget->m_ItemInterface->AddItemToFreeSlot(&pItem) )
					{
						pItem->DeleteMe();
						pItem = NULL;
						_player->mTradeItems[Index] = NULL;
						continue;
					}
				}

				pItem = pTarget->mTradeItems[Index];
				if(pItem != 0 && _player)
				{
					pItem->SetOwner(_player);
					if( !_player->m_ItemInterface->AddItemToFreeSlot(&pItem) )
					{
						pItem->DeleteMe();
						pItem = NULL;
						pTarget->mTradeItems[Index] = NULL;
						continue;
					}
				}
			}

			// Trade Gold
			if(pTarget->mTradeGold && pTarget->GetGold() >= pTarget->mTradeGold )
			{
				_player->ModGold(pTarget->mTradeGold);
				pTarget->ModGold(-(int64)pTarget->mTradeGold);
				if(GetPermissionCount()>0)
					sGMLog.writefromsession(this, "traded(gave) %u gold to %s", pTarget->mTradeGold, pTarget->GetName());
			}

			if(_player->mTradeGold && _player->GetGold() >= _player->mTradeGold)
			{
				pTarget->ModGold( _player->mTradeGold);
				_player->ModGold( -(int64)_player->mTradeGold);
				if(pTarget->GetSession() && pTarget->GetSession()->GetPermissionCount()>0)
					sGMLog.writefromsession(pTarget->GetSession(), "traded(gave) %u gold to %s", _player->mTradeGold, _player->GetName());
			}

			// Close Window
			data.trade_status = TRADE_STATUS_COMPLETE;
			
		}

		OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);
		plr->m_session->OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data);

		_player->mTradeStatus = TRADE_STATUS_COMPLETE;
		plr->mTradeStatus = TRADE_STATUS_COMPLETE;

		// Reset Trade Vars
		_player->ResetTradeVariables();		
		plr->ResetTradeVariables();

		//removed by zack. Hehe, just a way to spam db with saves. Not funny
		// added alternative way as item saves before 
		// Save for eachother
		//plr->SaveToDB(false);
		//_player->SaveToDB(false);
	}
}
示例#19
0
void WorldSession::HandleSendMail(WorldPacket & recv_data)
{
	CHECK_INWORLD_RETURN

	MailMessage msg;
	uint64 gameobject;
	uint32 unk2;
	uint8 itemcount;
	uint8 itemslot;
	uint8 i;
	uint64 itemguid;
	vector< Item* > items;
	vector< Item* >::iterator itr;
	string recepient;
	Item* pItem;
	//uint32 err = MAIL_OK;

	recv_data >> gameobject >> recepient;
	recv_data >> msg.subject >> msg.body >> msg.stationery;
	recv_data >> unk2 >> itemcount;

	if(itemcount > MAIL_MAX_ITEM_SLOT || msg.body.find("%") != string::npos || msg.subject.find("%") != string::npos)
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	// Search for the recipient
	PlayerInfo* player = ObjectMgr::getSingleton().GetPlayerInfoByName(recepient.c_str());
	if(player == NULL)
	{
		SendMailError(MAIL_ERR_RECIPIENT_NOT_FOUND);
		return;
	}

	for(i = 0; i < itemcount; ++i)
	{
		recv_data >> itemslot;
		recv_data >> itemguid;

		pItem = _player->GetItemInterface()->GetItemByGUID(itemguid);
		if(pItem == NULL || pItem->IsSoulbound() || pItem->IsConjured())
		{
			SendMailError(MAIL_ERR_INTERNAL_ERROR);
			return;
		}
		if(pItem->IsAccountbound() && GetAccountId() !=  player->acct) // don't mail account-bound items to another account
		{
			WorldPacket data(SMSG_SEND_MAIL_RESULT, 16);
			data << uint32(0);
			data << uint32(0);
			data << uint32(MAIL_ERR_BAG_FULL);
			data << uint32(INV_ERR_ARTEFACTS_ONLY_FOR_OWN_CHARACTERS);
			SendPacket(&data);
			return;
		}

		items.push_back(pItem);
	}

	recv_data >> msg.money;
	recv_data >> msg.cod;
	// left over: (TODO- FIX ME BURLEX!)
	// uint32
	// uint32
	// uint8

	bool interfaction = false;
	if(sMailSystem.MailOption(MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION) || (HasGMPermissions() && sMailSystem.MailOption(MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION_GM)))
	{
		interfaction = true;
	}

	// Check we're sending to the same faction (disable this for testing)
	if(player->team != _player->GetTeam() && !interfaction)
	{
		SendMailError(MAIL_ERR_NOT_YOUR_ALLIANCE);
		return;
	}

	// Check if we're sending mail to ourselves
	if(strcmp(player->name, _player->GetName()) == 0 && !GetPermissionCount())
	{
		SendMailError(MAIL_ERR_CANNOT_SEND_TO_SELF);
		return;
	}

	if(msg.stationery == MAIL_STATIONERY_GM && !HasGMPermissions())
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	// Instant delivery time by default.
	msg.delivery_time = (uint32)UNIXTIME;

	// Set up the cost
	int32 cost = 0;

	// Check for attached money
	if(msg.money > 0)
		cost += msg.money;

	if(cost < 0)
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	if(!sMailSystem.MailOption(MAIL_FLAG_DISABLE_POSTAGE_COSTS) && !(GetPermissionCount() && sMailSystem.MailOption(MAIL_FLAG_NO_COST_FOR_GM)))
	{
		cost += 30;
		if(cost < 30)  //Overflow prevention for those silly WPE hoez.
		{
			SendMailError(MAIL_ERR_INTERNAL_ERROR);
			return;
		}
	}

	// check that we have enough in our backpack
	if(!_player->HasGold(cost))
	{
		SendMailError(MAIL_ERR_NOT_ENOUGH_MONEY);
		return;
	}

	// Check for the item, and required item.
	if(!items.empty())
	{
		for(itr = items.begin(); itr != items.end(); ++itr)
		{
			pItem = *itr;
			if(_player->GetItemInterface()->SafeRemoveAndRetreiveItemByGuid(pItem->GetGUID(), false) != pItem)
				continue;		// should never be hit.

			pItem->RemoveFromWorld();
			pItem->SetOwner(NULL);
			pItem->SaveToDB(INVENTORY_SLOT_NOT_SET, 0, true, NULL);
			msg.items.push_back(pItem->GetLowGUID());

			if(GetPermissionCount() > 0)
			{
				/* log the message */
				sGMLog.writefromsession(this, "sent mail with item entry %u to %s, with gold %u.", pItem->GetEntry(), player->name, msg.money);
			}

			pItem->DeleteMe();
		}
	}

	if(msg.money != 0 || msg.cod != 0 || (!msg.items.size() && player->acct != _player->GetSession()->GetAccountId()))
	{
		if(!sMailSystem.MailOption(MAIL_FLAG_DISABLE_HOUR_DELAY_FOR_ITEMS))
			msg.delivery_time += 3600;  // 1hr
	}

	// take the money
	_player->ModGold(-cost);

	// Fill in the rest of the info
	msg.player_guid = player->guid;
	msg.sender_guid = _player->GetGUID();

	// 30 day expiry time for unread mail
	if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
		msg.expire_time = (uint32)UNIXTIME + (TIME_DAY * MAIL_DEFAULT_EXPIRATION_TIME);
	else
		msg.expire_time = 0;

	msg.deleted_flag = false;
	msg.message_type = 0;
	msg.checked_flag = msg.body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY;

	// Great, all our info is filled in. Now we can add it to the other players mailbox.
	sMailSystem.DeliverMessage(player->guid, &msg);
	// Save/Update character's gold if they've received gold that is. This prevents a rollback.
	CharacterDatabase.Execute("UPDATE characters SET gold = %u WHERE guid = %u", _player->GetGold(), _player->m_playerInfo->guid);
	// Success packet :)
	SendMailError(MAIL_OK);
}
示例#20
0
void WorldSession::HandleSendMail(WorldPacket & recv_data )
{
	MailMessage msg;
	uint64 gameobject;
	uint32 unk2;
	uint8 itemcount;
	uint8 itemslot;
	uint8 i;
	uint64 itemguid;
	vector< Item* > items;
	vector< Item* >::iterator itr;
	string recepient;
	Item * pItem;
	//uint32 err = MAIL_OK;

	recv_data >> gameobject >> recepient;
	recv_data >> msg.subject >> msg.body >> msg.stationary;
	recv_data >> unk2 >> itemcount;

	//he simply ads ' ' after each '%' to string so that vsnprintf function would not find tokens in string
	char *t=(char*)msg.subject.c_str();
	if( t[0] != 0 ) //if not an empty string
	{
		int ind=1;
		//make sure we do not have any recognizable tokens here
		while(t[ind]!=0 && ind<5000)
		{
			if(t[ind-1]=='%')
				t[ind]=' ';//just remove chars that could be interpreted
			ind++;
		}
	}
	msg.subject = t;
	t=(char*)msg.body.c_str();
	if( t[0] != 0 ) //if not an empty string
	{
		int ind=1;
		while(t[ind]!=0 && ind<5000)
		{
			if(t[ind-1]=='%')
				t[ind]=' ';//just remove chars that could be interpreted
			ind++;
		}
	}
	msg.body = t;


	if( itemcount > 12 )
	{
		//SystemMessage("Sorry, Ascent does not support sending multiple items at this time. (don't want to lose your item do you) Remove some items, and try again.");
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	for( i = 0; i < itemcount; ++i )
	{
		recv_data >> itemslot;
		recv_data >> itemguid;

        pItem = _player->GetItemInterface()->GetItemByGUID( itemguid );
		if( pItem == NULL || pItem->IsSoulbound() || pItem->HasFlag( ITEM_FIELD_FLAGS, ITEM_FLAG_CONJURED ) )
		{
			SendMailError( MAIL_ERR_INTERNAL_ERROR );
			return;
		}

		items.push_back( pItem );
	}
	
	recv_data >> msg.money;
	recv_data >> msg.cod;
	// left over: (TODO- FIX ME BURLEX!)
	// uint32
	// uint32
	// uint8
	
	// Search for the recipient
	PlayerInfo* player = ObjectMgr::getSingleton().GetPlayerInfoByName(recepient.c_str());
	if( player == NULL )
	{
		SendMailError( MAIL_ERR_RECIPIENT_NOT_FOUND );
		return;
	}

	bool interfaction = false;
	if( sMailSystem.MailOption( MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION ) || (HasGMPermissions() && sMailSystem.MailOption( MAIL_FLAG_CAN_SEND_TO_OPPOSITE_FACTION_GM ) ) )
	{
		interfaction = true;
	}

	// Check we're sending to the same faction (disable this for testing)
	if( player->team != _player->GetTeam() && !interfaction )
	{
		SendMailError( MAIL_ERR_NOT_YOUR_ALLIANCE );
		return;
	}

	// Check if we're sending mail to ourselves
	if( strcmp(player->name, _player->GetName()) == 0 && !GetPermissionCount())
	{
		SendMailError(MAIL_ERR_CANNOT_SEND_TO_SELF);
		return;
	}

	if( msg.stationary == 0x3d || msg.stationary == 0x3d && !HasGMPermissions())
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	// Instant delivery time by default.
	msg.delivery_time = (uint32)UNIXTIME;

	// Set up the cost
	int32 cost = 0;
	if( !sMailSystem.MailOption( MAIL_FLAG_DISABLE_POSTAGE_COSTS ) && !( GetPermissionCount() && sMailSystem.MailOption( MAIL_FLAG_NO_COST_FOR_GM ) ) )
	{
		cost = 30;
	}

	// Check for attached money
	if( msg.money > 0 )
		cost += msg.money;

	if( cost < 0 )
	{
		SendMailError(MAIL_ERR_INTERNAL_ERROR);
		return;
	}

	// check that we have enough in our backpack
	if( (int32)_player->GetUInt32Value( PLAYER_FIELD_COINAGE ) < cost )
	{
		SendMailError( MAIL_ERR_NOT_ENOUGH_MONEY );
		return;
	}

	// Check for the item, and required item.
	if( !items.empty( ) )
	{
		for( itr = items.begin(); itr != items.end(); ++itr )
		{
			pItem = *itr;
			if( _player->GetItemInterface()->SafeRemoveAndRetreiveItemByGuid(pItem->GetGUID(), false) != pItem )
				continue;		// should never be hit.

			pItem->RemoveFromWorld();
			pItem->SetOwner( NULL );
			pItem->SaveToDB( INVENTORY_SLOT_NOT_SET, 0, true, NULL );
			msg.items.push_back( pItem->GetUInt32Value(OBJECT_FIELD_GUID) );

			if( GetPermissionCount() > 0 )
			{
				/* log the message */
				sGMLog.writefromsession(this, "sent mail with item entry %u to %s, with gold %u.", pItem->GetEntry(), player->name, msg.money);
			}

			pItem->DeleteMe();
		}
	}

	if(msg.money != 0 || msg.cod != 0 || !msg.items.size() && player->acct != _player->GetSession()->GetAccountId())
	{
		if(!sMailSystem.MailOption(MAIL_FLAG_DISABLE_HOUR_DELAY_FOR_ITEMS))
			msg.delivery_time += 3600;  // 1hr
	}

	// take the money
	_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -cost);

	// Fill in the rest of the info
	msg.player_guid = player->guid;
	msg.sender_guid = _player->GetGUID();
	
	// 30 day expiry time for unread mail mail
	if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
		msg.expire_time = (uint32)UNIXTIME + (TIME_DAY * MAIL_DEFAULT_EXPIRATION_TIME);
	else
		msg.expire_time = 0;

	msg.copy_made = false;
	msg.read_flag = false;
	msg.deleted_flag = false;
	msg.message_type = 0;

	// Great, all our info is filled in. Now we can add it to the other players mailbox.
	sMailSystem.DeliverMessage(player->guid, &msg);

	// Success packet :)
	SendMailError(MAIL_OK);
}
示例#21
0
void WorldSession::HandleTakeItem(WorldPacket & recv_data)
{
	CHECK_INWORLD_RETURN

	uint64 mailbox;
	uint32 message_id;
	uint32 lowguid;
	vector< uint32 >::iterator itr;

	recv_data >> mailbox >> message_id >> lowguid;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_ITEM_TAKEN);

	MailMessage* message = _player->m_mailBox.GetMessage(message_id);
	if(message == 0 || message->items.empty())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	for(itr = message->items.begin(); itr != message->items.end(); ++itr)
	{
		if((*itr) == lowguid)
			break;
	}

	if(itr == message->items.end())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// check for cod credit
	if(message->cod > 0)
	{
		if(!_player->HasGold(message->cod))
		{
			data << uint32(MAIL_ERR_NOT_ENOUGH_MONEY);
			SendPacket(&data);
			return;
		}
	}

	// grab the item
	Item* item = objmgr.LoadItem(*itr);
	if(item == 0)
	{
		// doesn't exist
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	//Find free slot
	SlotResult result = _player->GetItemInterface()->FindFreeInventorySlot(item->GetProto());
	if(result.Result == 0)
	{
		//End of slots
		data << uint32(MAIL_ERR_BAG_FULL);
		SendPacket(&data);

		item->DeleteMe();
		return;
	}
	item->m_isDirty = true;

	if(!_player->GetItemInterface()->SafeAddItem(item, result.ContainerSlot, result.Slot))
	{
		if(!_player->GetItemInterface()->AddItemToFreeSlot(item))
		{
			//End of slots
			data << uint32(MAIL_ERR_BAG_FULL);
			SendPacket(&data);
			item->DeleteMe();
			return;
		}
	}
	else
		item->SaveToDB(result.ContainerSlot, result.Slot, true, NULL);

	// send complete packet
	data << uint32(MAIL_OK);
	data << item->GetLowGUID();
	data << item->GetStackCount();

	message->items.erase(itr);

	// re-save (update the items field)
	sMailSystem.SaveMessageToSQL(message);
	SendPacket(&data);

	if(message->cod > 0)
	{
		_player->ModGold(-(int32)message->cod);
		string subject = "COD Payment: ";
		subject += message->subject;
		sMailSystem.SendAutomatedMessage(NORMAL, message->player_guid, message->sender_guid, subject, "", message->cod, 0, 0, MAIL_STATIONERY_TEST1, MAIL_CHECK_MASK_COD_PAYMENT);

		message->cod = 0;
		CharacterDatabase.Execute("UPDATE mailbox SET cod = 0 WHERE message_id = %u", message->message_id);
	}

	// probably need to send an item push here
}
示例#22
0
void WorldSession::HandleGuildBankSwapItem(WorldPacket & recv_data)
{
	uint64 guid;
	uint8 source_isfrombank;
	uint32 itementry, unk1;
	uint8 autostore;
	uint32 i;

	Guild * pGuild = _player->m_playerInfo->guild;
	GuildMember * pMember = _player->m_playerInfo->guildMember;

	if(pGuild== NULL || pMember== NULL)
		return;

	recv_data >> guid >> source_isfrombank;
	if(source_isfrombank)
	{
		GuildBankTab * pSourceTab;
		GuildBankTab * pDestTab;
		Item* pSourceItem;
		Item* pDestItem;
		uint8 dest_bank;
		uint8 dest_bankslot;
		uint8 source_bank;
		uint8 source_bankslot;
		int32 splitted_count;

		/* read packet */
		recv_data >> dest_bank;
		recv_data >> dest_bankslot;
		recv_data >> unk1;
		recv_data >> source_bank;
		recv_data >> source_bankslot;

		recv_data >> itementry;
		recv_data >> autostore;
		recv_data >> splitted_count;

		/* sanity checks to avoid overflows */
		if(source_bankslot >= MAX_GUILD_BANK_SLOTS ||
			dest_bankslot >= MAX_GUILD_BANK_SLOTS ||
			source_bank >= MAX_GUILD_BANK_TABS ||
			dest_bank >= MAX_GUILD_BANK_TABS)
		{
			return;
		}

		/* make sure we have permissions */
		if(!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, dest_bank) ||
			!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, source_bank))
			return;

		/* locate the tabs */
		pSourceTab = pGuild->GetBankTab( source_bank );
		pDestTab = pGuild->GetBankTab( dest_bank );

		if(pSourceTab == NULL || pDestTab == NULL)
			return;

		if(pSourceTab == pDestTab && source_bankslot == dest_bankslot)
			return;

		pSourceItem = pSourceTab->pSlots[source_bankslot];
		pDestItem = pDestTab->pSlots[dest_bankslot];

		if(pSourceItem == NULL && pDestItem == NULL)
			return;

		if(splitted_count)
		{
			uint32 source_count = pSourceItem->GetUInt32Value( ITEM_FIELD_STACK_COUNT );

			if(pDestItem == NULL)
			{
				if(source_count == (uint32)splitted_count)
				{
					// swap
					pSourceTab->pSlots[source_bankslot] = pDestItem;
					pDestTab->pSlots[dest_bankslot] = pSourceItem;
				}
				else
				{
					pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count );

					pDestItem = objmgr.CreateItem(pSourceItem->GetEntry(), NULL);
					pDestItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT, splitted_count);
					pDestItem->SetUInt32Value(ITEM_FIELD_CREATOR, pSourceItem->GetUInt32Value(ITEM_FIELD_CREATOR));

					pDestTab->pSlots[dest_bankslot] = pDestItem;
				}
			}
			else
			{
				pDestItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, splitted_count );

				if((uint32)splitted_count != source_count)
					pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count );
				else
				{
					pSourceItem->DeleteMe();
					pSourceItem = NULLITEM;
					pSourceTab->pSlots[source_bankslot] = NULLITEM;
				}
			}
		}
		else
		{
			// swap
			pSourceTab->pSlots[source_bankslot] = pDestItem;
			pDestTab->pSlots[dest_bankslot] = pSourceItem;
		}

		/* update the client */
		if(pSourceTab == pDestTab)
		{
			/* send both slots in the packet */
			pGuild->SendGuildBank(this, pSourceTab, source_bankslot, dest_bankslot);
		}
		else
		{
			/* send a packet for each different bag */
			pGuild->SendGuildBank(this, pSourceTab, source_bankslot, -1);
			pGuild->SendGuildBank(this, pDestTab, dest_bankslot, -1);
		}

		/* update in sql */
		if(pDestItem == NULL)
		{
			/* this means the source slot is no longer being used. */
			CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u",
				pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot);
		}
		else
		{
			/* insert the new Item* */
			CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)",
				pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot, pDestItem->GetLowGUID());
		}

		if(pSourceItem == NULL)
		{
			/* this means the destination slot is no longer being used. */
			CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u",
				pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot);
		}
		else
		{
			/* insert the new Item* */
			CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)",
				pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot, pSourceItem->GetLowGUID());
		}
	}
	else
	{
示例#23
0
void LootRoll::Finalize()
{
	sEventMgr.RemoveEvents(this);

	// this we will have to finalize with groups types.. for now
	// we'll just assume need before greed. person with highest roll
	// in need gets the item.

	uint32 highest = 0;
	int8 hightype = -1;
	uint64 player = 0;

	WorldPacket data(34);

/*
	Player * gplr = NULL;
	for(std::map<uint64, uint32>::iterator itr = NeedRolls.begin(); itr != NeedRolls.end(); ++itr)
	{
		gplr = _mgr->GetPlayer((uint32)itr->first);
		if(gplr) break;
	}
	
	if(!gplr)
	{
		for(std::map<uint64, uint32>::iterator itr = GreedRolls.begin(); itr != GreedRolls.end(); ++itr)
		{
			gplr = _mgr->GetPlayer((uint32)itr->first);
			if(gplr) break;
		}
	}
*/
	for(std::map<uint32, uint32>::iterator itr = m_NeedRolls.begin(); itr != m_NeedRolls.end(); ++itr)
	{
		if(itr->second > highest)
		{
			highest = itr->second;
			player = itr->first;
			hightype = LOOT_ROLL_TYPE_NEED;
		}
		/*
		data.Initialize(SMSG_LOOT_ROLL);
		data << _guid << _slotid << itr->first;
		data << _itemid << random_suffix_factor << random_suffix_id;
		data << uint8(itr->second) << uint8(LOOT_ROLL_TYPE_NEED);
		if(gplr && gplr->GetGroup())
			gplr->GetGroup()->SendPacketToAll(&data);
		*/
	}

	if(!highest)
	{
		for(std::map<uint32, uint32>::iterator itr = m_GreedRolls.begin(); itr != m_GreedRolls.end(); ++itr)
		{
			if(itr->second > highest)
			{
				highest = itr->second;
				player = itr->first;
				hightype = LOOT_ROLL_TYPE_GREED;
			}
		/*
		data.Initialize(SMSG_LOOT_ROLL);
		data << _guid << _slotid << itr->first;
		data << _itemid << random_suffix_factor << random_suffix_id;
		data << uint8(itr->second) << uint8(LOOT_ROLL_TYPE_GREED);
		if(gplr && gplr->GetGroup())
			gplr->GetGroup()->SendPacketToAll(&data);
		*/
		}
	}

	Loot * pLoot = 0;
	uint32 guidtype = GET_TYPE_FROM_GUID(_guid);
	if( guidtype == HIGHGUID_TYPE_UNIT )
	{
		Creature * pc = _mgr->GetCreature( _guid );
		if(pc) pLoot = &pc->loot;
	}
	else if( guidtype == HIGHGUID_TYPE_GAMEOBJECT )
	{
		GameObject * go = _mgr->GetGameObject( _guid );
		if(go) pLoot = &go->loot;
	}

	if(!pLoot)
	{
		delete this;
		return;
	}

	if(_slotid >= pLoot->items.size())
	{
		delete this;
		return;
	}

	pLoot->items.at(_slotid).roll = NULL;

	uint32 itemid = pLoot->items.at(_slotid).item.itemproto->ItemId;
	uint32 amt = pLoot->items.at(_slotid).iItemsCount;
	if(!amt)
	{
		delete this;
		return;
	}

	Player * _player = (player) ? _mgr->GetPlayer( player ) : 0;
	if(!player || !_player)
	{
		/* all passed */
		data.Initialize(SMSG_LOOT_ALL_PASSED);
		data << _guid << _groupcount << _itemid << random_suffix_factor << random_suffix_id;
		set<uint32>::iterator pitr = m_passRolls.begin();
		while(_player == NULL && pitr != m_passRolls.end())
			_player = _mgr->GetPlayer( (*(pitr++)) );

		if( _player != NULL )
		{
			if(_player->InGroup())
				_player->GetGroup()->SendPacketToAll(&data);
			else
				_player->GetSession()->SendPacket(&data);
		}

		/* item can now be looted by anyone :) */
		pLoot->items.at(_slotid).passed = true;
		delete this;
		return;
	}

	/*
	0C BA 0E D0 0E 00 30 F1 - guid
	00 00 00 00 slot
	7A 16 00 00 itemid
	00 26 81 8E randomfactor
	00 00 00 00 randomid
	07 34 42 02 00 00 00 07 -guid
	0C roll
	01 roll type
	*/
    pLoot->items.at(_slotid).roll = NULL;
	data.Initialize(SMSG_LOOT_ROLL_WON);
	data << _guid << _slotid << _itemid << random_suffix_factor << random_suffix_id;
	data << _player->GetGUID() << uint8(highest) << uint8(hightype);
	if(_player->InGroup())
		_player->GetGroup()->SendPacketToAll(&data);
	else
		_player->GetSession()->SendPacket(&data);

	ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid);

	int8 error;
	if((error = _player->GetItemInterface()->CanReceiveItem(it, 1)) != 0)
	{
		_player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, error);
		return;
	}

	Item * add = _player->GetItemInterface()->FindItemLessMax(itemid, amt, false);

	if (!add)
	{
		SlotResult slotresult = _player->GetItemInterface()->FindFreeInventorySlot(it);
		if(!slotresult.Result)
		{
			_player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL);
			return;
		}

		sLog.outDebug("AutoLootItem MISC");
		Item *item = objmgr.CreateItem( itemid, _player);

		item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,amt);
		if(pLoot->items.at(_slotid).iRandomProperty!=NULL)
		{
			item->SetRandomProperty(pLoot->items.at(_slotid).iRandomProperty->ID);
			item->ApplyRandomProperties(false);
		}
		else if(pLoot->items.at(_slotid).iRandomSuffix != NULL)
		{
			item->SetRandomSuffix(pLoot->items.at(_slotid).iRandomSuffix->id);
			item->ApplyRandomProperties(false);
		}
		RandomizeEPLItem( item );


		AddItemResult res = _player->GetItemInterface()->SafeAddItem(item,slotresult.ContainerSlot, slotresult.Slot);
		if( res == ADD_ITEM_RESULT_OK )
		{
			_player->GetSession()->SendItemPushResult(item,false,true,true,true,slotresult.ContainerSlot,slotresult.Slot,1);
			sQuestMgr.OnPlayerItemPickup(_player,item);
		}
		else if( res == ADD_ITEM_RESULT_ERROR )
		{
			item->DeleteMe();
			item = NULL;
		}
	}
	else 
	{	
		add->SetCount(add->GetUInt32Value(ITEM_FIELD_STACK_COUNT) + amt);
		add->m_isDirty = true;
		sQuestMgr.OnPlayerItemPickup(_player,add);
		_player->GetSession()->SendItemPushResult(add, false, true, true, false, _player->GetItemInterface()->GetBagSlotByGuid(add->GetGUID()), 0xFFFFFFFF, 1);
	}

	pLoot->items.at(_slotid).iItemsCount=0;
	// this gets sent to all looters
	data.Initialize(SMSG_LOOT_REMOVED);
	data << uint8(_slotid);
	Player * plr;
	for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); ++itr)
	{
		if((plr = _player->GetMapMgr()->GetPlayer(*itr)) != 0)
			plr->GetSession()->SendPacket(&data);
	}

	/*WorldPacket idata(45);
	_player->GetSession()->BuildItemPushResult(&idata, _player->GetGUID(), ITEM_PUSH_TYPE_LOOT, amt, itemid, pLoot->items.at(_slotid).iRandomProperty ? pLoot->items.at(_slotid).iRandomProperty->ID : 0);

	if(_player->InGroup())
		_player->GetGroup()->SendPacketToAll(&idata);
	else
		_player->GetSession()->SendPacket(&idata);*/

	delete this;
}
示例#24
0
void WinterReveler(Player* pPlayer, Unit* pUnit)
{
    if (pUnit->GetEntry() == 15760)
    {
        uint32 Winteritem = 0;
        SlotResult slotresult;

        uint32 chance = RandomUInt(2);
        switch (chance)
        {
            case 0:
            {
                ItemPrototype const* proto = sMySQLStore.GetItemProto(21212);
                if (!proto)
                    return;

                slotresult = pPlayer->GetItemInterface()->FindFreeInventorySlot(proto);
                Winteritem = 21212;
            }
            break;
            case 1:
            {
                ItemPrototype const* proto = sMySQLStore.GetItemProto(21519);
                if (!proto)
                    return;

                slotresult = pPlayer->GetItemInterface()->FindFreeInventorySlot(proto);
                Winteritem = 21519;
            }
            break;
            case 2:
            {
                ItemPrototype const* proto = sMySQLStore.GetItemProto(34191);
                if (!proto)
                    return;

                slotresult = pPlayer->GetItemInterface()->FindFreeInventorySlot(proto);
                Winteritem = 34191;
            }
            break;

        }

        if (!slotresult.Result)
        {
            pPlayer->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL);
            return;
        }
        else
        {
            Item* item = objmgr.CreateItem(Winteritem, pPlayer);
            if (item == nullptr)
                return;

            item->SetStackCount(5);
            auto item_add_result = pPlayer->GetItemInterface()->SafeAddItem(item, slotresult.ContainerSlot, slotresult.Slot);
            if (!item_add_result)
            {
                Log.Error("Event_WinterVeil", "Error while adding item %u to player %s", item->GetEntry(), pPlayer->GetNameString());
                item->DeleteMe();
            }
            else
            {
                pUnit->CastSpell(pPlayer, 26218, true);
            }
        }
    }
}
示例#25
0
void WorldSession::HandleAcceptTrade(WorldPacket & recv_data)
{
	Player * plr = _player->GetTradeTarget();
	if(_player->mTradeTarget == 0 || !plr)
		return;

	uint32 TradeStatus = TRADE_STATUS_ACCEPTED;
	
	// Tell the other player we're green.
#ifdef USING_BIG_ENDIAN
	swap32(&TradeStatus);
	plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
	_player->mTradeStatus = TradeStatus;
	swap32(&TradeStatus);
#else
	plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
	_player->mTradeStatus = TradeStatus;
#endif

	if(plr->mTradeStatus == TRADE_STATUS_ACCEPTED)
	{
		// Ready!
		uint32 ItemCount = 0;
		uint32 TargetItemCount = 0;
		Player * pTarget = plr;

		// Calculate Item Count
		for(uint32 Index = 0; Index < 7; ++Index)
		{
			if(_player->mTradeItems[Index] != 0)	++ItemCount;
			if(pTarget->mTradeItems[Index] != 0)	++TargetItemCount;
		}

		if( (_player->m_ItemInterface->CalculateFreeSlots(NULL) + ItemCount) < TargetItemCount ||
			(pTarget->m_ItemInterface->CalculateFreeSlots(NULL) + TargetItemCount) < ItemCount )
		{
			// Not enough slots on one end.
			TradeStatus = TRADE_STATUS_CANCELLED;
		}
		else
		{
			TradeStatus = TRADE_STATUS_COMPLETE;
			uint64 Guid;
			Item * pItem;
			
			// Remove all items from the players inventory
			for(uint32 Index = 0; Index < 6; ++Index)
			{
				Guid = _player->mTradeItems[Index] ? _player->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( _player->mTradeItems[Index]->GetProto()->Bonding == ITEM_BIND_ON_PICKUP ||
						_player->mTradeItems[Index]->GetProto()->Bonding  >=  ITEM_BIND_QUEST  )
					{
						_player->mTradeItems[Index] = NULL;
					}
					else
					{
						if(GetPermissionCount()>0)
						{
							sGMLog.writefromsession(this, "traded item %s to %s", _player->mTradeItems[Index]->GetProto()->Name1, pTarget->GetName());
						}
						pItem = _player->m_ItemInterface->SafeRemoveAndRetreiveItemByGuid(Guid, true);
					}
				}

				Guid = pTarget->mTradeItems[Index] ? pTarget->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( pTarget->mTradeItems[Index]->GetProto()->Bonding == ITEM_BIND_ON_PICKUP ||  
						pTarget->mTradeItems[Index]->GetProto()->Bonding  >=  ITEM_BIND_QUEST )
					{
						pTarget->mTradeItems[Index] = NULL;
					}
					else
					{
						pTarget->m_ItemInterface->SafeRemoveAndRetreiveItemByGuid(Guid, true);
					}
				}
			}

			// Dump all items back into the opposite players inventory
			for(uint32 Index = 0; Index < 6; ++Index)
			{
				pItem = _player->mTradeItems[Index];
				if(pItem != 0)
				{
					pItem->SetOwner(pTarget);
					if( !pTarget->m_ItemInterface->AddItemToFreeSlot(pItem) )
						pItem->DeleteMe();
				}

				pItem = pTarget->mTradeItems[Index];
				if(pItem != 0)
				{
					pItem->SetOwner(_player);
					if( !_player->m_ItemInterface->AddItemToFreeSlot(pItem) )
						pItem->DeleteMe();
				}
			}

			// Trade Gold
			if(pTarget->mTradeGold)
			{
				_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, pTarget->mTradeGold);
				pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pTarget->mTradeGold);
			}

			if(_player->mTradeGold)
			{
				pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, _player->mTradeGold);
				_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)_player->mTradeGold);
			}

			// Close Window
			TradeStatus = TRADE_STATUS_COMPLETE;
#ifdef USING_BIG_ENDIAN
            swap32(&TradeStatus);
			OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
			plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
			swap32(&TradeStatus);
#else
			OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
			plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus);
#endif

			_player->mTradeStatus = TRADE_STATUS_COMPLETE;
			plr->mTradeStatus = TRADE_STATUS_COMPLETE;

			// Reset Trade Vars
			_player->ResetTradeVariables();
			pTarget->ResetTradeVariables();
			
			plr->mTradeTarget = 0;
			_player->mTradeTarget = 0;

			plr->SaveToDB(false);
			_player->SaveToDB(false);
		}
	}
}