mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
[AFC] Implemented Maddening Hex
This commit is contained in:
parent
dfcb98b951
commit
e61f019cd3
3 changed files with 157 additions and 0 deletions
139
Mage.Sets/src/mage/cards/m/MaddeningHex.java
Normal file
139
Mage.Sets/src/mage/cards/m/MaddeningHex.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
package mage.cards.m;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.AttachEffect;
|
||||
import mage.abilities.keyword.EnchantAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPlayer;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class MaddeningHex extends CardImpl {
|
||||
|
||||
public MaddeningHex(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{R}{R}");
|
||||
|
||||
this.subtype.add(SubType.AURA);
|
||||
this.subtype.add(SubType.CURSE);
|
||||
|
||||
// Enchant player
|
||||
TargetPlayer auraTarget = new TargetPlayer();
|
||||
this.getSpellAbility().addTarget(auraTarget);
|
||||
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
|
||||
Ability ability = new EnchantAbility(auraTarget.getTargetName());
|
||||
this.addAbility(ability);
|
||||
|
||||
// Whenever enchanted player casts a noncreature spell, roll a d6. Maddening Hex deals damage to that player equal to the result. Then attach Maddening Hex to another one of your opponents chosen at random.
|
||||
this.addAbility(new MaddeningHexTriggeredAbility());
|
||||
}
|
||||
|
||||
private MaddeningHex(final MaddeningHex card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaddeningHex copy() {
|
||||
return new MaddeningHex(this);
|
||||
}
|
||||
}
|
||||
|
||||
class MaddeningHexTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public MaddeningHexTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new MaddeningHexEffect());
|
||||
}
|
||||
|
||||
private MaddeningHexTriggeredAbility(final MaddeningHexTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.SPELL_CAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Spell spell = game.getSpell(event.getTargetId());
|
||||
Permanent permanent = getSourcePermanentIfItStillExists(game);
|
||||
if (spell == null
|
||||
|| permanent == null
|
||||
|| spell.isCreature(game)
|
||||
|| !event.getPlayerId().equals(permanent.getAttachedTo())) {
|
||||
return false;
|
||||
}
|
||||
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaddeningHexTriggeredAbility copy() {
|
||||
return new MaddeningHexTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever enchanted player casts a noncreature spell, roll a d6. " +
|
||||
"{this} deals damage to that player equal to the result. " +
|
||||
"Then attach {this} to another one of your opponents chosen at random.";
|
||||
}
|
||||
}
|
||||
|
||||
class MaddeningHexEffect extends OneShotEffect {
|
||||
|
||||
MaddeningHexEffect() {
|
||||
super(Outcome.Benefit);
|
||||
}
|
||||
|
||||
private MaddeningHexEffect(final MaddeningHexEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaddeningHexEffect copy() {
|
||||
return new MaddeningHexEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
int result = controller.rollDice(source, game, 6);
|
||||
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.damage(result, source.getSourceId(), source, game);
|
||||
}
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent == null) {
|
||||
return true;
|
||||
}
|
||||
Set<UUID> opponents = game.getOpponents(source.getControllerId());
|
||||
if (player != null) {
|
||||
opponents.remove(player.getId());
|
||||
}
|
||||
if (!opponents.isEmpty()) {
|
||||
permanent.attachTo(RandomUtil.randomFromSet(opponents), source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -141,6 +141,7 @@ public final class ForgottenRealmsCommander extends ExpansionSet {
|
|||
cards.add(new SetCardInfo("Lightning Greaves", 331, Rarity.UNCOMMON, mage.cards.l.LightningGreaves.class));
|
||||
cards.add(new SetCardInfo("Loyal Apprentice", 132, Rarity.UNCOMMON, mage.cards.l.LoyalApprentice.class));
|
||||
cards.add(new SetCardInfo("Lumbering Falls", 247, Rarity.RARE, mage.cards.l.LumberingFalls.class));
|
||||
cards.add(new SetCardInfo("Maddening Hex", 32, Rarity.RARE, mage.cards.m.MaddeningHex.class));
|
||||
cards.add(new SetCardInfo("Magmaquake", 133, Rarity.RARE, mage.cards.m.Magmaquake.class));
|
||||
cards.add(new SetCardInfo("Marionette Master", 102, Rarity.RARE, mage.cards.m.MarionetteMaster.class));
|
||||
cards.add(new SetCardInfo("Masterwork of Ingenuity", 209, Rarity.RARE, mage.cards.m.MasterworkOfIngenuity.class));
|
||||
|
|
|
@ -2,6 +2,8 @@ package mage.util;
|
|||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by IGOUDT on 5-9-2016.
|
||||
|
@ -40,4 +42,19 @@ public final class RandomUtil {
|
|||
public static void setSeed(long newSeed) {
|
||||
random.setSeed(newSeed);
|
||||
}
|
||||
|
||||
public static UUID randomFromSet(Set<UUID> uuids) {
|
||||
if (uuids.size() < 2) {
|
||||
return uuids.stream().findFirst().orElse(null);
|
||||
}
|
||||
int rand = nextInt(uuids.size());
|
||||
int count = 0;
|
||||
for (UUID currentId : uuids) {
|
||||
if (count == rand) {
|
||||
return currentId;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue