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