Merge branch 'network-play' into 'master'

Network play

See merge request core-developers/forge!854
This commit is contained in:
Sol
2018-08-13 15:09:27 +00:00
4 changed files with 81 additions and 12 deletions

View File

@@ -0,0 +1,26 @@
package forge.game.card;
import java.io.Serializable;
public class CardFaceView implements Serializable, Comparable<CardFaceView> {
private String name;
public CardFaceView(String faceName) {
this.name = faceName;
}
public String getName() { return name;}
public void setName(String name) {
this.name = name;
}
public String toString() {
return name;
}
@Override
public int compareTo(CardFaceView o) {
return this.getName().compareTo(o.getName());
}
}

View File

@@ -14,6 +14,7 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.card.CardStateName;
import forge.game.card.CardFaceView;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function;
@@ -160,18 +161,23 @@ public class GuiChoose {
if (sel instanceof InventoryItem) {
matchUI.setCard((InventoryItem) list.getSelectedValue());
return;
} else if (sel instanceof ICardFace) {
final ICardFace face = (ICardFace)sel;
PaperCard paper = FModel.getMagicDb().getCommonCards().getUniqueByName(face.getName());
} else if (sel instanceof ICardFace || sel instanceof CardFaceView) {
String faceName;
if (sel instanceof ICardFace) {
faceName = ((ICardFace) sel).getName();
} else {
faceName = ((CardFaceView) sel).getName();
}
PaperCard paper = FModel.getMagicDb().getCommonCards().getUniqueByName(faceName);
if (paper == null) {
paper = FModel.getMagicDb().getVariantCards().getUniqueByName(face.getName());
paper = FModel.getMagicDb().getVariantCards().getUniqueByName(faceName);
}
if (paper != null) {
Card c = Card.getCardForUi(paper);
boolean foundState = false;
for (CardStateName cs : c.getStates()) {
if (c.getState(cs).getName().equals(face.getName())) {
if (c.getState(cs).getName().equals(faceName)) {
foundState = true;
c.setState(cs, true);
matchUI.setCard(c.getView());

View File

@@ -1,5 +1,6 @@
package forge.net;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
@@ -22,6 +23,7 @@ import forge.match.NextGameDecision;
import forge.trackable.TrackableCollection;
import forge.util.ITriggerEvent;
import forge.util.ReflectionUtil;
import org.apache.commons.lang3.SerializationUtils;
/**
* The methods that can be sent through this protocol.
@@ -155,6 +157,11 @@ public enum ProtocolMethod {
if (!ReflectionUtil.isInstance(arg, type)) {
throw new InternalError(String.format("Protocol method %s: illegal argument (%d) of type %s, %s expected", name(), iArg, arg.getClass().getName(), type.getName()));
}
if (arg != null) {
// attempt to Serialize each argument, this will throw an exception if it can't.
byte[] serialized = SerializationUtils.serialize((Serializable)arg);
SerializationUtils.deserialize(serialized);
}
}
}

View File

@@ -7,6 +7,7 @@ import com.google.common.collect.*;
import forge.FThreads;
import forge.GuiBase;
import forge.LobbyPlayer;
import forge.StaticData;
import forge.achievement.AchievementCollection;
import forge.ai.GameState;
import forge.assets.FSkinProp;
@@ -1387,12 +1388,17 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public List<AbilitySub> chooseModeForAbility(final SpellAbility sa, final int min, final int num,
boolean allowRepeat) {
final List<AbilitySub> choices = CharmEffect.makePossibleOptions(sa);
final List<AbilitySub> possible = CharmEffect.makePossibleOptions(sa);
HashMap<SpellAbilityView, AbilitySub> spellViewCache = new HashMap<>();
for (AbilitySub spellAbility : possible) {
spellViewCache.put(spellAbility.getView(), spellAbility);
}
final List<SpellAbilityView> choices = new ArrayList<>(spellViewCache.keySet());
final String modeTitle = TextUtil.concatNoSpace(sa.getActivatingPlayer().toString(), " activated ",
sa.getHostCard().toString(), " - Choose a mode");
final List<AbilitySub> chosen = Lists.newArrayListWithCapacity(num);
for (int i = 0; i < num; i++) {
AbilitySub a;
SpellAbilityView a;
if (i < min) {
a = getGui().one(modeTitle, choices);
} else {
@@ -1405,7 +1411,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (!allowRepeat) {
choices.remove(a);
}
chosen.add(a);
chosen.add(spellViewCache.get(a));
}
return chosen;
}
@@ -1465,8 +1471,15 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final String name) {
final Iterable<ICardFace> cardsFromDb = FModel.getMagicDb().getCommonCards().getAllFaces();
final List<ICardFace> cards = Lists.newArrayList(Iterables.filter(cardsFromDb, cpp));
Collections.sort(cards);
return getGui().one(message, cards);
CardFaceView cardFaceView;
List<CardFaceView> choices = new ArrayList<>();
for (ICardFace cardFace : cards) {
cardFaceView = new CardFaceView(cardFace.getName());
choices.add(cardFaceView);
}
Collections.sort(choices);
cardFaceView = getGui().one(message, choices);
return StaticData.instance().getCommonCards().getFaceByName(cardFaceView.getName());
}
@Override
@@ -2762,8 +2775,25 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public List<Card> chooseCardsForSplice(SpellAbility sa, List<Card> cards) {
return getGui().many("Choose cards to Splice onto", "Chosen Cards", 0, cards.size(), cards,
sa.getHostCard().getView());
HashMap<CardView, Card> mapCVtoC = new HashMap<>();
for (Card card : cards) {
mapCVtoC.put(card.getView(), card);
}
List<CardView> choices = new ArrayList<CardView>(mapCVtoC.keySet());
List<CardView> chosen;
chosen = getGui().many(
"Choose cards to Splice onto",
"Chosen Cards",
0,
choices.size(),
choices,
sa.getHostCard().getView()
);
List<Card> chosenCards = new ArrayList<Card>();
for (CardView cardView : chosen) {
chosenCards.add(mapCVtoC.get(cardView));
}
return chosenCards;
}
/*