use of com.janfic.games.computercombat.model.moves.MoveAnimation 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.MoveAnimation 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;
}
use of com.janfic.games.computercombat.model.moves.MoveAnimation 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;
}
use of com.janfic.games.computercombat.model.moves.MoveAnimation 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.model.moves.MoveAnimation in project computercombat by janfic.
the class TransformComponentsAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
Component[][] board = state.getComponentBoard();
List<MoveAnimation> animations = new ArrayList<>();
MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
List<Component> originalComponents = new ArrayList<>(), newComponents = new ArrayList<>();
for (Component[] components : board) {
for (Component component : components) {
if (filter.filter(component, state, move)) {
int randomIndex = (int) (Math.random() * transformTypes.size());
Component c = new Component(transformTypes.get(randomIndex), component.getX(), component.getY());
originalComponents.add(new Component(component));
newComponents.add(c);
board[component.getX()][component.getY()].changeColor(transformTypes.get(randomIndex));
board[component.getX()][component.getY()].invalidate();
board[component.getX()][component.getY()].invalidateNeighbors();
}
}
}
animations.add(consumeProgress);
animations.add(new SpawnAnimation(originalComponents, newComponents));
MoveResult result = new MoveResult(move, MatchState.record(state), animations);
List<MoveResult> afterMove = state.results(move);
results.add(result);
results.addAll(afterMove);
return results;
}
Aggregations