Search in sources :

Example 1 with AttackAnimation

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;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) AttackAnimation(com.janfic.games.computercombat.model.animations.AttackAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Aggregations

Card (com.janfic.games.computercombat.model.Card)1 AttackAnimation (com.janfic.games.computercombat.model.animations.AttackAnimation)1 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)1 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)1 ArrayList (java.util.ArrayList)1