private async Task NotifyTerminatedUnit(PerformErrandResult result) { if (result.PerformingActor.Id == result.TerminatedActor.Id) { await _notificationHub.Clients.All.SendAsync("Notify", new Notification($"{result.PerformingActor.Name} ({Enum.GetName(typeof(ActorType), result.PerformingActor.ActorType)}) has destroyed... itself!", SeverityLevel.Error)); } else { await _notificationHub.Clients.All.SendAsync("Notify", new Notification($"{result.PerformingActor.Name} ({Enum.GetName(typeof(ActorType), result.PerformingActor.ActorType)}) has destroyed a unit ({result.TerminatedActor.Name})!", SeverityLevel.Error)); } }
private async Task NotifyTaskCompletionStatus(PerformErrandResult result) { if (result.PerformedErrand.Status == ErrandStatus.Completed) { await NotifyTaskCompleted(result); } else { await NotifyFailedTask(result); } if (result.TerminatedActor != null) { await NotifyTerminatedUnit(result); } }
public async Task <PerformErrandResult> PerformErrand(ICanPerformErrand actor, ErrandType errandType) { var errandToExecute = new Errand(actor, errandType) { Status = ErrandStatus.In_Progress }; var performanceResult = new PerformErrandResult(actor, errandToExecute); await AttemptToFailErrand(actor, errandType, errandToExecute, performanceResult); if (ErrandDidNotFail(errandToExecute)) { errandToExecute.Status = ErrandStatus.Completed; } await CompleteErrand(actor, errandToExecute); return(performanceResult); }
private async Task AttemptToFailErrand(ICanPerformErrand actor, ErrandType errandType, Errand errand, PerformErrandResult result) { //higher actorTypes have extra chances to kill an opponent, but have extra 'dice rolls' to fail their task foreach (var item in Enumerable.Range(0, ((int)actor.ActorType) + 1)) { _stopwatch.Start(); Thread.Sleep((int)errandType / ((int)actor.ActorType + 1) + _randomGenerator.Next(1000)); if (TaskedFailedDiceRoll()) { //actor destroyed the errand task!!!! errand.Status = ErrandStatus.Failed; result.TerminatedActor = await _battleService.KillAnotherActor(actor); break; } } }
private async Task NotifyFailedTask(PerformErrandResult result) { await _notificationHub.Clients.All.SendAsync("Notify", new Notification($"{result.PerformingActor.Name} ({Enum.GetName(typeof(ActorType), result.PerformingActor.ActorType)}) failed task: { Enum.GetName(typeof(ErrandType), result.PerformedErrand.Type) }!", SeverityLevel.Warn)); }