diff --git a/ARKBreedingStats/Form1.cs b/ARKBreedingStats/Form1.cs index bf5c7292..dab88684 100644 --- a/ARKBreedingStats/Form1.cs +++ b/ARKBreedingStats/Form1.cs @@ -1768,34 +1768,34 @@ private void buttonRecalculateTops_Click(object sender, EventArgs e) private void aliveToolStripMenuItem_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Available); + SetStatusOfSelectedCreatures(CreatureStatus.Available); } private void deadToolStripMenuItem_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Dead); + SetStatusOfSelectedCreatures(CreatureStatus.Dead); } private void unavailableToolStripMenuItem_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Unavailable); + SetStatusOfSelectedCreatures(CreatureStatus.Unavailable); } private void obeliskToolStripMenuItem1_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Obelisk); + SetStatusOfSelectedCreatures(CreatureStatus.Obelisk); } - private void SetStatusOfSelected(CreatureStatus s) + private void SetStatusOfSelectedCreatures(CreatureStatus s) { List cs = new List(); foreach (int i in listViewLibrary.SelectedIndices) cs.Add(_creaturesDisplayed[i]); if (cs.Any()) - SetStatus(cs, s); + SetCreatureStatus(cs, s); } - private void SetStatus(IEnumerable cs, CreatureStatus s) + private void SetCreatureStatus(IEnumerable cs, CreatureStatus s) { bool changed = false; List speciesBlueprints = new List(); @@ -1854,7 +1854,7 @@ private void ShowBestBreedingPartner(Creature c) "Selected Creature not Available", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - SetStatus(new List { c }, CreatureStatus.Available); + SetCreatureStatus(new List { c }, CreatureStatus.Available); breedingPlan1.BreedingPlanNeedsUpdate = false; } else diff --git a/ARKBreedingStats/Form1.library.cs b/ARKBreedingStats/Form1.library.cs index 186af542..93b35b3c 100644 --- a/ARKBreedingStats/Form1.library.cs +++ b/ARKBreedingStats/Form1.library.cs @@ -14,7 +14,6 @@ using System.Text.RegularExpressions; using ARKBreedingStats.library; using ARKBreedingStats.settings; -using System.Runtime.ConstrainedExecution; namespace ARKBreedingStats { @@ -1712,27 +1711,27 @@ private void toolStripMenuItemRemove_Click(object sender, EventArgs e) private void toolStripMenuItem2_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Available); + SetStatusOfSelectedCreatures(CreatureStatus.Available); } private void toolStripMenuItem3_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Unavailable); + SetStatusOfSelectedCreatures(CreatureStatus.Unavailable); } private void toolStripMenuItem4_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Dead); + SetStatusOfSelectedCreatures(CreatureStatus.Dead); } private void obeliskToolStripMenuItem_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Obelisk); + SetStatusOfSelectedCreatures(CreatureStatus.Obelisk); } private void cryopodToolStripMenuItem_Click(object sender, EventArgs e) { - SetStatusOfSelected(CreatureStatus.Cryopod); + SetStatusOfSelectedCreatures(CreatureStatus.Cryopod); } private void currentValuesToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index c92af62b..e9e530a8 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -249,9 +249,24 @@ public CreatureStatus Status get => _status; set { + if (_status == value) return; + + if (Maturation < 1) + { + if (value == CreatureStatus.Dead) + PauseMaturationTimer(); + else if ((_status == CreatureStatus.Cryopod || _status == CreatureStatus.Obelisk) + && (value == CreatureStatus.Available || value == CreatureStatus.Unavailable)) + StartMaturationTimer(); + else if ((_status == CreatureStatus.Available || _status == CreatureStatus.Unavailable) + && (value == CreatureStatus.Cryopod || value == CreatureStatus.Obelisk)) + PauseMaturationTimer(); + } + _status = value; // remove other status while keeping the other flags flags = (flags & CreatureFlags.StatusMask) | (CreatureFlags)(1 << (int)value); + } } @@ -420,25 +435,32 @@ public void RecalculateNewMutations() /// /// Starts the timer for maturation. /// - private void StartTimer() + private void StartMaturationTimer() { if (growingPaused) { growingPaused = false; - growingUntil = DateTime.Now.Add(growingLeft); + if (growingLeft.Ticks <= 0) + growingUntil = null; + else + growingUntil = DateTime.Now.Add(growingLeft); } } /// /// Pauses the timer for maturation. /// - private void PauseTimer() + private void PauseMaturationTimer() { if (!growingPaused) { growingPaused = true; - growingLeft = growingUntil?.Subtract(DateTime.Now) ?? new TimeSpan(); - if (growingLeft.TotalHours < 0) growingLeft = new TimeSpan(); + growingLeft = growingUntil?.Subtract(DateTime.Now) ?? TimeSpan.Zero; + if (growingLeft.Ticks <= 0) + { + growingLeft = TimeSpan.Zero; + growingUntil = null; + } } } @@ -448,8 +470,8 @@ private void PauseTimer() public void StartStopMatureTimer(bool start) { if (start) - StartTimer(); - else PauseTimer(); + StartMaturationTimer(); + else PauseMaturationTimer(); } /// @@ -460,11 +482,8 @@ public void StartStopMatureTimer(bool start) public string GrowingLeftString { get => System.Xml.XmlConvert.ToString(growingLeft); - set - { - growingLeft = string.IsNullOrEmpty(value) ? + set => growingLeft = string.IsNullOrEmpty(value) ? TimeSpan.Zero : System.Xml.XmlConvert.ToTimeSpan(value); - } } ///