refactor: added runtime check for wrong usage of AddContinuousEffectToGame (closes #12427)

This commit is contained in:
Oleg Agafonov 2024-06-07 23:20:13 +04:00
parent 37dbdb4b4b
commit a071593d47

View file

@ -8,6 +8,7 @@ import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.target.targetpointer.FirstTargetPointer;
/**
* @author noxx
@ -36,6 +37,14 @@ public class AddContinuousEffectToGame extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
for (Effect effect : this.effects) {
// runtime check
if (!effect.getTargetPointer().getClass().equals(FirstTargetPointer.class)
&& !effect.getTargetPointer().getClass().equals(this.getTargetPointer().getClass())) {
throw new IllegalArgumentException("Wrong code usage: found diff target pointers, must set target pointers to AddContinuousEffectToGame, not to inner effects"
+ " - " + source.getClass().getSimpleName()
+ " - " + source
);
}
effect.setTargetPointer(this.getTargetPointer().copy());
game.addEffect((ContinuousEffect) effect, source);
}