mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Implemented Jirina Kudro
This commit is contained in:
parent
87d322c8e9
commit
176f06c1dc
5 changed files with 134 additions and 32 deletions
|
|
@ -0,0 +1,35 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.CommanderPlaysCountWatcher;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum CommanderCastCountValue implements DynamicValue {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability source, Effect effect) {
|
||||
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
|
||||
return watcher != null ? watcher.getPlayerCount(source.getControllerId()) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommanderCastCountValue copy() {
|
||||
return CommanderCastCountValue.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "for each";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "time you've cast a commander from the command zone this game";
|
||||
}
|
||||
}
|
||||
|
|
@ -42,17 +42,18 @@ public class CommanderStormAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getSourceId().equals(getSourceId())) {
|
||||
StackObject spell = game.getStack().getStackObject(getSourceId());
|
||||
if (spell instanceof Spell) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setValue("StormSpell", spell);
|
||||
effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!event.getSourceId().equals(getSourceId())) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
StackObject spell = game.getStack().getStackObject(getSourceId());
|
||||
if (!(spell instanceof Spell)) {
|
||||
return false;
|
||||
}
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setValue("StormSpell", spell);
|
||||
effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,11 +66,11 @@ public class CommanderStormAbility extends TriggeredAbilityImpl {
|
|||
|
||||
class CommanderStormEffect extends OneShotEffect {
|
||||
|
||||
public CommanderStormEffect() {
|
||||
CommanderStormEffect() {
|
||||
super(Outcome.Copy);
|
||||
}
|
||||
|
||||
public CommanderStormEffect(final CommanderStormEffect effect) {
|
||||
private CommanderStormEffect(final CommanderStormEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
|
@ -79,14 +80,19 @@ class CommanderStormEffect extends OneShotEffect {
|
|||
if (spellRef == null) {
|
||||
return false;
|
||||
}
|
||||
int stormCount = 0;
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
stormCount = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER).stream()
|
||||
.map((commanderId) -> game.getState().getWatcher(CommanderPlaysCountWatcher.class).getPlaysCount(commanderId))
|
||||
.reduce(stormCount, Integer::sum);
|
||||
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
|
||||
if (watcher == null) {
|
||||
return false;
|
||||
}
|
||||
int stormCount = game
|
||||
.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER)
|
||||
.stream()
|
||||
.mapToInt(watcher::getPlaysCount)
|
||||
.sum();
|
||||
if (stormCount == 0) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
|
@ -21,6 +21,7 @@ import java.util.UUID;
|
|||
public class CommanderPlaysCountWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> playsCount = new HashMap<>();
|
||||
private final Map<UUID, Integer> playerCount = new HashMap<>();
|
||||
|
||||
public CommanderPlaysCountWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
|
|
@ -28,27 +29,31 @@ public class CommanderPlaysCountWatcher extends Watcher {
|
|||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() != EventType.LAND_PLAYED && event.getType() != EventType.SPELL_CAST) {
|
||||
if (event.getType() != EventType.LAND_PLAYED
|
||||
&& event.getType() != EventType.SPELL_CAST) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID possibleCommanderId = event.getSourceId();
|
||||
boolean isCommanderObject = false;
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (game.getCommandersIds(player).contains(possibleCommanderId)) {
|
||||
isCommanderObject = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCommanderObject && event.getZone() == Zone.COMMAND) {
|
||||
int count = playsCount.getOrDefault(possibleCommanderId, 0);
|
||||
count++;
|
||||
playsCount.put(possibleCommanderId, count);
|
||||
boolean isCommanderObject = game
|
||||
.getPlayerList()
|
||||
.stream()
|
||||
.map(game::getPlayer)
|
||||
.map(game::getCommandersIds)
|
||||
.flatMap(Collection::stream)
|
||||
.anyMatch(event.getSourceId()::equals);
|
||||
if (!isCommanderObject || event.getZone() != Zone.COMMAND) {
|
||||
return;
|
||||
}
|
||||
playsCount.putIfAbsent(event.getSourceId(), 0);
|
||||
playsCount.computeIfPresent(event.getSourceId(), (u, i) -> i + 1);
|
||||
playerCount.putIfAbsent(event.getPlayerId(), 0);
|
||||
playerCount.compute(event.getPlayerId(), (u, i) -> i + 1);
|
||||
}
|
||||
|
||||
public int getPlaysCount(UUID commanderId) {
|
||||
return this.playsCount.getOrDefault(commanderId, 0);
|
||||
}
|
||||
|
||||
public int getPlayerCount(UUID playerId) {
|
||||
return this.playerCount.getOrDefault(playerId, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue