mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Completely refactor the GUI code.
All direct references to a gui have been replaced by a field, allowing dynamic GUI assignment throughout the code (necessary for eg. network play). Fixes almost all errors. Untested.
This commit is contained in:
@@ -23,13 +23,10 @@ import forge.game.io.GameStateDeserializer;
|
||||
import forge.game.io.GameStateSerializer;
|
||||
import forge.game.io.IGameStateObject;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* GameLog class.
|
||||
@@ -64,7 +61,6 @@ public class GameLog extends Observable implements IGameStateObject {
|
||||
* Instantiates a new game log.
|
||||
*/
|
||||
public GameLog() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,11 +78,6 @@ public class GameLog extends Observable implements IGameStateObject {
|
||||
log.add(entry);
|
||||
this.setChanged();
|
||||
this.notifyObservers();
|
||||
}
|
||||
|
||||
public String getLogText(final GameLogEntryType logLevel) {
|
||||
List<GameLogEntry> filteredAndReversed = getLogEntries(logLevel);
|
||||
return StringUtils.join(filteredAndReversed, "\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.player.Player;
|
||||
@@ -9,6 +11,7 @@ import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetChoices;
|
||||
import forge.game.zone.MagicStack;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@@ -87,8 +90,8 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
|
||||
SpellAbility changingTgtSA = changingTgtSI.getSpellAbility();
|
||||
if (sa.hasParam("RandomTarget")){
|
||||
changingTgtSA.resetTargets();
|
||||
List<GameObject> candidates = changingTgtSA.getTargetRestrictions().getAllCandidates(changingTgtSA, true);
|
||||
GameObject choice = Aggregates.random(candidates);
|
||||
List<GameEntity> candidates = changingTgtSA.getTargetRestrictions().getAllCandidates(changingTgtSA, true);
|
||||
GameEntity choice = Aggregates.random(candidates);
|
||||
changingTgtSA.getTargets().add(choice);
|
||||
changingTgtSI.updateTarget(changingTgtSA.getTargets());
|
||||
} else if (sa.hasParam("DefinedMagnet")){
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import forge.game.GameObject;
|
||||
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.card.Card;
|
||||
@@ -94,7 +95,7 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
if (targetedSA == null) {
|
||||
return;
|
||||
}
|
||||
List<GameObject> candidates = targetedSA.getTargetRestrictions().getAllCandidates(targetedSA, true);
|
||||
final List<GameEntity> candidates = targetedSA.getTargetRestrictions().getAllCandidates(targetedSA, true);
|
||||
if (sa.hasParam("CanTargetPlayer")) {
|
||||
// Radiate
|
||||
// Remove targeted players because getAllCandidates include all the valid players
|
||||
@@ -102,7 +103,7 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
candidates.remove(p);
|
||||
|
||||
mayChoseNewTargets = false;
|
||||
for (GameObject o : candidates) {
|
||||
for (GameEntity o : candidates) {
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndSrcCard(card, chosenSA.getHostCard(), chosenSA, true);
|
||||
copy.resetFirstTarget(o, targetedSA);
|
||||
copies.add(copy);
|
||||
@@ -110,7 +111,7 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
} else {// Precursor Golem, Ink-Treader Nephilim
|
||||
final String type = sa.getParam("CopyForEachCanTarget");
|
||||
List<Card> valid = new ArrayList<Card>();
|
||||
for (final Object o : candidates) {
|
||||
for (final GameEntity o : candidates) {
|
||||
if (o instanceof Card) {
|
||||
valid.add((Card) o);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ import forge.item.PaperCard;
|
||||
import forge.util.CollectionSuppliers;
|
||||
import forge.util.Expressions;
|
||||
import forge.util.Lang;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.maps.HashMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
@@ -1632,29 +1631,15 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO Write javadoc for this method.
|
||||
*
|
||||
* @param globalChanges
|
||||
* an ArrayList<CardColor>
|
||||
* @return a CardColor
|
||||
* @return a {@link ColorSet}.
|
||||
* @see CardCharacteristics#determineColor()
|
||||
*/
|
||||
public final ColorSet determineColor() {
|
||||
if (this.isImmutable()) {
|
||||
return ColorSet.getNullColor();
|
||||
}
|
||||
|
||||
List<CardColor> colorList = this.getCharacteristics().getCardColor();
|
||||
|
||||
byte colors = 0;
|
||||
for (int i = colorList.size() - 1;i >= 0;i--) {
|
||||
final CardColor cc = colorList.get(i);
|
||||
colors |= cc.getColorMask();
|
||||
if (!cc.isAdditional()) {
|
||||
return ColorSet.fromMask(colors);
|
||||
}
|
||||
}
|
||||
return ColorSet.fromMask(colors);
|
||||
return this.getCharacteristics().determineColor();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8244,13 +8229,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
* removed.
|
||||
*/
|
||||
public final void setRandomFoil() {
|
||||
CardEdition.FoilType foilType = CardEdition.FoilType.NOT_SUPPORTED;
|
||||
if (this.getCurSetCode() != null && StaticData.instance().getEditions().get(this.getCurSetCode()) != null) {
|
||||
foilType = StaticData.instance().getEditions().get(this.getCurSetCode()).getFoilType();
|
||||
}
|
||||
if (foilType != CardEdition.FoilType.NOT_SUPPORTED) {
|
||||
this.setFoil(foilType == CardEdition.FoilType.MODERN ? MyRandom.getRandom().nextInt(9) + 1 : MyRandom.getRandom().nextInt(9) + 11);
|
||||
}
|
||||
this.setFoil(CardEdition.getRandomFoil(this.getCurSetCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
package forge.game.card;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -432,7 +434,6 @@ public class CardCharacteristics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CardRarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
@@ -452,4 +453,22 @@ public class CardCharacteristics {
|
||||
this.curSetCode = curSetCode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the colors.
|
||||
*
|
||||
* @return a {@link ColorSet}.
|
||||
*/
|
||||
public final ColorSet determineColor() {
|
||||
final List<CardColor> colorList = this.getCardColor();
|
||||
byte colors = 0;
|
||||
for (int i = colorList.size() - 1;i >= 0;i--) {
|
||||
final CardColor cc = colorList.get(i);
|
||||
colors |= cc.getColorMask();
|
||||
if (!cc.isAdditional()) {
|
||||
return ColorSet.fromMask(colors);
|
||||
}
|
||||
}
|
||||
return ColorSet.fromMask(colors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.game.player;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import forge.LobbyPlayer;
|
||||
import forge.card.ColorSet;
|
||||
@@ -38,12 +39,10 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* A prototype for player controller class
|
||||
*
|
||||
@@ -83,11 +82,11 @@ public abstract class PlayerController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically pass priority until reaching the given phase of the current turn
|
||||
* @param phase
|
||||
* Automatically pass priority until reaching the Cleanup phase of the
|
||||
* current turn.
|
||||
*/
|
||||
public void autoPassUntil(PhaseType phase) {
|
||||
autoPassUntilPhase = phase;
|
||||
public void autoPassUntilEndOfTurn() {
|
||||
autoPassUntilPhase = PhaseType.CLEANUP;
|
||||
}
|
||||
|
||||
protected PhaseType getAutoPassUntilPhase() {
|
||||
@@ -118,14 +117,14 @@ public abstract class PlayerController {
|
||||
}
|
||||
|
||||
// Abilities to auto-yield to
|
||||
private Set<String> autoYields = new HashSet<String>();
|
||||
private final Set<String> autoYields = Sets.newHashSet();
|
||||
public Iterable<String> getAutoYields() {
|
||||
return autoYields;
|
||||
}
|
||||
public boolean shouldAutoYield(String key) {
|
||||
public boolean shouldAutoYield(final String key) {
|
||||
return autoYields.contains(key);
|
||||
}
|
||||
public void setShouldAutoYield(String key, boolean autoYield) {
|
||||
public void setShouldAutoYield(final String key, final boolean autoYield) {
|
||||
if (autoYield) {
|
||||
autoYields.add(key);
|
||||
}
|
||||
|
||||
@@ -17,21 +17,22 @@
|
||||
*/
|
||||
package forge.game.spellability;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.CardType;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Target class.
|
||||
@@ -473,9 +474,9 @@ public class TargetRestrictions {
|
||||
* Check Valid Candidates and Targeting
|
||||
* @return a List<Object>.
|
||||
*/
|
||||
public final List<GameObject> getAllCandidates(final SpellAbility sa, final boolean isTargeted) {
|
||||
public final List<GameEntity> getAllCandidates(final SpellAbility sa, final boolean isTargeted) {
|
||||
final Game game = sa.getActivatingPlayer().getGame();
|
||||
List<GameObject> candidates = new ArrayList<GameObject>();
|
||||
final List<GameEntity> candidates = Lists.newArrayList();
|
||||
for (Player player : game.getPlayers()) {
|
||||
if (sa.canTarget(player)) {
|
||||
candidates.add(player);
|
||||
|
||||
Reference in New Issue
Block a user