mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 13:19:18 -08:00
Some changes to prevention effects.
This commit is contained in:
parent
969aca4b2c
commit
b572e8c7d6
6 changed files with 31 additions and 77 deletions
|
|
@ -28,15 +28,12 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.constants.Duration;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.PreventionEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
|
|
@ -68,57 +65,19 @@ public class PreventDamageByTargetEffect extends PreventionEffectImpl<PreventDam
|
|||
return new PreventDamageByTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
for (Target target : source.getTargets()) {
|
||||
for (UUID chosen : target.getTargets()) {
|
||||
if (event.getSourceId().equals(chosen)) {
|
||||
preventDamage(event, source, chosen, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
|
||||
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getId(), source.getControllerId(), event.getAmount(), false);
|
||||
if (!game.replaceEvent(preventEvent)) {
|
||||
if (amountToPrevent == Integer.MAX_VALUE) {
|
||||
int damage = event.getAmount();
|
||||
event.setAmount(0);
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage));
|
||||
} else {
|
||||
if (event.getAmount() >= amountToPrevent) {
|
||||
int damage = amountToPrevent;
|
||||
event.setAmount(event.getAmount() - amountToPrevent);
|
||||
this.used = true;
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage));
|
||||
} else {
|
||||
int damage = event.getAmount();
|
||||
event.setAmount(0);
|
||||
amountToPrevent -= damage;
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (!this.used && super.applies(event, source, game)) {
|
||||
for (Target target : source.getTargets()) {
|
||||
for (UUID chosen : target.getTargets()) {
|
||||
if (event.getSourceId().equals(chosen)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.getTargetPointer().getTargets(game, source).contains(event.getSourceId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
if (amountToPrevent == Integer.MAX_VALUE) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Prevent all damage target ");
|
||||
|
|
|
|||
|
|
@ -38,19 +38,19 @@ import mage.game.events.GameEvent;
|
|||
*
|
||||
* @author Quercitron
|
||||
*/
|
||||
public class PreventDamageSourceEffect extends PreventionEffectImpl<PreventDamageSourceEffect> {
|
||||
public class PreventDamageToSourceEffect extends PreventionEffectImpl<PreventDamageToSourceEffect> {
|
||||
|
||||
public PreventDamageSourceEffect(Duration duration, int amountToPrevent) {
|
||||
public PreventDamageToSourceEffect(Duration duration, int amountToPrevent) {
|
||||
super(duration, amountToPrevent, false);
|
||||
}
|
||||
|
||||
public PreventDamageSourceEffect(final PreventDamageSourceEffect effect) {
|
||||
public PreventDamageToSourceEffect(final PreventDamageToSourceEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreventDamageSourceEffect copy() {
|
||||
return new PreventDamageSourceEffect(this);
|
||||
public PreventDamageToSourceEffect copy() {
|
||||
return new PreventDamageToSourceEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -112,31 +112,35 @@ public class TargetSource extends TargetObject<TargetSource> {
|
|||
for (StackObject stackObject: game.getStack()) {
|
||||
if (game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) && filter.match(stackObject, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
|
||||
if (filter.match(permanent, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Card card : game.getExile().getAllCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -149,7 +153,7 @@ public class TargetSource extends TargetObject<TargetSource> {
|
|||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
for (StackObject stackObject: game.getStack()) {
|
||||
if (game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) && filter.match(stackObject, game)) {
|
||||
possibleTargets.add(stackObject.getId());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue