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