Combat class. @author Forge @version $Id$
| 57 | * @version $Id$ |
| 58 | */ |
| 59 | public class Combat { |
| 60 | private final Player playerWhoAttacks; |
| 61 | private boolean legacyOrderCombatants; |
| 62 | private AttackConstraints attackConstraints; |
| 63 | // Defenders, as they are attacked by hostile forces |
| 64 | private final Supplier<FCollection<GameEntity>> attackableEntries = Suppliers.memoize(FCollection::new); |
| 65 | // Keyed by attackable defender (player or planeswalker or battle) |
| 66 | private final Supplier<Multimap<GameEntity, AttackingBand>> attackedByBands = Suppliers.memoize(() -> Multimaps.synchronizedMultimap(ArrayListMultimap.create())); |
| 67 | private final Supplier<Multimap<AttackingBand, Card>> blockedBands = Suppliers.memoize(() -> Multimaps.synchronizedMultimap(ArrayListMultimap.create())); |
| 68 | private final Supplier<Map<Card, CardCollection>> attackersOrderedForDamageAssignment = Suppliers.memoize(Maps::newHashMap); |
| 69 | private final Supplier<Map<Card, CardCollection>> blockersOrderedForDamageAssignment = Suppliers.memoize(Maps::newHashMap); |
| 70 | private final Supplier<CardCollection> lkiCache = Suppliers.memoize(CardCollection::new); |
| 71 | private final Supplier<CardDamageTable> damageMap = Suppliers.memoize(CardDamageTable::new); |
| 72 | |
| 73 | // List holds creatures who have dealt 1st strike damage to disallow them deal damage on regular basis (unless they have double-strike KW) |
| 74 | private final Supplier<CardCollection> combatantsThatDealtFirstStrikeDamage = Suppliers.memoize(CardCollection::new); |
| 75 | |
| 76 | public Combat(final Player attacker) { |
| 77 | playerWhoAttacks = attacker; |
| 78 | legacyOrderCombatants = playerWhoAttacks.getGame().getRules().hasOrderCombatants(); |
| 79 | initConstraints(); |
| 80 | } |
| 81 | |
| 82 | public Combat(Combat combat, IEntityMap map) { |
| 83 | playerWhoAttacks = map.map(combat.playerWhoAttacks); |
| 84 | for (GameEntity entry : combat.attackableEntries.get()) { |
| 85 | attackableEntries.get().add(map.map(entry)); |
| 86 | } |
| 87 | |
| 88 | HashMap<AttackingBand, AttackingBand> bandsMap = new HashMap<>(); |
| 89 | for (Entry<GameEntity, AttackingBand> entry : combat.attackedByBands.get().entries()) { |
| 90 | AttackingBand origBand = entry.getValue(); |
| 91 | ArrayList<Card> attackers = new ArrayList<>(); |
| 92 | for (Card c : origBand.getAttackers()) { |
| 93 | attackers.add(map.map(c)); |
| 94 | } |
| 95 | AttackingBand newBand = new AttackingBand(attackers); |
| 96 | Boolean blocked = entry.getValue().isBlocked(); |
| 97 | if (blocked != null) { |
| 98 | newBand.setBlocked(blocked); |
| 99 | } |
| 100 | bandsMap.put(origBand, newBand); |
| 101 | attackedByBands.get().put(map.map(entry.getKey()), newBand); |
| 102 | } |
| 103 | for (Entry<AttackingBand, Card> entry : combat.blockedBands.get().entries()) { |
| 104 | blockedBands.get().put(bandsMap.get(entry.getKey()), map.map(entry.getValue())); |
| 105 | } |
| 106 | |
| 107 | for (Entry<Card, CardCollection> entry : combat.attackersOrderedForDamageAssignment.get().entrySet()) { |
| 108 | attackersOrderedForDamageAssignment.get().put(map.map(entry.getKey()), map.mapCollection(entry.getValue())); |
| 109 | } |
| 110 | for (Entry<Card, CardCollection> entry : combat.blockersOrderedForDamageAssignment.get().entrySet()) { |
| 111 | blockersOrderedForDamageAssignment.get().put(map.map(entry.getKey()), map.mapCollection(entry.getValue())); |
| 112 | } |
| 113 | // Note: Doesn't currently set up lkiCache, since it's just a cache and not strictly needed... |
| 114 | for (Table.Cell<Card, GameEntity, Integer> entry : combat.damageMap.get().cellSet()) { |
| 115 | damageMap.get().put(map.map(entry.getRowKey()), map.map(entry.getColumnKey()), entry.getValue()); |
| 116 | } |