VOID CGameInterface::PacketItem_UserItem(tActionItem* pActionItem, int targetServerID, fVector2& fvPos)
{
	//空物品
	if(!pActionItem || pActionItem->GetType() != AOT_ITEM) return;
	CObject_Item* pItem = (CObject_Item*)(((CActionItem_Item*)pActionItem)->GetItemImpl());
	if(!pItem) return;
	//必须是能够使用的物品
	if(pItem->GetItemClass()!=ICLASS_COMITEM && pItem->GetItemClass()!=ICLASS_TASKITEM) return;
	//特殊物品不能在背包中直接使用,例如,宠物技能书
	STRING strTemp;
	if(!CObject_Item::CheckUseInPackage(pItem, strTemp))
	{
		if(!strTemp.empty()) CGameProcedure::s_pEventSystem->PushEvent(GE_NEW_DEBUGMESSAGE, strTemp.c_str());
		return;
	}
	//组队跟随中...
	if(CObjectManager::GetMe()->GetMySelf()->GetCharacterData()->Get_TeamFollowFlag()) return;

	//检查目前选中的目标
	CObject* pObj = (CObject*)CObjectManager::GetMe()->FindServerObject(targetServerID);
	
	//检查物品是否能够直接使用
	int objID;
	PET_GUID_t petID;
	bool bCanuseDir = ((CObject_Item_Medicine*)pItem)->IsValidTarget(pObj, fvPos, objID, petID);

	if(bCanuseDir)
	{
		WORLD_POS posTarget(fvPos.x, fvPos.y);

		//能够直接使用
		CGUseItem msg;
		msg.SetBagIndex( pItem->GetPosIndex() );
		msg.SetTargetObjID(objID);
		msg.SetTargetPetGUID(petID);
		msg.SetTargetPos(&posTarget);

		CNetManager::GetMe()->SendPacket( &msg );
		return;
	}

	//如果已经选中目标,说明目标不合适,如果是用在自己宠物上的物品,说明宠物没有释放
	if(pObj || ((CObject_Item_Medicine*)pItem)->IsTargetOne())
	{
		CGameProcedure::s_pEventSystem->PushEvent(GE_NEW_DEBUGMESSAGE, "无效目标");
		return;
	}

	//需要选中目标,在鼠标上挂上物品
	CActionSystem::GetMe()->SetDefaultAction(pActionItem);
}
Beispiel #2
0
VOID CCursorMng::MouseCommand_Set( BOOL bHoverInUI, CObject* pSelectObj, const fVector3& fvPos, tActionItem* pActiveSkill )
{
    m_cmdCurrent_Left.m_typeMouse	= SCommand_Mouse::MCT_NULL;
    m_cmdCurrent_Right.m_typeMouse	= SCommand_Mouse::MCT_NULL;


    // 在UI上空
    if(bHoverInUI)
    {
        if(!pActiveSkill)
            return;

        switch(pActiveSkill->GetType())
        {
        // 修理装备
        case AOT_MOUSECMD_REPARE:
        {
            //左键挂锤子
            m_cmdCurrent_Left.m_typeMouse  = SCommand_Mouse::MCT_REPAIR;
            //右键取消
            m_cmdCurrent_Right.m_typeMouse = SCommand_Mouse::MCT_CANCLE_REPAIR;
        }
        break;

        //鉴定装备
        case AOT_MOUSECMD_IDENTIFY:
        {
            //左键鉴定
            m_cmdCurrent_Left.m_typeMouse  = SCommand_Mouse::MCT_UI_USE_IDENTIFY;
            //右键取消
            m_cmdCurrent_Right.m_typeMouse = SCommand_Mouse::MCT_UI_USE_CANCEL_IDENTIFY;
        }
        break;
        }
    }
    else
    {
        // 判断鼠标下有无选择对象来计算相应obj鼠标指令
        if( pSelectObj != NULL )
        {
            pSelectObj->FillMouseCommand_Left( &m_cmdCurrent_Left, pActiveSkill );
            pSelectObj->FillMouseCommand_Right( &m_cmdCurrent_Right, pActiveSkill );
        }
        else
        {
            if( !pActiveSkill )
            {
                // 如果鼠标下没有相应的对象, 就当作移动来处理, 改掉了必须要有个默认技能才能走路得问题
                m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_PLAYER_MOVETO;
                m_cmdCurrent_Left.m_afParam[0] = fvPos.x;
                m_cmdCurrent_Left.m_afParam[1] = fvPos.z;
            }

        }

        if( m_cmdCurrent_Left.m_typeMouse == SCommand_Mouse::MCT_NULL )
        {
            // 当前存在激活的技能
            if( pActiveSkill != NULL )
            {
                // 根据技能的类型设置鼠标行为
                switch( pActiveSkill->GetType() )
                {
                // 技能 和 宠物技能
                case AOT_SKILL:
                case AOT_PET_SKILL:
                {
                    const void* pSkillImpl = pActiveSkill->GetImpl();

                    // 不存在内部数据就设为行走状态
                    if( !pSkillImpl )
                    {
                        m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_PLAYER_MOVETO;
                        m_cmdCurrent_Left.m_afParam[0] = fvPos.x;
                        m_cmdCurrent_Left.m_afParam[1] = fvPos.z;

                        return;
                    }

                    // 根据是否为战斗技能处理是人物(或宠物)的技能选择类型
                    ENUM_SELECT_TYPE typeSel = (ENUM_SELECT_TYPE)(	pActiveSkill->GetType() == AOT_SKILL ?
                                               ((SCLIENT_SKILL*)pSkillImpl)->m_pDefine->m_nSelectType :	// 人物技能
                                               ((PET_SKILL*)pSkillImpl)->m_pDefine->m_nSelectType );		// 宠物技能

                    // 技能使用的鼠标选择逻辑
                    switch( typeSel )
                    {
                    // 点选角色
                    case SELECT_TYPE_CHARACTER:
                    {
                        m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_PLAYER_MOVETO;
                        m_cmdCurrent_Left.m_afParam[0] = fvPos.x;
                        m_cmdCurrent_Left.m_afParam[1] = fvPos.z;
                    }
                    break;

                    // 点选范围
                    case SELECT_TYPE_POS:
                    {
                        // 储存技能
                        m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_SKILL_AREA;		// 在自动技能时被改为 SCommand_Mouse::MCT_PLAYER_MOVETO;
                        m_cmdCurrent_Left.m_apParam[0] = (VOID*)pActiveSkill;
                        m_cmdCurrent_Left.m_afParam[1] = fvPos.x;
                        m_cmdCurrent_Left.m_afParam[2] = fvPos.z;
                    }
                    break;

                    // 方向
                    case SELECT_TYPE_DIR:
                    {
                        // 储存技能
                        m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_SKILL_DIR;	// 在自动技能时被改为 SCommand_Mouse::MCT_PLAYER_MOVETO;
                        m_cmdCurrent_Left.m_apParam[0] = (VOID*)pActiveSkill;

                        //====== 计算方向

                        // 主角位置
                        fVector3 fvPlayer = CObjectManager::GetMe()->GetMySelf()->GetPosition();
                        // 鼠标位置
                        fVector3 fvTarget = fvPos;

                        m_cmdCurrent_Left.m_afParam[1] = KLU_GetYAngle(fVector2(fvPlayer.x, fvPlayer.z), fVector2(fvTarget.x, fvTarget.z));
                    }
                    break;

                    case SELECT_TYPE_SELF:
                        // ERROR...
                        break;
                    }
                }
                break;

                // 物品
                case AOT_ITEM:
                {
                    if(!pActiveSkill || pActiveSkill->GetType() != AOT_ITEM)
                        break;

                    CObject_Item* pItem = (CObject_Item*)(((CActionItem_Item*)pActiveSkill)->GetItemImpl());
                    if(!pItem)
                        break;

                    // 必须是能够使用的物品
                    if(pItem->GetItemClass() != ICLASS_COMITEM)
                        break;

                    BOOL bAreaItem = ((CObject_Item_Medicine*)pItem)->IsAreaTargetType();

                    m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_USE_ITEM;
                    m_cmdCurrent_Left.m_apParam[0] = (VOID*)pActiveSkill;
                    m_cmdCurrent_Left.m_adwParam[1] = -1;
                    m_cmdCurrent_Left.m_afParam[2] = fvPos.x;
                    m_cmdCurrent_Left.m_afParam[3] = fvPos.z;
                    m_cmdCurrent_Left.m_adwParam[4] = bAreaItem;

                    m_cmdCurrent_Right.m_typeMouse = SCommand_Mouse::MCT_CANCEL_USE_ITEM;
                }
                break;

                // 修理单独处理
                case AOT_MOUSECMD_REPARE:
                {
                    //左键挂锤子
                    m_cmdCurrent_Left.m_typeMouse  = SCommand_Mouse::MCT_REPAIR;
                    //右键取消
                    m_cmdCurrent_Right.m_typeMouse = SCommand_Mouse::MCT_CANCLE_REPAIR;
                }
                break;

                // 鉴定装备
                case AOT_MOUSECMD_IDENTIFY:
                {
                    //左键鉴定
                    m_cmdCurrent_Left.m_typeMouse  = SCommand_Mouse::MCT_UI_USE_IDENTIFY;
                    //右键取消
                    m_cmdCurrent_Right.m_typeMouse = SCommand_Mouse::MCT_UI_USE_CANCEL_IDENTIFY;
                }
                break;

                // 添加好友
                case AOT_MOUSECMD_ADDFRIEND:
                {
                    m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_ADD_FRIEND;
                }
                break;

                default:
                    // 移动
                {
                    m_cmdCurrent_Left.m_typeMouse = SCommand_Mouse::MCT_PLAYER_MOVETO;
                    m_cmdCurrent_Left.m_afParam[0] = fvPos.x;
                    m_cmdCurrent_Left.m_afParam[1] = fvPos.z;
                }
                break;
                }
            }
        }

        // 跳跃 //好像都不太喜欢右键跳跃,忍痛割爱了
        /*if( m_cmdCurrent_Right.m_typeMouse == SCommand_Mouse::MCT_NULL )
        {
        	m_cmdCurrent_Right.m_typeMouse = SCommand_Mouse::MCT_PLAYER_JUMP;
        }*/
    }
}