1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-01 19:07:57 -09:00

moved {this} and {source} replacement to server

This commit is contained in:
BetaSteward 2010-12-26 20:41:40 -05:00
parent 5bdfd1b467
commit c8db6ba350
13 changed files with 62 additions and 52 deletions

View file

@ -48,7 +48,7 @@ public class AbilityView extends CardView {
this.sourceName = sourceName;
this.sourceCard = sourceCard;
this.rules = new ArrayList<String>();
rules.add(formatRule(ability.getRule()));
rules.add(ability.getRule(sourceName));
this.power = "";
this.toughness = "";
this.loyalty = "";
@ -60,13 +60,6 @@ public class AbilityView extends CardView {
this.art = "";
}
@Override
protected String formatRule(String rule) {
String newRule = rule.replace("{this}", this.sourceName);
newRule.replace("{source}", this.sourceName);
return newRule;
}
public CardView getSourceCard() {
return this.sourceCard;
}

View file

@ -76,7 +76,7 @@ public class CardView implements Serializable {
public CardView(Card card) {
this.id = card.getId();
this.name = card.getName();
this.rules = formatRules(card.getRules());
this.rules = card.getRules();
if (card instanceof Permanent) {
this.power = Integer.toString(card.getPower().getValue());
this.toughness = Integer.toString(card.getToughness().getValue());
@ -118,7 +118,7 @@ public class CardView implements Serializable {
CardView(Token token) {
this.id = token.getId();
this.name = token.getName();
this.rules = formatRules(token.getAbilities().getRules());
this.rules = token.getAbilities().getRules(this.name);
this.power = token.getPower().toString();
this.toughness = token.getToughness().toString();
this.loyalty = token.getLoyalty().toString();
@ -143,19 +143,19 @@ public class CardView implements Serializable {
}
}
protected List<String> formatRules(List<String> rules) {
List<String> newRules = new ArrayList<String>();
for (String rule: rules) {
newRules.add(formatRule(rule));
}
return newRules;
}
protected String formatRule(String rule) {
String replace = rule.replace("{this}", this.name);
replace = replace.replace("{source}", this.name);
return replace;
}
// protected List<String> formatRules(List<String> rules) {
// List<String> newRules = new ArrayList<String>();
// for (String rule: rules) {
// newRules.add(formatRule(rule));
// }
// return newRules;
// }
//
// protected String formatRule(String rule) {
// String replace = rule.replace("{this}", this.name);
// replace = replace.replace("{source}", this.name);
// return replace;
// }
public String getName() {
return name;

View file

@ -47,7 +47,7 @@ public class StackAbilityView extends CardView {
this.sourceName = sourceName;
this.sourceCard = sourceCard;
this.rules = new ArrayList<String>();
rules.add(formatRule(ability.getRule()));
rules.add(ability.getRule(sourceName));
this.power = ability.getPower().toString();
this.toughness = ability.getToughness().toString();
this.loyalty = ability.getLoyalty().toString();
@ -60,13 +60,6 @@ public class StackAbilityView extends CardView {
setTargets(ability.getTargets());
}
@Override
protected String formatRule(String rule) {
String newRule = rule.replace("{this}", this.sourceName);
newRule.replace("{source}", this.sourceName);
return newRule;
}
public CardView getSourceCard() {
return this.sourceCard;
}

View file

@ -39,7 +39,7 @@ import mage.filter.FilterAbility;
public interface Abilities<T extends Ability> extends List<T>, Serializable {
public List<String> getRules();
public List<String> getRules(String source);
public Abilities<ActivatedAbility> getActivatedAbilities(Zone zone);
public Abilities<ActivatedAbility> getActivatedAbilities(Zone zone, FilterAbility filter);
public Abilities<ManaAbility> getManaAbilities(Zone zone);

View file

@ -58,7 +58,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
}
@Override
public List<String> getRules() {
public List<String> getRules(String source) {
List<String> rules = new ArrayList<String>();
for (T ability:this) {

View file

@ -73,6 +73,7 @@ public interface Ability extends Serializable {
public Zone getZone();
public boolean isUsesStack();
public String getRule();
public String getRule(String source);
public boolean activate(Game game, boolean noMana);
public boolean resolve(Game game);
public void reset(Game game);

View file

@ -302,6 +302,17 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
return sbRule.toString();
}
@Override
public String getRule(String source) {
return formatRule(getRule(), source);
}
protected String formatRule(String rule, String source) {
String replace = rule.replace("{this}", source);
replace = replace.replace("{source}", source);
return replace;
}
@Override
public void addCost(Cost cost) {
if (cost != null) {

View file

@ -81,10 +81,13 @@ public abstract class TriggeredAbilityImpl<T extends TriggeredAbilityImpl<T>> ex
Player player = game.getPlayer(this.getControllerId());
MageObject object = game.getObject(sourceId);
StringBuilder sb = new StringBuilder();
sb.append("Use ").append(this.getRule()).append("ability");
if (object != null) {
sb.append("Use ").append(this.getRule(object.getName())).append("ability");
sb.append(" from ").append(object.getName());
}
else {
sb.append("Use ").append(this.getRule()).append("ability");
}
sb.append("?");
if (!player.chooseUse(this.effects.get(0).getOutcome(), sb.toString(), game)) {
return false;

View file

@ -30,15 +30,17 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect<SacrificeSour
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, cost.getText() + " or sacrifice {this}?", game)) {
cost.clearPaid();
if (cost.pay(game, source.getId(), source.getControllerId(), false))
return true;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null)
if (player != null && permanent != null) {
if (player.chooseUse(Outcome.Benefit, cost.getText() + " or sacrifice " + permanent.getName() + "?", game)) {
cost.clearPaid();
if (cost.pay(game, source.getId(), source.getControllerId(), false))
return true;
}
permanent.sacrifice(source.getSourceId(), game);
return true;
return true;
}
return false;
}
@Override
@ -48,6 +50,6 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect<SacrificeSour
@Override
public String getText(Ability source) {
return "sacrifice it unless you pay " + cost.getText();
return "sacrifice {this} unless you pay " + cost.getText();
}
}

View file

@ -57,15 +57,17 @@ public class TapSourceUnlessPaysEffect extends OneShotEffect<TapSourceUnlessPays
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, cost.getText() + " or {this} comes into play tapped?", game)) {
cost.clearPaid();
if (cost.pay(game, source.getId(), source.getControllerId(), false))
return true;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null)
if (player != null && permanent != null) {
if (player.chooseUse(Outcome.Benefit, cost.getText() + " or " + permanent.getName() + " comes into play tapped?", game)) {
cost.clearPaid();
if (cost.pay(game, source.getId(), source.getControllerId(), false))
return true;
}
permanent.setTapped(true);
return true;
return true;
}
return false;
}
@Override

View file

@ -93,7 +93,7 @@ public class LevelAbility extends StaticAbility<LevelAbility> {
else
sb.append("-").append(level2);
sb.append(": ").append(power).append("/").append(toughness).append(" ");
for (String rule: abilities.getRules()) {
for (String rule: abilities.getRules("{this}")) {
sb.append(rule).append(" ");
}
return sb.toString();

View file

@ -130,9 +130,9 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
@Override
public List<String> getRules() {
List<String> rules = abilities.getRules();
List<String> rules = abilities.getRules(this.name);
if (cardType.contains(CardType.INSTANT) || cardType.contains(CardType.SORCERY)) {
rules.add(0, getSpellAbility().getRule());
rules.add(0, getSpellAbility().getRule(this.name));
}
return rules;
}

View file

@ -192,6 +192,11 @@ public class StackAbility implements StackObject, Ability {
return ability.getRule();
}
@Override
public String getRule(String source) {
return ability.getRule(source);
}
@Override
public void setControllerId(UUID controllerId) {
this.controllerId = controllerId;