diff --git a/forge-game/src/main/java/forge/game/combat/CombatView.java b/forge-game/src/main/java/forge/game/combat/CombatView.java index cc03b9b4aa0..cad7e80b3f1 100644 --- a/forge-game/src/main/java/forge/game/combat/CombatView.java +++ b/forge-game/src/main/java/forge/game/combat/CombatView.java @@ -2,44 +2,44 @@ package forge.game.combat; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; + import forge.game.GameEntityView; import forge.game.card.CardView; import forge.trackable.TrackableObject; import forge.trackable.TrackableProperty; +import forge.util.FCollection; public class CombatView extends TrackableObject { public CombatView() { super(-1); //ID not needed set(TrackableProperty.AttackersWithDefenders, new HashMap()); - set(TrackableProperty.AttackersWithBlockers, new HashMap>()); - set(TrackableProperty.BandsWithDefenders, new HashMap, GameEntityView>()); - set(TrackableProperty.BandsWithBlockers, new HashMap, Iterable>()); - set(TrackableProperty.AttackersWithPlannedBlockers, new HashMap>()); - set(TrackableProperty.BandsWithPlannedBlockers, new HashMap, Iterable>()); + set(TrackableProperty.AttackersWithBlockers, new HashMap>()); + set(TrackableProperty.BandsWithDefenders, new HashMap, GameEntityView>()); + set(TrackableProperty.BandsWithBlockers, new HashMap, FCollection>()); + set(TrackableProperty.AttackersWithPlannedBlockers, new HashMap>()); + set(TrackableProperty.BandsWithPlannedBlockers, new HashMap, FCollection>()); } private Map getAttackersWithDefenders() { return get(TrackableProperty.AttackersWithDefenders); } - private Map> getAttackersWithBlockers() { + private Map> getAttackersWithBlockers() { return get(TrackableProperty.AttackersWithBlockers); } - private Map, GameEntityView> getBandsWithDefenders() { + private Map, GameEntityView> getBandsWithDefenders() { return get(TrackableProperty.BandsWithDefenders); } - private Map, Iterable> getBandsWithBlockers() { + private Map, FCollection> getBandsWithBlockers() { return get(TrackableProperty.BandsWithBlockers); } - private Map> getAttackersWithPlannedBlockers() { + private Map> getAttackersWithPlannedBlockers() { return get(TrackableProperty.AttackersWithPlannedBlockers); } - private Map, Iterable> getBandsWithPlannedBlockers() { + private Map, FCollection> getBandsWithPlannedBlockers() { return get(TrackableProperty.BandsWithPlannedBlockers); } @@ -64,7 +64,7 @@ public class CombatView extends TrackableObject { } public boolean isBlocking(final CardView card) { - for (final Iterable blockers : getAttackersWithBlockers().values()) { + for (final FCollection blockers : getAttackersWithBlockers().values()) { if (blockers == null) { continue; } @@ -80,7 +80,7 @@ public class CombatView extends TrackableObject { * @return the blockers associated with an attacker, or {@code null} if the * attacker is unblocked. */ - public Iterable getBlockers(final CardView attacker) { + public FCollection getBlockers(final CardView attacker) { return getAttackersWithBlockers().get(attacker); } @@ -89,7 +89,7 @@ public class CombatView extends TrackableObject { * @return the blockers associated with an attacker, or {@code null} if the * attacker is unblocked (planning stage, for targeting overlay). */ - public Iterable getPlannedBlockers(final CardView attacker) { + public FCollection getPlannedBlockers(final CardView attacker) { return getAttackersWithPlannedBlockers().get(attacker); } @@ -101,7 +101,7 @@ public class CombatView extends TrackableObject { * an {@link Iterable} representing an attacking band. * @return an {@link Iterable} of {@link CardView} objects, or {@code null}. */ - public Iterable getBlockers(final Iterable attackingBand) { + public FCollection getBlockers(final FCollection attackingBand) { return getBandsWithBlockers().get(attackingBand); } @@ -113,12 +113,12 @@ public class CombatView extends TrackableObject { * an {@link Iterable} representing an attacking band. * @return an {@link Iterable} of {@link CardView} objects, or {@code null}. */ - public Iterable getPlannedBlockers(final Iterable attackingBand) { + public FCollection getPlannedBlockers(final FCollection attackingBand) { return getBandsWithPlannedBlockers().get(attackingBand); } - public Iterable getAttackersOf(final GameEntityView defender) { - ArrayList views = new ArrayList(); + public FCollection getAttackersOf(final GameEntityView defender) { + FCollection views = new FCollection(); for (Entry entry : getAttackersWithDefenders().entrySet()) { if (entry.getValue().equals(defender)) { views.add(entry.getKey()); @@ -126,9 +126,9 @@ public class CombatView extends TrackableObject { } return views; } - public Iterable> getAttackingBandsOf(final GameEntityView defender) { - ArrayList> views = new ArrayList>(); - for (Entry, GameEntityView> entry : getBandsWithDefenders().entrySet()) { + public Iterable> getAttackingBandsOf(final GameEntityView defender) { + ArrayList> views = new ArrayList>(); + for (Entry, GameEntityView> entry : getBandsWithDefenders().entrySet()) { if (entry.getValue().equals(defender)) { views.add(entry.getKey()); } @@ -137,9 +137,17 @@ public class CombatView extends TrackableObject { } public void addAttackingBand(final Iterable attackingBand, final GameEntityView defender, final Iterable blockers, final Iterable plannedBlockers) { - final List attackingBandCopy = Lists.newArrayList(attackingBand); - final List blockersCopy = blockers == null ? null : Lists.newArrayList(blockers); - final List plannedBlockersCopy = plannedBlockers == null ? null : Lists.newArrayList(plannedBlockers); + final FCollection attackingBandCopy = new FCollection(); + final FCollection blockersCopy = new FCollection(); + final FCollection plannedBlockersCopy = new FCollection(); + + attackingBandCopy.addAll(attackingBand); + if (blockers != null) { + blockersCopy.addAll(blockers); + } + if (plannedBlockers != null) { + plannedBlockersCopy.addAll(plannedBlockers); + } for (final CardView attacker : attackingBandCopy) { this.getAttackersWithDefenders().put(attacker, defender); diff --git a/forge-game/src/main/java/forge/trackable/TrackableProperty.java b/forge-game/src/main/java/forge/trackable/TrackableProperty.java index 080fa4a488c..3165871cbf7 100644 --- a/forge-game/src/main/java/forge/trackable/TrackableProperty.java +++ b/forge-game/src/main/java/forge/trackable/TrackableProperty.java @@ -118,12 +118,12 @@ public enum TrackableProperty { OptionalTrigger(TrackableTypes.BooleanType), //Combat - AttackersWithDefenders(TrackableTypes.CardViewCollectionType), //TODO: change out for proper types when serialization needed - AttackersWithBlockers(TrackableTypes.CardViewCollectionType), - BandsWithDefenders(TrackableTypes.CardViewCollectionType), - BandsWithBlockers(TrackableTypes.CardViewCollectionType), - AttackersWithPlannedBlockers(TrackableTypes.CardViewCollectionType), - BandsWithPlannedBlockers(TrackableTypes.CardViewCollectionType), + AttackersWithDefenders(TrackableTypes.CardViewCollectionType, false), //TODO: change out for proper types when serialization needed + AttackersWithBlockers(TrackableTypes.CardViewCollectionType, false), + BandsWithDefenders(TrackableTypes.CardViewCollectionType, false), + BandsWithBlockers(TrackableTypes.CardViewCollectionType, false), + AttackersWithPlannedBlockers(TrackableTypes.CardViewCollectionType, false), + BandsWithPlannedBlockers(TrackableTypes.CardViewCollectionType, false), //Game GameType(TrackableTypes.EnumType(GameType.class)), diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java index b196f75401c..ebafb45d6f5 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java @@ -12,6 +12,7 @@ import forge.game.combat.CombatView; import forge.game.player.PlayerView; import forge.gui.framework.ICDoc; import forge.screens.match.views.VCombat; +import forge.util.FCollection; import forge.util.Lang; /** @@ -70,7 +71,7 @@ public enum CCombat implements ICDoc { private static String getCombatDescription(final CombatView localCombat, final GameEntityView defender) { final StringBuilder display = new StringBuilder(); - Iterable> bands = localCombat.getAttackingBandsOf(defender); + Iterable> bands = localCombat.getAttackingBandsOf(defender); if (bands == null || Iterables.isEmpty(bands)) { return StringUtils.EMPTY; } @@ -86,7 +87,7 @@ public enum CCombat implements ICDoc { // Associate Bands, Attackers Blockers boolean previousBand = false; - for (final Iterable band : bands) { + for (final FCollection band : bands) { final int bandSize = Iterables.size(band); if (bandSize == 0) { continue; @@ -97,7 +98,7 @@ public enum CCombat implements ICDoc { display.append("\n"); } - final Iterable blockers = localCombat.getBlockers(band); + final FCollection blockers = localCombat.getBlockers(band); final boolean blocked = (blockers != null); final boolean isBand = bandSize > 1; if (isBand) {