Search in sources :

Example 1 with ConsumeProgressAnimation

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

Example 2 with ConsumeProgressAnimation

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

the class Ability method consumeCardProgress.

public static MoveAnimation consumeCardProgress(MatchState newState, Move move) {
    UseAbilityMove useAbilityMove = (UseAbilityMove) move;
    int index = newState.activeEntities.get(useAbilityMove.getPlayerUID()).indexOf(useAbilityMove.getCard());
    if (index != -1) {
        newState.activeEntities.get(useAbilityMove.getPlayerUID()).get(index).setProgress(0);
        List<Card> used = new ArrayList<>();
        used.add(useAbilityMove.getCard());
        return new ConsumeProgressAnimation(useAbilityMove.getPlayerUID(), used);
    } else {
        return null;
    }
}
Also used : UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)

Example 3 with ConsumeProgressAnimation

use of com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation 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)

Example 4 with ConsumeProgressAnimation

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

the class SwitchComponentsAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove useAbility = (UseAbilityMove) move;
    Component[][] newBoard = state.componentBoard;
    Component a = useAbility.getSelectedComponents().get(0);
    Component b = useAbility.getSelectedComponents().get(1);
    Component bb = newBoard[b.getX()][b.getY()];
    Component ba = newBoard[a.getX()][a.getY()];
    bb.invalidate();
    ba.invalidate();
    ba.invalidateNeighbors();
    bb.invalidateNeighbors();
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    List<MoveAnimation> anims = new ArrayList<>();
    anims.add(new ConsumeProgressAnimation(move.getPlayerUID(), drained));
    anims.add(new SwitchAnimation(bb, ba));
    MoveResult r = new MoveResult(move, MatchState.record(state), anims);
    List<MoveResult> collectCheckResults = state.results(move);
    results.add(r);
    results.addAll(collectCheckResults);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) SwitchAnimation(com.janfic.games.computercombat.model.animations.SwitchAnimation) Card(com.janfic.games.computercombat.model.Card)

Example 5 with ConsumeProgressAnimation

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

the class DamageAllAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove abilityMove = (UseAbilityMove) move;
    List<Card> destroyed = new ArrayList<>();
    List<MoveAnimation> animation = new ArrayList<>();
    int index = state.activeEntities.get(abilityMove.getCard().getOwnerUID()).indexOf(abilityMove.getCard());
    state.activeEntities.get(abilityMove.getPlayerUID()).get(index).setProgress(0);
    for (Card card : state.getAllCards()) {
        if (filter == null || filter.filter(card, state, move)) {
            int damage = amount.analyze(state, move);
            animation.add(new ReceiveDamageAnimation(card, damage, card.getOwnerUID()));
            card.recieveDamage(damage);
            if (card.isDead()) {
                destroyed.add(card);
            }
        }
    }
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animation);
    results.add(result);
    if (destroyed.isEmpty() == false) {
        DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
        List<MoveResult> r = destroyAbility.doAbility(state, move);
        results.addAll(r);
    }
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    results.get(0).getAnimations().add(0, new ConsumeProgressAnimation(move.getPlayerUID(), drained));
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ReceiveDamageAnimation(com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card)

Aggregations

ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)5 ArrayList (java.util.ArrayList)5 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)4 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)4 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)4 Card (com.janfic.games.computercombat.model.Card)3 Player (com.janfic.games.computercombat.model.Player)2 Ability (com.janfic.games.computercombat.model.Ability)1 Component (com.janfic.games.computercombat.model.Component)1 Deck (com.janfic.games.computercombat.model.Deck)1 DrawAnimation (com.janfic.games.computercombat.model.animations.DrawAnimation)1 ReceiveDamageAnimation (com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation)1 SwitchAnimation (com.janfic.games.computercombat.model.animations.SwitchAnimation)1