当前位置: 首页>>代码示例>>C++>>正文


C++ PlayerPointer::ResetTradeVariables方法代码示例

本文整理汇总了C++中PlayerPointer::ResetTradeVariables方法的典型用法代码示例。如果您正苦于以下问题:C++ PlayerPointer::ResetTradeVariables方法的具体用法?C++ PlayerPointer::ResetTradeVariables怎么用?C++ PlayerPointer::ResetTradeVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PlayerPointer的用法示例。


在下文中一共展示了PlayerPointer::ResetTradeVariables方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandleCancelTrade

void WorldSession::HandleCancelTrade(WorldPacket & recv_data)
{
	if(!_player->IsInWorld() || _player->mTradeTarget == 0)
		return;

	if( _player->mTradeStatus == TRADE_STATUS_COMPLETE)
	{
		_player->ResetTradeVariables();
		return;
	}

	uint32 TradeStatus = TRADE_STATUS_CANCELLED;

	PlayerPointer pTarget = _player->GetTradeTarget();
	if(pTarget == NULL || !pTarget->IsInWorld())
	{
		TradeStatus = TRADE_STATUS_PLAYER_NOT_FOUND;
		_player->ResetTradeVariables();
		SendTradeStatus(TradeStatus);
	}
	else
	{
		pTarget->ResetTradeVariables();
		_player->ResetTradeVariables();
	
		SendTradeStatus(TradeStatus);
		if(pTarget->m_session && pTarget->m_session->GetSocket())
			pTarget->m_session->SendTradeStatus(TradeStatus);
	}
}
开发者ID:Vanj-crew,项目名称:HearthStone-Emu,代码行数:30,代码来源:TradeHandler.cpp

示例2: HandleInitiateTrade

void WorldSession::HandleInitiateTrade(WorldPacket & recv_data)
{
	CHECK_INWORLD_RETURN;

	CHECK_PACKET_SIZE(recv_data, 8);

	uint64 guid;
	recv_data >> guid;

	uint32 TradeStatus = TRADE_STATUS_PROPOSED;

	PlayerPointer pTarget = _player->GetMapMgr()->GetPlayer((uint32)guid);
	if(pTarget == NULL || !pTarget->IsInWorld())
		TradeStatus = TRADE_STATUS_PLAYER_NOT_FOUND;
	else
	{
		// Handle possible error outcomes
		if(_player->isDead())
			TradeStatus = TRADE_STATUS_DEAD;
		if(pTarget->isDead())
			TradeStatus = TRADE_STATUS_TARGET_DEAD;
		else if(pTarget->mTradeTarget != 0)
			TradeStatus = TRADE_STATUS_ALREADY_TRADING;
		else if(pTarget->GetTeam() != _player->GetTeam() && GetPermissionCount() == 0)
			TradeStatus = TRADE_STATUS_WRONG_FACTION;
		else if(_player->CalcDistance(pTarget) > 10.0f)		// This needs to be checked
			TradeStatus = TRADE_STATUS_TOO_FAR_AWAY;
	}	

	if(TradeStatus != TRADE_STATUS_PROPOSED)
	{
		_player->ResetTradeVariables();
		SendTradeStatus(TradeStatus);
	}
	else
	{
		_player->ResetTradeVariables();
		pTarget->ResetTradeVariables();

		pTarget->mTradeTarget = _player->GetLowGUID();
		_player->mTradeTarget = pTarget->GetLowGUID();

		pTarget->mTradeStatus = TradeStatus;
		_player->mTradeStatus = TradeStatus;

		WorldPacket data(SMSG_TRADE_STATUS, 12);
		data << TradeStatus;
		data << _player->GetGUID();

		if(pTarget->m_session && pTarget->m_session->GetSocket())
			pTarget->m_session->SendPacket(&data);
	}
}
开发者ID:Vanj-crew,项目名称:HearthStone-Emu,代码行数:53,代码来源:TradeHandler.cpp

示例3: HandleAcceptTrade


//.........这里部分代码省略.........
				else
					++TargetItemCount;
			}
		}
		//Do we have something to trade?
		if( ItemCount == 0 && TargetItemCount == 0 && _player->mTradeGold == 0 && pTarget->mTradeGold == 0 )
			TradeStatus = TRADE_STATUS_CANCELLED;
		//Do we have enough free slots on both sides?
		else if((_player->m_ItemInterface->CalculateFreeSlots(NULL) + ItemCount) < TargetItemCount || (pTarget->m_ItemInterface->CalculateFreeSlots(NULL) + TargetItemCount) < ItemCount )
			TradeStatus = TRADE_STATUS_CANCELLED;
		//Everything still ok?
		else if(TradeStatus == TRADE_STATUS_ACCEPTED)
		{
			uint64 Guid;
			
			//Swapp 6 itemslots (7th will not trade)
			for(uint32 Index = 0; Index < 6; ++Index)
			{
				Guid = _player->mTradeItems[Index] ? _player->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( _player->mTradeItems[Index]->IsSoulbound())
						_player->GetItemInterface()->BuildInventoryChangeError(	_player->mTradeItems[Index], NULLITEM, INV_ERR_CANNOT_TRADE_THAT);
					else
					{
						//Remove from player
						pItem = _player->m_ItemInterface->SafeRemoveAndRetreiveItemByGuidRemoveStats(Guid, true);

						//and add to pTarget
						if(pItem != NULL)
						{
							pItem->SetOwner(pTarget);
							if( !pTarget->m_ItemInterface->AddItemToFreeSlot(pItem) )
							{
								pItem->Destructor();
								pItem = NULLITEM;
							}
						}

						if(GetPermissionCount()>0 || pTarget->GetSession()->GetPermissionCount()>0)
							sGMLog.writefromsession(this, "trade item %s with %s (soulbound = %d)", _player->mTradeItems[Index]->GetProto()->Name1, pTarget->GetName());
					}
				}

				Guid = pTarget->mTradeItems[Index] ? pTarget->mTradeItems[Index]->GetGUID() : 0;
				if(Guid != 0)
				{
					if( pTarget->mTradeItems[Index]->IsSoulbound())
						pTarget->GetItemInterface()->BuildInventoryChangeError(	pTarget->mTradeItems[Index], NULLITEM, INV_ERR_CANNOT_TRADE_THAT);
					else
					{
						//Remove from pTarget
						pItem = pTarget->m_ItemInterface->SafeRemoveAndRetreiveItemByGuidRemoveStats(Guid, true);

						//and add to initiator
						if(pItem != NULL)
						{
							pItem->SetOwner(_player);
							if( !_player->m_ItemInterface->AddItemToFreeSlot(pItem) )
							{
								pItem->Destructor();
								pItem = NULLITEM;
							}

						}

						if(GetPermissionCount()>0 || pTarget->GetSession()->GetPermissionCount()>0)
							sGMLog.writefromsession(this, "trade item %s with %s", pTarget->mTradeItems[Index]->GetProto()->Name1, _player->GetName());
					}
				}
			}


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

			pTarget->SaveToDB(false);
			_player->SaveToDB(false);

			TradeStatus = TRADE_STATUS_COMPLETE;
		}

		SendTradeStatus(TradeStatus);
		if(pTarget->m_session && pTarget->m_session->GetSocket())
			pTarget->m_session->SendTradeStatus(TradeStatus);

		// Reset Trade Vars
		_player->ResetTradeVariables();
		pTarget->ResetTradeVariables();
	}
}
开发者ID:Vanj-crew,项目名称:HearthStone-Emu,代码行数:101,代码来源:TradeHandler.cpp


注:本文中的PlayerPointer::ResetTradeVariables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。