mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Merge branch 'network-play' into 'master'
Network play See merge request core-developers/forge!854
This commit is contained in:
26
forge-game/src/main/java/forge/game/card/CardFaceView.java
Normal file
26
forge-game/src/main/java/forge/game/card/CardFaceView.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import javax.swing.event.ListSelectionEvent;
|
|||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
import forge.card.CardStateName;
|
import forge.card.CardStateName;
|
||||||
|
import forge.game.card.CardFaceView;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
@@ -160,18 +161,23 @@ public class GuiChoose {
|
|||||||
if (sel instanceof InventoryItem) {
|
if (sel instanceof InventoryItem) {
|
||||||
matchUI.setCard((InventoryItem) list.getSelectedValue());
|
matchUI.setCard((InventoryItem) list.getSelectedValue());
|
||||||
return;
|
return;
|
||||||
} else if (sel instanceof ICardFace) {
|
} else if (sel instanceof ICardFace || sel instanceof CardFaceView) {
|
||||||
final ICardFace face = (ICardFace)sel;
|
String faceName;
|
||||||
PaperCard paper = FModel.getMagicDb().getCommonCards().getUniqueByName(face.getName());
|
if (sel instanceof ICardFace) {
|
||||||
|
faceName = ((ICardFace) sel).getName();
|
||||||
|
} else {
|
||||||
|
faceName = ((CardFaceView) sel).getName();
|
||||||
|
}
|
||||||
|
PaperCard paper = FModel.getMagicDb().getCommonCards().getUniqueByName(faceName);
|
||||||
if (paper == null) {
|
if (paper == null) {
|
||||||
paper = FModel.getMagicDb().getVariantCards().getUniqueByName(face.getName());
|
paper = FModel.getMagicDb().getVariantCards().getUniqueByName(faceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paper != null) {
|
if (paper != null) {
|
||||||
Card c = Card.getCardForUi(paper);
|
Card c = Card.getCardForUi(paper);
|
||||||
boolean foundState = false;
|
boolean foundState = false;
|
||||||
for (CardStateName cs : c.getStates()) {
|
for (CardStateName cs : c.getStates()) {
|
||||||
if (c.getState(cs).getName().equals(face.getName())) {
|
if (c.getState(cs).getName().equals(faceName)) {
|
||||||
foundState = true;
|
foundState = true;
|
||||||
c.setState(cs, true);
|
c.setState(cs, true);
|
||||||
matchUI.setCard(c.getView());
|
matchUI.setCard(c.getView());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package forge.net;
|
package forge.net;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -22,6 +23,7 @@ import forge.match.NextGameDecision;
|
|||||||
import forge.trackable.TrackableCollection;
|
import forge.trackable.TrackableCollection;
|
||||||
import forge.util.ITriggerEvent;
|
import forge.util.ITriggerEvent;
|
||||||
import forge.util.ReflectionUtil;
|
import forge.util.ReflectionUtil;
|
||||||
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods that can be sent through this protocol.
|
* The methods that can be sent through this protocol.
|
||||||
@@ -155,6 +157,11 @@ public enum ProtocolMethod {
|
|||||||
if (!ReflectionUtil.isInstance(arg, type)) {
|
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()));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.google.common.collect.*;
|
|||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
import forge.GuiBase;
|
import forge.GuiBase;
|
||||||
import forge.LobbyPlayer;
|
import forge.LobbyPlayer;
|
||||||
|
import forge.StaticData;
|
||||||
import forge.achievement.AchievementCollection;
|
import forge.achievement.AchievementCollection;
|
||||||
import forge.ai.GameState;
|
import forge.ai.GameState;
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
@@ -1387,12 +1388,17 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
@Override
|
@Override
|
||||||
public List<AbilitySub> chooseModeForAbility(final SpellAbility sa, final int min, final int num,
|
public List<AbilitySub> chooseModeForAbility(final SpellAbility sa, final int min, final int num,
|
||||||
boolean allowRepeat) {
|
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 ",
|
final String modeTitle = TextUtil.concatNoSpace(sa.getActivatingPlayer().toString(), " activated ",
|
||||||
sa.getHostCard().toString(), " - Choose a mode");
|
sa.getHostCard().toString(), " - Choose a mode");
|
||||||
final List<AbilitySub> chosen = Lists.newArrayListWithCapacity(num);
|
final List<AbilitySub> chosen = Lists.newArrayListWithCapacity(num);
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
AbilitySub a;
|
SpellAbilityView a;
|
||||||
if (i < min) {
|
if (i < min) {
|
||||||
a = getGui().one(modeTitle, choices);
|
a = getGui().one(modeTitle, choices);
|
||||||
} else {
|
} else {
|
||||||
@@ -1405,7 +1411,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
if (!allowRepeat) {
|
if (!allowRepeat) {
|
||||||
choices.remove(a);
|
choices.remove(a);
|
||||||
}
|
}
|
||||||
chosen.add(a);
|
chosen.add(spellViewCache.get(a));
|
||||||
}
|
}
|
||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
@@ -1465,8 +1471,15 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
final String name) {
|
final String name) {
|
||||||
final Iterable<ICardFace> cardsFromDb = FModel.getMagicDb().getCommonCards().getAllFaces();
|
final Iterable<ICardFace> cardsFromDb = FModel.getMagicDb().getCommonCards().getAllFaces();
|
||||||
final List<ICardFace> cards = Lists.newArrayList(Iterables.filter(cardsFromDb, cpp));
|
final List<ICardFace> cards = Lists.newArrayList(Iterables.filter(cardsFromDb, cpp));
|
||||||
Collections.sort(cards);
|
CardFaceView cardFaceView;
|
||||||
return getGui().one(message, cards);
|
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
|
@Override
|
||||||
@@ -2762,8 +2775,25 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Card> chooseCardsForSplice(SpellAbility sa, List<Card> cards) {
|
public List<Card> chooseCardsForSplice(SpellAbility sa, List<Card> cards) {
|
||||||
return getGui().many("Choose cards to Splice onto", "Chosen Cards", 0, cards.size(), cards,
|
HashMap<CardView, Card> mapCVtoC = new HashMap<>();
|
||||||
sa.getHostCard().getView());
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user