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 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); } }