/// <summary> /// Toggle unit sleeping. /// </summary> /// <param name="sleeping"></param> public void SetSleeping(bool sleeping) { this.sleeping = sleeping; moves = 0; UpdateState(); CommunicationController.UpdateState(0f); }
/// <summary> /// Moves the unit into the cargo space of another unit. /// </summary> /// <param name="unit"></param> public void MoveToCargo(Unit unit) { tile.RemoveUnit(this); if (transportedIn != null) { transportedIn.RemoveCargo(this); } if (sleeping) { sleeping = false; } unit.AddCargo(this); SetTile(unit.tile); moves = 0; CommunicationController.UpdateState(0.3f); }
protected static void Battle(Combatant attacker, Combatant defender) { bool attackerDead = false; bool defenderDead = false; int attackerStrength = attacker.CalculateStrength(defender); int defenderStrength = defender.CalculateStrength(attacker); CommunicationController.SpawnExplosion(defender.tile, attacker.tile); CommunicationController.SpawnExplosion(attacker.tile, defender.tile); while (!attackerDead && !defenderDead) { if (Random.Range(0f, 1f) < attackerStrength * 1f / (attackerStrength + defenderStrength)) { CommunicationController.SpawnExplosion(defender.tile, attacker.tile); defenderDead = defender.TakeDamage(); } else { CommunicationController.SpawnExplosion(attacker.tile, defender.tile); attackerDead = attacker.TakeDamage(); } } if (attackerDead) { attacker.OnDefeat(defender); } if (defenderDead) { defender.OnDefeat(attacker); attacker.OnVictory(defender); } CommunicationController.UpdateState(0.3f); }
/// <summary> /// Moves the unit onto the tile. /// </summary> /// <param name="tile"></param> /// <returns></returns> public bool Move(Tile tile) { if (!tile.CanEnter(this)) { return(false); } this.tile.RemoveUnit(this); if (transportedIn != null) { transportedIn.RemoveCargo(this); } if (sleeping) { sleeping = false; } SetTile(tile); tile.PlaceUnit(this); moves -= tile.MovementCost(this); CommunicationController.UpdateState(0.3f); if (fuel != -1) { fuel--; if (fuel == 0) { CommunicationController.SpawnExplosion(tile, tile); Destroy(); CommunicationController.UpdateState(0.3f); } } return(true); }