// TODO do here more than just direction change. // Updates units animation. public static void UpdateUnitAnimation(BasicUnit unit, GameObject unitObject) { // Gets unit animator. Animator animator = unitObject.GetComponent <Animator>(); if (animator == null) { return; } // Sets animation depending on facing. switch (unit.Facing) { case Direction.Up: animator.SetFloat("xFacing", 0); animator.SetFloat("yFacing", 1); break; case Direction.Left: animator.SetFloat("xFacing", -1); animator.SetFloat("yFacing", 0); break; case Direction.Down: animator.SetFloat("xFacing", 0); animator.SetFloat("yFacing", -1); break; case Direction.Right: animator.SetFloat("xFacing", 1); animator.SetFloat("yFacing", 0); break; } }
// Constructor. public AttackAction(BasicUnit executer, int cost = 0, Damage damage = null, int maxRange = 1, int minRange = 1) : base(executer, cost) { Tag = ActionTag.Attack; Damage = damage; MaxRange = maxRange; MinRange = minRange; }
// Constructors. public Cell(BasicTile tile, BasicUnit unit = null, BasicObject obj = null) { Position = new Coordinates(); Tile = tile; Unit = unit; Object = obj; }
// For cloning. public object Clone() { // We don't clone Cell to avoid recursion. BasicUnit unit = new BasicUnit(null, Facing, Class.Tag); unit.HealthPoints = (Parameter <int>)HealthPoints.Clone(); unit.ActionPoints = (Parameter <int>)ActionPoints.Clone(); return(unit); }
// Attack execution. public override bool Execute(List <Cell> targets, Map map) { // If no damage. if (Damage == null) { return(false); } // If no target. if (targets == null) { return(false); } // If more than one target. if (targets.Count != 1) { return(false); } Cell cell = targets[0]; // If no executer or cell to attack. if (Executer == null || cell == null) { return(false); } // If no target to attack. IDamageable target = cell.Unit; if (target == null) { return(false); } BasicUnit unit = Executer as BasicUnit; // If cell is not in range. if (!InRange(cell, map)) { return(false); } // If not enough action points. if (!unit.UseActionPoints(Cost)) { return(false); } unit.UpdateFacing(cell); unit.DealDamage(target, Damage); return(true); }
// Checks if position is in action range. public override bool InRange(Coordinates pos, Map map) { if (map == null || map.Cells == null || !map.Cells.ContainsKey(pos) || map.Cells[pos] == null || map.Cells[pos].Tile == null || !map.Cells[pos].Tile.Walkable) { return(false); } BasicUnit unit = Executer as BasicUnit; return(unit.Cell.Position.Equals(pos)); }
// For performance. public bool Equals(BasicUnit unit) { if (unit == null) { return(false); } // We don't check if Cell.Equals(unit.Cell) to avoid recursion. We also ignore actions. return(Facing.Equals(unit.Facing) && Class.Equals(unit.Class)); }
// Skill execution. public override bool Execute(List <Cell> targets, Map map) { // If no target. if (targets == null) { return(false); } // If more than one target. if (targets.Count != 1) { return(false); } Cell cell = targets[0]; // If no executer or cell to teleport. if (Executer == null || cell == null) { return(false); } BasicUnit unit = Executer as BasicUnit; // If target is not a wizard on the same cell. // TODO nullexception if (unit == null || unit.Cell == null || cell.Unit == null || !(cell.Unit.Class is Wizard && cell.Equals(unit.Cell))) { return(false); } // If cell is not in range. if (!InRange(cell, map)) { return(false); } // If not enough action points. if (!unit.UseActionPoints(Cost)) { return(false); } // finds random unoccupied cell to teleport the wizard to var targetCell = map.GetRandomUnoccupiedCell(false, false, true); unit.UpdateFacing(cell); unit.Cell.Unit = null; unit.Cell = targetCell; targetCell.Unit = unit; return(true); }
// Move execution. public override bool Execute(List <Cell> targets, Map map) { // If no target. if (targets == null) { return(false); } // If more than one target. if (targets.Count != 1) { return(false); } Cell cell = targets[0]; // If no executer or cell to move to. if (Executer == null || cell == null) { return(false); } Route route = null; // If cell is not in range. if (!InRange(cell.Position, map, ref route)) { return(false); } // If there is no route to move. if (route == null) { return(false); } BasicUnit unit = Executer as BasicUnit;; for (int i = 1; i < route.Length + 1; ++i) { if (unit.IsAlive) { BasicMove.Execute(route.Cells[i], map); } else { break; } } return(true); }
// Returns all cells in range. public override List <Cell> AllInRange(Map map) { if (map == null || map.Cells == null || Executer == null) { return(new List <Cell>()); } BasicUnit unit = Executer as BasicUnit; Cell center = map.Cells[unit.Cell.Position]; return(map.GetSelfCell(center)); }
// Move execution. public override bool Execute(List <Cell> targets, Map map) { // If no target. if (targets == null) { return(false); } // If more than one target. if (targets.Count != 1) { return(false); } Cell cell = targets[0]; // If no executer or cell to move to. if (Executer == null || cell == null) { return(false); } BasicUnit unit = Executer as BasicUnit; // If cell is not in range. if (!InRange(cell, map)) { return(false); } // If there is no place to move to. if (!cell.Tile.Walkable || cell.Unit != null) { return(false); } // If not enough action points. if (!unit.UseActionPoints(Cost)) { return(false); } unit.UpdateFacing(cell); unit.Cell.Unit = null; unit.Cell = cell; cell.Unit = unit; return(true); }
// Returns all cells in range. public override List <Cell> AllInRange(Map map) { if (map == null || map.Cells == null || Executer == null) { return(new List <Cell>()); } BasicUnit unit = Executer as BasicUnit; Cell center = map.Cells[unit.Cell.Position]; List <Cell> cells = map.GetCellsInRange(center, PossibleDistance).Keys.ToList(); cells.Remove(center); return(cells); }
// Returns all cells in range. public override List <Cell> AllInRange(Map map) { if (map == null || map.Cells == null || Executer == null) { return(new List <Cell>()); } BasicUnit unit = Executer as BasicUnit; Cell center = map.Cells[unit.Cell.Position]; List <Cell> cells = map.GetVisibleCells(center, MaxRange); cells.Remove(center); return(cells); }
// Equality override. public override bool Equals(object obj) { if (obj == null) { return(false); } // If obj can not be cast to BasicUnit. BasicUnit unit = obj as BasicUnit; if (unit == null) { return(false); } // We don't check if Cell.Equals(unit.Cell) to avoid recursion. We also ignore actions. return(Facing.Equals(unit.Facing) && Class.Equals(unit.Class)); }
// Checks if position is in action range. public override bool InRange(Coordinates pos, Map map) { if (map == null || map.Cells == null || !map.Cells.ContainsKey(pos) || map.Cells[pos] == null || map.Cells[pos].Tile == null || !map.Cells[pos].Tile.Walkable) { return(false); } BasicUnit unit = Executer as BasicUnit; int distance = unit.Cell.Position.Distance(pos); if (distance > MaxRange || distance < MinRange) { return(false); } if (!map.CanBeSeen(unit.Cell.Position, pos, MaxRange)) { return(false); } return(true); }
// Skill execution. public override bool Execute(List <Cell> targets, Map map) { // If no target. if (targets == null) { return(false); } // If more than one target. if (targets.Count != 1) { return(false); } Cell cell = targets[0]; // If no executer or cell to place spikes. if (Executer == null || cell == null) { return(false); } BasicUnit unit = Executer as BasicUnit; // If cell is not in range. if (!InRange(cell, map)) { return(false); } // If not enough action points. if (!unit.UseActionPoints(Cost)) { return(false); } unit.UpdateFacing(cell); new BasicObject(cell, ObjectType.Spikes); return(true); }
public bool InRange(Coordinates pos, Map map, ref Route route) { if (map == null || map.Cells == null || !map.Cells.ContainsKey(pos)) { return(false); } BasicUnit unit = Executer as BasicUnit; int minimumDistance = unit.Cell.Position.Distance(pos); if (minimumDistance > PossibleDistance || minimumDistance < 1) { return(false); } route = map.GetRoute(map.Cells[unit.Cell.Position], map.Cells[pos], PossibleDistance); if (route == null) { return(false); } return(true); }
// Returns all cells in range. public override List <Cell> AllInRange(Map map) { if (map == null || map.Cells == null || Executer == null) { return(new List <Cell>()); } BasicUnit unit = Executer as BasicUnit; Cell center = map.Cells[unit.Cell.Position]; List <Cell> cells = map.GetVisibleCells(center, MaxRange); for (int i = cells.Count - 1; i >= 0; --i) { if (cells[i].IsOccupied(false, true, false)) { cells.Remove(cells[i]); } } return(cells); }
// Gets new class from class tag. public static Class GetNewClass(ClassTag tag, BasicUnit unit) { Class clas; switch (tag) { case ClassTag.Rogue: clas = new Rogue(unit); break; case ClassTag.Wizard: clas = new Wizard(unit); break; case ClassTag.Warrior: clas = new Warrior(unit); break; default: clas = null; break; } return(clas); }
// Returns all cells in range. public override List <Cell> AllInRange(Map map) { if (map == null || map.Cells == null || Executer == null) { return(new List <Cell>()); } BasicUnit unit = Executer as BasicUnit; List <Cell> cellsInRange = new List <Cell>(); foreach (Coordinates pos in unit.Cell.Position.GetClose()) { if (!map.Cells.ContainsKey(pos) || map.Cells[pos].Unit != null || map.Cells[pos].Tile == null || !map.Cells[pos].Tile.Walkable || !map.CanBeSeen(unit.Cell.Position, pos, 1)) { continue; } cellsInRange.Add(map.Cells[pos]); } return(cellsInRange); }
// Attack execution. public override bool Execute(List <Cell> targets, Map map) { // If no damage. if (Damage == null) { return(false); } // If no target. if (targets == null) { return(false); } // If more than one target. if (targets.Count != 1) { return(false); } Cell cell = targets[0]; // If no executer or cell to attack. if (Executer == null || cell == null) { return(false); } // If no target to attack. BasicUnit target = cell.Unit; if (target == null) { return(false); } BasicUnit unit = Executer as BasicUnit; // If cell is not in range. if (!InRange(cell, map)) { return(false); } // If not enough action points. if (!unit.UseActionPoints(Cost)) { return(false); } var translation = Coordinates.GetVectorByDirection(unit.Cell.GetDirection(cell)); var targetCellCoords = new Coordinates(unit.Cell.Position.X + (int)translation.x, unit.Cell.Position.Y + (int)translation.y); var targetCell = map.Cells[targetCellCoords]; target.Cell.Unit = null; target.Cell = targetCell; targetCell.Unit = target; unit.UpdateFacing(targetCell); target.UpdateFacing(unit.Cell); unit.DealDamage(target, Damage); return(true); }
public Cell(Coordinates position, BasicTile tile, BasicUnit unit = null, BasicObject obj = null) : this(tile, unit, obj) { Position = position; }
// Constructor. protected Class(BasicUnit unit) { Unit = unit; }
// Constructor. public MoveAction(BasicUnit executer, int cost = 0) : base(executer, cost) { Tag = ActionTag.Move; }
// Assigns controlled unit. public void AssignUnit(BasicUnit unit) { ControlledUnit = unit; }
public SpikesTrapAction(BasicUnit executer, int cost = 0, int maxRange = 2) : base(executer, cost) { Tag = ActionTag.SpikesTrap; MaxRange = maxRange; }
// Constructor. public TeleportAction(BasicUnit executer, int cost = 0) : base(executer, cost) { Tag = ActionTag.Teleport; }