mirror of
https://github.com/magefree/mage.git
synced 2025-12-30 07:22:03 -08:00
[OTJ] Implementing "saddle" mechanic (#12012)
* [OTJ] Implement Trained Arynx * implement saddle cost * update saddled effect * add test * add sorcery speed to saddle ability * apply requested changes * [OTJ] Implement Quilled Charger * rework test
This commit is contained in:
parent
2dbd313956
commit
8fbc7c9507
12 changed files with 447 additions and 2 deletions
|
|
@ -0,0 +1,37 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class AttacksWhileSaddledTriggeredAbility extends AttacksTriggeredAbility {
|
||||
|
||||
public AttacksWhileSaddledTriggeredAbility(Effect effect) {
|
||||
super(effect);
|
||||
this.setTriggerPhrase("Whenever {this} attacks while saddled, ");
|
||||
}
|
||||
|
||||
private AttacksWhileSaddledTriggeredAbility(final AttacksWhileSaddledTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttacksWhileSaddledTriggeredAbility copy() {
|
||||
return new AttacksWhileSaddledTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
return super.checkTrigger(event, game)
|
||||
&& Optional
|
||||
.ofNullable(getSourcePermanentIfItStillExists(game))
|
||||
.map(Permanent::isSaddled)
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum SaddledCondition implements Condition {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return Optional
|
||||
.ofNullable(source.getSourcePermanentIfItStillExists(game))
|
||||
.map(Permanent::isSaddled)
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
177
Mage/src/main/java/mage/abilities/keyword/SaddleAbility.java
Normal file
177
Mage/src/main/java/mage/abilities/keyword/SaddleAbility.java
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.condition.common.SaddledCondition;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.hint.ConditionHint;
|
||||
import mage.abilities.hint.Hint;
|
||||
import mage.abilities.hint.HintUtils;
|
||||
import mage.constants.*;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.AnotherPredicate;
|
||||
import mage.filter.predicate.permanent.TappedPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class SaddleAbility extends SimpleActivatedAbility {
|
||||
|
||||
private final int value;
|
||||
private static final Hint hint = new ConditionHint(SaddledCondition.instance, "This permanent is saddled");
|
||||
|
||||
public SaddleAbility(int value) {
|
||||
super(new SaddleEffect(), new SaddleCost(value));
|
||||
this.value = value;
|
||||
this.addHint(hint);
|
||||
this.setTiming(TimingRule.SORCERY);
|
||||
}
|
||||
|
||||
private SaddleAbility(final SaddleAbility ability) {
|
||||
super(ability);
|
||||
this.value = ability.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaddleAbility copy() {
|
||||
return new SaddleAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Saddle " + value + " <i>(Tap any number of other creatures you control with total power " +
|
||||
value + " or more: This Mount becomes saddled until end of turn. Saddle only as a sorcery.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class SaddleEffect extends ContinuousEffectImpl {
|
||||
|
||||
SaddleEffect() {
|
||||
super(Duration.EndOfTurn, Layer.RulesEffects, SubLayer.NA, Outcome.Benefit);
|
||||
}
|
||||
|
||||
private SaddleEffect(final SaddleEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaddleEffect copy() {
|
||||
return new SaddleEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
game.fireEvent(GameEvent.getEvent(
|
||||
GameEvent.EventType.MOUNT_SADDLED,
|
||||
source.getSourceId(),
|
||||
source, source.getControllerId()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Optional.ofNullable(source.getSourcePermanentIfItStillExists(game))
|
||||
.ifPresent(permanent -> permanent.setSaddled(true));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class SaddleCost extends CostImpl {
|
||||
|
||||
|
||||
private static final FilterControlledCreaturePermanent filter
|
||||
= new FilterControlledCreaturePermanent("another untapped creature you control");
|
||||
|
||||
static {
|
||||
filter.add(TappedPredicate.UNTAPPED);
|
||||
filter.add(AnotherPredicate.instance);
|
||||
}
|
||||
|
||||
private final int value;
|
||||
|
||||
SaddleCost(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private SaddleCost(final SaddleCost cost) {
|
||||
super(cost);
|
||||
this.value = cost.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true) {
|
||||
@Override
|
||||
public String getMessage() {
|
||||
// shows selected power
|
||||
int selectedPower = this.targets.keySet().stream()
|
||||
.map(game::getPermanent)
|
||||
.filter(Objects::nonNull)
|
||||
.map(MageObject::getPower)
|
||||
.mapToInt(MageInt::getValue)
|
||||
.sum();
|
||||
String extraInfo = "(selected power " + selectedPower + " of " + value + ")";
|
||||
if (selectedPower >= value) {
|
||||
extraInfo = HintUtils.prepareText(extraInfo, Color.GREEN);
|
||||
}
|
||||
return super.getMessage() + " " + extraInfo;
|
||||
}
|
||||
};
|
||||
|
||||
// can cancel
|
||||
if (target.choose(Outcome.Tap, controllerId, source.getSourceId(), source, game)) {
|
||||
int sumPower = 0;
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.SADDLE_MOUNT, targetId, source, controllerId);
|
||||
if (!game.replaceEvent(event)) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null && permanent.tap(source, game)) {
|
||||
sumPower += permanent.getPower().getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
paid = sumPower >= value;
|
||||
if (paid) {
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.SADDLED_MOUNT, targetId, source, controllerId));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return paid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
int sumPower = 0;
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controllerId, game)) {
|
||||
sumPower += Math.max(permanent.getPower().getValue(), 0);
|
||||
if (sumPower >= value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaddleCost copy() {
|
||||
return new SaddleCost(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -315,6 +315,7 @@ public enum SubType {
|
|||
PINCHER("Pincher", SubTypeSet.CreatureType),
|
||||
PIRATE("Pirate", SubTypeSet.CreatureType),
|
||||
PLANT("Plant", SubTypeSet.CreatureType),
|
||||
PORCUPINE("Porcupine", SubTypeSet.CreatureType),
|
||||
PRAETOR("Praetor", SubTypeSet.CreatureType),
|
||||
PRIMARCH("Primarch", SubTypeSet.CreatureType),
|
||||
PRISM("Prism", SubTypeSet.CreatureType),
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public class GameEvent implements Serializable {
|
|||
*/
|
||||
CREW_VEHICLE,
|
||||
/* CREW_VEHICLE
|
||||
targetId the id of the creature that crewed a vehicle
|
||||
targetId the id of the creature that will crew a vehicle
|
||||
sourceId sourceId of the vehicle
|
||||
playerId the id of the controlling player
|
||||
*/
|
||||
|
|
@ -176,6 +176,24 @@ public class GameEvent implements Serializable {
|
|||
sourceId sourceId of the vehicle
|
||||
playerId the id of the controlling player
|
||||
*/
|
||||
SADDLE_MOUNT,
|
||||
/* SADDLE_MOUNT
|
||||
targetId the id of the creature that will saddle a mount
|
||||
sourceId sourceId of the mount
|
||||
playerId the id of the controlling player
|
||||
*/
|
||||
SADDLED_MOUNT,
|
||||
/* SADDLED_MOUNT
|
||||
targetId the id of the creature that saddled a mount
|
||||
sourceId sourceId of the mount
|
||||
playerId the id of the controlling player
|
||||
*/
|
||||
MOUNT_SADDLED,
|
||||
/* MOUNT_SADDLED
|
||||
targetId the id of the mount
|
||||
sourceId sourceId of the mount
|
||||
playerId the id of the controlling player
|
||||
*/
|
||||
X_MANA_ANNOUNCE,
|
||||
/* X_MANA_ANNOUNCE
|
||||
mana x-costs announced by players (X value can be changed by replace events like Unbound Flourishing)
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ public interface Permanent extends Card, Controllable {
|
|||
|
||||
void setSuspected(boolean value, Game game, Ability source);
|
||||
|
||||
boolean isSaddled();
|
||||
|
||||
void setSaddled(boolean value);
|
||||
|
||||
boolean isPrototyped();
|
||||
|
||||
void setPrototyped(boolean value);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
protected boolean monstrous;
|
||||
protected boolean renowned;
|
||||
protected boolean suspected;
|
||||
protected boolean saddled;
|
||||
protected boolean manifested = false;
|
||||
protected boolean morphed = false;
|
||||
protected boolean disguised = false;
|
||||
|
|
@ -175,6 +176,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
this.monstrous = permanent.monstrous;
|
||||
this.renowned = permanent.renowned;
|
||||
this.suspected = permanent.suspected;
|
||||
this.saddled = permanent.saddled;
|
||||
this.ringBearerFlag = permanent.ringBearerFlag;
|
||||
this.classLevel = permanent.classLevel;
|
||||
this.goadingPlayers.addAll(permanent.goadingPlayers);
|
||||
|
|
@ -203,7 +205,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
+ ":" + getCardNumber()
|
||||
+ ":" + getImageFileName()
|
||||
+ ":" + getImageNumber();
|
||||
return name
|
||||
return name
|
||||
+ ", " + (getBasicMageObject() instanceof Token ? "T" : "C")
|
||||
+ ", " + getBasicMageObject().getClass().getSimpleName()
|
||||
+ ", " + imageInfo
|
||||
|
|
@ -237,6 +239,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
this.maxBlockedBy = 0;
|
||||
this.copy = false;
|
||||
this.goadingPlayers.clear();
|
||||
this.saddled = false;
|
||||
this.loyaltyActivationsAvailable = 1;
|
||||
this.legendRuleApplies = true;
|
||||
this.canBeSacrificed = true;
|
||||
|
|
@ -1722,6 +1725,16 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaddled() {
|
||||
return saddled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSaddled(boolean saddled) {
|
||||
this.saddled = saddled;
|
||||
}
|
||||
|
||||
// Used as key for the ring bearer info.
|
||||
private static final String ringbearerInfoKey = "IS_RINGBEARER";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue