using UnityEngine; using System.Collections; using System.Collections.Generic; public class ShowAI : CraftAI { public Vector2 origin; // Use this for initialization override protected void Start () { base.Start(); checkTimeInterval = 2f; } // Update is called once per frame protected virtual void FixedUpdate () { if (owner.IsCtrl ()) ManualCheck (); else AICheck (); } private void ManualCheck() { if(owner.IsDead()) { return; } if(battleController.isGameOver) { return; } if(CheckDead()) { return; } if(owner.GetSwapManager().isPreparingSwap) { Debuger.Log("swap prapare time : "+owner.GetSwapManager().GetPreparingSwapTime()); if(owner.GetSwapManager().IsReadySwap()) { battleController.GetMessageManager().RequestSwap(owner.id, owner.GetSwapManager().GetTargetSwapId()); owner.GetSwapManager().RequestedSwap(); } } else if(GameTime.time-lastCheckTime >= checkTimeInterval) { lastCheckTime = GameTime.time; CheckAction(); } } private void CheckAction() { if(owner.target != null) { float targetDis = NumberUtil.distanceVector3(owner.position, owner.target.position, true); Power attack = owner.GetPowerManager().GetAttack(); if(!owner.target.CanShoot()) { owner.target = null; } else if(targetDis > owner.viewRange) { owner.target = null; } else if(targetDis > attack.GetDistance()) { if(!owner.isMoving) { Vector3 targetPos = owner.target.position; owner.MoveTo(targetPos.x, targetPos.z); } } else if(targetDis <= attack.GetDistance()) { if(owner.isMoving && !owner.forceMove) owner.StopMove(); owner.GetPowerManager().AttempUserPower(attack.GetId(), battleController); } } else { FindTarget(); if(owner.target == null) { CheckOccupy(); } } } protected override bool CheckOccupy () { if(!base.CheckOccupy()) return false; CrystalBase targetCrystal = battleController.GetMap().GetInRangeCrystalBase(owner.position); if(targetCrystal == null || targetCrystal.GetStation() != null) return false; List list = map.GetBattleObjectByRange(targetCrystal.position, targetCrystal.range, TeamUtil.GetOpponentTeam(owner.team)); if(list.Count > 0) return false; if(owner && targetCrystal != null) battleController.GetMessageManager().OccupyStation(owner, targetCrystal); return true; } private void AICheck() { if(CheckDead()) { return; } if(GameTime.time-lastCheckTime >= checkTimeInterval) { lastCheckTime = GameTime.time; if(origin.x == 0) origin.x = owner.col; if(origin.y == 0) origin.y = owner.row; if(!owner.isMoving) { // int col = (int)origin.x + Random.Range(-1, 2); // int row = (int)origin.y + Random.Range(-1, 2); if ((int)origin.x != owner.col && (int)origin.y != owner.row) { owner.MoveTo ((int)origin.x, (int)origin.y); } else if (Random.Range (0, 100) > 50) { // float angle = owner.rotateMoveTargetAngle + (Random.Range(0, 100) > 50 ? 1 : -1) * Random.Range (45f, 90f); // angle = NumberUtil.corverAngleBetween (angle, -180, 180f); // owner.Rotate (angle); } } } else { return; } } }