mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Refactor - made card specific effects to attack random opponent shared effects
This commit is contained in:
parent
568044261c
commit
a9e479f7dd
4 changed files with 103 additions and 165 deletions
|
|
@ -0,0 +1,50 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.RequirementEffect;
|
||||
import mage.constants.Duration;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AttacksIfAbleTargetPlayerSourceEffect extends RequirementEffect {
|
||||
|
||||
public AttacksIfAbleTargetPlayerSourceEffect() {
|
||||
super(Duration.EndOfTurn);
|
||||
staticText = "{this} attacks that player this combat if able";
|
||||
}
|
||||
|
||||
public AttacksIfAbleTargetPlayerSourceEffect(final AttacksIfAbleTargetPlayerSourceEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttacksIfAbleTargetPlayerSourceEffect copy() {
|
||||
return new AttacksIfAbleTargetPlayerSourceEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||
if (permanent.getId().equals(source.getSourceId())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustAttack(Game game) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustBlock(Game game) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID mustAttackDefender(Ability source, Game game) {
|
||||
return getTargetPointer().getFirst(game, source);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package mage.abilities.effects.common.combat;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.AttacksIfAbleTargetPlayerSourceEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AttackIfAbleTargetRandomOpponentSourceEffect extends OneShotEffect {
|
||||
|
||||
public AttackIfAbleTargetRandomOpponentSourceEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "choose an opponent at random. {this} attacks that player this combat if able";
|
||||
}
|
||||
|
||||
public AttackIfAbleTargetRandomOpponentSourceEffect(final AttackIfAbleTargetRandomOpponentSourceEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttackIfAbleTargetRandomOpponentSourceEffect copy() {
|
||||
return new AttackIfAbleTargetRandomOpponentSourceEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
List<UUID> opponents = new ArrayList<>();
|
||||
opponents.addAll(game.getOpponents(controller.getId()));
|
||||
Player opponent = game.getPlayer(opponents.get(RandomUtil.nextInt(opponents.size())));
|
||||
if (opponent != null) {
|
||||
ContinuousEffect effect = new AttacksIfAbleTargetPlayerSourceEffect();
|
||||
effect.setTargetPointer(new FixedTarget(opponent.getId()));
|
||||
game.addEffect(effect, source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue