Beispiel #1
0
Item*	HumanItemLogic::GetBankItem(Obj_Human* pHuman,UINT BankIndex)
{
	__ENTER_FUNCTION

		Assert(BankIndex<MAX_BANK_SIZE);
	Assert(BankIndex>=0);
	if(BankIndex<0||BankIndex>MAX_BANK_SIZE)
	{
		AssertEx(FALSE,"HumanItemLogic::GetBankItem() BankIndex 不在合法范围 ");
		return NULL;
	}

	ItemContainer*	pBankContainer = pHuman->GetBankContain();

	Assert(pBankContainer);

	if(!pBankContainer)
	{
		return NULL;
	}

	return pBankContainer->GetItem((UINT)BankIndex);

	__LEAVE_FUNCTION

		return NULL;
}
uint CGAskMyBagListHandler::Execute(CGAskMyBagList* 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 ) ;

	
	ASK_BAG_MODE	mode		=	pPacket->GetAskMode();

	GCMyBagList Msg;

	switch(mode) 
	{
	case ASK_ALL:
		{
			_BAG_ITEM		ItemIterator;
			_ITEM_GUID		NullGuid;
			uint			AllAskCount = 0;
			uint            nItemCount  = 0;
			memset(&NullGuid,0,sizeof(_ITEM_GUID));
			

			Msg.SetAskMode(ASK_ALL);

			//读取扩展容器
			ItemContainer* pExtraContainer = pHuman->GetExtraContain();
			Assert(pExtraContainer);
			for( INT i=0; i<pExtraContainer->GetContainerSize(); i++ )
			{
				//临时代码
				Item*	pItem =	HumanItemLogic::GetExtraContainerItem(pHuman,pExtraContainer->ConIndex2BagIndex(i));
				Assert(pItem);

				if(!(pItem->IsEmpty()))
				{
					ItemIterator.m_nndex			=	pExtraContainer->ConIndex2BagIndex(i);
					pItem->SaveValueTo(&ItemIterator.m_nItemData);
					Msg.SetAskItemData(&ItemIterator,nItemCount);
					++nItemCount;
				}

			}
			//读取基本背包
			ItemContainer* pBaseContainer = pHuman->GetBaseContain();
			Assert(pBaseContainer);
			for( INT i=0; i<pBaseContainer->GetContainerSize(); i++ )
			{
				//临时代码
				Item*	pItem =	pBaseContainer->GetItem(i);
				Assert(pItem);

				if(!(pItem->IsEmpty()))
				{
					ItemIterator.m_nndex			=	pBaseContainer->ConIndex2BagIndex(i);
					pItem->SaveValueTo(&ItemIterator.m_nItemData);
					Msg.SetAskItemData(&ItemIterator,nItemCount);
					++nItemCount;
				}
			}

			//读取扩展背包
			for (INT j=0; j<MAX_EXTRA_BAG_NUM; ++j)
			{
				ItemContainer* pBaseContainer = pHuman->GetExtraBagContain(j);
				Assert(pBaseContainer);
				if (pBaseContainer->IsValid())
				{
					for( INT i=0; i<pBaseContainer->GetContainerSize(); i++ )
					{
						//临时代码
						Item*	pItem =	pBaseContainer->GetItem(i);
						Assert(pItem);

						if(!(pItem->IsEmpty()))
						{
							ItemIterator.m_nndex			=	pBaseContainer->ConIndex2BagIndex(i);
							pItem->SaveValueTo(&ItemIterator.m_nItemData);
							Msg.SetAskItemData(&ItemIterator,nItemCount);
							++nItemCount;
						}
					}
				}
			}

			Msg.SetItemCount(nItemCount);

			pGamePlayer->SendPacket(&Msg);
			
		}
		break;
	case ASK_SET:
		{
			//_BAG_ITEM	ItemIterator;
			//BYTE		askIndex ;
			//Msg.SetAskMode(ASK_SET);
			////设置当前玩家最大包裹大小
			//if(askCount>MAX_BAG_SIZE)	askCount= MAX_BAG_SIZE;

			//Msg.SetAskCount(askCount);

			//for(INT i=0;i<askCount;i++)
			//{

			//	
			//	askIndex						=	pPacket->GetAskItemIndex(i);	
			//	ItemIterator.m_nndex			=	askIndex;

			//	Item*	pItem =	HumanItemLogic::GetBagItem(pHuman,i);
			//	Assert(pItem);

			//	ItemIterator.m_ItemID			=	pItem->GetGUID();
			//	ItemIterator.m_ItemTableIndex	=	pItem->GetItemTableIndex();
			//	ItemIterator.m_Count			=	pItem->GetLayedNum();
			//	Msg.SetAskItemData(&ItemIterator,i);
			//}

			//pGamePlayer->SendPacket(&Msg);
		}
		break;
	default:
		break;
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGAskMyBagListHandler: mode=%d ",
		mode) ;

	// 发送玩家当前搜侠录列表,暂时不用客户端请求
	GCSouXiaList	souXiaListMsg;
	BYTE curSouXia = pHuman->GetCurSouXiaCount();
	souXiaListMsg.SetSouXiaCount(curSouXia);

	BYTE  iCount = 0;
	for (int i=0; i<MAX_SOUXIA_CONTAINER; ++i)
	{
		SouXia souXia	= pHuman->GetSouXia(i);
		UINT   souXiaID = souXia.GetSouXiaData().m_SouXiaID;
		if (souXiaID > 0)
		{
			SHORT curPos = souXia.GetSouXiaData().GetCurPos();
			Assert(curPos >= 0 );

			SOUXIA_DATA	souXiaData = souXia.GetSouXiaData();
			souXiaListMsg.SetSouXiaData(&souXiaData, iCount);//注意取得与容器对应的序号
			iCount++;
		}
	}
	Assert(iCount == curSouXia);
	pGamePlayer->SendPacket(&souXiaListMsg);

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
uint CGExchangeOkIIIHandler::Execute( CGExchangeOkIII* 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)
	ObjID_t	DestID = pHuman->m_ExchangBox.m_ObjID;
	Obj_Character *pTarget = (Obj_Character*)(pScene->GetObjManager()->GetObj( DestID ));
	if(pTarget->GetObjType() != Obj::OBJ_TYPE_HUMAN)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeOkIIIHandler: %s ask not a human.", pHuman->GetName() ) ;
		return	PACKET_EXE_CONTINUE;
	}
	Obj_Human* pDestHuman = (Obj_Human*)pTarget;
	if( pDestHuman == NULL )
	{
		Assert(FALSE);
		return PACKET_EXE_CONTINUE;
	}

	// 不同阵营,不让查看
	if( pHuman->IsEnemy( pDestHuman ) )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeOkIIIHandler: %s cann't ask %s's detailattr ", pHuman->GetName(), pDestHuman->GetName() ) ;
		return	PACKET_EXE_CONTINUE;
	}

	if(pHuman->m_ExchangBox.m_Status == ServerExchangeBox::EXCHANGE_WAIT_FOR_CONFIRM)
	{
		//设置可以交换
		pHuman->m_ExchangBox.m_Status = ServerExchangeBox::EXCHANGE_CONFIRM_READY;
		if(pDestHuman->m_ExchangBox.m_Status ==  ServerExchangeBox::EXCHANGE_CONFIRM_READY)
		{//可以交换了

			//1.变量初始化
			ItemContainer*		pMyExchangeContainer = &(pHuman->m_ExchangBox.m_Container);
			ItemContainer*		pOtExchangeContainer = &(pDestHuman->m_ExchangBox.m_Container);
			ItemContainer*		pMyExchangePetContainer = &(pHuman->m_ExchangBox.m_PetContainer);
			ItemContainer*		pOtExchangePetContainer = &(pDestHuman->m_ExchangBox.m_PetContainer);

			_EXCHANGE_ITEM_LIST			ItemListMeToOt;
			_EXCHANGE_ITEM_LIST			ItemListOtToMe;

			ItemListMeToOt.Init();
			ItemListOtToMe.Init();

			//2.验证循环
			g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始验证循环",	pHuman->GetName(), pDestHuman->GetName()) ;
			for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
			{
				if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					ItemListMeToOt.AddItem( pMyExchangeContainer->GetItem(i) );
				}
				if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					ItemListOtToMe.AddItem( pOtExchangeContainer->GetItem(i) );
				}
			}

			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					ItemListMeToOt.AddItem( pMyExchangePetContainer->GetItem(i) );
				}
				if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					ItemListOtToMe.AddItem( pOtExchangePetContainer->GetItem(i) );
				}
			}

			if( FALSE == HumanItemLogic::CanReceiveExchangeItemList( pHuman, ItemListOtToMe) )
			{//空间不够
				GCExchangeError MsgSelf;
				MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_SELF);
				pHuman->GetPlayer()->SendPacket(&MsgSelf);

				GCExchangeError MsgOther;
				MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_OTHER);
				pDestHuman->GetPlayer()->SendPacket(&MsgOther);
				
				pHuman->m_ExchangBox.CleanUp();
				pDestHuman->m_ExchangBox.CleanUp();
				g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] 空间不够", pHuman->GetName()) ;
				return PACKET_EXE_CONTINUE;
			}

			if( FALSE == HumanItemLogic::CanReceiveExchangeItemList( pDestHuman, ItemListMeToOt) )
			{//空间不够
				GCExchangeError MsgSelf;
				MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_SELF);
				pDestHuman->GetPlayer()->SendPacket(&MsgSelf);

				GCExchangeError MsgOther;
				MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_OTHER);
				pHuman->GetPlayer()->SendPacket(&MsgOther);

				pHuman->m_ExchangBox.CleanUp();
				pDestHuman->m_ExchangBox.CleanUp();
				g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] 空间不够", pDestHuman->GetName()) ;
				return PACKET_EXE_CONTINUE;
			}

			if( pHuman->m_ExchangBox.m_Money > pHuman->GetMoney() )
			{//金钱非法
				GCExchangeError MsgSelf;
				MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_SELF);
				pHuman->GetPlayer()->SendPacket(&MsgSelf);

				GCExchangeError MsgOther;
				MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_OTHER);
				pDestHuman->GetPlayer()->SendPacket(&MsgOther);

				pHuman->m_ExchangBox.CleanUp();
				pDestHuman->m_ExchangBox.CleanUp();
				g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] 金钱不足", pHuman->GetName()) ;
				return PACKET_EXE_CONTINUE;
			}

			if( pDestHuman->m_ExchangBox.m_Money > pDestHuman->GetMoney() )
			{//金钱非法
				GCExchangeError MsgSelf;
				MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_SELF);
				pDestHuman->GetPlayer()->SendPacket(&MsgSelf);

				GCExchangeError MsgOther;
				MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_OTHER);
				pHuman->GetPlayer()->SendPacket(&MsgOther);

				pHuman->m_ExchangBox.CleanUp();
				pDestHuman->m_ExchangBox.CleanUp();
				g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] 金钱不足", pDestHuman->GetName()) ;
				return PACKET_EXE_CONTINUE;
			}

			//2.1宠物验证
			Obj_Pet* pDestPet	= pDestHuman->GetPet();
			Obj_Pet* pMyPet		= pHuman->GetPet();

			PET_GUID_t	DestPetGuid;
			PET_GUID_t	MyPetGuid;
			
			if(pDestPet)
			{
				DestPetGuid = pDestPet->GetPetGUID();
			}
			if(pMyPet)
			{
				MyPetGuid = pMyPet->GetPetGUID();
			}

			//如果是当前召唤出来的宠物,先收回来再换
			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT nPetLevel			= pMyExchangePetContainer->GetItem(i)->GetLevel();
					INT nHumanLevel			= pDestHuman->GetLevel();
					PET_GUID_t	ExchPetGuid	= pMyExchangePetContainer->GetItem(i)->GetPetGUID();
					if(nPetLevel>nHumanLevel)
					{
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_PET_LEVEL_TOO_HIGH);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> 宠物级别过高 petlevel = %d, humanlevel = %d", nPetLevel, nHumanLevel) ;
						return PACKET_EXE_CONTINUE;
					}
					if(ExchPetGuid == MyPetGuid)
					{
						pHuman->ReCallPet();
					}
				}

				if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT nPetLevel = pOtExchangePetContainer->GetItem(i)->GetLevel();
					INT nHumanLevel = pHuman->GetLevel();
					PET_GUID_t	ExchPetGuid	= pOtExchangePetContainer->GetItem(i)->GetPetGUID();
					if(nPetLevel>nHumanLevel)
					{
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_PET_LEVEL_TOO_HIGH);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> 宠物级别过高 petlevel = %d, humanlevel = %d", nPetLevel, nHumanLevel) ;
						return PACKET_EXE_CONTINUE;
					}
					if(ExchPetGuid == DestPetGuid)
					{
						pDestHuman->ReCallPet();
					}
				}
			}

			//3.移动物品循环
			g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始移动循环",	pHuman->GetName(), pDestHuman->GetName()) ;
			GCExchangeSuccessIII MsgSuccessToMe, MsgSuccessToOt;
			GCExchangeSuccessIII::_SUCC_ITEM ItemListToMe[EXCHANGE_BOX_SIZE+EXCHANGE_PET_BOX_SIZE];
			INT	MyItemNum = 0;
			GCExchangeSuccessIII::_SUCC_ITEM ItemListToOt[EXCHANGE_BOX_SIZE+EXCHANGE_PET_BOX_SIZE];
			INT	OtItemNum = 0;
			BOOL	bFlag = FALSE;

			//用来记录可以交换的物品
			struct ExItem_t
			{
				UCHAR	uItemType;
				INT		nIndex;
				INT		nIndexInEx;
				ExItem_t()
				{
					uItemType	= 0;
					nIndex		= -1;
					nIndexInEx	= -1;
				}
			};

			INT				ExItemNumOt = 0;
			ExItem_t		ExItemIndexInOt[EXCHANGE_BOX_SIZE];
			INT				ExItemNumMy = 0;
			ExItem_t		ExItemIndexInMy[EXCHANGE_BOX_SIZE];
			INT				ExPetItemNumOt = 0;
			ExItem_t		ExPetItemIndexInOt[EXCHANGE_PET_BOX_SIZE];
			INT				ExPetItemNumMy = 0;
			ExItem_t		ExPetItemIndexInMy[EXCHANGE_PET_BOX_SIZE];

			for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
			{
				if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					Item* pItemRef = pMyExchangeContainer->GetItem(i);
					ItemContainer*	pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex());
					ExItemIndexInMy[ExItemNumMy].uItemType	= pItemRef->GetItemClass();
					ExItemIndexInMy[ExItemNumMy].nIndex		= pMyBagContainer->GetIndexByGUID(&pItemRef->GetGUID());
					ExItemIndexInMy[ExItemNumMy].nIndexInEx	= i;
					ExItemNumMy++;
				}

				if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					Item* pItemRef = pOtExchangeContainer->GetItem(i);
					ItemContainer*	pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex());
					ExItemIndexInOt[ExItemNumOt].uItemType	= pItemRef->GetItemClass();
					ExItemIndexInOt[ExItemNumOt].nIndex		= pOtBagContainer->GetIndexByGUID(&pItemRef->GetGUID());
					ExItemIndexInOt[ExItemNumOt].nIndexInEx	= i;
					ExItemNumOt++;
				}
			}

			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					Item* pItemRef = pMyExchangePetContainer->GetItem(i);
					ItemContainer*	pMyPetContainer = pHuman->GetPetContain();
					ExPetItemIndexInMy[ExPetItemNumMy].nIndex = pMyPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID());
					ExPetItemIndexInMy[ExPetItemNumMy].nIndexInEx = i;
					ExPetItemNumMy++;
				}

				if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					Item* pItemRef = pOtExchangePetContainer->GetItem(i);
					ItemContainer*	pOtPetContainer = pDestHuman->GetPetContain();
					ExPetItemIndexInOt[ExPetItemNumOt].nIndex		= pOtPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID());
					ExPetItemIndexInOt[ExPetItemNumOt].nIndexInEx = i;
					ExPetItemNumOt++;
				}
			}

			//3.1先把能交换的交换掉,如果在对方的包中找到了正在跟自己交易的物品,直接交换这两个物品的位置
			for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
			{
				if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT result = 0;
					Item* pItemRef = pMyExchangeContainer->GetItem(i);

					//自己的容器
					ItemContainer*	pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex());
					INT	BagIndex = pMyBagContainer->GetIndexByGUID(&pItemRef->GetGUID());

					//对方的容器
					ItemContainer*	pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex());

					//去换能换得
					for(INT j = 0; j<ExItemNumOt; j++)
					{

						//此位置已经无效
						if(ExItemIndexInOt[j].nIndex == -1)
							continue;

						//只有同一类型的物品才能够交换
						if(pItemRef->GetItemClass()!=ExItemIndexInOt[j].uItemType)
							continue;

						//解锁自己
						g_ItemOperator.UnlockItem( pMyBagContainer, BagIndex );

						//先解锁对方
						g_ItemOperator.UnlockItem( pOtBagContainer, ExItemIndexInOt[j].nIndex );

						//设置自己物品已经不是交易物品了
						pMyBagContainer->GetItem(BagIndex)->SetInExchange(FALSE);

						//设置对方物品已经不是交易物品了
						pOtBagContainer->GetItem(ExItemIndexInOt[j].nIndex)->SetInExchange(FALSE);

						//与一个对方欲交易的物品交换
						result = 
							g_ItemOperator.ExchangeItem
							(
							pMyBagContainer,
							BagIndex,
							pOtBagContainer,
							ExItemIndexInOt[j].nIndex
							);
						if(result<0)
						{//拷贝失败
							GCExchangeError Msg;
							Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
							pHuman->GetPlayer()->SendPacket(&Msg);
							pDestHuman->GetPlayer()->SendPacket(&Msg);
							pHuman->m_ExchangBox.CleanUp();
							pDestHuman->m_ExchangBox.CleanUp();
							g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] <-> [%s] 物品 [%d]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex(), result );
							return PACKET_EXE_CONTINUE;
						}
						else
						{
							ITEM_LOG_PARAM	ItemLogParam;
							ItemLogParam.OpType		=	ITEM_EXCHANGE_TOOTHER;
							ItemLogParam.CharGUID	=	pHuman->GetGUID();
							ItemLogParam.TargetGUID	=	pDestHuman->GetGUID();
							ItemLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
							ItemLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
							ItemLogParam.SceneID	=	pHuman->getScene()->SceneID();
							ItemLogParam.ItemGuid	=	pItemRef->GetGUID();
							ItemLogParam.ItemType	=	pItemRef->GetItemTableIndex();

							ItemListToOt[OtItemNum].m_FromType	= 0;
							ItemListToOt[OtItemNum].m_FromIndex = i;
							ItemListToOt[OtItemNum].m_ToType	= EXCHANGE_MSG::POS_BAG;
							ItemListToOt[OtItemNum++].m_ToIndex	= pOtBagContainer->ConIndex2BagIndex(ExItemIndexInOt[j].nIndex);

							ItemListToMe[MyItemNum].m_FromType	= 0;
							ItemListToMe[MyItemNum].m_FromIndex = ExItemIndexInOt[j].nIndexInEx;
							ItemListToMe[MyItemNum].m_ToType	= EXCHANGE_MSG::POS_BAG;
							ItemListToMe[MyItemNum++].m_ToIndex	= pMyBagContainer->ConIndex2BagIndex(BagIndex);

							//从交易盒中删掉此物品,在后面的移动中就不用再移动它了
							g_ItemOperator.EraseItem(pMyExchangeContainer, i);
							g_ItemOperator.EraseItem(pOtExchangeContainer, ExItemIndexInOt[j].nIndexInEx);
							ExItemIndexInOt[j].nIndex = -1;
						
							g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] <-> [%s] 物品 [%d]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex() );

							break;
						}
					}
				}
			}
	
			//3.2不能交换的一个一个放进去,剩下的直接由系统找格放入
			for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
			{
				if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT result = 0;
					Item* pItemRef = pMyExchangeContainer->GetItem(i);

					//自己的容器
					ItemContainer*	pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex());
					INT	BagIndex = pMyBagContainer->GetIndexByGUID(&pItemRef->GetGUID());

					//对方的容器
					ItemContainer*	pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex());

					//先解锁
					g_ItemOperator.UnlockItem( pMyBagContainer, BagIndex );
					pMyBagContainer->GetItem(BagIndex)->SetInExchange(FALSE);


					//自动找格,支持自动叠加
					//这里的自动找格改成可以自动叠加,这里会有一个问题,上面收取检测时是不考虑叠加状态的,所以,如果非叠加状态下的
					//可以收取一系列物品,可叠加的一定可以接受。检测的范围会大一点。
					result = 
						g_ItemOperator.MoveItem
						(
						pMyBagContainer,
						BagIndex,
						bFlag,
						pOtBagContainer
						);
					if(result<0)
					{//拷贝失败
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 物品 [%d]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex(), result );
						return PACKET_EXE_CONTINUE;
					}
					else
					{
						ITEM_LOG_PARAM	ItemLogParam;
						ItemLogParam.OpType		=	ITEM_EXCHANGE_TOOTHER;
						ItemLogParam.CharGUID	=	pHuman->GetGUID();
						ItemLogParam.TargetGUID	=	pDestHuman->GetGUID();
						ItemLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
						ItemLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
						ItemLogParam.SceneID	=	pHuman->getScene()->SceneID();
						ItemLogParam.ItemGuid	=	pItemRef->GetGUID();
						ItemLogParam.ItemType	=	pItemRef->GetItemTableIndex();

						ItemListToOt[OtItemNum].m_FromType	= 0;
						ItemListToOt[OtItemNum].m_FromIndex = i;
						ItemListToOt[OtItemNum].m_ToType	= EXCHANGE_MSG::POS_BAG;
						ItemListToOt[OtItemNum++].m_ToIndex	= pOtBagContainer->ConIndex2BagIndex(result);
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 物品 [%d]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex() );
					}
				}
				if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT result = 0;
					Item* pItemRef = pOtExchangeContainer->GetItem(i);

					//对方的容器
					ItemContainer*	pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex());
					INT	BagIndex = pOtBagContainer->GetIndexByGUID(&pItemRef->GetGUID());

					//自己的容器
					ItemContainer*	pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex());

					//先解锁
					g_ItemOperator.UnlockItem( pOtBagContainer, BagIndex );

					pOtBagContainer->GetItem(BagIndex)->SetInExchange(FALSE);

					
					//自动找格,支持自动叠加
					result = 
						g_ItemOperator.MoveItem
						(
						pOtBagContainer,
						BagIndex,
						bFlag,
						pMyBagContainer
						);
					if(result<0)
					{//拷贝失败
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 物品 [%d]失败 result = %d", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetItemTableIndex(), result );
						return PACKET_EXE_CONTINUE;
					}
					else
					{
						ITEM_LOG_PARAM	ItemLogParam;
						ItemLogParam.OpType		=	ITEM_EXCHANGE_TOOTHER;
						ItemLogParam.CharGUID	=	pDestHuman->GetGUID();
						ItemLogParam.TargetGUID	=	pHuman->GetGUID();
						ItemLogParam.XPos		=	pDestHuman->getWorldPos()->m_fX;
						ItemLogParam.ZPos		=	pDestHuman->getWorldPos()->m_fZ;
						ItemLogParam.SceneID	=	pDestHuman->getScene()->SceneID();
						ItemLogParam.ItemGuid	=	pItemRef->GetGUID();
						ItemLogParam.ItemType	=	pItemRef->GetItemTableIndex();

						SaveItemLog(&ItemLogParam);
						ItemListToMe[MyItemNum].m_FromType	= 0;
						ItemListToMe[MyItemNum].m_FromIndex = i;
						ItemListToMe[MyItemNum].m_ToType	= EXCHANGE_MSG::POS_BAG;
						ItemListToMe[MyItemNum++].m_ToIndex	= pMyBagContainer->ConIndex2BagIndex(result);
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 物品 [%d]成功", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetItemTableIndex() );
					}
				}
			}

            //3.3换宠物
			g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始交换宠物",	pHuman->GetName(), pDestHuman->GetName()) ;

			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				INT result = 0;
				Item* pItemRef = pMyExchangePetContainer->GetItem(i);

				if(pItemRef->IsEmpty())
					continue;

				PET_LOG_PARAM	PetLogParam;
				PetLogParam.PetGUID		=	pItemRef->GetPetGUID();
				PetLogParam.DataID		=	pItemRef->GetDataID();
				//自己的容器
				ItemContainer*	pMyPetContainer = pHuman->GetPetContain();
				INT	PetIndexInBag = pMyPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID());

				//对方的容器
				ItemContainer*	pOtPetContainer = pDestHuman->GetPetContain();

				//去换能换得
				for(INT j = 0; j<ExPetItemNumOt; j++)
				{
					//如果无效
					if(ExPetItemIndexInOt[j].nIndex == -1)
						continue;

					//解锁自己
					g_ItemOperator.UnlockItem( pMyPetContainer, PetIndexInBag );

					//先解锁对方
					g_ItemOperator.UnlockItem( pOtPetContainer, ExPetItemIndexInOt[j].nIndex );

					//设置自己物品已经不是交易物品了
					pMyPetContainer->GetItem(PetIndexInBag)->SetInExchange(FALSE);

					//设置对方物品已经不是交易物品了
					pOtPetContainer->GetItem(ExPetItemIndexInOt[j].nIndex )->SetInExchange(FALSE);

					//与一个对方欲交易的物品交换
					result = 
						g_ItemOperator.ExchangeItem
						(
						pMyPetContainer,
						PetIndexInBag,
						pOtPetContainer,
						ExPetItemIndexInOt[j].nIndex
						);
					if(result<0)
					{//拷贝失败
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] <-> [%s] 物品 [%d]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex(), result );
						return PACKET_EXE_CONTINUE;
					}
					else
					{
						PetLogParam.CharGUID	=	pDestHuman->GetGUID();
						PetLogParam.OPType		=	PET_OP_EXCHANGE_OTHER;
						PetLogParam.SceneID		=	pDestHuman->getScene()->SceneID();
						PetLogParam.TargetGUID	=	pHuman->GetGUID();
						PetLogParam.XPos		=	pDestHuman->getWorldPos()->m_fX;
						PetLogParam.ZPos		=	pDestHuman->getWorldPos()->m_fZ;
						SavePetLog(&PetLogParam);

						ItemListToMe[MyItemNum].m_FromType	= EXCHANGE_MSG::POS_PET;
						ItemListToMe[MyItemNum].m_FromIndex = ExPetItemIndexInOt[j].nIndexInEx;
						ItemListToMe[MyItemNum].m_ToType	= EXCHANGE_MSG::POS_PET;
						ItemListToMe[MyItemNum++].m_ToIndex	= PetIndexInBag;

						ItemListToOt[OtItemNum].m_FromType	= EXCHANGE_MSG::POS_PET;
						ItemListToOt[OtItemNum].m_FromIndex = i;
						ItemListToOt[OtItemNum].m_ToType	= EXCHANGE_MSG::POS_PET;
						ItemListToOt[OtItemNum++].m_ToIndex	= ExPetItemIndexInOt[j].nIndex;
					
						//从交易盒中删掉此物品,在后面的移动中就不用再移动它了
						g_ItemOperator.EraseItem(pMyExchangePetContainer, i);
						g_ItemOperator.EraseItem(pOtExchangePetContainer, ExPetItemIndexInOt[j].nIndexInEx);

						ExPetItemIndexInOt[j].nIndex = -1;

						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] <-> [%s] 物品 [%s]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetName() );

						break;
					}
				}
			}

			//3.4移宠物
			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT result = 0;
					Item* pItemRef = pMyExchangePetContainer->GetItem(i);
					
					PET_LOG_PARAM	PetLogParam;
					PetLogParam.PetGUID		=	pItemRef->GetPetGUID();
					PetLogParam.DataID		=	pItemRef->GetDataID();
					//自己的容器
					ItemContainer*	pMyPetContainer = pHuman->GetPetContain();
					INT	PetIndexInBag = pMyPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID());

					//对方的容器
					ItemContainer*	pOtPetContainer = pDestHuman->GetPetContain();

					//先解锁
					g_ItemOperator.UnlockItem( pMyPetContainer, PetIndexInBag );

					pMyPetContainer->GetItem(PetIndexInBag)->SetInExchange(FALSE);

					//自动找格,支持自动叠加
					//这里的自动找格改成可以自动叠加,这里会有一个问题,上面收取检测时是不考虑叠加状态的,所以,如果非叠加状态下的
					//可以收取一系列物品,可叠加的一定可以接受。检测的范围会大一点。
					result = 
						g_ItemOperator.MoveItem
						(
						pMyPetContainer,
						PetIndexInBag,
						pOtPetContainer
						);
					if(result<0)
					{//拷贝失败
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 宠物 [%s]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetName(), result );
						return PACKET_EXE_CONTINUE;
					}
					else
					{
						PetLogParam.CharGUID	=	pDestHuman->GetGUID();
						PetLogParam.OPType		=	PET_OP_EXCHANGE_OTHER;
						PetLogParam.SceneID		=	pDestHuman->getScene()->SceneID();
						PetLogParam.TargetGUID	=	pHuman->GetGUID();
						PetLogParam.XPos		=	pDestHuman->getWorldPos()->m_fX;
						PetLogParam.ZPos		=	pDestHuman->getWorldPos()->m_fZ;
						SavePetLog(&PetLogParam);

						ItemListToOt[OtItemNum].m_FromType	= EXCHANGE_MSG::POS_PET;
						ItemListToOt[OtItemNum].m_FromIndex = i;
						ItemListToOt[OtItemNum].m_ToType	= EXCHANGE_MSG::POS_PET;
						ItemListToOt[OtItemNum++].m_ToIndex	= result;
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 宠物 [%s]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetName() );
					}
				}

				if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					INT result = 0;
					Item* pItemRef = pOtExchangePetContainer->GetItem(i);
					PET_LOG_PARAM	PetLogParam;
					PetLogParam.PetGUID		=	pItemRef->GetPetGUID();
					PetLogParam.DataID		=	pItemRef->GetDataID();

					//对方的容器
					ItemContainer*	pOtPetContainer = pDestHuman->GetPetContain();
					INT	PetIndexInBag = pOtPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID());

					//自己的容器
					ItemContainer*	pMyPetContainer = pHuman->GetPetContain();

					//先解锁
					g_ItemOperator.UnlockItem( pOtPetContainer, PetIndexInBag );
					pOtPetContainer->GetItem(PetIndexInBag)->SetInExchange(FALSE);

					//自动找格,支持自动叠加
					result = 
						g_ItemOperator.MoveItem
						(
						pOtPetContainer,
						PetIndexInBag,
						pMyPetContainer
						);
					if(result<0)
					{//拷贝失败
						GCExchangeError Msg;
						Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
						pHuman->GetPlayer()->SendPacket(&Msg);
						pDestHuman->GetPlayer()->SendPacket(&Msg);
						pHuman->m_ExchangBox.CleanUp();
						pDestHuman->m_ExchangBox.CleanUp();
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 宠物 [%s]失败 result = %d", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetName(), result );
						return PACKET_EXE_CONTINUE;
					}
					else
					{
						PetLogParam.CharGUID	=	pHuman->GetGUID();
						PetLogParam.OPType		=	PET_OP_EXCHANGE_OTHER;
						PetLogParam.SceneID		=	pHuman->getScene()->SceneID();
						PetLogParam.TargetGUID	=	pDestHuman->GetGUID();
						PetLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
						PetLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
						SavePetLog(&PetLogParam);
						ItemListToMe[MyItemNum].m_FromType	= EXCHANGE_MSG::POS_PET;
						ItemListToMe[MyItemNum].m_FromIndex = i;
						ItemListToMe[MyItemNum].m_ToType	= EXCHANGE_MSG::POS_PET;
						ItemListToMe[MyItemNum++].m_ToIndex	= result;
						g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 宠物 [%s]成功", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetName() );
					}
				}
			}
			

			//2.换钱
			g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始交换金钱",	pHuman->GetName(), pDestHuman->GetName()) ;
			if( pHuman->m_ExchangBox.m_Money <= pHuman->GetMoney() && pHuman->m_ExchangBox.m_Money>0 )
			{
				pDestHuman->SetMoney(pDestHuman->GetMoney()+pHuman->m_ExchangBox.m_Money);
				pHuman->SetMoney(pHuman->GetMoney()-pHuman->m_ExchangBox.m_Money);

				MONEY_LOG_PARAM	MoneyLogParam;
				MoneyLogParam.CharGUID	=	pHuman->GetGUID();
				MoneyLogParam.TargetGUID	=	pDestHuman->GetGUID();
				MoneyLogParam.OPType	=	MONEY_EXCHANGE_OUTCOME;	
				MoneyLogParam.Count		=	pHuman->m_ExchangBox.m_Money;
				MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
				MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
				MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
				SaveMoneyLog(&MoneyLogParam);

				MoneyLogParam.CharGUID	=	pDestHuman->GetGUID();
				MoneyLogParam.TargetGUID	=	pHuman->GetGUID();
				MoneyLogParam.OPType	=	MONEY_EXCHANGE_INCOME;	
				MoneyLogParam.Count		=	pHuman->m_ExchangBox.m_Money;
				MoneyLogParam.SceneID	=	pDestHuman->getScene()->SceneID();
				MoneyLogParam.XPos		=	pDestHuman->getWorldPos()->m_fX;
				MoneyLogParam.ZPos		=	pDestHuman->getWorldPos()->m_fZ;
				SaveMoneyLog(&MoneyLogParam);


				g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 金钱 [%d]", pHuman->GetName(), pDestHuman->GetName(), pHuman->m_ExchangBox.m_Money );
			}

			if( pDestHuman->m_ExchangBox.m_Money <= pDestHuman->GetMoney() && pDestHuman->m_ExchangBox.m_Money>0 )
			{
				pHuman->SetMoney(pHuman->GetMoney()+pDestHuman->m_ExchangBox.m_Money);
				pDestHuman->SetMoney(pDestHuman->GetMoney() - pDestHuman->m_ExchangBox.m_Money);

				MONEY_LOG_PARAM	MoneyLogParam;
				MoneyLogParam.CharGUID	=	pHuman->GetGUID();
				MoneyLogParam.TargetGUID	=	pDestHuman->GetGUID();
				MoneyLogParam.OPType	=	MONEY_EXCHANGE_INCOME;	
				MoneyLogParam.Count		=	pDestHuman->m_ExchangBox.m_Money;
				MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
				MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
				MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
				SaveMoneyLog(&MoneyLogParam);

				MoneyLogParam.CharGUID	=	pDestHuman->GetGUID();
				MoneyLogParam.TargetGUID	=	pHuman->GetGUID();
				MoneyLogParam.OPType	=	MONEY_EXCHANGE_OUTCOME;	
				MoneyLogParam.Count		=	pDestHuman->m_ExchangBox.m_Money;
				MoneyLogParam.SceneID	=	pDestHuman->getScene()->SceneID();
				MoneyLogParam.XPos		=	pDestHuman->getWorldPos()->m_fX;
				MoneyLogParam.ZPos		=	pDestHuman->getWorldPos()->m_fZ;
				SaveMoneyLog(&MoneyLogParam);


				g_pLog->FastSaveLog( LOG_FILE_1, "		<交易> [%s] -> [%s] 金钱 [%d]", pDestHuman->GetName(), pHuman->GetName(), pDestHuman->m_ExchangBox.m_Money );
			}


			//给双方发送成功消息
			MsgSuccessToMe.SetItemNum(MyItemNum);
			MsgSuccessToMe.SetItemList(ItemListToMe);
			pHuman->GetPlayer()->SendPacket(&MsgSuccessToMe);

			MsgSuccessToOt.SetItemNum(OtItemNum);
			MsgSuccessToOt.SetItemList(ItemListToOt);
			pDestHuman->GetPlayer()->SendPacket(&MsgSuccessToOt);

			g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 交易成功",	pHuman->GetName(), pDestHuman->GetName()) ;

			//能走到这儿证明所有操作都已完成清空各自的交易盒
			pHuman->m_ExchangBox.CleanUp();
			pDestHuman->m_ExchangBox.CleanUp();

		}
		else
		{//啥也不做,等待对方消息

		}
	}
	else
	{//一定出错了
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
		pHuman->GetPlayer()->SendPacket(&Msg);
		pHuman->m_ExchangBox.CleanUp();
		pDestHuman->GetPlayer()->SendPacket(&Msg);
		pDestHuman->m_ExchangBox.CleanUp();
		return PACKET_EXE_CONTINUE;
	}

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Beispiel #4
0
uint CGManipulateMountHandler::Execute(CGManipulateMount* 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, "CGManipulateMountHandler: change scene") ;
		return PACKET_EXE_CONTINUE;
	}
	//交易状态不可操作
	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 ;
	}

	Assert( NULL != pPacket ) ;

	BYTE bagIndex = pPacket->getBagIndex();
	BYTE mountIndex = pPacket->getMountIndex();
	INT  mountID = pPacket->getMountID();

	ItemContainer* pMountContainer = HumanItemLogic::GetMountContainer(pHuman);

	if (pMountContainer == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGManipulateMountHandler BagIndex is invalid, BagIndex = %d", mountIndex) ;

		return PACKET_EXE_ERROR;
	}

    GCManipulateMountResult Msg;

	switch(pPacket->getMountOperator())
	{
		case CGManipulateMount::MANIPULATE_EQUIP_MOUNT:
			{
				ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, bagIndex);
				_ITEM* pSourceItem = pBagContainer->GetItem(bagIndex)->GetItemData();
				INT result = g_ItemOperator.MoveItem(pBagContainer, bagIndex, pMountContainer);

				if (ITEMOE_SUCCESS <= result)
				{
					MOUNT_INFO* mountInfo = pSourceItem->GetMountData();
                    INT elapseMinute = g_pTimeManager->DiffDWORDTime(g_pTimeManager->GetANSITime(), mountInfo->m_nObtainDate);
					const INT MINUTE_IN_ONE_DAY = 1488;

					mountInfo->m_nObtainDate = (UINT)g_pTimeManager->GetANSITime();
					mountInfo->m_nRemainTime = mountInfo->m_nLife * MINUTE_IN_ONE_DAY - elapseMinute;

					if(CGManipulateMount::EQUIP_BIND == (CGManipulateMount::MOUNT_BIND_TYPE) mountInfo->m_nBindType)
					    mountInfo->m_bIsBinded = TRUE;

					Msg.setResult(TRUE);
					Msg.setMountObtainDate(mountInfo->m_nObtainDate);
					Msg.setMountIsBinded(mountInfo->m_bIsBinded);
					Msg.setMountRemainTime(mountInfo->m_nRemainTime);
					Msg.setMountGUID(pSourceItem->m_ItemGUID);
				}
				else
				{
                    Msg.setResult(FALSE);  
				}

                Msg.setBagIndex(bagIndex);
				Msg.setMountIndex(result);
				Msg.setMountOperator(GCManipulateMountResult::MANIPULATE_EQUIP_MOUNT);
				pGamePlayer->SendPacket( &Msg ) ;
			}
			break;

		case CGManipulateMount::MANIPULATE_CALL_MOUNT:
			{
				INT addtionSpeed = pHuman->GetDB()->GetMountDB()->m_pItem[mountIndex].GetMountData()->m_nAddtionSpeed;
				pHuman->GetDB()->SetMountID(mountID);
				pHuman->GetDB()->SetMountIndex(mountIndex);
                pHuman->SetBaseMoveSpeed(pHuman->GetBaseMoveSpeed() + addtionSpeed);

				Msg.setMountIndex(mountIndex);
				Msg.setMountOperator(GCManipulateMountResult::MANIPULATE_CALL_MOUNT);
				Msg.setResult(TRUE);

				pGamePlayer->SendPacket( &Msg ) ;
			}
			break;

		case CGManipulateMount::MANIPULATE_RECALL_MOUNT:
			{
				INT addtionSpeed = pHuman->GetDB()->GetMountDB()->m_pItem[mountIndex].GetMountData()->m_nAddtionSpeed;
				pHuman->GetDB()->SetMountID(INVALID_ID);
				pHuman->GetDB()->SetMountIndex(INVALID_INDEX);
                pHuman->SetBaseMoveSpeed(pHuman->GetBaseMoveSpeed() - addtionSpeed);

				Msg.setMountIndex(mountIndex);
				Msg.setMountOperator(GCManipulateMountResult::MANIPULATE_RECALL_MOUNT);
				Msg.setResult(TRUE);

				pGamePlayer->SendPacket( &Msg ) ;
			}
			break;

		case CGManipulateMount::MANIPULATE_DISCARD_MOUNT:
			{
				pHuman->GetDB()->EraseMountItem(mountIndex);

				Msg.setMountIndex(mountIndex);
				Msg.setMountOperator(GCManipulateMountResult::MANIPULATE_DISCARD_MOUNT);
				Msg.setResult(TRUE);

				pGamePlayer->SendPacket( &Msg ) ;
			}
			break;

		case CGManipulateMount::MANIPULATE_DESTROY_MOUNT:
			{
				if (INVALID_ID != pHuman->GetDB()->GetMountID())
				{
					INT addtionSpeed = pHuman->GetDB()->GetMountDB()->m_pItem[mountIndex].GetMountData()->m_nAddtionSpeed;
					pHuman->GetDB()->SetMountID(INVALID_ID);
					pHuman->GetDB()->SetMountIndex(INVALID_INDEX);
					pHuman->SetBaseMoveSpeed(pHuman->GetBaseMoveSpeed() - addtionSpeed);
				}

				pHuman->GetDB()->EraseMountItem(mountIndex);

				Msg.setMountIndex(mountIndex);
				Msg.setMountOperator(GCManipulateMountResult::MANIPULATE_DESTROY_MOUNT);
				Msg.setResult(TRUE);

				pGamePlayer->SendPacket( &Msg ) ;
			}
			break;

		default:break;
	}

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Beispiel #5
0
uint CGStallOpenHandler::Execute( CGStallOpen* 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 ) ;
	ObjID_t ObjId = pPacket->GetObjID();


	//临时数组
	GCStallOpen::_STALL_ITEM	StallItem[STALL_BOX_SIZE+STALL_PET_BOX_SIZE];

	if(ObjId == pHuman->GetID())
	{//自己打开自己,肯定打开
		//摊主container
		if(pHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
		{
			GCStallError	Msg;
			Msg.SetID(STALL_MSG::ERR_ILLEGAL);
			pGamePlayer->SendPacket(&Msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallOpenHandler::ObjID=%d, ERR_ILLEGAL: != ServerStallBox::STALL_OPEN"
				,pHuman->GetID()) ;
			return PACKET_EXE_CONTINUE;
		}

		ItemContainer*	pStallContainer		= pHuman->m_StallBox.GetContainer(); 
		ItemContainer*	pStallPetContainer	= pHuman->m_StallBox.GetPetContainer(); 
		
		//循环写入
		UINT	k = 0;	
		for(INT i = 0; i<pStallContainer->GetContainerSize(); i++)
		{
			if( pHuman->m_StallBox.GetSerialByIndex(i) != 0 )
			{//这个格子里的东西更改过,需要通知客户端它的序列号
				StallItem[k].nIndex		= i;
				StallItem[k].nPrice		= pHuman->m_StallBox.GetPriceByIndex(i);
				StallItem[k].nSerial	= pHuman->m_StallBox.GetSerialByIndex(i);
				if(pStallContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					pStallContainer->GetItem(i)->SaveValueTo(&(StallItem[k].item));
				}
				k++;
			}
		}

		for(INT i = 0; i<pStallPetContainer->GetContainerSize(); i++)
		{
			if( pHuman->m_StallBox.GetPetSerialByIndex(i) != 0 )
			{//有东西
				StallItem[k].bIsPet		=	TRUE;
				StallItem[k].nIndex		=	i;
				StallItem[k].nPrice		=	pHuman->m_StallBox.GetPetPriceByIndex(i);
				StallItem[k].nSerial	=	pHuman->m_StallBox.GetPetSerialByIndex(i);
				if(pStallPetContainer->GetItem(i)->IsEmpty() == FALSE)
				{
					StallItem[k].PetGuid	=	pStallPetContainer->GetItem(i)->GetPetGUID();
				}
				k++;
			}
		}

		pHuman->StallNameChanged();

		//消息填充
		GCStallOpen Msg;
		Msg.SetFirstPage( pHuman->m_StallBox.GetFirstPage());
		Msg.SetMerchadiseNum(k);
		Msg.SetMerchadiseList(StallItem);
		Msg.SetShopName(pHuman->m_StallBox.GetStallName(), (UINT)strlen(pHuman->m_StallBox.GetStallName()));
		Msg.SetObjID(ObjId);
		Msg.SetGUID(pHuman->GetGUID());

		//发还本人Q
		pGamePlayer->SendPacket(&Msg);

	}
	else
	{//别人
		//判断距离是否可以打开
		Obj_Human* pTargetHuman = pScene->GetHumanManager()->GetHuman( ObjId );
		if( pTargetHuman == NULL )
		{
			GCStallError Msg;
			Msg.SetID(STALL_MSG::ERR_OWNER_INVALID);
			pHuman->GetPlayer()->SendPacket(&Msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallOpenHandler::ObjName=%s, ERR_OWNER_INVALID: ObjId = %d"
				,pHuman->GetName(), ObjId) ;
			return PACKET_EXE_CONTINUE;
		}
		
		if(pTargetHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
		{
			GCStallError	Msg;
			Msg.SetID(STALL_MSG::ERR_CLOSE);
			pGamePlayer->SendPacket(&Msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallOpenHandler::ObjName=%s, ERR_CLOSE"
				,pHuman->GetName()) ;
			return PACKET_EXE_CONTINUE;
		}

		//摊主container
		ItemContainer*	pStallContainer = pTargetHuman->m_StallBox.GetContainer(); 

		//循环写入
		UINT	k = 0;	
		for(INT i = 0; i<pStallContainer->GetContainerSize(); i++)
		{
			if( pStallContainer->GetItem(i)->IsEmpty() == FALSE )
			{//有东西
				StallItem[k].nIndex		= i;
				StallItem[k].nPrice		= pTargetHuman->m_StallBox.GetPriceByIndex(i);
				StallItem[k].nSerial	= pTargetHuman->m_StallBox.GetSerialByIndex(i);
				pStallContainer->GetItem(i)->SaveValueTo(&(StallItem[k].item));
				k++;
			}
		}

		//消息填充
		GCStallOpen Msg;
		Msg.SetFirstPage( pTargetHuman->m_StallBox.GetFirstPage());
		Msg.SetMerchadiseNum(k);
		Msg.SetMerchadiseList(StallItem);
		Msg.SetShopName(pTargetHuman->m_StallBox.GetStallName(), MAX_STALL_NAME);
		Msg.SetObjID(ObjId);
		Msg.SetGUID(pTargetHuman->GetGUID());

		//发还本人
		pGamePlayer->SendPacket(&Msg);

		//宠物列表
		ItemContainer*	pStallPetContainer = pTargetHuman->m_StallBox.GetPetContainer(); 

		//循环写入
		for(INT i = 0; i<pStallPetContainer->GetContainerSize(); i++)
		{
			if( pStallPetContainer->GetItem(i)->IsEmpty() == FALSE )
			{//有东西
				INT	nPrice	= pTargetHuman->m_StallBox.GetPetPriceByIndex(i);
				INT	nSerial	= pTargetHuman->m_StallBox.GetPetSerialByIndex(i);

				Item* pIt = pStallPetContainer->GetItem(i);
				GCDetailAttrib_Pet PetMsgDetail;

				//组装GCDetailAttrib_Pet结构
				Obj_Human::CalculatePetDetailAttrib(PetMsgDetail, pIt);
				PetMsgDetail.SetTradeIndex( i );
				
				PET_EXTRA_STRUCT::GCStallPetView_t	ExtraPetInfo;
				ExtraPetInfo.m_bFlag	= TYPE_STALL;
				ExtraPetInfo.m_nPrice	= nPrice;
				ExtraPetInfo.m_nSerial	= nSerial;

				PetMsgDetail.SetExtraInfoLength(ExtraPetInfo.GetSize());
				PetMsgDetail.SetExtraInfoData((BYTE*)&ExtraPetInfo);
				pGamePlayer->SendPacket( &PetMsgDetail );		
			}
		}
	}
	g_pLog->FastSaveLog( LOG_FILE_1, "CGStallOpenHandler::ObjID=%d"
		,pHuman->GetID()) ;
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
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;

	_ITEM_ATTR tmpItemAttr[MAX_ITEM_ATTR];
	for (BYTE index=0; index<pEquipment->GetAttrCount(); ++index)
	{
		tmpItemAttr[index] = pEquipment->GetEquipAttr(index);
		if (tmpItemAttr[index].m_AttrType > 0)
		{
			attrCount++;
		}
	}
	Assert(attrCount == pEquipment->GetAttrCount());
	//开始删除装备和扣除金钱
	BOOL bRet = FALSE;
	ITEM_LOG_PARAM		ItemLogParam;
	ItemLogParam.OpType	= ITEM_EQUIP_REFINING;

	bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iEquipItemPos));
	if(bRet)
	{
		SaveItemLog(&ItemLogParam);
	}
	else
	{
		msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}
	//删除炼化道具
	bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningItemPos));
	if(bRet)
	{
		SaveItemLog(&ItemLogParam);
	}
	else
	{
		msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	UINT iSoulBeadBagIndex = 0;
	Item*	pSoulBeadItem = NULL;
	//武魂珠
	if (HEQUIP_MAINHAND == curEquipPoint)
	{
		bRet = HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,ITEM_WU_SOUL_BEAD, iSoulBeadBagIndex);
		if(bRet)
		{
			SaveItemLog(&ItemLogParam);
		} 
		else 
		{
			msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			return PACKET_EXE_CONTINUE;
		}
		
		pSoulBeadItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iSoulBeadBagIndex));
		Assert(NULL != pSoulBeadItem);
		Assert(ICLASS_SOUL_BEAD == pSoulBeadItem->GetItemClass());	
		
		pSoulBeadItem->SetSoulBeadPrice(iPrice);//由基本价格计算得出
		pSoulBeadItem->SetSoulBeadNeedLevel(iRequireLevel);
		pSoulBeadItem->SetWuSoulBeadAttr(attrCount, tmpItemAttr);
		
	}//器魂珠
	else if (EQUIP_CAP == pEquipment->GetItemType()//EQUIP_PIFENG == pEquipment->GetEquipPoint() || 
			|| EQUIP_SHOULDER == pEquipment->GetItemType() || EQUIP_HAND == pEquipment->GetItemType()
			|| EQUIP_ARMOR == pEquipment->GetItemType() || EQUIP_BOOT == pEquipment->GetItemType())
	{
		bRet = HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,ITEM_WU_SOUL_BEAD, iSoulBeadBagIndex);
		if(bRet)
		{
			SaveItemLog(&ItemLogParam);
		} 
		else 
		{
			msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			return PACKET_EXE_CONTINUE;
		}
		pSoulBeadItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iSoulBeadBagIndex));
		Assert(NULL != pSoulBeadItem);
		Assert(ICLASS_SOUL_BEAD == pSoulBeadItem->GetItemClass());	
		
		pSoulBeadItem->SetSoulBeadPrice(iPrice);//由基本价格计算得出
		pSoulBeadItem->SetSoulBeadNeedLevel(iRequireLevel);
		pSoulBeadItem->SetQiSoulBeadAttr(attrCount, tmpItemAttr);
	}
	// 通知增加道具到背包
	GCNotifyEquip ItemMsg;
	Assert(pSoulBeadItem);
	ItemMsg.SetBagIndex(iSoulBeadBagIndex);
	pSoulBeadItem->SaveValueTo(ItemMsg.GetItem());
	pGamePlayer->SendPacket(&ItemMsg);
	
	msg.SetResult(EQUIPREFINING_SUCCESS);
	//pGamePlayer->SendPacket(&msg);
	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return	PACKET_EXE_ERROR;
}
uint CGEquipExChangePaiTypeHandler::Execute(CGEquipExChangePaiType* 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 ;
	}

	//摆摊不可操作
	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 ;
	}

	ObjID_t		NpcObjID=	pPacket->GetUniqueID();
	Obj* pNpcObj = pScene->GetObjManager()->GetObj(NpcObjID);
	if (pNpcObj == NULL)
	{
		return PACKET_EXE_ERROR;
	}
	else
	{
		if( pNpcObj->GetObjType() != Obj::OBJ_TYPE_MONSTER )
		{
			return PACKET_EXE_ERROR;
		}
	}

	FLOAT fDist = MySqrt(pNpcObj->getWorldPos(), pHuman->getWorldPos());

	if(fDist>MAX_NPC_DISTANCE)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Out Of Range ObjName = %s", pHuman->GetName()) ;
		return PACKET_EXE_CONTINUE ; 
	}


	EQUIPEXCHANGEPAITTYPE_RESULT	Result = EQUIPEXCHANGEPAITTYPE_FAIL;
	GCEquipExChangePaiTypeResult  ResultPacket;

	Item*		pEquip1Item		= NULL;
	Item*		pEquip2Item		= NULL;
	INT			Equip1Point		= INVALID_ITEM_POS;
	INT			Equip2Point		= INVALID_ITEM_POS;
	if(pPacket->GetEquip1PosType()>=INVALID_ITEM_POS_TYPE)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip posType error, posType=%d", pPacket->GetEquip1PosType()) ;
		return PACKET_EXE_ERROR;
	}

	if(pPacket->GetEquip1PosType() == ENUM_BAG)
	{
		ItemContainer* pItemContainer1 = HumanItemLogic::GetBagContainer(pHuman,pPacket->GetPos1());
		if( pItemContainer1 == NULL )
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler: BagIndex error, BagIndex=%d", pPacket->GetPos1()) ;
			return PACKET_EXE_ERROR;
		}
		if (!pItemContainer1->IsCanUse())
		{
			Result = EQUIPEXCHANGEPAITTYPE_BAG_INVALID;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);;
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d", 
				pItemContainer1->GetContainerType(), pPacket->GetPos1()) ;
				return PACKET_EXE_ERROR;
		}

		pEquip1Item		=	pItemContainer1->GetItem(pItemContainer1->BagIndex2ConIndex(pPacket->GetPos1()));
		if(pEquip1Item->IsEmpty())
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip empyty, bagpos=%d", pPacket->GetPos1()) ;
			return PACKET_EXE_CONTINUE;
		}

		if(pEquip1Item->GetItemClass()!=ICLASS_EQUIP)
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler is not ICLASS_EQUIP") ;
			return PACKET_EXE_CONTINUE;
		}

		if (pEquip1Item->GetItemType() > EQUIP_ADORN)
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler is not ICLASS_EQUIP") ;
			return PACKET_EXE_CONTINUE;
		}
	}

	if(pPacket->GetEquip1PosType() == ENUM_EQUIP_POINT)
	{
		if(pPacket->GetPos1()>HEQUIP_ADORN2)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Item pos error") ;
			return PACKET_EXE_ERROR;
		}
		Equip1Point = pPacket->GetPos1();
		ItemContainer* pEquipContainer = pHuman->GetEquipContain();
		if(NULL==pEquipContainer)
		{
			AssertEx(FALSE,"[CGEquipExChangePaiTypeHandler]: NULL EquipContainer pointer found!");
		}
		pEquip1Item = pEquipContainer->GetItem((UINT)Equip1Point);
		Assert(pEquip1Item != NULL);
		if(pEquip1Item->IsEmpty())
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip empyty, bagpos=%d", pPacket->GetPos1()) ;
			return PACKET_EXE_CONTINUE;
		}

		Assert (pEquip1Item->GetItemClass() == ICLASS_EQUIP);
	}

	if(!(pEquip1Item->GetGUID() == pPacket->getItem1ID()))
	{
		Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
		ResultPacket.SetResult(Result);
		pGamePlayer->SendPacket(&ResultPacket);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler guid error") ;
		return PACKET_EXE_CONTINUE;
	}
	
	if(pPacket->GetEquip2PosType()>=INVALID_ITEM_POS_TYPE)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip posType error, posType=%d", pPacket->GetEquip1PosType()) ;
		return PACKET_EXE_ERROR;
	}

	if(pPacket->GetEquip2PosType() == ENUM_BAG)
	{
		ItemContainer* pItemContainer2 = HumanItemLogic::GetBagContainer(pHuman,pPacket->GetPos2());
		if( pItemContainer2 == NULL )
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipDecompoundHandler: BagIndex error, BagIndex=%d", pPacket->GetPos2()) ;
			return PACKET_EXE_ERROR;
		}
		if (!pItemContainer2->IsCanUse())
		{
			Result = EQUIPEXCHANGEPAITTYPE_BAG_INVALID;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);;
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipDecompoundHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d", 
				pItemContainer2->GetContainerType(), pPacket->GetPos2()) ;
				return PACKET_EXE_ERROR;
		}

		pEquip2Item		=	pItemContainer2->GetItem(pItemContainer2->BagIndex2ConIndex(pPacket->GetPos2()));
		if(pEquip2Item->IsEmpty())
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip empyty, bagpos=%d", pPacket->GetPos2()) ;
			return PACKET_EXE_CONTINUE;
		}

		if(pEquip2Item->GetItemClass()!=ICLASS_EQUIP)
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler is not ICLASS_EQUIP") ;
			return PACKET_EXE_CONTINUE;
		}

		if (pEquip2Item->GetItemType() > EQUIP_ADORN)
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler is not ICLASS_EQUIP") ;
			return PACKET_EXE_CONTINUE;
		}
	}

	if(pPacket->GetEquip2PosType() == ENUM_EQUIP_POINT)
	{
		if(pPacket->GetPos2()>HEQUIP_ADORN2)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Item pos error") ;
			return PACKET_EXE_ERROR;
		}
		Equip2Point = pPacket->GetPos2();
		ItemContainer* pEquipContainer = pHuman->GetEquipContain();
		if(NULL==pEquipContainer)
		{
			AssertEx(FALSE,"[CGEquipExChangePaiTypeHandler]: NULL EquipContainer pointer found!");
		}
		pEquip2Item = pEquipContainer->GetItem((UINT)Equip2Point);
		Assert(pEquip2Item != NULL);
		if(pEquip2Item->IsEmpty())
		{
			Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
			ResultPacket.SetResult(Result);
			pGamePlayer->SendPacket(&ResultPacket);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip empyty, bagpos=%d", pPacket->GetPos2()) ;
			return PACKET_EXE_CONTINUE;
		}

		Assert (pEquip2Item->GetItemClass() == ICLASS_EQUIP);
	}

	if(!(pEquip2Item->GetGUID() == pPacket->getItem2ID()))
	{
		Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
		ResultPacket.SetResult(Result);
		pGamePlayer->SendPacket(&ResultPacket);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler guid error") ;
		return PACKET_EXE_CONTINUE;
	}
	
	if ((!pEquip1Item->GetItemBind())||(!pEquip2Item->GetItemBind()))
	{
		Result = EQUIPEXCHANGEPAITTYPE_EQUIPBIND_FAIL;
		ResultPacket.SetResult(Result);
		pGamePlayer->SendPacket(&ResultPacket);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler no Bind") ;
		return PACKET_EXE_CONTINUE;
	}

	Result	= (EQUIPEXCHANGEPAITTYPE_RESULT)pHuman->EquipChangePai(pEquip1Item, pEquip2Item, pPacket->getGemBagPos());
	ResultPacket.SetResult(Result);
	pGamePlayer->SendPacket(&ResultPacket);

	//如果装备在身上
	if(((pPacket->GetEquip1PosType() == ENUM_EQUIP_POINT)&&(Equip1Point != INVALID_ITEM_POS))
		||((pPacket->GetEquip2PosType() == ENUM_EQUIP_POINT)&&(Equip2Point != INVALID_ITEM_POS)))
	{
		//设置装备版本
		pHuman->SetEquipVer(pHuman->GetEquipVer()+1);

		//刷新装备对人物的属性影响
		pHuman->ItemEffectFlush();

		//更新装备
		UINT RetPart = 0;
		GCDetailEquipList	SelfMsg;
		SelfMsg.setObjID( pHuman->GetID() );
		if (pPacket->GetEquip1PosType() == ENUM_EQUIP_POINT)
		{
			pEquip1Item = HumanItemLogic::GetEquip(pHuman,(HUMAN_EQUIP)Equip1Point);
			if(!pEquip1Item)
			{
				Assert(FALSE);
				return PACKET_EXE_CONTINUE;
			}
			if(pEquip1Item->IsEmpty()) 
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler: Equip_Point =%d Fail", Equip1Point ) ;
				return PACKET_EXE_CONTINUE;
			}

			pEquip1Item->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)Equip1Point));
			RetPart|=(1<<((UINT)Equip1Point));
		}
		
		if (pPacket->GetEquip2PosType() == ENUM_EQUIP_POINT)
		{
			pEquip2Item = HumanItemLogic::GetEquip(pHuman,(HUMAN_EQUIP)Equip2Point);
			if(!pEquip2Item)
			{
				Assert(FALSE);
				return PACKET_EXE_CONTINUE;
			}
			if(pEquip2Item->IsEmpty()) 
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler: Equip_Point =%d Fail", Equip2Point ) ;
				return PACKET_EXE_CONTINUE;
			}

			pEquip2Item->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)Equip2Point));
			RetPart|=(1<<((UINT)Equip2Point));
		}
		SelfMsg.SetAskPart(RetPart);
		pGamePlayer->SendPacket( &SelfMsg ) ;

		if (pPacket->GetEquip1PosType() != ENUM_EQUIP_POINT)
		{
			GCItemInfo  EquipMsg;
			EquipMsg.setIsNull(FALSE);
			EquipMsg.setID(pPacket->GetPos1());
			pEquip1Item->SaveValueTo(EquipMsg.getItem());
			pHuman->GetPlayer()->SendPacket(&EquipMsg);
		}

		if (pPacket->GetEquip2PosType() != ENUM_EQUIP_POINT)
		{
			GCItemInfo	EquipMsg;
			EquipMsg.setIsNull(FALSE);
			EquipMsg.setID(pPacket->GetPos2());
			pEquip2Item->SaveValueTo(EquipMsg.getItem());
			pHuman->GetPlayer()->SendPacket(&EquipMsg);
		}
	}

	else	//仅仅通知背包内物品改变
	{
		GCItemInfo  EquipMsg;
		EquipMsg.setIsNull(FALSE);
		EquipMsg.setID(pPacket->GetPos1());
		pEquip1Item->SaveValueTo(EquipMsg.getItem());
		pHuman->GetPlayer()->SendPacket(&EquipMsg);

		EquipMsg.setIsNull(FALSE);
		EquipMsg.setID(pPacket->GetPos2());
		pEquip2Item->SaveValueTo(EquipMsg.getItem());
		pHuman->GetPlayer()->SendPacket(&EquipMsg);
	}
	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR;
}
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());
									pGamePlayer->SendPacket(&msg2);
								}
								g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: MoveSpliceItem" ) ;
								return PACKET_EXE_CONTINUE ;
							}
							else
							{
								//判断银行内的这个物品是不是能够放入背包中
								ItemContainer* pBankContainer = pHuman->GetBankContain();
								Item *pItem = pBankContainer->GetItem(indexTo); 

								ItemContainer *pHumanCon = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex());
								if( !pHumanCon )
								{
									//返回错误信息
									Msg.SetToType(GCBankSwapItem::ERROR_POS);
									break;
								}

								if( !pHumanCon->IsInContainer(indexFrom) )
								{
									//返回错误信息
									Msg.SetToType(GCBankSwapItem::ERROR_POS);
									break;
								}

								g_ItemOperator.ExchangeItem(pBagContainer,
									pBagContainer->BagIndex2ConIndex(indexFrom),
									pBankContainer,
									(UINT)indexTo);

								Msg.SetFromType(GCBankSwapItem::BAG_POS);
								Msg.SetToType(GCBankSwapItem::BANK_POS);
								Msg.SetIndexFrom(indexFrom);
								Msg.SetIndexTo(indexTo);
							}
						}
						else
						{
							Msg.SetFromType(GCBankSwapItem::ERROR_POS);
							Msg.SetToType(GCBankSwapItem::ERROR_POS);
						}
					}
					else
					{
						Msg.SetFromType(GCBankSwapItem::ERROR_POS);
						Msg.SetToType(GCBankSwapItem::ERROR_POS);
					}
				}
				break;
			default:
				break;
			}
		}
		break;
	case CGBankSwapItem::BANK_POS:
		{
			switch(pPacket->GetToType())
			{
			case CGBankSwapItem::BAG_POS:			// Bank->Bag
				{
					//验证位置的合法性
					if( indexTo>=0 
						&& indexTo<MAX_BAG_SIZE 
						&& indexFrom>=0 
						&& indexFrom<(UINT)(pHuman->__GetBankEndIndex()) 
						)
					{
						if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom)) 
							&& ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexTo))
							)
						{
							ItemContainer*	pBagContainer =
								HumanItemLogic::GetContainer(pHuman,indexFrom);

							ItemContainer* pBankContainer = pHuman->GetBankContain();

							//判断银行内的这个物品是不是能够放入背包中
							Item *pItem = pBankContainer->GetItem(indexFrom); 

							ItemContainer *pHumanCon = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex());
							if( !pHumanCon )
							{
								//返回错误信息
								Msg.SetToType(GCBankSwapItem::ERROR_POS);
								break;
							}

							if( !pHumanCon->IsInContainer(indexTo) )
							{
								//返回错误信息
								Msg.SetToType(GCBankSwapItem::ERROR_POS);
								break;
							}

							g_ItemOperator.ExchangeItem(pBagContainer,
								pBagContainer->BagIndex2ConIndex(indexTo),
								pBankContainer,
								(UINT)indexFrom);

							//pHuman->GetDB()->SwapBankWithBag(indexTo, indexFrom);
							Msg.SetFromType(GCBankSwapItem::BANK_POS);
							Msg.SetToType(GCBankSwapItem::BAG_POS);
							Msg.SetIndexFrom(indexFrom);
							Msg.SetIndexTo(indexTo);
						}
						else
						{
							Msg.SetFromType(GCBankSwapItem::ERROR_POS);
							Msg.SetToType(GCBankSwapItem::ERROR_POS);
						}
					}
					else
					{
						Msg.SetFromType(GCBankSwapItem::ERROR_POS);
						Msg.SetToType(GCBankSwapItem::ERROR_POS);
					}

				}
				break;
			case CGBankSwapItem::EQUIP_POS:
				{
				}
				break;
			case CGBankSwapItem::BANK_POS:			//Bank->Bank
				{
					ItemContainer *pBankContainer  = pHuman->GetBankContain();

					Item *pItem1  = pBankContainer->GetItem( indexFrom );

					INT nSpliceType	= 0;
					INT nSpliceTo	= -1;
					//银行容器
					ItemContainer* pBankContain = pHuman->GetBankContain();
					Item *pItem = pBankContain->GetItem(indexFrom);
					UINT TempIndexTo =  indexTo;

					if(pItem->IsEmpty()||pItem1->IsEmpty())
					{
						g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: Too much click" ) ;
						return PACKET_EXE_CONTINUE;
					}
					
					switch(TempIndexTo)
					{
					case CGBankSwapItem::AUTO_POS_BOX1:
						{
							if(pItem1->IsCanLay())
							{
								for(INT i=RENTBOX1_START_INDEX; i<RENTBOX2_START_INDEX; i++)
								{
									Item *pItem2 = pBankContain->GetItem(i);
									if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && 
										pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() )
									{
										nSpliceType = 1;
										nSpliceTo = i;
										indexTo = i;
										break;
									}
								}
							}

							BYTE	indextemp = RENTBOX1_START_INDEX;
							if(0 == nSpliceType)
							{
								while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
									&&  indextemp < RENTBOX2_START_INDEX
									)
								{
									indextemp++;
								}

								if(indextemp == RENTBOX2_START_INDEX)
								{
									indexTo = indextemp-1;
								}
								else
								{
									indexTo = indextemp;
								}
							}
						}
						break;
					case CGBankSwapItem::AUTO_POS_BOX2:
						{
							if(pItem1->IsCanLay())
							{
								for(INT i=RENTBOX2_START_INDEX; i<RENTBOX3_START_INDEX; i++)
								{
									Item *pItem2 = pBankContain->GetItem(i);
									if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && 
										pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() )
									{
										nSpliceType = 1;
										nSpliceTo = i;
										indexTo = i;
										break;
									}
								}
							}
							BYTE	indextemp = RENTBOX2_START_INDEX;
							if(0 == nSpliceType)
							{
								while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
									&&  indextemp < RENTBOX3_START_INDEX
									)
								{
									indextemp++;
								}

								if(indextemp == RENTBOX3_START_INDEX)
								{
									indexTo = indextemp-1;
								}
								else
								{
									indexTo = indextemp;
								}
							}
						}
						break;
					case CGBankSwapItem::AUTO_POS_BOX3:
						{
							if(pItem1->IsCanLay())
							{
								for(INT i=RENTBOX3_START_INDEX; i<RENTBOX4_START_INDEX; i++)
								{
									Item *pItem2 = pBankContain->GetItem(i);
									if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && 
										pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() )
									{
										nSpliceType = 1;
										nSpliceTo = i;
										indexTo = i;
										break;
									}
								}
							}
							BYTE	indextemp = RENTBOX3_START_INDEX;
							if(0 == nSpliceType)
							{
								while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
									&&  indextemp < RENTBOX4_START_INDEX
									)
								{
									indextemp++;
								}

								if(indextemp == RENTBOX4_START_INDEX)
								{
									indexTo = indextemp-1;
								}
								else
								{
									indexTo = indextemp;
								}
							}
						}
						break;
					case CGBankSwapItem::AUTO_POS_BOX4:
						{
							if(pItem1->IsCanLay())
							{
								for(INT i=RENTBOX4_START_INDEX; i<RENTBOX5_START_INDEX; i++)
								{
									Item *pItem2 = pBankContain->GetItem(i);
									if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && 
										pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() )
									{
										nSpliceType = 1;
										nSpliceTo = i;
										indexTo = i;
										break;
									}
								}
							}
							BYTE	indextemp = RENTBOX4_START_INDEX;
							if(0 == nSpliceType)
							{
								while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
									&&  indextemp < RENTBOX5_START_INDEX
									)
								{
									indextemp++;
								}

								if(indextemp == RENTBOX5_START_INDEX)
								{
									indexTo = indextemp-1;
								}
								else
								{
									indexTo = indextemp;
								}
							}
						}
						break;
					case CGBankSwapItem::AUTO_POS_BOX5:
						{
							if(pItem1->IsCanLay())
							{
								for(INT i=RENTBOX5_START_INDEX; i<MAX_BANK_SIZE; i++)
								{
									Item *pItem2 = pBankContain->GetItem(i);
									if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && 
										pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() )
									{
										nSpliceType = 1;
										nSpliceTo = i;
										indexTo = i;
										break;
									}
								}
							}
							BYTE	indextemp = RENTBOX5_START_INDEX;
							if(0 == nSpliceType)
							{
								while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
									&&  indextemp < MAX_BANK_SIZE
									)
								{
									indextemp++;
								}

								if(indextemp == MAX_BANK_SIZE)
								{
									indexTo = indextemp-1;
								}
								else
								{
									indexTo = indextemp;
								}
							}
						}
						break;
					default:
						{
							if(pItem->IsCanLay())
							{
								Item *pItem2   = pBankContainer->GetItem(indexTo);
								if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() )
								{
									nSpliceType = 2;
									nSpliceTo = indexTo;
								}
							}
						}
						break;
					}

					//验证位置的合法性
					if( indexTo>=0 
						&& indexTo<(UINT)(pHuman->__GetBankEndIndex()) 
						&& indexFrom>=0 
						&& indexFrom<(UINT)(pHuman->__GetBankEndIndex()) 
						)
					{
						if(1 == nSpliceType)	//执行合并
						{
							//验证位置里是否有东西
							if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom)))
							{
								if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo)))
								{
									g_ItemOperator.SpliceItem(pBankContainer,
										(UINT)indexFrom,
										pBankContainer,
										(UINT)nSpliceTo);

									Item *pItem1 = pBankContainer->GetItem(indexFrom);
									Item *pItem2 = pBankContainer->GetItem(nSpliceTo);

									//发一个通知更新银行的消息
									GCBankItemInfo MsgBankItemInfo1;
									MsgBankItemInfo1.setBankIndex((WORD)indexFrom);
									MsgBankItemInfo1.setIsNull(pItem1->IsEmpty());
									pItem1->SaveValueTo(MsgBankItemInfo1.getItem());
									pGamePlayer->SendPacket( &MsgBankItemInfo1 );

									//发送一个通知背包更新的消息
									GCBankItemInfo MsgBankItemInfo2;
									MsgBankItemInfo2.setBankIndex((WORD)nSpliceTo);
									MsgBankItemInfo2.setIsNull(pItem2->IsEmpty());
									pItem2->SaveValueTo(MsgBankItemInfo2.getItem());
									pGamePlayer->SendPacket( &MsgBankItemInfo2 );
								}
							}
							g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: empty item" ) ;
							return PACKET_EXE_CONTINUE;
						}
						if(2 == nSpliceType)	//执行合并
						{
							//验证位置里是否有东西
							if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom)))
							{
								if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo)))
								{
									g_ItemOperator.MoveSpliceItem(pBankContainer,
										(UINT)indexFrom,
										pBankContainer,
										(UINT)nSpliceTo);

									Item *pItem1 = pBankContainer->GetItem(indexFrom);
									Item *pItem2 = pBankContainer->GetItem(nSpliceTo);

									//发一个通知更新银行的消息
									GCBankItemInfo MsgBankItemInfo1;
									MsgBankItemInfo1.setBankIndex((WORD)indexFrom);
									MsgBankItemInfo1.setIsNull(pItem1->IsEmpty());
									pItem1->SaveValueTo(MsgBankItemInfo1.getItem());
									pGamePlayer->SendPacket( &MsgBankItemInfo1 );

									//发送一个通知背包更新的消息
									GCBankItemInfo MsgBankItemInfo2;
									MsgBankItemInfo2.setBankIndex((WORD)nSpliceTo);
									MsgBankItemInfo2.setIsNull(pItem2->IsEmpty());
									pItem2->SaveValueTo(MsgBankItemInfo2.getItem());
									pGamePlayer->SendPacket( &MsgBankItemInfo2 );
								}
							}

							g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: empty item indexFrom = %d", indexFrom ) ;
							return PACKET_EXE_CONTINUE;
						}

						if(indexTo == indexFrom)
						{
							/*Msg.SetFromType(GCBankSwapItem::ERROR_POS);
							Msg.SetToType(GCBankSwapItem::ERROR_POS);*/
						}
                        else if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom)))
						{
							if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexTo)))
							{
								ItemContainer* pBankContainer = pHuman->GetBankContain();

								g_ItemOperator.ExchangeItem(pBankContainer,
									(UINT)indexFrom,
									pBankContainer,
									(UINT)indexTo);
							}
							else
							{
								ItemContainer* pBankContainer = pHuman->GetBankContain();

								g_ItemOperator.MoveItem(pBankContainer,
									(UINT)indexFrom,
									pBankContainer,
									(UINT)indexTo);
							}

							//pHuman->GetDB()->SwapBankWithBank(indexTo, indexFrom);
							Msg.SetFromType(GCBankSwapItem::BANK_POS);
							Msg.SetToType(GCBankSwapItem::BANK_POS);
							Msg.SetIndexFrom(indexFrom);
							Msg.SetIndexTo(indexTo);
						}
						else
						{
							Msg.SetFromType(GCBankSwapItem::ERROR_POS);
							Msg.SetToType(GCBankSwapItem::ERROR_POS);
						}
					}
					else
					{
						Msg.SetFromType(GCBankSwapItem::ERROR_POS);
						Msg.SetToType(GCBankSwapItem::ERROR_POS);
					}

				}
				break;
			default:
				break;
			}
		}
		break;
	default:
		break;
	}

	pGamePlayer->SendPacket(&Msg);
	g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: indexFrom=%d, indexTo=%d", indexFrom, indexTo ) ;

		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Beispiel #9
0
UINT CGSouXiaRefiningHandler::Execute( CGSouXiaRefining* 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 iRefiningSouXiaItem = pPacket->GetRefiningSouXiaIndex();
    Assert(iRefiningSouXiaItem >= 0 );
    Assert(iRefiningSouXiaItem <= MAX_BAG_SIZE);

    BYTE iRefiningSouXiaItem2 = pPacket->GetRefiningSouXia2Index();
    Assert(iRefiningSouXiaItem2 >= 0 );
    Assert(iRefiningSouXiaItem2 <= MAX_BAG_SIZE);


    BYTE iRefiningItem = pPacket->GetRefiningItemIndex();
    Assert(iRefiningItem >= 0 );
    Assert(iRefiningItem <= MAX_BAG_SIZE);

    GCSouXiaRefining  refiningMsg;
    // 背包索引获取搜侠道具信息并验证
    ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningSouXiaItem);
    if (pBagContainer == NULL)
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia BagIndex is invalid, BagIndex = %d", iRefiningSouXiaItem) ;
        return PACKET_EXE_ERROR;
    }

    Item* pRefiningSouXiaItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem));
    if(pRefiningSouXiaItem->GetItemClass() != ICLASS_EQUIP || EQUIP_SOUXIA != pRefiningSouXiaItem->GetItemType())
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia type is invalid, BagIndex = %d", iRefiningSouXiaItem) ;
        refiningMsg.SetResult(GET_ITEM_ERROR);
        pGamePlayer->SendPacket(&refiningMsg);

        return PACKET_EXE_ERROR;
    }

    // 背包索引获取第二本搜侠录道具信息
    pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningSouXiaItem2);
    if (pBagContainer == NULL)
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia BagIndex is invalid, BagIndex = %d", iRefiningSouXiaItem2) ;
        return PACKET_EXE_ERROR;
    }

    Item* pRefiningSouXiaItem2 = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem2));
    if(pRefiningSouXiaItem2->GetItemClass() != ICLASS_EQUIP || EQUIP_SOUXIA != pRefiningSouXiaItem2->GetItemType())
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia type is invalid, BagIndex = %d", iRefiningSouXiaItem2) ;
        refiningMsg.SetResult(GET_ITEM_ERROR);
        pGamePlayer->SendPacket(&refiningMsg);
        return PACKET_EXE_ERROR;
    }

    // 背包索引获取炼化道具信息
    pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningItem);
    if (pBagContainer == NULL)
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining refiningItem BagIndex is invalid, BagIndex = %d", iRefiningItem) ;
        return PACKET_EXE_ERROR;
    }

    Item* pRefiningItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningItem));
    if(pRefiningItem->GetItemClass() != ICLASS_COMITEM || COMITEM_SOUXIA != pRefiningItem->GetItemType())
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining refiningItem type is invalid, BagIndex = %d", iRefiningSouXiaItem2) ;
        refiningMsg.SetResult(GET_ITEM_ERROR);
        pGamePlayer->SendPacket(&refiningMsg);
        return PACKET_EXE_ERROR;
    }

    SOUXIA_INFO_TB* pGet = g_ItemTable.GetSouXiaTB(pRefiningItem->GetItemTableIndex());
    if (NULL != pGet && ITEM_REFINING == pGet->m_nUseType)
    {
        if(pGet->m_nNeedLevel > pHuman->GetLevel()) // 使用道具没有达到限制等级
        {
            refiningMsg.SetResult(HUMAN_LEVEL_NOT_ENOUGH);
            Player* pPlayer = pHuman->GetPlayer();
            if( pPlayer != NULL )
            {
                pPlayer->SendPacket( &refiningMsg );
            }

            return PACKET_EXE_CONTINUE;
        }
    }
    // 炼化逻辑
    ItemParamValue ipv = (ItemParamValue)IPV_INT;
    INT	iParamSouXiaID = pRefiningSouXiaItem->GetItemParam(0,ipv);
    INT	iParamSouXiaPos = pRefiningSouXiaItem->GetItemParam(4,ipv);

    INT iParamSouXiaID2 = pRefiningSouXiaItem2->GetItemParam(0,ipv);
    INT iParamSouXiaPos2 = pRefiningSouXiaItem2->GetItemParam(4,ipv);
    //两本捜侠录都为空
    if ( (iParamSouXiaID == 0 && iParamSouXiaPos <= 0 ) && (iParamSouXiaID2 == 0 && iParamSouXiaPos2 <= 0 ))
    {
        refiningMsg.SetResult(SOUXIA_EMPTY);
        Player* pPlayer = pHuman->GetPlayer();
        if( pPlayer != NULL )
        {
            pPlayer->SendPacket( &refiningMsg );
        }
        return PACKET_EXE_CONTINUE;
    }

    BOOL  bRefiningResult = FALSE;
    BYTE  refiningType = 0;
    BYTE  refiningRule = 0;
    SHORT refiningRate = -1;
    BYTE randNum = pScene->GetRand100();
    SOUXIA_DATA randSouXiaData;//炼化随机后取得的新数据

    if (pGet->m_nRefiningRule[0][0] > 0)//炼化技能道具
    {
        refiningRule = pGet->m_nRefiningRule[0][0];
        refiningRate = pGet->m_nRefiningRule[0][1];
        if (randNum < refiningRate)
        {
            bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_SOUXIASKILL);
            refiningType = ITEM_SOUXIASKILL;
        }
    }
    else if (pGet->m_nRefiningRule[1][0] > 0)//炼化配方道具
    {
        refiningRule = pGet->m_nRefiningRule[1][0];
        refiningRate = pGet->m_nRefiningRule[1][1];
        if (randNum < refiningRate)
        {
            bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_PRODUCT);
            refiningType = ITEM_PRODUCT;
        }
    }
    else if (pGet->m_nRefiningRule[2][0] > 0)//炼化神兽召唤道具
    {
        refiningRule = pGet->m_nRefiningRule[2][0];
        refiningRate = pGet->m_nRefiningRule[2][1];
        if (randNum < refiningRate)
        {
            bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_PET_ZHAOHUAN);
            refiningType = ITEM_PET_ZHAOHUAN;
        }
    }
    else if (pGet->m_nRefiningRule[3][0] > 0)//炼化坐骑召唤道具
    {
        refiningRule = pGet->m_nRefiningRule[3][0];
        refiningRate = pGet->m_nRefiningRule[3][1];
        if (randNum < refiningRate)
        {
            bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_ZUOJI_ZHAOHUAN);
            refiningType = ITEM_ZUOJI_ZHAOHUAN;
        }
    }

    if (!bRefiningResult)
    {
        refiningMsg.SetResult(SOUXIA_SKILL_REFINING_FAIL);
        Player* pPlayer = pHuman->GetPlayer();
        if( pPlayer != NULL )
        {
            pPlayer->SendPacket( &refiningMsg );
        }
        return PACKET_EXE_CONTINUE;
    }

    // 手续费用的扣除
    // 成功删除使用的道具和捜侠录
    if (randNum <= refiningRate)
    {
        UINT  newSouXiaIndex = 0;
        BYTE  newSouXiaCurPos = 0;

        // 取玩家身上捜侠录的数据pos 和 skillId
        if (iParamSouXiaID == 0 && iParamSouXiaPos <= 0)//第一本为空
        {
            newSouXiaIndex = iParamSouXiaID2;
            newSouXiaCurPos = iParamSouXiaPos2;
        }
        if (iParamSouXiaID2 == 0 && iParamSouXiaPos2 <= 0)//第二本为空
        {
            newSouXiaIndex = iParamSouXiaID;
            newSouXiaCurPos = iParamSouXiaPos;
        }

        // 第一本的最大页数
        BYTE maxPage = 0, maxPage2 = 0;
        pGet = g_ItemTable.GetSouXiaTB(pRefiningSouXiaItem->GetItemTableIndex());
        Assert(pGet);
        maxPage = pGet->m_nMaxPages[0];
        // 第二本最大页数
        pGet = g_ItemTable.GetSouXiaTB(pRefiningSouXiaItem2->GetItemTableIndex());
        Assert(pGet);
        maxPage2 = pGet->m_nMaxPages[0];

        ITEM_LOG_PARAM	ItemLogParam;
        ItemLogParam.OpType	=	ITEM_REFINING_SOUXIA;
        UINT  newSouXiaBagIndex = 0;//新的捜侠录item背包索引

        if (maxPage >= maxPage2) // 第一本的最大页大于第二本则保留第一本
        {
            BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem2));
            if(bRet)
            {
                SaveItemLog(&ItemLogParam);
            }
            else
            {
                refiningMsg.SetResult(ERASE_ITEM_FAIL);
                pGamePlayer->SendPacket(&refiningMsg);
                return PACKET_EXE_CONTINUE;
            }
            if (iParamSouXiaPos2 >= 0)
            {
                pHuman->EraseSouXia(iParamSouXiaPos2);//人身上销毁第二本
            }

            newSouXiaBagIndex = iRefiningSouXiaItem;//保留第一本的数据的bagindex

            if ( (iParamSouXiaID > 0  && iParamSouXiaPos >= 0) && (iParamSouXiaID2 > 0  && iParamSouXiaPos2 >= 0))
            {
                newSouXiaIndex = iParamSouXiaID;
                newSouXiaCurPos = iParamSouXiaPos;
            }
        }
        else // 销毁第一本
        {
            BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem));
            if(bRet)
            {
                SaveItemLog(&ItemLogParam);
            }
            else
            {
                refiningMsg.SetResult(ERASE_ITEM_FAIL);
                pGamePlayer->SendPacket(&refiningMsg);
                return PACKET_EXE_CONTINUE;
            }

            if (iParamSouXiaPos >= 0)
            {
                pHuman->EraseSouXia(iParamSouXiaPos);//人身上销毁第一本
            }
            newSouXiaBagIndex = iRefiningSouXiaItem2;//保留第二本的数据的bagindex

            if ( (iParamSouXiaID > 0  && iParamSouXiaPos >= 0) && (iParamSouXiaID2 > 0  && iParamSouXiaPos2 >= 0))
            {
                newSouXiaIndex = iParamSouXiaID2;
                newSouXiaCurPos = iParamSouXiaPos2;
            }
        }
        Assert (newSouXiaIndex > 0 && newSouXiaCurPos >= 0);
        randSouXiaData.m_CurPos = newSouXiaCurPos;
        randSouXiaData.m_SouXiaID = newSouXiaIndex;
        // 销毁炼化道具
        BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningItem));
        if(bRet)
        {
            SaveItemLog(&ItemLogParam);
        }
        else
        {
            refiningMsg.SetResult(ERASE_ITEM_FAIL);
            pGamePlayer->SendPacket(&refiningMsg);
            return PACKET_EXE_CONTINUE;
        }
        // 改变保留的捜侠录道具的信息
        Item* pNewSouXiaItem = HumanItemLogic::GetBagItem(pHuman, pBagContainer->BagIndex2ConIndex(newSouXiaBagIndex));
        Assert(pNewSouXiaItem);

        bRet = g_ItemOperator.SetItemParam( pHuman->GetBaseContain(),pHuman->GetBaseContain()->BagIndex2ConIndex(newSouXiaBagIndex),0, ipv, newSouXiaIndex);
        if (!bRet)
        {
            return PACKET_EXE_CONTINUE;
        }

        bRet = g_ItemOperator.SetItemParam( pHuman->GetBaseContain(),pHuman->GetBaseContain()->BagIndex2ConIndex(newSouXiaBagIndex), 4, ipv, newSouXiaCurPos);

        if (!bRet)
        {
            return PACKET_EXE_CONTINUE;
        }

        /*bRet = g_ItemOperator.SetItemParam( pHuman->GetBaseContain(),pHuman->GetBaseContain()->BagIndex2ConIndex(newSouXiaBagIndex),8, ipv, refiningType);

        if (!bRet)
        {
        	return PACKET_EXE_CONTINUE;
        }*/

        // 以上设置ITEM param注意保存到文件,并且要通知ITEM 的param 改变
        GCItemInfo	Msg;
        Msg.setID( newSouXiaBagIndex );
        Msg.setIsNull(FALSE);
        pNewSouXiaItem->SaveValueTo(Msg.getItem());
        pHuman->GetPlayer()->SendPacket(&Msg);

        pHuman->SetSouXia(randSouXiaData, newSouXiaCurPos);
        // 保存到文件
        _SOUXIA_DB_LOAD		SouXia_db_Load;
        SouXia_db_Load.m_SouXiaData[newSouXiaCurPos] = randSouXiaData;
        pHuman->GetDB()->SetSouXiaDBInfo(&SouXia_db_Load, newSouXiaCurPos);

        // 发送新的捜侠录消息
        refiningMsg.SetNewItemBagIndex(newSouXiaBagIndex);
        refiningMsg.SetSouXiaData(&randSouXiaData);//炼化以后的捜侠录数据
        refiningMsg.SetCurRefiningType(refiningType);
        refiningMsg.SetResult(SOUXIA_REFINING_SUCCESS);
        Player* pPlayer = pHuman->GetPlayer();
        if( pPlayer != NULL )
        {
            pPlayer->SendPacket( &refiningMsg );
        }
    }
    return PACKET_EXE_CONTINUE;

    __LEAVE_FUNCTION

    return	PACKET_EXE_ERROR;
}
Beispiel #10
0
uint CGEquipRemouldHandler::Execute(CGEquipRemould* 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;  
	EQUIPREMOULD_RESULT nResult	= EQUIPREMOULD_FAIL;
	GCEquipRemouldResult Msg;
	switch(pPacket->GetEquipPosType())
	{
	case ENUM_EQUIP_POINT:
		{
			EquipPoint = pPacket->GetPos();
			if(EquipPoint>HEQUIP_ADORN2)
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: EquipPoint error, EquipPoint=%d", EquipPoint) ;
				return PACKET_EXE_ERROR;
			}

			ItemContainer* pEquipContainer = pHuman->GetEquipContain();
			if(NULL==pEquipContainer)
			{
				AssertEx(FALSE,"[CGEquipRemouldHandler]: NULL EquipContainer pointer found!");
			}
			pEquipItem = pEquipContainer->GetItem((UINT)EquipPoint);
			Assert(pEquipItem);

			if(pEquipItem->IsEmpty())
			{
				nResult = EQUIPREMOULD_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler pEquipItem is Null at  EquipPoint= %d", EquipPoint) ;
				return PACKET_EXE_CONTINUE;
			}

			Assert (pEquipItem->GetItemClass() == ICLASS_EQUIP);

			if(!(pPacket->getItemID() == pEquipItem->GetGUID()))
			{
				nResult = EQUIPREMOULD_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler 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, "CGEquipRemouldHandler: BagIndex error, BagIndex=%d", BagIndex) ;
				return PACKET_EXE_ERROR;
			}
			if (!pItemContainer->IsCanUse())
			{
				nResult = EQUIPREMOULD_BAG_INVALID;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d", 
					pItemContainer->GetContainerType(), BagIndex) ;
					return PACKET_EXE_ERROR;
			}

			pEquipItem		=	pItemContainer->GetItem(pItemContainer->BagIndex2ConIndex(BagIndex));
			if(pEquipItem->IsEmpty())
			{
				nResult = EQUIPREMOULD_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler pEquipItem is Null at  BagIndex= %d", BagIndex) ;
				return PACKET_EXE_CONTINUE;
			}

			if (pEquipItem->GetItemClass() != ICLASS_EQUIP)
			{
				nResult = EQUIPREMOULD_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler GetItemClass is not ICLASS_EQUIP ") ;
				return PACKET_EXE_CONTINUE;
			}

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

			if (pEquipItem->GetItemType() > EQUIP_ADORN)
			{
				nResult = EQUIPREMOULD_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler GUID is different ") ;
				return PACKET_EXE_CONTINUE;
			}
		}
		break;
	default:
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: EquipFromType error, EquipFromType=%d", pPacket->GetEquipPosType()) ;
			return PACKET_EXE_ERROR;
		}
		break;
	}

	if (pEquipItem->GetEquipFromType() != ITEM_CREATE)
	{
		nResult = EQUIPREMOULD_TYPE_FAIL;
		Msg.SetResult(nResult);
		pGamePlayer->SendPacket( &Msg ) ;
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler Type error ") ;
		return PACKET_EXE_CONTINUE;
	}

	ITEM_PRODUCT_INFO_TB* pCreateTB = g_ItemTable.GetItemProductInfoTB(pEquipItem->GetItemTableIndex());
	if(pCreateTB == NULL)
	{
		nResult = EQUIPREMOULD_EQUIP_FAIL;
		Msg.SetResult(nResult);
		pGamePlayer->SendPacket(&Msg);
		return PACKET_EXE_CONTINUE;
	}
	if (pCreateTB->m_nRemouldInfoCount != pPacket->GetValidNum())
	{
		return PACKET_EXE_ERROR;
	}
	
	if (pCreateTB->m_RemouldMoney > pHuman->GetMoney())
	{
		nResult = EQUIPREMOULD_MONEY_FAIL;
		Msg.SetResult(nResult);
		pGamePlayer->SendPacket(&Msg);
		return PACKET_EXE_CONTINUE;
	}
	struct MATERIAL_REQ 
	{
		UINT m_nIndex;
		UINT m_nCount;
	};
	MATERIAL_REQ MaterialIndex[MAX_REMOULD_MATERIAL_NUM];
	UINT nEquipScore = 0;
	for (UINT i=0; i<pCreateTB->m_nRemouldInfoCount; ++i)
	{
		REMOULDITEM_INFO RemouldInfo = pCreateTB->m_RemouldInfo[i];

		EQUIPREMOULD_MATERIAL_INFO MaterialInfo = pPacket->GetMaterialReq(i);
		if(MaterialInfo.m_nMaterialType != RemouldInfo.m_MaterialType)
		{
			nResult = EQUIPREMOULD_MATERIAL_FAIL;
			Msg.SetResult(nResult);
			pGamePlayer->SendPacket( &Msg ) ;
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler MaterialType error") ;
			return PACKET_EXE_CONTINUE;
		}

		if(MaterialInfo.m_nMaterialLevel < RemouldInfo.m_NeedLevel)
		{
			nResult = EQUIPREMOULD_MATERIAL_LEVEL;
			Msg.SetResult(nResult);
			pGamePlayer->SendPacket( &Msg ) ;
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler MaterialLevel fail") ;
			return PACKET_EXE_CONTINUE;
		}

		UINT nMaterialIndex = GenMaterialIndex(MaterialInfo.m_nMaterialType, MaterialInfo.m_nMaterialLevel);
		//查询物品表该材料是否存在
		COMMITEM_INFO_TB* pMaterialInfoTB = g_ItemTable.GetCommItemInfoTB(nMaterialIndex);
		if(pMaterialInfoTB == NULL)
		{
			return PACKET_EXE_ERROR;
		}

		INT nCount = HumanItemLogic::CalcBagItemCount(pHuman, nMaterialIndex);
		if (nCount<RemouldInfo.m_MaterialNum)
		{
			nResult = EQUIPREMOULD_MATERIAL_COUNT;
			Msg.SetResult(nResult);
			pGamePlayer->SendPacket( &Msg ) ;
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler Material num fail") ;
			return PACKET_EXE_CONTINUE;
		}

		//获取对应材料分
		MATERIAL_LEVEL_INFO_TB* pMaterialLevelInfo = g_ItemTable.GetMaterialInfoTB(MaterialInfo.m_nMaterialLevel);
		Assert(pMaterialLevelInfo != NULL);
		if (!pMaterialLevelInfo)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "[CGEquipRemouldHandler::Execute] GetMaterialInfoTB index is error [%d]",MaterialInfo.m_nMaterialLevel);
			return PACKET_EXE_ERROR;
		}
		nEquipScore = nEquipScore + pMaterialLevelInfo->m_MaterialValue;

		MaterialIndex[i].m_nIndex = nMaterialIndex;
		MaterialIndex[i].m_nCount = pCreateTB->m_RemouldInfo[i].m_MaterialNum;
	}

	nResult = (EQUIPREMOULD_RESULT)pHuman->EquipRemould(pEquipItem, nEquipScore);
	if(nResult == EQUIPREMOULD_FAIL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: pHuman->AddHole Fail") ;
		return PACKET_EXE_ERROR;
	}

	if (nResult == EQUIPREMOULD_SUCCESS)
	{
		ITEM_LOG_PARAM LogParam;
		LogParam.OpType     =   ITEM_REMOULD_CONSUME;
		LogParam.CharGUID	=	pHuman->GetGUID();
		LogParam.XPos		=	pHuman->getWorldPos()->m_fX;
		LogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
		LogParam.SceneID	=	pHuman->getScene()->SceneID();

		for (UINT i=0; i<pCreateTB->m_nRemouldInfoCount; ++i)
		{
			if(HumanItemLogic::EraseBagItem(&LogParam, pHuman,MaterialIndex[i].m_nIndex, MaterialIndex[i].m_nCount))
			{
				SaveItemLog(&LogParam);
			}
		}
		
		pHuman->SetMoney(pHuman->GetMoney() - pCreateTB->m_RemouldMoney);

		MONEY_LOG_PARAM	MoneyLogParam;
		MoneyLogParam.CharGUID	=	pHuman->GetGUID();
		MoneyLogParam.OPType	=	MONEY_REMOULD_REDUCE;	
		MoneyLogParam.Count		=	(INT)pCreateTB->m_RemouldMoney;
		MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
		MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
		MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
		SaveMoneyLog(&MoneyLogParam);
	}

	Msg.SetResult(nResult);
	pGamePlayer->SendPacket( &Msg ) ;
	//////////////////////////////////////////////////////////////////////////

	if((nResult == EQUIPREMOULD_SUCCESS)||(nResult == EQUIPREMOULD_MAX_FAIL))
	{
		if(pPacket->GetEquipPosType() == ENUM_EQUIP_POINT)
		{
			pHuman->ItemEffectFlush();

			pHuman->SetEquipVer(pHuman->GetEquipVer()+1);
			INT Equip_Point = pPacket->GetPos();
			UINT RetPart = 0;
			GCDetailEquipList	SelfMsg;
			SelfMsg.setObjID( pHuman->GetID() );
			Item* pEquipItem = HumanItemLogic::GetEquip(pHuman, (HUMAN_EQUIP)Equip_Point);
			if(!pEquipItem)
			{
				Assert(FALSE);
			}
			if(pEquipItem->IsEmpty()) 
			{
				Assert(FALSE);
			}
			pEquipItem->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)Equip_Point));
			RetPart|=(1<<((UINT)Equip_Point));
			SelfMsg.SetAskPart(RetPart);
			pGamePlayer->SendPacket( &SelfMsg ) ;
		}
		else
		{
			GCItemInfo	 ItemMsg;
			ItemMsg.setIsNull(FALSE);
			ItemMsg.setID(BagIndex);
			pEquipItem->SaveValueTo(ItemMsg.getItem());
			pHuman->GetPlayer()->SendPacket(&ItemMsg);

		}
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: success nResult=%d", nResult ) ;
	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR;
}
Beispiel #11
0
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,
										pBagContainer->BagIndex2ConIndex(BagIndex),
										pEquipContainer,
										(UINT)Equip_Point);

							
			}
			
			Item* pEquip = pEquipContainer->GetItem((UINT)Equip_Point);
			
			if(pEquip&&pEquip->IsCanEquipBind())
			{
				g_ItemOperator.SetItemBind(pEquipContainer,(UINT)Equip_Point);	
			}

			

			Msg.setBagIndex(BagIndex);
			Msg.setEquipPoint(Equip_Point);
			Msg.setEquipID(pEquipItem->GetGUID());
			Msg.setEquipResID(pEquipItem->GetItemTableIndex());
			Msg.setItemResID(pUseItem->GetItemTableIndex());
			Msg.setBagItemId(pUseItem->GetGUID());
			Msg.setResult(USEEQUIP_SUCCESS);
			
			pGamePlayer->SendPacket( &Msg ) ;
			pHuman->SetEquipVer(pHuman->GetEquipVer()+1);
			//刷新装备对人物的属性影响

			pHuman->ItemEffectFlush();

			//如果可见
			if(pHuman->IsVisualPart(Equip_Point))
			{	
				GCCharEquipment OtherMsg;
				OtherMsg.setObjID(pHuman->GetID());
				if(Equip_Point == HEQUIP_WEAPON)
				{
					UINT uGemID = GetEquipmentMaxLevelGemID(pEquip);
					OtherMsg.setID(Equip_Point,pEquip->GetItemTableIndex(), uGemID);
				}
				else
				{
					OtherMsg.setID(Equip_Point,pEquip->GetItemTableIndex(), -1);
				}
				pScene->BroadCast(&OtherMsg,pHuman,TRUE);

			}


			WORD RetPart = 0;
			GCDetailEquipList	SelfMsg;
			SelfMsg.setObjID( pHuman->GetID() );
			pEquipItem = HumanItemLogic::GetEquip(pHuman,Equip_Point);
			if(!pEquipItem)
			{
				Assert(FALSE);
				return PACKET_EXE_CONTINUE;
			}
			if(pEquipItem->IsEmpty()) 
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGUseEquipmentHandler: Equip_Point =%d Fail", Equip_Point ) ;
				return PACKET_EXE_CONTINUE;
			}
				
			pEquipItem->SaveValueTo(SelfMsg.GetEquipData(Equip_Point));
			RetPart|=(1<<((INT)Equip_Point));
			SelfMsg.SetAskPart(RetPart);
			pGamePlayer->SendPacket( &SelfMsg ) ;
		}
		
		
		
		
		
	}
	else
	{
		Msg.setResult(USEEQUIP_TYPE_FAIL);
		Msg.setBagIndex(0);
		Msg.setEquipPoint(0);
		pGamePlayer->SendPacket( &Msg ) ;
		
	}
	
	

	
	

	g_pLog->FastSaveLog( LOG_FILE_1, "CGUseEquipmentHandler: BagIndex=%d", BagIndex ) ;

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Beispiel #12
0
uint CGShopSpecialRepairHandler::Execute( CGShopSpecialRepair* 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 ;
	}

	BYTE	Opt         =	pPacket->GetOpt();
	BYTE	BagIndex	=	pPacket->GetBagIndex();		//包中的位置

	
	Item*	pCurItem = NULL;
	INT				MoneySpent = 0;
	INT				MoneyLast = 0;
	INT				MoneyHave  = pHuman->GetMoney();
	INT				RepairedIndex = 0;
	GCShopSpecialRepairResult MsgResult;
	GCShopSpecialRepairResult::REPAIRED_ITEM	ItemList;

	if(Opt == CGShopSpecialRepair::FromBag)
	{
		//一定是修理单个
		ItemContainer* pItemContainer = HumanItemLogic::GetBagContainer(pHuman, BagIndex);
		if (pItemContainer == NULL)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler BagIndex is invalid, BagIndex = %d", BagIndex) ;

			return PACKET_EXE_ERROR;
		}
		if (!pItemContainer->IsCanUse())
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler extrabag is invalid time BagIndex = %d", BagIndex) ;
			return PACKET_EXE_CONTINUE ;
		}

		pCurItem = pItemContainer->GetItem(pItemContainer->BagIndex2ConIndex(BagIndex));
		if(!pCurItem->IsEmpty())
		{
			if(pCurItem->GetItemClass() != ICLASS_EQUIP)
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler pCurItem->GetItemClass() != ICLASS_EQUIP ") ;
				return PACKET_EXE_ERROR ;
			}
			EQUIP_SPECIALREPAIR_TB* pSpecialRepair = g_ItemTable.GetSpecialRepairTB(); 
			Assert (pSpecialRepair != NULL);
			if (!pSpecialRepair)
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "[CGShopSpecialRepairHandler::Execute] GetSpecialRepairTB index is error");
				return PACKET_EXE_ERROR;
			}
		
			//获得Human背包中对应ItemIndex的物品位置
			UINT	nItemCount	= 	HumanItemLogic::CalcBagItemCount(pHuman, pSpecialRepair->m_ItemID);
			if((nItemCount == 0)||(nItemCount < pPacket->GetItemNum()))
			{
				MsgResult.SetResult(EQUIPSPECIALREPAIR_ITEM);
				pGamePlayer->SendPacket(&MsgResult);
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler nItemIndex = %d", pSpecialRepair->m_ItemID) ;
				return PACKET_EXE_CONTINUE ;
			}

			FLOAT fCur = (FLOAT)pCurItem->GetDurPoints();
			FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint();
			FLOAT fCurMax	= (FLOAT)pCurItem->GetCurMaxDurPoint();
			if(fMax != fCurMax)
			{
				UINT nUsedItem = 0;
				for (UINT i=0; i<pPacket->GetItemNum(); ++i)
				{
					++nUsedItem;
					fCurMax = pSpecialRepair->m_RecoverPoint + fCurMax;
					if (fCurMax>=fMax)
					{
						fCurMax = fMax;
						break;
					}
					
				}
				
				HumanItemLogic::SetBagItemCurMaxDur(pHuman,(UINT)BagIndex, (INT)fCurMax);
				HumanItemLogic::SetBagItemDur(pHuman,(UINT)BagIndex, (INT)fCurMax);
				
				
				ITEM_LOG_PARAM LogParam;
				LogParam.OpType     =   ITEM_SPECIALREPAIR_CONSUME;
				LogParam.CharGUID	=	pHuman->GetGUID();
				LogParam.XPos		=	pHuman->getWorldPos()->m_fX;
				LogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
				LogParam.SceneID	=	pHuman->getScene()->SceneID();
				BOOL bOK = HumanItemLogic::EraseBagItem(&LogParam,pHuman, pSpecialRepair->m_ItemID, nUsedItem);
				Assert(bOK);
				SaveItemLog(&LogParam);

				ItemList.IsIn		=	GCShopSpecialRepairResult::BAG;	
				ItemList.nCurDur		=  pCurItem->GetDurPoints(); 
				ItemList.nCurMaxDur	=  pCurItem->GetCurMaxDurPoint(); 
				ItemList.BagIndex	=  BagIndex;
				MsgResult.SetResult(EQUIPSPECIALREPAIR_SUCCESS);
				MsgResult.SetReList(&ItemList);
				pHuman->GetPlayer()->SendPacket(&MsgResult);
				return PACKET_EXE_CONTINUE ;
			}
			else
			{
				MsgResult.SetResult(EQUIPSPECIALREPAIR_NOREAPIR);
				pGamePlayer->SendPacket(&MsgResult);
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler needn't repair") ;
				return PACKET_EXE_CONTINUE ;
			}
		}
		else
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler BagIndex = %d", BagIndex) ;
			return PACKET_EXE_CONTINUE ;
		}
	}
	else if(Opt == CGShopSpecialRepair::FromEquip)
	{
		pCurItem = HumanItemLogic::GetEquip(pHuman,(HUMAN_EQUIP)BagIndex);

		if(!pCurItem->IsEmpty())
		{//有东西
			if(pCurItem->GetItemClass() != ICLASS_EQUIP)
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler pCurItem->GetItemClass() != ICLASS_EQUIP ") ;
				return PACKET_EXE_ERROR ;
			}
			EQUIP_SPECIALREPAIR_TB* pSpecialRepair = g_ItemTable.GetSpecialRepairTB(); 
			Assert (pSpecialRepair != NULL);
			if (!pSpecialRepair)
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "[CGShopSpecialRepairHandler::Execute] GetSpecialRepairTB index is error");
				return PACKET_EXE_ERROR;
			}
			//获得Human背包中对应ItemIndex的物品位置
			UINT	nItemCount	= 	HumanItemLogic::CalcBagItemCount(pHuman, pSpecialRepair->m_ItemID);
			if((nItemCount == 0)||(nItemCount < pPacket->GetItemNum()))
			{
				MsgResult.SetResult(EQUIPSPECIALREPAIR_ITEM);
				pGamePlayer->SendPacket(&MsgResult);
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler nItemIndex = %d", pSpecialRepair->m_ItemID) ;
				return PACKET_EXE_CONTINUE ;
			}

			FLOAT fCur = (FLOAT)pCurItem->GetDurPoints();
			FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint();
			FLOAT fCurMax	= (FLOAT)pCurItem->GetCurMaxDurPoint();

			if(fMax != fCurMax)
			{
				UINT nUsedItem = 0;
				for (UINT i=0; i<pPacket->GetItemNum(); ++i)
				{
					++nUsedItem;
					fCurMax = pSpecialRepair->m_RecoverPoint + fCurMax;
					if (fCurMax>=fMax)
					{
						fCurMax = fMax;
						break;
					}
				}
				
				HumanItemLogic::SetCurEquipMaxDur(pHuman,(HUMAN_EQUIP)BagIndex, (INT)fCurMax);
				HumanItemLogic::SetEquipDur(pHuman,(HUMAN_EQUIP)BagIndex, (INT)fCurMax);

				ITEM_LOG_PARAM LogParam;
				LogParam.OpType     =   ITEM_SPECIALREPAIR_CONSUME;
				LogParam.CharGUID	=	pHuman->GetGUID();
				LogParam.XPos		=	pHuman->getWorldPos()->m_fX;
				LogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
				LogParam.SceneID	=	pHuman->getScene()->SceneID();
				BOOL bOK = HumanItemLogic::EraseBagItem(&LogParam,pHuman, pSpecialRepair->m_ItemID,nUsedItem);
				Assert(bOK);
				SaveItemLog(&LogParam);

				ItemList.IsIn		=	GCShopSpecialRepairResult::EQUIP;	
				ItemList.nCurDur		=  pCurItem->GetDurPoints(); 
				ItemList.nCurMaxDur	=  pCurItem->GetCurMaxDurPoint(); 
				ItemList.BagIndex	=  BagIndex;
				MsgResult.SetResult(EQUIPSPECIALREPAIR_SUCCESS);
				MsgResult.SetReList(&ItemList);
				pHuman->GetPlayer()->SendPacket(&MsgResult);

				if ((INT)fCur == 0)
				{
					pHuman->ItemEffectFlush();
				}
				return PACKET_EXE_CONTINUE ;
			}
			else
			{
				MsgResult.SetResult(EQUIPSPECIALREPAIR_NOREAPIR);
				pGamePlayer->SendPacket(&MsgResult);
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler needn't repair") ;
				return PACKET_EXE_CONTINUE ;
			}
		}

	}
	g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopSpecialRepairHandler error Opt=", Opt);
	return PACKET_EXE_ERROR;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
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;

			case CGBankAddItem::AUTO_POS_BOX2:
				{
					//先查询是不是有可以合并的物品,(只在本租赁箱中)
					if( pBagItem->IsCanLay() )
					{
						for( INT i=RENTBOX2_START_INDEX; i<RENTBOX3_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 = RENTBOX2_START_INDEX;
					if(0 == bSplice)
					{
						while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
							&&  indextemp < RENTBOX3_START_INDEX
							)
						{
							indextemp++;
						}

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

			case CGBankAddItem::AUTO_POS_BOX3:
				{
					//先查询是不是有可以合并的物品,(只在本租赁箱中)
					if( pBagItem->IsCanLay() )
					{
						for( INT i=RENTBOX3_START_INDEX; i<RENTBOX4_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 = RENTBOX3_START_INDEX;
					if(0 == bSplice)
					{
						while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
							&&  indextemp < RENTBOX4_START_INDEX
							)
						{
							indextemp++;
						}

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

			case CGBankAddItem::AUTO_POS_BOX4:
				{
					//先查询是不是有可以合并的物品,(只在本租赁箱中)
					if( pBagItem->IsCanLay() )
					{
						for( INT i=RENTBOX4_START_INDEX; i<RENTBOX5_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 = RENTBOX4_START_INDEX;
					if(0 == bSplice)
					{
						while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
							&&  indextemp < RENTBOX5_START_INDEX
							)
						{
							indextemp++;
						}

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

			case CGBankAddItem::AUTO_POS_BOX5:
				{
					//先查询是不是有可以合并的物品,(只在本租赁箱中)
					if( pBagItem->IsCanLay() )
					{
						for( INT i=RENTBOX5_START_INDEX; i<MAX_BANK_SIZE; 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 = RENTBOX5_START_INDEX;
					if(0 == bSplice)
					{
						while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) 
							&&  indextemp < MAX_BANK_SIZE
							)
						{
							indextemp++;
						}

						if(indextemp == MAX_BANK_SIZE)
						{
							indexTo = indextemp-1;
						}
						else
						{
							indexTo = indextemp;
						}
					}
				}
				break;
			//检查直接选定的目标是不是可以合并
			default:
				{
					if( pBagItem->IsCanLay() )
					{
						Item *pItemFrom = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom));
						Item *pItemTo   = pBankContainer->GetItem(indexTo);
						if( pItemFrom->GetItemTableIndex() == pItemTo->GetItemTableIndex() )
						{
							bSplice = 2;
							nSpliceTo = indexTo;
						}
					}
				}
				break;
			}

			//验证位置的合法性
			if( indexFrom>=0 
				&& indexFrom<MAX_BAG_SIZE 
				&& indexTo>=0 
				&& (indexTo<(UINT)(pHuman->__GetBankEndIndex()) || (indexTo>=251 && indexTo<=255) )
				) 				
			{
				if(1 == bSplice)	//执行合并
				{
					//验证位置里是否有东西
					if(ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom)))
					{
						if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo)))
						{
							g_ItemOperator.SpliceItem(pBagContainer,
								(UINT)pBagContainer->BagIndex2ConIndex(indexFrom),
								pBankContainer,
								(UINT)nSpliceTo);

							Item *pItemBag = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom));
							Item *pItemBank= pBankContainer->GetItem(nSpliceTo);

							//发一个通知更新银行的消息
							GCBankItemInfo MsgBankItemInfo;
							MsgBankItemInfo.setBankIndex((WORD)nSpliceTo);
							MsgBankItemInfo.setIsNull(pItemBank->IsEmpty());
							pItemBank->SaveValueTo(MsgBankItemInfo.getItem());
							pGamePlayer->SendPacket( &MsgBankItemInfo );

							//发送一个通知背包更新的消息
							GCItemInfo MsgBagItemInfo;
							MsgBagItemInfo.setID((WORD)indexFrom);
							MsgBagItemInfo.setIsNull(pItemBag->IsEmpty());
							pItemBag->SaveValueTo(MsgBagItemInfo.getItem());
							pGamePlayer->SendPacket( &MsgBagItemInfo );
						}
					}
					g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler Empty Item indexFrom = %d", indexFrom) ;
					return PACKET_EXE_CONTINUE;
				}
				else if(2 == bSplice)
				{
					//验证位置里是否有东西
					if(ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom)))
					{
						if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo)))
						{
							g_ItemOperator.MoveSpliceItem(pBagContainer,
								(UINT)pBagContainer->BagIndex2ConIndex(indexFrom),
								pBankContainer,
								(UINT)nSpliceTo);

							Item *pItemBag = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom));
							Item *pItemBank= pBankContainer->GetItem(nSpliceTo);

							//发一个通知更新银行的消息
							GCBankItemInfo MsgBankItemInfo;
							MsgBankItemInfo.setBankIndex((WORD)nSpliceTo);
							MsgBankItemInfo.setIsNull(pItemBank->IsEmpty());
							pItemBank->SaveValueTo(MsgBankItemInfo.getItem());
							pGamePlayer->SendPacket( &MsgBankItemInfo );

							//发送一个通知背包更新的消息
							GCItemInfo MsgBagItemInfo;
							MsgBagItemInfo.setID((WORD)indexFrom);
							MsgBagItemInfo.setIsNull(pItemBag->IsEmpty());
							pItemBag->SaveValueTo(MsgBagItemInfo.getItem());
							pGamePlayer->SendPacket( &MsgBagItemInfo );
						}
					}
					g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler Empty Item indexFrom = %d", indexFrom) ;
					return PACKET_EXE_CONTINUE;
				}
				else				//不执行合并
				{
					//验证位置里是否有东西
					if(ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom)))
					{
						if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexTo))) //执行了交换
						{
							//判断银行内的这个物品是不是能够放入背包中
							ItemContainer* pBankContainer = pHuman->GetBankContain();
							Item *pItem = pBankContainer->GetItem(indexTo); 

							ItemContainer *pHumanCon = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex());
							if( !pHumanCon )
							{
								//返回错误信息
								Msg.SetFromType(GCBankAddItem::ERROR_POS);
								break;
							}

							if( !pHumanCon->IsInContainer(indexFrom) )
							{
								//返回错误信息
								Msg.SetFromType(GCBankAddItem::ERROR_POS);
								break;
							}

							g_ItemOperator.ExchangeItem(pBagContainer,
								pBagContainer->BagIndex2ConIndex(indexFrom),
								pBankContainer,
								(UINT)indexTo);

							//执行了交换
							Msg.SetOperateType(GCBankAddItem::OPERATE_SWAP);
						}
						else //执行了移动
						{
							g_ItemOperator.MoveItem(pBagContainer,
								pBagContainer->BagIndex2ConIndex(indexFrom),
								pBankContainer,
								(UINT)indexTo);

							//执行了移动
							Msg.SetOperateType(GCBankAddItem::OPERATE_MOVE);
						}
						Msg.SetFromType(GCBankAddItem::BAG_POS);
						Msg.SetIndexFrom(indexFrom);
						Msg.SetIndexTo(indexTo);
						
					}
					else
					{
						Msg.SetFromType(GCBankAddItem::ERROR_POS);
					}
				}
			}
			else	//数据不合法
			{
				Msg.SetFromType(GCBankAddItem::ERROR_POS);
			}
		}
		break;
	default:
		break;
	}

	pGamePlayer->SendPacket( &Msg ) ;
	g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler: indexFrom=%d, indexTo=%d", indexFrom, indexTo ) ;
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
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 = 
							g_ItemOperator.CopyItem
							(
								pBagContainer,
								pBagContainer->BagIndex2ConIndex(FromIndex),
								pExchangeContainer
							);

						if(result>=0)
						{//拷贝成功,

							//发送消息给双方客户端
							Item* pIt = pExchangeContainer->GetItem(result);	

							g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入交易物品 [%d]",	pHuman->GetName(), pIt->GetItemTableIndex() ) ;												

							if( pIt != NULL && pIt->IsEmpty() == FALSE )
							{
								INT iConIndex = pBagContainer->BagIndex2ConIndex(FromIndex);
								//先锁定此物品
								g_ItemOperator.LockItem( pBagContainer, iConIndex );
								
								//标示次物品已经放在交易栏中,计算空间用
								pBagContainer->GetItem(iConIndex)->SetInExchange(TRUE);

								//再发
								pIt->SaveValueTo(&ItemTemp);//取出实例
								
								/*
								先发自己
								*/
								Msg.SetIsMyself(TRUE);//发给自己
								Msg.SetOpt(OPT_ADDITEM);//设置操作类型
								Msg.SetFromType(POS_BAG);//设置来自类型
								Msg.SetFromIndex(FromIndex);//设置来自索引
								Msg.SetToIndex(result);//设置目标位置索引
								pGamePlayer->SendPacket(&Msg);

								/*
								再发对方
								*/
								Msg.SetIsMyself(FALSE);//发给对方
								Msg.SetOpt(OPT_ADDITEM);//设置操作类型
								Msg.SetToIndex(result);

								_EXCHANGE_ITEM Exitem;
								Exitem.byNumber = ItemTemp.GetItemCount();
								Exitem.isBlueEquip	= 1;
								Exitem.item_data	= ItemTemp;
                                Exitem.uBagPos      = result;
								Msg.SetItem(&Exitem);

								pDestHuman->GetPlayer()->SendPacket(&Msg);

                                //改变物品  自己解锁
                                pHuman->m_ExchangBox.m_IsLocked = FALSE;
                                if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE)
                                {//如果对方已经加锁
                                    pDestHuman->m_ExchangBox.m_IsLocked = FALSE;
                                    GCExchangeSynchLock MsgToDes, MsgToSelf;

                                    //通知对方,解双方锁
                                    MsgToDes.SetIsBoth(TRUE);
                                    MsgToDes.SetIsLocked(FALSE);
                                    pDestHuman->GetPlayer()->SendPacket(&MsgToDes);

                                    //通知自己解对方锁
                                    MsgToSelf.SetIsMyself(FALSE);
                                    MsgToSelf.SetIsLocked(FALSE);
                                    pHuman->GetPlayer()->SendPacket(&MsgToSelf);

                                }
                                else
                                {//对方没有加锁,直接同步
                                    GCExchangeSynchLock MsgToDes;
                                    MsgToDes.SetIsMyself (FALSE);
                                    MsgToDes.SetIsLocked(FALSE);
                                    pDestHuman->GetPlayer()->SendPacket(&MsgToDes);
                                }
							}
							else
							{
								MsgError.SetID(ERR_ILLEGAL);
								pGamePlayer->SendPacket(&MsgError);
								g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入非法交易物品 [%d]",	pHuman->GetName(), pIt->GetItemTableIndex() ) ;
								return PACKET_EXE_CONTINUE ;

							}//if( pIt != NULL && pIt->IsEmpty() == FALSE )
						}
						else
						{//拷贝失败
							MsgError.SetID(ERR_NOT_ENOUGHT_EXROOM);
							pGamePlayer->SendPacket(&MsgError);
							g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 交易盒没有足够空间",	pHuman->GetName() ) ;
							return PACKET_EXE_CONTINUE ;

						}//if(result>=0)

					}
					else
					{
						MsgError.SetID(ERR_ILLEGAL);
						pGamePlayer->SendPacket(&MsgError);
						g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 没有获取到所要交易的背包物品",	pHuman->GetName() ) ;
						return PACKET_EXE_CONTINUE ;

					}//if(pItem->IsEmpty() == FALSE)

				}
				break;
			case POS_EQUIP:
				{
				}
				break;
			case POS_PET:
				{
				}
				break;
			default:
				break;
			}

		}
		break;
	case OPT_REMOVEITEM:
		{
			switch(ToType)
			{
				case POS_BAG:
					{
						Item* pIt = pExchangeContainer->GetItem(FromIndex);

						if( pIt != NULL && pIt->IsEmpty() == FALSE )
						{							
							INT BagIndex = -1;
							ItemContainer*	pBagContainer = HumanItemLogic::GetBagItemContain( pHuman,&pIt->GetGUID(), BagIndex);

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

							//从交易盒中删掉此物品
							if(g_ItemOperator.EraseItem(pExchangeContainer, FromIndex))
							{
								//解锁此物品
								g_ItemOperator.UnlockItem( pBagContainer, BagIndex );

								//标示次物品已经取消放在交易栏中,计算空间用
								pBagContainer->GetItem(BagIndex)->SetInExchange(FALSE);

								g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易物品 [%d]",	pHuman->GetName(), BagIndex) ;

								//发消息								
								if(BagIndex>=0)
								{
									/*
									先发自己
									*/
									Msg.SetIsMyself(TRUE);//发给自己
									Msg.SetOpt(OPT_REMOVEITEM);//设置操作类型
									Msg.SetToType(POS_BAG);//设置目的类型
									Msg.SetToIndex(BagIndex);//设置目的索引
									Msg.SetFromIndex(FromIndex);//设置来源索引
									pGamePlayer->SendPacket(&Msg);

									/*
									再发对方
									*/
									Msg.SetIsMyself(FALSE);//发给对方
									Msg.SetOpt(OPT_REMOVEITEM);//设置操作类型
									Msg.SetFromIndex(FromIndex);//设置来源索引
									pDestHuman->GetPlayer()->SendPacket(&Msg);

                                    //改变物品    自己解锁
                                    pHuman->m_ExchangBox.m_IsLocked = FALSE;
                                    if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE)
                                    {//如果对方已经加锁
                                        pDestHuman->m_ExchangBox.m_IsLocked = FALSE;
                                        GCExchangeSynchLock MsgToDes, MsgToSelf;

                                        //通知对方,解双方锁
                                        MsgToDes.SetIsBoth(TRUE);
                                        MsgToDes.SetIsLocked(FALSE);
                                        pDestHuman->GetPlayer()->SendPacket(&MsgToDes);

                                        //通知自己解对方锁
                                        MsgToSelf.SetIsMyself(FALSE);
                                        MsgToSelf.SetIsLocked(FALSE);
                                        pHuman->GetPlayer()->SendPacket(&MsgToSelf);

                                    }
                                    else
                                    {//对方没有加锁,直接同步
                                        GCExchangeSynchLock MsgToDes;
                                        MsgToDes.SetIsMyself (FALSE);
                                        MsgToDes.SetIsLocked(FALSE);
                                        pDestHuman->GetPlayer()->SendPacket(&MsgToDes);
                                    }
								}
								else
								{
									MsgError.SetID(ERR_ILLEGAL);
									pGamePlayer->SendPacket(&MsgError);
									return PACKET_EXE_CONTINUE;
								}

							}
							else
							{
								MsgError.SetID(ERR_ILLEGAL);
								pGamePlayer->SendPacket(&MsgError);
								g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易盒位置 [%d] 处的物品时出错",	pHuman->GetName(), FromIndex ) ;
								return PACKET_EXE_CONTINUE;
							}

						}
						else
						{
							MsgError.SetID(ERR_ILLEGAL);
							pGamePlayer->SendPacket(&MsgError);
							g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 交易盒位置 [%d] 处不存在物品",	pHuman->GetName(), FromIndex ) ;
							return PACKET_EXE_CONTINUE;
						}
					}
					break;

				case POS_EQUIP:
					{
					}
					break;

				case POS_PET:
					{
					}
					break;
				default:
					break;

			}

		}
		break;
	case OPT_ADDPET:
		{
			ItemContainer*	pPetContainer = pHuman->GetPetContain();
			FromIndex = pPetContainer->GetIndexByGUID( &PetGuid );

            if (255 == FromIndex)
            {
                g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入非法交易宠物",	pHuman->GetName()) ;
                return PACKET_EXE_CONTINUE ;
            }

			//先查一遍交易盒中是不是已经有该物品了
			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				if(pExchangePetContainer->GetItem(i)->GetPetGUID() == pPetContainer->GetItem(FromIndex)->GetPetGUID() )
				{//物品已经在交易盒中,丢弃该消息
					return PACKET_EXE_CONTINUE ;
				}
			}

			//自动找格
			INT result = 
				g_ItemOperator.CopyItem
				(
				pPetContainer,
				FromIndex,
				pExchangePetContainer
				);

			if(result>=0)
			{//拷贝成功
				Item* pIt = pExchangePetContainer->GetItem(result);
				g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入交易宠物 [%s]",	pHuman->GetName(), pIt->GetName() ) ;
				if(pIt->IsEmpty() == FALSE)
				{
					//先锁定此物品
					g_ItemOperator.LockItem( pPetContainer, FromIndex );

					//标示次物品已经放在交易栏中,计算空间用
					pPetContainer->GetItem(FromIndex)->SetInExchange(TRUE);
					/*
					先发自己
					*/
					Msg.SetIsMyself(TRUE);//发给自己
					Msg.SetOpt(OPT_ADDPET);//设置操作类型
					Msg.SetToIndex(result);//设置目的地位置
					Msg.SetPetGuid(PetGuid);//宠物GUID
					pGamePlayer->SendPacket(&Msg);

					/*
					再发对方
					*/
					GCDetailAttrib_Pet PetMsgDetail;
					//组装GCDetailAttrib_Pet结构
					Obj_Human::CalculatePetDetailAttrib(PetMsgDetail, pIt);
					PetMsgDetail.SetTradeIndex( result );

					PET_EXTRA_STRUCT::GCExchangePetView_t ExtraPetInfo;
					ExtraPetInfo.m_bFlag	=	TYPE_EXCHANGE;
					PetMsgDetail.SetExtraInfoLength(ExtraPetInfo.GetSize());
					PetMsgDetail.SetExtraInfoData((BYTE*)&ExtraPetInfo);
					pDestHuman->GetPlayer()->SendPacket(&PetMsgDetail);	

                    //改变金钱    自己解锁
                    pHuman->m_ExchangBox.m_IsLocked = FALSE;
                    if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE)
                    {//如果对方已经加锁
                        pDestHuman->m_ExchangBox.m_IsLocked = FALSE;
                        GCExchangeSynchLock MsgToDes, MsgToSelf;

                        //通知对方,解双方锁
                        MsgToDes.SetIsBoth(TRUE);
                        MsgToDes.SetIsLocked(FALSE);
                        pDestHuman->GetPlayer()->SendPacket(&MsgToDes);

                        //通知自己解对方锁
                        MsgToSelf.SetIsMyself(FALSE);
                        MsgToSelf.SetIsLocked(FALSE);
                        pHuman->GetPlayer()->SendPacket(&MsgToSelf);

                    }
                    else
                    {//对方没有加锁,直接同步
                        GCExchangeSynchLock MsgToDes;
                        MsgToDes.SetIsMyself (FALSE);
                        MsgToDes.SetIsLocked(FALSE);
                        pDestHuman->GetPlayer()->SendPacket(&MsgToDes);
                    }
				}
				else
				{
					MsgError.SetID(ERR_ILLEGAL);
					pGamePlayer->SendPacket(&MsgError);
					g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入非法交易宠物 [%s]",	pHuman->GetName(), pIt->GetName() ) ;
					return PACKET_EXE_CONTINUE ;
				}
			}
		}
		break;
	case OPT_REMOVEPET:
		{
			ItemContainer*	pPetContainer = pHuman->GetPetContain();
			INT nIndexInPet = pPetContainer->GetIndexByGUID(&PetGuid);
			FromIndex = pExchangePetContainer->GetIndexByGUID(&PetGuid);

			if(g_ItemOperator.EraseItem(pExchangePetContainer, FromIndex))
			{
				//解锁此物品
				g_ItemOperator.UnlockItem( pPetContainer, nIndexInPet );

				//标示次物品已经放在交易栏中,计算空间用
				pPetContainer->GetItem(nIndexInPet)->SetInExchange(FALSE);

				//发消息
				g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易宠物 [%s]",	pHuman->GetName(), pPetContainer->GetItem(nIndexInPet)->GetName()) ;
				if(nIndexInPet>=0)
				{
					/*
					先发自己
					*/
					Msg.SetIsMyself(TRUE);//发给自己
					Msg.SetOpt(OPT_REMOVEPET);//设置操作类型
					Msg.SetPetGuid(PetGuid);//宠物GUID
					pGamePlayer->SendPacket(&Msg);

					/*
					再发对方
					*/
					Msg.SetIsMyself(FALSE);//发给对方
					Msg.SetOpt(OPT_REMOVEPET);//设置操作类型
					Msg.SetPetGuid(PetGuid);//宠物GUID
					pDestHuman->GetPlayer()->SendPacket(&Msg);

                    //改变金钱    自己解锁
                    pHuman->m_ExchangBox.m_IsLocked = FALSE;
                    if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE)
                    {//如果对方已经加锁
                        pDestHuman->m_ExchangBox.m_IsLocked = FALSE;
                        GCExchangeSynchLock MsgToDes, MsgToSelf;

                        //通知对方,解双方锁
                        MsgToDes.SetIsBoth(TRUE);
                        MsgToDes.SetIsLocked(FALSE);
                        pDestHuman->GetPlayer()->SendPacket(&MsgToDes);

                        //通知自己解对方锁
                        MsgToSelf.SetIsMyself(FALSE);
                        MsgToSelf.SetIsLocked(FALSE);
                        pHuman->GetPlayer()->SendPacket(&MsgToSelf);

                    }
                    else
                    {//对方没有加锁,直接同步
                        GCExchangeSynchLock MsgToDes;
                        MsgToDes.SetIsMyself (FALSE);
                        MsgToDes.SetIsLocked(FALSE);
                        pDestHuman->GetPlayer()->SendPacket(&MsgToDes);
                    }
				}
				else
				{
					MsgError.SetID(ERR_ILLEGAL);
					pGamePlayer->SendPacket(&MsgError);
					return PACKET_EXE_CONTINUE;
				}
			}
			else
			{
				MsgError.SetID(ERR_ILLEGAL);
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易盒位置 [%d] 处的物品时出错",	pHuman->GetName(), FromIndex ) ;
				return PACKET_EXE_CONTINUE;
			}
		}
		break;
	default:
		break;
	}
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
uint CGStallAddItemHandler::Execute( CGStallAddItem* 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 ) ;

	//操作
	_ITEM_GUID	ItemGuid = pPacket->GetObjGUID();
	UINT		ItemPrice = pPacket->GetPrice();
	BYTE		FromType = pPacket->GetFromType();
	PET_GUID_t	PetGuid  = pPacket->GetPetGUID();

	if(pHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
	{
		GCStallError	Msg;
		Msg.SetID(STALL_MSG::ERR_ILLEGAL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d ERR_ILLEGAL: != ServerStallBox::STALL_OPEN", pHuman->GetID()) ;
		return PACKET_EXE_CONTINUE ;
	}
	
	ItemContainer*		pStallContainer		= pHuman->m_StallBox.GetContainer();
	ItemContainer*		pStallPetContainer	= pHuman->m_StallBox.GetPetContainer();

	GCStallError		MsgError;
	GCStallAddItem		MsgAddItem;

	switch(FromType)
	{
	case STALL_MSG::POS_BAG :
		{
			//ItemContainer* pMatContainer	= pHuman->GetMatContain();
			ItemContainer* pBaseContainer	= pHuman->GetBaseContain();
			//ItemContainer* pBagContainer	=	NULL;

			//if(pMatContainer->GetIndexByGUID(&ItemGuid) >= 0)
			//{
			//	pBagContainer = pMatContainer;
			//}
			//else if(pBaseContainer->GetIndexByGUID(&ItemGuid) >=0 )
			//{
			//	pBagContainer = pBaseContainer;
			//}
			//else
			//{//guid非法
			//	Assert(0);
			//	GCStallError	Msg;
			//	Msg.SetID(STALL_MSG::ERR_ILLEGAL);
			//	pGamePlayer->SendPacket(&Msg);
			//	g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, ERR_ILLEGAL:World = %d, Server = %d, Serial = %d "
			//		,pHuman->GetID(), ItemGuid.m_World, ItemGuid.m_Server, ItemGuid.m_Serial) ;
			//	return PACKET_EXE_CONTINUE ;
			//}

			INT	IndexInBag = pBaseContainer->GetIndexByGUID(&ItemGuid);
			
			//先查一遍摊位盒中是不是已经有该物品了
			for(INT i = 0; i<STALL_BOX_SIZE; i++)
			{
				if(pStallContainer->GetItem(i)->GetGUID() == ItemGuid )
				{//物品已经在t摊位盒中,丢弃该消息
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, Already in box "
						,pHuman->GetID()) ;
					return PACKET_EXE_CONTINUE ;
				}
			}

			//拷贝到摊位盒
			//自动找格
			INT result = 
				g_ItemOperator.CopyItem
				(
				pBaseContainer,
				IndexInBag,
				pStallContainer
				);

			if(result>=0)
			{//拷贝成功,
				//发送消息给双方客户端
				Item* pIt = pStallContainer->GetItem(result);
				if(pIt->IsEmpty() == FALSE)
				{
					//先锁定此物品
					g_ItemOperator.LockItem( pBaseContainer, IndexInBag );

					//设置价格
					pHuman->m_StallBox.SetPriceByIndex(result, ItemPrice);

					//序列号递增
					pHuman->m_StallBox.IncSerialByIndex(result);

					//发送消息给客户端
					MsgAddItem.SetFromType( STALL_MSG::POS_BAG );
					MsgAddItem.SetToIndex(result);
					MsgAddItem.SetPrice(ItemPrice);
					MsgAddItem.SetObjGUID(ItemGuid);
					MsgAddItem.SetSerial(pHuman->m_StallBox.GetSerialByIndex(result));

					pGamePlayer->SendPacket(&MsgAddItem);
				}
				else
				{
					MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
					pGamePlayer->SendPacket(&MsgError);
					pHuman->m_StallBox.CleanUp();
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, ERR_ILLEGAL: pIt->IsEmpty() == FALSE"
						,pHuman->GetID()) ;
					return PACKET_EXE_CONTINUE ;
				}
			}
			else
			{//拷贝失败
				if(result == ITEMOE_DESTOPERATOR_FULL)
				{
					MsgError.SetID(STALL_MSG::ERR_NOT_ENOUGH_ROOM_IN_STALL);
					pGamePlayer->SendPacket(&MsgError);
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, ERR_NOT_ENOUGH_ROOM_IN_STALL"
						,pHuman->GetID()) ;
					return PACKET_EXE_CONTINUE ;
				}
				else if(result == ITEMOE_SOUROPERATOR_LOCK)
				{
					MsgError.SetID(STALL_MSG::ERR_ALREADY_LOCK);
					pGamePlayer->SendPacket(&MsgError);
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, ERR_ALREAD_LOCK"
						,pHuman->GetID()) ;
					return PACKET_EXE_CONTINUE ;
				}
			}

		}
		break;

	case STALL_MSG::POS_EQUIP :
		{
		}
		break;

	case STALL_MSG::POS_PET :
		{//从宠物列表中拿出宠物到交易盒中
			ItemContainer*	pPetContainer = pHuman->GetPetContain();
			BYTE	FromIndex = pPetContainer->GetIndexByGUID( &PetGuid );

			//先查一遍交易盒中是不是已经有该物品了
			for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
			{
				if(pStallPetContainer->GetItem(i)->GetPetGUID() == pPetContainer->GetItem(FromIndex)->GetPetGUID() )
				{//物品已经在交易盒中,丢弃该消息
					return PACKET_EXE_CONTINUE ;
				}
			}

			//自动找格
			INT result = 
				g_ItemOperator.CopyItem
				(
				pPetContainer,
				FromIndex,
				pStallPetContainer
				);

			if(result>=0)
			{//拷贝成功,
				//发送消息给双方客户端
				Item* pIt = pStallPetContainer->GetItem(result);
				if(pIt->IsEmpty() == FALSE)
				{
					//先锁定此物品
					g_ItemOperator.LockItem( pPetContainer, FromIndex );

					//设置价格
					pHuman->m_StallBox.SetPetPriceByIndex(result, ItemPrice);

					//序列号递增
					pHuman->m_StallBox.IncPetSerialByIndex(result);

					//发送消息给客户端
					MsgAddItem.SetFromType( STALL_MSG::POS_PET );
					MsgAddItem.SetToIndex(result);
					MsgAddItem.SetPrice(ItemPrice);
					MsgAddItem.SetPetGUID(PetGuid);
					MsgAddItem.SetSerial(pHuman->m_StallBox.GetPetSerialByIndex(result));

					pGamePlayer->SendPacket(&MsgAddItem);
				}
				else
				{
					MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
					pGamePlayer->SendPacket(&MsgError);
					pHuman->m_StallBox.CleanUp();
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjName=%s, ERR_ILLEGAL: pIt->IsEmpty() == FALSE"
						,pHuman->GetName()) ;
					return PACKET_EXE_CONTINUE ;
				}
			}
			else
			{//拷贝失败
				if(result == ITEMOE_DESTOPERATOR_FULL)
				{
					MsgError.SetID(STALL_MSG::ERR_NOT_ENOUGH_ROOM_IN_STALL);
					pGamePlayer->SendPacket(&MsgError);
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjName=%d, ERR_NOT_ENOUGH_ROOM_IN_STALL"
						,pHuman->GetName()) ;
					return PACKET_EXE_CONTINUE ;
				}
				else if(result == ITEMOE_SOUROPERATOR_LOCK)
				{
					MsgError.SetID(STALL_MSG::ERR_ALREADY_LOCK);
					pGamePlayer->SendPacket(&MsgError);
					g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjName=%d, ERR_ALREAD_LOCK"
						,pHuman->GetName()) ;
					return PACKET_EXE_CONTINUE ;
				}
			}
		}
		break;

	default:
		break;
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGStallAddItemHandler::ObjName=%d"
		,pHuman->GetName()) ;
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
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));
			if(pEquipItem->IsEmpty())
			{
				nResult = EQUIPLEVEUP_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "Obj_Human::EquipLevelup pEquipItem is Null at  BagIndex= %d", BagIndex) ;
				return PACKET_EXE_CONTINUE;
			}
			
			if (pEquipItem->GetItemClass() != ICLASS_EQUIP)
			{
				nResult = EQUIPLEVEUP_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "EquipLevelup GetItemClass is not ICLASS_EQUIP ") ;
				return PACKET_EXE_CONTINUE;
			}

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

			if (pEquipItem->GetItemType() > EQUIP_ADORN)
			{
				nResult = EQUIPLEVEUP_EQUIP_FAIL;
				Msg.SetResult(nResult);
				pGamePlayer->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "Obj_Human::EquipLevelup GUID is different ") ;
				return PACKET_EXE_CONTINUE;
			}
		}
		break;
	default:
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: EquipFromType error, EquipFromType=%d", pPacket->GetEquipPosType()) ;
			return PACKET_EXE_ERROR;
		}
		break;
	}

	INT nCurLevel = pEquipItem->GetCurLevel();
	if(nCurLevel >=MAX_EQUIP_LEVELUP_NUM)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler LEVEL full ") ;
		nResult = EQUIPLEVEUP_FULL_FAIL;
		Msg.SetResult(nResult);
		pGamePlayer->SendPacket( &Msg ) ;
		return PACKET_EXE_CONTINUE;
	}


	nResult = (EQUIPLEVEUP_RESULT)pHuman->EquipLevelup(pEquipItem, pPacket->getGemID(), pPacket->GetGemNum());

	if(nResult == EQUIPLEVEUP_FAIL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: pHuman->AddHole Fail") ;
		return PACKET_EXE_ERROR;
	}

	Msg.SetResult(nResult);
	pGamePlayer->SendPacket( &Msg ) ;
	//////////////////////////////////////////////////////////////////////////

	if((nResult == EQUIPLEVEUP_SUCCESS)||(nResult == EQUIPLEVEUP_FAIL_SUCCESS))
	{
		if(pPacket->GetEquipPosType() == ENUM_EQUIP_POINT)
		{
			pHuman->ItemEffectFlush();

			pHuman->SetEquipVer(pHuman->GetEquipVer()+1);
			INT Equip_Point = pPacket->GetPos();
			UINT RetPart = 0;
			GCDetailEquipList	SelfMsg;
			SelfMsg.setObjID( pHuman->GetID() );
			Item* pEquipItem = HumanItemLogic::GetEquip(pHuman, (HUMAN_EQUIP)Equip_Point);
			if(!pEquipItem)
			{
				Assert(FALSE);
			}
			if(pEquipItem->IsEmpty()) 
			{
				Assert(FALSE);
			}
			pEquipItem->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)Equip_Point));
			RetPart|=(1<<((UINT)Equip_Point));
			SelfMsg.SetAskPart(RetPart);
			pGamePlayer->SendPacket( &SelfMsg ) ;
		}
		else
		{
			GCItemInfo	EquipMsg;
			EquipMsg.setIsNull(FALSE);
			EquipMsg.setID(BagIndex);
			pEquipItem->SaveValueTo(EquipMsg.getItem());
			pHuman->GetPlayer()->SendPacket(&EquipMsg);
		}
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: success nResult=%d", nResult ) ;
	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR;
}
Beispiel #17
0
uint CGEquipSuitExchangeHandler::Execute(CGEquipSuitExchange* 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 ;
	}

	//切场景时丢弃换装消息
	if(pGamePlayer->GetPlayerStatus()!=PS_SERVER_NORMAL ||
		!pHuman->IsActiveObj() )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: change scene") ;
		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 ;
	}

	UINT  nSuitNum = pPacket->getEquipSuitNum();

	if( nSuitNum > MAX_EQUIP_SUIT_NUM )
	{
		return PACKET_EXE_ERROR ;
	}

	ItemContainer* pEquipContainer = pHuman->GetEquipContain();
	
	Assert(pEquipContainer);
	_SUIT_SETTING suitSetting = pHuman->GetEquipSuitSetting(nSuitNum);

	GCEquipSuitExchangeResult Msg;
	GCDetailEquipList	SelfMsg;
	GCCharEquipment OtherMsg;
	SelfMsg.setObjID( pHuman->GetID() );
	BOOL bChange = FALSE;
	UINT RetPart = 0;

	//遍历所有套装
	for(INT i=0; i<HEQUIP_NUMBER; ++i)
	{
		//存在套装数据
		if(!suitSetting.m_EquipData[i].isNull())
		{
			//检查装备栏
			Item* pEquip = pEquipContainer->GetItem(i);
			Assert(pEquip);

			//装备有变化,装备栏数据与保存的对应位置套装信息不一致,需要到背包里找
			if(!(pEquip->GetGUID() == suitSetting.m_EquipData[i]))
			{
				INT nPos = INVALID_INDEX;
				ItemContainer* pBagContainer = HumanItemLogic::GetBagItemContain(pHuman, &suitSetting.m_EquipData[i], nPos);
				//背包里也找不到,需记录下来(卖掉了?丢掉了?。。)
				if(nPos == INVALID_INDEX)
				{
					EXCHANGE_EQUIP_INFO ExchangeInfo;
					ExchangeInfo.m_BagIndex = INVALID_ITEM_POS;
					ExchangeInfo.m_EquipPoint	= INVALID_ITEM_POS;
					Msg.setEquipInfo(ExchangeInfo, i);
					continue;
				}
				
				//找到了
				Item*	pExchangeItem = HumanItemLogic::GetBagItem(pHuman, nPos);
				
				Assert(pExchangeItem->GetItemClass() == ICLASS_EQUIP);
				if(pExchangeItem->GetEquipPoint() != i)
				{
					if(pExchangeItem->GetEquipPoint() == HEQUIP_RING1)
					{
						Assert(i == HEQUIP_RING2);
					}
					else if(pExchangeItem->GetEquipPoint() == HEQUIP_ADORN1)
					{
						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)
				{
					Assert(FALSE);
					return PACKET_EXE_CONTINUE;
				}
				Assert(!pEquipItem->IsEmpty()); 

				pEquipItem->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)i));
				RetPart|=(1<<((UINT)i));
				SelfMsg.SetAskPart(RetPart);
				RetPart = 0;
				//如果可见
				if(pHuman->IsVisualPart((HUMAN_EQUIP)i))
				{	
					OtherMsg.setObjID(pHuman->GetID());
					OtherMsg.setID((HUMAN_EQUIP)i, pEquipItem->GetItemTableIndex());
				}

				//换装了
				bChange = TRUE;
			}

			//装备正穿着呢,不需要通知
			continue;
		}
		else
		{
			//根本没有呀
			EXCHANGE_EQUIP_INFO ExchangeInfo;
			ExchangeInfo.m_BagIndex = INVALID_ITEM_POS;
			ExchangeInfo.m_EquipPoint	= i;
			Msg.setEquipInfo(ExchangeInfo, i);
		}
	}

	
	if(bChange)
	{
		Msg.setResult(EQUIPSUIT_SUCCESS);
		pGamePlayer->SendPacket(&Msg);
		pGamePlayer->SendPacket( &SelfMsg ) ;
		pScene->BroadCast(&OtherMsg,pHuman,TRUE);
		pHuman->SetEquipVer(pHuman->GetEquipVer()+1);
		//刷新装备对人物的属性影响

		pHuman->ItemEffectFlush();
	}
	else
	{
		Msg.setResult(EQUIPSUIT_SUCCESS);
		pGamePlayer->SendPacket(&Msg);
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: nSuitNum=%d", nSuitNum ) ;

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
uint CGStallRemoveItemHandler::Execute( CGStallRemoveItem* 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 ) ;

	_ITEM_GUID	ItemGuid	= pPacket->GetObjGUID();
	PET_GUID_t  PetGuid		= pPacket->GetPetGUID();
	BYTE		ToType		= pPacket->GetToType();
	UINT		Serial		= pPacket->GetSerial();

	if(pHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
	{
		GCStallError	Msg;
		Msg.SetID(STALL_MSG::ERR_ILLEGAL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: != ServerStallBox::STALL_OPEN"
			,pHuman->GetName()) ;
		return PACKET_EXE_CONTINUE;
	}

	ItemContainer*			pStallContainer		= pHuman->m_StallBox.GetContainer();
	ItemContainer*			pStallPetContainer	= pHuman->m_StallBox.GetPetContainer();
	GCStallError			MsgError;
	GCStallRemoveItem		MsgRemoveItem;

	switch(ToType)
	{
	case STALL_MSG::POS_BAG:
		{
			INT	IndexInStall = pStallContainer->GetIndexByGUID(&ItemGuid);
			if(IndexInStall<0)
			{
				MsgError.SetID(STALL_MSG::ERR_NEED_NEW_COPY);
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_NEED_NEW_COPY: IndexInStall = %d"
					,pHuman->GetName(), IndexInStall) ;
				return PACKET_EXE_CONTINUE;
			}

			if( pHuman->m_StallBox.GetSerialByIndex(IndexInStall) > Serial)
			{
				MsgError.SetID(STALL_MSG::ERR_NEED_NEW_COPY);
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_NEED_NEW_COPY: Serial = %d, BoxSerial = %d"
					,pHuman->GetName(), Serial, pHuman->m_StallBox.GetSerialByIndex(IndexInStall)) ;
				return PACKET_EXE_CONTINUE;
			}

			Item* pItem =	pStallContainer->GetItem(IndexInStall);
			
			ItemContainer* pBagContainer = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex());
			INT	IndexInBag = pBagContainer->GetIndexByGUID(&ItemGuid);
			if(IndexInBag<0)
			{
				MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
				pHuman->m_StallBox.CleanUp();
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: IndexInBag = %d"
					,pHuman->GetName(), IndexInBag) ;
				return PACKET_EXE_CONTINUE;
			}

			//解锁原背包中的物品
			g_ItemOperator.UnlockItem( pBagContainer, IndexInBag );

			//干掉物品
			if(g_ItemOperator.EraseItem(pStallContainer, IndexInStall)>0)
			{
				pHuman->m_StallBox.IncSerialByIndex(IndexInStall);
				pHuman->m_StallBox.SetPriceByIndex(IndexInStall, 0);
			}
			else
			{
				MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
				pHuman->m_StallBox.CleanUp();
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: IndexInStall = %d"
					,pHuman->GetName(), IndexInStall) ;
				return PACKET_EXE_CONTINUE;
			}

			//通知客户端
			MsgRemoveItem.SetObjGUID( ItemGuid );
			MsgRemoveItem.SetSerial( pHuman->m_StallBox.GetSerialByIndex(IndexInStall) );
			MsgRemoveItem.SetToType( STALL_MSG::POS_BAG );

			pGamePlayer->SendPacket(&MsgRemoveItem);
	
		}
		break;
	case STALL_MSG::POS_EQUIP:
		{
		}
		break;
	case STALL_MSG::POS_PET:
		{
			INT	IndexInStall = pStallPetContainer->GetIndexByGUID(&PetGuid);
			if(IndexInStall<0)
			{
				MsgError.SetID(STALL_MSG::ERR_NEED_NEW_COPY);
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_NEED_NEW_COPY: IndexInStall = %d"
					,pHuman->GetName(), IndexInStall) ;
				return PACKET_EXE_CONTINUE;
			}

			if( pHuman->m_StallBox.GetPetSerialByIndex(IndexInStall) > Serial)
			{
				MsgError.SetID(STALL_MSG::ERR_NEED_NEW_COPY);
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_NEED_NEW_COPY: Serial = %d, BoxSerial = %d"
					,pHuman->GetName(), Serial, pHuman->m_StallBox.GetPetSerialByIndex(IndexInStall)) ;
				return PACKET_EXE_CONTINUE;
			}

			ItemContainer*	pPetContainer = pHuman->GetPetContain();
			INT	IndexInBag = pPetContainer->GetIndexByGUID(&PetGuid);
			if(IndexInBag<0)
			{
				MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
				pHuman->m_StallBox.CleanUp();
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: IndexInBag = %d"
					,pHuman->GetName(), IndexInBag) ;
				return PACKET_EXE_CONTINUE;
			}

			//解锁原背包中的物品
			g_ItemOperator.UnlockItem( pPetContainer, IndexInBag );

			//干掉物品
			if(g_ItemOperator.EraseItem(pStallPetContainer, IndexInStall)>0)
			{
				pHuman->m_StallBox.IncPetSerialByIndex(IndexInStall);
				pHuman->m_StallBox.SetPetPriceByIndex(IndexInStall, 0);
			}
			else
			{
				MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
				pHuman->m_StallBox.CleanUp();
				pGamePlayer->SendPacket(&MsgError);
				g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: IndexInStall = %d"
					,pHuman->GetName(), IndexInStall) ;
				return PACKET_EXE_CONTINUE;
			}

			//通知客户端
			MsgRemoveItem.SetPetGUID( PetGuid );
			MsgRemoveItem.SetSerial( pHuman->m_StallBox.GetPetSerialByIndex(IndexInStall) );
			MsgRemoveItem.SetToType( STALL_MSG::POS_PET );

			pGamePlayer->SendPacket(&MsgRemoveItem);

		}
		break;
	default:
		break;
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGStallRemoveItemHandler::ObjName=%s, m_World = %d, m_Server = %d, m_Serial = %d"
		,pHuman->GetName(), ItemGuid.m_World, ItemGuid.m_Server, ItemGuid.m_Serial) ;
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Beispiel #19
0
uint CGSaveEquipSuitHandler::Execute(CGSaveEquipSuit* 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 nSuitNum = pPacket->getSuitNum();
	if(nSuitNum>MAX_EQUIP_SUIT_NUM)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: nSuitNum=%d", nSuitNum ) ;
		return PACKET_EXE_ERROR ;
	}
	ItemContainer* pItemContainer = pHuman->GetEquipContain();
	Assert(pItemContainer);
	BOOL bDataValid = TRUE;
	BYTE nResult = EQUIPSUIT_EQUIP_FAIL;
	GCSaveEquipSuitResult Msg;
	_SUIT_SETTING suitSetting = pPacket->getSuitSetting();
	for(INT i=0; i<HEQUIP_NUMBER; ++i)
	{
		//有数据
		if(!suitSetting.m_EquipData[i].isNull())
		{
			Item* pEquip = pItemContainer->GetItem(i);
			Assert(pEquip);

			//装备点有数据
			if(!pEquip->IsEmpty())
			{
				if(!(pEquip->GetGUID() == suitSetting.m_EquipData[i]))
				{
					//检查背包里有没有
					UINT nPos = HumanItemLogic::GetBagItemPosByGUID(pHuman, suitSetting.m_EquipData[i]);

					//找不到
					if(nPos == INVALID_INDEX)
					{
						bDataValid = FALSE;
						break;
					}
					//从背包里找到
					Item* pUseItem = HumanItemLogic::GetBagItem(pHuman ,nPos);

					//判断类型
					if(pUseItem->GetItemClass() != ICLASS_EQUIP)
					{
						g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: Equip is not ICLASS_EQUIP, EquipPoint=%d", i ) ;
						return PACKET_EXE_ERROR ;
					}
					//判断装备点
					if(pUseItem->GetEquipPoint() != i)
					{
						if(pUseItem->GetEquipPoint() == HEQUIP_RING1)
						{
							if((i != HEQUIP_RING1)&&(i != HEQUIP_RING2))
							{
								g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EquipPoint error , pUseItem->GetEquipPoint()=%d", pUseItem->GetEquipPoint() ) ;
								return PACKET_EXE_ERROR ;
							}
						}
						else if(pUseItem->GetEquipPoint() == HEQUIP_ADORN1)
						{
							if((i != HEQUIP_ADORN1)&&(i != HEQUIP_ADORN2))
							{
								g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EquipPoint error , pUseItem->GetEquipPoint()=%d", pUseItem->GetEquipPoint() ) ;
								return PACKET_EXE_ERROR ;
							}
						}
						else
						{
							g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EquipPoint error , pUseItem->GetEquipPoint()=%d", pUseItem->GetEquipPoint() ) ;
							return PACKET_EXE_ERROR ;
						}
					}
					//判断等级
					if(pUseItem->GetRequireLevel() > pHuman->GetLevel() )
					{
						nResult = EQUIPSUIT_LEVEL;
						Msg.setResult(nResult);
						Msg.setSuitNum(0);
						pGamePlayer->SendPacket(&Msg);
						g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: Equiplevel , pUseItem->GetRequireLevel()=%d", pUseItem->GetRequireLevel() ) ;
						return PACKET_EXE_CONTINUE;
					}
					//判断职业
					if(!pUseItem->IsWuMenPai())
					{
						if(!pUseItem->InReqJob(pHuman->GetMenPai()))
						{
							nResult = EQUIPSUIT_JOB_FAIL;
							Msg.setResult(nResult);
							Msg.setSuitNum(0);
							pGamePlayer->SendPacket(&Msg);
							g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: ReqJob , pUseItem->GetReqJob ") ;

							return PACKET_EXE_CONTINUE;
						}
					}

					//来自背包正常数据,继续下一个查询
					continue;
				}
			}

			//装备点没有数据,要检查背包
			else
			{
				//检查背包里有没有
				UINT nPos = HumanItemLogic::GetBagItemPosByGUID(pHuman, suitSetting.m_EquipData[i]);

				//找不到
				if(nPos == INVALID_INDEX)
				{
					bDataValid = FALSE;
					break;
				}
				//从背包里找到
				Item* pUseItem = HumanItemLogic::GetBagItem(pHuman ,nPos);

				//判断类型
				if(pUseItem->GetItemClass() != ICLASS_EQUIP)
				{
					g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: Equip is not ICLASS_EQUIP, EquipPoint=%d", i ) ;
					return PACKET_EXE_ERROR ;
				}
				//判断装备点
				if(pUseItem->GetEquipPoint() != i)
				{
					if(pUseItem->GetEquipPoint() == HEQUIP_RING1)
					{
						if((i != HEQUIP_RING1)&&(i != HEQUIP_RING2))
						{
							g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EquipPoint error , pUseItem->GetEquipPoint()=%d", pUseItem->GetEquipPoint() ) ;
							return PACKET_EXE_ERROR ;
						}
					}
					else if(pUseItem->GetEquipPoint() == HEQUIP_ADORN1)
					{
						if((i != HEQUIP_ADORN1)&&(i != HEQUIP_ADORN2))
						{
							g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EquipPoint error , pUseItem->GetEquipPoint()=%d", pUseItem->GetEquipPoint() ) ;
							return PACKET_EXE_ERROR ;
						}
					}
					else
					{
						g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EquipPoint error , pUseItem->GetEquipPoint()=%d", pUseItem->GetEquipPoint() ) ;
						return PACKET_EXE_ERROR ;
					}
				}
				//判断等级
				if(pUseItem->GetRequireLevel() > pHuman->GetLevel() )
				{
					nResult = EQUIPSUIT_LEVEL;
					Msg.setResult(nResult);
					Msg.setSuitNum(0);
					pGamePlayer->SendPacket(&Msg);
					g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: Equiplevel , pUseItem->GetRequireLevel()=%d", pUseItem->GetRequireLevel() ) ;
					return PACKET_EXE_CONTINUE;
				}
				//判断职业
				if(!pUseItem->IsWuMenPai())
				{
					if(!pUseItem->InReqJob(pHuman->GetMenPai()))
					{
						nResult = EQUIPSUIT_JOB_FAIL;
						Msg.setResult(nResult);
						Msg.setSuitNum(0);
						pGamePlayer->SendPacket(&Msg);
						g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: ReqJob ") ;

						return PACKET_EXE_CONTINUE;
					}
				}
			}
		}
	}
	
	//存在无效数据
	if(bDataValid == FALSE)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: EQUIP don't exsist " ) ;

		return PACKET_EXE_CONTINUE; ;
	}
	//保存
	pHuman->SetEquipSuitSetting(suitSetting, nSuitNum);

	nResult = EQUIPSUIT_SUCCESS;

	Msg.setResult(nResult);
	Msg.setSuitNum(nSuitNum);
	Msg.setSuitSetting(pHuman->GetEquipSuitSetting(nSuitNum));
	pGamePlayer->SendPacket(&Msg);
	g_pLog->FastSaveLog( LOG_FILE_1, "CGSaveEquipSuitHandler: nSuitNum=%d", nSuitNum ) ;

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Beispiel #20
0
uint CGPackage_SwapItemHandler :: Execute( CGPackage_SwapItem* 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 ) ;

	//得到所要交换的两个索引
	INT index1 = pPacket->GetPackageIndex1();
	INT index2 = pPacket->GetPackageIndex2();

	INT bSucc = -1;
	GCPackage_SwapItem msg;
	//扩展包互换 禁止
	if ((index1>=EXTRA_CONTAINER_OFFSET)&&(index2>=EXTRA_CONTAINER_OFFSET))
	{
		msg.SetResult(SWITCHITEM_EXTRBAG_EXCHANGE_FAIL);
		pGamePlayer->SendPacket(&msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d extrabag fail", 
			index1, index2) ;
		return PACKET_EXE_CONTINUE;
	}
	if (index1>=EXTRA_CONTAINER_OFFSET)
	{
		ItemContainer* pExtraBagContainer = HumanItemLogic::GetBagByExtraContainPos(pHuman, index1);
		//位置无效
		if (pExtraBagContainer == NULL)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, is invalid", index1) ;
			return PACKET_EXE_ERROR;
		}
		//扩展包不存在
		if (!pExtraBagContainer->IsValid())
		{
			msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_NOALIVE);
			pGamePlayer->SendPacket(&msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, extrabag is not alive", index1) ;
			return PACKET_EXE_CONTINUE;
		}
		//非空扩展包不许移动
		if (!pExtraBagContainer->IsEmpty())
		{
			msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_ITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, extrabag has items", index1) ;
			return PACKET_EXE_CONTINUE;
		}
		ItemContainer* pExtraContainer = pHuman->GetExtraContain();

		INT index_container1 = pExtraContainer->BagIndex2ConIndex(index1);
		
		ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, index2);
		INT index_container2 = pBagContainer->BagIndex2ConIndex(index2);
		
		if (pExtraBagContainer->IsInContainer(index2))
		{
			return PACKET_EXE_CONTINUE; 
		}
		Item* pItem2 = pBagContainer->GetItem(index_container2);

		//不能将扩展包移动到有物品位置
		if (!pItem2->IsEmpty())
		{
			msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_ITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, extrabag has items", index1) ;
			return PACKET_EXE_CONTINUE;
		}
		
		bSucc = g_ItemOperator.MoveItem(pExtraContainer, index_container1, pBagContainer, index_container2);
		if (bSucc>=0)
		{
			pHuman->ReInitExtraBag();
			msg.SetResult(SWITCHITEM_SUCCESS);
			msg.SetPackageIndex1(index1);
			msg.SetPackageIndex2(index2);

			pGamePlayer->SendPacket(&msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Success", 
				index1, index2 ) ;
			return PACKET_EXE_CONTINUE;
		}
	}
	if ((index2>=EXTRA_CONTAINER_OFFSET)&&(index2<BASE_BAG_POS))
	{
		ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, index1);
		Item* pItem1 = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(index1));
		if (pItem1->IsEmpty())
		{
			return PACKET_EXE_CONTINUE;
		}
		ItemContainer* pExtraContainer = pHuman->GetExtraContain();

		//将物品放入扩展包
		ItemContainer* pExtraBagContainer = HumanItemLogic::GetBagByExtraContainPos(pHuman, index2);
		if (pExtraBagContainer == NULL)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index2=%d, is invalid", index2) ;
			return PACKET_EXE_ERROR;
		}

		INT index_container1 = pBagContainer->BagIndex2ConIndex(index1);
		INT index_container2 = pExtraContainer->BagIndex2ConIndex(index2);

		//扩展包不存在
		if (!pExtraBagContainer->IsValid())
		{
			if (pItem1->GetItemClass() == ICLASS_EXTRABAG)
			{
				INT ret = g_ItemOperator.MoveItem(pBagContainer, index_container1, 
					pExtraContainer, index_container2);
				if (ret>=0)
				{
					msg.SetResult(SWITCHITEM_SUCCESS);
					msg.SetPackageIndex1(index1);
					msg.SetPackageIndex2(index2);
					pGamePlayer->SendPacket(&msg);
					
					Item* pDestItem = pExtraContainer->GetItem(index_container2);
					Assert(pDestItem);
					if (pDestItem->GetExtraBagBeginTime() == INVALID_TIME)
					{
						pDestItem->SetExtraBagBeginTime();
					}
					pHuman->ReInitExtraBag();

					g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: use extrabagitem, index2=%d ", index2 ) ;
					return PACKET_EXE_CONTINUE;
				}
				msg.SetResult(SWITCHITEM_FAIL);
				pGamePlayer->SendPacket(&msg);
				return PACKET_EXE_CONTINUE;
			}
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index2=%d, can't put", index2) ;
			return PACKET_EXE_CONTINUE;
		}
		if (pExtraBagContainer->IsInContainer(index1))
		{
			return PACKET_EXE_CONTINUE;
		}
		if (pExtraBagContainer->IsCanUse())
		{
			INT nBagIndex = -1;
			nBagIndex =g_ItemOperator.MoveItem(pBagContainer, index_container1, pExtraBagContainer, -1);
			if (nBagIndex>=0)
			{
				msg.SetResult(SWITCHITEM_SUCCESS);
				msg.SetPackageIndex1(index1);
				msg.SetPackageIndex2(pExtraBagContainer->ConIndex2BagIndex(nBagIndex));
				pGamePlayer->SendPacket(&msg);
				g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Success", 
					index1, index2 ) ;
				return PACKET_EXE_CONTINUE;
			}
			msg.SetResult(SWITCHITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			return PACKET_EXE_CONTINUE;
		}
		msg.SetResult(SWITCHITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}
	if (index2 == BASE_BAG_POS)
	{
		if (index1<MAX_SINGLEBAG_SIZE)
		{
			return PACKET_EXE_CONTINUE;
		}
		
		ItemContainer* pBagContainer = pHuman->GetBaseContain();
		ItemContainer* pExtraBagContainer = HumanItemLogic::GetBagContainer(pHuman, index1);
		if (pExtraBagContainer == NULL)
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d fail", 
				index1, index2 ) ;
			return PACKET_EXE_ERROR;
		}
		INT index_container1 = pExtraBagContainer->BagIndex2ConIndex(index1);
		INT nBagIndex = -1;
		nBagIndex =g_ItemOperator.MoveItem(pExtraBagContainer, index_container1, pBagContainer, -1);
		if (nBagIndex>=0)
		{
			msg.SetResult(SWITCHITEM_SUCCESS);
			msg.SetPackageIndex1(index1);
			msg.SetPackageIndex2(pBagContainer->ConIndex2BagIndex(nBagIndex));
			pGamePlayer->SendPacket(&msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Success", 
				index1, index2 ) ;
			return PACKET_EXE_CONTINUE;
		}

		msg.SetResult(SWITCHITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
		
	}
	//调用物品底层交换物品
	Item* pItem1 = HumanItemLogic::GetBagItem(pHuman, index1);
	Item* pItem2 = HumanItemLogic::GetBagItem(pHuman, index2);

	if ((pItem1==NULL)||(pItem2==NULL))
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d pos fail", 
			index1, index2) ;
		return PACKET_EXE_ERROR;
	}

	//判断是否在同一个容器内
	ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, index1);
	if(pBagContainer != HumanItemLogic::GetBagContainer(pHuman, index2)) return PACKET_EXE_CONTINUE;
	
	if (!pBagContainer->IsCanUse())
	{
		msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_ITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}
	//转换Index基数
	INT index_container1 = pBagContainer->BagIndex2ConIndex(index1);
	INT index_container2 = pBagContainer->BagIndex2ConIndex(index2);

	//两个物品格都是空格
	if(pItem1->IsEmpty() && pItem2->IsEmpty())
	{
		return PACKET_EXE_CONTINUE;
	}
	// Item1 -> Item2(EMPTY)
	else if(!(pItem1->IsEmpty()) && pItem2->IsEmpty())
	{
		bSucc = g_ItemOperator.MoveItem(pBagContainer, index_container1, pBagContainer, index_container2) >= 0;
	}
	// Item1(EMPTY) <- Item2
	else if(pItem1->IsEmpty() && !(pItem2->IsEmpty()))
	{
		bSucc = g_ItemOperator.MoveItem(pBagContainer, index_container2, pBagContainer, index_container1) >= 0;
	}
	// Item1 <-> Item2
	else
	{
		ITEM_LOG_PARAM	ItemLogParam;

		//合并相同的物品
		//1、判断两个物品是不是可以叠加的
		if(pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->IsCanLay())
		{
			int Count  = pItem1->GetLayedNum();
			//2、转移物品
			if(g_ItemOperator.MoveItem(pBagContainer, index_container1, index_container2) >= 0)
			{
				//合并成功,将结果通知客户端,不能只发送Index,需要包括内容;
				_ITEM temp1;
				pItem1->SaveValueTo(&temp1);
				GCItemInfo msg1;
				msg1.setID(index1);
				msg1.setIsNull(pItem1->IsEmpty());
				msg1.setItem(&temp1);
				pGamePlayer->SendPacket(&msg1);

				_ITEM temp2;
				pItem2->SaveValueTo(&temp2);
				GCItemInfo msg2;
				msg2.setID(index2);
				msg2.setIsNull(pItem2->IsEmpty());
				msg2.setItem(&temp2);
				pGamePlayer->SendPacket(&msg2);


				ITEM_LOG_PARAM	ItemLogParam;
				ItemLogParam.OpType		= ITEM_TILED_BAG_DEST;
				ItemLogParam.CharGUID	= pHuman->GetGUID();
				ItemLogParam.SceneID	= pHuman->getScene()->SceneID();
				ItemLogParam.XPos		= pHuman->getWorldPos()->m_fX;
				ItemLogParam.ZPos		= pHuman->getWorldPos()->m_fZ;
				ItemLogParam.ContainerPos		= index2;
				ItemLogParam.Count		= Count;
				ItemLogParam.ItemGuid	= pItem2->GetGUID();	
				SaveItemLog(&ItemLogParam);


				ItemLogParam.OpType		= ITEM_TILED_BAG_DEST;
				ItemLogParam.CharGUID	= pHuman->GetGUID();
				ItemLogParam.SceneID	= pHuman->getScene()->SceneID();
				ItemLogParam.XPos		= pHuman->getWorldPos()->m_fX;
				ItemLogParam.ZPos		= pHuman->getWorldPos()->m_fZ;
				ItemLogParam.ContainerPos		= index1;
				ItemLogParam.Count		= Count;
				ItemLogParam.ItemGuid	= pItem1->GetGUID();	
				SaveItemLog(&ItemLogParam);

				return PACKET_EXE_CONTINUE ;
			}
		}

		// 交换两物品
		bSucc = g_ItemOperator.ExchangeItem(pBagContainer, index_container1, pBagContainer, index_container2) == ITEMOE_SUCCESS;
	}

	msg.SetResult(SWITCHITEM_SUCCESS);
	msg.SetPackageIndex1(index1);
	msg.SetPackageIndex2(index2);

	pGamePlayer->SendPacket(&msg);
	g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Succ=%s", 
		index1, index2, bSucc?"TRUE":"FALSE" ) ;


	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}