Search in sources :

Example 1 with MoveAnimation

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

use of com.janfic.games.computercombat.model.moves.MoveAnimation 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 3 with MoveAnimation

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

the class SpawnAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    MoveAnimation consumeProgressAnimation = Ability.consumeCardProgress(state, move);
    List<int[]> newCoords = new ArrayList<>();
    int amountSpawned = amount.analyze(state, move);
    for (int i = 0; i < amountSpawned; i++) {
        int[] newLocation = new int[] { (int) (Math.random() * 8), (int) (Math.random() * 8) };
        boolean duplicate = false;
        while (state.getComponentBoard()[newLocation[0]][newLocation[1]].getColor() == componentType || duplicate == true) {
            for (int[] newCoord : newCoords) {
                if (newLocation[0] == newCoord[0] && newLocation[1] == newCoord[1]) {
                    duplicate = true;
                    break;
                }
            }
            newLocation = new int[] { (int) (Math.random() * 8), (int) (Math.random() * 8) };
        }
        newCoords.add(newLocation);
    }
    List<Component> spawned = new ArrayList<>();
    List<Component> destroyed = new ArrayList<>();
    for (int[] newCoord : newCoords) {
        Component destroy = state.getComponentBoard()[newCoord[0]][newCoord[1]];
        Component spawn = new Component(componentType, newCoord[0], newCoord[1]);
        state.getComponentBoard()[newCoord[0]][newCoord[1]].changeColor(spawn.getColor());
        state.getComponentBoard()[newCoord[0]][newCoord[1]].invalidate();
        state.getComponentBoard()[newCoord[0]][newCoord[1]].invalidateNeighbors();
        spawned.add(spawn);
        destroyed.add(destroy);
    }
    List<MoveAnimation> animations = new ArrayList<>();
    if (consumeProgressAnimation != null) {
        animations.add(consumeProgressAnimation);
    }
    animations.add(new SpawnAnimation(destroyed, spawned));
    MoveResult moveResult = new MoveResult(move, MatchState.record(state), animations);
    List<MoveResult> afterMove = state.results(move);
    results.add(moveResult);
    results.addAll(afterMove);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) SpawnAnimation(com.janfic.games.computercombat.model.animations.SpawnAnimation)

Example 4 with MoveAnimation

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

the class TransformCardAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    List<MoveAnimation> animations = new ArrayList<>();
    MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
    List<Card> old = new ArrayList<>();
    List<Card> newC = new ArrayList<>();
    for (CardFilter filter : oldCards) {
        for (String uid : state.activeEntities.keySet()) {
            for (int i = 0; i < state.activeEntities.get(uid).size(); i++) {
                Card oldCard = state.activeEntities.get(uid).get(i);
                if (filter.filter(oldCard, state, move)) {
                    Card newCard = SQLAPI.getSingleton().getCardById(newCards.get(oldCards.indexOf(filter)), oldCard.getOwnerUID());
                    newCard.generateMatchID();
                    state.activeEntities.get(uid).set(i, newCard);
                    old.add(oldCard);
                    newC.add(newCard);
                }
            }
        }
    }
    if (consumeProgress != null) {
        animations.add(consumeProgress);
    }
    animations.add(new TransformCardAnimation(old, newC));
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    results.add(result);
    return results;
}
Also used : CardFilter(com.janfic.games.computercombat.util.CardFilter) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) TransformCardAnimation(com.janfic.games.computercombat.model.animations.TransformCardAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 5 with MoveAnimation

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

the class TransformComponentsAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    Component[][] board = state.getComponentBoard();
    List<MoveAnimation> animations = new ArrayList<>();
    MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
    List<Component> originalComponents = new ArrayList<>(), newComponents = new ArrayList<>();
    for (Component[] components : board) {
        for (Component component : components) {
            if (filter.filter(component, state, move)) {
                int randomIndex = (int) (Math.random() * transformTypes.size());
                Component c = new Component(transformTypes.get(randomIndex), component.getX(), component.getY());
                originalComponents.add(new Component(component));
                newComponents.add(c);
                board[component.getX()][component.getY()].changeColor(transformTypes.get(randomIndex));
                board[component.getX()][component.getY()].invalidate();
                board[component.getX()][component.getY()].invalidateNeighbors();
            }
        }
    }
    animations.add(consumeProgress);
    animations.add(new SpawnAnimation(originalComponents, newComponents));
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    List<MoveResult> afterMove = state.results(move);
    results.add(result);
    results.addAll(afterMove);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) SpawnAnimation(com.janfic.games.computercombat.model.animations.SpawnAnimation)

Aggregations

MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)15 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)15 ArrayList (java.util.ArrayList)14 Card (com.janfic.games.computercombat.model.Card)11 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)6 Component (com.janfic.games.computercombat.model.Component)5 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)5 Ability (com.janfic.games.computercombat.model.Ability)2 Player (com.janfic.games.computercombat.model.Player)2 CollectAnimation (com.janfic.games.computercombat.model.animations.CollectAnimation)2 ReceiveDamageAnimation (com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation)2 SpawnAnimation (com.janfic.games.computercombat.model.animations.SpawnAnimation)2 List (java.util.List)2 Deck (com.janfic.games.computercombat.model.Deck)1 GameRules (com.janfic.games.computercombat.model.GameRules)1 AttackAnimation (com.janfic.games.computercombat.model.animations.AttackAnimation)1 CardToFrontAnimation (com.janfic.games.computercombat.model.animations.CardToFrontAnimation)1 CascadeAnimation (com.janfic.games.computercombat.model.animations.CascadeAnimation)1 ChangeStatAnim (com.janfic.games.computercombat.model.animations.ChangeStatAnim)1 DestroyCardAnimation (com.janfic.games.computercombat.model.animations.DestroyCardAnimation)1