add copy mission to route entry
This commit is contained in:
@@ -6,6 +6,7 @@ import ru.trader.core.Offer;
|
||||
import ru.trader.store.simple.SimpleOffer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MissionModel {
|
||||
private final StationModel target;
|
||||
@@ -17,21 +18,11 @@ public class MissionModel {
|
||||
private Collection<RouteReserve> reserves;
|
||||
|
||||
public MissionModel(StationModel target, double profit) {
|
||||
this.target = target;
|
||||
this.profit = profit;
|
||||
item = null;
|
||||
count = 0;
|
||||
offer = null;
|
||||
need = 0;
|
||||
this(target, null, 0, profit);
|
||||
}
|
||||
|
||||
public MissionModel(StationModel target, long count, double profit) {
|
||||
this.target = target;
|
||||
this.count = count;
|
||||
this.profit = profit;
|
||||
this.item = null;
|
||||
offer = null;
|
||||
need = 0;
|
||||
this(target, null, count, profit);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +31,13 @@ public class MissionModel {
|
||||
this.item = item;
|
||||
this.count = count;
|
||||
this.profit = profit;
|
||||
if (item != null) {
|
||||
offer = SimpleOffer.fakeBuy(target.getStation(), item.getItem(), profit / count, count);
|
||||
need = count;
|
||||
} else {
|
||||
need = 0;
|
||||
offer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public StationModel getTarget() {
|
||||
@@ -65,15 +61,24 @@ public class MissionModel {
|
||||
}
|
||||
|
||||
public boolean isDelivery(){
|
||||
return count > 0;
|
||||
return item == null && count > 0;
|
||||
}
|
||||
|
||||
public boolean isCourier(){
|
||||
return count == 0;
|
||||
return item == null && count == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isDelivery()){
|
||||
return String.format("Deliver %d items to %s", count, target.getName());
|
||||
}
|
||||
if (isCourier()){
|
||||
return String.format("Deliver message to %s", target.getName());
|
||||
}
|
||||
if (isSupply()){
|
||||
return String.format("Supply %d %s to %s", count, item.getName(), target.getName());
|
||||
}
|
||||
return "MissionModel{" +
|
||||
"target=" + target +
|
||||
", item=" + item +
|
||||
@@ -121,4 +126,26 @@ public class MissionModel {
|
||||
public boolean isCompleted(){
|
||||
return need <= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MissionModel that = (MissionModel) o;
|
||||
return Objects.equals(count, that.count) &&
|
||||
Objects.equals(profit, that.profit) &&
|
||||
Objects.equals(target, that.target) &&
|
||||
Objects.equals(item, that.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(target, item, count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MissionModel getCopy(){
|
||||
return new MissionModel(target, item, count, profit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ public class RouteModel {
|
||||
}
|
||||
|
||||
public void add(int offset, MissionModel mission){
|
||||
mission = mission.getCopy();
|
||||
int completeIndex = -1;
|
||||
Offer offer = mission.getOffer();
|
||||
if (offer != null){
|
||||
@@ -176,6 +177,7 @@ public class RouteModel {
|
||||
|
||||
public void addAll(int offset, Collection<MissionModel> missions){
|
||||
for (MissionModel mission : missions) {
|
||||
mission = mission.getCopy();
|
||||
Offer offer = mission.getOffer();
|
||||
int completeIndex = -1;
|
||||
if (offer != null){
|
||||
|
||||
Reference in New Issue
Block a user