From c2bba588fff70e16084f74d3cf21937d79d0919e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 24 Jun 2015 00:10:06 +0200 Subject: [PATCH] [ORI] Implemented Renown keyword. --- .../mage/abilities/keyword/RenownAbility.java | 111 ++++++++++++++++++ Mage/src/mage/game/events/GameEvent.java | 1 + Mage/src/mage/game/permanent/Permanent.java | 3 + .../mage/game/permanent/PermanentImpl.java | 11 ++ Utils/keywords.txt | 1 + 5 files changed, 127 insertions(+) create mode 100644 Mage/src/mage/abilities/keyword/RenownAbility.java diff --git a/Mage/src/mage/abilities/keyword/RenownAbility.java b/Mage/src/mage/abilities/keyword/RenownAbility.java new file mode 100644 index 0000000000..506071634a --- /dev/null +++ b/Mage/src/mage/abilities/keyword/RenownAbility.java @@ -0,0 +1,111 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.keyword; + +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.DamagedPlayerEvent; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.util.CardUtil; + +/** + * + * @author LevelX2 + */ + + +public class RenownAbility extends TriggeredAbilityImpl { + + private int renownValue; + + public RenownAbility(int renownValue) { + super(Zone.BATTLEFIELD, new BecomeRenownSourceEffect(renownValue), false); + this.renownValue = renownValue; + } + + public RenownAbility(final RenownAbility ability) { + super(ability); + this.renownValue = ability.renownValue; + } + + @Override + public RenownAbility copy() { + return new RenownAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + return event.getSourceId().equals(getSourceId()) + && ((DamagedPlayerEvent) event).isCombatDamage(); + } + + @Override + public String getRule() { + return "Whenever {this} deals combat damage to a player, " + super.getRule(); + } + + public int getRenownValue() { + return renownValue; + } +} + +class BecomeRenownSourceEffect extends OneShotEffect { + + public BecomeRenownSourceEffect(int renownValue) { + super(Outcome.BoostCreature); + this.staticText = setText(renownValue); + } + + public BecomeRenownSourceEffect(final BecomeRenownSourceEffect effect) { + super(effect); + } + + @Override + public BecomeRenownSourceEffect copy() { + return new BecomeRenownSourceEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null && !permanent.isRenown() && source instanceof RenownAbility) { + game.informPlayers(permanent.getLogName() + " is now renown"); + int renownValue = ((RenownAbility) source).getRenownValue(); + // handle renown = X + if (renownValue == Integer.MAX_VALUE) { + renownValue = source.getManaCostsToPay().getX(); + } + new AddCountersSourceEffect(CounterType.P1P1.createInstance(renownValue),true).apply(game, source); + permanent.setRenown(true); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_RENOWN, source.getSourceId(), source.getSourceId(), source.getControllerId(), renownValue)); + return true; + } + return false; + } + + private String setText(int renownValue) { + // Renown 1 (When this creature deals combat damage to a player, if it isn't renowned, put a +1/+1 counter on it and it becomes renowned.) + StringBuilder sb = new StringBuilder("Renown "); + sb.append(renownValue == Integer.MAX_VALUE ? "X":renownValue) + .append(". (When this creature deals combat damage to a player, if it isn't renowned, put ") + .append(renownValue == Integer.MAX_VALUE ? "X":CardUtil.numberToText(renownValue, "a")) + .append(" +1/+1 counter on it and it becomes renowned.)").toString(); + return sb.toString(); + } + +} diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index aae2b81a16..4b0c5223b6 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -185,6 +185,7 @@ public class GameEvent implements Serializable { UNFLIP, UNFLIPPED, TRANSFORM, TRANSFORMED, BECOMES_MONSTROUS, + BECOMES_RENOWN, PHASE_OUT, PHASED_OUT, PHASE_IN, PHASED_IN, TURNFACEUP, TURNEDFACEUP, diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 8e7258301a..22e6319590 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -75,6 +75,9 @@ public interface Permanent extends Card, Controllable { boolean isMonstrous(); void setMonstrous(boolean value); + boolean isRenown(); + void setRenown(boolean value); + void setCardNumber(int cid); void setExpansionSetCode(String expansionSetCode); void setRarity(Rarity rarity); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index e50d04cb09..60df01dae3 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -91,6 +91,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { protected boolean flipped; protected boolean transformed; protected boolean monstrous; + protected boolean renown; protected boolean manifested = false; protected boolean morphed = false; protected UUID originalControllerId; @@ -1265,6 +1266,16 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { this.monstrous = value; } + @Override + public boolean isRenown() { + return this.renown; + } + + @Override + public void setRenown(boolean value) { + this.renown = value; + } + @Override public void setPairedCard(UUID pairedCard) { this.pairedCard = pairedCard; diff --git a/Utils/keywords.txt b/Utils/keywords.txt index 57945d8a0f..0e7ad4bea2 100644 --- a/Utils/keywords.txt +++ b/Utils/keywords.txt @@ -52,6 +52,7 @@ Provoke|new| Prowess|new| Reach|instance| Rebound|new| +Renown|number| Scavenge|cost| Shadow|instance| Shroud|instance|