public virtual void Move(Cell destinationCell, List <Cell> path, TrapManager trapmanager) { if (isMoving) { return; } var totalMovementCost = path.Sum(h => h.MovementCost); if (MovementPoints < totalMovementCost) { return; } MovementPoints -= totalMovementCost; Cell.IsTaken = false; Cell.Occupent = null; bool trapfound = false; List <Cell> TrapPath = new List <Cell>(); foreach (Cell c in path) { if (!trapfound) { TrapPath.Add(c); } if (trapmanager.findTrap(c)) { trapmanager.Trigger(this); trapfound = true; } } TrapPath.Reverse(); Cell = destinationCell; destinationCell.IsTaken = true; destinationCell.Occupent = this; if (MovementSpeed > 0 && trapfound) { StartCoroutine(MovementAnimation(TrapPath)); } else if (MovementSpeed > 0 && !trapfound) { StartCoroutine(MovementAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null && trapfound) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, TrapPath)); } else if (UnitMoved != null && !trapfound) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } }
public virtual void Dash(Cell destinationCell, List <Cell> path, TrapManager trapmanager) { Cell.IsTaken = false; Cell.Occupent = null; bool trapfound = false; List <Cell> TrapPath = new List <Cell>(); foreach (Cell c in path) { if (!trapfound) { TrapPath.Add(c); } if (trapmanager.findTrap(c)) { trapmanager.Trigger(this); trapfound = true; } } TrapPath.Reverse(); Cell = destinationCell; Cell.IsTaken = true; Cell.Occupent = this; if (MovementSpeed > 0 && trapfound) { StartCoroutine(RunAnimation(TrapPath)); } else if (MovementSpeed > 0 && !trapfound) { StartCoroutine(RunAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null && trapfound) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, TrapPath)); } else if (UnitMoved != null && !trapfound) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } }