fixed items, fixed retreet on enemy capture
This commit is contained in:
parent
e51a742d2c
commit
6f1f5911cd
@ -1,5 +1,6 @@
|
|||||||
using DefaultNamespace;
|
using DefaultNamespace;
|
||||||
using HexFiled;
|
using HexFiled;
|
||||||
|
using Units;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items
|
namespace Items
|
||||||
@ -21,16 +22,16 @@ namespace Items
|
|||||||
|
|
||||||
public BonusType BonusType => bonusType;
|
public BonusType BonusType => bonusType;
|
||||||
|
|
||||||
public override void PickUp(UnitColor color)
|
public override void PickUp(Unit unit)
|
||||||
{
|
{
|
||||||
if(bonusType != BonusType.Heal)
|
if(bonusType != BonusType.Heal)
|
||||||
base.PickUp(color);
|
base.PickUp(unit);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Unit = HexManager.UnitCurrentCell[color].unit;
|
Unit = unit;
|
||||||
VFXController.Instance.PlayEffect(usisngVFX, Unit.Instance.transform);
|
VFXController.Instance.PlayEffect(usisngVFX, Unit.Instance.transform);
|
||||||
Unit.UnitView.OnHit.Invoke(-value);
|
Unit.UnitView.OnHit.Invoke(-value);
|
||||||
|
Despawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace Items
|
|||||||
[SerializeField] private Sprite icon;
|
[SerializeField] private Sprite icon;
|
||||||
[SerializeField] private bool isInvokeOnPickUp = false;
|
[SerializeField] private bool isInvokeOnPickUp = false;
|
||||||
[SerializeField] private ItemType type;
|
[SerializeField] private ItemType type;
|
||||||
|
|
||||||
public ItemType Type => type;
|
public ItemType Type => type;
|
||||||
|
|
||||||
public bool IsInvokeOnPickUp => isInvokeOnPickUp;
|
public bool IsInvokeOnPickUp => isInvokeOnPickUp;
|
||||||
@ -45,17 +45,19 @@ namespace Items
|
|||||||
|
|
||||||
public GameObject Spawn(HexCell cell, GameObject parent, GameObject iconPrefab)
|
public GameObject Spawn(HexCell cell, GameObject parent, GameObject iconPrefab)
|
||||||
{
|
{
|
||||||
_instance = GameObject.Instantiate(iconPrefab, cell.transform.position + new Vector3(0, 1, 0),Quaternion.identity, parent.transform);
|
_instance = GameObject.Instantiate(iconPrefab, cell.transform.position + new Vector3(0, 1, 0),
|
||||||
|
Quaternion.identity, parent.transform);
|
||||||
_instance.AddComponent<ItemView>().SetUp(this);
|
_instance.AddComponent<ItemView>().SetUp(this);
|
||||||
cell.Item = this;
|
cell.Item = this;
|
||||||
_instance.AddComponent<CapsuleCollider>().isTrigger = true;
|
_instance.AddComponent<CapsuleCollider>().isTrigger = true;
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void PickUp(UnitColor color)
|
public virtual void PickUp(Unit unit)
|
||||||
{
|
{
|
||||||
if (HexManager.UnitCurrentCell.TryGetValue(color, out var value))
|
Unit = unit;
|
||||||
Unit = value.unit;
|
unit.PickUpItem(this);
|
||||||
|
Despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Despawn()
|
public void Despawn()
|
||||||
|
@ -22,6 +22,7 @@ namespace Chars
|
|||||||
private Joystick _placeJoystick;
|
private Joystick _placeJoystick;
|
||||||
private UnitView _unitView;
|
private UnitView _unitView;
|
||||||
private Vector2 _attackDircetion;
|
private Vector2 _attackDircetion;
|
||||||
|
private HexDirection previousDir;
|
||||||
|
|
||||||
private bool returnedMoveJoystick = false;
|
private bool returnedMoveJoystick = false;
|
||||||
|
|
||||||
@ -159,8 +160,11 @@ namespace Chars
|
|||||||
|
|
||||||
public void FixedExecute()
|
public void FixedExecute()
|
||||||
{
|
{
|
||||||
if (_moveJoystick.Direction.normalized.Equals(Vector2.zero) || _unit.IsHardToCapture)
|
if ((previousDir != DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized) ||
|
||||||
|
_moveJoystick.isJoysticDirectionZero) && _unit.IsHardToCapture)
|
||||||
|
{
|
||||||
returnedMoveJoystick = _unit.IsHardToCapture;
|
returnedMoveJoystick = _unit.IsHardToCapture;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_unit.IsAlive || _moveJoystick.Direction == Vector2.zero) return;
|
if (!_unit.IsAlive || _moveJoystick.Direction == Vector2.zero) return;
|
||||||
|
|
||||||
@ -190,6 +194,8 @@ namespace Chars
|
|||||||
{
|
{
|
||||||
_unit.Move(DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized));
|
_unit.Move(DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previousDir = DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -245,6 +245,30 @@ namespace Units
|
|||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CanPickUpItem(Item item)
|
||||||
|
{
|
||||||
|
switch (item.Type)
|
||||||
|
{
|
||||||
|
case ItemType.ATTACK:
|
||||||
|
if (_inventory.Count < _data.inventoryCapacity / 2)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ItemType.DEFENCE:
|
||||||
|
if (_inventoryDefence.Count < _data.inventoryCapacity / 2)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool PickUpItem(Item item)
|
public bool PickUpItem(Item item)
|
||||||
{
|
{
|
||||||
switch (item.Type)
|
switch (item.Type)
|
||||||
@ -252,7 +276,6 @@ namespace Units
|
|||||||
case ItemType.ATTACK:
|
case ItemType.ATTACK:
|
||||||
if (_inventory.Count < _data.inventoryCapacity / 2)
|
if (_inventory.Count < _data.inventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
item.PickUp(_data.color);
|
|
||||||
_inventory.Add(item);
|
_inventory.Add(item);
|
||||||
OnItemPickUp?.Invoke(item);
|
OnItemPickUp?.Invoke(item);
|
||||||
_cell.Item = null;
|
_cell.Item = null;
|
||||||
@ -263,18 +286,18 @@ namespace Units
|
|||||||
case ItemType.DEFENCE:
|
case ItemType.DEFENCE:
|
||||||
if (_inventoryDefence.Count < _data.inventoryCapacity / 2)
|
if (_inventoryDefence.Count < _data.inventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
item.PickUp(_data.color);
|
|
||||||
_inventoryDefence.Add(item);
|
_inventoryDefence.Add(item);
|
||||||
OnItemPickUp?.Invoke(item);
|
OnItemPickUp?.Invoke(item);
|
||||||
_cell.Item = null;
|
_cell.Item = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,10 +175,11 @@ public class UnitView : MonoBehaviour
|
|||||||
{
|
{
|
||||||
ItemView itemView = other.GetComponent<ItemView>();
|
ItemView itemView = other.GetComponent<ItemView>();
|
||||||
|
|
||||||
if (itemView == null || itemView.pickedUp || !_unit.PickUpItem(itemView.Item)) return;
|
if (itemView == null || itemView.pickedUp || !_unit.CanPickUpItem(itemView.Item)) return;
|
||||||
itemView.pickedUp = true;
|
itemView.pickedUp = true;
|
||||||
|
itemView.Item.PickUp(_unit);
|
||||||
ItemFabric.Items.Remove(itemView.gameObject);
|
ItemFabric.Items.Remove(itemView.gameObject);
|
||||||
Destroy(itemView.gameObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator Reload()
|
private IEnumerator Reload()
|
||||||
|
@ -44,6 +44,7 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
|||||||
public event Action OnTouchUp;
|
public event Action OnTouchUp;
|
||||||
public event Action OnTouchDown;
|
public event Action OnTouchDown;
|
||||||
public event Action<Vector2> OnDrug;
|
public event Action<Vector2> OnDrug;
|
||||||
|
public bool isJoysticDirectionZero;
|
||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private Camera cam;
|
private Camera cam;
|
||||||
@ -90,6 +91,8 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
|||||||
FormatInput();
|
FormatInput();
|
||||||
HandleInput(input.magnitude, input.normalized, radius, cam);
|
HandleInput(input.magnitude, input.normalized, radius, cam);
|
||||||
handle.anchoredPosition = input * radius * handleRange;
|
handle.anchoredPosition = input * radius * handleRange;
|
||||||
|
isJoysticDirectionZero = Direction.Equals(Vector2.zero);
|
||||||
|
|
||||||
OnDrug?.Invoke(Direction);
|
OnDrug?.Invoke(Direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user