123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class ManualAI : CraftAI
- {
- public bool followTarget;
- // Update is called once per frame
- void FixedUpdate ()
- {
- 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;
- }
- }
|