Esempio n. 1
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 ;
}
Esempio n. 2
0
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;
}
Esempio n. 3
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 ;
}
Esempio n. 4
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 ;
}
uint CGShopRepairHandler::Execute( CGShopRepair* 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	Opt         =	pPacket->GetOpt();
	BOOL	RepairAll	=	pPacket->IsRepairAll();		//修理全部
	BYTE	BagIndex	=	pPacket->GetBagIndex();		//包中的位置
	UINT	UniqueID	=	pPacket->GetUniqueID();

	SceneID_t	SceneID =	UniqueID>>16;
	ObjID_t		NpcObjID=	UniqueID&0x00ff;

	if(SceneID != pScene->SceneID())
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler Illegal scene ObjName = %s", pHuman->GetName()) ;
		return PACKET_EXE_CONTINUE ; 
	}

	//距离判定
	Obj* pNpcObj = (Obj*) (pScene->GetObjManager()->GetObj(NpcObjID));
	if(pNpcObj == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler Illegal Obj ObjName = %s", pHuman->GetName()) ;
		return PACKET_EXE_CONTINUE ; 
	}

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

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

	Item*	pCurItem = NULL;
	INT				MoneySpent = 0;
	INT				MoneyLast = 0;
	INT				MoneyHave  = pHuman->GetMoney();
	INT				RepairedIndex = 0;
	GCShopRepair	Msg;
	GCShopRepair::REPAIRED_ITEM	ItemList[MAX_REPAIRED_NUMBER];

	_SHOP*		pShop	=	pHuman->Shop( )	;
	if(!pShop)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopRepairHandler Npc Shop Lose");
		return PACKET_EXE_CONTINUE;
	}

	if(Opt == CGShopRepair::FromBag)
	{
		if(RepairAll)
		{
			INT nBeginPoint	= 0;
			INT nEndPoint	= 0;
			switch( pShop->m_nRepairType )
			{
			case SHOP_All:
				{
					nBeginPoint = HEQUIP_WEAPON;
					nEndPoint	= HEQUIP_RIDER;
				}
				break;
			case SHOP_WEAPON:		//防具
				{
					nBeginPoint = HEQUIP_WEAPON;
					nEndPoint	= HEQUIP_WEAPON;
				}
				break;
			case SHOP_DEFENCE:		//饰物
				{
					nBeginPoint = HEQUIP_CAP;
					nEndPoint	= HEQUIP_BOOT;
				}
				break;
			case SHOP_ADORN:		//武器
				{
					nBeginPoint = HEQUIP_SASH;
					nEndPoint	= HEQUIP_RIDER;
				}
				break;
			default:
				{
					return PACKET_EXE_CONTINUE;
				}
				break;
			}


			for(INT i =nBeginPoint; i<=nEndPoint; i++)
			{
				pCurItem	= HumanItemLogic::GetEquip(pHuman,(HUMAN_EQUIP)i);
				//pCurItem = pHuman->GetEquip((HUMAN_EQUIP)i);
				if(!pCurItem->IsEmpty())
				{//有东西
					//判定是否狗修理等级
					if(pCurItem->GetRequireLevel() > pShop->m_nRepairLevel)
					{
						continue;
					}

					FLOAT fCur = (FLOAT)pCurItem->GetDurPoints();
					FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint();
					FLOAT V	   = (FLOAT)pCurItem->GetPrice();

					if(fCur != fMax)
					{
						//if(fCur<fMax/3)
						//	MoneySpent += (INT)(7*V*V*fCur*6/(4*fMax)+V*V);
						//else if(fCur>=fMax/3&&fCur<fMax*2/3)
						//	MoneySpent += (INT)(V*V*fCur*6/fMax+V*V*3/4);
						//else if(fCur>=fMax*2/3&&fCur<fMax)
						//	MoneySpent += (INT)(V*V*fCur*6/(4*fMax)+V*V/4);
						MoneySpent += (INT) ( ((REPAIR_SPEND * (1- fCur/fMax) * V) * pShop->m_nRepairSpend) + 0.5);

						//临时的修理费计算方法
//						FLOAT scale = (FLOAT)(fCur/fMax);
//						scale = 1-scale;
//						MoneySpent += static_cast<INT>(pCurItem->GetPrice()*scale);
						if(MoneyHave<MoneySpent)
							break;
						MoneyLast	=	MoneySpent;
						HumanItemLogic::SetEquipDur(pHuman,(HUMAN_EQUIP)i, (INT)fMax);

						ItemList[RepairedIndex].IsIn		=	GCShopRepair::EQUIP;					
						ItemList[RepairedIndex++].BagIndex	=	(BYTE)i;
					}
				}
			}

			if(MoneyHave<MoneySpent)
			{//break出来的
				if(RepairedIndex)
				{
					pHuman->SetMoney(MoneyHave - MoneyLast);
					
					MONEY_LOG_PARAM	MoneyLogParam;
					MoneyLogParam.CharGUID	=	pHuman->GetGUID();
					MoneyLogParam.OPType	=	MONEY_SHOP_REPAIR;
					MoneyLogParam.Count		=	MoneyLast;
					MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
					MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
					MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
					SaveMoneyLog(&MoneyLogParam);


					Msg.SetAll(0);
					Msg.SetReListNum(RepairedIndex);
					Msg.SetReList(ItemList);
					pHuman->GetPlayer()->SendPacket(&Msg);
				}

				GCShopBuy Msg ;
				Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
				pHuman->GetPlayer()->SendPacket( &Msg ) ;
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler BUY_MONEY_FAIL") ;
				return PACKET_EXE_CONTINUE ;
			}
			else if(MoneySpent != 0)
			{//全修完了
				pHuman->SetMoney(MoneyHave - MoneySpent);
				MONEY_LOG_PARAM	MoneyLogParam;
				MoneyLogParam.CharGUID	=	pHuman->GetGUID();
				MoneyLogParam.OPType	=	MONEY_SHOP_REPAIR;
				MoneyLogParam.Count		=	MoneySpent;
				MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
				MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
				MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
				SaveMoneyLog(&MoneyLogParam);

				Msg.SetAll(1);
				Msg.SetReListNum(0);
				pHuman->GetPlayer()->SendPacket(&Msg);
			}
		}
		else
		{//修理单个,一定应该在背包中
			pCurItem =	HumanItemLogic::GetItem(pHuman,BagIndex);
			if(!pCurItem->IsEmpty())
			{
				if(pCurItem->GetRequireLevel()>pShop->m_nRepairLevel)
				{
					g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler Npc have no the Repair Levle") ;
					return PACKET_EXE_CONTINUE;
				}
				BOOL bCanRepair = TRUE;
				switch( pShop->m_nRepairType )
				{
				case SHOP_All:
					{
					}
					break;
				case SHOP_DEFENCE:		//防具
					{
						if( pCurItem->GetEquipPoint() != HEQUIP_CAP &&
							pCurItem->GetEquipPoint() != HEQUIP_ARMOR &&
							pCurItem->GetEquipPoint() != HEQUIP_CUFF &&
							pCurItem->GetEquipPoint() != HEQUIP_BOOT )
						{
							bCanRepair = FALSE;
						}
					}
					break;
				case SHOP_ADORN:		//饰物
					{
						if( pCurItem->GetEquipPoint() != HEQUIP_SASH &&
							pCurItem->GetEquipPoint() != HEQUIP_RING &&
							pCurItem->GetEquipPoint() != HEQUIP_NECKLACE &&
							pCurItem->GetEquipPoint() != HEQUIP_RIDER)
						{
							bCanRepair = FALSE;
						}
					}
					break;
				case SHOP_WEAPON:		//武器
					{
						if( pCurItem->GetEquipPoint() != HEQUIP_WEAPON )
						{
							bCanRepair = FALSE;
						}
					}
					break;
				default:
					{
						bCanRepair = FALSE;
					}
					break;
				}

				if(bCanRepair == FALSE)
				{
					g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler Npc have no the Repair type") ;
					return PACKET_EXE_CONTINUE;
				}


				FLOAT fCur = (FLOAT)pCurItem->GetDurPoints();
				FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint();
				FLOAT V	   = (FLOAT)pCurItem->GetPrice();
				if(fCur != fMax)
				{
					//if(fCur<fMax/3)
					//	MoneySpent += (INT)(7*V*V*fCur*6/(4*fMax)+V*V);
					//else if(fCur>=fMax/3&&fCur<fMax*2/3)
					//	MoneySpent += (INT)(V*V*fCur*6/fMax+V*V*3/4);
					//else if(fCur>=fMax*2/3&&fCur<fMax)
					//	MoneySpent += (INT)(V*V*fCur*6/(4*fMax)+V*V/4);
					MoneySpent += (INT) ( ((REPAIR_SPEND * (1- fCur/fMax) * V) * pShop->m_nRepairSpend) + 0.99);


					if(MoneyHave>=MoneySpent)
					{//可以修
						pHuman->SetMoney(MoneyHave - MoneySpent);
						
						MONEY_LOG_PARAM	MoneyLogParam;
						MoneyLogParam.CharGUID	=	pHuman->GetGUID();
						MoneyLogParam.OPType	=	MONEY_SHOP_REPAIR;
						MoneyLogParam.Count		=	MoneySpent;
						MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
						MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
						MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
						SaveMoneyLog(&MoneyLogParam);

						HumanItemLogic::SetBagItemDur(pHuman,(UINT)BagIndex,(INT)fMax);
						ItemList[0].IsIn		=	GCShopRepair::BAG;					
						ItemList[0].BagIndex	=	(BYTE)BagIndex;
						Msg.SetAll(0);
						Msg.SetReListNum(1);
						Msg.SetReList(ItemList);
						pHuman->GetPlayer()->SendPacket(&Msg);
					}
					else
					{//没钱还捣乱
						GCShopBuy Msg ;
						Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
						pHuman->GetPlayer()->SendPacket( &Msg ) ;
						g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler BUY_MONEY_FAIL") ;
						return PACKET_EXE_CONTINUE ;
					}
				}
			}
			else
			{
				g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler BagIndex = %d", BagIndex) ;
				return PACKET_EXE_CONTINUE ;
			}
		}
	}
	else if(Opt == CGShopRepair::FromEquip)
	{
		pCurItem = HumanItemLogic::GetEquip(pHuman,(HUMAN_EQUIP)BagIndex);

		if(!pCurItem->IsEmpty())
		{//有东西
			FLOAT fCur = (FLOAT)pCurItem->GetDurPoints();
			FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint();
			FLOAT V	   = (FLOAT)pCurItem->GetPrice();

			{
				if(pCurItem->GetRequireLevel()>pShop->m_nRepairLevel)
				{
					g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler Npc have no the Repair Levle") ;
					return PACKET_EXE_CONTINUE;
				}
				BOOL bCanRepair = TRUE;
				switch( pShop->m_nRepairType )
				{
				case SHOP_All:
					{
					}
					break;
				case SHOP_DEFENCE:		//防具
					{
						if( pCurItem->GetEquipPoint() != HEQUIP_CAP &&
							pCurItem->GetEquipPoint() != HEQUIP_ARMOR &&
							pCurItem->GetEquipPoint() != HEQUIP_CUFF &&
							pCurItem->GetEquipPoint() != HEQUIP_BOOT )
						{
							bCanRepair = FALSE;
						}
					}
					break;
				case SHOP_ADORN:		//饰物
					{
						if( pCurItem->GetEquipPoint() != HEQUIP_SASH &&
							pCurItem->GetEquipPoint() != HEQUIP_RING &&
							pCurItem->GetEquipPoint() != HEQUIP_NECKLACE &&
							pCurItem->GetEquipPoint() != HEQUIP_RIDER)
						{
							bCanRepair = FALSE;
						}
					}
					break;
				case SHOP_WEAPON:		//武器
					{
						if( pCurItem->GetEquipPoint() != HEQUIP_WEAPON )
						{
							bCanRepair = FALSE;
						}
					}
					break;
				default:
					{
						bCanRepair = FALSE;
					}
					break;
				}

				if(bCanRepair == FALSE)
				{
					g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler Npc have no the Repair type") ;
					return PACKET_EXE_CONTINUE;
				}
			}


			if(fCur != fMax)
			{
				//if(fCur<fMax/3)
				//	MoneySpent += (INT)(7*V*V*fCur*6/(4*fMax)+V*V);
				//else if(fCur>=fMax/3&&fCur<fMax*2/3)
				//	MoneySpent += (INT)(V*V*fCur*6/fMax+V*V*3/4);
				//else if(fCur>=fMax*2/3&&fCur<fMax)
				//	MoneySpent += (INT)(V*V*fCur*6/(4*fMax)+V*V/4);

				MoneySpent += (INT) ( ((REPAIR_SPEND * (1- fCur/fMax) * V) * pShop->m_nRepairSpend) + 0.5);

				if(MoneyHave>=MoneySpent)
				{//可以修
					pHuman->SetMoney(MoneyHave - MoneySpent);
					MONEY_LOG_PARAM	MoneyLogParam;
					MoneyLogParam.CharGUID	=	pHuman->GetGUID();
					MoneyLogParam.OPType	=	MONEY_SHOP_REPAIR;
					MoneyLogParam.Count		=	MoneySpent;
					MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
					MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
					MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
					SaveMoneyLog(&MoneyLogParam);

					HumanItemLogic::SetEquipDur(pHuman,(HUMAN_EQUIP)BagIndex,(INT)fMax);
					ItemList[0].IsIn		=	GCShopRepair::EQUIP;					
					ItemList[0].BagIndex	=	(BYTE)BagIndex;
					Msg.SetAll(0);
					Msg.SetReListNum(1);
					Msg.SetReList(ItemList);
					pHuman->GetPlayer()->SendPacket(&Msg);
				}
				else
				{//没钱还捣乱
					GCShopBuy Msg ;
					Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
					pHuman->GetPlayer()->SendPacket( &Msg ) ;
					g_pLog->FastSaveLog( LOG_FILE_1, "CGShopRepairHandler BUY_MONEY_FAIL") ;
					return PACKET_EXE_CONTINUE ;
				}
			}
		}

	}


	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
uint CGShopSellHandler::Execute( CGShopSell* 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	m_nBagIndex	=	pPacket->GetBagIndex();		//包中的位置
    UINT	UniqueID	=	pPacket->GetUniqueID();

    SceneID_t	SceneID =	UniqueID>>16;
    ObjID_t		NpcObjID=	UniqueID&0x00ff;

    if(SceneID != pScene->SceneID())
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler Illegal scene ObjName = %s", pHuman->GetName()) ;
        return PACKET_EXE_CONTINUE ;
    }

    //距离判定
    Obj* pNpcObj = (Obj*) (pScene->GetObjManager()->GetObj(NpcObjID));
    if(pNpcObj == NULL)
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler Illegal Obj ObjName = %s", pHuman->GetName()) ;
        return PACKET_EXE_CONTINUE ;
    }

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

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

    Item*		 pCurrentItem = HumanItemLogic::GetItem(pHuman,m_nBagIndex);

    if(!pCurrentItem||ConvertSerial2ItemType(pCurrentItem->GetItemTableIndex()).isNull())
    {
        //背包索引不存在
        g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopSellHandler m_nBagIndex=%d PlayerName=s%",
                             m_nBagIndex,  pHuman->GetName()) ;
        return PACKET_EXE_CONTINUE;
    }

    //判定这个商人是不是收购这个物品
    _SHOP*		pShop	=	pHuman->Shop( )	;

    //商店不存在
    if(!pShop)
    {
        g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopSellHandler Npc Shop Lose");
        return PACKET_EXE_CONTINUE;
    }

    //查询收购等级限制
    if( pCurrentItem->GetItemClass() == ICLASS_EQUIP )
    {
        if( pCurrentItem->GetRequireLevel() > pShop->m_nBuyLevel )
        {
            return PACKET_EXE_CONTINUE;
        }
    }
    else
    {
        if( pCurrentItem->GetItemLevel() > pShop->m_nBuyLevel )
        {
            return PACKET_EXE_CONTINUE;
        }
    }

    BOOL bCanBuy = TRUE;
    if(pShop->m_nBuyType != SHOP_All)
    {
        switch(pShop->m_nBuyType)
        {
        case SHOP_All:
        {
        }
        break;
        case SHOP_DEFENCE:		//防具
        {
            if( ICLASS_EQUIP == pCurrentItem->GetItemClass())
            {
                if( pCurrentItem->GetEquipPoint() != HEQUIP_CAP &&
                        pCurrentItem->GetEquipPoint() != HEQUIP_ARMOR &&
                        pCurrentItem->GetEquipPoint() != HEQUIP_CUFF &&
                        pCurrentItem->GetEquipPoint() != HEQUIP_BOOT )
                {
                    bCanBuy = FALSE;
                }
            }
            else
            {
                bCanBuy = FALSE;
            }
        }
        break;
        case SHOP_ADORN:		//饰物
        {
            if( ICLASS_EQUIP == pCurrentItem->GetItemClass())
            {
                if( pCurrentItem->GetEquipPoint() != HEQUIP_SASH &&
                        pCurrentItem->GetEquipPoint() != HEQUIP_RING &&
                        pCurrentItem->GetEquipPoint() != HEQUIP_NECKLACE &&
                        pCurrentItem->GetEquipPoint() != HEQUIP_RIDER)
                {
                    bCanBuy = FALSE;
                }
            }
            else
            {
                bCanBuy = FALSE;
            }
        }
        break;
        case SHOP_WEAPON:		//武器
        {
            if( ICLASS_EQUIP == pCurrentItem->GetItemClass())
            {
                if( pCurrentItem->GetEquipPoint() != HEQUIP_WEAPON )
                {
                    bCanBuy = FALSE;
                }
            }
            else
            {
                bCanBuy = FALSE;
            }
        }
        break;
        case SHOP_FOOD:			//食物
        {
            if( ICLASS_COMITEM != pCurrentItem->GetItemClass())
            {
                bCanBuy = FALSE;
            }
        }
        break;
        case SHOP_MATERIAL:		//材料
        {
            if( ICLASS_MATERIAL != pCurrentItem->GetItemClass())
            {
                bCanBuy = FALSE;
            }
        }
        break;
        case SHOP_COMITEM:		//药品
        {
            if( ICLASS_COMITEM != pCurrentItem->GetItemClass())
            {
                bCanBuy = FALSE;
            }
        }
        break;
        default:
        {
            bCanBuy = FALSE;
            break;
        }
        }
    }

    //是否返回失败消息???
    if(bCanBuy == FALSE)
    {
        return PACKET_EXE_CONTINUE;
    }

    INT   iPrice = ShopMgr::ConvertItemType2Money(ConvertSerial2ItemType(pCurrentItem->GetItemTableIndex()));
    iPrice *= pCurrentItem->GetLayedNum();
    //2006-4-21
    //玩家向商店出售已经鉴定过的物品或者无需鉴定的物品按照基础价格*系数A(=1/3) 计算;
    //若出售未鉴定物品,价格应该更低,设此价格系数为B(=1/10),这个有待于调整,请在config中开放调整A,B的接口。
    //耐久衰减系数D=当前耐久/最大耐久
    //修理失败衰减次数F=1/(修理失败次数+1)
    //因此最终的出售价格为V=基础价格B*A*D*F
    //再乘以商店得价格比例

    FLOAT fCur			= 1;
    FLOAT fMax			= 1;
    INT	  iFailTimes	= 0;

    if(pCurrentItem->GetItemClass() == ICLASS_EQUIP)
    {
        fCur		= (FLOAT)pCurrentItem->GetDurPoints();
        fMax		= (FLOAT)pCurrentItem->GetMaxDurPoint();
        iFailTimes	= pCurrentItem->GetFailTimes();
    }

    if(pCurrentItem->GetItemIdent())
    {
        iPrice = (INT)( ((FLOAT)iPrice/(FLOAT)3.0) * (fCur/fMax) * ((FLOAT)1/(FLOAT)(iFailTimes+1)) * (pShop->m_scale) );
    }
    else
    {
        iPrice = (INT)( ((FLOAT)iPrice/(FLOAT)10.0) * (fCur/fMax) * ((FLOAT)1/(FLOAT)(iFailTimes+1)) * (pShop->m_scale) );
    }

    //备份一下,一会儿放到购回列表里
    _ITEM tempitem;
    pCurrentItem->SaveValueTo(&tempitem);

    //备份到回购列表中
    pHuman->AddToSoldList(m_nBagIndex, iPrice);

    //给钱
    pHuman->SetMoney( pHuman->GetMoney() + iPrice);

    MONEY_LOG_PARAM	MoneyLogParam;
    MoneyLogParam.CharGUID	=	pHuman->GetGUID();
    MoneyLogParam.OPType	=	MONEY_SHOP_SELL;
    MoneyLogParam.Count		=	iPrice;
    MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
    MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
    MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
    SaveMoneyLog(&MoneyLogParam);

    //把这个回购商品显示到界面
    GCShopSoldList::_MERCHANDISE_ITEM	SoldItem;
    SoldItem.item_data = tempitem;
    GCShopSoldList	MsgSold;
    MsgSold.SetMerchadiseNum(1);
    MsgSold.SetMerchadiseList(&SoldItem);
    pHuman->GetPlayer()->SendPacket( &MsgSold );

    GCShopSell	MsgSell;
    pHuman->GetPlayer()->SendPacket( &MsgSell );

    g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler m_nBagIndex=%d ",
                         m_nBagIndex  ) ;

    return PACKET_EXE_CONTINUE;

    __LEAVE_FUNCTION

    return PACKET_EXE_ERROR ;
}