using System.Collections; using System.Collections.Generic; using UnityEngine; public class UAVehicle : BattleObject, IPowerOwner { public const float MAX_ATTACK_RANGE = 10f; public const float MIN_FOLLOW_DISTANCE = 2f; private PowerManager powerManager; private Craft owner; private UAVItem uavItem; private float moveSpeed = 1f; public void Init (Map map, Craft owner, UAVItem uavItem) { this.map = map; this.owner = owner; this.userId = owner.userId; position = owner.position; map.AddUAVehicle (this); this.uavItem = uavItem; if (powerManager == null) { powerManager = new PowerManager (this, uavItem.GetData().attack, null, null); } else { powerManager.UpdatePower (uavItem.GetData().attack, null); } } public void Attack(Craft target) { if(target != null) { Power attack = GetPowerManager ().GetAttack (); if (target.team == owner.team) { if (TargetType.IsContainTarget (TargetType.ALLY, attack.targetType)) { this.target = target; return; } } else if (target.team != owner.team) { if (TargetType.IsContainTarget (TargetType.ENEMY, attack.targetType)) { this.target = target; return; } } } this.target = null; } public float GetDamage() { float value = uavItem.GetEquipment ().GetDmg (); if (value > 0) return value; value = uavItem.GetEquipment ().GetHp (); return value; } void Update() { if(IsDead()) { return; } if(owner.IsDead()) { Dead (); return; } if(target == null) { target = owner; } if (Vector3.Distance (target.position, this.position) > MIN_FOLLOW_DISTANCE) { this.position = Vector3.Lerp (this.position, owner.position, GameTime.deltaTime * moveSpeed); } else { if(CanAttack()){ GetPowerManager ().AttempUserPower (GetPowerManager ().GetAttack ().GetId (), Session.GetInstance ().GetBattleSession ().GetBattleController ()); } } if(Vector3.Distance(owner.position, this.position) > MAX_ATTACK_RANGE) { target = owner; } Rotate (); } private bool CanAttack() { if (owner.IsCtrl () || (owner.userId < 0 && Session.GetInstance ().GetBattleSession ().GetBattleController ().IsAITaker ())) { Craft craft = target as Craft; Power attack = GetPowerManager ().GetAttack (); uint targetType = TargetType.NONE; if (craft.team == owner.team) targetType = TargetType.ALLY; else if (craft.team != owner.team) targetType = TargetType.ENEMY; if(TargetType.IsContainTarget(targetType, attack.targetType)){ if(attack.GetPowerEffect() == Power.PowerEffect.Heal && craft.hp == craft.maxHp) { return false; } return true; } } return false; } private void Rotate() { if (target == null) return; Vector3 pos = target.position - this.position; pos.y = 0; if (pos.magnitude > 0) { Quaternion newRotation = Quaternion.LookRotation (pos); this.transform.rotation = newRotation; } } public PowerManager GetPowerManager() { return powerManager; } public void Teleport(int step) { } public override void Dead () { if(_isDead) return; deadPos = position; _isDead = true; deadTime = GameTime.time; map.RemoveUAVehicle (this); Destroy (this.gameObject); } }