foul-magics/Mage/src/main/java/mage/game/command/Dungeon.java
Evan Kranzler 947351932b
Ready for Review: Implementing Battles (#10156)
* add types and subtypes

* add startingDefense attribute

* [MOM] Implement Invasion of Ravnica / Guildpact Paragon

* fix two small errors

* refactor various instances of "any target"

* fully implement defense counters

* battles can now be attacked

* [MOM] Implement Invasion of Dominaria / Serra Faithkeeper

* [MOM] Implement Invasion of Innistrad / Deluge of the Dead

* [MOM] Implement Invasion of Kaladesh / Aetherwing, Golden-Scale Flagship

* [MOM] Implement Invasion of Kamigawa / Rooftop Saboteurs

* [MOM] Implement Invasion of Karsus / Refraction Elemental

* [MOM] Implement Invasion of Tolvada / The Broken Sky

* simplify battle info ability

* fix verify failure

* some more fixes for attacking battles

* [MOM] Implement Invasion of Kaldheim / Pyre of the World Tree

* [MOM] Implement Invasion of Lorwyn / Winnowing Forces

* [MOM] Implement Invasion of Moag / Bloomwielder Dryads

* [MOM] Implement Invasion of Shandalar / Leyline Surge

* [MOM] Implement Invasion of Belenon / Belenon War Anthem

* [MOM] Implement Invasion of Pyrulea / Gargantuan Slabhorn

* [MOM] Implement Invasion of Vryn / Overloaded Mage-Ring

* [MOM] Implement Marshal of Zhalfir

* [MOM] Implement Sunfall

* implement protectors for sieges

* partially implement siege defeated trigger

* fix verify failure

* some updates to blocking

* [MOM] Implement Invasion of Mercadia / Kyren Flamewright

* [MOM] Implement Invasion of Theros / Ephara, Ever-Sheltering

* [MOM] Implement Invasion of Ulgrotha / Grandmother Ravi Sengir

* [MOM] Implement Invasion of Xerex / Vertex Paladin

* add initial battle test

* fix verify failure

* [MOM] Implement Invasion of Amonkhet / Lazotep Convert

* [MOM] update spoiler

* update how protectors are chosen

* update text

* battles can't block

* add control change test

* rename battle test for duel

* add multiplayer test

* [MOM] Implement Invasion of Alara / Awaken the Maelstrom

* [MOM] Implement Invasion of Eldraine

* [MOM] Implement Invasion of Ergamon / Truga Cliffhanger

* [MOM] Implement Invasion of Ixalan / Belligerent Regisaur

* battles now cast transformed (this is super hacky but we need to refactor TDFCs anyway)

* add TODO

* add ignore for randomly failing test

* a few small fixes

* add defense to MtgJsonCard (unused like loyalty)

* implement ProtectorIdPredicate

* small fixes
2023-04-13 20:03:16 -04:00

390 lines
11 KiB
Java

package mage.game.command;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.hint.HintUtils;
import mage.cards.FrameStyle;
import mage.choices.Choice;
import mage.choices.ChoiceHintType;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.game.Game;
import mage.game.command.dungeons.DungeonOfTheMadMageDungeon;
import mage.game.command.dungeons.LostMineOfPhandelverDungeon;
import mage.game.command.dungeons.TombOfAnnihilationDungeon;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.players.Player;
import mage.util.GameLog;
import mage.util.SubTypes;
import java.util.*;
/**
* @author TheElk801
*/
public class Dungeon implements CommandObject {
private static final Set<String> dungeonNames = new HashSet<>();
static {
dungeonNames.add("Tomb of Annihilation");
dungeonNames.add("Lost Mine of Phandelver");
dungeonNames.add("Dungeon of the Mad Mage");
}
private static final List<CardType> emptyList = Collections.unmodifiableList(Arrays.asList(CardType.DUNGEON));
private static final ObjectColor emptyColor = new ObjectColor();
private static final ManaCosts<ManaCost> emptyCost = new ManaCostsImpl<>();
private final String name;
private UUID id;
private UUID controllerId;
private boolean copy;
private MageObject copyFrom; // copied card INFO (used to call original adjusters)
private FrameStyle frameStyle;
private final Abilities<Ability> abilites = new AbilitiesImpl<>();
private String expansionSetCodeForImage;
private final List<DungeonRoom> dungeonRooms = new ArrayList<>();
private DungeonRoom currentRoom = null;
public Dungeon(String name, String expansionSetCodeForImage) {
this.id = UUID.randomUUID();
this.name = name;
this.expansionSetCodeForImage = expansionSetCodeForImage;
}
public Dungeon(final Dungeon dungeon) {
this.id = dungeon.id;
this.name = dungeon.name;
this.frameStyle = dungeon.frameStyle;
this.controllerId = dungeon.controllerId;
this.copy = dungeon.copy;
this.copyFrom = (dungeon.copyFrom != null ? dungeon.copyFrom : null);
this.expansionSetCodeForImage = dungeon.expansionSetCodeForImage;
this.copyRooms(dungeon);
}
private void copyRooms(Dungeon dungeon) {
Map<String, DungeonRoom> copyMap = new HashMap<>();
for (DungeonRoom dungeonRoom : dungeon.dungeonRooms) {
DungeonRoom copiedRoom = copyMap.computeIfAbsent(dungeonRoom.getName(), (s) -> dungeonRoom.copy());
for (DungeonRoom nextRoom : dungeonRoom.getNextRooms()) {
copiedRoom.addNextRoom(copyMap.computeIfAbsent(nextRoom.getName(), (s) -> nextRoom.copy()));
}
this.addRoom(copiedRoom);
}
this.currentRoom = copyMap.computeIfAbsent(dungeon.currentRoom.getName(), (s) -> dungeon.currentRoom.copy());
}
public void addRoom(DungeonRoom room) {
this.dungeonRooms.add(room);
room.getRoomTriggeredAbility().setSourceId(id);
this.abilites.add(room.getRoomTriggeredAbility());
}
public void moveToNextRoom(UUID playerId, Game game) {
if (currentRoom == null) {
currentRoom = dungeonRooms.get(0);
} else {
currentRoom = currentRoom.chooseNextRoom(playerId, game);
}
Player player = game.getPlayer(getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " has entered " + currentRoom.getName());
}
game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.ROOM_ENTERED, currentRoom.getId(), null, playerId
));
}
public DungeonRoom getCurrentRoom() {
return currentRoom;
}
public boolean hasNextRoom() {
return currentRoom != null && currentRoom.hasNextRoom();
}
public List<String> getRules() {
List<String> rules = new ArrayList<>();
rules.add("<i>(" + (
currentRoom != null ?
"Currently in " + currentRoom.getName() :
"Not currently in a room"
) + ")</i>");
dungeonRooms.stream()
.map(room -> {
// mark useful rooms by icons
String prefix = "";
if (room.equals(currentRoom)) {
prefix += HintUtils.prepareText(null, null, HintUtils.HINT_ICON_DUNGEON_ROOM_CURRENT);
}
if (currentRoom != null && currentRoom.getNextRooms().stream().anyMatch(room::equals)) {
prefix += HintUtils.prepareText(null, null, HintUtils.HINT_ICON_DUNGEON_ROOM_NEXT);
}
return prefix + room;
})
.forEach(rules::add);
return rules;
}
public static Dungeon selectDungeon(UUID playerId, Game game) {
Player player = game.getPlayer(playerId);
Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD_DUNGEON);
choice.setMessage("Choose a dungeon to venture into");
choice.setChoices(dungeonNames);
player.choose(Outcome.Neutral, choice, game);
if (choice.getChoice() != null) {
return createDungeon(choice.getChoice());
} else {
// on disconnect
return createDungeon("Tomb of Annihilation");
}
}
public static Dungeon createDungeon(String name) {
switch (name) {
case "Tomb of Annihilation":
return new TombOfAnnihilationDungeon();
case "Lost Mine of Phandelver":
return new LostMineOfPhandelverDungeon();
case "Dungeon of the Mad Mage":
return new DungeonOfTheMadMageDungeon();
default:
throw new UnsupportedOperationException("A dungeon should have been chosen");
}
}
@Override
public FrameStyle getFrameStyle() {
return frameStyle;
}
@Override
public void assignNewId() {
this.id = UUID.randomUUID();
}
@Override
public MageObject getSourceObject() {
return null;
}
@Override
public UUID getSourceId() {
return null;
}
@Override
public UUID getControllerId() {
return this.controllerId;
}
public void setControllerId(UUID controllerId) {
this.controllerId = controllerId;
this.abilites.setControllerId(controllerId);
}
@Override
public void setCopy(boolean isCopy, MageObject copyFrom) {
this.copy = isCopy;
this.copyFrom = (copyFrom != null ? copyFrom.copy() : null);
}
@Override
public boolean isCopy() {
return this.copy;
}
@Override
public MageObject getCopyFrom() {
return this.copyFrom;
}
@Override
public String getName() {
return name;
}
@Override
public String getIdName() {
return getName() + " [" + getId().toString().substring(0, 3) + ']';
}
@Override
public String getLogName() {
return GameLog.getColoredObjectIdName(this);
}
@Override
public String getImageName() {
return this.name;
}
@Override
public void setName(String name) {
}
@Override
public List<CardType> getCardType(Game game) {
return emptyList;
}
@Override
public SubTypes getSubtype() {
return new SubTypes();
}
@Override
public SubTypes getSubtype(Game game) {
return new SubTypes();
}
@Override
public boolean hasSubtype(SubType subtype, Game game) {
return false;
}
@Override
public EnumSet<SuperType> getSuperType() {
return EnumSet.noneOf(SuperType.class);
}
@Override
public Abilities<Ability> getAbilities() {
return abilites;
}
@Override
public boolean hasAbility(Ability ability, Game game) {
return getAbilities().contains(ability);
}
@Override
public ObjectColor getColor() {
return emptyColor;
}
@Override
public ObjectColor getColor(Game game) {
return emptyColor;
}
@Override
public ObjectColor getFrameColor(Game game) {
return emptyColor;
}
@Override
public ManaCosts<ManaCost> getManaCost() {
return emptyCost;
}
@Override
public int getManaValue() {
return 0;
}
@Override
public MageInt getPower() {
return MageInt.EmptyMageInt;
}
@Override
public MageInt getToughness() {
return MageInt.EmptyMageInt;
}
@Override
public int getStartingLoyalty() {
return 0;
}
@Override
public void setStartingLoyalty(int startingLoyalty) {
}
@Override
public int getStartingDefense() {
return 0;
}
@Override
public void setStartingDefense(int startingDefense) {
}
@Override
public UUID getId() {
return this.id;
}
@Override
public Dungeon copy() {
return new Dungeon(this);
}
@Override
public String getExpansionSetCodeForImage() {
return expansionSetCodeForImage;
}
@Override
public void setExpansionSetCodeForImage(String expansionSetCodeForImage) {
this.expansionSetCodeForImage = expansionSetCodeForImage;
}
@Override
public int getZoneChangeCounter(Game game) {
return 1;
}
@Override
public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
throw new UnsupportedOperationException("Unsupported operation");
}
@Override
public void setZoneChangeCounter(int value, Game game) {
throw new UnsupportedOperationException("Unsupported operation");
}
@Override
public boolean isAllCreatureTypes(Game game) {
return false;
}
@Override
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public void setIsAllCreatureTypes(Game game, boolean value) {
}
public void discardEffects() {
for (Ability ability : abilites) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof ContinuousEffect) {
((ContinuousEffect) effect).discard();
}
}
}
}
@Override
public void removePTCDA() {
}
}