Пример #1
0
        // 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;
            }
        }
Пример #2
0
 // 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;
 }
Пример #3
0
 // Constructors.
 public Cell(BasicTile tile, BasicUnit unit = null, BasicObject obj = null)
 {
     Position = new Coordinates();
     Tile     = tile;
     Unit     = unit;
     Object   = obj;
 }
Пример #4
0
        // 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);
        }
Пример #5
0
        // 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);
        }
Пример #6
0
        // 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));
        }
Пример #7
0
        // 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));
        }
Пример #8
0
        // 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);
        }
Пример #9
0
        // 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);
        }
Пример #10
0
        // 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));
        }
Пример #11
0
        // 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);
        }
Пример #12
0
        // 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);
        }
Пример #13
0
        // 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);
        }
Пример #14
0
        // 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));
        }
Пример #15
0
        // 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);
        }
Пример #16
0
        // 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);
        }
Пример #17
0
        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);
        }
Пример #18
0
        // 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);
        }
Пример #19
0
        // 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);
        }
Пример #20
0
        // 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);
        }
Пример #21
0
        // 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);
        }
Пример #22
0
 public Cell(Coordinates position, BasicTile tile, BasicUnit unit = null, BasicObject obj = null) : this(tile, unit, obj)
 {
     Position = position;
 }
Пример #23
0
 // Constructor.
 protected Class(BasicUnit unit)
 {
     Unit = unit;
 }
Пример #24
0
 // Constructor.
 public MoveAction(BasicUnit executer, int cost = 0) : base(executer, cost)
 {
     Tag = ActionTag.Move;
 }
Пример #25
0
 // Assigns controlled unit.
 public void AssignUnit(BasicUnit unit)
 {
     ControlledUnit = unit;
 }
Пример #26
0
 public SpikesTrapAction(BasicUnit executer, int cost = 0, int maxRange = 2) : base(executer, cost)
 {
     Tag      = ActionTag.SpikesTrap;
     MaxRange = maxRange;
 }
Пример #27
0
 // Constructor.
 public TeleportAction(BasicUnit executer, int cost = 0) : base(executer, cost)
 {
     Tag = ActionTag.Teleport;
 }