[ONC] Implement Staff of the Storyteller

This commit is contained in:
theelk801 2023-04-28 19:25:34 -04:00
parent 753452d8a0
commit 4757356bc2
6 changed files with 137 additions and 1 deletions

View file

@ -180,6 +180,7 @@ public enum CounterType {
SPORE("spore"),
STASH("stash"),
STORAGE("storage"),
STORY("story"),
STRIFE("strife"),
STUDY("study"),
STUN("stun"),

View file

@ -0,0 +1,44 @@
package mage.game.events;
import com.google.common.collect.Sets;
import mage.abilities.Ability;
import mage.game.Controllable;
import mage.game.Game;
import mage.game.permanent.PermanentToken;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* @author TheElk801
*/
public class CreatedTokensEvent extends GameEvent {
private final Set<PermanentToken> createdTokens = new HashSet<>();
private CreatedTokensEvent(UUID playerId, Set<PermanentToken> createdTokens, Ability source) {
super(EventType.CREATED_TOKENS, playerId, source, playerId);
this.createdTokens.addAll(createdTokens);
}
public static void addEvents(Set<PermanentToken> allAddedTokens, Ability source, Game game) {
allAddedTokens
.stream()
.collect(Collectors.toMap(
Controllable::getControllerId,
Collections::singleton,
Sets::union
))
.entrySet()
.stream()
.map(entry -> new CreatedTokensEvent(entry.getKey(), entry.getValue(), source))
.forEach(game::addSimultaneousEvent);
}
public Set<PermanentToken> getCreatedTokens() {
return createdTokens;
}
}

View file

@ -462,7 +462,7 @@ public class GameEvent implements Serializable {
flag not used for this event
*/
GAINED_CONTROL,
CREATE_TOKEN, CREATED_TOKEN,
CREATE_TOKEN, CREATED_TOKEN, CREATED_TOKENS,
/* REGENERATE
targetId id of the creature to regenerate
sourceId sourceId of the effect doing the regeneration

View file

@ -18,6 +18,7 @@ import mage.game.Game;
import mage.game.command.CommandObject;
import mage.game.events.CreateTokenEvent;
import mage.game.events.CreatedTokenEvent;
import mage.game.events.CreatedTokensEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
@ -249,6 +250,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
return;
}
Set<PermanentToken> allAddedTokens = new HashSet<>();
for (Map.Entry<Token, Integer> entry : event.getTokens().entrySet()) {
Token token = entry.getKey();
int amount = entry.getValue();
@ -306,6 +308,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
game.addSimultaneousEvent(zccEvent);
if (permanent instanceof PermanentToken && created) {
game.addSimultaneousEvent(new CreatedTokenEvent(source, (PermanentToken) permanent));
allAddedTokens.add((PermanentToken) permanent);
}
// if token was created (not a spell copy) handle auras coming into the battlefield
@ -382,6 +385,8 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
}
}
}
CreatedTokensEvent.addEvents(allAddedTokens, source, game);
game.getState().applyEffects(game); // Needed to do it here without LKIReset i.e. do get SwordOfTheMeekTest running correctly.
}