mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
- Cleanup GameRules (mostly make a variable private)
- Minor cleanup in some other files
This commit is contained in:
@@ -233,7 +233,7 @@ public class Game {
|
|||||||
*/
|
*/
|
||||||
public final FCollectionView<Player> getNonactivePlayers() {
|
public final FCollectionView<Player> getNonactivePlayers() {
|
||||||
// Don't use getPlayersInTurnOrder to prevent copying the player collection twice
|
// Don't use getPlayersInTurnOrder to prevent copying the player collection twice
|
||||||
final FCollection<Player> players = new FCollection<Player>(ingamePlayers);;
|
final FCollection<Player> players = new FCollection<>(ingamePlayers);
|
||||||
players.remove(phaseHandler.getPlayerTurn());
|
players.remove(phaseHandler.getPlayerTurn());
|
||||||
if (!turnOrder.isDefaultDirection()) {
|
if (!turnOrder.isDefaultDirection()) {
|
||||||
Collections.reverse(players);
|
Collections.reverse(players);
|
||||||
@@ -636,12 +636,12 @@ public class Game {
|
|||||||
List<CardRarity> validRarities = new ArrayList<>(Arrays.asList(CardRarity.values()));
|
List<CardRarity> validRarities = new ArrayList<>(Arrays.asList(CardRarity.values()));
|
||||||
for (final Player player : getPlayers()) {
|
for (final Player player : getPlayers()) {
|
||||||
final Set<CardRarity> playerRarity = getValidRarities(player.getCardsIn(ZoneType.Library));
|
final Set<CardRarity> playerRarity = getValidRarities(player.getCardsIn(ZoneType.Library));
|
||||||
if (onePlayerHasTimeShifted == false) {
|
if (!onePlayerHasTimeShifted) {
|
||||||
onePlayerHasTimeShifted = playerRarity.contains(CardRarity.Special);
|
onePlayerHasTimeShifted = playerRarity.contains(CardRarity.Special);
|
||||||
}
|
}
|
||||||
validRarities.retainAll(playerRarity);
|
validRarities.retainAll(playerRarity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validRarities.size() == 0) { //If no possible rarity matches were found, use the original method to choose antes
|
if (validRarities.size() == 0) { //If no possible rarity matches were found, use the original method to choose antes
|
||||||
for (Player player : getPlayers()) {
|
for (Player player : getPlayers()) {
|
||||||
chooseRandomCardsForAnte(player, anteed);
|
chooseRandomCardsForAnte(player, anteed);
|
||||||
|
|||||||
@@ -4,19 +4,19 @@ import java.util.EnumSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class GameRules {
|
public class GameRules {
|
||||||
private GameType gameType;
|
private final GameType gameType;
|
||||||
private boolean manaBurn;
|
private boolean manaBurn;
|
||||||
private int poisonCountersToLose = 10; // is commonly 10, but turns into 15 for 2HG
|
private int poisonCountersToLose = 10; // is commonly 10, but turns into 15 for 2HG
|
||||||
private int gamesPerMatch = 3;
|
private int gamesPerMatch = 3;
|
||||||
private int gamesToWinMatch = 2;
|
private int gamesToWinMatch = 2;
|
||||||
private boolean playForAnte = false;
|
private boolean playForAnte = false;
|
||||||
private boolean matchAnteRarity = false;
|
private boolean matchAnteRarity = false;
|
||||||
private EnumSet<GameType> appliedVariants = EnumSet.noneOf(GameType.class);
|
private final Set<GameType> appliedVariants = EnumSet.noneOf(GameType.class);
|
||||||
|
|
||||||
// it's a preference, not rule... but I could hardly find a better place for it
|
// it's a preference, not rule... but I could hardly find a better place for it
|
||||||
public boolean canCloneUseTargetsImage;
|
private boolean canCloneUseTargetsImage;
|
||||||
|
|
||||||
public GameRules(GameType type) {
|
public GameRules(final GameType type) {
|
||||||
this.gameType = type;
|
this.gameType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,28 +24,19 @@ public class GameRules {
|
|||||||
return gameType;
|
return gameType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the manaBurn
|
|
||||||
*/
|
|
||||||
public boolean hasManaBurn() {
|
public boolean hasManaBurn() {
|
||||||
return manaBurn;
|
return manaBurn;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param manaBurn the manaBurn to set
|
public void setManaBurn(final boolean manaBurn) {
|
||||||
*/
|
|
||||||
public void setManaBurn(boolean manaBurn) {
|
|
||||||
this.manaBurn = manaBurn;
|
this.manaBurn = manaBurn;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @return the poisonCountersToLose
|
|
||||||
*/
|
|
||||||
public int getPoisonCountersToLose() {
|
public int getPoisonCountersToLose() {
|
||||||
return poisonCountersToLose;
|
return poisonCountersToLose;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param poisonCountersToLose the poisonCountersToLose to set
|
public void setPoisonCountersToLose(final int amount) {
|
||||||
*/
|
|
||||||
public void setPoisonCountersToLose(int amount) {
|
|
||||||
this.poisonCountersToLose = amount;
|
this.poisonCountersToLose = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +44,7 @@ public class GameRules {
|
|||||||
return gamesPerMatch;
|
return gamesPerMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGamesPerMatch(int gamesPerMatch) {
|
public void setGamesPerMatch(final int gamesPerMatch) {
|
||||||
this.gamesPerMatch = gamesPerMatch;
|
this.gamesPerMatch = gamesPerMatch;
|
||||||
this.gamesToWinMatch = gamesPerMatch / 2 + 1;
|
this.gamesToWinMatch = gamesPerMatch / 2 + 1;
|
||||||
}
|
}
|
||||||
@@ -62,7 +53,7 @@ public class GameRules {
|
|||||||
return playForAnte;
|
return playForAnte;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayForAnte(boolean useAnte) {
|
public void setPlayForAnte(final boolean useAnte) {
|
||||||
this.playForAnte = useAnte;
|
this.playForAnte = useAnte;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +61,7 @@ public class GameRules {
|
|||||||
return matchAnteRarity;
|
return matchAnteRarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMatchAnteRarity(boolean matchRarity) {
|
public void setMatchAnteRarity(final boolean matchRarity) {
|
||||||
matchAnteRarity = matchRarity;
|
matchAnteRarity = matchRarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,15 +69,22 @@ public class GameRules {
|
|||||||
return gamesToWinMatch;
|
return gamesToWinMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAppliedVariants(Set<GameType> appliedVariants) {
|
public void setAppliedVariants(final Set<GameType> appliedVariants) {
|
||||||
this.appliedVariants.addAll(appliedVariants);
|
this.appliedVariants.addAll(appliedVariants);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAppliedVariant(GameType variant) {
|
public boolean hasAppliedVariant(final GameType variant) {
|
||||||
return appliedVariants.contains(variant);
|
return appliedVariants.contains(variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCommander() {
|
public boolean hasCommander() {
|
||||||
return appliedVariants.contains(GameType.Commander) || appliedVariants.contains(GameType.TinyLeaders);
|
return appliedVariants.contains(GameType.Commander) || appliedVariants.contains(GameType.TinyLeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canCloneUseTargetsImage() {
|
||||||
|
return canCloneUseTargetsImage;
|
||||||
|
}
|
||||||
|
public void setCanCloneUseTargetsImage(final boolean canCloneUseTargetsImage) {
|
||||||
|
this.canCloneUseTargetsImage = canCloneUseTargetsImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class CloneEffect extends SpellAbilityEffect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// determine the image to be used for the clone
|
// determine the image to be used for the clone
|
||||||
String imageFileName = cardToCopy.getGame().getRules().canCloneUseTargetsImage ? tgtCard.getImageKey() : cardToCopy.getImageKey();
|
String imageFileName = cardToCopy.getGame().getRules().canCloneUseTargetsImage() ? tgtCard.getImageKey() : cardToCopy.getImageKey();
|
||||||
if (sa.hasParam("ImageSource")) { // Allow the image to be stipulated by using a defined card source
|
if (sa.hasParam("ImageSource")) { // Allow the image to be stipulated by using a defined card source
|
||||||
List<Card> cloneImgSources = AbilityUtils.getDefinedCards(host, sa.getParam("ImageSource"), sa);
|
List<Card> cloneImgSources = AbilityUtils.getDefinedCards(host, sa.getParam("ImageSource"), sa);
|
||||||
if (!cloneImgSources.isEmpty()) {
|
if (!cloneImgSources.isEmpty()) {
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
package forge.game.ability.effects;
|
package forge.game.ability.effects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.card.CardStateName;
|
|
||||||
import forge.card.CardRulesPredicates;
|
import forge.card.CardRulesPredicates;
|
||||||
|
import forge.card.CardStateName;
|
||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -27,39 +23,38 @@ import forge.game.zone.ZoneType;
|
|||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlayLandVariantEffect extends SpellAbilityEffect {
|
public class PlayLandVariantEffect extends SpellAbilityEffect {
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve(SpellAbility sa) {
|
public void resolve(final SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
Player activator = sa.getActivatingPlayer();
|
final Player activator = sa.getActivatingPlayer();
|
||||||
final Game game = source.getGame();
|
final Game game = source.getGame();
|
||||||
final String landType = sa.getParam("Clone");
|
final String landType = sa.getParam("Clone");
|
||||||
List<PaperCard> cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
|
List<PaperCard> cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
|
||||||
if ("BasicLand".equals(landType)) {
|
if ("BasicLand".equals(landType)) {
|
||||||
Predicate<PaperCard> cpp = Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, PaperCard.FN_GET_RULES);
|
final Predicate<PaperCard> cpp = Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, PaperCard.FN_GET_RULES);
|
||||||
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
|
||||||
}
|
}
|
||||||
// current color of source card
|
// current color of source card
|
||||||
ColorSet color = CardUtil.getColors(source);
|
final ColorSet color = CardUtil.getColors(source);
|
||||||
if (color.isColorless()) {
|
if (color.isColorless()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// find basic lands that can produce mana of one of the card's colors
|
// find basic lands that can produce mana of one of the card's colors
|
||||||
final List<String> landnames = new ArrayList<String>();
|
final List<String> landNames = Lists.newArrayList();
|
||||||
for (byte i = 0; i < MagicColor.WUBRG.length; i++) {
|
for (byte i = 0; i < MagicColor.WUBRG.length; i++) {
|
||||||
if (color.hasAnyColor(MagicColor.WUBRG[i])) {
|
if (color.hasAnyColor(MagicColor.WUBRG[i])) {
|
||||||
landnames.add(MagicColor.Constant.BASIC_LANDS.get(i));
|
landNames.add(MagicColor.Constant.BASIC_LANDS.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Predicate<PaperCard> cp = Predicates.compose(new Predicate<String>() {
|
final Predicate<PaperCard> cp = Predicates.compose(new Predicate<String>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final String name) {
|
public boolean apply(final String name) {
|
||||||
return landnames.contains(name);
|
return landNames.contains(name);
|
||||||
}
|
}
|
||||||
}, PaperCard.FN_GET_NAME);
|
}, PaperCard.FN_GET_NAME);
|
||||||
cards = Lists.newArrayList(Iterables.filter(cards, cp));
|
cards = Lists.newArrayList(Iterables.filter(cards, cp));
|
||||||
@@ -74,12 +69,12 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
|
|||||||
random = CardFactory.getCard(ran, activator, game);
|
random = CardFactory.getCard(ran, activator, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
String imageFileName = game.getRules().canCloneUseTargetsImage ? source.getImageKey() : random.getImageKey();
|
final String imageFileName = game.getRules().canCloneUseTargetsImage() ? source.getImageKey() : random.getImageKey();
|
||||||
source.addAlternateState(CardStateName.Cloner, false);
|
source.addAlternateState(CardStateName.Cloner, false);
|
||||||
source.switchStates(CardStateName.Original, CardStateName.Cloner, false);
|
source.switchStates(CardStateName.Original, CardStateName.Cloner, false);
|
||||||
source.setState(CardStateName.Original, false);
|
source.setState(CardStateName.Original, false);
|
||||||
source.updateStateForView();
|
source.updateStateForView();
|
||||||
CardStateName stateToCopy = random.getCurrentStateName();
|
final CardStateName stateToCopy = random.getCurrentStateName();
|
||||||
CardFactory.copyState(random, stateToCopy, source, source.getCurrentStateName());
|
CardFactory.copyState(random, stateToCopy, source, source.getCurrentStateName());
|
||||||
source.setImageKey(imageFileName);
|
source.setImageKey(imageFileName);
|
||||||
|
|
||||||
@@ -90,7 +85,7 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
|
|||||||
game.fireEvent(new GameEventLandPlayed(activator, source));
|
game.fireEvent(new GameEventLandPlayed(activator, source));
|
||||||
|
|
||||||
// Run triggers
|
// Run triggers
|
||||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
final Map<String, Object> runParams = Maps.newHashMap();
|
||||||
runParams.put("Card", source);
|
runParams.put("Card", source);
|
||||||
game.getTriggerHandler().runTrigger(TriggerType.LandPlayed, runParams, false);
|
game.getTriggerHandler().runTrigger(TriggerType.LandPlayed, runParams, false);
|
||||||
game.getStack().unfreezeStack();
|
game.getStack().unfreezeStack();
|
||||||
|
|||||||
@@ -1058,7 +1058,7 @@ public class FSkin {
|
|||||||
final File f = new File(preferredDir + ForgeConstants.SPLASH_BG_FILE);
|
final File f = new File(preferredDir + ForgeConstants.SPLASH_BG_FILE);
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
if (skinName.equals("default")) {
|
if (skinName.equals("default")) {
|
||||||
throw new RuntimeException("Cannot find default skin.");
|
throw new RuntimeException(String.format("Cannot find default skin at %s", f.getAbsolutePath()));
|
||||||
}
|
}
|
||||||
loadLight("default", true);
|
loadLight("default", true);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class HostedMatch {
|
|||||||
gameRules.setPlayForAnte(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE));
|
gameRules.setPlayForAnte(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE));
|
||||||
gameRules.setMatchAnteRarity(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE_MATCH_RARITY));
|
gameRules.setMatchAnteRarity(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE_MATCH_RARITY));
|
||||||
gameRules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
gameRules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||||
gameRules.canCloneUseTargetsImage = FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
gameRules.setCanCloneUseTargetsImage(FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE));
|
||||||
return gameRules;
|
return gameRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ public class ConquestController {
|
|||||||
final GameRules rules = new GameRules(GameType.PlanarConquest);
|
final GameRules rules = new GameRules(GameType.PlanarConquest);
|
||||||
rules.setGamesPerMatch(1); //only play one game at a time
|
rules.setGamesPerMatch(1); //only play one game at a time
|
||||||
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||||
rules.canCloneUseTargetsImage = FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
rules.setCanCloneUseTargetsImage(FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE));
|
||||||
final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
|
final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
|
||||||
FThreads.invokeInEdtNowOrLater(new Runnable(){
|
FThreads.invokeInEdtNowOrLater(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public class QuestDraftUtils {
|
|||||||
rules.setMatchAnteRarity(false);
|
rules.setMatchAnteRarity(false);
|
||||||
rules.setGamesPerMatch(3);
|
rules.setGamesPerMatch(3);
|
||||||
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||||
rules.canCloneUseTargetsImage = FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
rules.setCanCloneUseTargetsImage(FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE));
|
||||||
|
|
||||||
final HostedMatch newMatch = GuiBase.getInterface().hostMatch();
|
final HostedMatch newMatch = GuiBase.getInterface().hostMatch();
|
||||||
newMatch.startMatch(rules, null, nextMatch.matchStarter, nextMatch.humanPlayer, GuiBase.getInterface().getNewGuiGame());
|
newMatch.startMatch(rules, null, nextMatch.matchStarter, nextMatch.humanPlayer, GuiBase.getInterface().getNewGuiGame());
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ public class QuestUtil {
|
|||||||
rules.setMatchAnteRarity(matchAnteRarity);
|
rules.setMatchAnteRarity(matchAnteRarity);
|
||||||
rules.setGamesPerMatch(qData.getCharmState() ? 5 : 3);
|
rules.setGamesPerMatch(qData.getCharmState() ? 5 : 3);
|
||||||
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||||
rules.canCloneUseTargetsImage = FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
rules.setCanCloneUseTargetsImage(FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE));
|
||||||
final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
|
final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
|
||||||
final IGuiGame gui = GuiBase.getInterface().getNewGuiGame();
|
final IGuiGame gui = GuiBase.getInterface().getNewGuiGame();
|
||||||
gui.setPlayerAvatar(aiPlayer, event);
|
gui.setPlayerAvatar(aiPlayer, event);
|
||||||
|
|||||||
Reference in New Issue
Block a user