コード例 #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();
        }
    }
コード例 #2
0
ファイル: Guard.cpp プロジェクト: ueverything/mmo-resourse
BOOL Guard::CanAttackCurrent()
{
	if( !HasTarget() )
	{
		return FALSE;
	}

	CMoveShape *pTarget = GetTarget();
	long dis = m_pOwner->Distance( pTarget );
	long attack_range = static_cast<CMonster*>( m_pOwner )->GetAttribute( string( "C_GuardRange" ) );

	if( dis > attack_range )
	{
		return FALSE;
	}

	CMonster *pSelf = static_cast<CMonster*>( m_pOwner );
	DWORD ai_ref = 0;
	
	if( pTarget->GetType() == TYPE_PLAYER )
	{
		CPlayer *pPlayer = static_cast<CPlayer*>( pTarget );
		// ai reference 1
		ai_ref = pSelf->GetAIReferrence( 0 );
		if( ai_ref >= 0 )
		{
			if( pPlayer->GetPVPValue() >= ai_ref && !IsSameCamp( pPlayer, pSelf ) )
			{
				return TRUE;
			}
		}
		// ai reference 2
		ai_ref = pSelf->GetAIReferrence( 1 );
		if( ai_ref > 0 )
		{
			if( pPlayer->GetPkValue() >= ai_ref )
			{
				return TRUE;
			}
		}
	}
	
	// actually, it's not necessary to judge monsters, that because the property for the monsters will
	// not changed .So ignored here.
	// ...

	return FALSE;
}
コード例 #3
0
ファイル: Guard.cpp プロジェクト: ueverything/mmo-resourse
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;	
}