use of com.janfic.games.computercombat.util.CardFilter 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;
}
use of com.janfic.games.computercombat.util.CardFilter in project computercombat by janfic.
the class MatchScreen method playerUseAbilityMoveCheck.
private void playerUseAbilityMoveCheck() {
for (SoftwareActor softwareActor : softwareActors.get(game.getCurrentProfile().getUID())) {
if (softwareActor.activatedAbility()) {
Ability ability = softwareActor.getSoftware().getAbility();
if (isSelecting == false) {
this.selectIndex = 0;
selectedCards.clear();
selectedComponents.clear();
this.isSelecting = true;
}
if (ability.getSelectFilters().size() > 0) {
this.currentSelectFilter = ability.getSelectFilters().get(selectIndex);
if (this.currentSelectFilter instanceof ComponentFilter) {
if (!board.isSelecting()) {
board.startComponentSelection((ComponentFilter) this.currentSelectFilter);
}
if (board.didCompleteSelection()) {
selectedComponents.addAll(board.getSelected());
selectIndex++;
board.endComponentSelection();
}
} else if (this.currentSelectFilter instanceof CardFilter) {
CardFilter filter = (CardFilter) this.currentSelectFilter;
for (String uid : this.softwareActors.keySet()) {
for (SoftwareActor sa : this.softwareActors.get(uid)) {
if (!sa.isSelecting()) {
if (!filter.filter(sa.getSoftware(), matchData.getCurrentState(), null)) {
sa.setColor(Color.GRAY);
sa.setTouchable(Touchable.disabled);
} else {
sa.startSelection();
}
}
if (sa.isSelected()) {
this.selectedCards.add(sa);
selectIndex++;
for (String u : this.softwareActors.keySet()) {
for (SoftwareActor s : this.softwareActors.get(u)) {
s.endSelection();
sa.setColor(Color.WHITE);
sa.setTouchable(Touchable.enabled);
}
}
}
}
}
}
}
if (selectIndex == ability.getSelectFilters().size()) {
List<Component> components = new ArrayList<>();
List<Card> cards = new ArrayList<>();
for (ComponentActor selectedComponent : selectedComponents) {
components.add(selectedComponent.getComponent());
}
for (SoftwareActor selectedCard : selectedCards) {
cards.add(selectedCard.getSoftware());
}
UseAbilityMove move = new UseAbilityMove(game.getCurrentProfile().getUID(), softwareActor.getSoftware(), components, cards);
softwareActor.setActivatedAbility(false);
System.out.println("USED ABILITY MOVE");
if (GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move)) {
game.getServerAPI().sendMessage(new Message(Type.MOVE_REQUEST, json.toJson(move)));
} else {
System.out.println("NOT VALID MOVE???");
}
this.isSelecting = false;
this.selectIndex = -1;
this.selectedCards.clear();
this.selectedComponents.clear();
for (String u : this.softwareActors.keySet()) {
for (SoftwareActor s : this.softwareActors.get(u)) {
s.endSelection();
s.setColor(Color.WHITE);
s.setTouchable(Touchable.enabled);
}
}
}
}
}
ComputerActor computerActor = computerActors.get(game.getCurrentProfile().getUID());
if (computerActor.activatedAbility()) {
UseAbilityMove move = new UseAbilityMove(game.getCurrentProfile().getUID(), computerActor.getComputer(), new ArrayList<>(), new ArrayList<>());
computerActor.setActivatedAbility(false);
if (GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move)) {
game.getServerAPI().sendMessage(new Message(Type.MOVE_REQUEST, json.toJson(move)));
}
}
}
use of com.janfic.games.computercombat.util.CardFilter 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;
}
Aggregations