Пример #1
0
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 ;
}
Пример #2
0
UINT CGUnEquipHandler::Execute( CGUnEquip* 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 ) ;

	HUMAN_EQUIP	EquipPoint = (HUMAN_EQUIP)pPacket->getEquipPoint();

	//Assert( pHuman->GetDB()->GetEquipDB()->IsSet(EquipPoint) ) ;



	Item*	pEquipItem = HumanItemLogic::GetEquip(pHuman,EquipPoint);
	
	if(!pEquipItem)
	{
		Assert(pEquipItem);
		return	PACKET_EXE_CONTINUE;
	}
	if(pEquipItem->IsEmpty())
	{
		return	PACKET_EXE_CONTINUE;
	}

	UCHAR	itemClass = pEquipItem->GetItemClass();
	if(itemClass ==	ICLASS_EQUIP)
	{
		INT		BagIndex;//	=	pHuman->GetFirstEmptyBagIndex();

		ItemContainer*	pEquipContainer = pHuman->GetEquipContain();
		ItemContainer*	pBaseContainer	= pHuman->GetBaseContain();

		if(!pEquipContainer)
		{
			Assert(pEquipItem);
			return	PACKET_EXE_CONTINUE;
		}
		
		BYTE	DeliverBagIndex = pPacket->getBagIndex();

		if(DeliverBagIndex<pBaseContainer->GetContainerSize())
		{
			BagIndex	=	g_ItemOperator.MoveItem(pEquipContainer,
				EquipPoint,
				pBaseContainer,DeliverBagIndex);
		}
		else
		{
			BagIndex	=	g_ItemOperator.MoveItem(pEquipContainer,
							EquipPoint,
							pBaseContainer);
		}
		

		GCUnEquipResult	 Msg;
		if(BagIndex>=0
			&& BagIndex<pBaseContainer->GetContainerSize())
		{
			Msg.setEquipPoint(EquipPoint);
			Msg.setBagIndex(BagIndex);
			Msg.setItemID(pEquipItem->GetGUID());
			Msg.setItemTableIndex(pEquipItem->GetItemTableIndex());
			Msg.setResult(UNEQUIP_SUCCESS);
			pHuman->SetEquipVer(pHuman->GetEquipVer()+1);
			pHuman->ItemEffectFlush();

			pGamePlayer->SendPacket( &Msg ) ;

			//如果可见
			if(pHuman->IsVisualPart(EquipPoint))
			{	
				GCCharEquipment OtherMsg;
				OtherMsg.setObjID(pHuman->GetID());
				//if(EquipPoint == HEQUIP_WEAPON)
				//{
				//	UINT uGemID = GetEquipmentMaxLevelGemID(pEquipItem);
				//	OtherMsg.setID(EquipPoint,pEquipItem->GetItemTableIndex(), uGemID);
				//}
				//else
				//{
					OtherMsg.setID(EquipPoint,pEquipItem->GetItemTableIndex(), -1);
				//}
				pScene->BroadCast(&OtherMsg,pHuman,TRUE);
			}
		}
		else
		{
			if(ITEMOE_DESTOPERATOR_HASITEM == BagIndex)
			{
				Msg.setResult(UNEQUIP_HAS_ITEM);
				pGamePlayer->SendPacket( &Msg ); 
			}
			else if(ITEMOE_DESTOPERATOR_FULL == BagIndex)
			{
				Msg.setResult(UNEQUIP_BAG_FULL);
				pGamePlayer->SendPacket( &Msg ); 
			}
		}
		
	}
	else
	{
		Assert(FALSE);
		//装备为什么不是 ICLASS_EQUIP
	}
	
	g_pLog->FastSaveLog( LOG_FILE_1, "CGUnEquipHandler EquipPoint=%d itemClass=%d",
		EquipPoint, itemClass  ) ;

	
	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
Пример #3
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 ;
}