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


C++ ItemContainer::BagIndex2ConIndex方法代码示例

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


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

示例1: Execute

uint CGBankSwapItemHandler::Execute( CGBankSwapItem* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION


	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	UINT indexFrom = pPacket->GetIndexFrom();
	UINT indexTo   = pPacket->GetIndexTo();
	GCBankSwapItem Msg;

	switch(pPacket->GetFromType())
	{
	case CGBankSwapItem::EQUIP_POS:
		{
			switch(pPacket->GetToType())
			{
				case CGBankSwapItem::BAG_POS:
					{
					}
					break;
				case CGBankSwapItem::EQUIP_POS:
					{
					}
					break;
				case CGBankSwapItem::BANK_POS:
					{
					}
					break;
				default:
					break;
			}
		}
		break;
	case CGBankSwapItem::BAG_POS:
		{
			switch(pPacket->GetToType())
			{
			case CGBankSwapItem::BAG_POS:
				{
				}
				break;
			case CGBankSwapItem::EQUIP_POS:
				{
				}
				break;
			case CGBankSwapItem::BANK_POS:			// Bag->Bank
				{
					//验证位置的合法性
					if( indexFrom>=0 
						&& indexFrom<MAX_BAG_SIZE 
						&& indexTo>=0 
						&& indexTo<(UINT)(pHuman->__GetBankEndIndex()) 
						)
					{
						//验证位置里是否有东西
						if( ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom))
							&&ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexTo))
							)
						{
							ItemContainer*	pBagContainer =
								HumanItemLogic::GetContainer(pHuman,indexFrom);

							ItemContainer* pBankContainer = pHuman->GetBankContain();

							Item *pItem1 = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom));
							Item *pItem2 = pBankContainer->GetItem(indexTo);
							//检测是否能够合并,如果可以,就执行合并而不是交换
							if(pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->IsCanLay())
							{
								if(g_ItemOperator.MoveSpliceItem(  pBagContainer,
																(UCHAR)indexFrom,
																pBankContainer,
																indexTo)
									== ITEMOE_SUCCESS)
								{
									GCItemInfo msg1;
									msg1.setID(indexFrom);
									msg1.setIsNull(pItem1->IsEmpty());
									pItem1->SaveValueTo(msg1.getItem());
									pGamePlayer->SendPacket(&msg1);

									GCBankItemInfo msg2;
									msg2.setBankIndex(indexTo);
									msg2.setIsNull(pItem2->IsEmpty());
									pItem2->SaveValueTo(msg2.getItem());
//.........这里部分代码省略.........
开发者ID:ueverything,项目名称:mmo-resourse,代码行数:101,代码来源:CGBankSwapItemHandler.cpp

示例2: Execute

uint CGEquipLevelupHandler::Execute(CGEquipLevelup* pPacket,Player* pPlayer)
{
	__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer;
	Assert( pGamePlayer );

	Obj_Human* pHuman = pGamePlayer->GetHuman();
	Assert( pHuman );

	Scene* pScene = pHuman->getScene();
	if( pScene==NULL )
	{
		Assert(FALSE);
		return PACKET_EXE_ERROR;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );

	//交易状态不可操作
	if(pHuman->m_ExchangBox.m_Status > 0)
	{//丢弃
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ExchangBox::m_Status>0" ,pHuman->GetID()) ;
		return PACKET_EXE_CONTINUE ;
	}
	//摆摊状态不可操作
	if(pHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
	{//丢弃
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ServerStallBox::STALL_OPEN" ,pHuman->GetID()) ;
		return PACKET_EXE_CONTINUE ;
	}

	Item*		pEquipItem		= NULL;
	UINT		EquipPoint		= INVALID_ITEM_POS;
	UINT		BagIndex		= INVALID_ITEM_POS;  
	EQUIPLEVEUP_RESULT nResult	= EQUIPLEVEUP_FAIL;
	GCEquipLevelupResult Msg;
	switch(pPacket->GetEquipPosType())
	{
	case ENUM_EQUIP_POINT:
		{
			EquipPoint = pPacket->GetPos();
			if(EquipPoint>HEQUIP_ADORN2)
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: EquipPoint error, EquipPoint=%d", EquipPoint) ;
				return PACKET_EXE_ERROR;
			}

			ItemContainer* pEquipContainer = pHuman->GetEquipContain();
			if(NULL==pEquipContainer)
			{
				AssertEx(FALSE,"[CGUseGem]: NULL EquipContainer pointer found!");
			}
			pEquipItem = pEquipContainer->GetItem((UINT)EquipPoint);
			Assert(pEquipItem);
			
			if(pEquipItem->IsEmpty())
			{
				nResult = EQUIPLEVEUP_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler pEquipItem is Null at  EquipPoint= %d", EquipPoint) ;
				return PACKET_EXE_CONTINUE;
			}
			
			Assert (pEquipItem->GetItemClass() == ICLASS_EQUIP);

			if(!(pPacket->getItemID() == pEquipItem->GetGUID()))
			{
				nResult = EQUIPLEVEUP_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler GUID is different ") ;
				return PACKET_EXE_CONTINUE;
			}


		}
		break;
	case ENUM_BAG:
		{
			BagIndex = pPacket->GetPos();
			ItemContainer* pItemContainer = HumanItemLogic::GetBagContainer(pHuman,BagIndex);
			if( pItemContainer == NULL )
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: BagIndex error, BagIndex=%d", BagIndex) ;
				return PACKET_EXE_ERROR;
			}
			if (!pItemContainer->IsCanUse())
			{
				nResult = EQUIPLEVEUP_BAG_INVALID;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d", 
					pItemContainer->GetContainerType(), BagIndex) ;
					return PACKET_EXE_ERROR;
			}

			pEquipItem		=	pItemContainer->GetItem(pItemContainer->BagIndex2ConIndex(BagIndex));
//.........这里部分代码省略.........
开发者ID:uvbs,项目名称:wx2Server,代码行数:101,代码来源:CGEquipLevelupHandler.cpp

示例3: Execute


//.........这里部分代码省略.........
					{
						Assert(i == HEQUIP_ADORN2);
					}
					else
						Assert(0);
				}
				//玩家可能等级变了
				if(pExchangeItem->GetRequireLevel() > pHuman->GetLevel() )
				{
					EXCHANGE_EQUIP_INFO ExchangeInfo;
					ExchangeInfo.m_BagIndex = INVALID_ITEM_POS;
					ExchangeInfo.m_EquipPoint	= i;
					Msg.setEquipInfo(ExchangeInfo, i);
					g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: Equiplevel , pEquip->GetRequireLevel()=%d", pEquip->GetRequireLevel() ) ;
					continue;
				}
				
				//可能换职业了
				if(!pExchangeItem->IsWuMenPai())
				{
					if(!pExchangeItem->InReqJob(pHuman->GetMenPai()))
					{
						EXCHANGE_EQUIP_INFO ExchangeInfo;
						ExchangeInfo.m_BagIndex = INVALID_ITEM_POS;
						ExchangeInfo.m_EquipPoint	= i;
						Msg.setEquipInfo(ExchangeInfo, i);
						g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: ReqJob") ;
						continue;
					}
				}
				if (pEquip->IsEmpty())
				{
					g_ItemOperator.MoveItem( pBagContainer,
						pBagContainer->BagIndex2ConIndex(nPos),
						pEquipContainer,
						i ) ;
				}
				
				else
				{
					if (pBagContainer->IsCanUse())
					{
						//与装备的物品进行交换
						g_ItemOperator.ExchangeItem(pBagContainer,
							pBagContainer->BagIndex2ConIndex(nPos),
							pEquipContainer,
							i);
					}
					else //背包已经过期
					{
						EXCHANGE_EQUIP_INFO ExchangeInfo;
						ExchangeInfo.m_BagIndex = INVALID_ITEM_POS;
						ExchangeInfo.m_EquipPoint	= INVALID_ITEM_POS;
						Msg.setEquipInfo(ExchangeInfo, i);
						continue;
					}
				}
				EXCHANGE_EQUIP_INFO ExchangeInfo;
				ExchangeInfo.m_BagIndex = nPos;
				ExchangeInfo.m_EquipPoint	= i;
				Msg.setEquipInfo(ExchangeInfo, i);

				//交换到人身上了,重新获取一下
				Item* pEquipItem = HumanItemLogic::GetEquip(pHuman, (HUMAN_EQUIP)i);
				if(!pEquipItem)
				{
开发者ID:,项目名称:,代码行数:67,代码来源:

示例4: Execute

UINT CGEquipRefiningHandler::Execute( CGEquipRefining* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}
	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );

	//切场景时丢弃换装消息
	//交易状态不可操作
	//摆摊状态不可操作

	// 获取炼化的装备
	BYTE iEquipItemPos = pPacket->GetEquipItemPos();
	Assert(iEquipItemPos >= 0 );
	Assert(iEquipItemPos <= MAX_BAG_SIZE);
	
	GCEquipRefining	msg;
	ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iEquipItemPos);
	if (pBagContainer == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler equipment BagIndex is invalid, BagIndex = %d", iEquipItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	Item* pEquipment = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iEquipItemPos));
	Assert(NULL != pEquipment);
	//一些验证:星级,等级...
	if( NULL == pEquipment || ICLASS_EQUIP != pEquipment->GetItemClass() || !(pEquipment->IsRuler(IRL_DISCARD) )
		|| pEquipment->IsAdsorbMagic()	|| pEquipment->GetRequireLevel() < EQUIP_REFINING_MIN_LEVEL	//已经附魔或者需求等级小于40
		|| 0 == pEquipment->GetEquipGemCount())	//没有镶嵌宝石
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler equipment type is invalid, BagIndex = %d", iEquipItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);

		return PACKET_EXE_CONTINUE;
	}
	//获取炼化神器
	BYTE iRefiningItemPos = pPacket->GetRefiningItemPos();
	Assert(iRefiningItemPos >= 0 );
	Assert(iRefiningItemPos <= MAX_BAG_SIZE);

	pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningItemPos);
	if (pBagContainer == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler refining BagIndex is invalid, BagIndex = %d", iRefiningItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	Item* pRefiningItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningItemPos));
	Assert(NULL != pRefiningItem);
	if(NULL == pRefiningItem || pRefiningItem->GetItemClass() != ICLASS_COMITEM || pRefiningItem->GetItemType() != COMITEM_EQUIP_REFINING)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler refining type is invalid, BagIndex = %d", iRefiningItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);

		return PACKET_EXE_CONTINUE;
	}
	//逻辑处理 
	COMMITEM_INFO_TB* pGet = g_ItemTable.GetCommItemInfoTB(pRefiningItem->GetItemTableIndex());
	Assert(NULL != pGet);
	if ((pEquipment->GetRequireLevel()-1)/10+1 != pGet->m_nLevel)//验证等级
	{
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);

		return PACKET_EXE_CONTINUE;
	}

	if ( 0 == pEquipment->GetAttrCount())// && pEquipment->GetLevel() 
	{
		msg.SetResult(EQUIPREFINING_NOT_HAVE_ATTR);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	//EQUIP_TB* pGet = g_ItemTable.GetEquipTB(pEquipment->GetItemTableIndex());
	//Assert(NULL != pGet);
	//删除装备和炼化神符道具
	UINT iPrice = pEquipment->GetSellPrice();//保留将要删除的装备属性给后面用
	BYTE iRequireLevel = pEquipment->GetRequireLevel();
	BYTE curEquipPoint = pEquipment->GetEquipPoint();
	BYTE attrCount = 0;
//.........这里部分代码省略.........
开发者ID:uvbs,项目名称:wx2Server,代码行数:101,代码来源:CGEqupRefiningHandler.cpp

示例5: Execute

UINT CGUseEquipHandler::Execute(CGUseEquip* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION
	
	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;
	
	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	//切场景时丢弃换装消息
	if(pGamePlayer->GetPlayerStatus()!=PS_SERVER_NORMAL ||
		!pHuman->IsActiveObj() )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGUseEquipmentHandler: change scene") ;
		return PACKET_EXE_CONTINUE;
	}

	BYTE  BagIndex = pPacket->getBagIndex();

	if( BagIndex == INVALID_BAG_INDEX )
	{
		Assert(FALSE) ; //包发错了
		return PACKET_EXE_CONTINUE ;
	}
		
	Item* pUseItem = HumanItemLogic::GetItem(pHuman,BagIndex);
	
	GCUseEquipResult Msg;

	//////////////////////////////////////////////////////////////////////////
	//装配条件判断
	UCHAR	itemClass = pUseItem->GetItemClass();

	if(itemClass == ICLASS_EQUIP)
	{
		//需求等级判断
		if(pUseItem->GetRequireLevel()>pHuman->GetLevel())
		{
			Msg.setResult(USEEQUIP_IDENT_FAIL);
			pGamePlayer->SendPacket( &Msg ) ;
		}
		//鉴定判断
		else if(pUseItem->GetItemQual() == EQUALITY_BLUE && pUseItem->GetItemIdent() == FALSE)
		{
			Msg.setResult(USEEQUIP_LEVEL_FAIL);
			pGamePlayer->SendPacket( &Msg ) ;
		}
		else
		{
			
			HUMAN_EQUIP		Equip_Point =(HUMAN_EQUIP)pUseItem->GetEquipPoint();
			//const	_ITEM*			pEquip = pHuman->GetEquip(Equip_Point);
			ItemContainer*	pEquipContainer = pHuman->GetEquipContain();
			
			if(!pEquipContainer)
			{
				Assert(pEquipContainer);
				return PACKET_EXE_CONTINUE;
			}

			Item*	pEquipItem = pEquipContainer->GetItem((UINT)Equip_Point);

			if(!pEquipItem)
			{
				Assert(pEquipItem);
				return PACKET_EXE_CONTINUE;

			}
			
			BOOL			bEquipStatus = (!pEquipItem->IsEmpty());

			ItemContainer*	pBagContainer =
				HumanItemLogic::GetContainer(pHuman,BagIndex);

			if(bEquipStatus)
			{
				//装备上物品,替换下来装备点数据
				
				g_ItemOperator.ExchangeItem(pBagContainer,
											pBagContainer->BagIndex2ConIndex(BagIndex),
											pEquipContainer,
											(UINT)Equip_Point);


			}
			else
			{ 
				//pHuman->GetDB()->OverWriteBag2Equip(BagIndex,Equip_Point);
				g_ItemOperator.MoveItem(pBagContainer,
//.........这里部分代码省略.........
开发者ID:brock7,项目名称:TianLong,代码行数:101,代码来源:CGUseEquipHandler.cpp

示例6: Execute

uint CGBankAddItemHandler::Execute( CGBankAddItem* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	UINT indexFrom = pPacket->GetIndexFrom();
	UINT indexTo   = pPacket->GetIndexTo();

	GCBankAddItem Msg;

	switch(pPacket->GetFromType())
	{
	case CGBankAddItem::EQUIP_POS:
		{
			pHuman->GetDB()->OverWriteEquip2Bank((HUMAN_EQUIP)indexFrom, indexTo);
			Msg.SetFromType(GCBankAddItem::EQUIP_POS);
			Msg.SetIndexFrom(indexFrom);
			Msg.SetIndexTo(indexTo);
		}
		break;
	case CGBankAddItem::BAG_POS:		//Bag->Bank
		{
			ItemContainer *pBankContainer  = pHuman->GetBankContain();
			ItemContainer *pBagContainer = HumanItemLogic::GetContainer(pHuman,indexFrom);

			Item *pBagItem  = pBagContainer->GetItem( pBagContainer->BagIndex2ConIndex(indexFrom) );
			//防止连续点击
			if(pBagItem->IsEmpty())
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler too many click") ;
				return PACKET_EXE_CONTINUE;
			}
			//Item *pBankItem = pBankContainer->GetItem( indexTo );

			//合并标志
			INT	 bSplice = 0;
			INT  nSpliceTo = -1;
			UINT TempIndexTo = indexTo;

			//自动搜索空格租赁箱1
			switch(TempIndexTo)
			{
			case CGBankAddItem::AUTO_POS_BOX1:
				{
					//先查询是不是有可以合并的物品,(只在本租赁箱中)
					if( pBagItem->IsCanLay() )
					{
						for( INT i=RENTBOX1_START_INDEX; i<RENTBOX2_START_INDEX; i++ )
						{
							Item *pBankItem = pBankContainer->GetItem(i);
							
							// 验证是否可以叠加成功
							if( pBankItem->GetItemTableIndex() == pBagItem->GetItemTableIndex() && 
								pBankItem->GetLayedNum() + pBagItem->GetLayedNum() <= pBankItem->GetMaxLayedNum() )
							{
								bSplice = 1;
								nSpliceTo = i;
								indexTo = i;
								break;
							}
						}
					}
					//没有可以叠加的物品,就寻找一个空格
					BYTE	indextemp = RENTBOX1_START_INDEX;
					if(0 == bSplice)
					{
						while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp))  
							&&  indextemp < RENTBOX2_START_INDEX
							)
						{
							indextemp++;
						}

						if(indextemp == RENTBOX2_START_INDEX)
						{
							indexTo = indextemp-1;
						}
						else
						{
							indexTo = indextemp;
						}
					}
				}
				break;

//.........这里部分代码省略.........
开发者ID:ueverything,项目名称:mmo-resourse,代码行数:101,代码来源:CGBankAddItemHandler.cpp

示例7: Execute

uint CGExchangeSynchItemIIHandler::Execute( CGExchangeSynchItemII* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	//验证交易状态
	EXCHANGE_CERTIFY_EACH_OTHER(pHuman)  // 验证交易双方是否掉线合法
	EXCHANGE_CERTIFY_ISLOCK(pHuman)		 // 验证当前人物的交易状态是否已经上锁
	ObjID_t	DestID = pHuman->m_ExchangBox.m_ObjID;
	Obj_Human* pDestHuman = pScene->GetHumanManager()->GetHuman( DestID );
	EXCHANGE_CERTIFY_STATUS(pHuman, EXCHANGE_SYNCH_DATA) // 验证当前人物的交易状态是否正确
	EXCHANGE_CERTIFY_STATUS(pDestHuman, EXCHANGE_SYNCH_DATA)

	//操作
	BYTE		Opt = pPacket->GetOpt();
	BYTE		FromType = pPacket->GetFromType();
	BYTE		ToType = pPacket->GetToType();
	BYTE		FromIndex = pPacket->GetFromIndex();
	BYTE		ToIndex = pPacket->GetToIndex();
	PET_GUID_t	PetGuid = pPacket->GetPetGuid();

	_ITEM				ItemTemp;
	GCExchangeSynchII	Msg;
	GCExchangeError		MsgError;
	ItemContainer*		pExchangeContainer		= &(pHuman->m_ExchangBox.m_Container);
	ItemContainer*		pExchangePetContainer	= &(pHuman->m_ExchangBox.m_PetContainer);

	switch(Opt)
	{
	case OPT_ERROR:
		{
		}
		break;
	case OPT_ADDITEM:
		{
			switch(FromType)
			{
			case POS_BAG:
				{
					//验证位置里是否有东西
					Item* pItem = HumanItemLogic::GetBagItem(pHuman, FromIndex);

                    if ( pItem != NULL && pItem->GetItemClass() == ICLASS_EQUIP)
                    {
                        if(pItem->GetEquipBindLevel()>0) // 装备绑定
                        {
							MsgError.SetID(ERR_ITEM_LOCKED);
							pGamePlayer->SendPacket(&MsgError);
                            g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 该物品[%d]已绑定,不可交易",	pHuman->GetName(), FromIndex ) ;
                            return PACKET_EXE_CONTINUE;
                        }
                    }
                    
					if (pItem == NULL)
					{
						MsgError.SetID(ERR_ILLEGAL);
						pGamePlayer->SendPacket(&MsgError);
						g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 背包位置 [%d] 处不存在物品",	pHuman->GetName(), FromIndex ) ;
						return PACKET_EXE_CONTINUE;
					}
					if(pItem->IsEmpty() == FALSE)
					{
						ItemContainer*	pBagContainer = HumanItemLogic::GetBagContainer(pHuman, FromIndex);

						if ( pBagContainer == NULL )
						{
							MsgError.SetID(ERR_ILLEGAL);
							pGamePlayer->SendPacket(&MsgError);
							g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 背包不存在",	pHuman->GetName() ) ;
							return PACKET_EXE_CONTINUE;
						}

						//先查一遍交易盒中是不是已经有该物品了
						for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
						{
							_ITEM_GUID guid = (pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(FromIndex)))->GetGUID() ;
							if(pExchangeContainer->GetItem(i)->GetGUID() == guid)
							{//物品已经在交易盒中,丢弃该消息
								return PACKET_EXE_CONTINUE ;
							}

						}

						//自动找格
						INT result = 
//.........这里部分代码省略.........
开发者ID:uvbs,项目名称:wx2Server,代码行数:101,代码来源:CGExchangeSynchItemIIHandler.cpp

示例8: if

uint	CGAskLockObjHandler::Execute(CGAskLockObj* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	
	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
	
	BYTE LockType = pPacket->GetLockType();
	BYTE lockObj  = pPacket->GetLockObj();

	GCAddLockObj msg;

	// 如果要执行加锁先查询玩家是不是还有足够的精力(为一个物品或者宠物加保护,需要10点精力)
	if(pPacket->GetLockType() == CGAskLockObj::OPR_LOCK)
	{
		if( LOCK_A_OBJ_NEED_ENERGY > pHuman->GetEnergy() )
		{
			msg.SetLockObj(GCAddLockObj::LOCK_ITEM);
			msg.SetResult(GCAddLockObj::RESULT_NO_JINGLI);

			pHuman->GetPlayer()->SendPacket(&msg);

			return PACKET_EXE_CONTINUE ;
		}
	}

	switch(lockObj)
	{
	case CGAskLockObj::LOCK_ITEM:	//物品
		{
			msg.SetLockObj(GCAddLockObj::LOCK_ITEM);

			INT nItemIndex = HumanItemLogic::GetBagItemPosByGUID( pHuman, pPacket->GetItemGUID() );

			if(INVALID_ID == nItemIndex)
			{
				return PACKET_EXE_CONTINUE ;
			}

			Item* pItem = HumanItemLogic::GetBagItem( pHuman, nItemIndex );
			if(!pItem)
			{
				return PACKET_EXE_CONTINUE ;
			}

			ItemContainer* pCon = HumanItemLogic::GetBagContainer( pHuman, nItemIndex );
			if(!pCon)
			{
				return PACKET_EXE_CONTINUE ;
			}

			if(LockType == CGAskLockObj::OPR_LOCK)			//加锁
			{
				if(g_ItemOperator.SetItemPWLock(pCon, pCon->BagIndex2ConIndex(nItemIndex), TRUE))
				{
					//扣除精力
					pHuman->SetEnergy(pHuman->GetEnergy() - LOCK_A_OBJ_NEED_ENERGY);

					msg.SetResult(GCAddLockObj::RESULT_LOCK_OK);

					GCItemInfo  MsgItem;
					MsgItem.setIsNull(FALSE);
					MsgItem.setID((WORD)nItemIndex);
					pItem->SaveValueTo(MsgItem.getItem());
					pHuman->GetPlayer()->SendPacket(&MsgItem);
				}
			}
			else if(LockType == CGAskLockObj::OPR_UNLOCK)	//去锁
			{
				if(g_ItemOperator.SetItemPWLock(pCon, pCon->BagIndex2ConIndex(nItemIndex), FALSE))
				{
					msg.SetResult(GCAddLockObj::RESULT_UNLOCK_OK);

					GCItemInfo  MsgItem;
					MsgItem.setIsNull(FALSE);
					MsgItem.setID((WORD)nItemIndex);
					pItem->SaveValueTo(MsgItem.getItem());
					pHuman->GetPlayer()->SendPacket(&MsgItem);
				}
			}
		}
		break;
	case CGAskLockObj::LOCK_PET:	//宠物
		{
			msg.SetLockObj(GCAddLockObj::LOCK_PET);

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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