123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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<BattleObject> 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;
- }
- }
- }
|