use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class MatchState method read.
@Override
public void read(Json json, JsonValue jsonData) {
json.setTypeName("class");
this.players = json.readValue("players", List.class, Player.class, jsonData);
json.setTypeName(null);
this.isGameOver = json.readValue("isGameOver", boolean.class, jsonData);
this.winner = json.readValue("winner", String.class, jsonData);
this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
this.decks = json.readValue("decks", HashMap.class, Deck.class, jsonData);
HashMap<String, List<JsonValue>> v = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
this.activeEntities = new HashMap<>();
for (String string : v.keySet()) {
List<Card> cards = new ArrayList<>();
for (JsonValue jsonValue : v.get(string)) {
Card c = json.readValue(Card.class, jsonValue);
cards.add(c);
}
activeEntities.put(string, cards);
}
this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
String boardString = json.readValue("componentBoard", String.class, jsonData);
componentBoard = new Component[8][8];
assert (boardString.length() == 64);
for (int i = 0; i < boardString.length(); i++) {
int x = i / 8;
int y = i % 8;
try {
componentBoard[x][y] = new Component(Integer.parseInt("" + boardString.substring(i, i + 1)), x, y);
} catch (Exception e) {
e.printStackTrace();
}
}
json.setTypeName("class");
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class MatchState method progress.
public void progress(CollectAnimation collectAnimation) {
Map<Component, Card> progress = collectAnimation.progress;
for (Component c : collectAnimation.getAllComponents()) {
boolean collectedByCard = false;
for (Card card : activeEntities.get(currentPlayerMove)) {
if (card.getRunProgress() < card.getRunRequirements()) {
for (Integer requirement : card.getRunComponents()) {
if (c.getColor() == requirement) {
card.recieveComponents(requirement, 1);
collectedByCard = true;
progress.put(c, card);
break;
}
}
}
if (collectedByCard == true) {
break;
}
}
if (collectedByCard == false) {
computers.get(currentPlayerMove).recieveProgress(1);
}
}
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class FocusedDamageAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> moveResults = new ArrayList<>();
UseAbilityMove abilityMove = (UseAbilityMove) move;
List<Card> destroyed = new ArrayList<>();
List<MoveAnimation> animation = new ArrayList<>();
MoveAnimation consume = Ability.consumeCardProgress(state, move);
animation.add(consume);
int index = state.activeEntities.get(abilityMove.getCard().getOwnerUID()).indexOf(abilityMove.getCard());
state.activeEntities.get(abilityMove.getPlayerUID()).get(index).setProgress(0);
for (Card selectedSoftware : abilityMove.getSelectedSoftwares()) {
for (String playerUID : state.activeEntities.keySet()) {
for (Card card : state.activeEntities.get(playerUID)) {
if (card.equals(selectedSoftware)) {
int damage = amount.analyze(state, move);
card.recieveDamage(damage);
animation.add(new ReceiveDamageAnimation(selectedSoftware, damage, card.getOwnerUID()));
if (card.isDead()) {
destroyed.add(card);
}
}
}
}
}
state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
MoveResult result = new MoveResult(move, MatchState.record(state), animation);
moveResults.add(result);
if (destroyed.isEmpty() == false) {
DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
List<MoveResult> r = destroyAbility.doAbility(state, move);
moveResults.addAll(r);
}
return moveResults;
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class TransformCardAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
List<MoveAnimation> animations = new ArrayList<>();
MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
List<Card> old = new ArrayList<>();
List<Card> newC = new ArrayList<>();
for (CardFilter filter : oldCards) {
for (String uid : state.activeEntities.keySet()) {
for (int i = 0; i < state.activeEntities.get(uid).size(); i++) {
Card oldCard = state.activeEntities.get(uid).get(i);
if (filter.filter(oldCard, state, move)) {
Card newCard = SQLAPI.getSingleton().getCardById(newCards.get(oldCards.indexOf(filter)), oldCard.getOwnerUID());
newCard.generateMatchID();
state.activeEntities.get(uid).set(i, newCard);
old.add(oldCard);
newC.add(newCard);
}
}
}
}
if (consumeProgress != null) {
animations.add(consumeProgress);
}
animations.add(new TransformCardAnimation(old, newC));
state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
MoveResult result = new MoveResult(move, MatchState.record(state), animations);
results.add(result);
return results;
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class SQLAPI method getCardsInCollection.
public List<Card> getCardsInCollection(List<Integer> collectionIDs, String optionalUID) {
List<Card> cards = new ArrayList<>();
try {
String sql = "SELECT * FROM card\n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN join_components ON card.id = join_components.card \n" + "JOIN collection ON card.collection_id = collection.id;";
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(sql);
boolean areRowsLeft = set.next();
while (areRowsLeft) {
if (collectionIDs.contains(set.getInt("card.collection_id")) && set.getInt("card.id") != 0) {
Card c = readCardFromSet(set, optionalUID);
cards.add(c);
}
areRowsLeft = set.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return cards;
}
Aggregations