implement FSD modification
This commit is contained in:
36
core/src/main/java/ru/trader/core/ModEngine.java
Normal file
36
core/src/main/java/ru/trader/core/ModEngine.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package ru.trader.core;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ModEngine extends Engine {
|
||||
private final double optMass;
|
||||
|
||||
public ModEngine(int clazz, char rating) {
|
||||
super(clazz, rating);
|
||||
optMass = super.getOptMass();
|
||||
}
|
||||
|
||||
public ModEngine(int clazz, char rating, double optMass) {
|
||||
super(clazz, rating);
|
||||
this.optMass = optMass;
|
||||
}
|
||||
|
||||
public ModEngine(Engine engine, double optMass) {
|
||||
super(engine.getClazz(), engine.getRating());
|
||||
this.optMass = optMass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOptMass() {
|
||||
return optMass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ModEngine)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
ModEngine modEngine = (ModEngine) o;
|
||||
return Objects.equals(optMass, modEngine.optMass);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class Ship {
|
||||
}
|
||||
|
||||
public static Ship clone(Ship ship){
|
||||
return ship != null ? new Ship(ship) : ship;
|
||||
return ship != null ? new Ship(ship) : null;
|
||||
}
|
||||
|
||||
public long getCargo() {
|
||||
@@ -223,7 +223,12 @@ public class Ship {
|
||||
String e = values.getProperty("ship.engine","2E");
|
||||
Matcher matcher = ENGINE_REGEXP.matcher(e);
|
||||
if (matcher.find()){
|
||||
ship.setEngine(Integer.valueOf(matcher.group(1)), matcher.group(2).charAt(0));
|
||||
double optMass = Double.valueOf(values.getProperty("ship.engine.optmass", "-1"));
|
||||
if (optMass != -1) {
|
||||
ship.setEngine(new ModEngine(Integer.valueOf(matcher.group(1)), matcher.group(2).charAt(0), optMass));
|
||||
} else {
|
||||
ship.setEngine(Integer.valueOf(matcher.group(1)), matcher.group(2).charAt(0));
|
||||
}
|
||||
}
|
||||
return ship;
|
||||
}
|
||||
@@ -233,5 +238,10 @@ public class Ship {
|
||||
values.setProperty("ship.cargo", String.valueOf(cargo));
|
||||
values.setProperty("ship.tank", String.valueOf(tank));
|
||||
values.setProperty("ship.engine", String.valueOf(engine.getClazz()) + engine.getRating());
|
||||
double optMass = -1;
|
||||
if (engine instanceof ModEngine){
|
||||
optMass = engine.getOptMass();
|
||||
}
|
||||
values.setProperty("ship.engine.optmass", String.valueOf(optMass));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user