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 Move(Cell destinationCell, List <Cell> path) { if (isMoving) { return; } var totalMovementCost = path.Sum(h => h.MovementCost); if (MovementPoints < totalMovementCost) { return; } MovementPoints -= totalMovementCost; Cell.IsTaken = false; Cell = destinationCell; destinationCell.IsTaken = true; if (MovementSpeed > 0) { StartCoroutine(MovementAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } }
/// <summary> /// Handler method for moving the unit. /// </summary> /// <param name="destinationCell">Cell to move the unit to</param> /// <param name="path">A list of cells, path from source to destination cell</param> public virtual void Move(Cell destinationCell, List<Cell> path) { var totalMovementCost = path.Sum(h => h.MovementCost); MovementPoints -= totalMovementCost; Debug.Log(Cell.transform.position); Cell.IsTaken = false; Cell.CurrentUnit = null; Cell = destinationCell; destinationCell.IsTaken = true; destinationCell.CurrentUnit = this; Debug.Log(Cell.transform.position); Debug.Log(path); if (MovementAnimationSpeed > 0) { StartCoroutine(MovementAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } }
// Newly Added public void OnUnitMoved(object sender, MovementEventArgs args) { Debug.Log("Move from " + args.OriginCell.Location + " to " + args.DestinationCell.Location); if (UnitMoved != null) { UnitMoved.Invoke(this, args); } }
public void MoveTo(Square pSquare) { MoveEventArgs args = new MoveEventArgs(this, Location, pSquare); Location.SetUnit(null); pSquare.SetUnit(this); mLocation = pSquare; UnitMoved?.Invoke(this, args); }
/* * // Attacking unit calls Defend method on defending unit. * protected virtual void Defend(Unit other, int damage) * { * if (ActionPoints > 0) * { * CounterPoints++; * } * MarkAsDefending(other); * //Debug.Log(this); * //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. * //If result is below 1, it is set to 1. This behaviour can be overridden in derived classes. * HP -= Mathf.Clamp(damage - Def, 1, damage); * //Debug.Log(this + "" + HP); * if (UnitAttacked != null) * UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage)); * if (HP > 0) * { * //Debug.Log(this + "aaa" + ActionPoints); * if (!IsUnitAttackable(other, Cell)) * { * //Debug.Log("Counter!"); * } * else if (CounterPoints > 0) * { * * //Debug.Log("Potential victor: " + PlayerNumber); * PotentialVictor = PlayerNumber; * CounterPoints--; * //Debug.Log("Counter!: " + this); * StartCoroutine(Retaliate(other)); * } * } * * if (HP <= 0) * { * if (UnitDestroyed != null) * //Debug.Log("Potential victor: " + other.PlayerNumber); * PotentialVictor = other.PlayerNumber; * //Debug.Log("dead: " + PlayerNumber); * UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage)); * OnDestroyed(); * } * } */ // Moves the unit to destinationCell along the path. public virtual void Move(Cell destinationCell, List <Cell> path) { if (isMoving) { return; } var totalMovementCost = 0; if (card.moveClass == Card.MoveClass.Flier || card.moveClass == Card.MoveClass.Armor) { totalMovementCost = path.Sum(h => h.BypassMovementCost); } else { totalMovementCost = path.Sum(h => h.MovementCost); } if (MovementPoints < totalMovementCost) { return; } //Change this line back when adding in the full menu functionality for the combat system. //MovementPoints -= totalMovementCost; MovementPoints = 0; Cell.IsTaken = false; Cell.occupationID = 99; Cell = destinationCell; destinationCell.IsTaken = true; destinationCell.occupationID = PlayerNumber; x = Cell.x; y = Cell.y; if (MovementSpeed > 0) { StartCoroutine(MovementAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } moved = true; }
private void Unit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (isUnitMoving) { Unit unit = sender as Unit; moveTo = unit.Pos; //UnitMoving.SetStone(unit.Stone, board.IsMyFirst); UnitMoving.Width = unit.ActualWidth; UnitMoving.Height = unit.ActualHeight; UnitMoving.Visibility = Visibility.Collapsed; hideAllPossibleMove(); isUnitMoving = false; UnitMoved?.Invoke(new Move(moveFrom, moveTo)); } }
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)); } }
public virtual void Move(Cell destinationCell, List <Cell> path, bool fromNetwork = false) { if (isMoving) { return; } // if(!fromNetwork) // SendMoveInformation(path[0]); var totalMovementCost = path.Sum(h => h.MovementCost); if (MovementPoints < totalMovementCost) { return; } MovementPoints -= totalMovementCost; hasMoved = true; for (int i = 0; i < grid.Units.Count; i++) { Building b = grid.Units[i] as Building; if (b != null && b.transform.position.x == Cell.transform.position.x && b.transform.position.y == Cell.transform.position.y) { b.HitPoints = 20; break; } } Cell.IsTaken = false; Cell = destinationCell; destinationCell.IsTaken = true; if (MovementSpeed > 0) { StartCoroutine(MovementAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } }
// Method that moves unit towards specified target with a coroutine public virtual void Move(Cell destinationCell, List <Cell> path) { if (!this.State.Equals(CurrentState.Normal)) { return; } // Calculate cost of path var fullPath = new List <Cell>(path); var totalMovementCost = PathCost(fullPath); if (MovementPoints < totalMovementCost) { return; } MovementPoints -= totalMovementCost; foreach (var cell in Cells) { cell.HasObstacle = false; } // Set new cells; destinationCell is origin var newCells = new List <Cell>(GetGridSizeCells(destinationCell)); foreach (var cell in newCells) { cell.HasObstacle = true; } Cells = newCells; if (MovementSpeed > 0) { StartCoroutine(MovementAnimation(path)); } else { transform.position = GetGridSizePosition(Cells[0]); } if (UnitMoved != null) { UnitMoved.Invoke(this, new MovementEventArgs(Cells[0], destinationCell, path)); } }
//Metoda obsługi poruszania jednostki. public virtual void Move(Cell destinationCell, List <Cell> path) { if (GetComponent <Wizard>() != null && this.ActionPoints == magicAtttack) { actionPoints = 1; } var totalMovementCost = path.Sum(h => h.MovementCost); scorePanelControll = FindObjectOfType <ScorePanelControll>(); MovementPoints -= totalMovementCost; scorePanelControll.UpgradeMovment(this); Cell.IsBlocked = false; Cell.CurrentUnit = null; Cell = destinationCell; destinationCell.IsBlocked = true; destinationCell.CurrentUnit = this; unitsinRange = new List <Unit>(); List <Cell> TransformTo = new List <Cell>(); NewDestination = Cell; List <Unit> unitsInX = new List <Unit>(); List <Unit> unitsInY = new List <Unit>(); List <Unit> unitsInZ = new List <Unit>(); foreach (var cell in path) { if (cell.Swamp == true) { MovementPoints = 0; TransformTo.Add(cell); Debug.Log(TransformTo + "Destynacja"); NewDestination = TransformTo.First(); //destinationCell = NewDestination; } if (cell.Spikes == true) { audioManager.Play("Lava"); Debug.Log("Zadano Obrazenia"); HitPoints -= DamageSpikeParameterUnit; Debug.Log("Obecne Zdrowie: " + HitPoints + " Zadane Obrazenia: " + DamageSpikeParameterUnit); } } if (Cell != null && Cell.Temple == true) { Debug.Log("Obecne Zdrowie: " + HitPoints); audioManager.Play("Temple"); Debug.Log("Uzdrowiono"); HitPoints += HealTempleParameterUnit; if (HitPoints > totalHitPoints) { HitPoints = totalHitPoints; } Debug.Log("Obecne Zdrowie: " + HitPoints + " Dodano: " + HealTempleParameterUnit); Cell.Temple = false; Cell.Ruins = true; } /* * * path.RemoveAt(0); * path.Insert(0, NewDestination); */ /* foreach(var newcell in TransformTo) * { * path.Add(newcell); */ //Taker.OnCellDeselected(Cell); if (MovementAnimationSpeed > 0) { StartCoroutine(MovementAnimation(path)); } else { transform.position = Cell.transform.position; } if (UnitMoved != null) { UnitMoved.Invoke(this, new MovementEventArgs(Cell, destinationCell, path)); } if (destinationCell.Spikes == true) { audioManager.Play("Lava"); Debug.Log("Zadano Obrazenia"); HitPoints -= DamageSpikeParameterUnit; Debug.Log("Obecne Zdrowie: " + HitPoints + " Zadane Obrazenia: " + DamageSpikeParameterUnit); } if (destinationCell.Swamp == true) { audioManager.Play("Marsh"); Debug.Log("Bagno"); MovementPoints = 0; } }
private void OnUnitMoved(UnitMovedEventArgs e) { //Interlocked.CompareExchange(ref TurnEnded, null, null)?.Invoke(this, e); UnitMoved?.Invoke(this, e); }
public void OnUnitMoved(Unit unit, Cell from, Cell to, HashSet <Cell> cellsRevealed, HashSet <Cell> cellsHidden) { UnitMoved?.Invoke(this, new MoveEvent(unit, from, to, cellsRevealed, cellsHidden)); }