use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class AttackAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
String currentUID = move.getPlayerUID();
String opponentUID = state.getOtherProfile(state.currentPlayerMove);
List<Card> destroyed = new ArrayList<>();
List<MoveAnimation> animation = new ArrayList<>();
for (String key : attacks.keySet()) {
Array<Integer> attacked = attacks.get(key);
for (Integer c : attacked) {
Card att = state.getCardMyMatchID(Integer.parseInt(key));
if (att.getID() > 0) {
for (Card cardAttacked : state.activeEntities.get(opponentUID)) {
if (c == cardAttacked.getMatchID()) {
cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
if (cardAttacked.isDead()) {
destroyed.add(cardAttacked);
}
break;
}
}
} else if (att.getID() == 0) {
Card cardAttacked = state.computers.get(opponentUID);
cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
}
}
}
MoveResult result = new MoveResult(move, MatchState.record(state), animation);
results.add(result);
if (!destroyed.isEmpty()) {
DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
List<MoveResult> r = destroyAbility.doAbility(state, move);
results.addAll(r);
}
return results;
}
use of com.janfic.games.computercombat.model.Card 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;
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class MatchState method clone.
@Override
public Object clone() throws CloneNotSupportedException {
Player player1 = (Player) players.get(0).clone();
Player player2 = (Player) players.get(1).clone();
Component[][] componentBoard = new Component[8][8];
for (int x = 0; x < componentBoard.length; x++) {
for (int y = 0; y < componentBoard[x].length; y++) {
componentBoard[x][y] = new Component(this.componentBoard[x][y]);
}
}
Map<String, List<Card>> activeEntities = new HashMap<>();
List<Card> player1Cards = new ArrayList<>();
List<Card> player2Cards = new ArrayList<>();
activeEntities.put(player1.getUID(), player1Cards);
activeEntities.put(player2.getUID(), player2Cards);
for (String string : this.activeEntities.keySet()) {
for (Card card : this.activeEntities.get(string)) {
activeEntities.get(string).add((Card) (card.clone()));
}
}
Map<String, Deck> decks = new HashMap<>();
for (String uid : this.decks.keySet()) {
decks.put(uid, (Deck) this.decks.get(uid).clone());
}
Map<String, Card> computers = new HashMap<>();
for (String uid : this.computers.keySet()) {
computers.put(uid, (Card) this.computers.get(uid).clone());
}
MatchState state = new MatchState(player1, player2, componentBoard, activeEntities, computers, decks);
state.isGameOver = this.isGameOver;
if (this.winner != null) {
state.winner = "" + this.winner;
}
state.currentPlayerMove = "" + this.currentPlayerMove;
MatchState.buildNeighbors(componentBoard);
state.update();
return state;
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class MatchState method results.
public List<MoveResult> results(Move move) {
List<MoveResult> results = new ArrayList<>();
boolean extraTurn = false;
while (isInvalidBoard() || getMatches().isEmpty() == false) {
// Save Old State
// Update
update();
// Collect Components
Map<Integer, List<Component>> collected = collectComponents();
Map<Component, Card> progress = new HashMap<>();
CollectAnimation collectAnimation = new CollectAnimation(collected, progress);
progress(collectAnimation);
// Attack
boolean attack = false;
for (Integer integer : collected.keySet()) {
for (Component component : collected.get(integer)) {
if (component.getColor() == 5) {
attack = true;
break;
}
}
}
if (attack && activeEntities.get(currentPlayerMove).isEmpty() == false) {
results.addAll(attack(move));
}
// Remove
for (Integer matchNumber : collected.keySet()) {
for (Component component : collected.get(matchNumber)) {
this.componentBoard[component.getX()][component.getY()].changeColor(0);
}
}
// Cascade
// This can be optimized by storing collected components
CascadeAnimation cascadeAnimation = new CascadeAnimation(cascade());
List<MoveAnimation> moveAnimation = new ArrayList<>();
moveAnimation.add(collectAnimation);
moveAnimation.add(cascadeAnimation);
for (Integer integer : collected.keySet()) {
if (collected.get(integer).size() >= 4) {
extraTurn = true;
}
}
MoveResult result = new MoveResult(move, MatchState.record(this), moveAnimation);
results.add(result);
}
if (extraTurn == false && results.size() > 0) {
MoveResult last = results.get(results.size() - 1);
last.getState().currentPlayerMove = last.getState().getOtherProfile(last.getState().currentPlayerMove);
this.currentPlayerMove = last.getState().currentPlayerMove;
}
return results;
}
use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.
the class ChargeAbilitiesHeuristicAnalyzer method getCharges.
public int getCharges(MoveResult result) {
int totalCharge = 0;
String currentUID = result.getMove().getPlayerUID();
String opponentUID = result.getState().getOtherProfile(currentUID);
for (Card card : result.getState().activeEntities.get(opponentUID)) {
totalCharge += card.getRunProgress();
}
totalCharge += result.getState().computers.get(opponentUID).getRunProgress();
return totalCharge;
}
Aggregations