Skip to content

Commit

Permalink
Merge pull request evemondevteam#20 from wbSD/MoreSkillIssues
Browse files Browse the repository at this point in the history
Fix skillpoint calculation for skills in queue that are not completed yet
  • Loading branch information
peterhaneve authored May 24, 2018
2 parents a463da7 + ffb7601 commit 52d439d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
30 changes: 19 additions & 11 deletions src/EVEMon.Common/Models/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -791,22 +791,24 @@ private void SetAttribute(EveAttribute attribute, int value)
internal void Import(EsiAPISkills skills, EsiAPISkillQueue queue)
{
var newSkills = new LinkedList<SerializableCharacterSkill>();
DateTime uselessDate = DateTime.UtcNow;

FreeSkillPoints = skills.UnallocatedSP;

// Keep track of the current skill queue's completed skills, as ESI doesn't transfer them to the skills list until you login
Dictionary<long, QueuedSkill> dict = new Dictionary<long, QueuedSkill>();
Dictionary<long, SerializableQueuedSkill> dict = new Dictionary<long, SerializableQueuedSkill>();
if (queue != null && IsTraining)
{
DateTime uselessDate = DateTime.UtcNow;

foreach (var serialSkill in queue.ToXMLItem().Queue)
foreach (var queuedSkill in queue.ToXMLItem().Queue)
{
var queuedSkill = new QueuedSkill(this, serialSkill, ref uselessDate);
if (!dict.ContainsKey(queuedSkill.Skill.ID))
dict.Add(queuedSkill.Skill.ID, queuedSkill);
else if (queuedSkill.Level > dict[queuedSkill.Skill.ID].Level)
dict[queuedSkill.Skill.ID] = queuedSkill;
// If the skill is completed or currently training, we need it later to copy the progress over to the imported skills
if (queuedSkill.IsCompleted || queuedSkill.IsTraining)
{
if (!dict.ContainsKey(queuedSkill.ID))
dict.Add(queuedSkill.ID, queuedSkill);
else
dict[queuedSkill.ID] = queuedSkill;
}
}
}
// Convert skills to EVE format
Expand All @@ -819,12 +821,18 @@ internal void Import(EsiAPISkills skills, EsiAPISkillQueue queue)

if (queuedSkill.IsCompleted)
{
// Queued skill is completed, so make sure the imported skill is up to par
skill.ActiveLevel = Math.Max(skill.ActiveLevel, queuedSkill.Level);
skill.Level = Math.Max(skill.Level, queuedSkill.Level);
skill.Skillpoints = Math.Max(skill.Skillpoints, queuedSkill.EndSP);
}
else
skill.Skillpoints = Math.Max(skill.Skillpoints, queuedSkill.CurrentSP);
else if (queuedSkill.IsTraining)
{
// Queued skill is currently training - use QueuedSkill class to calculate the CurrentSP of the skill
var tmpQueuedSkill = new QueuedSkill(this, queuedSkill, ref uselessDate);

skill.Skillpoints = Math.Max(skill.Skillpoints, tmpQueuedSkill.CurrentSP);
}
}

newSkills.AddLast(skill.ToXMLItem());
Expand Down
2 changes: 1 addition & 1 deletion src/EVEMon.Common/Models/QueuedSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal QueuedSkill(Character character, SerializableQueuedSkill serial,
Level = serial.Level;
Skill = character.Skills[serial.ID];

if (serial.IsTraining)
if (!serial.IsPaused)
{
// Not paused, we should trust CCP
StartTime = serial.StartTime;
Expand Down
2 changes: 1 addition & 1 deletion src/EVEMon.Common/Models/SkillQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ internal void Import(IEnumerable<SerializableQueuedSkill> serial)
Items.Clear();
foreach (SerializableQueuedSkill serialSkill in serial)
{
if (!serialSkill.IsTraining)
if (serialSkill.IsPaused)
IsPaused = true;

// Creates the skill queue
Expand Down
14 changes: 13 additions & 1 deletion src/EVEMon.Common/Serialization/Eve/SerializableQueuedSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ public DateTime EndTime

// When the skill queue is paused, startTime and endTime are empty in the XML document
// As a result, the serialization leaves the DateTime with its default value
[XmlIgnore]
public bool IsPaused
{
get { return EndTime == DateTime.MinValue; }
}

[XmlIgnore]
public bool IsCompleted
{
get { return !IsPaused && EndTime <= DateTime.UtcNow; }
}

[XmlIgnore]
public bool IsTraining
{
get { return EndTime != DateTime.MinValue; }
get { return !IsPaused && StartTime <= DateTime.UtcNow && DateTime.UtcNow <= EndTime; }
}

#region ISynchronizableWithLocalClock Members
Expand Down

0 comments on commit 52d439d

Please sign in to comment.