private static async Task HitTarget(Player attacker, Player defender, Room room, int delay) { try { while (attacker.HitPoints > 0 && defender.HitPoints > 0) { bool canAttack = CanAttack(attacker, defender); if (canAttack) { bool alive = IsAlive(attacker, defender); if (alive && attacker.Status != Player.PlayerStatus.Busy) { await Task.Delay(delay); double offense = Offense(attacker); double evasion = Evasion(defender); double toHit = (offense / evasion) * 100; int chance = D100(); ShowAttack(attacker, defender, room, toHit, chance); if (attacker.Type == Player.PlayerTypes.Player) { Score.UpdateUiPrompt(attacker); } if (defender.Type == Player.PlayerTypes.Player) { Score.UpdateUiPrompt(defender); } } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private static async Task HitTarget(Player attacker, Player defender, Room room, int delay) { try { while (attacker.HitPoints > 0 && defender.HitPoints > 0) { //check still here Player target = FindValidTarget(room, defender.Name, attacker); if (target == null) { HubContext.SendToClient("No one here by that name", attacker.HubGuid); return; } bool canAttack = CanAttack(attacker, defender); if (canAttack) { bool alive = IsAlive(attacker, defender); if (alive && attacker.Status != Player.PlayerStatus.Busy) { await Task.Delay(delay); double offense = Offense(attacker); double evasion = Evasion(defender); double toHit = (offense / evasion) * 100; int chance = D100(); Player checkAttackerAgainAfterDelay = FindValidTarget(room, defender.Name, attacker); Player checkDefenderAgainAfterDelay = FindValidTarget(room, attacker.Name, defender); if (checkAttackerAgainAfterDelay == null || checkDefenderAgainAfterDelay == null) { //Fixes bug where fleeing you would still get hit and hit back while in another room. return; } ShowAttack(attacker, defender, room, toHit, chance, null); if (attacker.Type == Player.PlayerTypes.Player) { Score.UpdateUiPrompt(attacker); } if (defender.Type == Player.PlayerTypes.Player) { Score.UpdateUiPrompt(defender); } } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void SetUpCamp(PlayerSetup.Player player, Room.Room room) { if (room.containsCamp) { HubContext.Instance.SendToClient("A camp has already been set up here.", player.HubGuid); return; } if (room.items.FirstOrDefault(x => x.name.ToLower().Equals("camp fire")) == null) { HubContext.Instance.SendToClient("You need to have a camp fire before setting up camp.", player.HubGuid); return; } if (player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains("pot")) == null) { HubContext.Instance.SendToClient("You need a cooking pot if you want to set up camp.", player.HubGuid); return; } if (player.MovePoints < 10) { HubContext.Instance.SendToClient("You are too tired to set up camp.", player.HubGuid); player.ActiveSkill = null; return; } player.MovePoints -= 10; if (player.MovePoints < 0) { player.MovePoints = 0; } if (player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains("pot")) != null) { HubContext.Instance.SendToClient("You place the cooking pot upon the fire.", player.HubGuid); room.items.FirstOrDefault(x => x.name.ToLower().Equals("camp fire")).description.room = "A cooking pot is suspended over a camp fire."; player.Inventory.Remove(player.Inventory.FirstOrDefault(x => x.name.Contains("pot"))); foreach (var character in room.players) { if (character != player) { var roomMessage = $"{Helpers.ReturnName(player, character, string.Empty)} places a pot over the fire."; HubContext.Instance.SendToClient(roomMessage, character.HubGuid); } } } if (player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains("bed")) != null) { HubContext.Instance.SendToClient("You place the bed roll by the fire.", player.HubGuid); var bed = player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains("bed")); bed.description.room = "A bed roll is layed out by the fire."; room.items.Add(bed); player.Inventory.Remove(player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains("bed"))); foreach (var character in room.players) { if (character != player) { var roomMessage = $"{Helpers.ReturnName(player, character, string.Empty)} places a bed roll by the fire."; HubContext.Instance.SendToClient(roomMessage, character.HubGuid); } } } Score.UpdateUiPrompt(player); }
private static async Task HitTarget(Player attacker, Player defender, Room room, int delay) { try { attacker.ActiveFighting = true; while (attacker.HitPoints > 0 && defender.HitPoints > 0) { //check still here Player target = FindValidTarget(room, defender.Name, attacker); if (target == null) { HubContext.SendToClient("No one here by that name", attacker.HubGuid); return; } bool canAttack = CanAttack(attacker, defender); if (canAttack) { bool alive = IsAlive(attacker, defender); if (alive && attacker.Status != Player.PlayerStatus.Busy) { await Task.Delay(delay); double offense = Offense(attacker); double evasion = Evasion(defender); double toHit = (offense / evasion) * 100; int chance = D100(); Player checkAttackerAgainAfterDelay = FindValidTarget(room, defender.Name, attacker); Player checkDefenderAgainAfterDelay = FindValidTarget(room, attacker.Name, defender); if (checkAttackerAgainAfterDelay == null || checkDefenderAgainAfterDelay == null) { //Fixes bug where fleeing you would still get hit and hit back while in another room. return; } ShowAttack(attacker, defender, room, toHit, chance, null); if (attacker.Type == Player.PlayerTypes.Player) { Score.UpdateUiPrompt(attacker); } if (defender.Type == Player.PlayerTypes.Player) { Score.UpdateUiPrompt(defender); } } } } } catch (Exception ex) { var log = new Error.Error { Date = DateTime.Now, ErrorMessage = ex.InnerException.ToString(), MethodName = "fight" }; Save.LogError(log); } }