public void StartExecution() { if (Pillager == null) { throw new InvalidOperationException("Cannot execute while Pillager is null"); } Status = CommandStatus.Running; var pillageAbilities = Pillager.Abilities.Where( ability => ability.CommandRequests.Any(request => request.Type == AbilityCommandType.Pillage) ); foreach (var pillageAbility in pillageAbilities) { if (AbilityExecuter.CanExecuteAbilityOnUnit(pillageAbility, Pillager)) { AbilityExecuter.ExecuteAbilityOnUnit(pillageAbility, Pillager); Status = CommandStatus.Succeeded; return; } } Status = CommandStatus.Failed; }
public void StartExecution() { if (UnitToFortify == null) { throw new InvalidOperationException("UnitToFortify cannot be null"); } Status = CommandStatus.Running; if (FortificationLogic.GetFortificationStatusForUnit(UnitToFortify)) { Status = CommandStatus.Succeeded; } else { var fortifyAbility = UnitToFortify.Abilities.FirstOrDefault( ability => ability.CommandRequests.Any( request => request.Type == AbilityCommandType.Fortify ) ); if (fortifyAbility == null || !AbilityExecuter.CanExecuteAbilityOnUnit(fortifyAbility, UnitToFortify)) { Status = CommandStatus.Failed; } else { AbilityExecuter.ExecuteAbilityOnUnit(fortifyAbility, UnitToFortify); Status = FortificationLogic.GetFortificationStatusForUnit(UnitToFortify) ? CommandStatus.Succeeded : CommandStatus.Failed; } } }
private void Update() { if (!Input.anyKeyDown) { return; } var hotkeyActivatedAbility = ActiveAbilityDisplays .Select(display => display.AbilityToDisplay) .FirstOrDefault(ability => Input.GetButtonDown(ability.name)); if (hotkeyActivatedAbility != null && AbilityExecuter.CanExecuteAbilityOnUnit(hotkeyActivatedAbility, ObjectToDisplay) ) { AbilityExecuter.ExecuteAbilityOnUnit(hotkeyActivatedAbility, ObjectToDisplay); Refresh(); } }