123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- 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);
- }
- }
|