bool FightStateScript::CheckTracer(BaseType::EntityType *entity) { if(m_State == TRACING) { int ret = m_SkillTracer.Run(entity); if(ret == SkillTracer::TIMEOUT || ret == SkillTracer::FAILED) { OnUseSkillEnd(ret); } if(ret == SkillTracer::Okay) { MonsterAI *ai = dynamic_cast<MonsterAI*>(entity); CMonster *monster = dynamic_cast<CMonster*>(entity->GetOwner()); CServerRegion *region = dynamic_cast<CServerRegion*>(monster->GetFather()); CMoveShape *target = AIUtils::FindShape(region, m_SkillTracer.m_TargetID); if(target == NULL) { OnUseSkillEnd(SkillTracer::FAILED); } else { ai->BeginSkill(m_SkillTracer.m_SkillID, m_SkillTracer.m_SkillLvl, target); long actTime = monster->GetActModify(m_SkillTracer.m_SkillID); ai->SetTimer(AIDriver::SCRIPT_EVENT, actTime); } } 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 FightStateScript::ReceiveEvent(BaseType::EntityType *entity, const BaseType::EventType &ev) { SelfType::ReceiveEvent(entity, ev); if(ev.Type() == ET_SCRIPT_USESKILL) { const ScriptUseSkillEvent &sev = (const ScriptUseSkillEvent&) ev; CMonster *monster = dynamic_cast<CMonster*>(entity->GetOwner()); CServerRegion *region = dynamic_cast<CServerRegion*>(monster->GetFather()); MonsterAI *ai = dynamic_cast<MonsterAI*>(entity); long id = sev.id; long lvl = sev.lvl; long actTime = monster->GetActModify(sev.id); if(sev.type == ScriptUseSkillEvent::SHAPE) { if(sev.trace) { // trace the target m_SkillTracer.Init(id, lvl, sev.targetId, sev.traceTime); m_skillScriptID = sev.scriptId; m_State = TRACING; entity->Resume(0); return ; } else { CMoveShape *target = AIUtils::FindShape(region, sev.targetId); if(target == NULL) { OnUseSkillEnd(SkillTracer::FAILED); return ; } ai->BeginSkill(id, lvl, target); } } else if(sev.type == ScriptUseSkillEvent::CELL) { ai->BeginSkill(id, lvl, sev.x, sev.y); } m_skillScriptID = sev.scriptId; // register act time timer ai->SetTimer(AIDriver::SCRIPT_EVENT, actTime); } else if(ev.Type() == ET_SCRIPT_SKILLEND) { OnUseSkillEnd(SkillTracer::Okay); } else if(ev.Type() == ET_KILL) { entity->ChangeState(ST_DEAD); } }