mirror of
https://github.com/correl/mage.git
synced 2025-04-06 09:13:45 -09:00
moved {this} and {source} replacement to server
This commit is contained in:
parent
5bdfd1b467
commit
c8db6ba350
13 changed files with 62 additions and 52 deletions
Mage.Common/src/mage/view
Mage/src/mage
|
@ -48,7 +48,7 @@ public class AbilityView extends CardView {
|
||||||
this.sourceName = sourceName;
|
this.sourceName = sourceName;
|
||||||
this.sourceCard = sourceCard;
|
this.sourceCard = sourceCard;
|
||||||
this.rules = new ArrayList<String>();
|
this.rules = new ArrayList<String>();
|
||||||
rules.add(formatRule(ability.getRule()));
|
rules.add(ability.getRule(sourceName));
|
||||||
this.power = "";
|
this.power = "";
|
||||||
this.toughness = "";
|
this.toughness = "";
|
||||||
this.loyalty = "";
|
this.loyalty = "";
|
||||||
|
@ -60,13 +60,6 @@ public class AbilityView extends CardView {
|
||||||
this.art = "";
|
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() {
|
public CardView getSourceCard() {
|
||||||
return this.sourceCard;
|
return this.sourceCard;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class CardView implements Serializable {
|
||||||
public CardView(Card card) {
|
public CardView(Card card) {
|
||||||
this.id = card.getId();
|
this.id = card.getId();
|
||||||
this.name = card.getName();
|
this.name = card.getName();
|
||||||
this.rules = formatRules(card.getRules());
|
this.rules = card.getRules();
|
||||||
if (card instanceof Permanent) {
|
if (card instanceof Permanent) {
|
||||||
this.power = Integer.toString(card.getPower().getValue());
|
this.power = Integer.toString(card.getPower().getValue());
|
||||||
this.toughness = Integer.toString(card.getToughness().getValue());
|
this.toughness = Integer.toString(card.getToughness().getValue());
|
||||||
|
@ -118,7 +118,7 @@ public class CardView implements Serializable {
|
||||||
CardView(Token token) {
|
CardView(Token token) {
|
||||||
this.id = token.getId();
|
this.id = token.getId();
|
||||||
this.name = token.getName();
|
this.name = token.getName();
|
||||||
this.rules = formatRules(token.getAbilities().getRules());
|
this.rules = token.getAbilities().getRules(this.name);
|
||||||
this.power = token.getPower().toString();
|
this.power = token.getPower().toString();
|
||||||
this.toughness = token.getToughness().toString();
|
this.toughness = token.getToughness().toString();
|
||||||
this.loyalty = token.getLoyalty().toString();
|
this.loyalty = token.getLoyalty().toString();
|
||||||
|
@ -143,19 +143,19 @@ public class CardView implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> formatRules(List<String> rules) {
|
// protected List<String> formatRules(List<String> rules) {
|
||||||
List<String> newRules = new ArrayList<String>();
|
// List<String> newRules = new ArrayList<String>();
|
||||||
for (String rule: rules) {
|
// for (String rule: rules) {
|
||||||
newRules.add(formatRule(rule));
|
// newRules.add(formatRule(rule));
|
||||||
}
|
// }
|
||||||
return newRules;
|
// return newRules;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected String formatRule(String rule) {
|
// protected String formatRule(String rule) {
|
||||||
String replace = rule.replace("{this}", this.name);
|
// String replace = rule.replace("{this}", this.name);
|
||||||
replace = replace.replace("{source}", this.name);
|
// replace = replace.replace("{source}", this.name);
|
||||||
return replace;
|
// return replace;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class StackAbilityView extends CardView {
|
||||||
this.sourceName = sourceName;
|
this.sourceName = sourceName;
|
||||||
this.sourceCard = sourceCard;
|
this.sourceCard = sourceCard;
|
||||||
this.rules = new ArrayList<String>();
|
this.rules = new ArrayList<String>();
|
||||||
rules.add(formatRule(ability.getRule()));
|
rules.add(ability.getRule(sourceName));
|
||||||
this.power = ability.getPower().toString();
|
this.power = ability.getPower().toString();
|
||||||
this.toughness = ability.getToughness().toString();
|
this.toughness = ability.getToughness().toString();
|
||||||
this.loyalty = ability.getLoyalty().toString();
|
this.loyalty = ability.getLoyalty().toString();
|
||||||
|
@ -60,13 +60,6 @@ public class StackAbilityView extends CardView {
|
||||||
setTargets(ability.getTargets());
|
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() {
|
public CardView getSourceCard() {
|
||||||
return this.sourceCard;
|
return this.sourceCard;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ import mage.filter.FilterAbility;
|
||||||
|
|
||||||
public interface Abilities<T extends Ability> extends List<T>, Serializable {
|
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);
|
||||||
public Abilities<ActivatedAbility> getActivatedAbilities(Zone zone, FilterAbility filter);
|
public Abilities<ActivatedAbility> getActivatedAbilities(Zone zone, FilterAbility filter);
|
||||||
public Abilities<ManaAbility> getManaAbilities(Zone zone);
|
public Abilities<ManaAbility> getManaAbilities(Zone zone);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getRules() {
|
public List<String> getRules(String source) {
|
||||||
List<String> rules = new ArrayList<String>();
|
List<String> rules = new ArrayList<String>();
|
||||||
|
|
||||||
for (T ability:this) {
|
for (T ability:this) {
|
||||||
|
|
|
@ -73,6 +73,7 @@ public interface Ability extends Serializable {
|
||||||
public Zone getZone();
|
public Zone getZone();
|
||||||
public boolean isUsesStack();
|
public boolean isUsesStack();
|
||||||
public String getRule();
|
public String getRule();
|
||||||
|
public String getRule(String source);
|
||||||
public boolean activate(Game game, boolean noMana);
|
public boolean activate(Game game, boolean noMana);
|
||||||
public boolean resolve(Game game);
|
public boolean resolve(Game game);
|
||||||
public void reset(Game game);
|
public void reset(Game game);
|
||||||
|
|
|
@ -302,6 +302,17 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
||||||
return sbRule.toString();
|
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
|
@Override
|
||||||
public void addCost(Cost cost) {
|
public void addCost(Cost cost) {
|
||||||
if (cost != null) {
|
if (cost != null) {
|
||||||
|
|
|
@ -81,10 +81,13 @@ public abstract class TriggeredAbilityImpl<T extends TriggeredAbilityImpl<T>> ex
|
||||||
Player player = game.getPlayer(this.getControllerId());
|
Player player = game.getPlayer(this.getControllerId());
|
||||||
MageObject object = game.getObject(sourceId);
|
MageObject object = game.getObject(sourceId);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("Use ").append(this.getRule()).append("ability");
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
sb.append("Use ").append(this.getRule(object.getName())).append("ability");
|
||||||
sb.append(" from ").append(object.getName());
|
sb.append(" from ").append(object.getName());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
sb.append("Use ").append(this.getRule()).append("ability");
|
||||||
|
}
|
||||||
sb.append("?");
|
sb.append("?");
|
||||||
if (!player.chooseUse(this.effects.get(0).getOutcome(), sb.toString(), game)) {
|
if (!player.chooseUse(this.effects.get(0).getOutcome(), sb.toString(), game)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -30,15 +30,17 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect<SacrificeSour
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
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());
|
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);
|
permanent.sacrifice(source.getSourceId(), game);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,6 +50,6 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect<SacrificeSour
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText(Ability source) {
|
public String getText(Ability source) {
|
||||||
return "sacrifice it unless you pay " + cost.getText();
|
return "sacrifice {this} unless you pay " + cost.getText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,15 +57,17 @@ public class TapSourceUnlessPaysEffect extends OneShotEffect<TapSourceUnlessPays
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
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());
|
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);
|
permanent.setTapped(true);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class LevelAbility extends StaticAbility<LevelAbility> {
|
||||||
else
|
else
|
||||||
sb.append("-").append(level2);
|
sb.append("-").append(level2);
|
||||||
sb.append(": ").append(power).append("/").append(toughness).append(" ");
|
sb.append(": ").append(power).append("/").append(toughness).append(" ");
|
||||||
for (String rule: abilities.getRules()) {
|
for (String rule: abilities.getRules("{this}")) {
|
||||||
sb.append(rule).append(" ");
|
sb.append(rule).append(" ");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|
|
@ -130,9 +130,9 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getRules() {
|
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)) {
|
if (cardType.contains(CardType.INSTANT) || cardType.contains(CardType.SORCERY)) {
|
||||||
rules.add(0, getSpellAbility().getRule());
|
rules.add(0, getSpellAbility().getRule(this.name));
|
||||||
}
|
}
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,11 @@ public class StackAbility implements StackObject, Ability {
|
||||||
return ability.getRule();
|
return ability.getRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRule(String source) {
|
||||||
|
return ability.getRule(source);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setControllerId(UUID controllerId) {
|
public void setControllerId(UUID controllerId) {
|
||||||
this.controllerId = controllerId;
|
this.controllerId = controllerId;
|
||||||
|
|
Loading…
Add table
Reference in a new issue