Search in sources :

Example 6 with UseAbilityMove

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

the class GameRules method generateMovesWithSelection.

private static List<UseAbilityMove> generateMovesWithSelection(int index, Card card, MatchState state, List<Component> selectedComponents, List<Card> selectedCards) {
    List<UseAbilityMove> moves = new ArrayList<>();
    String uid = state.currentPlayerMove;
    System.out.println(card);
    System.out.println(card.getAbility());
    List<Filter> selectFilters = card.getAbility().getSelectFilters();
    if (index >= selectFilters.size()) {
        List<Component> selectedComponentsClone = new ArrayList<>(selectedComponents);
        List<Card> selectedCardsClone = new ArrayList<>(selectedCards);
        moves.add(new UseAbilityMove(uid, card, selectedComponentsClone, selectedCardsClone));
    } else {
        Filter filter = selectFilters.get(index);
        if (filter instanceof ComponentFilter) {
            List<Component> sComps = new ArrayList<>(selectedComponents);
            List<Card> sCards = new ArrayList<>(selectedCards);
            List<Component> selectableComponents = state.getComponentsByFilter((ComponentFilter) filter, new UseAbilityMove(uid, card, sComps, sCards));
            for (Component selectableComponent : selectableComponents) {
                sComps.add(selectableComponent);
                moves.addAll(generateMovesWithSelection(index + 1, card, state, sComps, sCards));
                sComps.remove(sComps.size() - 1);
            }
        } else if (filter instanceof CardFilter) {
            List<Component> sComps = new ArrayList<>(selectedComponents);
            List<Card> sCards = new ArrayList<>(selectedCards);
            List<Card> selectableCards = state.getCardsByFilter((CardFilter) filter, new UseAbilityMove(uid, card, sComps, sCards));
            for (Card selectableCard : selectableCards) {
                sCards.add(selectableCard);
                moves.addAll(generateMovesWithSelection(index + 1, card, state, sComps, sCards));
                sCards.remove(sCards.size() - 1);
            }
        }
    }
    return moves;
}
Also used : CardFilter(com.janfic.games.computercombat.util.CardFilter) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) CardFilter(com.janfic.games.computercombat.util.CardFilter) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) Filter(com.janfic.games.computercombat.util.Filter) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove)

Example 7 with UseAbilityMove

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

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

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

the class CollectAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    List<MoveAnimation> anim = new ArrayList<>();
    anim.add(Ability.consumeCardProgress(state, move));
    results.add(new MoveResult(move, MatchState.record(state), anim));
    UseAbilityMove useAbility = (UseAbilityMove) move;
    int index = state.activeEntities.get(useAbility.getPlayerUID()).indexOf(useAbility.getCard());
    state.activeEntities.get(useAbility.getPlayerUID()).get(index).setProgress(0);
    Stream<Component> components = state.getComponentsAsList().stream();
    for (CollectFilter filter : filters) {
        components = components.filter((c) -> {
            return filter.filter(state, move, c);
        });
    }
    List<Component> list = components.collect(Collectors.toList());
    Collections.shuffle(list);
    int count = amount.analyze(state, move);
    list = list.subList(0, Math.min(count, list.size()));
    Component[] c = list.toArray(new Component[0]);
    for (Component component : c) {
        component.getMatchNeighbors().add(-1);
    }
    List<MoveResult> result = state.results(move);
    results.addAll(result);
    return results;
}
Also used : Component(com.janfic.games.computercombat.model.Component) GameRules(com.janfic.games.computercombat.model.GameRules) MatchState(com.janfic.games.computercombat.model.match.MatchState) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Ability(com.janfic.games.computercombat.model.Ability) Filter(com.janfic.games.computercombat.util.Filter) Collectors(java.util.stream.Collectors) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) ArrayList(java.util.ArrayList) List(java.util.List) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) Stream(java.util.stream.Stream) Map(java.util.Map) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) Card(com.janfic.games.computercombat.model.Card) Collections(java.util.Collections) Move(com.janfic.games.computercombat.model.moves.Move) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 10 with UseAbilityMove

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

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