From 3b40ea0e94768433fd9faf7bc5287171d3ca8b06 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Mon, 23 Nov 2015 13:28:22 +0300 Subject: [PATCH] fix time left of missions when rebuild route --- .../controllers/MissionsController.java | 4 +- .../java/ru/trader/model/MissionModel.java | 38 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/MissionsController.java b/client/src/main/java/ru/trader/controllers/MissionsController.java index 90d472e..e5b4f14 100644 --- a/client/src/main/java/ru/trader/controllers/MissionsController.java +++ b/client/src/main/java/ru/trader/controllers/MissionsController.java @@ -13,6 +13,8 @@ import ru.trader.view.support.autocomplete.AutoCompletion; import ru.trader.view.support.autocomplete.CachedSuggestionProvider; import ru.trader.view.support.autocomplete.StationsProvider; +import java.time.Duration; + public class MissionsController { @@ -114,7 +116,7 @@ public class MissionsController { StationModel station = starport.getValue(); ItemModel item = cargo.getValue(); long count = quantity.getValue().longValue(); - long time = leftTime.getValue().longValue(); + Duration time = Duration.ofSeconds(leftTime.getValue().longValue()); double profit = reward.getValue().doubleValue(); if (station != null && profit > 0){ switch (missionType){ diff --git a/client/src/main/java/ru/trader/model/MissionModel.java b/client/src/main/java/ru/trader/model/MissionModel.java index e5c4fe1..4bdaea1 100644 --- a/client/src/main/java/ru/trader/model/MissionModel.java +++ b/client/src/main/java/ru/trader/model/MissionModel.java @@ -5,6 +5,10 @@ import ru.trader.analysis.RouteReserve; import ru.trader.core.Offer; import ru.trader.store.simple.SimpleOffer; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.Collection; import java.util.Objects; @@ -14,24 +18,24 @@ public class MissionModel { private final long count; private final double profit; private final Offer offer; - private final Long time; + private final LocalDateTime time; private long need; private Collection reserves; - public MissionModel(StationModel target, long time, double profit) { - this(target, null, 0, time, profit); + public MissionModel(StationModel target, Duration duration, double profit) { + this(target, null, 0, duration, profit); } - public MissionModel(StationModel target, long count, long time, double profit) { - this(target, null, count, time, profit); + public MissionModel(StationModel target, long count, Duration duration, double profit) { + this(target, null, count, duration, profit); } - public MissionModel(StationModel target, ItemModel item, long count, long time, double profit) { + public MissionModel(StationModel target, ItemModel item, long count, Duration duration, double profit) { this.target = target; this.item = item; this.count = count; - this.time = time; + this.time = LocalDateTime.now().plus(duration); this.profit = profit; if (item != null) { offer = SimpleOffer.fakeBuy(ModelFabric.get(target), ModelFabric.get(item), profit / count, count); @@ -83,14 +87,15 @@ public class MissionModel { @Override public String toString() { + String t = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).format(time); if (isDelivery()){ - return String.format("Deliver %d items to %s", count, target.getName()); + return String.format("Deliver %d items to %s at %s", count, target.getName(), t); } if (isCourier()){ - return String.format("Deliver message to %s", target.getName()); + return String.format("Deliver message to %s at %s", target.getName(), t); } if (isSupply()){ - return String.format("Supply %d %s to %s", count, item.getName(), target.getName()); + return String.format("Supply %d %s to %s at %s", count, item.getName(), target.getName(), t); } return "MissionModel{" + "target=" + target + @@ -102,18 +107,19 @@ public class MissionModel { } public void toSpecification(CrawlerSpecificator specificator){ + long interval = Duration.between(LocalDateTime.now(), time).getSeconds(); if (isSupply()){ if (isCompleted()){ - if (time == 0) specificator.add(ModelFabric.get(target), true); - else specificator.add(ModelFabric.get(target), time, true); + if (interval <= 0) specificator.add(ModelFabric.get(target), true); + else specificator.add(ModelFabric.get(target), interval, true); } else { - if (time == 0) specificator.buy(offer); - else specificator.buy(offer, time); + if (interval <= 0) specificator.buy(offer); + else specificator.buy(offer, interval); } } else if (isCourier() || isDelivery()){ - if (time == 0) specificator.add(ModelFabric.get(target), true); - else specificator.add(ModelFabric.get(target), time, true); + if (interval <= 0) specificator.add(ModelFabric.get(target), true); + else specificator.add(ModelFabric.get(target), interval, true); } }