Search in sources :

Example 1 with UseAbilityMove

use of com.janfic.games.computercombat.model.moves.UseAbilityMove 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;
}
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) Card(com.janfic.games.computercombat.model.Card)

Example 2 with UseAbilityMove

use of com.janfic.games.computercombat.model.moves.UseAbilityMove in project computercombat by janfic.

the class GameRules method getAvailableMoves.

public static List<Move> getAvailableMoves(MatchState state) {
    List<Move> moves = new ArrayList<>();
    // Get MatchComponentsMoves
    List<Integer[]> matches = areAvailableComponentMatches(state);
    for (Integer[] match : matches) {
        Component a = state.getComponentBoard()[match[0]][match[1]];
        Component b = state.getComponentBoard()[match[2]][match[3]];
        MatchComponentsMove m = new MatchComponentsMove(state.currentPlayerMove, a, b);
        moves.add(m);
    }
    // Get UseAbilityMoves
    String uid = state.currentPlayerMove;
    for (Card card : state.activeEntities.get(uid)) {
        if (card.getRunProgress() >= card.getRunRequirements()) {
            List<UseAbilityMove> generatedMoves = generateMovesWithSelection(0, card, state, new ArrayList<>(), new ArrayList<>());
            moves.addAll(generatedMoves);
        }
    }
    Card c = state.computers.get(uid);
    if (c.getRunProgress() >= c.getRunRequirements()) {
        UseAbilityMove m = new UseAbilityMove(uid, c, null, null);
        moves.add(m);
    }
    return moves;
}
Also used : MatchComponentsMove(com.janfic.games.computercombat.model.moves.MatchComponentsMove) MatchComponentsMove(com.janfic.games.computercombat.model.moves.MatchComponentsMove) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) Move(com.janfic.games.computercombat.model.moves.Move) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove)

Example 3 with UseAbilityMove

use of com.janfic.games.computercombat.model.moves.UseAbilityMove in project computercombat by janfic.

the class GameRules method makeMove.

public static List<MoveResult> makeMove(MatchState originalState, Move move) {
    List<MoveResult> results;
    if (move instanceof UseAbilityMove) {
        UseAbilityMove m = (UseAbilityMove) move;
        m.getCard().setAbility(Ability.getAbilityFromCode(m.getCard().getAbility()));
        results = m.doMove(originalState);
    } else {
        results = move.doMove(originalState);
    }
    return results;
}
Also used : UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 4 with UseAbilityMove

use of com.janfic.games.computercombat.model.moves.UseAbilityMove in project computercombat by janfic.

the class CardToFrontAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove useAbilityMove = (UseAbilityMove) move;
    MoveAnimation consume = Ability.consumeCardProgress(state, move);
    List<Card> toFront = new ArrayList<>();
    toFront.addAll(useAbilityMove.getSelectedSoftwares());
    for (Card card : useAbilityMove.getSelectedSoftwares()) {
        int cardIndex = state.activeEntities.get(card.getOwnerUID()).indexOf(card);
        Card newStateCard = state.activeEntities.get(card.getOwnerUID()).get(cardIndex);
        state.activeEntities.get(card.getOwnerUID()).remove(cardIndex);
        state.activeEntities.get(card.getOwnerUID()).add(0, newStateCard);
    }
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    List<MoveAnimation> animations = new ArrayList<>();
    animations.add(consume);
    animations.add(new CardToFrontAnimation(toFront));
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    results.add(result);
    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) Card(com.janfic.games.computercombat.model.Card) CardToFrontAnimation(com.janfic.games.computercombat.model.animations.CardToFrontAnimation)

Example 5 with UseAbilityMove

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

Aggregations

UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)10 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)7 ArrayList (java.util.ArrayList)7 Card (com.janfic.games.computercombat.model.Card)6 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)6 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)5 Component (com.janfic.games.computercombat.model.Component)2 ReceiveDamageAnimation (com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation)2 Move (com.janfic.games.computercombat.model.moves.Move)2 Filter (com.janfic.games.computercombat.util.Filter)2 Ability (com.janfic.games.computercombat.model.Ability)1 Deck (com.janfic.games.computercombat.model.Deck)1 GameRules (com.janfic.games.computercombat.model.GameRules)1 Player (com.janfic.games.computercombat.model.Player)1 CardToFrontAnimation (com.janfic.games.computercombat.model.animations.CardToFrontAnimation)1 DrawAnimation (com.janfic.games.computercombat.model.animations.DrawAnimation)1 SwitchAnimation (com.janfic.games.computercombat.model.animations.SwitchAnimation)1 MatchState (com.janfic.games.computercombat.model.match.MatchState)1 MatchComponentsMove (com.janfic.games.computercombat.model.moves.MatchComponentsMove)1 CardFilter (com.janfic.games.computercombat.util.CardFilter)1