| 3629 | } |
| 3630 | |
| 3631 | void UpgradePriceValue::update() { |
| 3632 | if (_all.empty() || _next.empty()) { |
| 3633 | _timer.cancel(); |
| 3634 | return; |
| 3635 | } |
| 3636 | const auto now = base::unixtime::now(); |
| 3637 | const auto i = ranges::upper_bound( |
| 3638 | _all, |
| 3639 | now, |
| 3640 | ranges::less(), |
| 3641 | &UpgradePrice::date); |
| 3642 | const auto j = ranges::upper_bound( |
| 3643 | _next, |
| 3644 | now, |
| 3645 | ranges::less(), |
| 3646 | &UpgradePrice::date); |
| 3647 | const auto full = (i == begin(_all)) ? i->stars : (i - 1)->stars; |
| 3648 | const auto part = (j == begin(_next)) ? j->stars : (j - 1)->stars; |
| 3649 | const auto fullDate = (i != end(_all)) ? i->date : TimeId(); |
| 3650 | const auto partDate = (j != end(_next)) ? j->date : TimeId(); |
| 3651 | _cost = std::min({ _cost.current(), part, full}); |
| 3652 | if (int(end(_next) - j) < 3) { |
| 3653 | refresh(); |
| 3654 | } |
| 3655 | |
| 3656 | const auto next = std::min({ |
| 3657 | partDate ? partDate : TimeId(INT_MAX), |
| 3658 | fullDate ? fullDate : TimeId(INT_MAX), |
| 3659 | }); |
| 3660 | if (next != TimeId(INT_MAX)) { |
| 3661 | _tillNext = next - now; |
| 3662 | } else { |
| 3663 | _tillNext = 0; |
| 3664 | _timer.cancel(); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | void UpgradePriceValue::refresh() { |
| 3669 | if (_refreshing || _finished) { |
no test coverage detected