[ORI] Implemented Renown keyword.

This commit is contained in:
LevelX2 2015-06-24 00:10:06 +02:00
parent 085870de1f
commit c2bba588ff
5 changed files with 127 additions and 0 deletions

View file

@ -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(". <i>(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.)</i>").toString();
return sb.toString();
}
}

View file

@ -185,6 +185,7 @@ public class GameEvent implements Serializable {
UNFLIP, UNFLIPPED, UNFLIP, UNFLIPPED,
TRANSFORM, TRANSFORMED, TRANSFORM, TRANSFORMED,
BECOMES_MONSTROUS, BECOMES_MONSTROUS,
BECOMES_RENOWN,
PHASE_OUT, PHASED_OUT, PHASE_OUT, PHASED_OUT,
PHASE_IN, PHASED_IN, PHASE_IN, PHASED_IN,
TURNFACEUP, TURNEDFACEUP, TURNFACEUP, TURNEDFACEUP,

View file

@ -75,6 +75,9 @@ public interface Permanent extends Card, Controllable {
boolean isMonstrous(); boolean isMonstrous();
void setMonstrous(boolean value); void setMonstrous(boolean value);
boolean isRenown();
void setRenown(boolean value);
void setCardNumber(int cid); void setCardNumber(int cid);
void setExpansionSetCode(String expansionSetCode); void setExpansionSetCode(String expansionSetCode);
void setRarity(Rarity rarity); void setRarity(Rarity rarity);

View file

@ -91,6 +91,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
protected boolean flipped; protected boolean flipped;
protected boolean transformed; protected boolean transformed;
protected boolean monstrous; protected boolean monstrous;
protected boolean renown;
protected boolean manifested = false; protected boolean manifested = false;
protected boolean morphed = false; protected boolean morphed = false;
protected UUID originalControllerId; protected UUID originalControllerId;
@ -1265,6 +1266,16 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.monstrous = value; this.monstrous = value;
} }
@Override
public boolean isRenown() {
return this.renown;
}
@Override
public void setRenown(boolean value) {
this.renown = value;
}
@Override @Override
public void setPairedCard(UUID pairedCard) { public void setPairedCard(UUID pairedCard) {
this.pairedCard = pairedCard; this.pairedCard = pairedCard;

View file

@ -52,6 +52,7 @@ Provoke|new|
Prowess|new| Prowess|new|
Reach|instance| Reach|instance|
Rebound|new| Rebound|new|
Renown|number|
Scavenge|cost| Scavenge|cost|
Shadow|instance| Shadow|instance|
Shroud|instance| Shroud|instance|