mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
wip
This commit is contained in:
parent
f09a6d847e
commit
cab436e9e5
9 changed files with 186 additions and 25 deletions
|
|
@ -17,6 +17,9 @@ import mage.cards.decks.Deck;
|
|||
import mage.choices.Choice;
|
||||
import mage.constants.*;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.combat.Combat;
|
||||
import mage.game.command.Commander;
|
||||
import mage.game.command.Emblem;
|
||||
|
|
@ -485,4 +488,9 @@ public interface Game extends MageItem, Serializable {
|
|||
default Set<UUID> getCommandersIds(Player player) {
|
||||
return getCommandersIds(player, CommanderCardType.ANY);
|
||||
}
|
||||
|
||||
void addUsePowerInsteadOfToughnessForDamageLethalityFilter(UUID source, FilterCreaturePermanent filter);
|
||||
|
||||
List<FilterCreaturePermanent> getActiveUsePowerInsteadOfToughnessForDamageLethalityFilters();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.game;
|
||||
|
||||
import mage.MageException;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.*;
|
||||
import mage.abilities.common.AttachableToRestrictedAbility;
|
||||
|
|
@ -31,6 +32,7 @@ import mage.filter.FilterCard;
|
|||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.combat.Combat;
|
||||
|
|
@ -69,6 +71,9 @@ import java.io.IOException;
|
|||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
public abstract class GameImpl implements Game, Serializable {
|
||||
|
||||
|
|
@ -144,6 +149,8 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
// temporary store for income concede commands, don't copy
|
||||
private final LinkedList<UUID> concedingPlayers = new LinkedList<>();
|
||||
|
||||
private Map<UUID, FilterCreaturePermanent> usePowerInsteadOfToughnessForDamageLethalityFilters = new HashMap<>();
|
||||
|
||||
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startLife) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.range = range;
|
||||
|
|
@ -1888,6 +1895,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
|
||||
List<Permanent> legendary = new ArrayList<>();
|
||||
List<Permanent> worldEnchantment = new ArrayList<>();
|
||||
List<FilterCreaturePermanent> usePowerInsteadOfToughnessForDamageLethalityFilters = getActiveUsePowerInsteadOfToughnessForDamageLethalityFilters();
|
||||
for (Permanent perm : getBattlefield().getAllActivePermanents()) {
|
||||
if (perm.isCreature()) {
|
||||
//20091005 - 704.5f
|
||||
|
|
@ -1897,10 +1905,19 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
continue;
|
||||
}
|
||||
} //20091005 - 704.5g/704.5h
|
||||
else if (perm.getToughness().getValue() <= perm.getDamage() || perm.isDeathtouched()) {
|
||||
if (perm.destroy(null, this, false)) {
|
||||
somethingHappened = true;
|
||||
continue;
|
||||
else {
|
||||
/*
|
||||
* for handling Zilortha, Strength Incarnate:
|
||||
* Any time the game is checking whether damage is lethal or if a creature should be destroyed for having lethal damage marked on it, use the power of your creatures rather than their toughness to check the damage against. This includes being assigned trample damage, damage from Flame Spill, and so on.
|
||||
*/
|
||||
boolean usePowerInsteadOfToughnessForDamageLethality = usePowerInsteadOfToughnessForDamageLethalityFilters.stream()
|
||||
.anyMatch(filter -> filter.match(perm, this));
|
||||
MageInt lethalDamageThreshold = usePowerInsteadOfToughnessForDamageLethality ? perm.getPower() : perm.getToughness();
|
||||
if (lethalDamageThreshold.getValue() <= perm.getDamage() || perm.isDeathtouched()) {
|
||||
if (perm.destroy(null, this, false)) {
|
||||
somethingHappened = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (perm.getPairedCard() != null) {
|
||||
|
|
@ -3300,4 +3317,17 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
return player.getCommandersIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUsePowerInsteadOfToughnessForDamageLethalityFilter(UUID source, FilterCreaturePermanent filter) {
|
||||
usePowerInsteadOfToughnessForDamageLethalityFilters.putIfAbsent(source, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FilterCreaturePermanent> getActiveUsePowerInsteadOfToughnessForDamageLethalityFilters() {
|
||||
return usePowerInsteadOfToughnessForDamageLethalityFilters.isEmpty() ? emptyList() : getBattlefield().getAllActivePermanents().stream()
|
||||
.map(Card::getId)
|
||||
.filter(usePowerInsteadOfToughnessForDamageLethalityFilters::containsKey)
|
||||
.map(usePowerInsteadOfToughnessForDamageLethalityFilters::get)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.io.Serializable;
|
|||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.ControllerAssignCombatDamageToBlockersAbility;
|
||||
import mage.abilities.common.ControllerDivideCombatDamageAbility;
|
||||
|
|
@ -19,12 +20,15 @@ import mage.abilities.keyword.TrampleAbility;
|
|||
import mage.constants.AsThoughEffectType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.util.Copyable;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -271,12 +275,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
|
|||
if (blocked && canDamage(attacker, first)) {
|
||||
int damage = getDamageValueFromPermanent(attacker, game);
|
||||
if (hasTrample(attacker)) {
|
||||
int lethalDamage;
|
||||
if (attacker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
|
||||
lethalDamage = 1;
|
||||
} else {
|
||||
lethalDamage = Math.max(blocker.getToughness().getValue() - blocker.getDamage(), 0);
|
||||
}
|
||||
int lethalDamage = getLethalDamage(blocker, attacker, game);
|
||||
if (lethalDamage >= damage) {
|
||||
blocker.markDamage(damage, attacker.getId(), game, true, true);
|
||||
} else {
|
||||
|
|
@ -325,12 +324,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
|
|||
for (UUID blockerId : new ArrayList<>(blockerOrder)) { // prevent ConcurrentModificationException
|
||||
Permanent blocker = game.getPermanent(blockerId);
|
||||
if (blocker != null) {
|
||||
int lethalDamage;
|
||||
if (attacker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
|
||||
lethalDamage = 1;
|
||||
} else {
|
||||
lethalDamage = Math.max(blocker.getToughness().getValue() - blocker.getDamage(), 0);
|
||||
}
|
||||
int lethalDamage = getLethalDamage(blocker, attacker, game);
|
||||
if (lethalDamage >= damage) {
|
||||
if (!oldRuleDamage) {
|
||||
assigned.put(blockerId, damage);
|
||||
|
|
@ -521,12 +515,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
|
|||
for (UUID attackerId : attackerOrder) {
|
||||
Permanent attacker = game.getPermanent(attackerId);
|
||||
if (attacker != null) {
|
||||
int lethalDamage;
|
||||
if (blocker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
|
||||
lethalDamage = 1;
|
||||
} else {
|
||||
lethalDamage = Math.max(attacker.getToughness().getValue() - attacker.getDamage(), 0);
|
||||
}
|
||||
int lethalDamage = getLethalDamage(attacker, blocker, game);
|
||||
if (lethalDamage >= damage) {
|
||||
if (!oldRuleDamage) {
|
||||
assigned.put(attackerId, damage);
|
||||
|
|
@ -936,4 +925,26 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int getLethalDamage(Permanent blocker, Permanent attacker, Game game) {
|
||||
int lethalDamage;
|
||||
if (attacker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
|
||||
lethalDamage = 1;
|
||||
} else {
|
||||
lethalDamage = getLethalDamage(blocker, game);
|
||||
}
|
||||
return lethalDamage;
|
||||
}
|
||||
|
||||
public static int getLethalDamage(Permanent damagedPermanent, Game game) {
|
||||
List<FilterCreaturePermanent> usePowerInsteadOfToughnessForDamageLethalityFilters = game.getActiveUsePowerInsteadOfToughnessForDamageLethalityFilters();
|
||||
/*
|
||||
* for handling Zilortha, Strength Incarnate:
|
||||
* Any time the game is checking whether damage is lethal or if a creature should be destroyed for having lethal damage marked on it, use the power of your creatures rather than their toughness to check the damage against. This includes being assigned trample damage, damage from Flame Spill, and so on.
|
||||
*/
|
||||
boolean usePowerInsteadOfToughnessForDamageLethality = usePowerInsteadOfToughnessForDamageLethalityFilters.stream()
|
||||
.anyMatch(filter -> filter.match(damagedPermanent, game));
|
||||
MageInt lethalDamageThreshold = usePowerInsteadOfToughnessForDamageLethality? damagedPermanent.getPower() : damagedPermanent.getToughness();
|
||||
return Math.max(lethalDamageThreshold.getValue() - damagedPermanent.getDamage(), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue