use of com.janfic.games.computercombat.model.Ability in project computercombat by janfic.
the class MultiAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
for (int i = 0; i < abilities.size(); i++) {
Ability ability = abilities.get(i);
List<MoveResult> abilityResults = ability.doAbility(state, move);
if (i != 0) {
for (MoveResult abilityResult : abilityResults) {
int index = -1;
for (MoveAnimation animation : abilityResult.getAnimations()) {
if (animation instanceof ConsumeProgressAnimation) {
index = abilityResult.getAnimations().indexOf(animation);
break;
}
}
if (index >= 0) {
abilityResult.getAnimations().remove(index);
}
}
}
results.addAll(abilityResults);
if (i < abilities.size() - 1) {
for (Player player : state.players) {
if (player.getUID().equals(move.getPlayerUID())) {
state.currentPlayerMove = player.getUID();
}
}
}
}
return results;
}
use of com.janfic.games.computercombat.model.Ability in project computercombat by janfic.
the class SQLAPI method getPlayerOwnedCards.
public Map<Card, Integer> getPlayerOwnedCards(String uid) {
System.out.println("[SERVER][MYSQL]: Querying for Player collection");
Map<Card, Integer> cards = new HashMap<>();
try {
// Get all player owned cards
String sql = "SELECT * FROM card \n" + "JOIN profile_owns_card ON card.id = profile_owns_card.card_id \n" + "JOIN profile ON profile.uid = profile_owns_card.profile_id \n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN run_requirements ON card.id = run_requirements.card_id\n" + "JOIN components ON components.id = run_requirements.component_id\n" + "JOIN collection ON card.collection_id = collection.id\n" + "WHERE profile.uid = '" + uid + "' ORDER BY card.id;";
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(sql);
boolean next = set.next();
while (next) {
int currentID = set.getInt("card.id");
Ability a = (Ability) shell.evaluate(set.getString("ability.code"));
a.setInformation(set.getString("ability.description"), set.getString("ability.textureName"), set.getString("ability.name"), set.getString("ability.code"), set.getInt("ability.id"));
Collection c = new Collection(set.getInt("collection.id"), set.getString("collection.name"), set.getString("collection.description"), set.getString("collection.textureName"), set.getString("collection.path"), set.getInt("collection.price"));
List<Integer> components = new ArrayList<>();
int id = set.getInt("card.id");
String name = set.getString("card.name");
String textureName = set.getString("card.textureName");
int level = set.getInt("card.level");
int maxHealth = set.getInt("card.maxHealth");
int maxDefense = set.getInt("card.maxDefense");
int maxAttack = set.getInt("card.maxAttack");
int runRequirements = set.getInt("card.runRequirements");
int rarity = set.getInt("card.rarity");
int amount = set.getInt("profile_owns_card.amount");
String description = set.getString("card.description");
do {
components.add(set.getInt("components.id"));
next = set.next();
} while (next && currentID == set.getInt("card.id"));
int[] componentTypes = new int[components.size()];
for (int i = 0; i < components.size(); i++) {
componentTypes[i] = components.get(i);
}
Card s = new Card(id, uid, name, c, textureName, level, maxHealth, maxDefense, maxAttack, // magic
1, componentTypes, runRequirements, a, rarity, description);
cards.put(s, amount);
}
} catch (Exception e) {
e.printStackTrace();
}
return cards;
}
use of com.janfic.games.computercombat.model.Ability in project computercombat by janfic.
the class SQLAPI method getAbilityByID.
public Ability getAbilityByID(int id) {
System.out.println("[SERVER][MYSQL]: Querying for Ability Data");
try {
String sql = "SELECT * \n" + "FROM ability \n" + "JOIN card ON card.ability_id = ability.id \n" + "WHERE ability.id = " + id + ";";
Statement getAbilityStatement = connection.createStatement();
ResultSet gAResults = getAbilityStatement.executeQuery(sql);
gAResults.next();
Ability a = (Ability) shell.evaluate(gAResults.getString("code"));
a.setInformation(gAResults.getString("description"), gAResults.getString("textureName"), gAResults.getString("name"), gAResults.getString("code"), gAResults.getInt("id"));
return a;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of com.janfic.games.computercombat.model.Ability in project computercombat by janfic.
the class SQLAPI method readCardFromSet.
private Card readCardFromSet(ResultSet set, String uid) {
try {
Ability a = (Ability) shell.evaluate(set.getString("ability.code"));
a.setInformation(set.getString("ability.description"), set.getString("ability.textureName"), set.getString("ability.name"), set.getString("ability.code"), set.getInt("ability.id"));
Collection collection = new Collection(set.getInt("collection.id"), set.getString("collection.name"), set.getString("collection.description"), set.getString("collection.textureName"), set.getString("collection.path"), set.getInt("collection.price"));
String name = set.getString("card.name");
String textureName = set.getString("card.textureName");
int level = set.getInt("card.level");
int id = set.getInt("card.id");
int maxHealth = set.getInt("card.maxHealth");
int maxDefense = set.getInt("card.maxDefense");
int maxAttack = set.getInt("card.maxAttack");
int runRequirements = set.getInt("card.runRequirements");
int rarity = set.getInt("card.rarity");
String description = set.getString("card.description");
String components = set.getString("components");
String[] c = components.split(",");
int[] componentTypes = new int[c.length];
for (int i = 0; i < c.length; i++) {
componentTypes[i] = Integer.parseInt(c[i]);
}
Card s = new Card(id, uid, name, collection, textureName, level, maxHealth, maxDefense, maxAttack, 1, componentTypes, runRequirements, a, rarity, description);
return s;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of com.janfic.games.computercombat.model.Ability in project computercombat by janfic.
the class SQLAPI method getCardById.
public Card getCardById(int id, String optionalUID) {
System.out.println("[SERVER][MYSQL]: Querying for Card Data");
try {
String sql = "SELECT * FROM card \n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN run_requirements ON card.id = run_requirements.card_id\n" + "JOIN components ON components.id = run_requirements.component_id\n" + "JOIN collection ON card.collection_id = collection.id\n" + "WHERE card.id = '" + id + "';";
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(sql);
set.next();
Ability a = (Ability) shell.evaluate(set.getString("ability.code"));
a.setInformation(set.getString("ability.description"), set.getString("ability.textureName"), set.getString("ability.name"), set.getString("ability.code"), set.getInt("ability.id"));
Collection c = new Collection(set.getInt("collection.id"), set.getString("collection.name"), set.getString("collection.description"), set.getString("collection.textureName"), set.getString("collection.path"), set.getInt("collection.price"));
List<Integer> components = new ArrayList<>();
String name = set.getString("card.name");
String textureName = set.getString("card.textureName");
int level = set.getInt("card.level");
int maxHealth = set.getInt("card.maxHealth");
int maxDefense = set.getInt("card.maxDefense");
int maxAttack = set.getInt("card.maxAttack");
int runRequirements = set.getInt("card.runRequirements");
int rarity = set.getInt("card.rarity");
String description = set.getString("card.description");
do {
components.add(set.getInt("components.id"));
} while (set.next());
int[] componentTypes = new int[components.size()];
for (int i = 0; i < components.size(); i++) {
componentTypes[i] = components.get(i);
}
Card s = new Card(id, optionalUID, name, c, textureName, level, maxHealth, maxDefense, maxAttack, 1, componentTypes, runRequirements, a, rarity, description);
return s;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations