implement add missions to route which don't have target
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.Pane;
|
||||
import ru.trader.analysis.CrawlerSpecificator;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Track;
|
||||
@@ -17,6 +18,8 @@ import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
||||
import ru.trader.view.support.autocomplete.SystemsProvider;
|
||||
import ru.trader.view.support.cells.OrderListCell;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RouteTrackController {
|
||||
@@ -129,10 +132,6 @@ public class RouteTrackController {
|
||||
if (index != -1) {
|
||||
RouteEntryModel entry = route.get(index);
|
||||
missionsController.setStation(entry.getStation());
|
||||
ObservableList<String> stations = BindingsHelper.observableList(route.getStations(index), StationModel::getFullName);
|
||||
missionsController.setStations(stations);
|
||||
ObservableList<ItemModel> items = FXCollections.observableList(route.getSellOffers(index).stream().map(OfferModel::getItem).collect(Collectors.toList()));
|
||||
missionsController.setItems(items);
|
||||
|
||||
station.setText(entry.getStation().getName());
|
||||
system.setText(entry.getStation().getSystem().getName());
|
||||
@@ -143,8 +142,6 @@ public class RouteTrackController {
|
||||
missionsList.setItems(entry.missions());
|
||||
} else {
|
||||
missionsController.setStation(ModelFabric.NONE_STATION);
|
||||
missionsController.setStations(FXCollections.emptyObservableList());
|
||||
missionsController.setItems(FXCollections.emptyObservableList());
|
||||
|
||||
station.setText("");
|
||||
system.setText("");
|
||||
@@ -169,8 +166,43 @@ public class RouteTrackController {
|
||||
|
||||
@FXML
|
||||
private void addMissionsToTrack(){
|
||||
int startIndex = trackNode.getActive();
|
||||
route.addAll(startIndex, addMissionsList.getItems());
|
||||
addMissionsToTrack(addMissionsList.getItems(), false);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addAllMissionsToTrack(){
|
||||
addMissionsToTrack(addMissionsList.getItems(), true);
|
||||
}
|
||||
|
||||
private void addMissionsToTrack(Collection<MissionModel> missions, boolean all){
|
||||
if (missions.isEmpty()) return;
|
||||
final int startIndex = trackNode.getActive();
|
||||
final Collection<MissionModel> notAdded = route.addAll(startIndex, missions);
|
||||
if (all && !notAdded.isEmpty()){
|
||||
CrawlerSpecificator specificator = new CrawlerSpecificator();
|
||||
specificator.setFullScan(false);
|
||||
final Collection<MissionModel> oldMissions = route.getMissions(startIndex);
|
||||
oldMissions.forEach(m -> m.toSpecification(specificator));
|
||||
notAdded.forEach(m -> m.toSpecification(specificator));
|
||||
StationModel from = route.get(startIndex).getStation();
|
||||
StationModel to = route.getLast().getStation();
|
||||
route.getMarket().getRoutes(from, to, route.getBalance(startIndex), specificator, routes -> {
|
||||
Optional<RouteModel> path = Screeners.showRouters(routes);
|
||||
if (path.isPresent()) {
|
||||
route.removeAll(oldMissions);
|
||||
RouteModel newRoute = route.set(startIndex, path.get());
|
||||
newRoute.addAll(startIndex, notAdded);
|
||||
newRoute.addAll(startIndex, oldMissions);
|
||||
setRoute(newRoute);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (notAdded.isEmpty()){
|
||||
Screeners.showInfo("Результат операции", null, "Миссии добавлены");
|
||||
} else {
|
||||
Screeners.showInfo("Результат операции", "Миссии не добавлены", notAdded.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -122,6 +122,16 @@ public class OrderModel {
|
||||
return buyOffer != null ? buyer.get().getStation() : null;
|
||||
}
|
||||
|
||||
public double getCredit(){
|
||||
return getCount() * getOffer().getPrice();
|
||||
}
|
||||
|
||||
public double getDebet(){
|
||||
OfferModel buyOffer = getBuyOffer();
|
||||
return buyOffer != null ? getCount() * getBuyOffer().getPrice() : 0;
|
||||
}
|
||||
|
||||
|
||||
public double getProfit() {
|
||||
return profitProperty().get();
|
||||
}
|
||||
|
||||
@@ -59,14 +59,23 @@ public class RouteModel {
|
||||
}
|
||||
}
|
||||
|
||||
public MarketModel getMarket(){
|
||||
return market;
|
||||
}
|
||||
|
||||
Route getRoute() {
|
||||
return _route;
|
||||
}
|
||||
|
||||
private RouteModel getCopy(){
|
||||
RouteModel res = new RouteModel(_route, market);
|
||||
|
||||
private RouteModel copyFill(Route route){
|
||||
return copyFill(route, entries.size()-1);
|
||||
}
|
||||
|
||||
private RouteModel copyFill(Route route, int index){
|
||||
RouteModel res = new RouteModel(route, market);
|
||||
res.setCurrentEntry(getCurrentEntry());
|
||||
int size = Math.min(entries.size(), res.entries.size());
|
||||
int size = Math.min(index+1, res.entries.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
RouteEntryModel entry = entries.get(i);
|
||||
RouteEntryModel rEntry = res.entries.get(i);
|
||||
@@ -83,6 +92,11 @@ public class RouteModel {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public RouteEntryModel getLast(){
|
||||
if (entries.size() == 1) return entries.get(0);
|
||||
return entries.get(entries.size()-1);
|
||||
}
|
||||
|
||||
public double getDistance() {
|
||||
return _route.getDistance();
|
||||
}
|
||||
@@ -137,8 +151,9 @@ public class RouteModel {
|
||||
public RouteModel add(OrderModel order){
|
||||
Route path = market._getPath(order);
|
||||
if (path == null) return this;
|
||||
_route.join(path);
|
||||
return getCopy();
|
||||
Route route = Route.clone(_route);
|
||||
route.join(path);
|
||||
return copyFill(route);
|
||||
}
|
||||
|
||||
public RouteModel add(SystemModel system){
|
||||
@@ -156,17 +171,26 @@ public class RouteModel {
|
||||
}
|
||||
|
||||
public RouteModel add(RouteModel route){
|
||||
_route.join(ModelFabric.get(route));
|
||||
return getCopy();
|
||||
Route res = Route.clone(_route);
|
||||
res.join(ModelFabric.get(route));
|
||||
return copyFill(res);
|
||||
}
|
||||
|
||||
public RouteModel set(int offset, RouteModel route){
|
||||
Route res = Route.clone(_route);
|
||||
res.dropTo(offset);
|
||||
res.join(ModelFabric.get(route));
|
||||
return copyFill(res, offset);
|
||||
}
|
||||
|
||||
public RouteModel remove(OrderModel order) {
|
||||
_route.dropTo(ModelFabric.get(order.getStation()));
|
||||
return getCopy();
|
||||
Route res = Route.clone(_route);
|
||||
res.dropTo(ModelFabric.get(order.getStation()));
|
||||
return copyFill(res);
|
||||
}
|
||||
|
||||
public void add(int offset, MissionModel mission){
|
||||
mission = mission.getCopy();
|
||||
public boolean add(int offset, MissionModel mission){
|
||||
mission = MissionModel.copy(mission);
|
||||
int completeIndex = -1;
|
||||
Offer offer = mission.getOffer();
|
||||
if (offer != null){
|
||||
@@ -198,16 +222,24 @@ public class RouteModel {
|
||||
}
|
||||
if (completeIndex != -1){
|
||||
entries.get(completeIndex).add(mission);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addAll(int offset, Collection<MissionModel> missions){
|
||||
for (MissionModel mission : missions) {
|
||||
mission = mission.getCopy();
|
||||
public Collection<MissionModel> addAll(int offset, Collection<MissionModel> missions){
|
||||
Collection<MissionModel> notAdded = new ArrayList<>();
|
||||
for (MissionModel m : missions) {
|
||||
MissionModel mission = MissionModel.copy(m);
|
||||
Offer offer = mission.getOffer();
|
||||
int completeIndex = -1;
|
||||
if (offer != null){
|
||||
Collection<RouteReserve> reserves = RouteFiller.getReserves(_route, offset, offer);
|
||||
Collection<RouteReserve> reserves;
|
||||
if (m.getReserves() != null){
|
||||
reserves = RouteFiller.changeReserves(_route, offset, offer, m.getReserves());
|
||||
} else {
|
||||
reserves = RouteFiller.getReserves(_route, offset, offer);
|
||||
}
|
||||
if (!reserves.isEmpty()) {
|
||||
_route.reserve(reserves);
|
||||
mission.setReserves(reserves);
|
||||
@@ -228,6 +260,34 @@ public class RouteModel {
|
||||
if (completeIndex != -1){
|
||||
if (completeIndex == 0 && _route.isLoop()) completeIndex = _route.getJumps()-1;
|
||||
entries.get(completeIndex).add(mission);
|
||||
} else {
|
||||
notAdded.add(mission);
|
||||
}
|
||||
}
|
||||
refresh();
|
||||
return notAdded;
|
||||
}
|
||||
|
||||
public void remove(MissionModel mission){
|
||||
Collection<RouteReserve> reserves = mission.getReserves();
|
||||
if (reserves != null) {
|
||||
_route.unreserve(reserves);
|
||||
}
|
||||
for (RouteEntryModel entry : entries) {
|
||||
entry.remove(mission);
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
public void removeAll(Collection<MissionModel> missions){
|
||||
for (MissionModel mission : missions) {
|
||||
Collection<RouteReserve> reserves = mission.getReserves();
|
||||
if (reserves != null) {
|
||||
_route.unreserve(reserves);
|
||||
}
|
||||
for (RouteEntryModel entry : entries) {
|
||||
entry.remove(mission);
|
||||
}
|
||||
}
|
||||
refresh();
|
||||
@@ -245,6 +305,15 @@ public class RouteModel {
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<MissionModel> getMissions(int offset){
|
||||
int startIndex = offset+1;
|
||||
if (startIndex >= entries.size()) return Collections.emptyList();
|
||||
List<MissionModel> res = entries.subList(startIndex, entries.size()).stream()
|
||||
.flatMap(e -> e.missions().stream())
|
||||
.collect(Collectors.toList());
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<OfferModel> getSellOffers(int offset){
|
||||
Map<ItemModel, OfferModel> res = new HashMap<>();
|
||||
for (StationModel station : getStations(offset)) {
|
||||
@@ -260,6 +329,15 @@ public class RouteModel {
|
||||
return res.values();
|
||||
}
|
||||
|
||||
public double getBalance(int index){
|
||||
int endIndex = index+1;
|
||||
if (endIndex > entries.size()) endIndex = entries.size();
|
||||
double balance = _route.getBalance();
|
||||
balance -= entries.subList(0, endIndex).stream().flatMap(e -> e.orders().stream()).mapToDouble(OrderModel::getCredit).sum();
|
||||
balance += entries.subList(0, endIndex).stream().flatMap(e -> e.sellOrders().stream()).mapToDouble(OrderModel::getDebet).sum();
|
||||
return balance;
|
||||
}
|
||||
|
||||
public int getCurrentEntry() {
|
||||
return currentEntry.get();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
<Button prefWidth="30" onAction="#removeMission"><graphic><Glyph text="FontAwesome|MINUS"/></graphic></Button>
|
||||
<Button prefWidth="30" onAction="#clearMissions"><graphic><Glyph text="FontAwesome|TRASH"/></graphic></Button>
|
||||
</VBox>
|
||||
<Button prefWidth="80" text="Добавить" onAction="#addMissionsToTrack" />
|
||||
<VBox>
|
||||
<Button prefWidth="80" text="Добавить" onAction="#addMissionsToTrack" />
|
||||
<Button prefWidth="80" text="Добавить все" onAction="#addAllMissionsToTrack" />
|
||||
</VBox>
|
||||
</HBox>
|
||||
</VBox>
|
||||
<VBox fx:id="infoGroup">
|
||||
|
||||
Reference in New Issue
Block a user