예제 #1
0
        public override bool CanTarget(GridOccupant target, GridOccupant wielder, Grid.Grid grid)
        {
            var direction = target.Position - wielder.Position;

            if (!direction.IsCardinal() || direction.CardinalMagnitude() > 1)
            {
                return(false);
            }

            var node = new Grid.Grid.Node();

            if (grid.TryGetNodeAt(wielder.Position, ref node))
            {
                return(node.Occupants.Any(it => TargetTypes.Contains(it.Type)));
            }

            return(false);
        }
예제 #2
0
        public virtual List <Grid.Grid.Node> FindEffectedNodes(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var occupants = FindTargets(wielder, direction, grid);
            var nodes     = new List <Grid.Grid.Node>();

            foreach (var occupant in occupants)
            {
                if (nodes.FindIndex(it => it.Position == occupant.Position) > -1)
                {
                    var n = new Grid.Grid.Node();
                    if (grid.TryGetNodeAt(occupant.Position, ref n))
                    {
                        nodes.Add(n);
                    }
                }
            }

            return(nodes);
        }
예제 #3
0
        // public override Grid.Grid.Node[] FindTargets(Grid.Grid.Node wielder, Grid.Grid grid)
        // {
        //     var neighbours = grid.GetNeighbours(wielder);
        //
        //     // todo(chris) consider optimising as this will be used by every mellee enemy on the grid
        //     return neighbours.Where(node => node.Occupants.Any(it => it.Tags.Intersect(TargetTypes).Any())).ToArray();
        // }

        // todo(chris) shouldnt this only find targets in direction??
        public override GridOccupant[] FindTargets(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var node = new Grid.Grid.Node();

            if (grid.TryGetNodeAt(wielder.Position, ref node))
            {
                var neighbours = grid.GetNeighbours(node);

                var targets = new List <GridOccupant>();

                foreach (var neighbour in neighbours)
                {
                    var validOccupants = neighbour.Occupants.Where(it => TargetTypes.Contains(it.Type));
                    targets.AddRange(validOccupants);
                }

                return(targets.ToArray());
            }

            return(null);
        }
예제 #4
0
        public PathDetails CalculatePath(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            PathDetails path = new PathDetails
            {
                Travelled        = new List <Grid.Grid.Node>(),
                IsLastNodeTarget = false
            };

            var normalised = direction.CardinalNormalise();

            var magnitude = projectile.Range;
            var node      = new Grid.Grid.Node();

            for (int i = 1; i <= magnitude; i++)
            {
                if (grid.TryGetNodeAt(wielder.Position + i * normalised, ref node))
                {
                    path.Travelled.Add(node);

                    // if we have hit something that has a type then weve eiher hit something we cant move though
                    // or weve hit our target
                    if (node.Occupants.Any(it => it.Type != null))
                    {
                        path.IsLastNodeTarget = node.Occupants.Any(it => it.Type != null && TargetTypes.Contains(it.Type));
                        break;
                    }
                    // todo(chris) add back in when we implement penetration
                    // else
                    // {
                    //     var targetOccupants = node.Occupants.Where(it => TargetTypes.Contains(it.Type));
                    //
                    //     var gridOccupants = targetOccupants as GridOccupant[] ?? targetOccupants.ToArray();
                    //
                    //     // occupant isnt a target so cant go through
                    //     if (gridOccupants.Length == 0)
                    //     {
                    //         break;
                    //     }
                    //
                    //     path.Hits.Add(node);
                    //
                    //     var penetrating = gridOccupants.Where(occupant => projectile.PenitrationTags.Contains(occupant.Type));
                    //
                    //     var penetratingArray = penetrating as GridOccupant[] ?? penetrating.ToArray();
                    //
                    //     // cant penetrate target to this will be as far as we go
                    //     if (penetratingArray.Length == 0)
                    //     {
                    //         break;
                    //     }
                    //
                    //     // if we cant penetrate all then we are done
                    //     if (remainingDepth <= penetratingArray.Length)
                    //     {
                    //         break;
                    //     }
                    //
                    //    // continue;
                    // }
                }
                else
                {
                    break;
                }
            }

            if (path.IsLastNodeTarget && path.Travelled.Count == 0)
            {
                path = new PathDetails
                {
                    Travelled        = new List <Grid.Grid.Node>(),
                    IsLastNodeTarget = false
                };
            }
            else
            {
                path.Travelled.RemoveAt(0);
            }

            return(path);
        }