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
12 changes: 12 additions & 0 deletions src/main/java/nomadrealms/context/game/actor/Actor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import nomadrealms.context.game.card.action.Action;
import nomadrealms.context.game.event.InputEvent;
import nomadrealms.context.game.event.Target;
import nomadrealms.context.game.world.map.area.Tile;
import nomadrealms.render.Renderable;

/**
Expand All @@ -33,4 +34,15 @@ default boolean isDestroyed() {
return health() <= 0;
}

@Override
default void move(Tile target) {
if (target.actor() != null) {
throw new IllegalStateException("Cannot move to occupied tile: " + target.coord());
}
if (tile() != null) {
tile().clearActor();
}
HasPosition.super.move(target);
target.actor(this);
}
}
16 changes: 8 additions & 8 deletions src/main/java/nomadrealms/context/game/actor/HasInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import nomadrealms.context.game.item.Inventory;
import nomadrealms.context.game.item.WorldItem;

public interface HasInventory extends HasPosition {
public interface HasInventory {

public Inventory inventory();
public Inventory inventory();

public default void addItem(WorldItem item) {
inventory().add(item);
}
public default void addItem(WorldItem item) {
inventory().add(item);
}

public default void removeItem(WorldItem item) {
inventory().remove(item);
}
public default void removeItem(WorldItem item) {
inventory().remove(item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void update(GameState state) {
self.tile().um(state.world),
self.tile().ur(state.world)
)
.filter(tile -> state.world.tileToEntityMap.get(tile) == null)
.filter(tile -> tile.actor() == null)
.min(comparingInt(t -> t.coord().distanceTo(nearestCardPlayer.tile().coord())));
if (!closestTile.isPresent()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import java.util.ArrayList;
import java.util.List;

import engine.visuals.constraint.box.ConstraintPair;
import nomadrealms.context.game.GameState;
import nomadrealms.context.game.actor.Actor;
import engine.visuals.constraint.box.ConstraintPair;
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;
import nomadrealms.context.game.event.InputEvent;
import nomadrealms.context.game.event.Target;
import nomadrealms.context.game.item.Inventory;
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import nomadrealms.context.game.actor.HasInventory;
import nomadrealms.context.game.item.WorldItem;
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;

public class BuryItemEffect extends Effect {

private final HasInventory owner;
private final WorldItem item;
private final Tile tile;

public BuryItemEffect(HasInventory owner, WorldItem item) {
public BuryItemEffect(HasInventory owner, WorldItem item, Tile tile) {
this.owner = owner;
this.item = item;
this.tile = tile;
}

@Override
public void resolve(World world) {
owner.inventory().remove(item);
owner.tile().buryItem(item);
tile.buryItem(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
import nomadrealms.context.game.actor.HasInventory;
import nomadrealms.context.game.item.WorldItem;
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;

public class DropItemEffect extends Effect {

private final HasInventory owner;
private final WorldItem item;
private final Tile tile;

public DropItemEffect(HasInventory owner, WorldItem item) {
public DropItemEffect(HasInventory owner, WorldItem item, Tile tile) {
this.owner = owner;
this.item = item;
this.tile = tile;
}

@Override
public void resolve(World world) {
owner.inventory().remove(item);
owner.tile().addItem(item);
tile.addItem(item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public List<Effect> effects(World world, Target target, CardPlayer source) {
.filter(item -> item.item().tags().contains(SEED))
.findAny();
if (seed.isPresent()) {
return singletonList(new BuryItemEffect(source, seed.get()));
return singletonList(new BuryItemEffect(source, seed.get(), source.tile()));
} else {
return emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import nomadrealms.context.game.actor.HasInventory;
import nomadrealms.context.game.item.WorldItem;
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;
import nomadrealms.render.ui.custom.game.GameInterface;

public class DropItemEvent implements InputEvent {

WorldItem worldItem;
HasInventory source;
private final Tile tile;

public DropItemEvent(WorldItem worldItem, HasInventory source) {
public DropItemEvent(WorldItem worldItem, HasInventory source, Tile tile) {
this.worldItem = worldItem;
this.source = source;
this.tile = tile;
}

public WorldItem item() {
Expand All @@ -23,6 +26,10 @@ public HasInventory source() {
return source;
}

public Tile tile() {
return tile;
}

@Override
public void resolve(World world) {
world.resolve(this);
Expand Down
26 changes: 6 additions & 20 deletions src/main/java/nomadrealms/context/game/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import static nomadrealms.context.game.item.Item.WHEAT_SEED;

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

import nomadrealms.context.game.GameState;
import nomadrealms.context.game.actor.Actor;
import nomadrealms.context.game.actor.HasPosition;
import nomadrealms.context.game.actor.cardplayer.CardPlayer;
import nomadrealms.context.game.actor.cardplayer.Farmer;
import nomadrealms.context.game.actor.cardplayer.FeralMonkey;
Expand Down Expand Up @@ -50,7 +47,6 @@ public class World {
public Nomad nomad;
public List<Actor> actors = new ArrayList<>();
public List<Structure> structures = new ArrayList<>();
public Map<Tile, HasPosition> tileToEntityMap;

public List<ProcChain> procChains = new ArrayList<>();

Expand All @@ -70,10 +66,9 @@ public World(GameState state, MapGenerationStrategy mapGenerationStrategy) {
Farmer farmer = new Farmer("Fred",
getTile(new TileCoordinate(new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0),
0, 1), 0, 0)));
actors.add(nomad);
actors.add(farmer);
// Add a feral monkey
actors.add(new FeralMonkey("bob", getTile(new TileCoordinate(
addActor(nomad);
addActor(farmer);
addActor(new FeralMonkey("bob", getTile(new TileCoordinate(
new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 0), 6, 6))));
}

Expand Down Expand Up @@ -102,13 +97,6 @@ public void update(InputEventFrame inputEventFrame) {
// nomad.tile(nomad.tile().dr(this));
i = 0;
}
tileToEntityMap = new HashMap<>();
for (Actor actor : currentActors) {
if (actor.isDestroyed()) {
continue; // TODO: trigger a destroy event
}
tileToEntityMap.put(actor.tile(), actor);
}
for (Actor actor : currentActors) {
if (actor.isDestroyed()) {
continue;
Expand Down Expand Up @@ -140,15 +128,11 @@ public void resolve(CardPlayedEvent event) {
}

public void resolve(DropItemEvent event) {
Effect effect = new DropItemEffect(event.source(), event.item());
Effect effect = new DropItemEffect(event.source(), event.item(), event.tile());
procChains.add(new ProcChain(singletonList(effect)));
state.uiEventChannel.add(event);
}

public HasPosition getTargetOnTile(Tile tile) {
return tileToEntityMap.get(tile);
}

public void setTile(Tile tile) {
tile.chunk().replace(tile);
}
Expand All @@ -166,6 +150,8 @@ public void addActor(Actor actor) {
if (actor instanceof Structure) {
structures.add((Structure) actor);
}
// TODO: figure out to do when tile is already occupied
actor.tile().actor(actor);
}

public GameMap map() {
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/nomadrealms/context/game/world/map/area/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import java.util.ArrayList;
import java.util.List;

import engine.common.math.Matrix4f;
import engine.common.math.Matrix4f;
import engine.common.math.Vector2f;
import engine.common.math.Vector3f;
import engine.visuals.constraint.box.ConstraintPair;
import engine.visuals.lwjgl.render.meta.DrawFunction;
import nomadrealms.context.game.actor.Actor;
import nomadrealms.context.game.actor.HasTooltip;
import nomadrealms.context.game.actor.cardplayer.appendage.Appendage;
import nomadrealms.context.game.event.Target;
Expand Down Expand Up @@ -41,6 +41,7 @@ public abstract class Tile implements Target, HasTooltip {
private transient Chunk chunk;
private TileCoordinate coord;

private Actor actor;
private final List<WorldItem> items = new ArrayList<>();
private WorldItem buried;

Expand Down Expand Up @@ -130,6 +131,24 @@ public void render(RenderingEnvironment re, Vector2f screenPosition, float scale
}
}

public Actor actor() {
return actor;
}

public void actor(Actor actor) {
if (actor == null) {
throw new IllegalArgumentException("Actor cannot be null. Use clearActor() instead.");
}
if (this.actor != null) {
throw new IllegalStateException("Tile " + coord + " is already occupied by " + this.actor);
}
this.actor = actor;
}

public void clearActor() {
this.actor = null;
}

public void addItem(WorldItem item) {
items.add(item);
item.tile(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void render(RenderingEnvironment re) {
);
}
if (info.targetType() == TargetType.CARD_PLAYER) {
target = state.world.getTargetOnTile(tile);
target = tile.actor();
if (target == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void addCallbacks(InputCallbackRegistry registry) {
registry.registerOnDrop(
(event) -> {
if (selectedItem != null && !constraintBox.contains(selectedItem.centerPosition())) {
owner.addNextPlay(new DropItemEvent(selectedItem.item(), owner));
owner.addNextPlay(new DropItemEvent(selectedItem.item(), owner, owner.tile()));
}
selectedItem = null;
});
Expand Down