Merge branch 'multiplayer' into 'master'

multiplayer fixes for graveyard and stack targeting

See merge request core-developers/forge!248
This commit is contained in:
Sol
2018-02-21 04:11:16 +00:00
2 changed files with 27 additions and 18 deletions

View File

@@ -20,7 +20,11 @@ public final class RemoteClient implements IToClient {
@Override @Override
public void send(final NetEvent event) { public void send(final NetEvent event) {
System.out.println("Sending event " + event + " to " + channel); System.out.println("Sending event " + event + " to " + channel);
channel.writeAndFlush(event); try {
channel.writeAndFlush(event).sync();
} catch (Exception e) {
e.printStackTrace();
}
} }
@Override @Override

View File

@@ -18,6 +18,7 @@
package forge.player; package forge.player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -29,9 +30,11 @@ import forge.game.GameEntity;
import forge.game.GameObject; import forge.game.GameObject;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardUtil; import forge.game.card.CardUtil;
import forge.game.card.CardView;
import forge.game.player.PlayerView; import forge.game.player.PlayerView;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityStackInstance; import forge.game.spellability.SpellAbilityStackInstance;
import forge.game.spellability.StackItemView;
import forge.game.spellability.TargetRestrictions; import forge.game.spellability.TargetRestrictions;
import forge.game.zone.Zone; import forge.game.zone.Zone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
@@ -170,20 +173,20 @@ public class TargetSelection {
// Send in a list of valid cards, and popup a choice box to target // Send in a list of valid cards, and popup a choice box to target
final Game game = ability.getActivatingPlayer().getGame(); final Game game = ability.getActivatingPlayer().getGame();
final List<Card> crdsBattle = Lists.newArrayList(); final List<CardView> crdsBattle = Lists.newArrayList();
final List<Card> crdsExile = Lists.newArrayList(); final List<CardView> crdsExile = Lists.newArrayList();
final List<Card> crdsGrave = Lists.newArrayList(); final List<CardView> crdsGrave = Lists.newArrayList();
final List<Card> crdsLibrary = Lists.newArrayList(); final List<CardView> crdsLibrary = Lists.newArrayList();
final List<Card> crdsStack = Lists.newArrayList(); final List<CardView> crdsStack = Lists.newArrayList();
final List<Card> crdsAnte = Lists.newArrayList(); final List<CardView> crdsAnte = Lists.newArrayList();
for (final Card inZone : choices) { for (final Card inZone : choices) {
Zone zz = game.getZoneOf(inZone); Zone zz = game.getZoneOf(inZone);
if (zz.is(ZoneType.Battlefield)) crdsBattle.add(inZone); if (zz.is(ZoneType.Battlefield)) crdsBattle.add(CardView.get(inZone));
else if (zz.is(ZoneType.Exile)) crdsExile.add(inZone); else if (zz.is(ZoneType.Exile)) crdsExile.add(CardView.get(inZone));
else if (zz.is(ZoneType.Graveyard)) crdsGrave.add(inZone); else if (zz.is(ZoneType.Graveyard)) crdsGrave.add(CardView.get(inZone));
else if (zz.is(ZoneType.Library)) crdsLibrary.add(inZone); else if (zz.is(ZoneType.Library)) crdsLibrary.add(CardView.get(inZone));
else if (zz.is(ZoneType.Stack)) crdsStack.add(inZone); else if (zz.is(ZoneType.Stack)) crdsStack.add(CardView.get(inZone));
else if (zz.is(ZoneType.Ante)) crdsAnte.add(inZone); else if (zz.is(ZoneType.Ante)) crdsAnte.add(CardView.get(inZone));
} }
List<Object> choicesFiltered = new ArrayList<Object>(); List<Object> choicesFiltered = new ArrayList<Object>();
if (!crdsBattle.isEmpty()) { if (!crdsBattle.isEmpty()) {
@@ -232,8 +235,8 @@ public class TargetSelection {
return true; return true;
} }
if (chosen instanceof Card) { if (chosen instanceof CardView) {
ability.getTargets().add((Card) chosen); ability.getTargets().add(game.getCard((CardView) chosen));
} }
return true; return true;
} }
@@ -243,6 +246,7 @@ public class TargetSelection {
final String message = tgt.getVTSelection(); final String message = tgt.getVTSelection();
// Find what's targetable, then allow human to choose // Find what's targetable, then allow human to choose
final List<Object> selectOptions = new ArrayList<Object>(); final List<Object> selectOptions = new ArrayList<Object>();
HashMap<StackItemView, SpellAbilityStackInstance> stackItemViewSpellAbilityHashMap = new HashMap<>();
final Game game = ability.getActivatingPlayer().getGame(); final Game game = ability.getActivatingPlayer().getGame();
for (final SpellAbilityStackInstance si : game.getStack()) { for (final SpellAbilityStackInstance si : game.getStack()) {
@@ -252,7 +256,8 @@ public class TargetSelection {
ability.resetTargets(); ability.resetTargets();
} }
else if (ability.canTargetSpellAbility(abilityOnStack)) { else if (ability.canTargetSpellAbility(abilityOnStack)) {
selectOptions.add(si); stackItemViewSpellAbilityHashMap.put(si.getView(), si);
selectOptions.add(si.getView());
} }
} }
@@ -275,8 +280,8 @@ public class TargetSelection {
if (madeChoice == null) { if (madeChoice == null) {
return false; return false;
} }
if (madeChoice instanceof SpellAbilityStackInstance) { if (madeChoice instanceof StackItemView) {
ability.getTargets().add(((SpellAbilityStackInstance)madeChoice).getSpellAbility(true)); ability.getTargets().add(stackItemViewSpellAbilityHashMap.get(madeChoice).getSpellAbility(true));
} }
else {// 'FINISH TARGETING' chosen else {// 'FINISH TARGETING' chosen
bTargetingDone = true; bTargetingDone = true;