Ejemplo n.º 1
0
    void GuardSearch::Execute( BaseType::EntityType *entity )
    {
        CMonster *pSelf = dynamic_cast<CMonster*>( entity->GetOwner() );
        ShapeListType player_list;
        ShapeListType monster_list;
        CServerRegion *pRegion = static_cast<CServerRegion*>( pSelf->GetFather() );
        CMoveShape *pTarget = NULL;

        if( CanAttackCurrent( pSelf, entity ) )
        {
            return;
        }

        // find the around players
        pRegion->FindAroundObject( pSelf, TYPE_PLAYER, player_list );
        // find the around monsters including the guards.
        pRegion->FindAroundObject( pSelf, TYPE_MONSTER, monster_list );

        // filter the result
        Filter filter( static_cast<CMonster*>( pSelf ) );
        filter_shape( player_list, filter );
        filter_shape( monster_list, filter );


        // retrieve the ai reference
        DWORD ai_ref = pSelf->GetAIReferrence( 0 );
        if( ai_ref >= 0 )
        {
            pTarget = SearchByAIRef1( pSelf, player_list, ai_ref );
        }

        if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 1 ) ) > 0 )
        {
            pTarget = SearchByAIRef2( pSelf, player_list, ai_ref );
        }	

        if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 2 ) ) > 0 )
        {
            pTarget = SearchByAIRef3( pSelf, monster_list, ai_ref );
        }

        if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 3 ) ) > 0 )
        {
            pTarget = SearchByAIRef4( pSelf, monster_list, ai_ref );
        }

        if( pTarget != NULL )
        {
            // search successfully
            entity->SetTarget( pTarget->GetExID(), pTarget->GetType() );
        }
        else if( entity->HasTarget() )
        {
            AI_EVENT_SENDER( entity ).ReturnPeace();
        }
    }
Ejemplo n.º 2
0
	static int IsValidOper( CShopManager *pShopMgr, CMessage *pMsg, const CGUID &npcID, long lShopID )
	{
		CPlayer *pPlayer = pMsg->GetPlayer();
		CServerRegion *pRegion = pMsg->GetRegion();
		if( pPlayer == NULL || pRegion == NULL )
		{
			return -2;
		}

		if( pPlayer->IsDied() )
		{
			return -1;
		}

		if( pPlayer->GetCurrentProgress() != CPlayer::PROGRESS_FBUSINESS )
		{
			PutoutLog( LOG_FILE, LT_WARNING, "The Player [%s] is not in PROGRESS_FBUSINESS state.",
				pPlayer->GetName() );
			return -1;
		}

		SetPlayerState( pPlayer, true );

		CMonster *pNPC = (CMonster*) pRegion->FindAroundObject( pPlayer, TYPE_MONSTER, npcID );
		if( pNPC == NULL )
		{
			return -1;
		}

		CShop *pShop = pShopMgr->GetShop( lShopID );
		if( pShop == NULL )
		{
			return -1;
		}

		// NPC是否与商店对应
		if( strcmp( pNPC->GetOriginName(), pShop->GetNpcOrigName() ) != 0 )
		{
			return -1;
		}

		if( pNPC->Distance( pPlayer ) > 10 )
		{
			return -1;
		}

		return 0;
	}
Ejemplo n.º 3
0
BOOL Guard::SearchEnemy()
{
	if( !CanSearchEnemy() )
	{
		return FALSE;
	}

	if( CanAttackCurrent() )
	{
		return FALSE;
	}

	ShapeListType player_list;
	ShapeListType monster_list;
	CServerRegion *pRegion = static_cast<CServerRegion*>( m_pOwner->GetFather() );
	CMonster *pSelf = static_cast<CMonster*>( m_pOwner );
	CMoveShape *pTarget = NULL;

	// find the around players
	pRegion->FindAroundObject( m_pOwner, TYPE_PLAYER, player_list );
	// find the around monsters including the guards.
	pRegion->FindAroundObject( m_pOwner, TYPE_MONSTER, monster_list );

	// filter the result
	Filter filter( static_cast<CMonster*>( m_pOwner ) );
	filter_shape( player_list, filter );
	filter_shape( monster_list, filter );


	// retrieve the ai reference
	DWORD ai_ref = pSelf->GetAIReferrence( 0 );
	if( ai_ref >= 0 )
	{
		pTarget = SearchByAIRef1( player_list, ai_ref );
	}

	if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 1 ) ) > 0 )
	{
		pTarget = SearchByAIRef2( player_list, ai_ref );
	}	

	if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 2 ) ) > 0 )
	{
		pTarget = SearchByAIRef3( monster_list, ai_ref );
	}

	if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 3 ) ) > 0 )
	{
		pTarget = SearchByAIRef4( monster_list, ai_ref );
	}

	if( pTarget != NULL )
	{
		// search successfully
		SetTarget( pTarget->GetType(), pTarget->GetExID() );
		return TRUE; 
	}
	else if( HasTarget() )
	{
		WhenLoseTarget();
	}

	return FALSE;	
}
Ejemplo n.º 4
0
//得到所用的作用对象
unsigned int CEffCirc::GetEffectObjs(list<CMoveShape*>& listObjs)
{
	listObjs.clear();
	int nNum = 0;
	list<POINT> listPos;
	m_pParam->nPosition = m_eCenter;
	
    if ( m_strNum!="" )
    {
          /// by:expter 2010/08/31 技能增加一个参数
          m_nNum = m_pParam->pFirer->GetSkillValue(m_pParam->nID,m_pParam->nLvl,m_strNum);
    }
    if( m_nNum < 0 )
        m_nNum = 0;

	CServerRegion* pServerRegion = (CServerRegion*)(m_pParam->pUser->GetFather());
	if(NULL == pServerRegion)	return 0;

	CBaseObject *pObj = pServerRegion->FindChildObject(m_pParam->nMouseShapeType,m_pParam->MouseShapeID);
	m_pParam->pMouseShape = dynamic_cast<CMoveShape*>(pObj);	

    CMoveShape *pExcept = NULL;
	if(m_eCenter == ePos_Self && m_pParam->pUser)
	{
		m_pParam->lDestX = m_pParam->pUser->GetTileX();
		m_pParam->lDestY = m_pParam->pUser->GetTileY();
	}
	else if (m_eCenter == ePos_Mouse)
	{
		m_pParam->lDestX = m_pParam->nMouseX;
		m_pParam->lDestY = m_pParam->nMouseY;
	}
	else if (m_eCenter == ePos_Dest && m_pParam->pMouseShape)
	{
		m_pParam->lDestX = m_pParam->pMouseShape->GetTileX();
		m_pParam->lDestY = m_pParam->pMouseShape->GetTileY();
        if( m_IsWithinObj)
            pExcept = m_pParam->pMouseShape;
	}
	else if(m_eCenter==ePos_DestCoord && m_pParam->lDestX==0 && m_pParam->lDestY==0 && m_pParam->pMouseShape)
	{
		m_pParam->lDestX = m_pParam->pMouseShape->GetTileX();
		m_pParam->lDestY = m_pParam->pMouseShape->GetTileY();
        if( m_IsWithinObj)
            pExcept = m_pParam->pMouseShape;
	}
	else if (m_eCenter == ePos_Coord)
	{
		m_pParam->lDestX = m_pParam->nMouseX;
		m_pParam->lDestY = m_pParam->nMouseY;
	}

	vector<CShape*> vOut;

	pServerRegion->FindAroundObject(m_pParam->pUser,TYPE_MONSTER,vOut);
	pServerRegion->FindAroundObject(m_pParam->pUser,TYPE_PLAYER,vOut);
	for (vector<CShape*>::iterator it=vOut.begin(); it!=vOut.end();++it)
	{
		if(m_eCenter == ePos_Self && (*it)!=m_pParam->pUser)
		{
			//使用者
			long lDistance = m_pParam->pUser->RealDistance((*it));
			if (lDistance<0)			
				lDistance = 0;
			
			if (lDistance>m_nRadius)
			{
				continue;
			}		
		}
		else if(m_eCenter == ePos_Mouse)
		{
			//鼠标
			if(Distance((*it)->GetTileX(),(*it)->GetTileY(),m_pParam->nMouseX,m_pParam->nMouseY)>m_nRadius)
			{
				continue;
			}			
		}
		else if(m_eCenter == ePos_Dest && m_pParam->pMouseShape && m_pParam->pMouseShape!=(*it))
		{
			//目标
			long lDistance = m_pParam->pMouseShape->RealDistance((*it));
			if (lDistance<0)
				lDistance = 0;
			if (lDistance>m_nRadius)
			{
				continue;			
			}		
		}
		else if(m_eCenter==ePos_DestCoord && m_pParam->lDestX!=0 && m_pParam->lDestY!=0)
		{
			//坐标
			if (Distance(m_pParam->lDestX,m_pParam->lDestY,(*it)->GetTileX(),(*it)->GetTileY())>m_nRadius)
			{
				continue;			
			}
		}
		else if (m_eCenter==ePos_Coord)
		{
			if (Distance(m_pParam->lDestX,m_pParam->lDestY,(*it)->GetTileX(),(*it)->GetTileY())>m_nRadius)
			{
				continue;			
			}
		}

        if ( pExcept )
        {
#ifdef _SKILL_INFO_D_      
            Log4c::Trace(SKILL_MODULE, "EffCirc:作用于对象外的玩家判断!\n");    
#endif
        }
		CMoveShape *pMoveShape = dynamic_cast<CMoveShape*>(*it);
		if(pMoveShape &&(NULL==m_pCondiGroup || m_pCondiGroup->Result(pMoveShape,m_pParam)))
		{
			++nNum;		
			if (m_nNum>0)
			{      
				if (m_nNum<nNum)
				{
					break;
				}
			}
            /// 除去范围内对象
            if( pExcept && pExcept == pMoveShape )
            {
                continue;                       
            }
			listObjs.push_back(pMoveShape);
		}		
	}	
	
	return nNum;
}
Ejemplo n.º 5
0
    bool PetAI::SearchEnemy()
    {
        CPet *owner = (CPet*) m_Owner;
        CMoveShape *host = owner->GetHost();
        if(NULL == host)
        {
			LogError(AI_MODULE, "m_Owner->GetHost() error.");
            return false;
        }
        CMoveShape *target = GetTarget();

        // 当前有追踪目标
        if(target != NULL)
        {
            long dis = owner->Distance(target);
            long tracDis = owner->GetTrackRange();
            if(!target->IsDied() &&
                tracDis > dis &&
                !target->IsGod())
            {
                return true;
            }
        }

        // 寻找所在场景
        CServerRegion *region = dynamic_cast<CServerRegion*>(host->GetFather());
        if(NULL == region)
        {
            return false;
        }

        vector<CShape*> vOut;
        region->FindAroundObject(owner, TYPE_PLAYER, vOut);
        region->FindAroundObject(owner, TYPE_MONSTER, vOut);
        region->FindAroundObject(owner, TYPE_PET, vOut);

        bool ret = false;
        map<long, CMoveShape*> AroundObjs;
        long distance = 0;
        for(size_t i=0; i < vOut.size(); ++i)
        {
            target = (CMoveShape*)vOut[i];
            if(target != NULL &&
                target->IsDied() &&
                !target->IsGod() &&
                target->IsAttackAble(owner))
            {
                distance = m_Owner->Distance(target->GetTileX(), target->GetTileY());
                AroundObjs[distance] = target;
                ret = true;
            }
        }

        if(ret)		// 满足条件设置对象
        {
            map<long, CMoveShape*>::iterator itr = AroundObjs.begin();
            target = itr->second;
            SetTarget(target->GetExID(), target->GetType());
            //if(PET_TYPE_TRAP == owner->GetPetType())
            //{
            //    owner->SetActTime(0, 0);		// 避免寻敌后无法攻击
            //    owner->OnTrapSpring();
            //}
        }

        return true;
    }