fixed items, fixed retreet on enemy capture

This commit is contained in:
dddushesss 2022-02-03 21:27:56 +03:00
parent e51a742d2c
commit 6f1f5911cd
7 changed files with 53 additions and 16 deletions

View File

@ -1,5 +1,6 @@
using DefaultNamespace;
using HexFiled;
using Units;
using UnityEngine;
namespace Items
@ -21,16 +22,16 @@ namespace Items
public BonusType BonusType => bonusType;
public override void PickUp(UnitColor color)
public override void PickUp(Unit unit)
{
if(bonusType != BonusType.Heal)
base.PickUp(color);
base.PickUp(unit);
else
{
Unit = HexManager.UnitCurrentCell[color].unit;
Unit = unit;
VFXController.Instance.PlayEffect(usisngVFX, Unit.Instance.transform);
Unit.UnitView.OnHit.Invoke(-value);
Despawn();
}
}

View File

@ -31,7 +31,7 @@ namespace Items
[SerializeField] private Sprite icon;
[SerializeField] private bool isInvokeOnPickUp = false;
[SerializeField] private ItemType type;
public ItemType Type => type;
public bool IsInvokeOnPickUp => isInvokeOnPickUp;
@ -45,17 +45,19 @@ namespace Items
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);
cell.Item = this;
_instance.AddComponent<CapsuleCollider>().isTrigger = true;
return _instance;
}
public virtual void PickUp(UnitColor color)
public virtual void PickUp(Unit unit)
{
if (HexManager.UnitCurrentCell.TryGetValue(color, out var value))
Unit = value.unit;
Unit = unit;
unit.PickUpItem(this);
Despawn();
}
public void Despawn()

View File

@ -22,6 +22,7 @@ namespace Chars
private Joystick _placeJoystick;
private UnitView _unitView;
private Vector2 _attackDircetion;
private HexDirection previousDir;
private bool returnedMoveJoystick = false;
@ -159,8 +160,11 @@ namespace Chars
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;
}
if (!_unit.IsAlive || _moveJoystick.Direction == Vector2.zero) return;
@ -190,6 +194,8 @@ namespace Chars
{
_unit.Move(DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized));
}
previousDir = DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized);
}
public void Dispose()

View File

@ -245,6 +245,30 @@ namespace Units
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)
{
switch (item.Type)
@ -252,7 +276,6 @@ namespace Units
case ItemType.ATTACK:
if (_inventory.Count < _data.inventoryCapacity / 2)
{
item.PickUp(_data.color);
_inventory.Add(item);
OnItemPickUp?.Invoke(item);
_cell.Item = null;
@ -263,18 +286,18 @@ namespace Units
case ItemType.DEFENCE:
if (_inventoryDefence.Count < _data.inventoryCapacity / 2)
{
item.PickUp(_data.color);
_inventoryDefence.Add(item);
OnItemPickUp?.Invoke(item);
_cell.Item = null;
return true;
}
break;
default:
throw new ArgumentOutOfRangeException();
}
return false;
}

View File

@ -175,10 +175,11 @@ public class UnitView : MonoBehaviour
{
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.Item.PickUp(_unit);
ItemFabric.Items.Remove(itemView.gameObject);
Destroy(itemView.gameObject);
}
private IEnumerator Reload()

View File

@ -44,6 +44,7 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
public event Action OnTouchUp;
public event Action OnTouchDown;
public event Action<Vector2> OnDrug;
public bool isJoysticDirectionZero;
private Canvas canvas;
private Camera cam;
@ -90,6 +91,8 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
FormatInput();
HandleInput(input.magnitude, input.normalized, radius, cam);
handle.anchoredPosition = input * radius * handleRange;
isJoysticDirectionZero = Direction.Equals(Vector2.zero);
OnDrug?.Invoke(Direction);
}

File diff suppressed because one or more lines are too long