remove global object reference from ZoneType

This commit is contained in:
Maxmtg
2014-01-12 17:20:45 +00:00
parent f1ff893962
commit 17891a62fa
5 changed files with 57 additions and 124 deletions

View File

@@ -108,6 +108,10 @@ public class Lang {
return name.endsWith("s") ? name + "'" : name + "'s"; return name.endsWith("s") ? name + "'" : name + "'s";
} }
public static String getPossessedObject(String owner, String object) {
return getPossesive(owner) + " " + object;
}
public static boolean startsWithVowel(String word) { public static boolean startsWithVowel(String word) {
return isVowel(word.trim().charAt(0)); return isVowel(word.trim().charAt(0));
} }
@@ -138,42 +142,4 @@ public class Lang {
} }
return Integer.toString(n); return Integer.toString(n);
} }
public enum PhraseCase {
Title,
Sentence,
Lower
}
public static String splitCompoundWord(String word, PhraseCase phraseCase) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (Character.isUpperCase(ch)) {
if (i > 0) {
builder.append(" ");
}
switch (phraseCase) {
case Title:
builder.append(ch);
break;
case Sentence:
if (i > 0) {
builder.append(ch);
}
else {
builder.append(Character.toLowerCase(ch));
}
break;
case Lower:
builder.append(Character.toLowerCase(ch));
continue;
}
}
else {
builder.append(ch);
}
}
return builder.toString();
}
} }

View File

@@ -184,14 +184,13 @@ public class DigEffect extends SpellAbilityEffect {
} }
else if (allButOne) { else if (allButOne) {
movedCards.addAll(valid); movedCards.addAll(valid);
String prefix; String prompt;
if (destZone2.equals(ZoneType.Library) && (libraryPosition2 == 0)) { if (destZone2.equals(ZoneType.Library) && (libraryPosition2 == 0)) {
prefix = "Choose a card to leave on top of "; prompt = "Choose a card to leave on top of {player's} library";
} }
else { else {
prefix = "Choose a card to leave in "; prompt = "Choose a card to leave in {player's} " + destZone2.name();
} }
String prompt = destZone2.createMessage(p, prefix);
Card chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, false, p); Card chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, false, p);
movedCards.remove(chosen); movedCards.remove(chosen);
@@ -202,16 +201,15 @@ public class DigEffect extends SpellAbilityEffect {
} }
else { else {
int j = 0; int j = 0;
String prefix = "Choose a card to put into "; String prompt = "Choose a card to put into ";
if (destZone1.equals(ZoneType.Library)) { if (destZone1.equals(ZoneType.Library)) {
if (libraryPosition == -1) { if (libraryPosition == -1) {
prefix = "Choose a card to put on the bottom of "; prompt = "Choose a card to put on the bottom of {player's} library";
} }
else if (libraryPosition == 0) { else if (libraryPosition == 0) {
prefix = "Choose a card to put on top of "; prompt = "Choose a card to put on top of {player's} library";
} }
} }
String prompt = destZone1.createMessage(p, prefix);
while ((j < destZone1ChangeNum) || (anyNumber && (j < numToDig))) { while ((j < destZone1ChangeNum) || (anyNumber && (j < numToDig))) {
// let user get choice // let user get choice
@@ -220,7 +218,7 @@ public class DigEffect extends SpellAbilityEffect {
chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, anyNumber || optional, p); chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, anyNumber || optional, p);
} }
else { else {
chooser.getController().notifyOfValue(sa, null, destZone1.createMessage(p, "No valid cards in ")); chooser.getController().notifyOfValue(sa, null, "No valid cards");
} }
if (chosen == null) { if (chosen == null) {

View File

@@ -100,38 +100,6 @@ public class CostPayment {
return true; return true;
} }
/**
* <p>
* payCost.
* </p>
*
* @return a boolean.
*/
public boolean payCost(final Player payer) {
HumanCostDecision hcd = new HumanCostDecision(payer, ability, ability.getSourceCard());
for (final CostPart part : this.cost.getCostParts()) {
PaymentDecision pd = part.accept(hcd);
if ( null == pd || !part.payAsDecided(payer, pd, ability))
return false;
// abilities care what was used to pay for them
if( part instanceof CostPartWithList )
((CostPartWithList) part).reportPaidCardsTo(ability);
this.paidCostParts.add(part);
}
// this clears lists used for undo.
for (final CostPart part1 : this.paidCostParts) {
if (part1 instanceof CostPartWithList) {
((CostPartWithList) part1).resetList();
}
}
return true;
}
/** /**
* <p> * <p>
* isAllPaid. * isAllPaid.
@@ -166,6 +134,38 @@ public class CostPayment {
this.ability.getActivatingPlayer().getManaPool().refundManaPaid(this.ability); this.ability.getActivatingPlayer().getManaPool().refundManaPaid(this.ability);
} }
/**
* <p>
* payCost.
* </p>
*
* @return a boolean.
*/
public boolean payCost(final Player payer) {
HumanCostDecision hcd = new HumanCostDecision(payer, ability, ability.getSourceCard());
for (final CostPart part : this.cost.getCostParts()) {
PaymentDecision pd = part.accept(hcd);
if ( null == pd || !part.payAsDecided(payer, pd, ability))
return false;
// abilities care what was used to pay for them
if( part instanceof CostPartWithList )
((CostPartWithList) part).reportPaidCardsTo(ability);
this.paidCostParts.add(part);
}
// this clears lists used for undo.
for (final CostPart part1 : this.paidCostParts) {
if (part1 instanceof CostPartWithList) {
((CostPartWithList) part1).resetList();
}
}
return true;
}
/** /**
* <p> * <p>
* payComputerCosts. * payComputerCosts.

View File

@@ -4,10 +4,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import forge.game.player.Player;
import forge.net.FServer;
import forge.util.Lang;
/** /**
* The Enum Zone. * The Enum Zone.
*/ */
@@ -84,38 +80,4 @@ public enum ZoneType {
public static boolean isKnown(final String origin) { public static boolean isKnown(final String origin) {
return !isHidden(origin); return !isHidden(origin);
} }
public String createMessage(Player player, String prefix) {
return createMessage(player, prefix, null);
}
public String createMessage(Player player, String prefix, String suffix) {
StringBuilder message = new StringBuilder();
String owner;
if (player.getLobbyPlayer() == FServer.instance.getLobby().getGuiPlayer()) {
owner = "your";
}
else {
owner = Lang.getPossesive(player.getName());
}
if (prefix != null && !prefix.isEmpty()) {
message.append(prefix);
if (!prefix.endsWith(" ")) {
message.append(" ");
}
message.append(owner);
}
else {
message.append(owner.substring(0, 1).toUpperCase() + owner.substring(1));
}
message.append(" " + Lang.splitCompoundWord(this.toString(), Lang.PhraseCase.Lower));
if (suffix != null && !suffix.isEmpty()) {
message.append(" " + suffix);
}
return message.toString();
}
} }

View File

@@ -357,14 +357,14 @@ public class PlayerControllerHuman extends PlayerController {
if (canUseSelectCardsInput) { if (canUseSelectCardsInput) {
InputSelectEntitiesFromList<T> input = new InputSelectEntitiesFromList<T>(isOptional ? 0 : 1, 1, options); InputSelectEntitiesFromList<T> input = new InputSelectEntitiesFromList<T>(isOptional ? 0 : 1, 1, options);
input.setCancelAllowed(isOptional); input.setCancelAllowed(isOptional);
input.setMessage(title); input.setMessage(formatMessage(title, targetedPlayer));
input.showAndWait(); input.showAndWait();
return Iterables.getFirst(input.getSelected(), null); return Iterables.getFirst(input.getSelected(), null);
} }
return isOptional ? GuiChoose.oneOrNone(title, options) : GuiChoose.one(title, options); return isOptional ? GuiChoose.oneOrNone(title, options) : GuiChoose.one(title, options);
} }
@Override @Override
public int chooseNumber(SpellAbility sa, String title, int min, int max) { public int chooseNumber(SpellAbility sa, String title, int min, int max) {
final Integer[] choices = new Integer[max + 1 - min]; final Integer[] choices = new Integer[max + 1 - min];
@@ -457,11 +457,11 @@ public class PlayerControllerHuman extends PlayerController {
* @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List, forge.game.zone.ZoneType, forge.game.player.Player) * @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List, forge.game.zone.ZoneType, forge.game.player.Player)
*/ */
@Override @Override
public void reveal(Collection<Card> cards, ZoneType zone, Player owner, String messagePrefix) { public void reveal(Collection<Card> cards, ZoneType zone, Player owner, String message) {
if (StringUtils.isBlank(messagePrefix)) { if (StringUtils.isBlank(message)) {
messagePrefix = "Looking at cards in "; message = "Looking at cards in {player's} " + zone.name();
} }
GuiChoose.reveal(zone.createMessage(owner, messagePrefix), cards); GuiChoose.reveal(formatMessage(message, owner), cards);
} }
@Override @Override
@@ -830,6 +830,13 @@ public class PlayerControllerHuman extends PlayerController {
GuiDialog.message(message, sa.getSourceCard() == null ? "" : sa.getSourceCard().getName()); GuiDialog.message(message, sa.getSourceCard() == null ? "" : sa.getSourceCard().getName());
} }
private String formatMessage(String message, Object related) {
if(related instanceof Player && message.indexOf("{player") >= 0)
message = message.replace("{player}", mayBeYou(related)).replace("{player's}", Lang.getPossesive(mayBeYou(related)));
return message;
}
// These are not much related to PlayerController // These are not much related to PlayerController
private String formatNotificationMessage(SpellAbility sa, GameObject target, String value) { private String formatNotificationMessage(SpellAbility sa, GameObject target, String value) {
if (sa.getApi() == null || sa.getSourceCard() == null) { if (sa.getApi() == null || sa.getSourceCard() == null) {
@@ -852,7 +859,7 @@ public class PlayerControllerHuman extends PlayerController {
} }
} }
private String mayBeYou(GameObject what) { private String mayBeYou(Object what) {
return what == null ? "(null)" : what == player ? "you" : what.toString(); return what == null ? "(null)" : what == player ? "you" : what.toString();
} }