diff --git a/src/EVEMon.Common/Collections/Global/GlobalCharacterCollection.cs b/src/EVEMon.Common/Collections/Global/GlobalCharacterCollection.cs index 1354f7c2e..1aa8b1b1f 100644 --- a/src/EVEMon.Common/Collections/Global/GlobalCharacterCollection.cs +++ b/src/EVEMon.Common/Collections/Global/GlobalCharacterCollection.cs @@ -197,16 +197,5 @@ internal IEnumerable ExportPlans() return serial; } - - /// - /// Update character account statuses. Used after APIKeys list is updated - /// - internal void UpdateAccountStatuses() - { - foreach (Character character in Items) - { - character.UpdateAccountStatus(); - } - } } } \ No newline at end of file diff --git a/src/EVEMon.Common/EveMonClient.Events.cs b/src/EVEMon.Common/EveMonClient.Events.cs index 40c030003..11b0b4892 100644 --- a/src/EVEMon.Common/EveMonClient.Events.cs +++ b/src/EVEMon.Common/EveMonClient.Events.cs @@ -417,7 +417,6 @@ internal static void OnAPIKeyCollectionChanged() return; Trace(); - EveMonClient.Characters.UpdateAccountStatuses(); Settings.Save(); APIKeyCollectionChanged?.ThreadSafeInvoke(null, EventArgs.Empty); } @@ -558,7 +557,6 @@ internal static void OnAccountStatusUpdated(APIKey apiKey) return; Trace(apiKey.ToString()); - EveMonClient.Characters.UpdateAccountStatuses(); Settings.Save(); AccountStatusUpdated?.ThreadSafeInvoke(null, EventArgs.Empty); } @@ -641,6 +639,7 @@ internal static void OnCharacterSkillQueueUpdated(Character character) return; Trace(character.Name); + character.UpdateAccountStatus(); Settings.Save(); CharacterSkillQueueUpdated?.ThreadSafeInvoke(null, new CharacterChangedEventArgs(character)); } diff --git a/src/EVEMon.Common/Models/AccountStatus.cs b/src/EVEMon.Common/Models/AccountStatus.cs index e68d0638f..beb584a8e 100644 --- a/src/EVEMon.Common/Models/AccountStatus.cs +++ b/src/EVEMon.Common/Models/AccountStatus.cs @@ -26,25 +26,6 @@ public AccountStatus(AccountStatusType statusType) CurrentStatus = statusType; } - /// - /// Creates an AccountStatus object from APIKey - /// - /// Type (Alpha, Omega, Unknown). - public AccountStatus (APIKey apiKey) - { - if (apiKey == null || - (apiKey != null && apiKey.Expiration < DateTime.UtcNow && apiKey.Expiration != DateTime.MinValue)) - { - CurrentStatus = AccountStatusType.Unknown; - } - else - { - CurrentStatus = apiKey.AccountExpires > DateTime.UtcNow ? - AccountStatusType.Omega : - AccountStatusType.Alpha; - } - } - /// /// Spits out a friendly name for the Account Status /// diff --git a/src/EVEMon.Common/Models/BaseCharacter.cs b/src/EVEMon.Common/Models/BaseCharacter.cs index 6c602c327..41d89a4fa 100644 --- a/src/EVEMon.Common/Models/BaseCharacter.cs +++ b/src/EVEMon.Common/Models/BaseCharacter.cs @@ -37,6 +37,17 @@ public abstract class BaseCharacter /// /// skill public virtual float GetBaseSPPerHour(StaticSkill skill) + { + return GetOmegaSPPerHour(skill); + } + + /// + /// Computes the SP per hour for the given skill, if the account status is Omega (subscribed) + /// + /// The skill. + /// + /// skill + public float GetOmegaSPPerHour(StaticSkill skill) { skill.ThrowIfNull(nameof(skill)); diff --git a/src/EVEMon.Common/Models/CCPCharacter.cs b/src/EVEMon.Common/Models/CCPCharacter.cs index f6fe78181..8283557e7 100644 --- a/src/EVEMon.Common/Models/CCPCharacter.cs +++ b/src/EVEMon.Common/Models/CCPCharacter.cs @@ -297,7 +297,7 @@ public IEnumerable IndustryJobs /// /// Gets the skill currently in training, even when it is paused. /// - public override QueuedSkill CurrentlyTrainingSkill => SkillQueue.CurrentlyTraining; + public override QueuedSkill CurrentlyTrainingSkill => SkillQueue?.CurrentlyTraining; /// /// Gets a value indicating whether the character has insufficient balance to complete its buy orders. diff --git a/src/EVEMon.Common/Models/Character.cs b/src/EVEMon.Common/Models/Character.cs index 638e74ae3..973b16446 100644 --- a/src/EVEMon.Common/Models/Character.cs +++ b/src/EVEMon.Common/Models/Character.cs @@ -76,17 +76,39 @@ protected Character(CharacterIdentity identity, Guid guid) UISettings = new CharacterUISettings(); } - public void UpdateAccountStatus() + public void UpdateAccountStatus(AccountStatusType statusType = AccountStatusType.Unknown) { - APIKey apiKey = Identity.FindAPIKeyWithAccess(CCPAPICharacterMethods.AccountStatus); - if (apiKey != null) + if (CurrentlyTrainingSkill != null && CurrentlyTrainingSkill.IsTraining) { - CharacterStatus = new AccountStatus(apiKey); - } - else if (CharacterStatus == null) - { - CharacterStatus = new AccountStatus(AccountStatusType.Unknown); + // Try to determine account status based on training time + var hoursToTrain = (CurrentlyTrainingSkill.EndTime - CurrentlyTrainingSkill.StartTime).TotalHours; + if (hoursToTrain > 0) + { + var spToTrain = (CurrentlyTrainingSkill.EndSP - CurrentlyTrainingSkill.StartSP); + if (spToTrain > 0) + { + var spPerHour = spToTrain / hoursToTrain; + if (spPerHour > 0) + { + var rate = (int)Math.Round(GetOmegaSPPerHour(CurrentlyTrainingSkill.Skill) / spPerHour, 0); + switch (rate) + { + case 1: + statusType = AccountStatusType.Omega; + break; + case 2: + statusType = AccountStatusType.Alpha; + break; + default: + statusType = AccountStatusType.Unknown; + break; + } + } + } + } } + + CharacterStatus = new AccountStatus(statusType); } #endregion @@ -443,7 +465,7 @@ public override Int64 GetSkillPoints(StaticSkill skill) /// Skill points earned per hour when training this skill public override float GetBaseSPPerHour(StaticSkill skill) { - return CharacterStatus.TrainingRate* base.GetBaseSPPerHour(skill); + return CharacterStatus.TrainingRate * base.GetBaseSPPerHour(skill); } #endregion