mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
remove global object reference from ZoneType
This commit is contained in:
@@ -108,6 +108,10 @@ public class Lang {
|
||||
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) {
|
||||
return isVowel(word.trim().charAt(0));
|
||||
}
|
||||
@@ -138,42 +142,4 @@ public class Lang {
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,14 +184,13 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
}
|
||||
else if (allButOne) {
|
||||
movedCards.addAll(valid);
|
||||
String prefix;
|
||||
String prompt;
|
||||
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 {
|
||||
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);
|
||||
movedCards.remove(chosen);
|
||||
@@ -202,16 +201,15 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
}
|
||||
else {
|
||||
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 (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) {
|
||||
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))) {
|
||||
// let user get choice
|
||||
@@ -220,7 +218,7 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, anyNumber || optional, p);
|
||||
}
|
||||
else {
|
||||
chooser.getController().notifyOfValue(sa, null, destZone1.createMessage(p, "No valid cards in "));
|
||||
chooser.getController().notifyOfValue(sa, null, "No valid cards");
|
||||
}
|
||||
|
||||
if (chosen == null) {
|
||||
|
||||
@@ -100,38 +100,6 @@ public class CostPayment {
|
||||
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>
|
||||
* isAllPaid.
|
||||
@@ -166,6 +134,38 @@ public class CostPayment {
|
||||
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>
|
||||
* payComputerCosts.
|
||||
|
||||
@@ -4,10 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import forge.game.player.Player;
|
||||
import forge.net.FServer;
|
||||
import forge.util.Lang;
|
||||
|
||||
/**
|
||||
* The Enum Zone.
|
||||
*/
|
||||
@@ -84,38 +80,4 @@ public enum ZoneType {
|
||||
public static boolean isKnown(final String 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (canUseSelectCardsInput) {
|
||||
InputSelectEntitiesFromList<T> input = new InputSelectEntitiesFromList<T>(isOptional ? 0 : 1, 1, options);
|
||||
input.setCancelAllowed(isOptional);
|
||||
input.setMessage(title);
|
||||
input.setMessage(formatMessage(title, targetedPlayer));
|
||||
input.showAndWait();
|
||||
return Iterables.getFirst(input.getSelected(), null);
|
||||
}
|
||||
@@ -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)
|
||||
*/
|
||||
@Override
|
||||
public void reveal(Collection<Card> cards, ZoneType zone, Player owner, String messagePrefix) {
|
||||
if (StringUtils.isBlank(messagePrefix)) {
|
||||
messagePrefix = "Looking at cards in ";
|
||||
public void reveal(Collection<Card> cards, ZoneType zone, Player owner, String message) {
|
||||
if (StringUtils.isBlank(message)) {
|
||||
message = "Looking at cards in {player's} " + zone.name();
|
||||
}
|
||||
GuiChoose.reveal(zone.createMessage(owner, messagePrefix), cards);
|
||||
GuiChoose.reveal(formatMessage(message, owner), cards);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -830,6 +830,13 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
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
|
||||
private String formatNotificationMessage(SpellAbility sa, GameObject target, String value) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user