mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
* Fixed some bugs in damage prevention handling.
This commit is contained in:
parent
a556341289
commit
29c7354bb4
3 changed files with 9 additions and 34 deletions
|
@ -60,6 +60,7 @@ public abstract class PreventionEffectImpl<T extends PreventionEffectImpl<T>> ex
|
||||||
this.effectType = EffectType.PREVENTION;
|
this.effectType = EffectType.PREVENTION;
|
||||||
this.amountToPrevent = amountToPrevent;
|
this.amountToPrevent = amountToPrevent;
|
||||||
this.onlyCombat = onlyCombat;
|
this.onlyCombat = onlyCombat;
|
||||||
|
this.consumable = consumable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreventionEffectImpl(final PreventionEffectImpl effect) {
|
public PreventionEffectImpl(final PreventionEffectImpl effect) {
|
||||||
|
@ -83,7 +84,7 @@ public abstract class PreventionEffectImpl<T extends PreventionEffectImpl<T>> ex
|
||||||
amountToPrevent = preventionData.getRemainingAmount();
|
amountToPrevent = preventionData.getRemainingAmount();
|
||||||
}
|
}
|
||||||
if (amountToPrevent == 0) {
|
if (amountToPrevent == 0) {
|
||||||
this.used = true;
|
this.discard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return preventionData;
|
return preventionData;
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
*/
|
*/
|
||||||
package mage.abilities.effects.common;
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
import mage.constants.Duration;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.Mode;
|
import mage.abilities.Mode;
|
||||||
import mage.abilities.effects.PreventionEffectImpl;
|
import mage.abilities.effects.PreventionEffectImpl;
|
||||||
|
import mage.constants.Duration;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
@ -40,16 +40,12 @@ import mage.game.events.GameEvent;
|
||||||
*/
|
*/
|
||||||
public class PreventDamageSourceEffect extends PreventionEffectImpl<PreventDamageSourceEffect> {
|
public class PreventDamageSourceEffect extends PreventionEffectImpl<PreventDamageSourceEffect> {
|
||||||
|
|
||||||
private int amount;
|
public PreventDamageSourceEffect(Duration duration, int amountToPrevent) {
|
||||||
|
super(duration, amountToPrevent, false);
|
||||||
public PreventDamageSourceEffect(Duration duration, int amount) {
|
|
||||||
super(duration);
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreventDamageSourceEffect(final PreventDamageSourceEffect effect) {
|
public PreventDamageSourceEffect(final PreventDamageSourceEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
this.amount = effect.amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,31 +58,9 @@ public class PreventDamageSourceEffect extends PreventionEffectImpl<PreventDamag
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
|
||||||
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getSourceId(), source.getId(), source.getControllerId(), event.getAmount(), false);
|
|
||||||
if (!game.replaceEvent(preventEvent)) {
|
|
||||||
if (event.getAmount() >= this.amount) {
|
|
||||||
int damage = amount;
|
|
||||||
event.setAmount(event.getAmount() - amount);
|
|
||||||
this.used = true;
|
|
||||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getSourceId(), source.getId(), source.getControllerId(), damage));
|
|
||||||
} else {
|
|
||||||
int damage = event.getAmount();
|
|
||||||
event.setAmount(0);
|
|
||||||
amount -= damage;
|
|
||||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getSourceId(), source.getId(), source.getControllerId(), damage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId())) {
|
return super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,10 +69,10 @@ public class PreventDamageSourceEffect extends PreventionEffectImpl<PreventDamag
|
||||||
return staticText;
|
return staticText;
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (amount == Integer.MAX_VALUE) {
|
if (amountToPrevent == Integer.MAX_VALUE) {
|
||||||
sb.append("Prevent all damage that would be dealt to ");
|
sb.append("Prevent all damage that would be dealt to ");
|
||||||
} else {
|
} else {
|
||||||
sb.append("Prevent the next ").append(amount).append(" damage that would be dealt to ");
|
sb.append("Prevent the next ").append(amountToPrevent).append(" damage that would be dealt to ");
|
||||||
}
|
}
|
||||||
sb.append("{source} ").append(duration.toString());
|
sb.append("{source} ").append(duration.toString());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|
|
@ -1893,7 +1893,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
}
|
}
|
||||||
if (amountToPrevent != Integer.MAX_VALUE) {
|
if (amountToPrevent != Integer.MAX_VALUE) {
|
||||||
// set remaining amount
|
// set remaining amount
|
||||||
event.setData(Integer.toString(amountToPrevent -= result.getPreventedDamage()));
|
result.setRemainingAmount(amountToPrevent -= result.getPreventedDamage());
|
||||||
}
|
}
|
||||||
MageObject damageSource = game.getObject(damageEvent.getSourceId());
|
MageObject damageSource = game.getObject(damageEvent.getSourceId());
|
||||||
MageObject preventionSource = game.getObject(source.getSourceId());
|
MageObject preventionSource = game.getObject(source.getSourceId());
|
||||||
|
|
Loading…
Reference in a new issue