void attack() { mOnEvent = onAttackEvent; mOnTimer = onAttackTimer; if (targetUnit == null || !targetUnit.isState(UnitState.Alive)) { next = Cmd.Idle; return; } mUnit.skill.targetUnit = targetUnit; Skill sk = mUnit.skill.getSkill(Skill.FuncType.Attack); if (Vector3.Distance(mUnit.pos, targetUnit.pos) <= sk.GS.distance) { mUnit.skill.targetPos = targetUnit.pos; mUnit.skill.play(sk.GS.id); } else { mUnit.move.nav(targetUnit, sk.GS.distance, delegate(bool arrive) { if (arrive) { mUnit.skill.targetPos = targetUnit.pos; mUnit.skill.play(sk.GS.id); } else { failed(Cmd.Attack); } }); } }
void idle() { mOnEvent = onIdleEvent; mOnTimer = onIdleTimer; mUnit.AddTimer(TimerDectect, 0.1f); mUnit.AddTimer(TimerWakeup, Randoms.range(3, 8)); }
void flee() { mOnEvent = onFleeEvent; mOnTimer = onFleeTimer; mUnit.move.nav(targetPos, 0, delegate(bool arrive) { if (arrive) { next = Cmd.Idle; } else { failed(Cmd.Flee); } }); }
void trace() { mOnEvent = onTraceEvent; mOnTimer = onTraceTimer; mUnit.move.nav(targetUnit, minDistance, delegate(bool arrive) { if (arrive) { next = Cmd.Idle; } else { failed(Cmd.Trace); } }); }
void patrol() { float r = Randoms.range(3f, this.patrolArea); float ang = Randoms.range(0f, 2 * Mathf.PI); targetPos = bornPos + new Vector3(Mathf.Cos(ang), 0, Mathf.Sin(ang)) * r; mOnEvent = onPatrolEvent; mOnTimer = onPatrolTimer; mUnit.move.nav(targetPos, 0, delegate(bool arrive) { if (arrive) { next = Cmd.Idle; } else { failed(Cmd.Patrol); } }); }