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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations