protected override ActorActionResult OnPerform(Actor user, Entity targetEntity, Vector2Int targetTile)
        {
            Vector2Int delta = MapUtils.To4Dir(targetTile - user.Entity.Cell);
            Vector2Int cell  = user.Entity.Cell + delta;

            if (user.CanOccupy(cell))
            {
                user.Entity.Position += delta;
            }

            return(null);
        }
Beispiel #2
0
        public override ActorActionResult TakeTurn()
        {
            var move = GetAbility(AbilitySignature.Move);

            if (target != null && move != null)
            {
                if (MapUtils.IsNeighborCells(target.Entity.Cell, Entity.Cell) == false)
                {
                    var dir   = target.Entity.Cell - Entity.Cell;
                    var delta = MapUtils.To4Dir(dir);

                    return(move.Perform(this, Entity.Cell + delta));
                }
            }

            return(null);
        }
        protected override ActorActionResult OnPerform(Actor user, Entity target, Vector2Int tile)
        {
            Item targetItem = null;

            if (target == null)
            {
                targetItem = user.Entity.Level.Entities.Get <Item>(tile);
            }
            else
            {
                targetItem = target.GetEntityComponent <Item>();
            }

            if (targetItem == null)
            {
                Debug.Log($"Can't take item at {tile}. No item found.");
                return(null);
            }

            Vector2Int actorCell = user.Entity.Cell;
            Vector2Int itemCell  = targetItem.Entity.Cell;

            if (actorCell == itemCell || MapUtils.IsNeighborCells(actorCell, itemCell))
            {
                var inv = user.Entity.GetEntityComponent <Inventory>();

                if (inv != null)
                {
                    Debug.Log($"Grabbing item {target.name}");
                    inv.Add(targetItem);
                }
                else
                {
                    Debug.Log($"Can't grab item {target.name}. Actor doesn't have inventory");
                }
            }

            return(null);
        }
 public override bool CanPerform(Actor user, Vector2Int tile)
 {
     return(base.CanPerform(user, tile) && MapUtils.IsNeighborCells(user.Entity.Cell, tile) && user.CanOccupy(tile));
 }