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 ;
}
Beispiel #2
0
uint CGUseItemHandler::Execute(CGUseItem* pPacket,Player* pPlayer)
{
	__ENTER_FUNCTION
	USEITEM_RESULT	Result ;
	
	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 ;
	}
	//检查是否可以使用物品
	ID_t	BagIndex = pPacket->GetBagIndex();

	//检查物品是否合法
	Item*	pBagItem = HumanItemLogic::GetBagItem(pHuman,BagIndex);
	if (pBagItem == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler ERROR BagIndex=%d", BagIndex) ;
		return PACKET_EXE_ERROR ;
	}
	if(pBagItem->IsEmpty())
	{
		//Assert(FALSE) ; //物品得不到
		g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler Can't GetItem	BagIndex=%d", BagIndex) ;
		return PACKET_EXE_CONTINUE ;
	}
	ObjID_t	Target = pHuman->GetID();
	//1.0 当前版本使用物品只处理吃药  
	//1.1 版本使用物品处理药品,藏宝图,配方  
	if(!pBagItem->IsRuler(IRL_CANUSE))
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler Can't use item BagIndex=%d", BagIndex);
		return PACKET_EXE_CONTINUE ;
	}
	if(pHuman->GetLevel()>=pBagItem->GetItemLevel()) //级别检查
	{
		switch(pBagItem->GetItemClass()) 
		{
			case ICLASS_TASKITEM: //任务物品类
			case ICLASS_COMITEM: //药品的使用
				{
					ScriptID_t nScript = pBagItem->GetScriptID();
					SkillID_t nSkill = pBagItem->GetSkillID();
					if(INVALID_ID!= nScript)
					{
						if(FALSE == g_ScriptLogic.Item_IsSkillLikeScript(*pHuman, nScript))
						{
							g_ScriptLogic.Item_CallDefaultEvent(*pHuman, nScript, BagIndex);
							break;
						}
						else if(FALSE == g_ScriptLogic.Script_CancelImpacts(*pHuman, nScript))
						{
							//取消效果失败
							PET_GUID_t	PetGUID = pPacket->GetTargetPetGUID();

							Result = (USEITEM_RESULT)pHuman->GetHumanAI()->PushCommand_UseItem(
								pPacket->GetBagIndex(), 
								pPacket->GetTargetObjID(),
								*(pPacket->GetTargetPos()),
								PetGUID,
								pPacket->GetTargetItem() 
								);
						}
						else
						{
							Result = USEITEM_SUCCESS;
						}
					}
				}
				break;
			case ICLASS_IDENT:
				{
					Result = (USEITEM_RESULT)pHuman->UseIdentScroll(pPacket->GetBagIndex(),pPacket->GetTargetItem());
				}
				break;
			case ICLASS_STOREMAP://藏宝图
				{
					Result	=	(USEITEM_RESULT)pHuman->UseStoreMap(BagIndex);
				}
				break;

			case ICLASS_SOUL_BEAD://魂珠
				{
					SOUL_BEAD_INFO_TB* pGet = g_ItemTable.GetSoulBeadTB(pBagItem->GetItemTableIndex());
					Assert(NULL != pGet);
					ImpactID_t nImpactId = pGet->m_nImpactId;

					//已经有魂珠附体的状态
					OWN_IMPACT* pImpact = pHuman->Impact_GetFirstImpactOfSpecificMutexID(nImpactId);
					if( NULL != pImpact )
					{
						g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler Can't use item BagIndex=%d", BagIndex);
						return PACKET_EXE_CONTINUE ;
					}
	
					if(INVALID_ID != nImpactId)
					{
						if(g_ImpactCore.SendImpactToUnit(*(Obj_Character*)pHuman, nImpactId, pHuman->GetID(), pGet->m_nValidTime, FALSE, 0, BagIndex))
						{
							Result = USEITEM_SUCCESS;
							//删除魂珠道具
							ITEM_LOG_PARAM	ItemLogParam;
							ItemLogParam.OpType	= ITEM_USE;
							BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam, pHuman, BagIndex);
							if (bRet)
							{
								SaveItemLog(&ItemLogParam);
							}
						}
					}
				}
				break;
			default:
				{
					Result	=	USEITEM_INVALID;
				}
				break;
		}
	}
	else
	{
		Result = USEITEM_LEVEL_FAIL;
	}
	GCUseItemResult	Msg;
	Msg.SetResult(Result);
	pGamePlayer->SendPacket(&Msg);

	g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler BagIndex=%d Result=%d",
		BagIndex, Result  ) ;

	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

	return	PACKET_EXE_ERROR;
}
Beispiel #3
0
UINT CGUseItemHandler::Execute(CGUseItem* pPacket,Player* pPlayer)
{
	__ENTER_FUNCTION
	USEITEM_RESULT	Result ;
	
	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 );
	
	//检查是否可以使用物品
	ID_t	BagIndex = pPacket->GetBagIndex();
	Assert(BagIndex<MAX_BAG_SIZE);

	//检查物品是否合法
	Item*	pBagItem = HumanItemLogic::GetItem(pHuman,BagIndex);
	
	if(pBagItem->IsEmpty())
	{
		//Assert(FALSE) ; //物品得不到
		g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler Can't GetItem	BagIndex=%d", BagIndex) ;
		return PACKET_EXE_CONTINUE ;
	}
	ObjID_t	Target = pHuman->GetID();
	//1.0 当前版本使用物品只处理吃药  
	//1.1 版本使用物品处理药品,藏宝图,配方  
	if(!pBagItem->IsRuler(IRL_CANUSE))
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler Can't use item BagIndex=%d", BagIndex);
		return PACKET_EXE_CONTINUE ;
	}
	if(pHuman->GetLevel()>=pBagItem->GetItemLevel()) //级别检查
	{
		switch(pBagItem->GetItemClass()) 
		{
			case ICLASS_TASKITEM: //任务物品类
			case ICLASS_COMITEM: //药品的使用
				{
					if(CLASS_OF_IDENT(pBagItem))
					{
						Result = (USEITEM_RESULT)pHuman->UseIdentScroll(pPacket->GetBagIndex(),pPacket->GetTargetItem());
					}
					else
					{
						ScriptID_t nScript = pBagItem->GetScriptID();
						SkillID_t nSkill = pBagItem->GetSkillID();
						if(INVALID_ID!= nScript)
						{
							if(FALSE == g_ScriptLogic.Item_IsSkillLikeScript(*pHuman, nScript))
							{
								g_ScriptLogic.Item_CallDefaultEvent(*pHuman, nScript, BagIndex);
								break;
							}
							else if(FALSE == g_ScriptLogic.Script_CancelImpacts(*pHuman, nScript))
							{
								//取消效果失败
								PET_GUID_t	PetGUID = pPacket->GetTargetPetGUID();

								Result = (USEITEM_RESULT)pHuman->GetHumanAI()->PushCommand_UseItem(
									pPacket->GetBagIndex(), 
									pPacket->GetTargetObjID(),
									*(pPacket->GetTargetPos()),
									PetGUID,
									pPacket->GetTargetItem() 
									);
							}
							else
							{
								Result = USEITEM_SUCCESS;
							}
						}
					}
				}
				break;
			case ICLASS_STOREMAP://藏宝图
				{
					Result	=	(USEITEM_RESULT)pHuman->UseStoreMap(BagIndex);
				}
				break;
			default:
				{
					Result	=	USEITEM_INVALID;
				}
				break;
		}
	}
	else
	{
		Result = USEITEM_LEVEL_FAIL;
	}
	GCUseItemResult	Msg;
	Msg.SetResult(Result);
	pGamePlayer->SendPacket(&Msg);

	g_pLog->FastSaveLog( LOG_FILE_1, "CGUseItemHandler BagIndex=%d Result=%d",
		BagIndex, Result  ) ;

	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

	return	PACKET_EXE_ERROR;
}