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