Items #3
@ -28,6 +28,8 @@ namespace Units
|
|||||||
private Weapon _weapon;
|
private Weapon _weapon;
|
||||||
private Vector2 _direction;
|
private Vector2 _direction;
|
||||||
private BarCanvas _barCanvas;
|
private BarCanvas _barCanvas;
|
||||||
|
private bool _isHardToCapture;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public bool IsBusy => _isBusy;
|
public bool IsBusy => _isBusy;
|
||||||
@ -42,17 +44,27 @@ namespace Units
|
|||||||
_isAlive = false;
|
_isAlive = false;
|
||||||
_hexGrid = hexGrid;
|
_hexGrid = hexGrid;
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
|
_isHardToCapture = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Move(HexDirection direction)
|
public void Move(HexDirection direction)
|
||||||
{
|
{
|
||||||
if (!_cell.GetNeighbor(direction) || _isBusy) return;
|
if (!_cell.GetNeighbor(direction) || _isBusy) return;
|
||||||
|
_unitView.StopHardCature();
|
||||||
if (_cell.GetNeighbor(direction).Color == _data.color)
|
if (_cell.GetNeighbor(direction).Color == _data.color)
|
||||||
{
|
{
|
||||||
DoTransit(direction);
|
DoTransit(direction);
|
||||||
}
|
}
|
||||||
|
else if (_cell.GetNeighbor(direction).Color != UnitColor.GREY)
|
||||||
|
{
|
||||||
|
_isHardToCapture = true;
|
||||||
|
_unitView.RegenMana(_mana);
|
||||||
|
DoTransit(direction);
|
||||||
|
}
|
||||||
|
|
||||||
else if (_mana - _hexGrid.HexCaptureCost >= 0)
|
else if (_mana - _hexGrid.HexCaptureCost >= 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
_mana -= _hexGrid.HexCaptureCost;
|
_mana -= _hexGrid.HexCaptureCost;
|
||||||
_unitView.RegenMana(_mana);
|
_unitView.RegenMana(_mana);
|
||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
@ -64,13 +76,17 @@ namespace Units
|
|||||||
{
|
{
|
||||||
_isBusy = true;
|
_isBusy = true;
|
||||||
_cell = _cell.GetNeighbor(direction);
|
_cell = _cell.GetNeighbor(direction);
|
||||||
|
|
||||||
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x, (_cell.transform.position - _instance.transform.position).normalized.z));
|
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x, (_cell.transform.position - _instance.transform.position).normalized.z));
|
||||||
_animator.SetTrigger("Move");
|
_animator.SetTrigger("Move");
|
||||||
_animator.SetBool("isMoving", _isBusy);
|
_animator.SetBool("isMoving", _isBusy);
|
||||||
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
|
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CaptureHex()
|
||||||
|
{
|
||||||
|
_cell.PaintHex(_data.color);
|
||||||
|
}
|
||||||
|
|
||||||
private void SetAnimLength()
|
private void SetAnimLength()
|
||||||
{
|
{
|
||||||
AnimationClip[] clips = _animator.runtimeAnimatorController.animationClips;
|
AnimationClip[] clips = _animator.runtimeAnimatorController.animationClips;
|
||||||
@ -108,7 +124,7 @@ namespace Units
|
|||||||
_animator = _instance.GetComponent<Animator>();
|
_animator = _instance.GetComponent<Animator>();
|
||||||
_unitView = _instance.GetComponent<UnitView>();
|
_unitView = _instance.GetComponent<UnitView>();
|
||||||
_barCanvas = _unitView.BarCanvas.GetComponent<BarCanvas>();
|
_barCanvas = _unitView.BarCanvas.GetComponent<BarCanvas>();
|
||||||
_unitView.SetUp(_barCanvas.SpawnShotUI(_weapon.shots), _weapon, RegenMana, _data.manaRegen);
|
_unitView.SetUp(_barCanvas.SpawnShotUI(_weapon.shots), _weapon, RegenMana, _data.manaRegen, CaptureHex);
|
||||||
SetAnimLength();
|
SetAnimLength();
|
||||||
_mana = _data.maxMana;
|
_mana = _data.maxMana;
|
||||||
_hp = _data.maxHP;
|
_hp = _data.maxHP;
|
||||||
@ -125,8 +141,16 @@ namespace Units
|
|||||||
private void MoveEnd()
|
private void MoveEnd()
|
||||||
{
|
{
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
_cell.PaintHex(_data.color);
|
|
||||||
_animator.SetBool("isMoving", _isBusy);
|
_animator.SetBool("isMoving", _isBusy);
|
||||||
|
if (_isHardToCapture)
|
||||||
|
{
|
||||||
|
_unitView.HardCaptureHex();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CaptureHex();
|
||||||
|
}
|
||||||
|
_isHardToCapture = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AttackEnd()
|
private void AttackEnd()
|
||||||
|
@ -25,17 +25,31 @@ public class UnitView : MonoBehaviour
|
|||||||
private Coroutine _previosRegen;
|
private Coroutine _previosRegen;
|
||||||
private Coroutine _previosReload;
|
private Coroutine _previosReload;
|
||||||
private int _mana;
|
private int _mana;
|
||||||
|
private Action _capureHex;
|
||||||
|
private Coroutine _captureHexCoroutine;
|
||||||
|
|
||||||
public GameObject BarCanvas => barCanvas;
|
public GameObject BarCanvas => barCanvas;
|
||||||
public GameObject AimCanvas => aimCanvas;
|
public GameObject AimCanvas => aimCanvas;
|
||||||
|
|
||||||
public void SetUp(Stack<ShotUIView> shots, Weapon weapon, Action RegenMana, int manaRegen)
|
public void SetUp(Stack<ShotUIView> shots, Weapon weapon, Action regenMana, int manaRegen, Action captureHex)
|
||||||
{
|
{
|
||||||
_shootUIStack = shots;
|
_shootUIStack = shots;
|
||||||
_weapon = weapon;
|
_weapon = weapon;
|
||||||
_toReloadStack = new Stack<ShotUIView>();
|
_toReloadStack = new Stack<ShotUIView>();
|
||||||
_startRegen = RegenMana;
|
_startRegen = regenMana;
|
||||||
_manaRegen = manaRegen;
|
_manaRegen = manaRegen;
|
||||||
|
_capureHex = captureHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HardCaptureHex()
|
||||||
|
{
|
||||||
|
_captureHexCoroutine = StartCoroutine(HardCapture());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopHardCature()
|
||||||
|
{
|
||||||
|
if (_captureHexCoroutine != null)
|
||||||
|
StopCoroutine(_captureHexCoroutine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Shoot()
|
public bool Shoot()
|
||||||
@ -48,6 +62,7 @@ public class UnitView : MonoBehaviour
|
|||||||
{
|
{
|
||||||
StopCoroutine(_previosReload);
|
StopCoroutine(_previosReload);
|
||||||
}
|
}
|
||||||
|
|
||||||
_previosReload = StartCoroutine(Reload());
|
_previosReload = StartCoroutine(Reload());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -109,9 +124,16 @@ public class UnitView : MonoBehaviour
|
|||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return new WaitForSeconds(1f);
|
yield return new WaitForSeconds(1f);
|
||||||
_mana += _manaRegen;
|
_mana += _manaRegen;
|
||||||
_startRegen.Invoke();
|
_startRegen.Invoke();
|
||||||
StartCoroutine(Regen());
|
StartCoroutine(Regen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerator HardCapture()
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(3f);
|
||||||
|
_capureHex.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user