- Cleanup GameRules (mostly make a variable private)

- Minor cleanup in some other files
This commit is contained in:
elcnesh
2015-06-04 16:06:48 +00:00
parent 71e4464ad9
commit 4eef9618d0
9 changed files with 48 additions and 55 deletions

View File

@@ -233,7 +233,7 @@ public class Game {
*/
public final FCollectionView<Player> getNonactivePlayers() {
// 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());
if (!turnOrder.isDefaultDirection()) {
Collections.reverse(players);
@@ -636,12 +636,12 @@ public class Game {
List<CardRarity> validRarities = new ArrayList<>(Arrays.asList(CardRarity.values()));
for (final Player player : getPlayers()) {
final Set<CardRarity> playerRarity = getValidRarities(player.getCardsIn(ZoneType.Library));
if (onePlayerHasTimeShifted == false) {
if (!onePlayerHasTimeShifted) {
onePlayerHasTimeShifted = playerRarity.contains(CardRarity.Special);
}
validRarities.retainAll(playerRarity);
}
if (validRarities.size() == 0) { //If no possible rarity matches were found, use the original method to choose antes
for (Player player : getPlayers()) {
chooseRandomCardsForAnte(player, anteed);

View File

@@ -4,19 +4,19 @@ import java.util.EnumSet;
import java.util.Set;
public class GameRules {
private GameType gameType;
private final GameType gameType;
private boolean manaBurn;
private int poisonCountersToLose = 10; // is commonly 10, but turns into 15 for 2HG
private int gamesPerMatch = 3;
private int gamesToWinMatch = 2;
private boolean playForAnte = 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
public boolean canCloneUseTargetsImage;
public GameRules(GameType type) {
private boolean canCloneUseTargetsImage;
public GameRules(final GameType type) {
this.gameType = type;
}
@@ -24,28 +24,19 @@ public class GameRules {
return gameType;
}
/**
* @return the manaBurn
*/
public boolean hasManaBurn() {
return manaBurn;
}
/**
* @param manaBurn the manaBurn to set
*/
public void setManaBurn(boolean manaBurn) {
public void setManaBurn(final boolean manaBurn) {
this.manaBurn = manaBurn;
}
/**
* @return the poisonCountersToLose
*/
public int getPoisonCountersToLose() {
return poisonCountersToLose;
}
/**
* @param poisonCountersToLose the poisonCountersToLose to set
*/
public void setPoisonCountersToLose(int amount) {
public void setPoisonCountersToLose(final int amount) {
this.poisonCountersToLose = amount;
}
@@ -53,7 +44,7 @@ public class GameRules {
return gamesPerMatch;
}
public void setGamesPerMatch(int gamesPerMatch) {
public void setGamesPerMatch(final int gamesPerMatch) {
this.gamesPerMatch = gamesPerMatch;
this.gamesToWinMatch = gamesPerMatch / 2 + 1;
}
@@ -62,7 +53,7 @@ public class GameRules {
return playForAnte;
}
public void setPlayForAnte(boolean useAnte) {
public void setPlayForAnte(final boolean useAnte) {
this.playForAnte = useAnte;
}
@@ -70,7 +61,7 @@ public class GameRules {
return matchAnteRarity;
}
public void setMatchAnteRarity(boolean matchRarity) {
public void setMatchAnteRarity(final boolean matchRarity) {
matchAnteRarity = matchRarity;
}
@@ -78,15 +69,22 @@ public class GameRules {
return gamesToWinMatch;
}
public void setAppliedVariants(Set<GameType> appliedVariants) {
public void setAppliedVariants(final Set<GameType> appliedVariants) {
this.appliedVariants.addAll(appliedVariants);
}
public boolean hasAppliedVariant(GameType variant) {
public boolean hasAppliedVariant(final GameType variant) {
return appliedVariants.contains(variant);
}
public boolean hasCommander() {
return appliedVariants.contains(GameType.Commander) || appliedVariants.contains(GameType.TinyLeaders);
}
public boolean canCloneUseTargetsImage() {
return canCloneUseTargetsImage;
}
public void setCanCloneUseTargetsImage(final boolean canCloneUseTargetsImage) {
this.canCloneUseTargetsImage = canCloneUseTargetsImage;
}
}

View File

@@ -88,7 +88,7 @@ public class CloneEffect extends SpellAbilityEffect {
}
// 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
List<Card> cloneImgSources = AbilityUtils.getDefinedCards(host, sa.getParam("ImageSource"), sa);
if (!cloneImgSources.isEmpty()) {

View File

@@ -1,17 +1,13 @@
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.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import forge.StaticData;
import forge.card.CardStateName;
import forge.card.CardRulesPredicates;
import forge.card.CardStateName;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.game.Game;
@@ -27,39 +23,38 @@ import forge.game.zone.ZoneType;
import forge.item.PaperCard;
import forge.util.Aggregates;
import java.util.List;
import java.util.Map;
public class PlayLandVariantEffect extends SpellAbilityEffect {
/* (non-Javadoc)
* @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility)
*/
@Override
public void resolve(SpellAbility sa) {
Card source = sa.getHostCard();
Player activator = sa.getActivatingPlayer();
public void resolve(final SpellAbility sa) {
final Card source = sa.getHostCard();
final Player activator = sa.getActivatingPlayer();
final Game game = source.getGame();
final String landType = sa.getParam("Clone");
List<PaperCard> cards = Lists.newArrayList(StaticData.instance().getCommonCards().getUniqueCards());
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));
}
// current color of source card
ColorSet color = CardUtil.getColors(source);
final ColorSet color = CardUtil.getColors(source);
if (color.isColorless()) {
return;
}
// 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++) {
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
public boolean apply(final String name) {
return landnames.contains(name);
return landNames.contains(name);
}
}, PaperCard.FN_GET_NAME);
cards = Lists.newArrayList(Iterables.filter(cards, cp));
@@ -74,12 +69,12 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
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.switchStates(CardStateName.Original, CardStateName.Cloner, false);
source.setState(CardStateName.Original, false);
source.updateStateForView();
CardStateName stateToCopy = random.getCurrentStateName();
final CardStateName stateToCopy = random.getCurrentStateName();
CardFactory.copyState(random, stateToCopy, source, source.getCurrentStateName());
source.setImageKey(imageFileName);
@@ -90,7 +85,7 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
game.fireEvent(new GameEventLandPlayed(activator, source));
// Run triggers
final HashMap<String, Object> runParams = new HashMap<String, Object>();
final Map<String, Object> runParams = Maps.newHashMap();
runParams.put("Card", source);
game.getTriggerHandler().runTrigger(TriggerType.LandPlayed, runParams, false);
game.getStack().unfreezeStack();

View File

@@ -1058,7 +1058,7 @@ public class FSkin {
final File f = new File(preferredDir + ForgeConstants.SPLASH_BG_FILE);
if (!f.exists()) {
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);
return;

View File

@@ -69,7 +69,7 @@ public class HostedMatch {
gameRules.setPlayForAnte(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE));
gameRules.setMatchAnteRarity(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE_MATCH_RARITY));
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;
}

View File

@@ -217,7 +217,7 @@ public class ConquestController {
final GameRules rules = new GameRules(GameType.PlanarConquest);
rules.setGamesPerMatch(1); //only play one game at a time
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();
FThreads.invokeInEdtNowOrLater(new Runnable(){
@Override

View File

@@ -183,7 +183,7 @@ public class QuestDraftUtils {
rules.setMatchAnteRarity(false);
rules.setGamesPerMatch(3);
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();
newMatch.startMatch(rules, null, nextMatch.matchStarter, nextMatch.humanPlayer, GuiBase.getInterface().getNewGuiGame());

View File

@@ -565,7 +565,7 @@ public class QuestUtil {
rules.setMatchAnteRarity(matchAnteRarity);
rules.setGamesPerMatch(qData.getCharmState() ? 5 : 3);
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 IGuiGame gui = GuiBase.getInterface().getNewGuiGame();
gui.setPlayerAvatar(aiPlayer, event);