Search in sources :

Example 1 with MoveResult

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

the class MatchState method attack.

public List<MoveResult> attack(Move move) {
    Map<String, Array<Integer>> attacks = new HashMap<>();
    String attacker = "" + activeEntities.get(currentPlayerMove).get(0).getMatchID();
    Array<Integer> attacked = new Array<>();
    if (activeEntities.get(this.getOtherProfile(currentPlayerMove)).isEmpty()) {
        attacked.add(computers.get(this.getOtherProfile(currentPlayerMove)).getMatchID());
    } else {
        attacked.add(activeEntities.get(this.getOtherProfile(currentPlayerMove)).get(0).getMatchID());
    }
    attacks.put(attacker, attacked);
    AttackAbility attackAbility = new AttackAbility(new ArrayList<>(), attacks);
    List<MoveResult> res = attackAbility.doAbility(this, move);
    return res;
}
Also used : Array(com.badlogic.gdx.utils.Array) HashMap(java.util.HashMap) AttackAbility(com.janfic.games.computercombat.model.abilities.AttackAbility) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 2 with MoveResult

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

the class ExtraTurnAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    state.currentPlayerMove = state.players.get(0).getUID().equals(move.getPlayerUID()) ? state.players.get(0).getUID() : state.players.get(1).getUID();
    MoveResult result = new MoveResult(move, MatchState.record(state), new ArrayList<>());
    results.add(result);
    return results;
}
Also used : ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 3 with MoveResult

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

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

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

Aggregations

MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)25 ArrayList (java.util.ArrayList)16 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)15 Card (com.janfic.games.computercombat.model.Card)12 Component (com.janfic.games.computercombat.model.Component)7 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)7 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)5 MatchState (com.janfic.games.computercombat.model.match.MatchState)4 Move (com.janfic.games.computercombat.model.moves.Move)4 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 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Array (com.badlogic.gdx.utils.Array)1 Json (com.badlogic.gdx.utils.Json)1 Deck (com.janfic.games.computercombat.model.Deck)1