Commit 4b5ef7fe authored by Eike Schaubeck's avatar Eike Schaubeck
Browse files

added squat arena to player. added same filters to guild

Took 1 hour 33 minutes
parent 6b734f20
......@@ -4,6 +4,7 @@ import mods.Mod;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class Char {
......@@ -124,8 +125,25 @@ public class Char {
return placedGear;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Char aChar = (Char) o;
return Objects.equals(name, aChar.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
@Override
public String toString() {
return stars + "* " + name + ", Level: " + level + ", Gear: " + gear;
}
public String toStringWithMods() {
return stars + "* " + name + ", Level: " + level + ", Gear: " + gear + "\n" + mods;
}
}
......@@ -4,9 +4,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import help.swgoh.api.SwgohAPI;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.concurrent.ExecutionException;
public class Guild {
......@@ -39,4 +37,89 @@ public class Guild {
public Guild(List<Player> players) {
this.players = players;
}
public int countChar(String name) {
int counter = 0;
for (Player p : players) {
for (Char c : p.getCharacters()) {
if (c.getName().toLowerCase().contains(name)) counter++;
}
}
return counter;
}
public int countChar(Char c) {
int counter = 0;
for (Player p : players) {
for (Char c2 : p.getCharacters()) {
if (c.getName().toLowerCase().contains(c.getName().toLowerCase())) counter++;
}
}
return counter;
}
public int countCharAbouveGear(String name, int minGear) {
int counter = 0;
for (Player p : players) {
for (Char c : p.getCharacters()) {
if (c.getName().toLowerCase().contains(name) && c.getGear() >= minGear) counter++;
}
}
return counter;
}
public Map<Player, Char> getPlayersWithCharAbouveGear(String name, int minGear) {
Map<Player, Char> map = new HashMap<>();
for (Player p : players) {
for (Char c : p.getCharacters()) {
if (c.getName().toLowerCase().contains(name) && c.getGear() >= minGear) {
map.put(p, c);
}
}
}
return map;
}
public Map<Player, Char> getPlayersWithCharAbouveStar(String name, int minStars) {
Map<Player, Char> map = new HashMap<>();
for (Player p : players) {
for (Char c : p.getCharacters()) {
if (c.getName().toLowerCase().contains(name) && c.getStars() >= minStars) {
map.put(p, c);
}
}
}
return map;
}
public Map<Player, Char> getPlayersWithCharAbouveStarAndGear(String name, int minStars, int minGear) {
Map<Player, Char> map = new HashMap<>();
for (Player p : players) {
for (Char c : p.getCharacters()) {
if (c.getName().toLowerCase().contains(name) && c.getStars() >= minStars && c.getGear() >= minGear) {
map.put(p, c);
}
}
}
return map;
}
public Map<String, Integer> countCharsAbouveStarAndGear(SwgohAPI api, int minStars, int minGear) throws ExecutionException, InterruptedException {
Map<String, Integer> map = new HashMap<>();
List<String> names = Player.getAllCharNames(api);
for (String name : names) {
int counter = 0;
for (Player p : players) {
for (Char c : p.getCharacters()) {
if (c.getName().equals(name) && c.getGear() >= minGear && c.getStars() >= minStars) {
counter++;
break;
}
}
}
map.put(name.substring(5, name.length()-5), counter);
}
return map;
}
}
import help.swgoh.api.SwgohAPI;
import help.swgoh.api.SwgohAPIBuilder;
import java.util.*;
import java.util.concurrent.ExecutionException;
public class Main {
......@@ -10,14 +11,54 @@ public class Main {
SwgohAPI api = new SwgohAPIBuilder().withUsername(ApiAccess.getApiUsername())
.withPassword(ApiAccess.getApiPassword()).build();
List<String> names = Player.getAllCharNames(api);
Guild g = Guild.getGuild(589477137, api);
//Player p = Player.getPlayer(api, 589477137);
//Player p2 = Player.getPlayer(api, 692526929);
//Player p2 = Player.getPlayer(api, 979382945);
Scanner sc = new Scanner(System.in);
/*while (true) {
System.out.println("Which Char?");
String name = sc.nextLine();
System.out.println("Which min gear level?");
int gear = Integer.parseInt(sc.nextLine());
System.out.println("Which min stars?");
int stars = Integer.parseInt(sc.nextLine());
Map<Player, Char> map = g.getPlayersWithCharAbouveStarAndGear(name, stars, gear);
for (Player p : map.keySet()) {
String out = p.getName();
Char c = map.get(p);
out += " -> " + c.toString();
System.out.println(out);
}
}
*/
System.out.println(g.players.get(0));
while (true) {
System.out.println("Which min gear level?");
int gear = Integer.parseInt(sc.nextLine());
System.out.println("Which min stars?");
int stars = Integer.parseInt(sc.nextLine());
Map<String, Integer> map = g.countCharsAbouveStarAndGear(api, stars, gear);
Object[] a = map.entrySet().toArray();
Arrays.sort(a, new Comparator() {
public int compare(Object o1, Object o2) {
return ((Map.Entry<String, Integer>) o2).getValue()
.compareTo(((Map.Entry<String, Integer>) o1).getValue());
}
});
for (Object e : a) {
System.out.println(((Map.Entry<String, Integer>) e).getKey() + " : "
+ ((Map.Entry<String, Integer>) e).getValue());
}
}
}
}
......@@ -17,6 +17,16 @@ public class Player {
private List<Char> characters;
private List<Ship> ships;
private Squat arenaSquat;
private Fleet arenaFleet;
public static List<String> getAllCharNames(SwgohAPI api) throws ExecutionException, InterruptedException {
Player topPlayer = getPlayer(api, 979382945);
List<String> names = new LinkedList<>();
for (Char c : topPlayer.getCharacters()) {
names.add(c.getName());
}
return names;
}
public static Player getPlayer(SwgohAPI api, int allyCode) throws ExecutionException, InterruptedException {
JsonParser parser = new JsonParser();
......@@ -41,7 +51,7 @@ public class Player {
ships.add(Ship.getShipFromJsonObject(jChar));
}
}
return sortCharsandShips(ally, name, guild, level, grandArenaLifeTimePoints, roster, ships);
return sortCharsandShips(ally, name, guild, level, grandArenaLifeTimePoints, roster, ships, null);
}
public static Player getPlayerFromJsonObject(JsonObject json) {
......@@ -63,13 +73,13 @@ public class Player {
}
}
List<Char> arenaSquatChars = new LinkedList<>();
JsonObject squat = ((JsonObject) ((JsonObject) json.get("arena")).get("char"));
//TODO get arena squat and arena fleet
return sortCharsandShips(ally, name, guild, level, grandArenaLifeTimePoints, roster, ships);
Squat squat = Squat.getSquatFromJsonObject ((JsonObject) ((JsonObject) json.get("arena")).get("char"), roster);
//TODO get arena fleet
return sortCharsandShips(ally, name, guild, level, grandArenaLifeTimePoints, roster, ships, squat);
}
private static Player sortCharsandShips(int ally, String name, String guild, int level, int grandArenaLifeTimePoints, List<Char> roster, List<Ship> ships) {
private static Player sortCharsandShips(int ally, String name, String guild, int level, int grandArenaLifeTimePoints,
List<Char> roster, List<Ship> ships, Squat squat) {
roster.sort(Comparator.comparing(Char::getGalacticPower).reversed());
List<Char> galacticLegends = new LinkedList<>();
for (Char c : roster) {
......@@ -77,6 +87,7 @@ public class Player {
galacticLegends.add(c);
}
}
//make sure, that galactic legends are on top
for (Char c : galacticLegends) {
roster.remove(c);
}
......@@ -85,7 +96,7 @@ public class Player {
roster.add(0, c);
}
ships.sort(Comparator.comparing(Ship::getGp).reversed());
return new Player(ally, level, grandArenaLifeTimePoints, name, guild, roster, ships);
return new Player(ally, level, grandArenaLifeTimePoints, name, guild, roster, ships, squat, null);
}
public Player(int allyCode, int level, int grandArenaLifeTimePoints, String name, String guildName, List<Char> characters, List<Ship> ships) {
......@@ -98,6 +109,19 @@ public class Player {
this.ships = ships;
}
public Player(int allyCode, int level, int grandArenaLifeTimePoints, String name, String guildName,
List<Char> characters, List<Ship> ships, Squat arenaSquat, Fleet arenaFleet) {
this.allyCode = allyCode;
this.level = level;
this.grandArenaLifeTimePoints = grandArenaLifeTimePoints;
this.name = name;
this.guildName = guildName;
this.characters = characters;
this.ships = ships;
this.arenaSquat = arenaSquat;
this.arenaFleet = arenaFleet;
}
public int getAllyCode() {
return allyCode;
}
......@@ -154,6 +178,22 @@ public class Player {
this.ships = ships;
}
public Squat getArenaSquat() {
return arenaSquat;
}
public void setArenaSquat(Squat arenaSquat) {
this.arenaSquat = arenaSquat;
}
public Fleet getArenaFleet() {
return arenaFleet;
}
public void setArenaFleet(Fleet arenaFleet) {
this.arenaFleet = arenaFleet;
}
@Override
public String toString() {
return name + ", Level: " + level + ", Charaktere: " + characters.size() + ", Schiffe: " + ships.size();
......
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.graalvm.compiler.api.replacements.Snippet;
import java.util.LinkedList;
......@@ -7,18 +10,50 @@ public class Squat {
private Char leader;
private List<Char> chars;
private int gp;
private int gp, rank;
//TODO arena rank
public Squat(Char leader, List<Char> chars, int gp) {
public Squat() {
}
public Squat(Char leader, List<Char> chars) {
this.leader = leader;
this.chars = chars;
this.gp = gp;
}
public Squat(Char leader, List<Char> chars) {
public Squat(Char leader, List<Char> chars, int rank) {
this.leader = leader;
this.chars = chars;
this.rank = rank;
}
public static Squat getSquatFromJsonObject(JsonObject json, List<Char> roster) {
List<Char> arenaSquatChars = new LinkedList<>();
JsonArray a = json.get("squad").getAsJsonArray();
Squat squat = new Squat();
for (JsonElement element : a) {
JsonObject object = (JsonObject) element;
if (object.get("squadUnitType").getAsString().equals("2")) {
String arenaName = object.get("defId").getAsString().toLowerCase();
for (Char c : roster) {
if (c.getName().toLowerCase().contains(arenaName)) {
squat.setLeader(c);
break;
}
}
} else {
String arenaName = object.get("defId").getAsString().toLowerCase();
for (Char c : roster) {
if (c.getName().toLowerCase().contains(arenaName)) {
arenaSquatChars.add(c);
break;
}
}
}
squat.setChars(arenaSquatChars);
}
return squat;
}
public List<Char> getChars() {
......@@ -45,6 +80,14 @@ public class Squat {
this.leader = leader;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
public String getFullInfos() {
StringBuilder result = new StringBuilder("GP : " + gp + "\n" + "Leader: " + leader + "\n");
for (Char c : chars) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment