More OOP classes
This commit is contained in:
parent
f3bbeb8d4a
commit
a08c6e1c64
@ -28,6 +28,8 @@ dependencies {
|
||||
implementation 'org.yaml:snakeyaml:2.2'
|
||||
implementation 'org.ojalgo:ojalgo:54.0.0'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
|
||||
implementation 'org.json:json:20240303'
|
||||
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
|
||||
@ -4,21 +4,34 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.bernard.greposimu.engine.Registerar;
|
||||
import com.bernard.greposimu.engine.game.Buildings;
|
||||
import com.bernard.greposimu.engine.json.MapJsonDeserializer;
|
||||
import com.bernard.greposimu.model.Dieu;
|
||||
import com.bernard.greposimu.model.Heros;
|
||||
import com.bernard.greposimu.model.OffDefStats;
|
||||
import com.bernard.greposimu.model.game.GameData;
|
||||
import com.bernard.greposimu.model.game.Power;
|
||||
import com.bernard.greposimu.model.game.GameConfig;
|
||||
import com.bernard.greposimu.model.game.God;
|
||||
import com.bernard.greposimu.model.game.Resources;
|
||||
import com.bernard.greposimu.model.game.units.FightType;
|
||||
import com.bernard.greposimu.model.game.units.NavalUnit;
|
||||
import com.bernard.greposimu.model.game.units.TerrestrialUnit;
|
||||
import com.bernard.greposimu.model.game.units.TransportUnit;
|
||||
import com.bernard.greposimu.model.game.units.Unit;
|
||||
import com.bernard.greposimu.model.jsongame.GameData;
|
||||
import com.bernard.greposimu.model.jsongame.Power;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.StreamReadFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -66,9 +79,26 @@ public class GrepoSimu {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
for(int i=0;i<26;i++)
|
||||
System.out.println(i+"->"+Buildings.wallBonus(i));
|
||||
public static GameConfig makeGameData() throws IOException {
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
try (InputStream is = classLoader.getResourceAsStream("gamedata.json")) {
|
||||
if (is == null) return null;
|
||||
try (InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader reader = new BufferedReader(isr)) {
|
||||
// Reading the file
|
||||
String json = reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
JSONObject obj = new JSONObject(json);
|
||||
|
||||
return new GameConfig(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println(makeGameData());
|
||||
//for(int i=0;i<26;i++)
|
||||
// System.out.println(i+"->"+Buildings.wallBonus(i));
|
||||
}
|
||||
|
||||
public static void mainZ(String[] args) {
|
||||
|
||||
@ -6,6 +6,8 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.model.game.Identified;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final double poly5(double a0, double a1, double a2, double a3, double a4, double a5, double x) {
|
||||
@ -18,6 +20,10 @@ public class Utils {
|
||||
a5 * x * x * x * x * x;
|
||||
}
|
||||
|
||||
public static final <T extends Identified> T getIdentified(Set<T> set, String id) {
|
||||
return set.stream().filter(x -> x.getId().equals(id)).findAny().orElse(null);
|
||||
}
|
||||
|
||||
public static final <T> Map<T,Boolean> setToMap(Set<T> set){
|
||||
return new AbstractMap<T,Boolean>() {
|
||||
|
||||
@ -65,5 +71,4 @@ public class Utils {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -18,18 +19,20 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.bernard.greposimu.GrepoSimu;
|
||||
import com.bernard.greposimu.Utils;
|
||||
import com.bernard.greposimu.engine.Optimizer;
|
||||
import com.bernard.greposimu.engine.Optimizer.UnitesProportions;
|
||||
import com.bernard.greposimu.engine.Registerar;
|
||||
import com.bernard.greposimu.engine.game.Fight;
|
||||
import com.bernard.greposimu.engine.game.Game;
|
||||
import com.bernard.greposimu.model.DefContext;
|
||||
import com.bernard.greposimu.model.Dieu;
|
||||
import com.bernard.greposimu.model.FightStats;
|
||||
import com.bernard.greposimu.model.Heros;
|
||||
import com.bernard.greposimu.model.OffDefStats;
|
||||
import com.bernard.greposimu.model.Unite;
|
||||
import com.bernard.greposimu.model.game.GameData;
|
||||
import com.bernard.greposimu.model.game.GameConfig;
|
||||
import com.bernard.greposimu.model.game.units.Unit;
|
||||
import com.bernard.greposimu.model.jsongame.GameData;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
|
||||
@ -55,23 +58,23 @@ public class GrepoSimuController {
|
||||
public String simulator(Model model) throws IOException {
|
||||
GameData data = GrepoSimu.readGameData();
|
||||
model.addAttribute("heroes", data.heroes.values());
|
||||
model.addAttribute("defUnits", Fight.relevantDefUnits(data));
|
||||
model.addAttribute("defUnits", Fight.relevantDefUnits(GrepoSimu.makeGameData()));
|
||||
model.addAttribute("defCounsellors",Fight.relevantDefCounsellors(data));
|
||||
model.addAttribute("defResearches",Fight.relevantDefResearch(data));
|
||||
model.addAttribute("defPowers",Fight.relevantDefPowers(data));
|
||||
model.addAttribute("defCtx",new DefContext());
|
||||
model.addAttribute("ctx",new DefSimulatorParams());
|
||||
return "simulator";
|
||||
}
|
||||
|
||||
@PostMapping("/simulate")
|
||||
@GetMapping("/simulate")
|
||||
public String simulate(@ModelAttribute DefContext defCtx, Model model) throws IOException {
|
||||
if(defCtx == null)
|
||||
defCtx = new DefContext();
|
||||
GameData data = GrepoSimu.readGameData();
|
||||
Game g = new Game(data);
|
||||
public String simulate(@ModelAttribute DefSimulatorParams defParams, Model model) throws IOException {
|
||||
if(defParams == null)
|
||||
defParams = new DefSimulatorParams();
|
||||
GameConfig gc = GrepoSimu.makeGameData();
|
||||
DefContext defCtx = defParams.asDefContext(gc);
|
||||
|
||||
FightStats cityStats = g.fight.computeDefStats(defCtx);
|
||||
FightStats cityStats = Fight.computeDefStats(gc,defCtx);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
|
||||
@ -120,6 +123,108 @@ public class GrepoSimuController {
|
||||
return "optimizerResult";
|
||||
}
|
||||
|
||||
public static class DefSimulatorParams {
|
||||
|
||||
// unitID -> number of units
|
||||
public Map<String, Integer> units = new HashMap<>();
|
||||
|
||||
public String hero = "";
|
||||
public int heroLevel = 0;
|
||||
|
||||
public int wallLevel = 0;
|
||||
public boolean hasTower = false;
|
||||
|
||||
public Set<String> powers = new HashSet<>();
|
||||
public Set<String> researches = new HashSet<>();
|
||||
|
||||
public Set<String> counsellors = new HashSet<>();
|
||||
|
||||
public boolean nightBonus = false;
|
||||
|
||||
public DefContext asDefContext(GameConfig gc) {
|
||||
Map<Unit,Integer> unitsU = new HashMap<>(units.size());
|
||||
for(String u : units.keySet())
|
||||
unitsU.put(gc.getUnit(u), units.get(u));
|
||||
return new DefContext(
|
||||
unitsU,
|
||||
gc.getHero(hero),
|
||||
heroLevel,
|
||||
wallLevel,
|
||||
hasTower,
|
||||
powers,
|
||||
researches,
|
||||
counsellors,
|
||||
nightBonus
|
||||
);
|
||||
}
|
||||
|
||||
public Map<String, Integer> getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setUnits(Map<String, Integer> units) {
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
public String getHero() {
|
||||
return hero;
|
||||
}
|
||||
|
||||
public void setHero(String hero) {
|
||||
this.hero = hero;
|
||||
}
|
||||
|
||||
public int getHeroLevel() {
|
||||
return heroLevel;
|
||||
}
|
||||
|
||||
public void setHeroLevel(int heroLevel) {
|
||||
this.heroLevel = heroLevel;
|
||||
}
|
||||
|
||||
public int getWallLevel() {
|
||||
return wallLevel;
|
||||
}
|
||||
|
||||
public void setWallLevel(int wallLevel) {
|
||||
this.wallLevel = wallLevel;
|
||||
}
|
||||
|
||||
public boolean isHasTower() {
|
||||
return hasTower;
|
||||
}
|
||||
|
||||
public void setHasTower(boolean hasTower) {
|
||||
this.hasTower = hasTower;
|
||||
}
|
||||
|
||||
public Set<String> getPowers() {
|
||||
return powers;
|
||||
}
|
||||
|
||||
public Map<String,Boolean> getPowersAsMap() {
|
||||
return Utils.setToMap(powers);
|
||||
}
|
||||
|
||||
public Map<String,Boolean> getResearchesAsMap() {
|
||||
return Utils.setToMap(researches);
|
||||
}
|
||||
|
||||
public Map<String,Boolean> getCounsellorsAsMap() {
|
||||
return Utils.setToMap(counsellors);
|
||||
}
|
||||
|
||||
public boolean isNightBonus() {
|
||||
return nightBonus;
|
||||
}
|
||||
|
||||
public void setNightBonus(boolean nightBonus) {
|
||||
this.nightBonus = nightBonus;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class OptimizerInput {
|
||||
|
||||
public String heros = Registerar.heros.stream().map(Heros::getPname).min(Comparator.comparing(Function.identity())).get();
|
||||
|
||||
@ -6,32 +6,29 @@ import java.util.Map;
|
||||
import com.bernard.greposimu.model.DefContext;
|
||||
import com.bernard.greposimu.model.FightStats;
|
||||
import com.bernard.greposimu.model.OffContext;
|
||||
import com.bernard.greposimu.model.game.GameData;
|
||||
import com.bernard.greposimu.model.game.Power;
|
||||
import com.bernard.greposimu.model.game.Research;
|
||||
import com.bernard.greposimu.model.game.Unit;
|
||||
|
||||
import com.bernard.greposimu.model.game.GameConfig;
|
||||
import com.bernard.greposimu.model.game.units.NavalUnit;
|
||||
import com.bernard.greposimu.model.game.units.TerrestrialUnit;
|
||||
import com.bernard.greposimu.model.game.units.Unit;
|
||||
import com.bernard.greposimu.model.jsongame.GameData;
|
||||
import com.bernard.greposimu.model.jsongame.Power;
|
||||
import com.bernard.greposimu.model.jsongame.Research;
|
||||
public class Fight {
|
||||
|
||||
Game g;
|
||||
|
||||
public Fight(Game g) {
|
||||
this.g = g;
|
||||
}
|
||||
public FightStats computeDefStats(DefContext def) {
|
||||
|
||||
public static FightStats computeDefStats(GameConfig gc, DefContext def) {
|
||||
//TODO replace def getters with more complex getters (.getCounsellors.contains -> .hasCounsellor; .getUnits.get -> .getUnitCount)
|
||||
|
||||
FightStats everyoneStatsBonus = FightStats.zero();
|
||||
Map<String,FightStats> unitsBonuses;
|
||||
Map<Unit,FightStats> unitsBonuses;
|
||||
FightStats cityBaseStats;
|
||||
|
||||
// Heroes
|
||||
unitsBonuses = g.heroes.heroFightBonuses(def.hero, def.heroLevel, false);
|
||||
unitsBonuses = Heroes.heroFightBonuses(gc, def.getHero(), def.getHeroLevel(), false);
|
||||
|
||||
// Tower & wall
|
||||
cityBaseStats = Buildings.cityBaseStats(def.wallLevel);
|
||||
everyoneStatsBonus = FightStats.add(everyoneStatsBonus, Buildings.wallBonus(def.wallLevel));
|
||||
if(def.hasTower)
|
||||
cityBaseStats = Buildings.cityBaseStats(def.getWallLevel());
|
||||
everyoneStatsBonus = FightStats.add(everyoneStatsBonus, Buildings.wallBonus(def.getWallLevel()));
|
||||
if(def.hasTower())
|
||||
// Add 10% to all units
|
||||
everyoneStatsBonus = FightStats.add(everyoneStatsBonus, FightStats.cst(0.1));
|
||||
|
||||
@ -40,53 +37,64 @@ public class Fight {
|
||||
//TODO powers
|
||||
|
||||
// Researches
|
||||
if(def.counsellors.contains("divine_selection"))
|
||||
for(String uid : g.data.units.keySet())
|
||||
if(g.data.units.get(uid).isMythological())
|
||||
unitsBonuses.put(uid, FightStats.add(unitsBonuses.getOrDefault(uid, FightStats.zero()), FightStats.cst(0.1)));
|
||||
if(def.counsellors.contains("phalanx"))
|
||||
for(String uid : g.data.units.keySet())
|
||||
if(g.data.units.get(uid).isGround())
|
||||
unitsBonuses.put(uid, FightStats.add(unitsBonuses.getOrDefault(uid, FightStats.zero()), FightStats.cst(0.1)));
|
||||
if(def.counsellors.contains("ram"))
|
||||
for(String uid : g.data.units.keySet())
|
||||
if(g.data.units.get(uid).isNaval())
|
||||
unitsBonuses.put(uid, FightStats.add(unitsBonuses.getOrDefault(uid, FightStats.zero()), FightStats.cst(0.1)));
|
||||
if(def.getCounsellors().contains("divine_selection"))
|
||||
for(Unit u : gc.getUnits())
|
||||
if(u.isMythological())
|
||||
unitsBonuses.put(u, FightStats.add(unitsBonuses.getOrDefault(u, FightStats.zero()), FightStats.cst(0.1)));
|
||||
if(def.getCounsellors().contains("phalanx"))
|
||||
for(Unit u : gc.getUnits())
|
||||
if(u.isGround())
|
||||
unitsBonuses.put(u, FightStats.add(unitsBonuses.getOrDefault(u, FightStats.zero()), FightStats.cst(0.1)));
|
||||
if(def.getCounsellors().contains("ram"))
|
||||
for(Unit u : gc.getUnits())
|
||||
if(u.isNaval())
|
||||
unitsBonuses.put(u, FightStats.add(unitsBonuses.getOrDefault(u, FightStats.zero()), FightStats.cst(0.1)));
|
||||
|
||||
// Counsellors
|
||||
if(def.counsellors.contains("priest"))
|
||||
for(String uid : g.data.units.keySet())
|
||||
if(g.data.units.get(uid).isMythological())
|
||||
unitsBonuses.put(uid, FightStats.add(unitsBonuses.getOrDefault(uid, FightStats.zero()), FightStats.cst(0.2)));
|
||||
if(def.counsellors.contains("commander"))
|
||||
for(String uid : g.data.units.keySet())
|
||||
if(g.data.units.get(uid).isGround())
|
||||
unitsBonuses.put(uid, FightStats.add(unitsBonuses.getOrDefault(uid, FightStats.zero()), FightStats.cst(0.2)));
|
||||
if(def.counsellors.contains("captain"))
|
||||
for(String uid : g.data.units.keySet())
|
||||
if(g.data.units.get(uid).isNaval())
|
||||
unitsBonuses.put(uid, FightStats.add(unitsBonuses.getOrDefault(uid, FightStats.zero()), FightStats.cst(0.2)));
|
||||
if(def.getCounsellors().contains("priest"))
|
||||
for(Unit u : gc.getUnits())
|
||||
if(u.isMythological())
|
||||
unitsBonuses.put(u, FightStats.add(unitsBonuses.getOrDefault(u, FightStats.zero()), FightStats.cst(0.2)));
|
||||
if(def.getCounsellors().contains("commander"))
|
||||
for(Unit u : gc.getUnits())
|
||||
if(u.isGround())
|
||||
unitsBonuses.put(u, FightStats.add(unitsBonuses.getOrDefault(u, FightStats.zero()), FightStats.cst(0.2)));
|
||||
if(def.getCounsellors().contains("captain"))
|
||||
for(Unit u : gc.getUnits())
|
||||
if(u.isNaval())
|
||||
unitsBonuses.put(u, FightStats.add(unitsBonuses.getOrDefault(u, FightStats.zero()), FightStats.cst(0.2)));
|
||||
|
||||
// Night Bonus
|
||||
if(def.nightBonus)
|
||||
if(def.isNightBonus())
|
||||
everyoneStatsBonus = FightStats.add(everyoneStatsBonus, FightStats.cst(1.0));
|
||||
|
||||
// Units
|
||||
FightStats total = cityBaseStats.clone();
|
||||
for(Unit u : g.data.units.values()) {
|
||||
for(Unit u : gc.getUnits()) {
|
||||
// total = total + ucount * ((1+bonus+bonus) * ustats)
|
||||
if(def.units.containsKey(u.id) && def.units.get(u.id) != null)
|
||||
if(def.getUnits().containsKey(u) && def.getUnits().get(u) != null)
|
||||
total = FightStats.add(total,
|
||||
FightStats.prod(def.units.get(u.id),
|
||||
FightStats.prod(def.getUnits().get(u),
|
||||
FightStats.mul(
|
||||
FightStats.add(FightStats.one(),everyoneStatsBonus,unitsBonuses.getOrDefault(u.id, FightStats.zero()))
|
||||
, u.getDefStats())
|
||||
FightStats.add(FightStats.one(),everyoneStatsBonus,unitsBonuses.getOrDefault(u, FightStats.zero()))
|
||||
, makeDefStats(u))
|
||||
));
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
public static FightStats makeDefStats(Unit u) {
|
||||
if(u instanceof TerrestrialUnit) {
|
||||
TerrestrialUnit tu = (TerrestrialUnit)u;
|
||||
return new FightStats(tu.getHackDef(), tu.getPierceDef(), tu.getDistanceDef(), 0.0);
|
||||
}else if(u instanceof NavalUnit) {
|
||||
NavalUnit nu = (NavalUnit)u;
|
||||
return new FightStats(0.0, 0.0, 0.0, nu.getDefense());
|
||||
}
|
||||
throw new UnsupportedOperationException("I don't know how to manage units of type "+u.getClass().getName());
|
||||
}
|
||||
|
||||
public static List<Power> relevantDefPowers(GameData gd) {
|
||||
System.out.println(gd.powers);
|
||||
return List.of("acumen", "divine_senses", "myrmidion_attack", "trojan_defense", "defense_boost",
|
||||
@ -100,8 +108,8 @@ public class Fight {
|
||||
return List.of("divine_selection","phalanx","ram")
|
||||
.stream().map(gd.researches::get).toList();
|
||||
}
|
||||
public static List<Unit> relevantDefUnits(GameData data) {
|
||||
return data.units.values().stream().toList();
|
||||
public static List<Unit> relevantDefUnits(GameConfig gc) {
|
||||
return gc.getUnits().stream().toList();
|
||||
}
|
||||
public static List<String> relevantDefCounsellors(GameData data) {
|
||||
return List.of("priest","commander","captain");
|
||||
|
||||
@ -1,20 +1,14 @@
|
||||
package com.bernard.greposimu.engine.game;
|
||||
|
||||
import com.bernard.greposimu.model.game.GameData;
|
||||
import com.bernard.greposimu.model.game.GameConfig;
|
||||
|
||||
public class Game {
|
||||
|
||||
GameData data;
|
||||
public Heroes heroes;
|
||||
public Buildings buildings;
|
||||
public Fight fight;
|
||||
GameConfig data;
|
||||
|
||||
|
||||
public Game(GameData data) {
|
||||
public Game(GameConfig data) {
|
||||
this.data = data;
|
||||
this.heroes = new Heroes(this);
|
||||
this.buildings = new Buildings(this);
|
||||
this.fight = new Fight(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,47 +2,33 @@ package com.bernard.greposimu.engine.game;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.bernard.greposimu.model.FightStats;
|
||||
import com.bernard.greposimu.model.game.Hero;
|
||||
import com.bernard.greposimu.model.game.GameConfig;
|
||||
import com.bernard.greposimu.model.game.units.Hero;
|
||||
import com.bernard.greposimu.model.game.units.Unit;
|
||||
|
||||
public class Heroes {
|
||||
|
||||
Game g;
|
||||
|
||||
|
||||
|
||||
public Heroes(Game g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Compute the bonus applied to each unit
|
||||
* @param hero The uid of the hero
|
||||
* @param hero The hero object to consider
|
||||
* @param level The level of the hero
|
||||
* @param off true for the off stat, false for the def stat
|
||||
* @return For each unit, the bonus that should be applied to it
|
||||
*/
|
||||
public Map<String,FightStats> heroFightBonuses(String hero, int level, boolean off){
|
||||
|
||||
Map<String,FightStats> bonuses = new HashMap<>();
|
||||
public static Map<Unit, FightStats> heroFightBonuses(GameConfig gc, Hero hero, int level, boolean off){
|
||||
|
||||
if(hero == null)
|
||||
return new HashMap<>();
|
||||
|
||||
double bonus = 0.0;
|
||||
Hero heroD = g.data.heroes.get(hero);
|
||||
if(heroD != null && heroD.description_args != null && heroD.description_args.containsKey("1")) {
|
||||
Hero.DescriptionArgs args = heroD.description_args.get("1");
|
||||
if(args.unit.equals("%"))
|
||||
bonus = args.value + level * args.level_mod;
|
||||
else
|
||||
throw new UnsupportedOperationException("I don't know about unit "+args.unit);
|
||||
}
|
||||
Map<String,FightStats> bonuses = new HashMap<>();
|
||||
|
||||
double bonus = hero.getPowerBaseValue() + level * hero.getPowerValuePerLevel();
|
||||
|
||||
FightStats appliedBonus = null;
|
||||
switch(hero) {
|
||||
switch(hero.getId()) {
|
||||
case "agamemnon":
|
||||
appliedBonus = FightStats.terrestre(bonus);
|
||||
bonuses.put("hoplite", appliedBonus);
|
||||
@ -59,7 +45,7 @@ public class Heroes {
|
||||
case "deimos":
|
||||
appliedBonus = FightStats.cst(bonus);
|
||||
if(off)
|
||||
for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
|
||||
for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
|
||||
break;
|
||||
case "hector":
|
||||
appliedBonus = FightStats.terrestre(bonus);
|
||||
@ -73,11 +59,11 @@ public class Heroes {
|
||||
case "leonidas":
|
||||
appliedBonus = FightStats.terrestre(bonus);
|
||||
if(!off)
|
||||
for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
|
||||
for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
|
||||
break;
|
||||
case "mihalis":
|
||||
appliedBonus = new FightStats(bonus, bonus, 0.0, 0.0);
|
||||
for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
|
||||
for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
|
||||
break;
|
||||
case "medea":
|
||||
appliedBonus = FightStats.terrestre(bonus);
|
||||
@ -103,17 +89,17 @@ public class Heroes {
|
||||
break;
|
||||
case "urephon":
|
||||
appliedBonus = FightStats.terrestre(bonus);
|
||||
for(String uid : g.data.units.keySet())if(g.data.units.get(uid).isMythological())bonuses.put(uid,appliedBonus);
|
||||
for(Unit u : gc.getUnits())if(u.isMythological())bonuses.put(u.getId(),appliedBonus);
|
||||
break;
|
||||
case "zuretha":
|
||||
appliedBonus = new FightStats(0.0, 0.0, 0.0, bonus);
|
||||
for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
|
||||
for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
|
||||
break;
|
||||
default:
|
||||
// No buff
|
||||
break;
|
||||
}
|
||||
return bonuses;
|
||||
return bonuses.keySet().stream().collect(Collectors.toMap(k -> gc.getUnit(k), k -> bonuses.get(k)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,110 +1,72 @@
|
||||
package com.bernard.greposimu.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.Utils;
|
||||
import com.bernard.greposimu.model.game.units.Hero;
|
||||
import com.bernard.greposimu.model.game.units.Unit;
|
||||
|
||||
public class DefContext {
|
||||
|
||||
// unitID -> number of units
|
||||
public Map<String, Integer> units;
|
||||
Map<Unit, Integer> units;
|
||||
|
||||
public String hero;
|
||||
public int heroLevel;
|
||||
Hero hero;
|
||||
int heroLevel;
|
||||
|
||||
public int wallLevel;
|
||||
public boolean hasTower;
|
||||
int wallLevel;
|
||||
boolean hasTower;
|
||||
|
||||
public Set<String> powers;
|
||||
public Set<String> researches;
|
||||
Set<String> powers;
|
||||
Set<String> researches;
|
||||
|
||||
public Set<String> counsellors;
|
||||
Set<String> counsellors;
|
||||
|
||||
public boolean nightBonus;
|
||||
boolean nightBonus;
|
||||
|
||||
public DefContext() {
|
||||
this.units = new HashMap<>();
|
||||
this.hero = null;
|
||||
this.heroLevel = 0;
|
||||
this.wallLevel = 0;
|
||||
this.hasTower = false;
|
||||
this.powers = new HashSet<>();
|
||||
this.researches = new HashSet<>();
|
||||
this.counsellors = new HashSet<>();
|
||||
this.nightBonus = false;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getUnits() {
|
||||
public DefContext(Map<Unit, Integer> units, Hero hero, int heroLevel, int wallLevel, boolean hasTower,
|
||||
Set<String> powers, Set<String> researches, Set<String> counsellors, boolean nightBonus) {
|
||||
this.units = units;
|
||||
this.hero = hero;
|
||||
this.heroLevel = heroLevel;
|
||||
this.wallLevel = wallLevel;
|
||||
this.hasTower = hasTower;
|
||||
this.powers = powers;
|
||||
this.researches = researches;
|
||||
this.counsellors = counsellors;
|
||||
this.nightBonus = nightBonus;
|
||||
}
|
||||
|
||||
public Map<Unit, Integer> getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public String getHero() {
|
||||
public Hero getHero() {
|
||||
return hero;
|
||||
}
|
||||
|
||||
public int getHeroLevel() {
|
||||
return heroLevel;
|
||||
}
|
||||
|
||||
public int getWallLevel() {
|
||||
return wallLevel;
|
||||
}
|
||||
|
||||
public boolean isHasTower() {
|
||||
public boolean hasTower() {
|
||||
return hasTower;
|
||||
}
|
||||
|
||||
public Set<String> getPowers() {
|
||||
return powers;
|
||||
}
|
||||
|
||||
public Set<String> getResearches() {
|
||||
return researches;
|
||||
}
|
||||
|
||||
public Set<String> getCounsellors() {
|
||||
return counsellors;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getPowersAsMap() {
|
||||
return Utils.setToMap(powers);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getResearchesAsMap() {
|
||||
return Utils.setToMap(researches);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getCounsellorsAsMap() {
|
||||
return Utils.setToMap(counsellors);
|
||||
}
|
||||
|
||||
public boolean isNightBonus() {
|
||||
return nightBonus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setHero(String hero) {
|
||||
this.hero = hero;
|
||||
}
|
||||
|
||||
public void setHeroLevel(int heroLevel) {
|
||||
this.heroLevel = heroLevel;
|
||||
}
|
||||
|
||||
public void setWallLevel(int wallLevel) {
|
||||
this.wallLevel = wallLevel;
|
||||
}
|
||||
|
||||
public void setHasTower(boolean hasTower) {
|
||||
this.hasTower = hasTower;
|
||||
}
|
||||
|
||||
public void setNightBonus(boolean nightBonus) {
|
||||
this.nightBonus = nightBonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Building {
|
||||
public String id;
|
||||
public String name;
|
||||
public String controller;
|
||||
public Object image;
|
||||
public String description;
|
||||
public Object level;
|
||||
public int max_level;
|
||||
public int min_level;
|
||||
public Object requiredBuildings;
|
||||
public String coordinates;
|
||||
public Resources resources;
|
||||
public int pop;
|
||||
public double wood_factor;
|
||||
public double stone_factor;
|
||||
public double iron_factor;
|
||||
public double pop_factor;
|
||||
public Object hide_factor;
|
||||
public int points;
|
||||
public double points_factor;
|
||||
public int build_time;
|
||||
public double build_time_factor;
|
||||
public double build_time_reduction;
|
||||
public Object bolt_protected;
|
||||
public List<Integer> image_levels;
|
||||
public Map<String,Integer> dependencies;
|
||||
public Map<Integer,Integer> fixed_building_times;
|
||||
public Map<Integer, LeveledFactor> level_build_time_factors;
|
||||
public boolean special;
|
||||
public Object resourcesFor;
|
||||
public List<Object> resourcesForLevelFixed;
|
||||
public Map<Integer, Double> resourcesForLevelFactor;
|
||||
public List<Object> resourcesForLevelReduceFactor;
|
||||
public List<Object> offset_value_map;
|
||||
public double catapult_factor;
|
||||
public double catapult_power;
|
||||
public double def_factor_per_level;
|
||||
public double storage_factor;
|
||||
public double storage_pow;
|
||||
public double farm_pow;
|
||||
public double farm_factor;
|
||||
public double thermal_pow;
|
||||
|
||||
public static class LeveledFactor {
|
||||
public int level;
|
||||
public double factor;
|
||||
}
|
||||
}
|
||||
177
src/main/java/com/bernard/greposimu/model/game/GameConfig.java
Normal file
177
src/main/java/com/bernard/greposimu/model/game/GameConfig.java
Normal file
@ -0,0 +1,177 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.bernard.greposimu.Utils;
|
||||
import com.bernard.greposimu.model.game.units.FightType;
|
||||
import com.bernard.greposimu.model.game.units.Hero;
|
||||
import com.bernard.greposimu.model.game.units.Hero.HeroCategory;
|
||||
import com.bernard.greposimu.model.game.units.NavalUnit;
|
||||
import com.bernard.greposimu.model.game.units.TerrestrialUnit;
|
||||
import com.bernard.greposimu.model.game.units.TransportUnit;
|
||||
import com.bernard.greposimu.model.game.units.Unit;
|
||||
|
||||
public class GameConfig {
|
||||
|
||||
Set<God> gods;
|
||||
|
||||
// Non-hero units
|
||||
Set<Unit> units;
|
||||
|
||||
Set<Hero> heroes;
|
||||
|
||||
public Set<Unit> getUnits() {
|
||||
return Collections.unmodifiableSet(this.units);
|
||||
}
|
||||
|
||||
public Unit getUnit(String id) {
|
||||
return Utils.getIdentified(this.units, id);
|
||||
}
|
||||
|
||||
public Set<Hero> getHeroes() {
|
||||
return Collections.unmodifiableSet(this.heroes);
|
||||
}
|
||||
public Hero getHero(String id) {
|
||||
return Utils.getIdentified(this.heroes, id);
|
||||
}
|
||||
|
||||
|
||||
public GameConfig(JSONObject json) {
|
||||
JSONObject godsJ = json.getJSONObject("gods");
|
||||
this.gods = new HashSet<>();
|
||||
for(String g : godsJ.keySet()) {
|
||||
JSONObject godJ = godsJ.getJSONObject(g);
|
||||
gods.add(new God(godJ.getString("id"), godJ.getString("name")));
|
||||
}
|
||||
|
||||
JSONObject unitsJ = json.getJSONObject("units");
|
||||
this.units = new HashSet<>();
|
||||
for(String u : unitsJ.keySet()) {
|
||||
JSONObject unit = unitsJ.getJSONObject(u);
|
||||
if(unit.getBoolean("is_naval")) {
|
||||
if(unit.getInt("capacity")>0) {
|
||||
units.add(new TransportUnit(
|
||||
unit.getString("id"),
|
||||
unit.getString("name"),
|
||||
unit.getString("description"),
|
||||
unit.getInt("population"),
|
||||
unit.getInt("speed"),
|
||||
unit.getString("category").equals("mythological_ground") || unit.getString("category").equals("mythological_naval"),
|
||||
unit.isNull("god_id")?null:gods.stream().filter(g -> g.getId().equals(unit.getString("god_id"))).findAny().orElse(null),
|
||||
unit.isNull("resources")?null:new Resources(
|
||||
unit.getJSONObject("resources").getInt("wood"),
|
||||
unit.getJSONObject("resources").getInt("stone"),
|
||||
unit.getJSONObject("resources").getInt("iron")),
|
||||
unit.getInt("favor"),
|
||||
unit.getInt("build_time"),
|
||||
IntStream.range(0, unit.getJSONArray("research_dependencies").length())
|
||||
.mapToObj(i -> unit.getJSONArray("research_dependencies").getString(i))
|
||||
.collect(Collectors.toSet()),
|
||||
unit.isNull("building_dependencies")?Map.of():unit.getJSONObject("building_dependencies").keySet().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), b -> unit.getJSONObject("building_dependencies").getInt(b))),
|
||||
unit.getInt("attack"),
|
||||
unit.getInt("defense"),
|
||||
unit.getInt("capacity")
|
||||
));
|
||||
} else {
|
||||
units.add(new NavalUnit(
|
||||
unit.getString("id"),
|
||||
unit.getString("name"),
|
||||
unit.getString("description"),
|
||||
unit.getInt("population"),
|
||||
unit.getInt("speed"),
|
||||
unit.getString("category").equals("mythological_ground") || unit.getString("category").equals("mythological_naval"),
|
||||
unit.isNull("god_id")?null:gods.stream().filter(g -> g.getId().equals(unit.getString("god_id"))).findAny().orElse(null),
|
||||
unit.isNull("resources")?null:new Resources(
|
||||
unit.getJSONObject("resources").getInt("wood"),
|
||||
unit.getJSONObject("resources").getInt("stone"),
|
||||
unit.getJSONObject("resources").getInt("iron")),
|
||||
unit.getInt("favor"),
|
||||
unit.getInt("build_time"),
|
||||
IntStream.range(0, unit.getJSONArray("research_dependencies").length())
|
||||
.mapToObj(i -> unit.getJSONArray("research_dependencies").getString(i))
|
||||
.collect(Collectors.toSet()),
|
||||
unit.isNull("building_dependencies")?Map.of():unit.getJSONObject("building_dependencies").keySet().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), b -> unit.getJSONObject("building_dependencies").getInt(b))),
|
||||
unit.getInt("attack"),
|
||||
unit.getInt("defense")
|
||||
));
|
||||
}
|
||||
} else {
|
||||
FightType ft = null;
|
||||
switch(unit.getString("attack_type")) {
|
||||
case "pierce": ft = FightType.PIERCE;break;
|
||||
case "hack": ft = FightType.HACK;break;
|
||||
case "distance": ft = FightType.DISTANCE;break;
|
||||
}
|
||||
units.add(new TerrestrialUnit(
|
||||
unit.getString("id"),
|
||||
unit.getString("name"),
|
||||
unit.getString("description"),
|
||||
unit.getInt("population"),
|
||||
unit.getInt("speed"),
|
||||
unit.getString("category").equals("mythological_ground") || unit.getString("category").equals("mythological_naval"),
|
||||
unit.isNull("god_id")?null:gods.stream().filter(g -> g.getId().equals(unit.getString("god_id"))).findAny().orElse(null),
|
||||
unit.isNull("resources")?null:new Resources(
|
||||
unit.getJSONObject("resources").getInt("wood"),
|
||||
unit.getJSONObject("resources").getInt("stone"),
|
||||
unit.getJSONObject("resources").getInt("iron")),
|
||||
unit.getInt("favor"),
|
||||
unit.getInt("build_time"),
|
||||
unit.isNull("research_dependencies")?Set.of():IntStream.range(0, unit.getJSONArray("research_dependencies").length())
|
||||
.mapToObj(i -> unit.getJSONArray("research_dependencies").getString(i))
|
||||
.collect(Collectors.toSet()),
|
||||
unit.isNull("building_dependencies")?Map.of():unit.getJSONObject("building_dependencies").keySet().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), b -> unit.getJSONObject("building_dependencies").getInt(b))),
|
||||
unit.getInt("attack"),
|
||||
ft,
|
||||
unit.getInt("def_pierce"),
|
||||
unit.getInt("def_hack"),
|
||||
unit.getInt("def_distance"),
|
||||
(unit.has("booty"))?unit.getInt("booty"):0,
|
||||
unit.getJSONArray("special_abilities").toList().stream().filter(o -> o.equals("flying")).findAny().isPresent()
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JSONObject heroesJ = json.getJSONObject("heroes");
|
||||
this.heroes = new HashSet<>();
|
||||
for(String h : heroesJ.keySet()) {
|
||||
JSONObject hero = heroesJ.getJSONObject(h);
|
||||
FightType ft = null;
|
||||
switch(hero.getString("attack_type")) {
|
||||
case "pierce": ft = FightType.PIERCE;break;
|
||||
case "hack": ft = FightType.HACK;break;
|
||||
case "distance": ft = FightType.DISTANCE;break;
|
||||
}
|
||||
JSONObject descargs = hero.getJSONObject("description_args").getJSONObject("1");
|
||||
this.heroes.add(new Hero(
|
||||
hero.getString("id"),
|
||||
hero.getString("name"),
|
||||
hero.getString("description"),
|
||||
hero.getInt("speed"),
|
||||
hero.getInt("attack"),
|
||||
ft,
|
||||
hero.getInt("def_pierce"),
|
||||
hero.getInt("def_hack"),
|
||||
hero.getInt("def_distance"),
|
||||
hero.getInt("booty"),
|
||||
hero.getString("category").equals("war")?HeroCategory.WAR:HeroCategory.WISDOM,
|
||||
hero.getInt("cost"),
|
||||
hero.getString("short_description"),
|
||||
descargs.getDouble("value"),
|
||||
descargs.getDouble("level_mod")
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class GameData {
|
||||
|
||||
public Map<String,Unit> units;
|
||||
|
||||
public Map<String, ? extends JsonPower> powers;
|
||||
|
||||
public Map<String, God> gods;
|
||||
|
||||
public Map<String, Hero> heroes;
|
||||
|
||||
public Map<String, Research> researches;
|
||||
|
||||
public Map<String, Building> buildings;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(FlowStyle.BLOCK);
|
||||
options.setPrettyFlow(true);
|
||||
Yaml yaml = new Yaml(options);
|
||||
StringWriter writer = new StringWriter();
|
||||
yaml.dump(this, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,22 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.List;
|
||||
public class God implements Identified{
|
||||
|
||||
public class God {
|
||||
public String name;
|
||||
public String id;
|
||||
public List<Unit> units;
|
||||
public List<String> powers;
|
||||
public String topic;
|
||||
public String description;
|
||||
String id;
|
||||
String name;
|
||||
|
||||
public God(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Hero {
|
||||
public String id;
|
||||
public String category;
|
||||
public String name;
|
||||
public String description;
|
||||
public Map<String,DescriptionArgs> description_args;
|
||||
public String short_description;
|
||||
public int default_level;
|
||||
public int cost;
|
||||
public List<Object> award_requirements;
|
||||
public boolean is_naval;
|
||||
public boolean exclusive;
|
||||
public boolean hidden;
|
||||
public String attack_type;
|
||||
public int attack;
|
||||
public int def_hack;
|
||||
public int def_pierce;
|
||||
public int def_distance;
|
||||
public int speed;
|
||||
public int booty;
|
||||
public List<Object> preconditions;
|
||||
public int max_per_attack;
|
||||
public int max_per_support;
|
||||
|
||||
public static class DescriptionArgs {
|
||||
public double value;
|
||||
public double level_mod;
|
||||
public String unit;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
public interface Identified {
|
||||
|
||||
public String getId();
|
||||
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
public class Image {
|
||||
public String mini;
|
||||
public String small;
|
||||
public String medium;
|
||||
public String large;
|
||||
}
|
||||
@ -1,115 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class JsonPower {
|
||||
public Object effect;
|
||||
public Object name;
|
||||
public Object description;
|
||||
public int lifetime;
|
||||
public String id;
|
||||
public String short_effect;
|
||||
public int favor;
|
||||
public int fury_percentage_cost;
|
||||
public String god_id;
|
||||
public BigInteger temple_level_sum_dependency;
|
||||
public List<String> targets;
|
||||
public boolean only_own_towns;
|
||||
public boolean boost;
|
||||
public boolean is_fake_power;
|
||||
public List<String> area_of_effect;
|
||||
public boolean destructive;
|
||||
public boolean negative;
|
||||
public boolean extendible;
|
||||
public String power_group;
|
||||
public int power_group_level;
|
||||
public List<String> seeds_to;
|
||||
public Image images;
|
||||
public List<String> effects;
|
||||
public boolean is_valid_for_happenings;
|
||||
public List<String> meta_fields;
|
||||
public Object meta_defaults;
|
||||
public boolean removed_on_target_loss;
|
||||
public boolean needs_level;
|
||||
public boolean requires_god;
|
||||
public boolean ignores_democritus;
|
||||
public boolean display_amount;
|
||||
public boolean wasteable;
|
||||
public boolean is_ritual;
|
||||
public boolean recreate_on_restart;
|
||||
public boolean transfer_to_casual_world;
|
||||
public boolean is_onetime_power;
|
||||
public boolean is_upgradable;
|
||||
public boolean is_capped;
|
||||
public List<String> compatible_powers;
|
||||
public boolean no_lifetime;
|
||||
public boolean passive;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<String> getTypes() {
|
||||
Set<String> types = new HashSet<>();
|
||||
if(name instanceof Map) {
|
||||
if(((Map<String,Map<String,String>>)name).containsKey("type"))
|
||||
types.addAll(((Map<String,Map<String,String>>)name).get("type").keySet());
|
||||
else
|
||||
name = ((Map<String,Map<String,String>>)name).get("god").get("athena");
|
||||
}
|
||||
if(description instanceof Map)
|
||||
types.addAll(((Map<String,Map<String,String>>)description).get("type").keySet());
|
||||
if(effect instanceof Map)
|
||||
types.addAll(((Map<String,Map<String,String>>)effect).get("type").keySet());
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JsonPower [effect=" + effect + ", lifetime=" + lifetime + ", id=" + id + ", name=" + name
|
||||
+ ", description=" + description + ", short_effect=" + short_effect + ", favor=" + favor
|
||||
+ ", fury_percentage_cost=" + fury_percentage_cost + ", god_id=" + god_id
|
||||
+ ", temple_level_sum_dependency=" + temple_level_sum_dependency + ", targets=" + targets
|
||||
+ ", only_own_towns=" + only_own_towns + ", boost=" + boost + ", is_fake_power=" + is_fake_power
|
||||
+ ", area_of_effect=" + area_of_effect + ", destructive=" + destructive + ", negative=" + negative
|
||||
+ ", extendible=" + extendible + ", power_group=" + power_group + ", power_group_level="
|
||||
+ power_group_level + ", seeds_to=" + seeds_to + ", images=" + images + ", effects=" + effects
|
||||
+ ", is_valid_for_happenings=" + is_valid_for_happenings + ", meta_fields=" + meta_fields
|
||||
+ ", meta_defaults=" + meta_defaults + ", removed_on_target_loss=" + removed_on_target_loss
|
||||
+ ", needs_level=" + needs_level + ", requires_god=" + requires_god + ", ignores_democritus="
|
||||
+ ignores_democritus + ", display_amount=" + display_amount + ", wasteable=" + wasteable
|
||||
+ ", is_ritual=" + is_ritual + ", recreate_on_restart=" + recreate_on_restart
|
||||
+ ", transfer_to_casual_world=" + transfer_to_casual_world + ", is_onetime_power=" + is_onetime_power
|
||||
+ ", is_upgradable=" + is_upgradable + ", is_capped=" + is_capped + ", compatible_powers="
|
||||
+ compatible_powers + ", no_lifetime=" + no_lifetime + ", passive=" + passive + "]";
|
||||
}
|
||||
|
||||
public Object getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public void setEffect(Object effect) {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public Object getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Object name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Object getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(Object description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,126 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Power extends JsonPower {
|
||||
public String effect;
|
||||
public String name;
|
||||
public String description;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Power(JsonPower power, String type) {
|
||||
this.effect = (power.effect instanceof String)?(String)power.effect:((Map<String,Map<String,String>>)power.effect).get("type").get(type);
|
||||
this.lifetime = power.lifetime;
|
||||
this.id = power.id+"."+type;
|
||||
this.name = (power.name instanceof String)?(String)power.name:((Map<String,Map<String,String>>)power.name).get("type").get(type);
|
||||
this.description = (power.description instanceof String)?(String)power.description:((Map<String,Map<String,String>>)power.description).get("type").get(type);
|
||||
this.short_effect = power.short_effect;
|
||||
this.favor = power.favor;
|
||||
this.fury_percentage_cost = power.fury_percentage_cost;
|
||||
this.god_id = power.god_id;
|
||||
this.temple_level_sum_dependency = power.temple_level_sum_dependency;
|
||||
this.targets = power.targets;
|
||||
this.only_own_towns = power.only_own_towns;
|
||||
this.boost = power.boost;
|
||||
this.is_fake_power = power.is_fake_power;
|
||||
this.area_of_effect = power.area_of_effect;
|
||||
this.destructive = power.destructive;
|
||||
this.negative = power.negative;
|
||||
this.extendible = power.extendible;
|
||||
this.power_group = power.power_group;
|
||||
this.power_group_level = power.power_group_level;
|
||||
this.seeds_to = power.seeds_to;
|
||||
this.images = power.images;
|
||||
this.effects = power.effects;
|
||||
this.is_valid_for_happenings = power.is_valid_for_happenings;
|
||||
this.meta_fields = power.meta_fields;
|
||||
this.meta_defaults = power.meta_defaults;
|
||||
this.removed_on_target_loss = power.removed_on_target_loss;
|
||||
this.needs_level = power.needs_level;
|
||||
this.requires_god = power.requires_god;
|
||||
this.ignores_democritus = power.ignores_democritus;
|
||||
this.display_amount = power.display_amount;
|
||||
this.wasteable = power.wasteable;
|
||||
this.is_ritual = power.is_ritual;
|
||||
this.recreate_on_restart = power.recreate_on_restart;
|
||||
this.transfer_to_casual_world = power.transfer_to_casual_world;
|
||||
this.is_onetime_power = power.is_onetime_power;
|
||||
this.is_upgradable = power.is_upgradable;
|
||||
this.is_capped = power.is_capped;
|
||||
this.compatible_powers = power.compatible_powers;
|
||||
this.no_lifetime = power.no_lifetime;
|
||||
this.passive = power.passive;
|
||||
}
|
||||
public Power(JsonPower power) {
|
||||
this.effect = (String) power.effect;
|
||||
this.lifetime = power.lifetime;
|
||||
this.id = power.id;
|
||||
this.name = (String) power.name;
|
||||
this.description = (String) power.description;
|
||||
this.short_effect = power.short_effect;
|
||||
this.favor = power.favor;
|
||||
this.fury_percentage_cost = power.fury_percentage_cost;
|
||||
this.god_id = power.god_id;
|
||||
this.temple_level_sum_dependency = power.temple_level_sum_dependency;
|
||||
this.targets = power.targets;
|
||||
this.only_own_towns = power.only_own_towns;
|
||||
this.boost = power.boost;
|
||||
this.is_fake_power = power.is_fake_power;
|
||||
this.area_of_effect = power.area_of_effect;
|
||||
this.destructive = power.destructive;
|
||||
this.negative = power.negative;
|
||||
this.extendible = power.extendible;
|
||||
this.power_group = power.power_group;
|
||||
this.power_group_level = power.power_group_level;
|
||||
this.seeds_to = power.seeds_to;
|
||||
this.images = power.images;
|
||||
this.effects = power.effects;
|
||||
this.is_valid_for_happenings = power.is_valid_for_happenings;
|
||||
this.meta_fields = power.meta_fields;
|
||||
this.meta_defaults = power.meta_defaults;
|
||||
this.removed_on_target_loss = power.removed_on_target_loss;
|
||||
this.needs_level = power.needs_level;
|
||||
this.requires_god = power.requires_god;
|
||||
this.ignores_democritus = power.ignores_democritus;
|
||||
this.display_amount = power.display_amount;
|
||||
this.wasteable = power.wasteable;
|
||||
this.is_ritual = power.is_ritual;
|
||||
this.recreate_on_restart = power.recreate_on_restart;
|
||||
this.transfer_to_casual_world = power.transfer_to_casual_world;
|
||||
this.is_onetime_power = power.is_onetime_power;
|
||||
this.is_upgradable = power.is_upgradable;
|
||||
this.is_capped = power.is_capped;
|
||||
this.compatible_powers = power.compatible_powers;
|
||||
this.no_lifetime = power.no_lifetime;
|
||||
this.passive = power.passive;
|
||||
}
|
||||
|
||||
|
||||
public String getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public void setEffect(String effect) {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Research {
|
||||
public String id;
|
||||
public String name;
|
||||
public String description;
|
||||
public List<Object> research_dependencies;
|
||||
public Map<String,Integer> building_dependencies;
|
||||
public Resources resources;
|
||||
public int required_time;
|
||||
public int research_points;
|
||||
}
|
||||
@ -1,7 +1,27 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
public class Resources {
|
||||
public int wood;
|
||||
public int stone;
|
||||
public int iron;
|
||||
|
||||
int wood;
|
||||
int stone;
|
||||
int iron;
|
||||
|
||||
public Resources(int wood, int stone, int iron) {
|
||||
this.wood = wood;
|
||||
this.stone = stone;
|
||||
this.iron = iron;
|
||||
}
|
||||
|
||||
public int getWood() {
|
||||
return wood;
|
||||
}
|
||||
|
||||
public int getStone() {
|
||||
return stone;
|
||||
}
|
||||
|
||||
public int getIron() {
|
||||
return iron;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
package com.bernard.greposimu.model.game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.bernard.greposimu.model.FightStats;
|
||||
|
||||
public class Unit {
|
||||
|
||||
public String id;
|
||||
public String name;
|
||||
public String name_plural;
|
||||
public int speed;
|
||||
public int attack;
|
||||
public String description;
|
||||
public Resources resources;
|
||||
public int favor;
|
||||
public int population;
|
||||
public int build_time;
|
||||
public String god_id;
|
||||
public List<String> research_dependencies;
|
||||
public Map<String, Integer> building_dependencies;
|
||||
public boolean is_naval;
|
||||
public int max_per_attack;
|
||||
public int max_per_support;
|
||||
public String unit_function;
|
||||
public String category;
|
||||
public List<Object> special_abilities;
|
||||
public String passive;
|
||||
public boolean is_npc_unit_only;
|
||||
public int def_hack;
|
||||
public int def_pierce;
|
||||
public int def_distance;
|
||||
public int booty;
|
||||
public Object infantry;
|
||||
public boolean flying;
|
||||
public String attack_type;
|
||||
|
||||
// Naval
|
||||
public int defense;
|
||||
public boolean transport;
|
||||
public int capacity;
|
||||
|
||||
public FightStats getDefStats() {
|
||||
return new FightStats(def_hack, def_pierce, def_distance, defense);
|
||||
}
|
||||
public FightStats getAttStats() {
|
||||
switch(attack_type) {
|
||||
case "hack":
|
||||
return new FightStats(attack, 0.0, 0.0, 0.0);
|
||||
case "pierce":
|
||||
return new FightStats(0.0, attack, 0.0, 0.0);
|
||||
case "distance":
|
||||
return new FightStats(0.0, 0.0, attack, 0.0);
|
||||
}
|
||||
if(is_naval)
|
||||
return new FightStats(0.0, 0.0, 0.0, attack);
|
||||
throw new IllegalStateException("This unit has no known attack type, and is not a ship");
|
||||
}
|
||||
|
||||
public boolean isMythological() {
|
||||
return category.equals("mythological_ground") || category.equals("mythological_naval");
|
||||
}
|
||||
public boolean isGround() {
|
||||
return category.equals("regular_ground") || category.equals("mythological_ground");
|
||||
}
|
||||
public boolean isNaval() {
|
||||
return category.equals("regular_naval") || category.equals("mythological_naval");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.bernard.greposimu.model.game.units;
|
||||
|
||||
public enum FightType {
|
||||
PIERCE,HACK,DISTANCE;
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.bernard.greposimu.model.game.units;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.model.game.God;
|
||||
import com.bernard.greposimu.model.game.Identified;
|
||||
import com.bernard.greposimu.model.game.Resources;
|
||||
|
||||
public class Hero extends TerrestrialUnit{
|
||||
|
||||
// Zero population
|
||||
// Non mythological
|
||||
// No building cost/time
|
||||
// no research/building dependencies
|
||||
// No flight
|
||||
// Terrestrial
|
||||
public Hero(String id, String name, String description, int speed,
|
||||
int attack, FightType attackType, int pierceDef, int hackDef,
|
||||
int distanceDef, int booty, HeroCategory category, int cost, String shortDescription, double powerBaseValue, double powerValuePerLevel) {
|
||||
super(id, name, description, 0, speed, false, null, null, 0, 0,
|
||||
Set.of(), Map.of(), attack, attackType, pierceDef, hackDef, distanceDef, booty, false);
|
||||
this.category = category;
|
||||
this.cost = cost;
|
||||
this.shortDescription = shortDescription;
|
||||
this.powerBaseValue = powerBaseValue;
|
||||
this.powerValuePerLevel = powerValuePerLevel;
|
||||
}
|
||||
|
||||
|
||||
HeroCategory category;
|
||||
int cost;
|
||||
|
||||
String shortDescription;
|
||||
|
||||
double powerBaseValue;
|
||||
double powerValuePerLevel;
|
||||
|
||||
|
||||
public static enum HeroCategory implements Identified{
|
||||
WAR("war"),WISDOM("wisdom");
|
||||
String id;
|
||||
|
||||
HeroCategory(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public HeroCategory getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
|
||||
public double getPowerBaseValue() {
|
||||
return powerBaseValue;
|
||||
}
|
||||
|
||||
|
||||
public double getPowerValuePerLevel() {
|
||||
return powerValuePerLevel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.bernard.greposimu.model.game.units;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.model.game.God;
|
||||
import com.bernard.greposimu.model.game.Resources;
|
||||
|
||||
public class NavalUnit extends Unit {
|
||||
|
||||
int attack;
|
||||
int defense;
|
||||
|
||||
public NavalUnit(String id, String name, String description, int population, int speed, boolean mythological, God god,
|
||||
Resources buildCost, int favorCost, int buildTime, Set<String> research_dependencies,
|
||||
Map<String, Integer> building_dependencies,int attack, int defense) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.population = population;
|
||||
this.speed = speed;
|
||||
this.mythological = mythological;
|
||||
this.god = god;
|
||||
this.buildCost = buildCost;
|
||||
this.favorCost = favorCost;
|
||||
this.buildTime = buildTime;
|
||||
this.research_dependencies = research_dependencies;
|
||||
this.building_dependencies = building_dependencies;
|
||||
this.attack = attack;
|
||||
this.defense = defense;
|
||||
}
|
||||
|
||||
public int getAttack() {
|
||||
return attack;
|
||||
}
|
||||
|
||||
public int getDefense() {
|
||||
return defense;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGround() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.bernard.greposimu.model.game.units;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.model.game.God;
|
||||
import com.bernard.greposimu.model.game.Resources;
|
||||
|
||||
public class TerrestrialUnit extends Unit{
|
||||
|
||||
int attack;
|
||||
FightType attackType;
|
||||
|
||||
int pierceDef;
|
||||
int hackDef;
|
||||
int distanceDef;
|
||||
int booty;
|
||||
|
||||
boolean flight;
|
||||
|
||||
public TerrestrialUnit(String id, String name, String description, int population, int speed, boolean mythological, God god,
|
||||
Resources buildCost, int favorCost, int buildTime, Set<String> research_dependencies,
|
||||
Map<String, Integer> building_dependencies,int attack, FightType attackType, int pierceDef, int hackDef, int distanceDef, int booty,
|
||||
boolean flight) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.population = population;
|
||||
this.speed = speed;
|
||||
this.mythological = mythological;
|
||||
this.god = god;
|
||||
this.buildCost = buildCost;
|
||||
this.favorCost = favorCost;
|
||||
this.buildTime = buildTime;
|
||||
this.research_dependencies = research_dependencies;
|
||||
this.building_dependencies = building_dependencies;
|
||||
this.attack = attack;
|
||||
this.attackType = attackType;
|
||||
this.pierceDef = pierceDef;
|
||||
this.hackDef = hackDef;
|
||||
this.distanceDef = distanceDef;
|
||||
this.booty = booty;
|
||||
this.flight = flight;
|
||||
}
|
||||
|
||||
public int getAttack() {
|
||||
return attack;
|
||||
}
|
||||
|
||||
public FightType getAttackType() {
|
||||
return attackType;
|
||||
}
|
||||
|
||||
public int getPierceDef() {
|
||||
return pierceDef;
|
||||
}
|
||||
|
||||
public int getHackDef() {
|
||||
return hackDef;
|
||||
}
|
||||
|
||||
public int getDistanceDef() {
|
||||
return distanceDef;
|
||||
}
|
||||
|
||||
public int getBooty() {
|
||||
return booty;
|
||||
}
|
||||
|
||||
public boolean isFlight() {
|
||||
return flight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGround() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.bernard.greposimu.model.game.units;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.model.game.God;
|
||||
import com.bernard.greposimu.model.game.Resources;
|
||||
|
||||
public class TransportUnit extends NavalUnit {
|
||||
int capacity;
|
||||
|
||||
public TransportUnit(String id, String name, String description, int population, int speed, boolean mythological,
|
||||
God god, Resources buildCost, int favorCost, int buildTime, Set<String> research_dependencies,
|
||||
Map<String, Integer> building_dependencies, int attack, int defense, int capacity) {
|
||||
super(id, name, description, population, speed, mythological, god, buildCost, favorCost, buildTime,
|
||||
research_dependencies, building_dependencies, attack, defense);
|
||||
this.capacity = capacity;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
package com.bernard.greposimu.model.game.units;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.bernard.greposimu.model.game.God;
|
||||
import com.bernard.greposimu.model.game.Identified;
|
||||
import com.bernard.greposimu.model.game.Resources;
|
||||
|
||||
public abstract class Unit implements Identified{
|
||||
|
||||
String id;
|
||||
|
||||
String name;
|
||||
String description;
|
||||
int population;
|
||||
int speed;
|
||||
|
||||
boolean mythological;
|
||||
|
||||
God god;
|
||||
Resources buildCost;
|
||||
int favorCost;
|
||||
int buildTime;
|
||||
|
||||
Set<String> research_dependencies;
|
||||
Map<String, Integer> building_dependencies;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public int getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMythological() {
|
||||
return mythological;
|
||||
}
|
||||
|
||||
|
||||
public God getGod() {
|
||||
return god;
|
||||
}
|
||||
|
||||
|
||||
public Resources getBuildCost() {
|
||||
return buildCost;
|
||||
}
|
||||
|
||||
|
||||
public int getFavorCost() {
|
||||
return favorCost;
|
||||
}
|
||||
|
||||
|
||||
public int getBuildTime() {
|
||||
return buildTime;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getResearch_dependencies() {
|
||||
return research_dependencies;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Integer> getBuilding_dependencies() {
|
||||
return building_dependencies;
|
||||
}
|
||||
|
||||
public abstract boolean isGround();
|
||||
|
||||
public boolean isNaval() {
|
||||
return !this.isGround();
|
||||
}
|
||||
|
||||
}
|
||||
@ -91,7 +91,7 @@ span.fixed50px {
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form action="#" th:object="${defCtx}" method="post" id="simuform" >
|
||||
<form action="#" th:object="${ctx}" method="post" id="simuform" >
|
||||
|
||||
<fieldset id="herosFields">
|
||||
<legend>Héros</legend>
|
||||
|
||||
@ -10,8 +10,7 @@ class GrepoSimuApplicationTests {
|
||||
|
||||
@Test
|
||||
void loadGameData() throws IOException {
|
||||
// System.out.println("Reading game data");
|
||||
// System.out.println(GrepoSimu.readGameData());
|
||||
System.out.println(GrepoSimu.makeGameData());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user