Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #77 skillpoints and SP/hour being wrong by guessing account status based on skill queue #80

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/EVEMon.Common/Collections/Global/GlobalCharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,5 @@ internal IEnumerable<SerializablePlan> ExportPlans()

return serial;
}

/// <summary>
/// Update character account statuses. Used after APIKeys list is updated
/// </summary>
internal void UpdateAccountStatuses()
{
foreach (Character character in Items)
{
character.UpdateAccountStatus();
}
}
}
}
3 changes: 1 addition & 2 deletions src/EVEMon.Common/EveMonClient.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ internal static void OnAPIKeyCollectionChanged()
return;

Trace();
EveMonClient.Characters.UpdateAccountStatuses();
Settings.Save();
APIKeyCollectionChanged?.ThreadSafeInvoke(null, EventArgs.Empty);
}
Expand Down Expand Up @@ -558,7 +557,6 @@ internal static void OnAccountStatusUpdated(APIKey apiKey)
return;

Trace(apiKey.ToString());
EveMonClient.Characters.UpdateAccountStatuses();
Settings.Save();
AccountStatusUpdated?.ThreadSafeInvoke(null, EventArgs.Empty);
}
Expand Down Expand Up @@ -641,6 +639,7 @@ internal static void OnCharacterSkillQueueUpdated(Character character)
return;

Trace(character.Name);
character.UpdateAccountStatus();
Settings.Save();
CharacterSkillQueueUpdated?.ThreadSafeInvoke(null, new CharacterChangedEventArgs(character));
}
Expand Down
19 changes: 0 additions & 19 deletions src/EVEMon.Common/Models/AccountStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ public AccountStatus(AccountStatusType statusType)
CurrentStatus = statusType;
}

/// <summary>
/// Creates an AccountStatus object from APIKey
/// </summary>
/// <param name="statusType">Type (Alpha, Omega, Unknown).</param>
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;
}
}

/// <summary>
/// Spits out a friendly name for the Account Status
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/EVEMon.Common/Models/BaseCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public abstract class BaseCharacter
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">skill</exception>
public virtual float GetBaseSPPerHour(StaticSkill skill)
{
return GetOmegaSPPerHour(skill);
}

/// <summary>
/// Computes the SP per hour for the given skill, if the account status is Omega (subscribed)
/// </summary>
/// <param name="skill">The skill.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">skill</exception>
public float GetOmegaSPPerHour(StaticSkill skill)
{
skill.ThrowIfNull(nameof(skill));

Expand Down
2 changes: 1 addition & 1 deletion src/EVEMon.Common/Models/CCPCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public IEnumerable<IndustryJob> IndustryJobs
/// <summary>
/// Gets the skill currently in training, even when it is paused.
/// </summary>
public override QueuedSkill CurrentlyTrainingSkill => SkillQueue.CurrentlyTraining;
public override QueuedSkill CurrentlyTrainingSkill => SkillQueue?.CurrentlyTraining;

/// <summary>
/// Gets a value indicating whether the character has insufficient balance to complete its buy orders.
Expand Down
40 changes: 31 additions & 9 deletions src/EVEMon.Common/Models/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These really don't need to be nested. You can rewrite this to something like:

var hoursToTrain = (CurrentlyTrainingSkill.EndTime - CurrentlyTrainingSkill.StartTime).TotalHours;
var spToTrain = (CurrentlyTrainingSkill.EndSP - CurrentlyTrainingSkill.StartSP);
var spPerHour = hoursToTrain == 0 ? 0 : spToTrain/hoursToTrain;
var rate = spPerHour == 0 ? 0 : (int)Math.Round(GetOmegaSPPerHour(CurrentlyTrainingSkill.Skill) / spPerHour, 0);
then your switch statement. You could also set the spPerHour to some ludicrous value instead of 0 to avoid the second ternary operation if you wanted to

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
Expand Down Expand Up @@ -443,7 +465,7 @@ public override Int64 GetSkillPoints(StaticSkill skill)
/// <returns>Skill points earned per hour when training this skill</returns>
public override float GetBaseSPPerHour(StaticSkill skill)
{
return CharacterStatus.TrainingRate* base.GetBaseSPPerHour(skill);
return CharacterStatus.TrainingRate * base.GetBaseSPPerHour(skill);
}

#endregion
Expand Down