Search in sources :

Example 1 with DrawAnimation

use of com.janfic.games.computercombat.model.animations.DrawAnimation in project computercombat by janfic.

the class DrawAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> r = new ArrayList<>();
    UseAbilityMove abilityMove = (UseAbilityMove) move;
    List<Card> cards = state.activeEntities.get(move.getPlayerUID());
    Deck deck = state.decks.get(move.getPlayerUID());
    List<Card> drawnCards = new ArrayList<>();
    if (cards.size() < 4) {
        if (this.cards == null) {
            if (deck.size() > 0) {
                Card s = deck.draw();
                s.setOwnerUID(move.getPlayerUID());
                cards.add(s);
                drawnCards.add(s);
            }
        } else {
            for (StateAnalyzer<Integer> card : this.cards) {
                Card s = SQLAPI.getSingleton().getCardById(card.analyze(state, move), move.getPlayerUID());
                s.setOwnerUID(move.getPlayerUID());
                s.generateMatchID();
                cards.add(s);
                drawnCards.add(s);
            }
        }
    }
    List<MoveAnimation> animations = new ArrayList<>();
    if (abilityMove.getCard().getID() == 0) {
        state.computers.get(move.getPlayerUID()).setProgress(0);
    } else {
        for (Card card : state.activeEntities.get(move.getPlayerUID())) {
            if (card.equals(abilityMove.getCard())) {
                card.setProgress(0);
            }
        }
    }
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    ConsumeProgressAnimation drainAnimation = new ConsumeProgressAnimation(move.getPlayerUID(), drained);
    DrawAnimation drawAnimation = new DrawAnimation(move.getPlayerUID(), drawnCards);
    for (Player player : state.players) {
        if (player.getUID().equals(move.getPlayerUID())) {
            state.currentPlayerMove = state.getOtherProfile(player.getUID());
        }
    }
    animations.add(drainAnimation);
    animations.add(drawAnimation);
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    r.add(result);
    return r;
}
Also used : Player(com.janfic.games.computercombat.model.Player) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) Deck(com.janfic.games.computercombat.model.Deck) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card) DrawAnimation(com.janfic.games.computercombat.model.animations.DrawAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Aggregations

Card (com.janfic.games.computercombat.model.Card)1 Deck (com.janfic.games.computercombat.model.Deck)1 Player (com.janfic.games.computercombat.model.Player)1 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)1 DrawAnimation (com.janfic.games.computercombat.model.animations.DrawAnimation)1 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)1 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)1 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1 ArrayList (java.util.ArrayList)1