Fixed game errors for non started games (some cards uses dynamic hints with non-protected code)

This commit is contained in:
Oleg Agafonov 2023-06-09 06:48:59 +04:00
parent ec7befa511
commit 35b00c3da1
2 changed files with 28 additions and 20 deletions

View file

@ -275,6 +275,11 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
rules.addAll(info.values()); rules.addAll(info.values());
} }
if (game == null || game.getPhase() == null) {
// dynamic hints for started game only
return rules;
}
// ability hints // ability hints
List<String> abilityHints = new ArrayList<>(); List<String> abilityHints = new ArrayList<>();
if (HintUtils.ABILITY_HINTS_ENABLE) { if (HintUtils.ABILITY_HINTS_ENABLE) {
@ -290,7 +295,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
// restrict hints // restrict hints
List<String> restrictHints = new ArrayList<>(); List<String> restrictHints = new ArrayList<>();
if (game != null && HintUtils.RESTRICT_HINTS_ENABLE) { if (HintUtils.RESTRICT_HINTS_ENABLE) {
// restrict // restrict
for (Map.Entry<RestrictionEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) { for (Map.Entry<RestrictionEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
for (Ability ability : entry.getValue()) { for (Ability ability : entry.getValue()) {

View file

@ -1116,31 +1116,34 @@ public final class CardUtil {
try { try {
List<String> rules = rulesSource.getRules(cardName); List<String> rules = rulesSource.getRules(cardName);
if (game != null) { if (game == null || game.getPhase() == null) {
// dynamic hints for started game only
return rules;
}
// debug state // debug state
rules.addAll(game.getState().getCardState(cardId).getInfo().values()); rules.addAll(game.getState().getCardState(cardId).getInfo().values());
// ability hints // ability hints
List<String> abilityHints = new ArrayList<>(); List<String> abilityHints = new ArrayList<>();
if (HintUtils.ABILITY_HINTS_ENABLE) { if (HintUtils.ABILITY_HINTS_ENABLE) {
for (Ability ability : hintsSource) { for (Ability ability : hintsSource) {
for (Hint hint : ability.getHints()) { for (Hint hint : ability.getHints()) {
String s = hint.getText(game, ability); String s = hint.getText(game, ability);
if (s != null && !s.isEmpty()) { if (s != null && !s.isEmpty()) {
abilityHints.add(s); abilityHints.add(s);
}
} }
} }
} }
// restrict hints only for permanents, not cards
// total hints
if (!abilityHints.isEmpty()) {
rules.add(HintUtils.HINT_START_MARK);
HintUtils.appendHints(rules, abilityHints);
}
} }
// restrict hints only for permanents, not cards
// total hints
if (!abilityHints.isEmpty()) {
rules.add(HintUtils.HINT_START_MARK);
HintUtils.appendHints(rules, abilityHints);
}
return rules; return rules;
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception in rules generation for card: " + cardName, e); logger.error("Exception in rules generation for card: " + cardName, e);