Skip to content

Commit

Permalink
add initial speed handling
Browse files Browse the repository at this point in the history
  • Loading branch information
theelk801 committed Jan 24, 2025
1 parent 33a9992 commit 01a47aa
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
2 changes: 0 additions & 2 deletions Mage.Sets/src/mage/sets/Aetherdrift.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,5 @@ private Aetherdrift() {
cards.add(new SetCardInfo("Wild Roads", 269, Rarity.UNCOMMON, mage.cards.w.WildRoads.class));
cards.add(new SetCardInfo("Willowrush Verge", 270, Rarity.RARE, mage.cards.w.WillowrushVerge.class));
cards.add(new SetCardInfo("Wind-Scarred Crag", 271, Rarity.COMMON, mage.cards.w.WindScarredCrag.class));

cards.removeIf(setCardInfo -> unfinished.contains(setCardInfo.getName()));
}
}
15 changes: 15 additions & 0 deletions Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3977,6 +3977,21 @@ public boolean isDrawsOnOpponentsTurn() {
return computerPlayer.isDrawsOnOpponentsTurn();
}

@Override
public int getSpeed() {
return computerPlayer.getSpeed();
}

@Override
public boolean initSpeed() {
return computerPlayer.initSpeed();
}

@Override
public void increaseSpeed() {
computerPlayer.increaseSpeed();
}

@Override
public void setPayManaMode(boolean payManaMode) {
computerPlayer.setPayManaMode(payManaMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.players.Player;

import java.util.Optional;

/**
* @author TheElk801
Expand All @@ -13,8 +16,10 @@ public enum ControllerSpeedCount implements DynamicValue {

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
// TODO: Implement this
return 0;
return Optional
.ofNullable(game.getPlayer(sourceAbility.getControllerId()))
.map(Player::getSpeed)
.orElse(0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public MaxSpeedGainAbilityEffect(Effect effect) {

public MaxSpeedGainAbilityEffect(Ability ability) {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
ability.setRuleVisible(false);
this.ability = ability;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package mage.abilities.keyword;

import mage.abilities.Ability;
import mage.abilities.StaticAbility;
import mage.constants.Zone;
import mage.abilities.dynamicvalue.common.ControllerSpeedCount;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.hint.Hint;
import mage.abilities.hint.ValueHint;
import mage.constants.*;
import mage.game.Game;
import mage.players.Player;

/**
* TODO: Implement this
*
* @author TheElk801
*/
public class StartYourEnginesAbility extends StaticAbility {

private static final Hint hint = new ValueHint("Your current speed", ControllerSpeedCount.instance);

public StartYourEnginesAbility() {
super(Zone.BATTLEFIELD, null);
super(Zone.BATTLEFIELD, new StartYourEnginesEffect());
this.addHint(hint);
}

private StartYourEnginesAbility(final StartYourEnginesAbility ability) {
Expand All @@ -25,6 +33,32 @@ public StartYourEnginesAbility copy() {

@Override
public String getRule() {
return "Start your engines!";
return "start your engines!";
}
}

class StartYourEnginesEffect extends ContinuousEffectImpl {

StartYourEnginesEffect() {
super(Duration.WhileOnBattlefield, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
}

private StartYourEnginesEffect(final StartYourEnginesEffect effect) {
super(effect);
}

@Override
public StartYourEnginesEffect copy() {
return new StartYourEnginesEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.initSpeed()) {
return false;
}
game.informPlayers(player.getLogName() + "'s speed is now 1.");
return true;
}
}
6 changes: 6 additions & 0 deletions Mage/src/main/java/mage/players/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ default boolean isComputer() {

boolean isDrawsOnOpponentsTurn();

int getSpeed();

boolean initSpeed();

void increaseSpeed();

/**
* Returns alternative casting costs a player can cast spells for
*
Expand Down
25 changes: 25 additions & 0 deletions Mage/src/main/java/mage/players/PlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public abstract class PlayerImpl implements Player, Serializable {
protected boolean canPlotFromTopOfLibrary = false;
protected boolean drawsFromBottom = false;
protected boolean drawsOnOpponentsTurn = false;
protected int speed = 0;

protected FilterPermanent sacrificeCostFilter;
protected List<AlternativeSourceCosts> alternativeSourceCosts = new ArrayList<>();
Expand Down Expand Up @@ -252,6 +253,7 @@ protected PlayerImpl(final PlayerImpl player) {
this.canPlotFromTopOfLibrary = player.canPlotFromTopOfLibrary;
this.drawsFromBottom = player.drawsFromBottom;
this.drawsOnOpponentsTurn = player.drawsOnOpponentsTurn;
this.speed = player.speed;

this.attachments.addAll(player.attachments);

Expand Down Expand Up @@ -367,6 +369,7 @@ public void restore(Player player) {
this.drawsFromBottom = player.isDrawsFromBottom();
this.drawsOnOpponentsTurn = player.isDrawsOnOpponentsTurn();
this.alternativeSourceCosts = CardUtil.deepCopyObject(((PlayerImpl) player).alternativeSourceCosts);
this.speed = player.getSpeed();

this.topCardRevealed = player.isTopCardRevealed();

Expand Down Expand Up @@ -480,6 +483,7 @@ public void init(Game game) {
this.canPlotFromTopOfLibrary = false;
this.drawsFromBottom = false;
this.drawsOnOpponentsTurn = false;
this.speed = 0;

this.sacrificeCostFilter = null;
this.alternativeSourceCosts.clear();
Expand Down Expand Up @@ -4674,6 +4678,27 @@ public boolean isDrawsOnOpponentsTurn() {
return drawsOnOpponentsTurn;
}

@Override
public int getSpeed() {
return speed;
}

@Override
public boolean initSpeed() {
if (speed < 1) {
speed = 1;
return true;
}
return false;
}

@Override
public void increaseSpeed() {
if (speed < 4) {
speed++;
}
}

@Override
public boolean autoLoseGame() {
return false;
Expand Down

0 comments on commit 01a47aa

Please sign in to comment.