Skip to content

Commit

Permalink
Fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Oct 20, 2024
1 parent 5dc1c84 commit c1312ef
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/game/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void loadRoom(Point p) {
findRoom(p, roomInstance);

// Create a controller for it
IRoomController roomController = RoomControllerFactory.constructRoom(kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
IRoomController roomController = RoomControllerFactory.constructRoom(entityData, kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
roomController.construct();
roomControllers.put(roomInstance, roomController);

Expand Down
53 changes: 29 additions & 24 deletions src/toniarts/openkeeper/game/controller/RoomControllerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Map;
Expand All @@ -39,6 +41,8 @@
import toniarts.openkeeper.game.controller.room.WorkshopController;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.Variable;
import toniarts.openkeeper.tools.convert.map.Variable.MiscVariable;
import toniarts.openkeeper.tools.convert.map.Variable.MiscVariable.MiscType;

/**
* A factory class you can use to build buildings
Expand All @@ -53,72 +57,73 @@ private RoomControllerFactory() {
// Nope
}

public static IRoomController constructRoom(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings, IGameTimer gameTimer) {
public static IRoomController constructRoom(EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, Map<MiscType, MiscVariable> gameSettings, IGameTimer gameTimer) {
String roomName = roomInstance.getRoom().getName();
EntityId entity = entityData.createEntity();

switch (roomInstance.getRoom().getTileConstruction()) {
case _3_BY_3 -> {
return new ThreeByThreeController(kwdFile, roomInstance, objectsController);
return new ThreeByThreeController(entity, entityData, kwdFile, roomInstance, objectsController);
}
case HERO_GATE, HERO_GATE_FRONT_END -> {
return new HeroGateFrontEndController(kwdFile, roomInstance, objectsController);
return new HeroGateFrontEndController(entity, entityData, kwdFile, roomInstance, objectsController);
}
case HERO_GATE_2_BY_2 -> {
return new NormalRoomController(kwdFile, roomInstance, objectsController);
return new NormalRoomController(entity, entityData, kwdFile, roomInstance, objectsController);
}
case _5_BY_5_ROTATED -> {
return new FiveByFiveRotatedController(kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
return new FiveByFiveRotatedController(entity, entityData, kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
}
case NORMAL -> {
return constructNormal(roomName, kwdFile, roomInstance, objectsController, gameTimer, gameSettings);
return constructNormal(entity, entityData, roomName, kwdFile, roomInstance, objectsController, gameTimer, gameSettings);
}
case DOUBLE_QUAD -> {
return constructDoubleQuad(roomName, kwdFile, roomInstance, objectsController, gameTimer);
return constructDoubleQuad(entity, entityData, roomName, kwdFile, roomInstance, objectsController, gameTimer);
}
default -> {
// TODO
logger.log(Level.WARNING, "Room {0} not exist", roomName);
return new NormalRoomController(kwdFile, roomInstance, objectsController);
return new NormalRoomController(entity, entityData, kwdFile, roomInstance, objectsController);
}

}
}

private static IRoomController constructDoubleQuad(String roomName, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, IGameTimer gameTimer) {
private static IRoomController constructDoubleQuad(EntityId entity, EntityData entityData, String roomName, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, IGameTimer gameTimer) {
if (roomName.equalsIgnoreCase("Prison")) {
return new PrisonController(kwdFile, roomInstance, objectsController, gameTimer);
return new PrisonController(entity, entityData, kwdFile, roomInstance, objectsController, gameTimer);
} else if (roomName.equalsIgnoreCase("Combat Pit")) {
return new CombatPitController(kwdFile, roomInstance, objectsController);
return new CombatPitController(entity, entityData, kwdFile, roomInstance, objectsController);
} else if (roomName.equalsIgnoreCase("Temple")) {
return new TempleController(kwdFile, roomInstance, objectsController);
return new TempleController(entity, entityData, kwdFile, roomInstance, objectsController);
}

return new DoubleQuadController(kwdFile, roomInstance, objectsController);
return new DoubleQuadController(entity, entityData, kwdFile, roomInstance, objectsController);
}

private static IRoomController constructNormal(String roomName, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, IGameTimer gameTimer, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings) {
private static IRoomController constructNormal(EntityId entity, EntityData entityData, String roomName, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, IGameTimer gameTimer, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings) {
if (roomName.equalsIgnoreCase("Lair")) {
return new LairController(kwdFile, roomInstance, objectsController, gameTimer);
return new LairController(entity, entityData, kwdFile, roomInstance, objectsController, gameTimer);
} else if (roomName.equalsIgnoreCase("Library")) {
return new LibraryController(kwdFile, roomInstance, objectsController, gameTimer);
return new LibraryController(entity, entityData, kwdFile, roomInstance, objectsController, gameTimer);
} else if (roomName.equalsIgnoreCase("Training Room")) {
return new TrainingRoomController(kwdFile, roomInstance, objectsController, gameTimer);
return new TrainingRoomController(entity, entityData, kwdFile, roomInstance, objectsController, gameTimer);
} else if (roomName.equalsIgnoreCase("Work Shop")) {
return new WorkshopController(kwdFile, roomInstance, objectsController);
return new WorkshopController(entity, entityData, kwdFile, roomInstance, objectsController);
// } else if (roomName.equalsIgnoreCase("Guard Room")) {
// return new GuardRoom(assetManager, roomInstance, objectLoader, worldState, effectManager);
} else if (roomName.equalsIgnoreCase("Casino")) {
return new CasinoController(kwdFile, roomInstance, objectsController);
return new CasinoController(entity, entityData, kwdFile, roomInstance, objectsController);
// } else if (roomName.equalsIgnoreCase("Graveyard")) {
// return new Graveyard(assetManager, roomInstance, objectLoader, worldState, effectManager);
} else if (roomName.equalsIgnoreCase("Torture Chamber")) {
return new TortureChamberController(kwdFile, roomInstance, objectsController, gameTimer);
return new TortureChamberController(entity, entityData, kwdFile, roomInstance, objectsController, gameTimer);
} else if (roomName.equalsIgnoreCase("Treasury")) {
return new TreasuryController(kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
return new TreasuryController(entity, entityData, kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
} else if (roomName.equalsIgnoreCase("Hatchery")) {
return new HatcheryController(kwdFile, roomInstance, objectsController, gameTimer);
return new HatcheryController(entity, entityData, kwdFile, roomInstance, objectsController, gameTimer);
}

return new NormalRoomController(kwdFile, roomInstance, objectsController);
return new NormalRoomController(entity, entityData, kwdFile, roomInstance, objectsController);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ private boolean isFleeing(EntityId entity) {
}

@Override
public void imprison(short playerId) {
public void imprison(short playerId, EntityId roomId) {

// Return health to 20%
Health health = entityData.getComponent(entityId, Health.class);
Expand All @@ -1243,7 +1243,7 @@ public void imprison(short playerId) {
entityData.setComponent(entityId, new Health((int) Math.floor(health.maxHealth * 0.2f), health.maxHealth));
entityData.removeComponent(entityId, Unconscious.class);
entityData.setComponent(entityId, new CreatureImprisoned(gameTimer.getGameTime(), gameTimer.getGameTime()));
entityData.setComponent(entityId, new RoomStorage(AbstractRoomController.ObjectType.PRISONER));
entityData.setComponent(entityId, new RoomStorage(roomId, AbstractRoomController.ObjectType.PRISONER));

// Switch the control to the imprisoning player
Owner owner = entityData.getComponent(entityId, Owner.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ public interface ICreatureController extends IGameLogicUpdatable, INavigable, IE
* to the prison
*
* @param playerId the imprisoner player
* @param roomId the room in which to imprison
*/
public void imprison(short playerId);
public void imprison(short playerId, EntityId roomId);

/**
* Is the (neutral) creature claimed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,9 @@ protected static Short getPillarObject(short roomId) {
return null; // No pillars
}
}

@Override
public EntityId getEntityId() {
return entityId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ public interface IRoomController {

public boolean isFullCapacity();

public EntityId getEntityId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import toniarts.openkeeper.common.RoomInstance;
import toniarts.openkeeper.game.controller.IGameTimer;
import toniarts.openkeeper.game.controller.IObjectsController;
Expand All @@ -29,9 +31,9 @@
*/
public class LairController extends NormalRoomController {

public LairController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
public LairController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
IGameTimer gameTimer) {
super(kwdFile, roomInstance, objectsController);
super(entityId, entityData, kwdFile, roomInstance, objectsController);

addObjectControl(new RoomLairControl(kwdFile, this, objectsController, gameTimer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import toniarts.openkeeper.common.RoomInstance;
import toniarts.openkeeper.game.controller.IGameTimer;
import toniarts.openkeeper.game.controller.IObjectsController;
Expand All @@ -30,9 +32,9 @@
*/
public class LibraryController extends NormalRoomController {

public LibraryController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
public LibraryController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
IGameTimer gameTimer) {
super(kwdFile, roomInstance, objectsController);
super(entityId, entityData, kwdFile, roomInstance, objectsController);

addObjectControl(new RoomResearcherControl(kwdFile, this, objectsController, gameTimer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import java.util.Collection;
import toniarts.openkeeper.common.RoomInstance;
Expand All @@ -37,9 +39,8 @@ public class PrisonController extends DoubleQuadController {

private Point door;

public PrisonController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
IGameTimer gameTimer) {
super(kwdFile, roomInstance, objectsController);
public PrisonController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, IGameTimer gameTimer) {
super(entityId, entityData, kwdFile, roomInstance, objectsController);

addObjectControl(new RoomPrisonerControl(kwdFile, this, objectsController, gameTimer) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package toniarts.openkeeper.game.controller.room;

import com.jme3.math.Vector3f;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import java.util.ArrayList;
Expand All @@ -27,7 +28,6 @@
import static toniarts.openkeeper.game.controller.room.AbstractRoomController.hasSameTile;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.utils.WorldUtils;
import toniarts.openkeeper.view.map.MapViewController;
import toniarts.openkeeper.view.map.WallSection;

/**
Expand All @@ -40,8 +40,8 @@ public class TempleController extends DoubleQuadController {
public static final short OBJECT_TEMPLE_HAND_ID = 66;
private static final int MIN_HAND_SIZE = 5;

public TempleController(KwdFile kwdFile, toniarts.openkeeper.common.RoomInstance roomInstance, IObjectsController objectsController) {
super(kwdFile, roomInstance, objectsController);
public TempleController(EntityId entityId, EntityData entityData, KwdFile kwdFile, toniarts.openkeeper.common.RoomInstance roomInstance, IObjectsController objectsController) {
super(entityId, entityData, kwdFile, roomInstance, objectsController);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import toniarts.openkeeper.common.RoomInstance;
import toniarts.openkeeper.game.controller.IGameTimer;
import toniarts.openkeeper.game.controller.IObjectsController;
Expand All @@ -30,9 +32,8 @@
*/
public class TortureChamberController extends NormalRoomController {

public TortureChamberController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
IGameTimer gameTimer) {
super(kwdFile, roomInstance, objectsController);
public TortureChamberController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController, IGameTimer gameTimer) {
super(entityId, entityData, kwdFile, roomInstance, objectsController);

addObjectControl(new RoomTortureeControl(kwdFile, this, objectsController, gameTimer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import toniarts.openkeeper.common.RoomInstance;
import toniarts.openkeeper.game.controller.IGameTimer;
import toniarts.openkeeper.game.controller.IObjectsController;
Expand All @@ -29,9 +31,9 @@
*/
public class TrainingRoomController extends NormalRoomController {

public TrainingRoomController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
public TrainingRoomController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
IGameTimer gameTimer) {
super(kwdFile, roomInstance, objectsController);
super(entityId, entityData, kwdFile, roomInstance, objectsController);

addObjectControl(new RoomTraineeControl(kwdFile, this, objectsController, gameTimer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.util.Map;
import toniarts.openkeeper.common.RoomInstance;
import toniarts.openkeeper.game.controller.IGameTimer;
Expand All @@ -33,9 +35,9 @@ public class TreasuryController extends NormalRoomController {

private final Integer goldPerTile;

public TreasuryController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
public TreasuryController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController,
Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings, IGameTimer gameTimer) {
super(kwdFile, roomInstance, objectsController);
super(entityId, entityData, kwdFile, roomInstance, objectsController);
goldPerTile = (int) gameSettings.get(Variable.MiscVariable.MiscType.MAX_GOLD_PER_TREASURY_TILE).getValue();
addObjectControl(new RoomGoldControl(kwdFile, this, objectsController, gameTimer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package toniarts.openkeeper.game.controller.room;

import com.jme3.math.FastMath;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import java.util.ArrayList;
Expand All @@ -35,8 +36,8 @@
*/
public class WorkshopController extends NormalRoomController {

public WorkshopController(KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController) {
super(kwdFile, roomInstance, objectsController);
public WorkshopController(EntityId entityId, EntityData entityData, KwdFile kwdFile, RoomInstance roomInstance, IObjectsController objectsController) {
super(entityId, entityData, kwdFile, roomInstance, objectsController);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Collection<Point> getAvailableCoordinates() {
}

protected void setRoomStorageToItem(EntityId entityId, boolean changeOwner) {
objectsController.getEntityData().setComponent(entityId, new RoomStorage(getObjectType()));
objectsController.getEntityData().setComponent(entityId, new RoomStorage(parent.getEntityId(), getObjectType()));
ObjectComponent objectComponent = objectsController.getEntityData().getComponent(entityId, ObjectComponent.class);
if (objectComponent != null && kwdFile.getObject(objectComponent.objectId).getFlags().contains(GameObject.ObjectFlag.DIE_OVER_TIME_IF_NOT_IN_ROOM)) {
objectsController.getEntityData().removeComponent(entityId, Decay.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String toString() {

@Override
public void executeTask(ICreatureController creature, float executionDuration) {
this.creature.imprison(playerId);
this.creature.imprison(playerId, room.getEntityId());
executed = true;

// Set the dragged state
Expand Down

0 comments on commit c1312ef

Please sign in to comment.