mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-12 16:58:57 +00:00
- Take 4. Avoid creating an extra CardCollection unless needed.
This commit is contained in:
@@ -2016,7 +2016,7 @@ public class ComputerUtilCombat {
|
|||||||
* @param defender
|
* @param defender
|
||||||
* @param overrideOrder overriding combatant order
|
* @param overrideOrder overriding combatant order
|
||||||
*/
|
*/
|
||||||
public static Map<Card, Integer> distributeAIDamage(final Player self, final Card attacker, final CardCollectionView block, final CardCollectionView remaining, int dmgCanDeal, GameEntity defender, boolean overrideOrder) {
|
public static Map<Card, Integer> distributeAIDamage(final Player self, final Card attacker, CardCollectionView block, final CardCollectionView remaining, int dmgCanDeal, GameEntity defender, boolean overrideOrder) {
|
||||||
Map<Card, Integer> damageMap = Maps.newHashMap();
|
Map<Card, Integer> damageMap = Maps.newHashMap();
|
||||||
Combat combat = attacker.getGame().getCombat();
|
Combat combat = attacker.getGame().getCombat();
|
||||||
|
|
||||||
@@ -2047,14 +2047,12 @@ public class ComputerUtilCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Order the combatants in preferred order in case legacy ordering is disabled
|
// Order the combatants in preferred order in case legacy ordering is disabled
|
||||||
final boolean legacyOrderCombatants = self.getGame().getRules().hasOrderCombatants();
|
if (!self.getGame().getRules().hasOrderCombatants()) {
|
||||||
CardCollection orderedBlockers = new CardCollection(block);
|
block = AiBlockController.orderBlockers(attacker, new CardCollection(block)); // assume sorted in case the legacy option is enabled
|
||||||
if (!legacyOrderCombatants) {
|
|
||||||
orderedBlockers = AiBlockController.orderBlockers(attacker, orderedBlockers); // assume sorted in case the legacy option is enabled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orderedBlockers.size() == 1) {
|
if (block.size() == 1) {
|
||||||
final Card blocker = orderedBlockers.getFirst();
|
final Card blocker = block.getFirst();
|
||||||
int dmgToBlocker = dmgCanDeal;
|
int dmgToBlocker = dmgCanDeal;
|
||||||
|
|
||||||
if (hasTrample && isAttacking && !aiDistributesBandingDmg) { // otherwise no entity to deliver damage via trample
|
if (hasTrample && isAttacking && !aiDistributesBandingDmg) { // otherwise no entity to deliver damage via trample
|
||||||
@@ -2077,7 +2075,7 @@ public class ComputerUtilCombat {
|
|||||||
// Does the attacker deal lethal damage to all blockers
|
// Does the attacker deal lethal damage to all blockers
|
||||||
//Blocking Order now determined after declare blockers
|
//Blocking Order now determined after declare blockers
|
||||||
Card lastBlocker = null;
|
Card lastBlocker = null;
|
||||||
for (final Card b : orderedBlockers) {
|
for (final Card b : block) {
|
||||||
lastBlocker = b;
|
lastBlocker = b;
|
||||||
final int dmgToKill = getEnoughDamageToKill(b, dmgCanDeal, attacker, true);
|
final int dmgToKill = getEnoughDamageToKill(b, dmgCanDeal, attacker, true);
|
||||||
if (dmgToKill <= dmgCanDeal) {
|
if (dmgToKill <= dmgCanDeal) {
|
||||||
@@ -2104,7 +2102,7 @@ public class ComputerUtilCombat {
|
|||||||
} else {
|
} else {
|
||||||
// In the event of Banding or Defensive Formation, assign max damage to the blocker who
|
// In the event of Banding or Defensive Formation, assign max damage to the blocker who
|
||||||
// can tank all the damage or to the worst blocker to lose as little as possible
|
// can tank all the damage or to the worst blocker to lose as little as possible
|
||||||
for (final Card b : orderedBlockers) {
|
for (final Card b : block) {
|
||||||
final int dmgToKill = getEnoughDamageToKill(b, dmgCanDeal, attacker, true);
|
final int dmgToKill = getEnoughDamageToKill(b, dmgCanDeal, attacker, true);
|
||||||
if (dmgToKill > dmgCanDeal) {
|
if (dmgToKill > dmgCanDeal) {
|
||||||
damageMap.put(b, dmgCanDeal);
|
damageMap.put(b, dmgCanDeal);
|
||||||
@@ -2112,7 +2110,7 @@ public class ComputerUtilCombat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (damageMap.isEmpty()) {
|
if (damageMap.isEmpty()) {
|
||||||
damageMap.put(ComputerUtilCard.getWorstCreatureAI(orderedBlockers), dmgCanDeal);
|
damageMap.put(ComputerUtilCard.getWorstCreatureAI(block), dmgCanDeal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return damageMap;
|
return damageMap;
|
||||||
|
|||||||
Reference in New Issue
Block a user