refactor: removed outdated and unused debug code (combat and continuous effects)

This commit is contained in:
Oleg Agafonov 2025-02-22 15:32:30 +04:00
parent 869cf83fd6
commit 90034fe9b0
4 changed files with 1 additions and 413 deletions

View file

@ -22,7 +22,6 @@ import mage.game.stack.Spell;
import mage.players.ManaPoolItem;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
import mage.util.trace.TraceInfo;
import org.apache.log4j.Logger;
import java.io.Serializable;
@ -1405,88 +1404,6 @@ public class ContinuousEffects implements Serializable {
return controllerFound;
}
/**
* Debug only: prints out a status of the currently existing continuous effects
*
* @param game
*/
public void traceContinuousEffects(Game game) {
game.getContinuousEffects().getLayeredEffects(game);
logger.info("-------------------------------------------------------------------------------------------------");
int numberEffects = 0;
for (ContinuousEffectsList list : allEffectsLists) {
numberEffects += list.size();
}
logger.info("Turn: " + game.getTurnNum() + " - currently existing continuous effects: " + numberEffects);
logger.info("layeredEffects ...................: " + layeredEffects.size());
logger.info("continuousRuleModifyingEffects ...: " + continuousRuleModifyingEffects.size());
logger.info("replacementEffects ...............: " + replacementEffects.size());
logger.info("preventionEffects ................: " + preventionEffects.size());
logger.info("requirementEffects ...............: " + requirementEffects.size());
logger.info("restrictionEffects ...............: " + restrictionEffects.size());
logger.info("restrictionUntapNotMoreThanEffects: " + restrictionUntapNotMoreThanEffects.size());
logger.info("costModificationEffects ..........: " + costModificationEffects.size());
logger.info("spliceCardEffects ................: " + spliceCardEffects.size());
logger.info("asThoughEffects:");
for (Map.Entry<AsThoughEffectType, ContinuousEffectsList<AsThoughEffect>> entry : asThoughEffectsMap.entrySet()) {
logger.info("... " + entry.getKey().toString() + ": " + entry.getValue().size());
}
logger.info("applyStatus ....................: " + (applyStatus != null ? "exists" : "null"));
logger.info("auraReplacementEffect ............: " + (continuousRuleModifyingEffects != null ? "exists" : "null"));
Map<String, TraceInfo> orderedEffects = new TreeMap<>();
traceAddContinuousEffects(orderedEffects, layeredEffects, game, "layeredEffects................");
traceAddContinuousEffects(orderedEffects, continuousRuleModifyingEffects, game, "continuousRuleModifyingEffects");
traceAddContinuousEffects(orderedEffects, replacementEffects, game, "replacementEffects............");
traceAddContinuousEffects(orderedEffects, preventionEffects, game, "preventionEffects.............");
traceAddContinuousEffects(orderedEffects, requirementEffects, game, "requirementEffects............");
traceAddContinuousEffects(orderedEffects, restrictionEffects, game, "restrictionEffects............");
traceAddContinuousEffects(orderedEffects, restrictionUntapNotMoreThanEffects, game, "restrictionUntapNotMore...");
traceAddContinuousEffects(orderedEffects, costModificationEffects, game, "costModificationEffects.......");
traceAddContinuousEffects(orderedEffects, spliceCardEffects, game, "spliceCardEffects.............");
for (Map.Entry<AsThoughEffectType, ContinuousEffectsList<AsThoughEffect>> entry : asThoughEffectsMap.entrySet()) {
traceAddContinuousEffects(orderedEffects, entry.getValue(), game, entry.getKey().toString());
}
String playerName = "";
for (Map.Entry<String, TraceInfo> entry : orderedEffects.entrySet()) {
if (!entry.getValue().getPlayerName().equals(playerName)) {
playerName = entry.getValue().getPlayerName();
logger.info("--- Player: " + playerName + " --------------------------------");
}
logger.info(entry.getValue().getInfo()
+ " " + entry.getValue().getSourceName()
+ " " + entry.getValue().getDuration().name()
+ " " + entry.getValue().getRule()
+ " (Order: " + entry.getValue().getOrder() + ")"
);
}
logger.info("---- End trace Continuous effects --------------------------------------------------------------------------");
}
public static void traceAddContinuousEffects(Map orderedEffects, ContinuousEffectsList<?> cel, Game game, String listName) {
for (ContinuousEffect effect : cel) {
Set<Ability> abilities = cel.getAbility(effect.getId());
for (Ability ability : abilities) {
Player controller = game.getPlayer(ability.getControllerId());
MageObject source = game.getObject(ability.getSourceId());
TraceInfo traceInfo = new TraceInfo();
traceInfo.setInfo(listName);
traceInfo.setOrder(effect.getOrder());
if (ability instanceof MageSingleton) {
traceInfo.setPlayerName("Mage Singleton");
traceInfo.setSourceName("Mage Singleton");
} else {
traceInfo.setPlayerName(controller == null ? "no controller" : controller.getName());
traceInfo.setSourceName(source == null ? "no source" : source.getIdName());
}
traceInfo.setRule(ability.getRule());
traceInfo.setAbilityId(ability.getId());
traceInfo.setEffectId(effect.getId());
traceInfo.setDuration(effect.getDuration());
orderedEffects.put(traceInfo.getPlayerName() + traceInfo.getSourceName() + effect.getId() + ability.getId(), traceInfo);
}
}
}
public int getTotalEffectsCount() {
return allEffectsLists.stream().mapToInt(ContinuousEffectsList::size).sum();
}

View file

@ -33,7 +33,6 @@ import mage.target.common.TargetControlledPermanent;
import mage.target.common.TargetDefender;
import mage.util.CardUtil;
import mage.util.Copyable;
import mage.util.trace.TraceUtil;
import org.apache.log4j.Logger;
import java.io.Serializable;
@ -744,8 +743,6 @@ public class Combat implements Serializable, Copyable<Combat> {
game.getCombat().logBlockerInfo(defender, game);
}
}
// tool to catch the bug about flyers blocked by non flyers or intimidate blocked by creatures with other colors
TraceUtil.traceCombatIfNeeded(game, game.getCombat());
}
private void makeSureItsNotComputer(Player controller) {
@ -761,7 +758,7 @@ public class Combat implements Serializable, Copyable<Combat> {
* Add info about attacker blocked by blocker to the game log
*/
private void logBlockerInfo(Player defender, Game game) {
boolean shownDefendingPlayer = game.getPlayers().size() < 3; // only two players no need to saw the attacked player
boolean shownDefendingPlayer = game.getPlayers().size() <= 2; // 1 vs 1 game, no need to saw the attacked player
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.defendingPlayerId.equals(defender.getId())) {
if (!shownDefendingPlayer) {

View file

@ -1,85 +0,0 @@
package mage.util.trace;
import java.util.UUID;
import mage.constants.Duration;
/**
*
* @author LevelX2
*/
public class TraceInfo {
public String info;
public String playerName;
public String sourceName;
public String rule;
public UUID abilityId;
public UUID effectId;
public Duration duration;
public long order;
public String getPlayerName() {
return playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public String getRule() {
return rule;
}
public void setRule(String rule) {
this.rule = rule;
}
public UUID getAbilityId() {
return abilityId;
}
public void setAbilityId(UUID abilityId) {
this.abilityId = abilityId;
}
public UUID getEffectId() {
return effectId;
}
public void setEffectId(UUID effectId) {
this.effectId = effectId;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public Duration getDuration() {
return duration;
}
public void setDuration(Duration duration) {
this.duration = duration;
}
public long getOrder() {
return order;
}
public void setOrder(long order) {
this.order = order;
}
}

View file

@ -1,241 +0,0 @@
package mage.util.trace;
import java.util.*;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.StaticAbility;
import mage.abilities.TriggeredAbility;
import mage.abilities.effects.ContinuousEffectsList;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.keyword.CantBeBlockedSourceAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.IntimidateAbility;
import mage.abilities.keyword.ReachAbility;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.combat.Combat;
import mage.game.combat.CombatGroup;
import mage.game.permanent.Permanent;
import mage.players.Player;
import org.apache.log4j.Logger;
/**
* @author magenoxx_at_gmail.com
*/
public final class TraceUtil {
private static final Logger log = Logger.getLogger(TraceUtil.class);
/**
* This method is intended to catch various bugs with combat.
*
* One of them (possibly the most annoying) is when creature without flying or reach blocks creature with flying.
* No test managed to reproduce it, but it happens in the games time to time and was reported by different players.
*
* The idea: is to catch such cases manually and print out as much information from game state that may help as possible.
* @param game
* @param combat
*/
public static void traceCombatIfNeeded(Game game, Combat combat) {
// trace non-flying vs flying
for (CombatGroup group : combat.getGroups()) {
for (UUID attackerId : group.getAttackers()) {
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null) {
if (hasFlying(attacker)) {
// traceCombat(game, attacker, null);
for (UUID blockerId : group.getBlockers()) {
Permanent blocker = game.getPermanent(blockerId);
if (blocker != null && !hasFlying(blocker) && !hasReach(blocker)) {
log.warn("Found non-flying non-reach creature blocking creature with flying");
traceCombat(game, attacker, blocker);
}
}
}
if (hasIntimidate(attacker)) {
for (UUID blockerId : group.getBlockers()) {
Permanent blocker = game.getPermanent(blockerId);
if (blocker != null && !blocker.isArtifact(game)
&& !attacker.getColor(game).shares(blocker.getColor(game))) {
log.warn("Found creature with intimidate blocked by non artifact not sharing color creature");
traceCombat(game, attacker, blocker);
}
}
}
if (cantBeBlocked(attacker)) {
if (!group.getBlockers().isEmpty()) {
Permanent blocker = game.getPermanent(group.getBlockers().get(0));
if (blocker != null) {
log.warn("Found creature that can't be blocked by some other creature");
traceCombat(game, attacker, blocker);
}
}
}
}
}
}
}
/**
* We need this to check Flying existence in not-common way: by instanceof.
* @return
*/
private static boolean hasFlying(Permanent permanent) {
for (Ability ability : permanent.getAbilities()) {
if (ability instanceof FlyingAbility) {
return true;
}
}
return false;
}
private static boolean hasIntimidate(Permanent permanent) {
for (Ability ability : permanent.getAbilities()) {
if (ability instanceof IntimidateAbility) {
return true;
}
}
return false;
}
private static boolean hasReach(Permanent permanent) {
for (Ability ability : permanent.getAbilities()) {
if (ability instanceof ReachAbility) {
return true;
}
}
return false;
}
private static boolean cantBeBlocked(Permanent permanent) {
for (Ability ability : permanent.getAbilities()) {
if (ability instanceof CantBeBlockedSourceAbility) {
return true;
}
}
return false;
}
private static void traceCombat(Game game, Permanent attacker, Permanent blocker) {
String prefix = "> ";
log.error(prefix+"Tracing game state...");
if (blocker != null) {
log.error(prefix+blocker.getLogName() + " could block " + attacker.getLogName());
}
log.error(prefix);
log.error(prefix+"Attacker abilities: ");
for (Ability ability : attacker.getAbilities()) {
log.error(prefix+" " + ability.toString() + ", id=" + ability.getId());
}
if (blocker != null) {
log.error(prefix+"Blocker abilities: ");
for (Ability ability : blocker.getAbilities()) {
log.error(prefix+" " + ability.toString() + ", id=" + ability.getId());
}
}
log.error(prefix);
log.error(prefix+"Flying ability id: " + FlyingAbility.getInstance().getId());
log.error(prefix+"Reach ability id: " + ReachAbility.getInstance().getId());
log.error(prefix+"Intimidate ability id: " + IntimidateAbility.getInstance().getId());
log.error(prefix);
log.error(prefix+"Restriction effects:");
log.error(prefix+" Applied to ATTACKER:");
Map<RestrictionEffect, Set<Ability>> attackerResEffects = game.getContinuousEffects().getApplicableRestrictionEffects(attacker, game);
for (Map.Entry<RestrictionEffect, Set<Ability>> entry : attackerResEffects.entrySet()) {
log.error(prefix+" " + entry.getKey());
log.error(prefix+" id=" + entry.getKey().getId());
for (Ability ability: entry.getValue()) {
log.error(prefix+" ability=" + ability);
}
}
log.error(prefix+" Applied to BLOCKER:");
if (blocker != null) {
Map<RestrictionEffect, Set<Ability>> blockerResEffects = game.getContinuousEffects().getApplicableRestrictionEffects(blocker, game);
for (Map.Entry<RestrictionEffect, Set<Ability>> entry : blockerResEffects.entrySet()) {
log.error(prefix+" " + entry.getKey());
log.error(prefix+" id=" + entry.getKey().getId());
for (Ability ability: entry.getValue()) {
log.error(prefix+" ability=" + ability);
}
}
}
ContinuousEffectsList<RestrictionEffect> restrictionEffects = (ContinuousEffectsList<RestrictionEffect>) game.getContinuousEffects().getRestrictionEffects();
log.error(prefix);
log.error(prefix+" List of all restriction effects:");
for (RestrictionEffect effect : restrictionEffects) {
log.error(prefix+" " + effect);
log.error(prefix+" id=" + effect.getId());
}
log.error(prefix);
log.error(prefix+" Trace Attacker:");
traceForPermanent(game, attacker, prefix, restrictionEffects);
if (blocker != null) {
log.error(prefix);
log.error(prefix+" Trace Blocker:");
traceForPermanent(game, blocker, prefix, restrictionEffects);
}
log.error(prefix);
}
private static void traceForPermanent(Game game, Permanent permanent, String uuid, ContinuousEffectsList<RestrictionEffect> restrictionEffects) {
for (RestrictionEffect effect: restrictionEffects) {
log.error(uuid+" effect=" + effect.toString() + " id=" + effect.getId());
for (Ability ability : restrictionEffects.getAbility(effect.getId())) {
if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, permanent, null)) {
log.error(uuid+" ability=" + ability + ", applies_to_attacker=" + effect.applies(permanent, ability, game));
} else {
boolean usable = ability.isInUseableZone(game, permanent, null);
log.error(uuid+" instanceof StaticAbility: " + (ability instanceof StaticAbility) + ", ability=" + ability);
log.error(uuid+" usable zone: " + usable + ", ability=" + ability);
if (!usable) {
Zone zone = ability.getZone();
log.error(uuid+" zone: " + zone);
MageObject object = game.getObject(ability.getSourceId());
log.error(uuid+" object: " + object);
if (object != null) {
log.error(uuid + " contains ability: " + object.getAbilities().contains(ability));
}
Zone test = game.getState().getZone(ability.getSourceId());
log.error(uuid+" test_zone: " + test);
}
}
}
}
}
public static void trace(String msg) {
log.info(msg);
}
/**
* Prints out a status of the currently existing triggered abilities
* @param game
*/
public static void traceTriggeredAbilities(Game game) {
log.info("-------------------------------------------------------------------------------------------------");
log.info("Turn: " + game.getTurnNum() + " - currently existing triggered abilities: " + game.getState().getTriggers().size());
Map<String, String> orderedAbilities = new TreeMap<>();
for (Map.Entry<String, TriggeredAbility> entry : game.getState().getTriggers().entrySet()) {
Player controller = game.getPlayer(entry.getValue().getControllerId());
MageObject source = game.getObject(entry.getValue().getSourceId());
orderedAbilities.put((controller == null ? "no controller": controller.getName()) + (source == null ? "no source": source.getIdName())+ entry.getKey(), entry.getKey());
}
String playerName = "";
for (Map.Entry<String, String> entry : orderedAbilities.entrySet()) {
TriggeredAbility trAbility = game.getState().getTriggers().get(entry.getValue());
Player controller = game.getPlayer(trAbility.getControllerId());
MageObject source = game.getObject(trAbility.getSourceId());
if (!controller.getName().equals(playerName)) {
playerName = controller.getName();
log.info("--- Player: " + playerName + " --------------------------------");
}
log.info((source == null ? "no source": source.getIdName()) + " -> "
+ trAbility.getRule());
}
}
}