use of com.janfic.games.computercombat.model.animations.AttackAnimation in project computercombat by janfic.
the class AttackAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
String currentUID = move.getPlayerUID();
String opponentUID = state.getOtherProfile(state.currentPlayerMove);
List<Card> destroyed = new ArrayList<>();
List<MoveAnimation> animation = new ArrayList<>();
for (String key : attacks.keySet()) {
Array<Integer> attacked = attacks.get(key);
for (Integer c : attacked) {
Card att = state.getCardMyMatchID(Integer.parseInt(key));
if (att.getID() > 0) {
for (Card cardAttacked : state.activeEntities.get(opponentUID)) {
if (c == cardAttacked.getMatchID()) {
cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
if (cardAttacked.isDead()) {
destroyed.add(cardAttacked);
}
break;
}
}
} else if (att.getID() == 0) {
Card cardAttacked = state.computers.get(opponentUID);
cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
}
}
}
MoveResult result = new MoveResult(move, MatchState.record(state), animation);
results.add(result);
if (!destroyed.isEmpty()) {
DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
List<MoveResult> r = destroyAbility.doAbility(state, move);
results.addAll(r);
}
return results;
}
Aggregations