mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
Refactor: fixed getRules usage, clean SplitCard code
This commit is contained in:
parent
8f748b0f2c
commit
914cfc1d3a
9 changed files with 70 additions and 51 deletions
|
|
@ -10,6 +10,7 @@ import mage.constants.SpellAbilityType;
|
|||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -20,6 +21,8 @@ import java.util.UUID;
|
|||
*/
|
||||
public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
||||
|
||||
static public String FUSE_RULE = "Fuse (You may cast both halves from your hand.)";
|
||||
|
||||
protected Card leftHalfCard;
|
||||
protected Card rightHalfCard;
|
||||
|
||||
|
|
@ -186,11 +189,29 @@ public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
|||
|
||||
@Override
|
||||
public List<String> getRules() {
|
||||
List<String> rules = new ArrayList<>();
|
||||
if (getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
||||
rules.add("--------------------------------------------------------------------------\nFuse (You may cast one or both halves of this card from your hand.)");
|
||||
}
|
||||
return rules;
|
||||
Abilities<Ability> sourceAbilities = this.getAbilities();
|
||||
List<String> res = CardUtil.getCardRulesWithAdditionalInfo(
|
||||
this.getId(),
|
||||
this.getName(),
|
||||
sourceAbilities,
|
||||
sourceAbilities
|
||||
);
|
||||
res.add("--------------------------------------------------------------------------\n" + FUSE_RULE);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRules(Game game) {
|
||||
Abilities<Ability> sourceAbilities = this.getAbilities(game);
|
||||
List<String> res = CardUtil.getCardRulesWithAdditionalInfo(
|
||||
game,
|
||||
this.getId(),
|
||||
this.getName(),
|
||||
sourceAbilities,
|
||||
sourceAbilities
|
||||
);
|
||||
res.add("--------------------------------------------------------------------------\n" + FUSE_RULE);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.cards.mock;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Abilities;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.SplitCard;
|
||||
|
|
@ -9,6 +10,8 @@ import mage.cards.repository.CardInfo;
|
|||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -109,4 +112,22 @@ public class MockSplitCard extends SplitCard {
|
|||
private static String getRightHalfName(CardInfo card) {
|
||||
return card.getName().split(" // ")[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRules() {
|
||||
// SplitCard adds additional fuse text to the card and to the database,
|
||||
// so a MockSplitCard must ignore it (duplicate fix)
|
||||
Abilities<Ability> sourceAbilities = this.getAbilities();
|
||||
return CardUtil.getCardRulesWithAdditionalInfo(
|
||||
this.getId(),
|
||||
this.getName(),
|
||||
sourceAbilities,
|
||||
sourceAbilities
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRules(Game game) {
|
||||
return this.getRules();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,31 +190,14 @@ public class CardInfo {
|
|||
|
||||
int length = 0;
|
||||
List<String> rulesList = new ArrayList<>();
|
||||
if (card instanceof SplitCard) {
|
||||
for (String rule : ((SplitCard) card).getLeftHalfCard().getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
for (String rule : ((SplitCard) card).getRightHalfCard().getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
for (String rule : card.getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
} else if (card instanceof ModalDoubleFacesCard) {
|
||||
// mdf card return main side's rules only (GUI can toggle it to another side)
|
||||
for (String rule : card.getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
} else {
|
||||
for (String rule : card.getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
// All cards must use getRules logic, so no special code here for rules, example:
|
||||
// - split card: show all rules from both sides
|
||||
// - mdf card: return main side's rules only (GUI can toggle it to another side)
|
||||
for (String rule : card.getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
|
||||
if (length > MAX_RULE_LENGTH) {
|
||||
length = 0;
|
||||
List<String> shortRules = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -263,13 +263,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
@Override
|
||||
public List<String> getRules(Game game) {
|
||||
try {
|
||||
List<String> rules = getRules();
|
||||
List<String> rules = super.getRules(game);
|
||||
|
||||
// add additional data for GUI
|
||||
|
||||
// info
|
||||
if (info != null) {
|
||||
for (String data : info.values()) {
|
||||
rules.add(data);
|
||||
}
|
||||
rules.addAll(info.values());
|
||||
}
|
||||
|
||||
// ability hints
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue