Пример #1
0
int main(int argc, char** argv) {
  try {
    PositiveNumber<int> v(1);
  } catch(AssertionFailed& e) {
    printf("%s\n", e.what());
  }
  
  try {
    PositiveNumber<int> v(-2);
  } catch(AssertionFailed& e) {
    printf("%s\n", e.what());
  }
  
  try {
    MySqrt(-1);
  } catch(AssertionFailed& e) {
    printf("%s\n", e.what());
  }
  
  try {
    assert(1 == 0);
  } catch(AssertionFailed& e) {
    printf("%s\n", e.what());
  }
  
  try {
    assertThrows(MySqrt(-1), int);
  } catch(AssertionFailed& e) {
    printf("%s\n", e.what());
  }
}
Пример #2
0
int MySqrt(int n, double low, double high)
{
  if(high-low<=1)
    return low;

  int middle = (int)floor((low + high)/2.0f);
  
  double MiddleSquare = middle*middle;

  if(fabs(MiddleSquare-n)<1)
    return middle;
  else if(MiddleSquare<n)
    return MySqrt(n, middle, high);
  else 
    return MySqrt(n, low, middle);
}
Пример #3
0
prob_t Entropy(KDTreeHist& oTree,vector<Neighbor>& vNeighbors,int iClustID,vector<int>& vClustIDs)
{
	//ScopedTimer S("Entropy...");

	int iFast = 0,iSlow = 0;

	prob_t dEntrop = 0.0;
	int isz = vClustIDs.size() , iV = 0, iT = 0, iNN = 0;
	
	double tsz = oTree.NumElems();

	for(iV=0;iV<isz;iV++)
	{
		if(vClustIDs[iV]!=iClustID)
			continue;

		prob_t dDist = 0.0;
		
		Neighbor& oN = vNeighbors[iV];
		if(vClustIDs[oN.m_id]==iClustID && oN.m_dist>0.0)
		{
			dDist = oN.m_dist;
			iFast++;
		}

		if(dDist <= 0.0)
		{
			dDist = oTree.GetNearestRadiusSQ(iT,true);
			iSlow++;
		}

		if(dDist >= 0.0)
		{
			//prob_t dProb = oTree.RProb(MySqrt(dDist));

			//if(dProb >= 0.0)			
			{
				//dEntrop += dProb * log2(dProb);
				dEntrop += log2(tsz*MySqrt(dDist));
			}
		}
		
		iT++;
	}
	//dEntrop *= (oTree.NumDims() / oTree.NumElems());
	dEntrop /= (double) isz;
	//dEntrop += 
	//double r = oTree.NumDims();
	//double N = oTree.NumDims();
	//double PI = 3.14159265;
	//double Sr = r * pow(PI,r/2.0) / Gamma(N/2.0+1.0);
	//double Sr = r * pow(PI,r/2.0) / Gamma(r/2.0+1.0);
	//dEntrop += log2( Sr * (N-1.0) / r);
	return dEntrop;
}
Пример #4
0
int main(void)
{
  double MinInt = 1.0f;
  double MaxInt = 10000.0f;

  int TestNumber = 21;

  int msqrt  = MySqrt(TestNumber, MinInt, MaxInt);
  int mpower = MyPower(TestNumber, 3);
  int mmul   = MyMultiplication(TestNumber, 3);
  int mdiv   = MyDivision(TestNumber, 4, MinInt, TestNumber);

  std::cout << msqrt  << std::endl;
  std::cout << mpower << std::endl;
  std::cout << mmul   << std::endl;
  std::cout << mdiv   << std::endl;
}
UINT CGExchangeReplyIHandler::Execute( CGExchangeReplyI* 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    SourceID = pPacket->GetObjID();
    Obj_Human* pDestHuman= pHuman;//自己被申请方
    Obj_Human* pSourceHuman = pScene->GetHumanManager()->GetHuman( SourceID );//交易发起者

    //验证
    if( pSourceHuman == NULL )
    {//发起者掉线
        Assert(FALSE);
        return PACKET_EXE_CONTINUE;
    }

    if(    pSourceHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA )
    {
        if( pSourceHuman->m_ExchangBox.m_ObjID == pDestHuman->GetID() )
        {//正在和你交易别捣乱了
            return PACKET_EXE_CONTINUE;
        }
        else
        {//告诉自己对方已经在跟别人交易了,所有状态清空
            GCExchangeError Msg;
            Msg.SetID(EXCHANGE_MSG::ERR_TARGET_IN_EXCHANGE);
            pHuman->GetPlayer()->SendPacket(&Msg);
            g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 已经在交易中, 不能接受[%s]的申请",    pSourceHuman->GetName(), pDestHuman->GetName() ) ;
            return PACKET_EXE_CONTINUE;
        }
    }

    if(pDestHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA)
    {
        if(    pDestHuman->m_ExchangBox.m_ObjID == pSourceHuman->GetID())
        {//正是当前交易
            return PACKET_EXE_CONTINUE;
        }
        else
        {//告诉自己自己已经在跟别人交易了,所有状态清空
            GCExchangeError Msg;
            Msg.SetID(EXCHANGE_MSG::ERR_SELF_IN_EXCHANGE);
            pHuman->GetPlayer()->SendPacket(&Msg);
            g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 已经在交易中, 不能接受[%s]的申请",    pDestHuman->GetName(), pSourceHuman->GetName() ) ;
            return PACKET_EXE_CONTINUE;
        }
    }

    //距离判定
    if(MySqrt( pSourceHuman->getWorldPos(), pDestHuman->getWorldPos() ) > 20 )
    {
        GCExchangeError Msg;
        Msg.SetID(EXCHANGE_MSG::ERR_TOO_FAR);
        pHuman->GetPlayer()->SendPacket(&Msg);
        g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 超过交易范围[%s]]",    pDestHuman->GetName(), pSourceHuman->GetName() ) ;
        return PACKET_EXE_CONTINUE;
    }

    //验证通过,开始初始化双方交易盒,进入步骤2
    pSourceHuman->m_ExchangBox.CleanUp();
    pSourceHuman->m_ExchangBox.m_Status = ServerExchangeBox::EXCHANGE_SYNCH_DATA;
    pSourceHuman->m_ExchangBox.m_Money = 0;
    pSourceHuman->m_ExchangBox.m_IsLocked = FALSE;
    pSourceHuman->m_ExchangBox.m_CanConform = FALSE;
    pSourceHuman->m_ExchangBox.m_ObjID = pDestHuman->GetID();
    //pSourceHuman->m_ExchangBox.

    pDestHuman->m_ExchangBox.CleanUp();
    pDestHuman->m_ExchangBox.m_Status = ServerExchangeBox::EXCHANGE_SYNCH_DATA;
    pDestHuman->m_ExchangBox.m_Money = 0;
    pDestHuman->m_ExchangBox.m_IsLocked = FALSE;
    pDestHuman->m_ExchangBox.m_CanConform = FALSE;
    pDestHuman->m_ExchangBox.m_ObjID = pSourceHuman->GetID();
    //pDestHuman->m_ExchangBox.
    g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 建立交易连接",    pSourceHuman->GetName(), pDestHuman->GetName() ) ;

    GCExchangeEstablishI MsgToSource;
    MsgToSource.SetObjID(pDestHuman->GetID());
    pSourceHuman->GetPlayer()->SendPacket(&MsgToSource);

    GCExchangeEstablishI MsgToDest;
    MsgToDest.SetObjID(pSourceHuman->GetID());
    pDestHuman->GetPlayer()->SendPacket(&MsgToDest);


    return PACKET_EXE_CONTINUE ;

    __LEAVE_FUNCTION

    return PACKET_EXE_ERROR ;
}
Пример #6
0
uint CGShopBuyHandler::Execute( CGShopBuy* 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_nndex		=	pPacket->GetIndex();	//资源位置索引
	UINT	UniqueID	=	pPacket->GetUniqueID();
	
	SceneID_t	SceneID =	UniqueID>>16;
	ObjID_t		NpcObjID=	UniqueID&0x00ff;

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

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

	if(fDist>MAX_NPC_DISTANCE)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGShopBuyHandler Out Of Range") ;
		return PACKET_EXE_CONTINUE ; 
	}

	if(pHuman->Shop( )	== NULL)
	{//没有打开交易窗口就买
		Assert(0);
		return PACKET_EXE_CONTINUE ;
	}

	//打开商店时,这个商店的指针已经被存在human身上了,关闭商店时它会被清空
	_SHOP*		pShop	=	pHuman->Shop( )	;
	INT		itemNumber	=	0;

	//暂时规定200以上为回购的商品栏
	if(m_nndex >= 200)
	{//在回购队列中查找
        m_nndex -= 200;
		_ITEM tempItem;
		UINT  uPrice = 0;
		if(!pHuman->GetFromSoldListByIndex(m_nndex, tempItem, uPrice))
		{
			//Assert(0);
			return PACKET_EXE_CONTINUE ;
		}

		itemNumber = tempItem.GetItemCount();
		INT iPrice = (INT)uPrice;

		if( ((INT)pHuman->GetMoney()) < iPrice )
		{//金钱不够
			GCShopBuy Msg ;
			Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
			pHuman->GetPlayer()->SendPacket( &Msg ) ;
			return PACKET_EXE_CONTINUE ;
		}
		
		if(!pHuman->RecieveOneFromSoldList(m_nndex))
		{
			GCShopBuy Msg ;
			Msg.SetBuyOk((BYTE)GCShopBuy::BUY_BAG_FULL);
			pHuman->GetPlayer()->SendPacket( &Msg ) ;
			return PACKET_EXE_CONTINUE ;
		}
		else
		{//从回购列表里面购买成功	
			pHuman->SetMoney( pHuman->GetMoney() - iPrice);
			MONEY_LOG_PARAM	MoneyLogParam;
			MoneyLogParam.CharGUID	=	pHuman->GetGUID();
			MoneyLogParam.OPType	=	MONEY_SHOP_COST;
			MoneyLogParam.Count		=	iPrice;
			MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
			MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
			MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
			SaveMoneyLog(&MoneyLogParam);


			GCShopBuy Msg ;
			Msg.SetBuyOk( (BYTE)GCShopBuy::BUY_OK );
			Msg.SetIndex( tempItem.m_ItemIndex );
			Msg.SetNum( tempItem.GetItemCount() );
			pHuman->GetPlayer()->SendPacket( &Msg ) ;

			//更新回购按钮
            //刷新整个回购列表商品到界面
            GCShopSoldList::_MERCHANDISE_ITEM	SoldItem[MAX_BOOTH_SOLD_NUMBER];

			// 20100413 AddCodeBegin
			pHuman->ReorderSoldList();	// 重新整理回购物品列表,去除中间的空物品格
			// 20100413 AddCodeBegin

            pHuman->GetSlodListInfo(&SoldItem[0]);
            GCShopSoldList	MsgSold;
            MsgSold.SetMerchadiseNum(MAX_BOOTH_SOLD_NUMBER);
            MsgSold.SetMerchadiseList(&SoldItem[0]);
            pHuman->GetPlayer()->SendPacket( &MsgSold );
		}
	}
	else
	{//在商人挂的商店里查找

		//一次点击可以买的个数  0为约定值,为默认购买数量以商店配置文件为准
        INT itemNumber;
        if (pPacket->GetCount() == 0)
        {
            itemNumber = 1; 
        }
        else
        {
            itemNumber = pPacket->GetCount();
        }

		if(	pShop->m_IsDyShop )
		{
            //校验商店版本,不匹配提示客户端刷新贩卖列表
            if (pShop->m_nVersion != pPacket->GetVersion())
            {
                GCShopBuy Msg ;
                Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MUST_FRESH);
                pPlayer->SendPacket( &Msg ) ;

                //填充消息
                GCShopUpdateMerchandiseList::_MERCHANDISE_ITEM	MerchandiseList[MAX_BOOTH_NUMBER];
                INT k = 0;
                for(INT i = 0;i<pShop->m_ItemList->m_ListCount;i++)
                {
                    MerchandiseList[k].idTable		=	pShop->m_ItemList->m_ListTypeIndex[i];
                    MerchandiseList[k].MaxNumber	=	pShop->m_ItemList->m_TypeMaxNum[i];

                    MerchandiseList[k].nPrice		=	pShop->m_ItemList->m_Price[i];
                    MerchandiseList[k].nPriceType	=	pShop->m_ItemList->m_PriceType[i];
                    MerchandiseList[k++].byNumber	=	pShop->m_ItemList->m_TypeMaxNum[i];
                }

                GCShopUpdateMerchandiseList	listMsg;
                listMsg.SetMerchadiseNum(k);//一定要先设置数量再设置List
                listMsg.SetMerchadiseList(MerchandiseList);
                listMsg.SetVersion(pShop->m_nVersion);
                pHuman->GetPlayer()->SendPacket( &listMsg ) ;

                return PACKET_EXE_CONTINUE ;
            }

            //有限商品不够卖了
            if(pShop->m_ItemList->m_TypeMaxNum[m_nndex] < itemNumber)
            {//卖完了,直接返回,
                //应该不会走到这里,
                //首先表里不应该出现0,
                //其次卖完的时候服务器会通知所有连在他之上的客户端
                //在界面上删掉这个商品,这样玩家也不可能再点这个商品了

                GCShopBuy Msg ;
                Msg.SetBuyOk((BYTE)GCShopBuy::BUY_NO_MERCH);
                pPlayer->SendPacket( &Msg ) ;
                return PACKET_EXE_CONTINUE ;
            }
		}

        uint BaseMoney= 0;
        //静态商店,只扣游戏币
        if (!pShop->m_IsDyShop)
        {
            //计算价格
            BaseMoney = ShopMgr::ConvertItemType2Money(pShop->m_ItemList->m_ListType[m_nndex]);
            if(BaseMoney<0) BaseMoney = 0;
            BaseMoney *= static_cast<INT>(pShop->m_scale);
            BaseMoney *= itemNumber;
            if( pHuman->GetMoney() < BaseMoney )
            {//金钱不够
                GCShopBuy Msg ;
                Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
                pHuman->GetPlayer()->SendPacket( &Msg ) ;
                return PACKET_EXE_CONTINUE ;
            }
        }
        else//动态商店
        {
            INT nPriceType  =   pShop->m_ItemList->m_PriceType[m_nndex];
            INT nPrice      =   pShop->m_ItemList->m_Price[m_nndex];
            switch (nPriceType)
            {
            case PRICE_GOLD:
                {
                    INT nGold = pHuman->GetMoney();
                    nGold    -= nPrice*itemNumber;
                    if (nGold < 0)//这里只管防止发生错误,为什么就不管了
                    {
                        nGold = 0;
                        GCShopBuy Msg ;
                        Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
                        pHuman->GetPlayer()->SendPacket( &Msg ) ;
                        return PACKET_EXE_CONTINUE ;
                    }
                    pHuman->SetMoney(nGold);
                }
                break;
            case PRICE_RMB:
                break;
            case PRICE_GP://帮贡
                {
                    INT nTotal  = pHuman->GetHonor() - nPrice*itemNumber;
                    if (nTotal < 0)
                    {
                        nTotal = 0;
                        GCShopBuy Msg ;
                        Msg.SetBuyOk((BYTE)GCShopBuy::BUY_MONEY_FAIL);
                        pHuman->GetPlayer()->SendPacket( &Msg ) ;
                        return PACKET_EXE_CONTINUE ;
                    }

                    pHuman->SetHonor(nTotal);
                }
                break;
            }
        }
        
		
		ITEM_LOG_PARAM	ItemLogParam;
		ItemLogParam.OpType		= ITEM_CREATE_FROM_SHOP;
		ItemLogParam.CharGUID	= pHuman->GetGUID();
		ItemLogParam.SceneID	= pHuman->getScene()->SceneID();
		ItemLogParam.XPos		= pHuman->getWorldPos()->m_fX;
		ItemLogParam.ZPos		= pHuman->getWorldPos()->m_fZ;
		ItemLogParam.ShopGUID	= pShop->m_ShopId;


		if(!HumanItemLogic::CreateMultiItemToBag(&ItemLogParam,
            pHuman,
            pShop->m_ItemList->m_ListTypeIndex[m_nndex],
            itemNumber))
        {
			GCShopBuy Msg ;
			Msg.SetBuyOk((BYTE)GCShopBuy::BUY_BAG_FULL);
			pHuman->GetPlayer()->SendPacket( &Msg ) ;
			return PACKET_EXE_CONTINUE ;
		}
		else
		{	
			SaveItemLog(&ItemLogParam);

            if (!pShop->m_IsDyShop)
            {
                pHuman->SetMoney( pHuman->GetMoney() - BaseMoney);

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

			GCShopBuy Msg ;
			Msg.SetBuyOk((BYTE)GCShopBuy::BUY_OK);
			Msg.SetIndex(pShop->m_ItemList->m_ListTypeIndex[m_nndex]);
			Msg.SetNum(itemNumber);
			pHuman->GetPlayer()->SendPacket( &Msg ) ;

			//要更新此商人的动态商品表
			if(pShop->m_IsDyShop)
			{
                // 扣除有限物品
                pShop->m_ItemList->m_TypeMaxNum[m_nndex] -= itemNumber;


                //填充消息
                GCShopUpdateMerchandiseList::_MERCHANDISE_ITEM	MerchandiseList[MAX_BOOTH_NUMBER];
                INT k = 0;
                for(INT i = 0;i<pShop->m_ItemList->m_ListCount;i++)
                {
                    MerchandiseList[k].idTable		=	pShop->m_ItemList->m_ListTypeIndex[i];
                    MerchandiseList[k].MaxNumber	=	pShop->m_ItemList->m_TypeMaxNum[i];

                    MerchandiseList[k].nPrice		=	pShop->m_ItemList->m_Price[i];
                    MerchandiseList[k].nPriceType	=	pShop->m_ItemList->m_PriceType[i];
                    MerchandiseList[k++].byNumber	=	pShop->m_ItemList->m_TypeMaxNum[i];
                }

                GCShopUpdateMerchandiseList	Msg;
                Msg.SetMerchadiseNum(k);//一定要先设置数量再设置List
                Msg.SetMerchadiseList(MerchandiseList);
                Msg.SetVersion(pShop->m_nVersion);
                pHuman->GetPlayer()->SendPacket( &Msg ) ;
			}
			return PACKET_EXE_CONTINUE ;
		}
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGShopBuyHandler m_nndex=%d",
		m_nndex) ;

	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 ;
}
Пример #9
0
uint CGExchangeApplyIHandler::Execute( CGExchangeApplyI* 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		TargetID = pPacket->GetObjID();
	Obj_Human* pSourceHuman = pHuman;//交易发起者
	Obj_Human* pDestHuman = pScene->GetHumanManager()->GetHuman( TargetID );//交易对象

    if (pSourceHuman->IsInLoginProtectTime() || pDestHuman->IsInLoginProtectTime())
    {//在上线保护时间内,不可操作
        GCExchangeError Msg;
        Msg.SetID(EXCHANGE_MSG::ERR_IN_PROTECT_TIME);
        pGamePlayer->SendPacket(&Msg);
        g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d or ID = %d ERR_IN_PROTECT_TIME", pSourceHuman->GetID(), pDestHuman->GetID()) ;

        return PACKET_EXE_CONTINUE;
    }

	//验证
	if( pDestHuman == NULL )
	{
		Assert(FALSE);
		return PACKET_EXE_CONTINUE;
	}
	INT iSettingData = pDestHuman->GetDB()->GetSetting(SETTING_TYPE_GAME)->m_SettingData;
	if(SETTINGFLAGISTRUE(iSettingData, GSF_REFUSE_TRADE))
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_REFUSE_TRADE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d ERR_REFUSE_TRADE", pSourceHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}
	if(pSourceHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA)
	{//发起者正在交易中
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_IN_EXCHANGE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d status = %d", pSourceHuman->GetID(), pSourceHuman->m_ExchangBox.m_Status) ;
		return PACKET_EXE_CONTINUE;
	}
	if(pDestHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA)
	{//目标正在交易中
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_IN_EXCHANGE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d status = %d", pDestHuman->GetID(),	pDestHuman->m_ExchangBox.m_Status ) ;
		return PACKET_EXE_CONTINUE;
	}
	//在使用战斗技能时不能交易
	//在使用生活技能时不能交易 
	//战斗中不能交易add by gh 2010/04/28
	if(pSourceHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_SKILL || pSourceHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_ABILITY)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_USE_SKILL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::使用技能中") ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pDestHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_SKILL || pDestHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_ABILITY)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_USE_SKILL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::目标使用技能中") ;
		return PACKET_EXE_CONTINUE ;
	}
	//行走中不能交易
	if(pSourceHuman->IsMoving())
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_MOVE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::移动中") ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pDestHuman->IsMoving())
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_MOVE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::目标移动中") ;
		return PACKET_EXE_CONTINUE ;
	}
    //在摆摊时不能交易
	if(pSourceHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_OPEN_STALL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::摆摊中") ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pDestHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_OPEN_STALL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::目标摆摊中") ;
		return PACKET_EXE_CONTINUE ;
	}
	// 死亡或者掉线不能交易
	if(pSourceHuman->GetHP() <= 0 || pSourceHuman->GetPlayer()->IsDisconnect())
	{//发起者死亡或者掉线
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_DEAD_OR_OFFLINE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d ERROR:DEAD OR OFFLINE", pSourceHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}
	if(pDestHuman->GetHP() <= 0 || pDestHuman->GetPlayer()->IsDisconnect()) // 验证过掉线
	{//目标死亡或者掉线
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_DEAD_OR_OFFLINE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d ERROR:TARGET DEAD OR OFFLINE ", pDestHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}
	// end of add
    //交易的玩家之间的距离超过xx米不能交易
    FLOAT fDistance = MySqrt( pDestHuman->getWorldPos(), pSourceHuman->getWorldPos() );
    if (fDistance > EXCHANGE_MAX_DISTANCE)
    {
        GCExchangeError Msg;
        Msg.SetID(EXCHANGE_MSG::ERR_TOO_FAR);
        pHuman->GetPlayer()->SendPacket(&Msg);
        g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 超过交易范围[%s]]",	pDestHuman->GetName(), pSourceHuman->GetName() ) ;
        return PACKET_EXE_CONTINUE;
    }

	//操作
	//发送消息向目标申请
	GCExchangeApplyI Msg;
	Msg.SetObjID(pSourceHuman->GetID());
	pDestHuman->GetPlayer()->SendPacket(&Msg);
	g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: SOURCEID = %d DESTID = %d", pSourceHuman->GetID(), pDestHuman->GetID() ) ;
	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}