- More Cleanup in Combat class.

This commit is contained in:
Sloth
2012-05-16 16:08:10 +00:00
parent 84d9c9b108
commit b8cc7ca2e5
3 changed files with 16 additions and 83 deletions

View File

@@ -20,9 +20,6 @@ package forge.card.trigger;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.CardList;
import forge.card.spellability.SpellAbility;
@@ -64,9 +61,7 @@ public class TriggerAttacks extends Trigger {
}
if (this.getMapParams().containsKey("Attacked")) {
if (this.getMapParams().get("Attacked").equals("Player")
&& StringUtils.isNumeric(runParams2.get("Attacked").toString())
&& (Integer.parseInt(runParams2.get("Attacked").toString()) > 0)) {
if (this.getMapParams().get("Attacked").equals("Player") && (Integer) runParams2.get("Attacked") > 0) {
return false;
}
}

View File

@@ -18,10 +18,8 @@
package forge.game.phase;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -65,9 +63,8 @@ public class Combat {
private int nextDefender = 0;
// This Hash keeps track of
private final HashMap<Card, Object> attackerToDefender = new HashMap<Card, Object>();
private final HashMap<Card, Integer> attackerToDefender = new HashMap<Card, Integer>();
private int attackingDamage;
private Player attackingPlayer = null;
private Player defendingPlayer = null;
@@ -91,8 +88,6 @@ public class Combat {
this.blocked.clear();
this.unblockedMap.clear();
this.attackingDamage = 0;
this.defendingDamageMap.clear();
this.attackingPlayer = null;
@@ -128,7 +123,7 @@ public class Combat {
*
* @return a {@link java.lang.Object} object.
*/
public final Object nextDefender() {
public final GameEntity nextDefender() {
if (this.nextDefender >= this.defenders.size()) {
return null;
}
@@ -204,17 +199,6 @@ public class Combat {
return pwDefending;
}
/**
* <p>
* getDeclaredAttackers.
* </p>
*
* @return a int.
*/
public final int getDeclaredAttackers() {
return this.attackerToDefender.size();
}
/**
* <p>
* Setter for the field <code>attackingPlayer</code>.
@@ -280,26 +264,6 @@ public class Combat {
return this.defendingDamageMap;
}
/**
* <p>
* getTotalDefendingDamage.
* </p>
*
* @return a int.
*/
public final int getTotalDefendingDamage() {
int total = 0;
final Collection<Integer> c = this.defendingDamageMap.values();
final Iterator<Integer> itr = c.iterator();
while (itr.hasNext()) {
total += itr.next();
}
return total;
}
/**
* <p>
* setDefendingDamage.
@@ -369,11 +333,11 @@ public class Combat {
* a {@link forge.Card} object.
*/
public final void addDefendingDamage(final int n, final Card source) {
final String slot = this.getDefenderByAttacker(source).toString();
final Object o = this.defenders.get(Integer.parseInt(slot));
final int slot = this.getDefenderByAttacker(source);
final GameEntity ge = this.defenders.get(slot);
if (o instanceof Card) {
final Card pw = (Card) o;
if (ge instanceof Card) {
final Card pw = (Card) ge;
pw.addAssignedDamage(n, source);
return;
@@ -386,29 +350,6 @@ public class Combat {
}
}
/**
* <p>
* addAttackingDamage.
* </p>
*
* @param n
* a int.
*/
public final void addAttackingDamage(final int n) {
this.attackingDamage += n;
}
/**
* <p>
* Getter for the field <code>attackingDamage</code>.
* </p>
*
* @return a int.
*/
public final int getAttackingDamage() {
return this.attackingDamage;
}
/**
* <p>
* sortAttackerByDefender.
@@ -423,8 +364,7 @@ public class Combat {
}
for (final Card atk : this.attackerToDefender.keySet()) {
final Object o = this.attackerToDefender.get(atk);
final int i = Integer.parseInt(o.toString());
final int i = this.attackerToDefender.get(atk);
attackers[i].add(atk);
}
@@ -466,7 +406,7 @@ public class Combat {
* a {@link forge.Card} object.
* @return a {@link java.lang.Object} object.
*/
public final Object getDefenderByAttacker(final Card c) {
public final Integer getDefenderByAttacker(final Card c) {
return this.attackerToDefender.get(c);
}
@@ -527,7 +467,7 @@ public class Combat {
*/
public final void addBlocker(final Card attacker, final Card blocker) {
this.blocked.add(attacker);
this.getList(attacker).add(blocker);
this.getBlockerList(attacker).add(blocker);
}
/**
@@ -558,10 +498,10 @@ public class Combat {
* @return a {@link forge.CardList} object.
*/
public final CardList getBlockers(final Card attacker) {
if (this.getList(attacker) == null) {
if (this.getBlockerList(attacker) == null) {
return new CardList();
} else {
return new CardList(this.getList(attacker));
return new CardList(this.getBlockerList(attacker));
}
}
@@ -595,7 +535,7 @@ public class Combat {
* a {@link forge.Card} object.
* @return a {@link forge.CardList} object.
*/
private CardList getList(final Card attacker) {
private CardList getBlockerList(final Card attacker) {
return this.map.get(attacker);
}
@@ -616,7 +556,7 @@ public class Combat {
} else { // card is a blocker
for (final Card a : att) {
if (this.getBlockers(a).contains(c)) {
this.getList(a).remove(c);
this.getBlockerList(a).remove(c);
// TODO if Declare Blockers and Declare Blockers (Abilities)
// merge this logic needs to be tweaked
if ((this.getBlockers(a).size() == 0)
@@ -853,9 +793,7 @@ public class Combat {
}
} // for
// if attacker has no trample, and there's damage left, assign the
// rest
// to a random blocker
// if attacker has no trample, and there's damage left, assign the rest to a random blocker
if ((damage > 0) && !(c.hasKeyword("Trample") && killsAllBlockers)) {
final int index = CardUtil.getRandomIndex(block);
block.get(index).addAssignedDamage(damage, c);

View File

@@ -343,7 +343,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
break;
case COMBAT_BEGIN:
PhaseUtil.verifyCombat();
//PhaseUtil.verifyCombat();
PhaseUtil.handleCombatBegin();
break;