/// 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; }
bool FightObj::CheckReturnPeace() { if (m_Owner->GetIsFlyToPeace() == 0) return false; long dis = Distance(m_EnterFightPos.x, m_EnterFightPos.y, m_Owner->GetTileX(), m_Owner->GetTileY()); unsigned long thisTime = timeGetTime(); if(m_AI->HasTarget()) { CMoveShape *target = m_AI->GetTarget(); if (target == NULL || PHASEMAN.PhasePlayerFilter(target,m_Owner)) { ReturnPeace(); return true; } if(target->IsDied() || !target->IsAttackAble(m_Owner) || !target->IsVisible(m_Owner)) { ReturnPeace(); return true; } if(dis > m_Owner->GetBaseChaseRange()) { ReturnPeace(); return true; } if(dis > m_Owner->GetReturnRange() && thisTime > m_HurtTime) { ReturnPeace(); return true; } } else if(thisTime > m_GuardTime) { ReturnPeace(); return true; } return false; }
void PetAI::OnSkillEnd(long subType) { LogoutRetPeaceAct(); AddRetPeaceAct(); if(eAdd_Type == subType && CShape::STATE_PEACE == GetOwner()->GetState()) { LogInfo(AI_MODULE, "PetAI Changed its owner\'s(id=%s) state from %s to %s", GetOwner()->GetExID().tostring(), CShape::State2Str(GetOwner()->GetState()), CShape::State2Str(CShape::STATE_PEACE) ); GetOwner()->ChangeStateTo(CShape::STATE_PEACE); } CMoveShape *target = GetTarget(); if(target == NULL || target->IsDied()) { Resume(CONTINUE_TIME); } }
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; }