/// return true to filter shape. bool operator() ( CShape *pShape ) { CMoveShape *pDest = static_cast<CMoveShape*>( pShape ); if( pDest->IsDied() ) { return true; } if( pOwner->Distance( pShape ) > lRange ) { return true; } if (!pDest->IsVisible(pOwner) ) // ÒþÐÎ { return true; } if( pDest->GetExID() == pOwner->GetBefoolID() ) { return true; } if( AIUtilities::IsInGodState( pShape ) ) { return true; } return false; }
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(); } }
//发送技能失败消息 void COpSendMsg::CreateSKillFailMsg() { CMoveShape* pUser = m_pParam->pUser; if(m_strVariaName !="") { // [5/4/2009 chenxianj] m_lValue = (long)m_pParam->pVariableList->GetVarValue<double>(m_strVariaName.c_str(),0); // [5/4/2009 chenxianj] } //技能失败重置吟唱时间 if (pUser) { m_pParam->pUser->SetIntonateTime(timeGetTime(),0); } CMessage msg(MSG_S2C_SKILL_USE); msg.Add((CHAR)SKILL_USE_RESULT_FAILED); msg.Add( pUser->GetExID()); //id和等级 msg.Add((long)m_pParam->nID); msg.Add((BYTE)m_pParam->nLvl ); //全局id msg.Add(m_pParam->dwGlobleID); //错误类型 msg.Add((BYTE)m_lValue); CMoveShape* pPlayer = pUser; if( TYPE_PET == pUser->GetType() ) { pPlayer = pUser->GetHost(); } if(m_eRange == MsgRange_Single) msg.SendToPlayer(pPlayer->GetExID(), false); else if(m_eRange == MsgRange_Around) msg.SendToPlayers(m_pParam->SendMsgPlayers); #ifdef _DEBUG char str[256]=""; _snprintf(str, 256, "发送技能失败消息:技能ID:%6d,全局ID:%6d,阶段号:%d\n",m_pParam->nID,m_pParam->dwGlobleID, m_pParam->nProceNum); OutputDebugString(str); #endif }
void FightObj::ReturnPeace() { CMoveShape *target = m_AI->GetTarget(); if(target) { TauntEvents events(m_Owner->GetTauntHandler()); events.TargetLost(target->GetExID(), target->GetType()); } m_AI->ChangeState(ST_RETURN, ReturnEvent(m_EnterFightPos.x, m_EnterFightPos.y)); }
unsigned int CEffEventByParam::GetEffectObjs(list<CMoveShape*>& listObjs) { listObjs.clear(); int nNum=0; if (m_pParam->pEventVar && m_pParam->pEventVar->pVar) { CMoveShape *pMoveShape = (CMoveShape*)(m_pParam->pEventVar->pVar); if (pMoveShape) { m_pParam->pMouseShape = pMoveShape; m_pParam->nMouseShapeType = pMoveShape->GetType(); m_pParam->MouseShapeID = pMoveShape->GetExID(); listObjs.push_back(pMoveShape); ++nNum; } } return nNum; }
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; }
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; }