public NodeBehaviour GetLinkInDirection(LinkPositions linkDir) { Vector3 direction; switch (linkDir) { case LinkPositions.Forward: direction = Vector3.forward; return(links.Find(x => x.position == position + direction)); break; case LinkPositions.Right: direction = Vector3.right; return(links.Find(x => x.position == position + direction)); break; case LinkPositions.Back: direction = Vector3.back; return(links.Find(x => x.position == position + direction)); break; case LinkPositions.Left: direction = Vector3.left; return(links.Find(x => x.position == position + direction)); break; } return(null); }
public override bool Execute() { if (!CheckTarget() || !CheckCost(actionCost)) { return(false); } LinkPositions direction = owner.currentNode.GetRelativePosition(target.GetComponent <NodeBehaviour>()); NodeBehaviour n = owner.currentNode; for (int i = 0; i < range; i++) { if (n.GetLinkInDirection(direction) != null) { n = n.GetLinkInDirection(direction); if (n.currentObject != null && n.currentObject.GetComponent <DestroyableProp>() != null) { n.currentObject.GetComponent <Health>().Damage(owner, 1); } foreach (LinkPositions d in LinkPositions.GetValues(typeof(LinkPositions))) { if (n.GetLinkInDirection(d) != null) { Targetable c = n.GetLinkInDirection(d).currentObject; if (c != null && c.GetComponent <DestroyableProp>() != null) { c.GetComponent <Health>().Damage(owner, 1); } } } } } List <NodeBehaviour> path = Pathfinder.GetPath(owner.currentNode, n); owner.GetComponent <GridNavMeshWrapper>().SetPath(path); Debug.Log(owner + " Executes " + name); return(true); }
public List <NodeBehaviour> CheckLines() { List <NodeBehaviour> tmpList = new List <NodeBehaviour>(); foreach (LinkPositions direction in LinkPositions.GetValues(typeof(LinkPositions))) { NodeBehaviour n = owner.currentNode; for (int i = 0; i < range; i++) { if (n.GetLinkInDirection(direction) != null) { n = n.GetLinkInDirection(direction); if (n.currentObject != null && n.currentObject.GetComponent <Pawn>() != null) { break; } tmpList.Add(n); } } } return(tmpList); }