- Attempt to fix blocker targeting arrows without breaking the combat log.

This commit is contained in:
Agetian
2014-09-22 17:50:09 +00:00
parent 86ecc75dbe
commit b357f88a8c
3 changed files with 41 additions and 8 deletions

View File

@@ -244,7 +244,7 @@ public enum TargetingOverlay {
});
}
for (final CardView attackingCard : combat.getAttackers()) {
final Iterable<CardView> cards = combat.getBlockers(attackingCard);
final Iterable<CardView> cards = combat.getPlannedBlockers(attackingCard);
if (cards == null) continue;
for (final CardView blockingCard : cards) {
if (!attackingCard.equals(c) && !blockingCard.equals(c)) { continue; }

View File

@@ -24,6 +24,9 @@ public class CombatView {
private Map<Iterable<CardView>, GameEntityView> bandsWithDefenders = Maps.newHashMap();
private Map<Iterable<CardView>, Iterable<CardView>> bandsWithBlockers = Maps.newHashMap();
private Map<CardView, Iterable<CardView>> attackersWithPlannedBlockers = Maps.newHashMap();
private Map<Iterable<CardView>, Iterable<CardView>> bandsWithPlannedBlockers = Maps.newHashMap();
public CombatView() {
}
@@ -68,6 +71,15 @@ public class CombatView {
return attackersWithBlockers.get(attacker);
}
/**
* @param attacker
* @return the blockers associated with an attacker, or {@code null} if the
* attacker is unblocked (planning stage, for targeting overlay).
*/
public Iterable<CardView> getPlannedBlockers(final CardView attacker) {
return attackersWithPlannedBlockers.get(attacker);
}
/**
* Get an {@link Iterable} of the blockers of the specified band, or
* {@code null} if that band is unblocked.
@@ -80,6 +92,18 @@ public class CombatView {
return bandsWithBlockers.get(attackingBand);
}
/**
* Get an {@link Iterable} of the blockers of the specified band, or
* {@code null} if that band is unblocked (planning stage, for targeting overlay).
*
* @param attackingBand
* an {@link Iterable} representing an attacking band.
* @return an {@link Iterable} of {@link CardView} objects, or {@code null}.
*/
public Iterable<CardView> getPlannedBlockers(final Iterable<CardView> attackingBand) {
return bandsWithPlannedBlockers.get(attackingBand);
}
public Iterable<CardView> getAttackersOf(final GameEntityView defender) {
return Maps.filterValues(attackersWithDefenders, Predicates.equalTo(defender)).keySet();
}
@@ -87,21 +111,29 @@ public class CombatView {
return Maps.filterValues(bandsWithDefenders, Predicates.equalTo(defender)).keySet();
}
public void addAttackingBand(final Iterable<CardView> attackingBand, final GameEntityView defender, final Iterable<CardView> blockers) {
final List<CardView> attackingBandCopy = Lists.newArrayList(attackingBand),
blockersCopy;
if (blockers == null) {
blockersCopy = null;
} else {
public void addPlannedBlockers(final CardView attacker, final Iterable<CardView> blockers) {
List<CardView> blockersCopy = null;
if (blockers != null) {
blockersCopy = Lists.newArrayList(blockers);
}
this.attackersWithPlannedBlockers.put(attacker, blockersCopy);
}
public void addAttackingBand(final Iterable<CardView> attackingBand, final GameEntityView defender, final Iterable<CardView> blockers, final Iterable<CardView> plannedBlockers) {
final List<CardView> attackingBandCopy = Lists.newArrayList(attackingBand),
blockersCopy, plannedBlockersCopy;
blockersCopy = blockers == null ? null : Lists.newArrayList(blockers);
plannedBlockersCopy = plannedBlockers == null ? null : Lists.newArrayList(plannedBlockers);
for (final CardView attacker : attackingBandCopy) {
this.attackersWithDefenders.put(attacker, defender);
this.attackersWithBlockers.put(attacker, blockersCopy);
this.attackersWithPlannedBlockers.put(attacker, plannedBlockersCopy);
}
this.bandsWithDefenders.put(attackingBandCopy, defender);
this.bandsWithBlockers.put(attackingBandCopy, blockersCopy);
this.bandsWithPlannedBlockers.put(attackingBandCopy, plannedBlockersCopy);
}
}

View File

@@ -184,7 +184,8 @@ public abstract class LocalGameView implements IGameView {
combatView.addAttackingBand(
getCardViews(b.getAttackers()),
getGameEntityView(defender),
blockers == null || !isBlocked ? null : getCardViews(blockers));
blockers == null || !isBlocked ? null : getCardViews(blockers),
blockers == null ? null : getCardViews(blockers));
}
return combatView;
}