Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import nomadrealms.context.game.card.CardMemory;
import nomadrealms.context.game.card.action.Action;
import nomadrealms.context.game.card.action.scheduler.CardPlayerActionScheduler;
import nomadrealms.context.game.card.expression.CardExpression;
import nomadrealms.context.game.event.DropItemEvent;
import nomadrealms.context.game.event.InputEventFrame;
import nomadrealms.context.game.event.ProcChain;
Expand Down Expand Up @@ -158,6 +159,7 @@ private void registerClasses() {
Reflections reflections = new Reflections(new ConfigurationBuilder().forPackage("nomadrealms"));
List<Class<?>> superclasses = Arrays.asList(
Event.class,
CardExpression.class,
Actor.class,
Structure.class,
CardPlayerAI.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import nomadrealms.context.game.actor.HasSpeech;
import nomadrealms.context.game.actor.ai.CardPlayerAI;
import nomadrealms.context.game.actor.cardplayer.appendage.Appendage;
import nomadrealms.context.game.event.Target;
import nomadrealms.context.game.card.WorldCard;
import nomadrealms.context.game.card.action.Action;
import nomadrealms.context.game.card.action.scheduler.CardPlayerActionScheduler;
Expand All @@ -22,7 +23,7 @@
import nomadrealms.render.RenderingEnvironment;
import nomadrealms.render.ui.custom.speech.SpeechBubble;

public abstract class CardPlayer implements Actor, HasSpeech {
public abstract class CardPlayer implements Actor, HasSpeech, Target {

private final CardPlayerActionScheduler actionScheduler = new CardPlayerActionScheduler();

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/nomadrealms/context/game/card/GameCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import nomadrealms.context.game.card.expression.BuryAnySeedExpression;
import nomadrealms.context.game.card.expression.CardExpression;
import nomadrealms.context.game.card.expression.CreateStructureExpression;
import nomadrealms.context.game.card.expression.DamageActorsExpression;
import nomadrealms.context.game.card.expression.DamageExpression;
import nomadrealms.context.game.card.expression.EditTileExpression;
import nomadrealms.context.game.card.expression.GatherExpression;
Expand All @@ -18,9 +19,11 @@
import nomadrealms.context.game.card.expression.SurfaceCardExpression;
import nomadrealms.context.game.card.expression.TeleportExpression;
import nomadrealms.context.game.card.expression.TeleportNoTargetExpression;
import nomadrealms.context.game.card.query.actor.ActorsOnTilesQuery;
import nomadrealms.context.game.card.query.actor.SelfQuery;
import nomadrealms.context.game.card.query.card.LastResolvedCardQuery;
import nomadrealms.context.game.card.query.tile.PreviousTileQuery;
import nomadrealms.context.game.card.query.tile.TilesInRadiusQuery;
import nomadrealms.context.game.card.target.TargetingInfo;
import nomadrealms.context.game.world.map.tile.factory.TileType;

Expand Down Expand Up @@ -57,8 +60,6 @@ public enum GameCard implements Card {
new TeleportExpression(10),
new TargetingInfo(HEXAGON, 2)),
REWIND(
//TODO: Rewind currently attempts to rewind itself since it is the last played card. Need to introduce an
// additional processing phase between playing a card and resolving its effects to avoid this.
"Rewind",
"teleport",
"Teleport to the last hexagon you occupied. Surface the last card you played.",
Expand Down Expand Up @@ -113,7 +114,13 @@ public enum GameCard implements Card {
"overclocked_machinery",
"Create a chest on target tile",
new CreateStructureExpression(StructureType.CHEST),
new TargetingInfo(HEXAGON, 1));
new TargetingInfo(HEXAGON, 1)),
FLAME_CIRCLE(
"Flame Circle",
"meteor",
"Deal 4 damage to all enemies within radius 3",
new DamageActorsExpression(new ActorsOnTilesQuery(new TilesInRadiusQuery(3), true), 4),
new TargetingInfo(NONE, 1));

private final String title;
private final String artwork;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package nomadrealms.context.game.card.expression;

import java.util.List;
import java.util.stream.Collectors;

import nomadrealms.context.game.actor.Actor;
import nomadrealms.context.game.actor.cardplayer.CardPlayer;
import nomadrealms.context.game.card.effect.DamageEffect;
import nomadrealms.context.game.card.effect.Effect;
import nomadrealms.context.game.card.query.Query;
import nomadrealms.context.game.event.Target;
import nomadrealms.context.game.world.World;

public class DamageActorsExpression implements CardExpression {

private final Query<Actor> actors;
private final int amount;

public DamageActorsExpression(Query<Actor> actors, int amount) {
this.actors = actors;
this.amount = amount;
}

@Override
public List<Effect> effects(World world, Target target, CardPlayer source) {
List<Actor> result = actors.find(world, source);
return result.stream()
.map(actor -> new DamageEffect(actor, source, amount))
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nomadrealms.context.game.card.query.actor;

import static java.util.stream.Collectors.toList;

import java.util.List;
import java.util.stream.Stream;

import nomadrealms.context.game.actor.Actor;
import nomadrealms.context.game.actor.cardplayer.CardPlayer;
import nomadrealms.context.game.card.query.Query;
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;

public class ActorsOnTilesQuery implements Query<Actor> {

private final Query<Tile> tileQuery;
private final boolean excludeSource;

public ActorsOnTilesQuery(Query<Tile> tileQuery, boolean excludeSource) {
this.tileQuery = tileQuery;
this.excludeSource = excludeSource;
}

public ActorsOnTilesQuery(Query<Tile> tileQuery) {
this(tileQuery, false);
}

@Override
public List<Actor> find(World world, CardPlayer source) {
List<Tile> tiles = tileQuery.find(world, source);
// TODO: Tiles need to store the actors on them for efficiency. Once we have that, we can optimize this.
Stream<CardPlayer> stream = world.actors.stream()
.filter(CardPlayer.class::isInstance)
.map(CardPlayer.class::cast)
.filter(actor -> tiles.contains(actor.tile()));
if (excludeSource) {
stream = stream.filter(actor -> actor != source);
}
return stream.collect(toList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package nomadrealms.context.game.card.query.tile;

import static java.util.Collections.emptyList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;

import nomadrealms.context.game.actor.cardplayer.CardPlayer;
import nomadrealms.context.game.card.query.Query;
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;

public class TilesInRadiusQuery implements Query<Tile> {

private final int radius;

public TilesInRadiusQuery(int radius) {
this.radius = radius;
}

@Override
public List<Tile> find(World world, CardPlayer source) {
Tile startTile = source.tile();
if (startTile == null) {
return emptyList();
}

List<Tile> tiles = new ArrayList<>();
Queue<Tile> queue = new LinkedList<>();
Map<Tile, Integer> distance = new HashMap<>();

queue.add(startTile);
distance.put(startTile, 0);

while (!queue.isEmpty()) {
Tile currentTile = queue.poll();
tiles.add(currentTile);

int currentDistance = distance.get(currentTile);
if (currentDistance < radius) {
for (Tile neighbor : getNeighbors(world, currentTile)) {
if (neighbor != null && !distance.containsKey(neighbor)) {
distance.put(neighbor, currentDistance + 1);
queue.add(neighbor);
}
}
}
}
return tiles;
}

private List<Tile> getNeighbors(World world, Tile tile) {
List<Tile> neighbors = new ArrayList<>();
neighbors.add(tile.ul(world));
neighbors.add(tile.um(world));
neighbors.add(tile.ur(world));
neighbors.add(tile.dl(world));
neighbors.add(tile.dm(world));
neighbors.add(tile.dr(world));
return neighbors;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static nomadrealms.context.game.card.GameCard.ATTACK;
import static nomadrealms.context.game.card.GameCard.CREATE_ROCK;
import static nomadrealms.context.game.card.GameCard.FLAME_CIRCLE;
import static nomadrealms.context.game.card.GameCard.GATHER;
import static nomadrealms.context.game.card.GameCard.HEAL;
import static nomadrealms.context.game.card.GameCard.MELEE_ATTACK;
Expand All @@ -23,7 +24,7 @@ public enum BeginnerDecks {
REWIND
)),
PUNCH_AND_GRAPPLE("Punch & Grapple", new DeckList(HEAL, ATTACK, HEAL, MELEE_ATTACK)),
CYCLE_AND_SEARCH("Cycle & Search ", new DeckList()),
CYCLE_AND_SEARCH("Cycle & Search ", new DeckList(FLAME_CIRCLE)),
AGRICULTURE_AND_LABOUR("Agriculture & Labour", new DeckList(GATHER, CREATE_ROCK, WOODEN_CHEST, TILL_SOIL, PLANT_SEED));

private final String name;
Expand Down