Merge pull request #5196 from credman0/EmissaryOfGrudges

Implemented Emissary of Grudges
This commit is contained in:
LevelX2 2018-08-15 08:17:16 +02:00 committed by GitHub
commit 6712e50146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 260 additions and 113 deletions

View file

@ -0,0 +1,68 @@
package mage.abilities.costs.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
import mage.abilities.effects.common.ChooseSecretOpponentEffect;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author LevelX2
* @author credman0
*/
public class RevealSecretOpponentCost extends CostImpl {
public RevealSecretOpponentCost() {
this.text = "Reveal the player you chose";
}
public RevealSecretOpponentCost(final RevealSecretOpponentCost cost) {
super(cost);
}
@Override
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
UUID playerThatChoseId = (UUID) game.getState().getValue(sourceId + ChooseSecretOpponentEffect.SECRET_OWNER);
if (playerThatChoseId == null || !playerThatChoseId.equals(controllerId)) {
return false;
}
UUID opponentId = (UUID) game.getState().getValue(sourceId + ChooseSecretOpponentEffect.SECRET_OPPONENT);
return opponentId != null;
}
@Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
UUID playerThatChoseId = (UUID) game.getState().getValue(sourceId + ChooseSecretOpponentEffect.SECRET_OWNER);
if (playerThatChoseId == null || !playerThatChoseId.equals(controllerId)) {
return false;
}
UUID opponentId = (UUID) game.getState().getValue(sourceId + ChooseSecretOpponentEffect.SECRET_OPPONENT);
if (opponentId != null) {
game.getState().setValue(sourceId + ChooseSecretOpponentEffect.SECRET_OWNER, null); // because only once, the vale is set to null
Player controller = game.getPlayer(controllerId);
Player opponent = game.getPlayer(opponentId);
MageObject sourceObject = game.getObject(sourceId);
if (controller != null && opponent != null && sourceObject != null) {
if (sourceObject instanceof Permanent) {
((Permanent) sourceObject).addInfo(ChooseSecretOpponentEffect.SECRET_OPPONENT, null, game);
}
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " reveals the secretly chosen opponent " + opponent.getLogName());
}
paid = true;
}
return paid;
}
@Override
public RevealSecretOpponentCost copy() {
return new RevealSecretOpponentCost(this);
}
}

View file

@ -0,0 +1,68 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetOpponent;
import mage.util.CardUtil;
/**
*
* @author LevelX2
* @author credman0
*/
public class ChooseSecretOpponentEffect extends OneShotEffect {
public static final String SECRET_OPPONENT = "_secOpp";
public static final String SECRET_OWNER = "_secOwn";
public ChooseSecretOpponentEffect() {
super(Outcome.Neutral);
staticText = "secretly choose an opponent";
}
public ChooseSecretOpponentEffect(final ChooseSecretOpponentEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
mageObject = game.getObject(source.getSourceId());
}
if (controller != null && mageObject != null) {
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setTargetName("opponent (secretly)");
while (!controller.choose(outcome, targetOpponent, source.getSourceId(), game)) {
if (!controller.canRespond()) {
return false;
}
}
if (targetOpponent.getTargets().isEmpty()) {
return false;
}
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has secretly chosen an opponent.");
}
game.getState().setValue(mageObject.getId() + SECRET_OPPONENT, targetOpponent.getTargets().get(0));
game.getState().setValue(mageObject.getId() + SECRET_OWNER, controller.getId());
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo(SECRET_OPPONENT,
CardUtil.addToolTipMarkTags(controller.getLogName() + " has secretly chosen an opponent."), game);
}
}
return false;
}
@Override
public ChooseSecretOpponentEffect copy() {
return new ChooseSecretOpponentEffect(this);
}
}