mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
- More Cleanup in Combat class.
This commit is contained in:
@@ -20,9 +20,6 @@ package forge.card.trigger;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardList;
|
import forge.CardList;
|
||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
@@ -64,9 +61,7 @@ public class TriggerAttacks extends Trigger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.getMapParams().containsKey("Attacked")) {
|
if (this.getMapParams().containsKey("Attacked")) {
|
||||||
if (this.getMapParams().get("Attacked").equals("Player")
|
if (this.getMapParams().get("Attacked").equals("Player") && (Integer) runParams2.get("Attacked") > 0) {
|
||||||
&& StringUtils.isNumeric(runParams2.get("Attacked").toString())
|
|
||||||
&& (Integer.parseInt(runParams2.get("Attacked").toString()) > 0)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,8 @@
|
|||||||
package forge.game.phase;
|
package forge.game.phase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -65,9 +63,8 @@ public class Combat {
|
|||||||
private int nextDefender = 0;
|
private int nextDefender = 0;
|
||||||
|
|
||||||
// This Hash keeps track of
|
// 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 attackingPlayer = null;
|
||||||
private Player defendingPlayer = null;
|
private Player defendingPlayer = null;
|
||||||
@@ -91,8 +88,6 @@ public class Combat {
|
|||||||
this.blocked.clear();
|
this.blocked.clear();
|
||||||
|
|
||||||
this.unblockedMap.clear();
|
this.unblockedMap.clear();
|
||||||
|
|
||||||
this.attackingDamage = 0;
|
|
||||||
this.defendingDamageMap.clear();
|
this.defendingDamageMap.clear();
|
||||||
|
|
||||||
this.attackingPlayer = null;
|
this.attackingPlayer = null;
|
||||||
@@ -128,7 +123,7 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return a {@link java.lang.Object} object.
|
* @return a {@link java.lang.Object} object.
|
||||||
*/
|
*/
|
||||||
public final Object nextDefender() {
|
public final GameEntity nextDefender() {
|
||||||
if (this.nextDefender >= this.defenders.size()) {
|
if (this.nextDefender >= this.defenders.size()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -204,17 +199,6 @@ public class Combat {
|
|||||||
return pwDefending;
|
return pwDefending;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* getDeclaredAttackers.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return a int.
|
|
||||||
*/
|
|
||||||
public final int getDeclaredAttackers() {
|
|
||||||
return this.attackerToDefender.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Setter for the field <code>attackingPlayer</code>.
|
* Setter for the field <code>attackingPlayer</code>.
|
||||||
@@ -280,26 +264,6 @@ public class Combat {
|
|||||||
return this.defendingDamageMap;
|
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>
|
* <p>
|
||||||
* setDefendingDamage.
|
* setDefendingDamage.
|
||||||
@@ -369,11 +333,11 @@ public class Combat {
|
|||||||
* a {@link forge.Card} object.
|
* a {@link forge.Card} object.
|
||||||
*/
|
*/
|
||||||
public final void addDefendingDamage(final int n, final Card source) {
|
public final void addDefendingDamage(final int n, final Card source) {
|
||||||
final String slot = this.getDefenderByAttacker(source).toString();
|
final int slot = this.getDefenderByAttacker(source);
|
||||||
final Object o = this.defenders.get(Integer.parseInt(slot));
|
final GameEntity ge = this.defenders.get(slot);
|
||||||
|
|
||||||
if (o instanceof Card) {
|
if (ge instanceof Card) {
|
||||||
final Card pw = (Card) o;
|
final Card pw = (Card) ge;
|
||||||
pw.addAssignedDamage(n, source);
|
pw.addAssignedDamage(n, source);
|
||||||
|
|
||||||
return;
|
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>
|
* <p>
|
||||||
* sortAttackerByDefender.
|
* sortAttackerByDefender.
|
||||||
@@ -423,8 +364,7 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (final Card atk : this.attackerToDefender.keySet()) {
|
for (final Card atk : this.attackerToDefender.keySet()) {
|
||||||
final Object o = this.attackerToDefender.get(atk);
|
final int i = this.attackerToDefender.get(atk);
|
||||||
final int i = Integer.parseInt(o.toString());
|
|
||||||
attackers[i].add(atk);
|
attackers[i].add(atk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +406,7 @@ public class Combat {
|
|||||||
* a {@link forge.Card} object.
|
* a {@link forge.Card} object.
|
||||||
* @return a {@link java.lang.Object} 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);
|
return this.attackerToDefender.get(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +467,7 @@ public class Combat {
|
|||||||
*/
|
*/
|
||||||
public final void addBlocker(final Card attacker, final Card blocker) {
|
public final void addBlocker(final Card attacker, final Card blocker) {
|
||||||
this.blocked.add(attacker);
|
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.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public final CardList getBlockers(final Card attacker) {
|
public final CardList getBlockers(final Card attacker) {
|
||||||
if (this.getList(attacker) == null) {
|
if (this.getBlockerList(attacker) == null) {
|
||||||
return new CardList();
|
return new CardList();
|
||||||
} else {
|
} 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.
|
* a {@link forge.Card} object.
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
private CardList getList(final Card attacker) {
|
private CardList getBlockerList(final Card attacker) {
|
||||||
return this.map.get(attacker);
|
return this.map.get(attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,7 +556,7 @@ public class Combat {
|
|||||||
} else { // card is a blocker
|
} else { // card is a blocker
|
||||||
for (final Card a : att) {
|
for (final Card a : att) {
|
||||||
if (this.getBlockers(a).contains(c)) {
|
if (this.getBlockers(a).contains(c)) {
|
||||||
this.getList(a).remove(c);
|
this.getBlockerList(a).remove(c);
|
||||||
// TODO if Declare Blockers and Declare Blockers (Abilities)
|
// TODO if Declare Blockers and Declare Blockers (Abilities)
|
||||||
// merge this logic needs to be tweaked
|
// merge this logic needs to be tweaked
|
||||||
if ((this.getBlockers(a).size() == 0)
|
if ((this.getBlockers(a).size() == 0)
|
||||||
@@ -853,9 +793,7 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
} // for
|
} // for
|
||||||
|
|
||||||
// if attacker has no trample, and there's damage left, assign the
|
// if attacker has no trample, and there's damage left, assign the rest to a random blocker
|
||||||
// rest
|
|
||||||
// to a random blocker
|
|
||||||
if ((damage > 0) && !(c.hasKeyword("Trample") && killsAllBlockers)) {
|
if ((damage > 0) && !(c.hasKeyword("Trample") && killsAllBlockers)) {
|
||||||
final int index = CardUtil.getRandomIndex(block);
|
final int index = CardUtil.getRandomIndex(block);
|
||||||
block.get(index).addAssignedDamage(damage, c);
|
block.get(index).addAssignedDamage(damage, c);
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case COMBAT_BEGIN:
|
case COMBAT_BEGIN:
|
||||||
PhaseUtil.verifyCombat();
|
//PhaseUtil.verifyCombat();
|
||||||
PhaseUtil.handleCombatBegin();
|
PhaseUtil.handleCombatBegin();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user