mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Checkstyle fixes in Combat.java
This commit is contained in:
@@ -44,7 +44,7 @@ public class Combat {
|
|||||||
/**
|
/**
|
||||||
* <p>reset.</p>
|
* <p>reset.</p>
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public final void reset() {
|
||||||
resetAttackers();
|
resetAttackers();
|
||||||
blocked.clear();
|
blocked.clear();
|
||||||
|
|
||||||
@@ -71,12 +71,13 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param defender a {@link forge.Player} object.
|
* @param defender a {@link forge.Player} object.
|
||||||
*/
|
*/
|
||||||
public void initiatePossibleDefenders(Player defender) {
|
public final void initiatePossibleDefenders(final Player defender) {
|
||||||
defenders.add(defender);
|
defenders.add(defender);
|
||||||
CardList planeswalkers = AllZoneUtil.getPlayerCardsInPlay(defender);
|
CardList planeswalkers = AllZoneUtil.getPlayerCardsInPlay(defender);
|
||||||
planeswalkers = planeswalkers.getType("Planeswalker");
|
planeswalkers = planeswalkers.getType("Planeswalker");
|
||||||
for (Card pw : planeswalkers)
|
for (Card pw : planeswalkers) {
|
||||||
defenders.add(pw);
|
defenders.add(pw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,9 +85,10 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link java.lang.Object} object.
|
* @return a {@link java.lang.Object} object.
|
||||||
*/
|
*/
|
||||||
public Object nextDefender() {
|
public final Object nextDefender() {
|
||||||
if (nextDefender >= defenders.size())
|
if (nextDefender >= defenders.size()) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
currentDefender = nextDefender;
|
currentDefender = nextDefender;
|
||||||
nextDefender++;
|
nextDefender++;
|
||||||
@@ -99,7 +101,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param def a int.
|
* @param def a int.
|
||||||
*/
|
*/
|
||||||
public void setCurrentDefender(int def) {
|
public final void setCurrentDefender(final int def) {
|
||||||
currentDefender = def;
|
currentDefender = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +110,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public int getRemainingDefenders() {
|
public final int getRemainingDefenders() {
|
||||||
return defenders.size() - nextDefender;
|
return defenders.size() - nextDefender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +119,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link java.util.ArrayList} object.
|
* @return a {@link java.util.ArrayList} object.
|
||||||
*/
|
*/
|
||||||
public ArrayList<Object> getDefenders() {
|
public final ArrayList<Object> getDefenders() {
|
||||||
return defenders;
|
return defenders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +128,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param newDef a {@link java.util.ArrayList} object.
|
* @param newDef a {@link java.util.ArrayList} object.
|
||||||
*/
|
*/
|
||||||
public void setDefenders(ArrayList<Object> newDef) {
|
public final void setDefenders(ArrayList<Object> newDef) {
|
||||||
defenders = newDef;
|
defenders = newDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +137,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return an array of {@link forge.Card} objects.
|
* @return an array of {@link forge.Card} objects.
|
||||||
*/
|
*/
|
||||||
public Card[] getDefendingPlaneswalkers() {
|
public final Card[] getDefendingPlaneswalkers() {
|
||||||
Card[] pwDefending = new Card[defenders.size() - 1];
|
Card[] pwDefending = new Card[defenders.size() - 1];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -155,7 +157,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public int getDeclaredAttackers() {
|
public final int getDeclaredAttackers() {
|
||||||
return attackerToDefender.size();
|
return attackerToDefender.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +166,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param player a {@link forge.Player} object.
|
* @param player a {@link forge.Player} object.
|
||||||
*/
|
*/
|
||||||
public void setAttackingPlayer(Player player) {
|
public final void setAttackingPlayer(final Player player) {
|
||||||
attackingPlayer = player;
|
attackingPlayer = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +175,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param player a {@link forge.Player} object.
|
* @param player a {@link forge.Player} object.
|
||||||
*/
|
*/
|
||||||
public void setDefendingPlayer(Player player) {
|
public final void setDefendingPlayer(final Player player) {
|
||||||
defendingPlayer = player;
|
defendingPlayer = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +184,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link forge.Player} object.
|
* @return a {@link forge.Player} object.
|
||||||
*/
|
*/
|
||||||
public Player getAttackingPlayer() {
|
public final Player getAttackingPlayer() {
|
||||||
return attackingPlayer;
|
return attackingPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +193,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link forge.Player} object.
|
* @return a {@link forge.Player} object.
|
||||||
*/
|
*/
|
||||||
public Player getDefendingPlayer() {
|
public final Player getDefendingPlayer() {
|
||||||
return defendingPlayer;
|
return defendingPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +202,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link java.util.HashMap} object.
|
* @return a {@link java.util.HashMap} object.
|
||||||
*/
|
*/
|
||||||
public HashMap<Card, Integer> getDefendingDamageMap() {
|
public final HashMap<Card, Integer> getDefendingDamageMap() {
|
||||||
return defendingDamageMap;
|
return defendingDamageMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,14 +211,15 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public int getTotalDefendingDamage() {
|
public final int getTotalDefendingDamage() {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
Collection<Integer> c = defendingDamageMap.values();
|
Collection<Integer> c = defendingDamageMap.values();
|
||||||
|
|
||||||
Iterator<Integer> itr = c.iterator();
|
Iterator<Integer> itr = c.iterator();
|
||||||
while (itr.hasNext())
|
while (itr.hasNext()) {
|
||||||
total += itr.next();
|
total += itr.next();
|
||||||
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
@@ -224,23 +227,25 @@ public class Combat {
|
|||||||
/**
|
/**
|
||||||
* <p>setDefendingDamage.</p>
|
* <p>setDefendingDamage.</p>
|
||||||
*/
|
*/
|
||||||
public void setDefendingDamage() {
|
public final void setDefendingDamage() {
|
||||||
defendingDamageMap.clear();
|
defendingDamageMap.clear();
|
||||||
CardList att = new CardList(getAttackers());
|
CardList att = new CardList(getAttackers());
|
||||||
// sum unblocked attackers' power
|
// sum unblocked attackers' power
|
||||||
for (int i = 0; i < att.size(); i++) {
|
for (int i = 0; i < att.size(); i++) {
|
||||||
if (!isBlocked(att.get(i))
|
if (!isBlocked(att.get(i))
|
||||||
|| (getBlockers(att.get(i)).size() == 0 && att.get(i).hasKeyword("Trample"))) {
|
|| (getBlockers(att.get(i)).size() == 0 && att.get(i).hasKeyword("Trample")))
|
||||||
|
{
|
||||||
|
|
||||||
int damageDealt = att.get(i).getNetCombatDamage();
|
int damageDealt = att.get(i).getNetCombatDamage();
|
||||||
|
|
||||||
if (damageDealt > 0) {
|
if (damageDealt > 0) {
|
||||||
//if the creature has first strike do not do damage in the normal combat phase
|
//if the creature has first strike do not do damage in the normal combat phase
|
||||||
if (!att.get(i).hasFirstStrike() || att.get(i).hasDoubleStrike())
|
if (!att.get(i).hasFirstStrike() || att.get(i).hasDoubleStrike()) {
|
||||||
addDefendingDamage(damageDealt, att.get(i));
|
addDefendingDamage(damageDealt, att.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // ! isBlocked...
|
} // ! isBlocked...
|
||||||
}// for
|
} // for
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,7 +254,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean setDefendingFirstStrikeDamage() {
|
public final boolean setDefendingFirstStrikeDamage() {
|
||||||
boolean needsFirstStrike = false;
|
boolean needsFirstStrike = false;
|
||||||
defendingDamageMap.clear();
|
defendingDamageMap.clear();
|
||||||
CardList att = new CardList(getAttackers());
|
CardList att = new CardList(getAttackers());
|
||||||
@@ -279,7 +284,7 @@ public class Combat {
|
|||||||
* @param n a int.
|
* @param n a int.
|
||||||
* @param source a {@link forge.Card} object.
|
* @param source a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public void addDefendingDamage(int n, Card source) {
|
public final void addDefendingDamage(final int n, final Card source) {
|
||||||
String slot = getDefenderByAttacker(source).toString();
|
String slot = getDefenderByAttacker(source).toString();
|
||||||
Object o = defenders.get(Integer.parseInt(slot));
|
Object o = defenders.get(Integer.parseInt(slot));
|
||||||
|
|
||||||
@@ -290,9 +295,9 @@ public class Combat {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defendingDamageMap.containsKey(source))
|
if (!defendingDamageMap.containsKey(source)) {
|
||||||
defendingDamageMap.put(source, n);
|
defendingDamageMap.put(source, n);
|
||||||
else {
|
} else {
|
||||||
defendingDamageMap.put(source, defendingDamageMap.get(source) + n);
|
defendingDamageMap.put(source, defendingDamageMap.get(source) + n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +307,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param n a int.
|
* @param n a int.
|
||||||
*/
|
*/
|
||||||
public void addAttackingDamage(int n) {
|
public final void addAttackingDamage(int n) {
|
||||||
attackingDamage += n;
|
attackingDamage += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +316,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public int getAttackingDamage() {
|
public final int getAttackingDamage() {
|
||||||
return attackingDamage;
|
return attackingDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,10 +325,11 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return an array of {@link forge.CardList} objects.
|
* @return an array of {@link forge.CardList} objects.
|
||||||
*/
|
*/
|
||||||
public CardList[] sortAttackerByDefender() {
|
public final CardList[] sortAttackerByDefender() {
|
||||||
CardList attackers[] = new CardList[defenders.size()];
|
CardList[] attackers = new CardList[defenders.size()];
|
||||||
for (int i = 0; i < attackers.length; i++)
|
for (int i = 0; i < attackers.length; i++) {
|
||||||
attackers[i] = new CardList();
|
attackers[i] = new CardList();
|
||||||
|
}
|
||||||
|
|
||||||
for (Card atk : attackerToDefender.keySet()) {
|
for (Card atk : attackerToDefender.keySet()) {
|
||||||
Object o = attackerToDefender.get(atk);
|
Object o = attackerToDefender.get(atk);
|
||||||
@@ -340,7 +346,7 @@ public class Combat {
|
|||||||
* @param c a {@link forge.Card} object.
|
* @param c a {@link forge.Card} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean isAttacking(Card c) {
|
public final boolean isAttacking(final Card c) {
|
||||||
return map.get(c) != null;
|
return map.get(c) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +355,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param c a {@link forge.Card} object.
|
* @param c a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public void addAttacker(Card c) {
|
public final void addAttacker(final Card c) {
|
||||||
map.put(c, new CardList());
|
map.put(c, new CardList());
|
||||||
attackerToDefender.put(c, currentDefender);
|
attackerToDefender.put(c, currentDefender);
|
||||||
}
|
}
|
||||||
@@ -360,14 +366,14 @@ public class Combat {
|
|||||||
* @param c a {@link forge.Card} object.
|
* @param c a {@link forge.Card} object.
|
||||||
* @return a {@link java.lang.Object} object.
|
* @return a {@link java.lang.Object} object.
|
||||||
*/
|
*/
|
||||||
public Object getDefenderByAttacker(Card c) {
|
public final Object getDefenderByAttacker(final Card c) {
|
||||||
return attackerToDefender.get(c);
|
return attackerToDefender.get(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>resetAttackers.</p>
|
* <p>resetAttackers.</p>
|
||||||
*/
|
*/
|
||||||
public void resetAttackers() {
|
public final void resetAttackers() {
|
||||||
map.clear();
|
map.clear();
|
||||||
attackerToDefender.clear();
|
attackerToDefender.clear();
|
||||||
}
|
}
|
||||||
@@ -377,7 +383,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return an array of {@link forge.Card} objects.
|
* @return an array of {@link forge.Card} objects.
|
||||||
*/
|
*/
|
||||||
public Card[] getAttackers() {
|
public final Card[] getAttackers() {
|
||||||
CardList out = new CardList();
|
CardList out = new CardList();
|
||||||
Iterator<Card> it = map.keySet().iterator();
|
Iterator<Card> it = map.keySet().iterator();
|
||||||
|
|
||||||
@@ -386,7 +392,7 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return out.toArray();
|
return out.toArray();
|
||||||
}// getAttackers()
|
} // getAttackers()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>isBlocked.</p>
|
* <p>isBlocked.</p>
|
||||||
@@ -394,7 +400,7 @@ public class Combat {
|
|||||||
* @param attacker a {@link forge.Card} object.
|
* @param attacker a {@link forge.Card} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean isBlocked(Card attacker) {
|
public final boolean isBlocked(final Card attacker) {
|
||||||
return blocked.contains(attacker);
|
return blocked.contains(attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +410,7 @@ public class Combat {
|
|||||||
* @param attacker a {@link forge.Card} object.
|
* @param attacker a {@link forge.Card} object.
|
||||||
* @param blocker a {@link forge.Card} object.
|
* @param blocker a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public void addBlocker(Card attacker, Card blocker) {
|
public final void addBlocker(final Card attacker, final Card blocker) {
|
||||||
blocked.add(attacker);
|
blocked.add(attacker);
|
||||||
getList(attacker).add(blocker);
|
getList(attacker).add(blocker);
|
||||||
}
|
}
|
||||||
@@ -412,12 +418,13 @@ public class Combat {
|
|||||||
/**
|
/**
|
||||||
* <p>resetBlockers.</p>
|
* <p>resetBlockers.</p>
|
||||||
*/
|
*/
|
||||||
public void resetBlockers() {
|
public final void resetBlockers() {
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
CardList att = new CardList(getAttackers());
|
CardList att = new CardList(getAttackers());
|
||||||
for (int i = 0; i < att.size(); i++)
|
for (int i = 0; i < att.size(); i++) {
|
||||||
addAttacker(att.get(i));
|
addAttacker(att.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -425,15 +432,16 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public CardList getAllBlockers() {
|
public final CardList getAllBlockers() {
|
||||||
CardList att = new CardList(getAttackers());
|
CardList att = new CardList(getAttackers());
|
||||||
CardList block = new CardList();
|
CardList block = new CardList();
|
||||||
|
|
||||||
for (int i = 0; i < att.size(); i++)
|
for (int i = 0; i < att.size(); i++) {
|
||||||
block.addAll(getBlockers(att.get(i)));
|
block.addAll(getBlockers(att.get(i)));
|
||||||
|
}
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
}// getAllBlockers()
|
} // getAllBlockers()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getBlockers.</p>
|
* <p>getBlockers.</p>
|
||||||
@@ -441,11 +449,12 @@ public class Combat {
|
|||||||
* @param attacker a {@link forge.Card} object.
|
* @param attacker a {@link forge.Card} object.
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public CardList getBlockers(Card attacker) {
|
public final CardList getBlockers(final Card attacker) {
|
||||||
if (getList(attacker) == null)
|
if (getList(attacker) == null) {
|
||||||
return new CardList();
|
return new CardList();
|
||||||
else
|
} else {
|
||||||
return new CardList(getList(attacker));
|
return new CardList(getList(attacker));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -454,11 +463,13 @@ public class Combat {
|
|||||||
* @param blocker a {@link forge.Card} object.
|
* @param blocker a {@link forge.Card} object.
|
||||||
* @return a {@link forge.Card} object.
|
* @return a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public Card getAttackerBlockedBy(Card blocker) {
|
public final Card getAttackerBlockedBy(final Card blocker) {
|
||||||
CardList att = new CardList(getAttackers());
|
CardList att = new CardList(getAttackers());
|
||||||
|
|
||||||
for (int i = 0; i < att.size(); i++) {
|
for (int i = 0; i < att.size(); i++) {
|
||||||
if (getBlockers(att.get(i)).contains(blocker)) return att.get(i);
|
if (getBlockers(att.get(i)).contains(blocker)) {
|
||||||
|
return att.get(i);
|
||||||
|
}
|
||||||
} // for
|
} // for
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -470,7 +481,7 @@ public class Combat {
|
|||||||
* @param attacker a {@link forge.Card} object.
|
* @param attacker a {@link forge.Card} object.
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
private CardList getList(Card attacker) {
|
private CardList getList(final Card attacker) {
|
||||||
return (CardList) map.get(attacker);
|
return (CardList) map.get(attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,25 +490,26 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @param c a {@link forge.Card} object.
|
* @param c a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public void removeFromCombat(Card c) {
|
public final void removeFromCombat(final Card c) {
|
||||||
// is card an attacker?
|
// is card an attacker?
|
||||||
CardList att = new CardList(getAttackers());
|
CardList att = new CardList(getAttackers());
|
||||||
if (att.contains(c)) {
|
if (att.contains(c)) {
|
||||||
map.remove(c);
|
map.remove(c);
|
||||||
attackerToDefender.remove(c);
|
attackerToDefender.remove(c);
|
||||||
} else// card is a blocker
|
} else { // card is a blocker
|
||||||
{
|
for (Card a : att) {
|
||||||
for (Card a : att)
|
|
||||||
if (getBlockers(a).contains(c)) {
|
if (getBlockers(a).contains(c)) {
|
||||||
getList(a).remove(c);
|
getList(a).remove(c);
|
||||||
// TODO if Declare Blockers and Declare Blockers (Abilities) merge this logic needs to be tweaked
|
// TODO if Declare Blockers and Declare Blockers (Abilities) merge this logic needs to be tweaked
|
||||||
if (getBlockers(a).size() == 0 && AllZone.getPhase().is(Constant.Phase.Combat_Declare_Blockers))
|
if (getBlockers(a).size() == 0 && AllZone.getPhase().is(Constant.Phase.Combat_Declare_Blockers)) {
|
||||||
blocked.remove(a);
|
blocked.remove(a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// update combat
|
// update combat
|
||||||
CombatUtil.showCombat();
|
CombatUtil.showCombat();
|
||||||
}// removeFromCombat()
|
} // removeFromCombat()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>verifyCreaturesInPlay.</p>
|
* <p>verifyCreaturesInPlay.</p>
|
||||||
@@ -507,15 +519,17 @@ public class Combat {
|
|||||||
all.addAll(getAttackers());
|
all.addAll(getAttackers());
|
||||||
all.addAll(getAllBlockers());
|
all.addAll(getAllBlockers());
|
||||||
|
|
||||||
for (int i = 0; i < all.size(); i++)
|
for (int i = 0; i < all.size(); i++) {
|
||||||
if (!AllZoneUtil.isCardInPlay(all.get(i)))
|
if (!AllZoneUtil.isCardInPlay(all.get(i))) {
|
||||||
removeFromCombat(all.get(i));
|
removeFromCombat(all.get(i));
|
||||||
}// verifyCreaturesInPlay()
|
}
|
||||||
|
}
|
||||||
|
} // verifyCreaturesInPlay()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>setUnblocked.</p>
|
* <p>setUnblocked.</p>
|
||||||
*/
|
*/
|
||||||
public void setUnblocked() {
|
public final void setUnblocked() {
|
||||||
CardList attacking = new CardList(getAttackers());
|
CardList attacking = new CardList(getAttackers());
|
||||||
|
|
||||||
for (Card attacker : attacking) {
|
for (Card attacker : attacking) {
|
||||||
@@ -541,7 +555,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean setAssignedFirstStrikeDamage() {
|
public final boolean setAssignedFirstStrikeDamage() {
|
||||||
|
|
||||||
boolean needFirstStrike = setDefendingFirstStrikeDamage();
|
boolean needFirstStrike = setDefendingFirstStrikeDamage();
|
||||||
|
|
||||||
@@ -569,24 +583,26 @@ public class Combat {
|
|||||||
// this damage is assigned to a player by setDefendingFirstStrikeDamage()
|
// this damage is assigned to a player by setDefendingFirstStrikeDamage()
|
||||||
} else if (attacker.hasFirstStrike() || attacker.hasDoubleStrike()) {
|
} else if (attacker.hasFirstStrike() || attacker.hasDoubleStrike()) {
|
||||||
needFirstStrike = true;
|
needFirstStrike = true;
|
||||||
if (getAttackingPlayer().isHuman()) {// human attacks
|
if (getAttackingPlayer().isHuman()) { // human attacks
|
||||||
if (attacker.hasKeyword("Trample") || block.size() > 1)
|
if (attacker.hasKeyword("Trample") || block.size() > 1) {
|
||||||
AllZone.getDisplay().assignDamage(attacker, block, damageDealt);
|
AllZone.getDisplay().assignDamage(attacker, block, damageDealt);
|
||||||
else block.get(0).addAssignedDamage(damageDealt, attacking.get(i));
|
} else {
|
||||||
} else {// computer attacks
|
block.get(0).addAssignedDamage(damageDealt, attacking.get(i));
|
||||||
|
}
|
||||||
|
} else { // computer attacks
|
||||||
distributeAIDamage(attacker, block, damageDealt);
|
distributeAIDamage(attacker, block, damageDealt);
|
||||||
}
|
}
|
||||||
}// if(hasFirstStrike || doubleStrike)
|
} // if(hasFirstStrike || doubleStrike)
|
||||||
}// for
|
} // for
|
||||||
return needFirstStrike;
|
return needFirstStrike;
|
||||||
}// setAssignedFirstStrikeDamage()
|
} // setAssignedFirstStrikeDamage()
|
||||||
|
|
||||||
// set Card.setAssignedDamage() for all creatures in combat
|
// set Card.setAssignedDamage() for all creatures in combat
|
||||||
// also assigns player damage by setPlayerDamage()
|
// also assigns player damage by setPlayerDamage()
|
||||||
/**
|
/**
|
||||||
* <p>setAssignedDamage.</p>
|
* <p>setAssignedDamage.</p>
|
||||||
*/
|
*/
|
||||||
public void setAssignedDamage() {
|
public final void setAssignedDamage() {
|
||||||
setDefendingDamage();
|
setDefendingDamage();
|
||||||
|
|
||||||
CardList block;
|
CardList block;
|
||||||
@@ -610,20 +626,22 @@ public class Combat {
|
|||||||
// this damage is assigned to a player by setDefendingDamage()
|
// this damage is assigned to a player by setDefendingDamage()
|
||||||
} else if (!attacker.hasFirstStrike() || attacker.hasDoubleStrike()) {
|
} else if (!attacker.hasFirstStrike() || attacker.hasDoubleStrike()) {
|
||||||
|
|
||||||
if (getAttackingPlayer().isHuman()) {// human attacks
|
if (getAttackingPlayer().isHuman()) { // human attacks
|
||||||
|
|
||||||
if (attacker.hasKeyword("Trample") || block.size() > 1)
|
if (attacker.hasKeyword("Trample") || block.size() > 1) {
|
||||||
AllZone.getDisplay().assignDamage(attacker, block, damageDealt);
|
AllZone.getDisplay().assignDamage(attacker, block, damageDealt);
|
||||||
else block.get(0).addAssignedDamage(damageDealt, attacking.get(i));
|
} else {
|
||||||
} else {// computer attacks
|
block.get(0).addAssignedDamage(damageDealt, attacking.get(i));
|
||||||
|
}
|
||||||
|
} else { // computer attacks
|
||||||
distributeAIDamage(attacker, block, damageDealt);
|
distributeAIDamage(attacker, block, damageDealt);
|
||||||
}
|
}
|
||||||
}// if !hasFirstStrike ...
|
} // if !hasFirstStrike ...
|
||||||
}// for
|
} // for
|
||||||
|
|
||||||
// should first strike affect the following?
|
// should first strike affect the following?
|
||||||
|
|
||||||
}// assignDamage()
|
} // assignDamage()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>distributeAIDamage.</p>
|
* <p>distributeAIDamage.</p>
|
||||||
@@ -632,7 +650,7 @@ public class Combat {
|
|||||||
* @param block a {@link forge.CardList} object.
|
* @param block a {@link forge.CardList} object.
|
||||||
* @param damage a int.
|
* @param damage a int.
|
||||||
*/
|
*/
|
||||||
private void distributeAIDamage(Card attacker, CardList block, int damage) {
|
private void distributeAIDamage(final Card attacker, final CardList block, int damage) {
|
||||||
Card c = attacker;
|
Card c = attacker;
|
||||||
|
|
||||||
if (block.size() == 1) {
|
if (block.size() == 1) {
|
||||||
@@ -644,25 +662,30 @@ public class Combat {
|
|||||||
|
|
||||||
int damageNeeded = 0;
|
int damageNeeded = 0;
|
||||||
|
|
||||||
//TODO: if the human can be killed distribute only the minimum of damage to the blocker
|
//TODO if the human can be killed distribute only the minimum of damage to the blocker
|
||||||
|
|
||||||
damageNeeded = blocker.getEnoughDamageToKill(damage, attacker, true);
|
damageNeeded = blocker.getEnoughDamageToKill(damage, attacker, true);
|
||||||
|
|
||||||
if (damageNeeded > damage)
|
if (damageNeeded > damage) {
|
||||||
damageNeeded = Math.min(blocker.getLethalDamage(), damage);
|
damageNeeded = Math.min(blocker.getLethalDamage(), damage);
|
||||||
else
|
} else {
|
||||||
damageNeeded = Math.max(blocker.getLethalDamage(), damageNeeded);
|
damageNeeded = Math.max(blocker.getLethalDamage(), damageNeeded);
|
||||||
|
}
|
||||||
|
|
||||||
int trample = damage - damageNeeded;
|
int trample = damage - damageNeeded;
|
||||||
|
|
||||||
if (0 < trample) // If Extra trample damage, assign to defending player/planeswalker
|
// If Extra trample damage, assign to defending player/planeswalker
|
||||||
|
if (0 < trample) {
|
||||||
this.addDefendingDamage(trample, attacker);
|
this.addDefendingDamage(trample, attacker);
|
||||||
|
}
|
||||||
|
|
||||||
blocker.addAssignedDamage(damageNeeded, attacker);
|
blocker.addAssignedDamage(damageNeeded, attacker);
|
||||||
} else blocker.addAssignedDamage(damage, attacker);
|
} else {
|
||||||
}// 1 blocker
|
blocker.addAssignedDamage(damage, attacker);
|
||||||
|
}
|
||||||
|
} // 1 blocker
|
||||||
else {
|
else {
|
||||||
boolean killsAllBlockers = true;//Does the attacker deal lethal damage to all blockers
|
boolean killsAllBlockers = true; //Does the attacker deal lethal damage to all blockers
|
||||||
for (Card b : block) {
|
for (Card b : block) {
|
||||||
int enoughDamageToKill = b.getEnoughDamageToKill(damage, attacker, true);
|
int enoughDamageToKill = b.getEnoughDamageToKill(damage, attacker, true);
|
||||||
if (enoughDamageToKill <= damage) {
|
if (enoughDamageToKill <= damage) {
|
||||||
@@ -671,8 +694,10 @@ public class Combat {
|
|||||||
cl.add(attacker);
|
cl.add(attacker);
|
||||||
|
|
||||||
b.addAssignedDamage(enoughDamageToKill, c);
|
b.addAssignedDamage(enoughDamageToKill, c);
|
||||||
} else killsAllBlockers = false;
|
} else {
|
||||||
}// for
|
killsAllBlockers = false;
|
||||||
|
}
|
||||||
|
} // for
|
||||||
|
|
||||||
// if attacker has no trample, and there's damage left, assign the rest
|
// if attacker has no trample, and there's damage left, assign the rest
|
||||||
// to a random blocker
|
// to a random blocker
|
||||||
@@ -687,7 +712,7 @@ public class Combat {
|
|||||||
this.addDefendingDamage(damage, c);
|
this.addDefendingDamage(damage, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}// setAssignedDamage()
|
} // setAssignedDamage()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>dealAssignedDamage.</p>
|
* <p>dealAssignedDamage.</p>
|
||||||
@@ -708,11 +733,12 @@ public class Combat {
|
|||||||
AllZone.getCombat().getUnblockedFirstStrikeAttackers());
|
AllZone.getCombat().getUnblockedFirstStrikeAttackers());
|
||||||
|
|
||||||
for (int j = 0; j < unblocked.size(); j++) {
|
for (int j = 0; j < unblocked.size(); j++) {
|
||||||
if (bFirstStrike)
|
if (bFirstStrike) {
|
||||||
CombatUtil.checkUnblockedAttackers(unblocked.get(j));
|
CombatUtil.checkUnblockedAttackers(unblocked.get(j));
|
||||||
else {
|
} else {
|
||||||
if (!unblocked.getCard(j).hasFirstStrike() && !unblocked.getCard(j).hasDoubleStrike())
|
if (!unblocked.getCard(j).hasFirstStrike() && !unblocked.getCard(j).hasDoubleStrike()) {
|
||||||
CombatUtil.checkUnblockedAttackers(unblocked.get(j));
|
CombatUtil.checkUnblockedAttackers(unblocked.get(j));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,8 +754,9 @@ public class Combat {
|
|||||||
c = combatants.get(i);
|
c = combatants.get(i);
|
||||||
|
|
||||||
// if no assigned damage to resolve, move to next
|
// if no assigned damage to resolve, move to next
|
||||||
if (c.getTotalAssignedDamage() == 0)
|
if (c.getTotalAssignedDamage() == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Map<Card, Integer> assignedDamageMap = c.getAssignedDamageMap();
|
Map<Card, Integer> assignedDamageMap = c.getAssignedDamageMap();
|
||||||
HashMap<Card, Integer> damageMap = new HashMap<Card, Integer>();
|
HashMap<Card, Integer> damageMap = new HashMap<Card, Integer>();
|
||||||
@@ -754,7 +781,7 @@ public class Combat {
|
|||||||
* @param att a {@link forge.Card} object.
|
* @param att a {@link forge.Card} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean isUnblocked(Card att) {
|
public final boolean isUnblocked(final Card att) {
|
||||||
return unblockedMap.containsKey(att);
|
return unblockedMap.containsKey(att);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,7 +790,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return an array of {@link forge.Card} objects.
|
* @return an array of {@link forge.Card} objects.
|
||||||
*/
|
*/
|
||||||
public Card[] getUnblockedAttackers() {
|
public final Card[] getUnblockedAttackers() {
|
||||||
CardList out = new CardList();
|
CardList out = new CardList();
|
||||||
Iterator<Card> it = unblockedMap.keySet().iterator();
|
Iterator<Card> it = unblockedMap.keySet().iterator();
|
||||||
while (it.hasNext()) { // only add creatures without firstStrike to this
|
while (it.hasNext()) { // only add creatures without firstStrike to this
|
||||||
@@ -775,14 +802,14 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return out.toArray();
|
return out.toArray();
|
||||||
}// getUnblockedAttackers()
|
} // getUnblockedAttackers()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getUnblockedFirstStrikeAttackers.</p>
|
* <p>getUnblockedFirstStrikeAttackers.</p>
|
||||||
*
|
*
|
||||||
* @return an array of {@link forge.Card} objects.
|
* @return an array of {@link forge.Card} objects.
|
||||||
*/
|
*/
|
||||||
public Card[] getUnblockedFirstStrikeAttackers() {
|
public final Card[] getUnblockedFirstStrikeAttackers() {
|
||||||
CardList out = new CardList();
|
CardList out = new CardList();
|
||||||
Iterator<Card> it = unblockedMap.keySet().iterator();
|
Iterator<Card> it = unblockedMap.keySet().iterator();
|
||||||
while (it.hasNext()) { // only add creatures without firstStrike to this
|
while (it.hasNext()) { // only add creatures without firstStrike to this
|
||||||
@@ -794,15 +821,15 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return out.toArray();
|
return out.toArray();
|
||||||
}// getUnblockedAttackers()
|
} // getUnblockedAttackers()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>addUnblockedAttacker.</p>
|
* <p>addUnblockedAttacker.</p>
|
||||||
*
|
*
|
||||||
* @param c a {@link forge.Card} object.
|
* @param c a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public void addUnblockedAttacker(Card c) {
|
public final void addUnblockedAttacker(final Card c) {
|
||||||
unblockedMap.put(c, new CardList());
|
unblockedMap.put(c, new CardList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}// Class Combat
|
} // Class Combat
|
||||||
|
|||||||
Reference in New Issue
Block a user