implement parsing Shipyard from EDCE
This commit is contained in:
@@ -131,7 +131,7 @@
|
|||||||
<item name="asp" id="i90"/>
|
<item name="asp" id="i90"/>
|
||||||
<item name="federal_dropship" id="i94"/>
|
<item name="federal_dropship" id="i94"/>
|
||||||
<item name="type7" id="i88"/>
|
<item name="type7" id="i88"/>
|
||||||
<item name="federal_assault ship" id="i248"/>
|
<item name="federal_assault_ship" id="i248"/>
|
||||||
<item name="imperial_clipper" id="i93"/>
|
<item name="imperial_clipper" id="i93"/>
|
||||||
<item name="federal_gunship" id="i249"/>
|
<item name="federal_gunship" id="i249"/>
|
||||||
<item name="orca" id="i92"/>
|
<item name="orca" id="i92"/>
|
||||||
|
|||||||
@@ -131,7 +131,7 @@
|
|||||||
<item name="asp" id="i95"/>
|
<item name="asp" id="i95"/>
|
||||||
<item name="federal_dropship" id="i99"/>
|
<item name="federal_dropship" id="i99"/>
|
||||||
<item name="type7" id="i96"/>
|
<item name="type7" id="i96"/>
|
||||||
<item name="federal_assault ship" id="i100"/>
|
<item name="federal_assault_ship" id="i100"/>
|
||||||
<item name="imperial_clipper" id="i97"/>
|
<item name="imperial_clipper" id="i97"/>
|
||||||
<item name="federal_gunship" id="i101"/>
|
<item name="federal_gunship" id="i101"/>
|
||||||
<item name="orca" id="i102"/>
|
<item name="orca" id="i102"/>
|
||||||
|
|||||||
@@ -150,6 +150,27 @@ public class EDCE {
|
|||||||
LOG.warn("Not found {}, id={}", commodity, id);
|
LOG.warn("Not found {}, id={}", commodity, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Shipyard shipyard = starport.getShips();
|
||||||
|
if (shipyard != null){
|
||||||
|
for (ShipyardItem ship : shipyard.getShips()) {
|
||||||
|
String id = Converter.getShipId(ship);
|
||||||
|
if (id.isEmpty()){
|
||||||
|
LOG.debug("{} is ignored, skip", ship.getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Optional<ItemModel> item = world.getItem(id);
|
||||||
|
if (item.isPresent()){
|
||||||
|
Optional<StationUpdater.FakeOffer> offer = updater.getOffer(item.get());
|
||||||
|
if (offer.isPresent()){
|
||||||
|
fillShipOffer(offer.get(), ship);
|
||||||
|
} else {
|
||||||
|
LOG.error("Not found offer in updater, item: {}", item.get());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG.warn("Not found {}, id={}", ship, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
StationModel res = updater.commit();
|
StationModel res = updater.commit();
|
||||||
updater.reset();
|
updater.reset();
|
||||||
return res;
|
return res;
|
||||||
@@ -157,9 +178,16 @@ public class EDCE {
|
|||||||
|
|
||||||
private void fillOffers(StationUpdater.FakeOffer offer, Commodity commodity){
|
private void fillOffers(StationUpdater.FakeOffer offer, Commodity commodity){
|
||||||
offer.setSprice(commodity.getBuyPrice());
|
offer.setSprice(commodity.getBuyPrice());
|
||||||
|
offer.setSupply(commodity.getStock());
|
||||||
offer.setBprice(commodity.getSellPrice());
|
offer.setBprice(commodity.getSellPrice());
|
||||||
offer.setDemand(commodity.getDemand());
|
offer.setDemand(commodity.getDemand());
|
||||||
offer.setSupply(commodity.getStock());
|
}
|
||||||
|
|
||||||
|
private void fillShipOffer(StationUpdater.FakeOffer offer, ShipyardItem ship){
|
||||||
|
offer.setSprice(ship.getBasevalue());
|
||||||
|
offer.setSupply(1);
|
||||||
|
offer.setBprice(0);
|
||||||
|
offer.setDemand(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkShip(Ship ship){
|
private void checkShip(Ship ship){
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.trader.edce;
|
package ru.trader.edce;
|
||||||
|
|
||||||
import ru.trader.edce.entities.Commodity;
|
import ru.trader.edce.entities.Commodity;
|
||||||
|
import ru.trader.edce.entities.ShipyardItem;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -114,29 +115,29 @@ public class Converter {
|
|||||||
GROUP_ID.put("Weapons", "weapons");
|
GROUP_ID.put("Weapons", "weapons");
|
||||||
|
|
||||||
|
|
||||||
SHIP_ID.put(128049249L,"Sidewinder");
|
SHIP_ID.put(128049249L,"sidewinder");
|
||||||
SHIP_ID.put(128049261L, "Hauler");
|
SHIP_ID.put(128049261L, "hauler");
|
||||||
SHIP_ID.put(128049255L, "Eagle");
|
SHIP_ID.put(128049255L, "eagle");
|
||||||
SHIP_ID.put(128049267L, "Adder");
|
SHIP_ID.put(128049267L, "adder");
|
||||||
// SHIP_ID.put("Imperial Eagle");
|
SHIP_ID.put(128672138L, "imperial_eagle");
|
||||||
SHIP_ID.put(128049273L, "Viper");
|
SHIP_ID.put(128049273L, "viper");
|
||||||
SHIP_ID.put(128049279L, "Cobra MK3");
|
SHIP_ID.put(128049279L, "cobraMk3");
|
||||||
SHIP_ID.put(128671217L, "Diamondback Scout");
|
SHIP_ID.put(128671217L, "diamondback_scout");
|
||||||
SHIP_ID.put(128049285L, "TYPE-6");
|
SHIP_ID.put(128049285L, "type6");
|
||||||
// SHIP_ID.put("Diamondback Explorer");
|
SHIP_ID.put(128671831L, "diamondback_explorer");
|
||||||
SHIP_ID.put(128049309L, "Vulture");
|
SHIP_ID.put(128049309L, "vulture");
|
||||||
SHIP_ID.put(128049303L, "ASP");
|
SHIP_ID.put(128049303L, "asp");
|
||||||
// SHIP_ID.put("TYPE-7");
|
SHIP_ID.put(128049297L, "type7");
|
||||||
// SHIP_ID.put("Imperial Clipper");
|
SHIP_ID.put(128049315L, "imperial_clipper");
|
||||||
// SHIP_ID.put("Imperial Courier");
|
SHIP_ID.put(128671223L, "imperial_courier");
|
||||||
SHIP_ID.put(128049321L, "Federal Dropship");
|
SHIP_ID.put(128049321L, "federal_dropship");
|
||||||
// SHIP_ID.put("Federal Assault Ship");
|
SHIP_ID.put(128672145L, "federal_assault_ship");
|
||||||
// SHIP_ID.put("Federal Gunship");
|
SHIP_ID.put(128672152L, "federal_gunship");
|
||||||
// SHIP_ID.put("Orca");
|
SHIP_ID.put(128049327L, "orca");
|
||||||
// SHIP_ID.put("Fer-de-Lance");
|
SHIP_ID.put(128049351L, "fer_de_lance");
|
||||||
SHIP_ID.put(128049339L, "Python");
|
SHIP_ID.put(128049339L, "python");
|
||||||
// SHIP_ID.put("TYPE-9");
|
SHIP_ID.put(128049333L, "type9");
|
||||||
SHIP_ID.put(128049363L, "Anaconda");
|
SHIP_ID.put(128049363L, "anaconda");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getItemId(Commodity commodity){
|
public static String getItemId(Commodity commodity){
|
||||||
@@ -151,4 +152,8 @@ public class Converter {
|
|||||||
return GROUP_ID.get(edName);
|
return GROUP_ID.get(edName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getShipId(ShipyardItem ship){
|
||||||
|
return SHIP_ID.get(ship.getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
35
utils/src/main/java/ru/trader/edce/entities/Shipyard.java
Normal file
35
utils/src/main/java/ru/trader/edce/entities/Shipyard.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package ru.trader.edce.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Shipyard {
|
||||||
|
@JsonProperty("shipyard_list")
|
||||||
|
private Map<String, ShipyardItem> items = new HashMap<>();
|
||||||
|
@JsonProperty("unavailable_list")
|
||||||
|
private List<ShipyardItem> unavailables = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String, ShipyardItem> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(Map<String, ShipyardItem> items) {
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShipyardItem> getUnavailables() {
|
||||||
|
return unavailables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnavailables(List<ShipyardItem> unavailables) {
|
||||||
|
this.unavailables = unavailables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ShipyardItem> getShips(){
|
||||||
|
Collection<ShipyardItem> ships = new ArrayList<>(items.values());
|
||||||
|
ships.addAll(unavailables);
|
||||||
|
return ships;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,4 +28,13 @@ public class ShipyardItem {
|
|||||||
public void setBasevalue(long basevalue) {
|
public void setBasevalue(long basevalue) {
|
||||||
this.basevalue = basevalue;
|
this.basevalue = basevalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ShipyardItem{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", basevalue=" + basevalue +
|
||||||
|
"} ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class Starport {
|
|||||||
private String faction;
|
private String faction;
|
||||||
private List<Commodity> commodities = new ArrayList<>();
|
private List<Commodity> commodities = new ArrayList<>();
|
||||||
private Map<String, Module> modules = new LinkedHashMap<>();
|
private Map<String, Module> modules = new LinkedHashMap<>();
|
||||||
|
private Shipyard ships;
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -49,6 +50,14 @@ public class Starport {
|
|||||||
this.modules = modules;
|
this.modules = modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Shipyard getShips() {
|
||||||
|
return ships;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShips(Shipyard ships) {
|
||||||
|
this.ships = ships;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|||||||
@@ -186,4 +186,23 @@ public class ParseTest extends Assert {
|
|||||||
assertNotNull(ship);
|
assertNotNull(ship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseShipyard() throws Exception {
|
||||||
|
LOG.info("Test parse json9");
|
||||||
|
InputStream is = getClass().getResourceAsStream("/edce/edce9.json");
|
||||||
|
String json = read(is);
|
||||||
|
LOG.trace("Parse json:");
|
||||||
|
LOG.trace("{}", json);
|
||||||
|
EDPacket packet = EDCEParser.parseJSON(json);
|
||||||
|
Commander commander = packet.getCommander();
|
||||||
|
assertNotNull(commander);
|
||||||
|
System system = packet.getLastSystem();
|
||||||
|
assertNotNull(system);
|
||||||
|
Starport starport = packet.getLastStarport();
|
||||||
|
assertNotNull(starport);
|
||||||
|
Shipyard shipyard = starport.getShips();
|
||||||
|
assertNotNull(shipyard);
|
||||||
|
assertEquals(23, shipyard.getShips().size());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user