Archived
0

add copy mission to route entry

This commit is contained in:
Mo
2015-10-22 15:11:25 +03:00
parent b90d977ba0
commit a9005c6539
2 changed files with 45 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import ru.trader.core.Offer;
import ru.trader.store.simple.SimpleOffer; import ru.trader.store.simple.SimpleOffer;
import java.util.Collection; import java.util.Collection;
import java.util.Objects;
public class MissionModel { public class MissionModel {
private final StationModel target; private final StationModel target;
@@ -17,21 +18,11 @@ public class MissionModel {
private Collection<RouteReserve> reserves; private Collection<RouteReserve> reserves;
public MissionModel(StationModel target, double profit) { public MissionModel(StationModel target, double profit) {
this.target = target; this(target, null, 0, profit);
this.profit = profit;
item = null;
count = 0;
offer = null;
need = 0;
} }
public MissionModel(StationModel target, long count, double profit) { public MissionModel(StationModel target, long count, double profit) {
this.target = target; this(target, null, count, profit);
this.count = count;
this.profit = profit;
this.item = null;
offer = null;
need = 0;
} }
@@ -40,8 +31,13 @@ public class MissionModel {
this.item = item; this.item = item;
this.count = count; this.count = count;
this.profit = profit; this.profit = profit;
offer = SimpleOffer.fakeBuy(target.getStation(), item.getItem(), profit/count, count); if (item != null) {
offer = SimpleOffer.fakeBuy(target.getStation(), item.getItem(), profit / count, count);
need = count; need = count;
} else {
need = 0;
offer = null;
}
} }
public StationModel getTarget() { public StationModel getTarget() {
@@ -65,15 +61,24 @@ public class MissionModel {
} }
public boolean isDelivery(){ public boolean isDelivery(){
return count > 0; return item == null && count > 0;
} }
public boolean isCourier(){ public boolean isCourier(){
return count == 0; return item == null && count == 0;
} }
@Override @Override
public String toString() { 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{" + return "MissionModel{" +
"target=" + target + "target=" + target +
", item=" + item + ", item=" + item +
@@ -121,4 +126,26 @@ public class MissionModel {
public boolean isCompleted(){ public boolean isCompleted(){
return need <= 0; 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);
}
} }

View File

@@ -140,6 +140,7 @@ public class RouteModel {
} }
public void add(int offset, MissionModel mission){ public void add(int offset, MissionModel mission){
mission = mission.getCopy();
int completeIndex = -1; int completeIndex = -1;
Offer offer = mission.getOffer(); Offer offer = mission.getOffer();
if (offer != null){ if (offer != null){
@@ -176,6 +177,7 @@ public class RouteModel {
public void addAll(int offset, Collection<MissionModel> missions){ public void addAll(int offset, Collection<MissionModel> missions){
for (MissionModel mission : missions) { for (MissionModel mission : missions) {
mission = mission.getCopy();
Offer offer = mission.getOffer(); Offer offer = mission.getOffer();
int completeIndex = -1; int completeIndex = -1;
if (offer != null){ if (offer != null){