fix time left of missions when rebuild route
This commit is contained in:
@@ -13,6 +13,8 @@ import ru.trader.view.support.autocomplete.AutoCompletion;
|
|||||||
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
||||||
import ru.trader.view.support.autocomplete.StationsProvider;
|
import ru.trader.view.support.autocomplete.StationsProvider;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
|
||||||
public class MissionsController {
|
public class MissionsController {
|
||||||
|
|
||||||
@@ -114,7 +116,7 @@ public class MissionsController {
|
|||||||
StationModel station = starport.getValue();
|
StationModel station = starport.getValue();
|
||||||
ItemModel item = cargo.getValue();
|
ItemModel item = cargo.getValue();
|
||||||
long count = quantity.getValue().longValue();
|
long count = quantity.getValue().longValue();
|
||||||
long time = leftTime.getValue().longValue();
|
Duration time = Duration.ofSeconds(leftTime.getValue().longValue());
|
||||||
double profit = reward.getValue().doubleValue();
|
double profit = reward.getValue().doubleValue();
|
||||||
if (station != null && profit > 0){
|
if (station != null && profit > 0){
|
||||||
switch (missionType){
|
switch (missionType){
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ import ru.trader.analysis.RouteReserve;
|
|||||||
import ru.trader.core.Offer;
|
import ru.trader.core.Offer;
|
||||||
import ru.trader.store.simple.SimpleOffer;
|
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.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -14,24 +18,24 @@ public class MissionModel {
|
|||||||
private final long count;
|
private final long count;
|
||||||
private final double profit;
|
private final double profit;
|
||||||
private final Offer offer;
|
private final Offer offer;
|
||||||
private final Long time;
|
private final LocalDateTime time;
|
||||||
private long need;
|
private long need;
|
||||||
private Collection<RouteReserve> reserves;
|
private Collection<RouteReserve> reserves;
|
||||||
|
|
||||||
public MissionModel(StationModel target, long time, double profit) {
|
public MissionModel(StationModel target, Duration duration, double profit) {
|
||||||
this(target, null, 0, time, profit);
|
this(target, null, 0, duration, profit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MissionModel(StationModel target, long count, long time, double profit) {
|
public MissionModel(StationModel target, long count, Duration duration, double profit) {
|
||||||
this(target, null, count, time, 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.target = target;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
this.time = time;
|
this.time = LocalDateTime.now().plus(duration);
|
||||||
this.profit = profit;
|
this.profit = profit;
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
offer = SimpleOffer.fakeBuy(ModelFabric.get(target), ModelFabric.get(item), profit / count, count);
|
offer = SimpleOffer.fakeBuy(ModelFabric.get(target), ModelFabric.get(item), profit / count, count);
|
||||||
@@ -83,14 +87,15 @@ public class MissionModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
String t = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).format(time);
|
||||||
if (isDelivery()){
|
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()){
|
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()){
|
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{" +
|
return "MissionModel{" +
|
||||||
"target=" + target +
|
"target=" + target +
|
||||||
@@ -102,18 +107,19 @@ public class MissionModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void toSpecification(CrawlerSpecificator specificator){
|
public void toSpecification(CrawlerSpecificator specificator){
|
||||||
|
long interval = Duration.between(LocalDateTime.now(), time).getSeconds();
|
||||||
if (isSupply()){
|
if (isSupply()){
|
||||||
if (isCompleted()){
|
if (isCompleted()){
|
||||||
if (time == 0) specificator.add(ModelFabric.get(target), true);
|
if (interval <= 0) specificator.add(ModelFabric.get(target), true);
|
||||||
else specificator.add(ModelFabric.get(target), time, true);
|
else specificator.add(ModelFabric.get(target), interval, true);
|
||||||
} else {
|
} else {
|
||||||
if (time == 0) specificator.buy(offer);
|
if (interval <= 0) specificator.buy(offer);
|
||||||
else specificator.buy(offer, time);
|
else specificator.buy(offer, interval);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
if (isCourier() || isDelivery()){
|
if (isCourier() || isDelivery()){
|
||||||
if (time == 0) specificator.add(ModelFabric.get(target), true);
|
if (interval <= 0) specificator.add(ModelFabric.get(target), true);
|
||||||
else specificator.add(ModelFabric.get(target), time, true);
|
else specificator.add(ModelFabric.get(target), interval, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user