feat: Multiplayer #2

Merged
jzitnik merged 14 commits from multiplayer into main 2026-02-04 10:33:25 +00:00
46 changed files with 792 additions and 86 deletions
Showing only changes of commit ac5a96eb19 - Show all commits

View File

@@ -9,6 +9,6 @@
<entry key="server" value="$PROJECT_DIR$" />
</map>
</option>
<option name="recentlySearchedFiles" value="rO0ABXNyABxqYXZheC5zd2luZy5EZWZhdWx0TGlzdE1vZGVsBgfGCGLvV2ICAAFMAAhkZWxlZ2F0ZXQAEkxqYXZhL3V0aWwvVmVjdG9yO3hyAB1qYXZheC5zd2luZy5BYnN0cmFjdExpc3RNb2RlbFrW+oYSs63tAgABTAAMbGlzdGVuZXJMaXN0dAAlTGphdmF4L3N3aW5nL2V2ZW50L0V2ZW50TGlzdGVuZXJMaXN0O3hwc3IAI2phdmF4LnN3aW5nLmV2ZW50LkV2ZW50TGlzdGVuZXJMaXN0kUjMLXPfDt4DAAB4cHB4c3IAEGphdmEudXRpbC5WZWN0b3LZl31bgDuvAQMAA0kAEWNhcGFjaXR5SW5jcmVtZW50SQAMZWxlbWVudENvdW50WwALZWxlbWVudERhdGF0ABNbTGphdmEvbGFuZy9PYmplY3Q7eHAAAAAAAAAABHVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAApzcgBIY29tLm1pdHV1ei5mdXp6aWVyLmVudGl0aWVzLkZ1enp5TWF0Y2hDb250YWluZXIkU2VyaWFsaXplZE1hdGNoQ29udGFpbmVy2S8sP5uny74CAARMAAhmaWxlUGF0aHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wACGZpbGVuYW1lcQB+AA1MAA5tb2R1bGVCYXNlUGF0aHEAfgANTAAFc2NvcmV0ADxMY29tL21pdHV1ei9mdXp6aWVyL2VudGl0aWVzL0Z1enp5TWF0Y2hDb250YWluZXIkRnV6enlTY29yZTt4cHQARC9nYW1lL3NyYy9tYWluL2phdmEvY3ovanppdG5pay9jbGllbnQvdXRpbHMvZXZlbnRzL0V2ZW50TWFuYWd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gAYAAAABnNxAH4AGAAAAAdzcQB+ABgAAAAIc3EAfgAYAAAACXNxAH4AGAAAAApzcQB+ABgAAAALeHNxAH4ADHQASS9nYW1lL3NyYy9tYWluL2phdmEvY3ovanppdG5pay9jbGllbnQvZ2FtZS9tb2JzL3Rhc2tzL3V0aWxzL0FTdGFyQWxnLmphdmF0AA1BU3RhckFsZy5qYXZhdAAWL2hvbWUva3ViYS9Db2RpbmcvZ2FtZXNxAH4AEwAAAAgAAAAAAAAACgAAAARzcQB+ABZ3DAAAABA/QAAAAAAACHEAfgBEcQB+AEVxAH4ARnEAfgBHcQB+AEhxAH4ASXEAfgBKcQB+AEt4c3EAfgAMdAA4L2dhbWUvc3JjL21haW4vamF2YS9jei9qeml0bmlrL2NsaWVudC91aS91dGlscy9HcmlkLmphdmF0AAlHcmlkLmphdmF0ABYvaG9tZS9rdWJhL0NvZGluZy9nYW1lc3EAfgATAAAACQAAAAAAAAAAAAAABnNxAH4AFncMAAAAED9AAAAAAAAJcQB+AERxAH4ARXEAfgBGcQB+AEdxAH4ASHEAfgBJcQB+AEpxAH4AS3EAfgBMeHBwcHg=" />
</component>
</project>

19
.idea/compiler.xml generated
View File

@@ -7,7 +7,25 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
</profile>
<profile name="Annotation profile for common" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false">
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.42/lombok-1.18.42.jar" />
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.42/lombok-1.18.42.jar" />
</processorPath>
<module name="common" />
</profile>
<profile name="Annotation profile for server" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false">
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.42/lombok-1.18.42.jar" />
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.42/lombok-1.18.42.jar" />
</processorPath>
<module name="server" />
</profile>
<profile name="Annotation profile for game-parent" enabled="true">
@@ -16,6 +34,7 @@
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false">
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.38/lombok-1.18.38.jar" />
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.38/lombok-1.18.38.jar" />
</processorPath>
<module name="game (1)" />
</profile>

View File

@@ -12,6 +12,27 @@
<artifactId>common</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.42</version>
</path>
</annotationProcessorPaths>
<source>25</source>
<target>25</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>tools.jackson.core</groupId>
@@ -31,5 +52,12 @@
<version>1.18.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.17</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,18 +1,18 @@
package cz.jzitnik.client.game.utils;
package cz.jzitnik.common.models.coordinates;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.game.GameRoomPart;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import java.io.Serializable;
import java.util.List;
@Slf4j
@ToString
@Getter
public class RoomCords implements Cloneable {
public class RoomCords implements Cloneable, Serializable {
private int x;
private int y;
@@ -29,8 +29,8 @@ public class RoomCords implements Cloneable {
this.y = y;
}
public void updateCordsWithColliders(List<GameRoomPart> colliders, int x, int y, GameRoomPart playerCollider) {
var normalizedPlayerCollider = new GameRoomPart(
public void updateCordsWithColliders(List<RoomPart> colliders, int x, int y, RoomPart playerCollider) {
var normalizedPlayerCollider = new RoomPart(
new RoomCords(playerCollider.getStart().getX() + x, playerCollider.getStart().getY() + y),
new RoomCords(playerCollider.getEnd().getX() + x, playerCollider.getEnd().getY() + y)
);

View File

@@ -1,19 +1,20 @@
package cz.jzitnik.client.game;
package cz.jzitnik.common.models.coordinates;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.game.utils.RoomCords;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
@Data
@ToString
public class GameRoomPart {
public class RoomPart implements Serializable {
private RoomCords start;
private RoomCords end;
@JsonCreator
public GameRoomPart(
public RoomPart(
@JsonProperty("start") RoomCords start,
@JsonProperty("end") RoomCords end
) {
@@ -31,7 +32,7 @@ public class GameRoomPart {
/**
* Checks if this GameRoomPart overlaps with another.
*/
public boolean isOverlapping(GameRoomPart other) {
public boolean isOverlapping(RoomPart other) {
return start.getX() <= other.getEnd().getX() &&
end.getX() >= other.getStart().getX() &&
start.getY() <= other.getEnd().getY() &&

View File

@@ -0,0 +1,24 @@
package cz.jzitnik.common.models.player;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomPart;
import lombok.Getter;
import java.io.Serializable;
@Getter
public final class PlayerCreation implements Serializable {
private final RoomCords playerCords;
private final RoomPart collider;
@JsonCreator
public PlayerCreation(
@JsonProperty("playerCords") RoomCords playerCords,
@JsonProperty("collider") RoomPart collider
) {
this.playerCords = playerCords;
this.collider = collider;
}
}

View File

@@ -1,6 +1,13 @@
package cz.jzitnik.common.socket.messages.game.creation;
import cz.jzitnik.common.models.player.PlayerCreation;
import cz.jzitnik.common.socket.SocketMessage;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class CreateGameResponse implements SocketMessage {
private final String gamePassword;
private final PlayerCreation ownerPlayer;
}

View File

@@ -68,6 +68,7 @@
<configuration>
<mainClass>cz.jzitnik.client.Main</mainClass>
<classpathScope>compile</classpathScope>
<skip>false</skip>
</configuration>
</plugin>

View File

@@ -10,7 +10,6 @@ import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.KeyboardPressEvent;
import cz.jzitnik.client.events.MouseAction;
import cz.jzitnik.client.events.TerminalResizeEvent;
import cz.jzitnik.client.socket.SocketEventManager;
import cz.jzitnik.client.states.RunningState;
import cz.jzitnik.client.states.TerminalState;
import cz.jzitnik.client.utils.events.EventManager;
@@ -24,9 +23,6 @@ public class Cli implements Runnable {
@InjectDependency
private EventManager eventManager;
@InjectDependency
private SocketEventManager socketEventManager;
@InjectState
private TerminalState terminalState;
@@ -36,9 +32,6 @@ public class Cli implements Runnable {
@Override
public void run() {
// Start event manager thread
eventManager.start();
socketEventManager.start();
try (TerminalScreen terminal = new DefaultTerminalFactory()
.setMouseCaptureMode(MouseCaptureMode.CLICK_RELEASE_DRAG_MOVE)
.createScreen()) {

View File

@@ -3,10 +3,12 @@ package cz.jzitnik.client;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.game.setup.GameSetup;
import cz.jzitnik.client.socket.Client;
import cz.jzitnik.client.socket.SocketEventManager;
import cz.jzitnik.client.utils.DependencyManager;
import cz.jzitnik.client.utils.GlobalIOHandlerRepository;
import cz.jzitnik.client.utils.ScheduledTaskManager;
import cz.jzitnik.client.utils.ThreadManager;
import cz.jzitnik.client.utils.events.EventManager;
import jakarta.websocket.DeploymentException;
import org.reflections.Reflections;
@@ -15,33 +17,33 @@ import java.io.IOException;
public class Game {
private final DependencyManager dependencyManager = new DependencyManager(new Reflections("cz.jzitnik.client"));
@InjectDependency
private Cli cli;
@InjectDependency
private GameSetup gameSetup;
@InjectDependency
private EventManager eventManager;
@InjectDependency
private SocketEventManager socketEventManager;
@InjectDependency
private Cli cli;
@InjectDependency
private ThreadManager threadManager;
@InjectDependency
private ScheduledTaskManager scheduledTaskManager;
@InjectDependency
private GlobalIOHandlerRepository globalIOHandlerRepository;
@InjectDependency
private Client client;
public void start() throws IOException {
dependencyManager.inject(this);
try {
client.connect();
eventManager.start();
socketEventManager.start();
gameSetup.setup();
threadManager.startAll();
scheduledTaskManager.startAll();
globalIOHandlerRepository.setup();
gameSetup.setup();
cli.run();
} catch (DeploymentException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -105,7 +105,7 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
OnEnd.AskQuestion.Answer[] answers
)) {
for (OnEnd.AskQuestion.Answer answer : answers) {
answersBuf.add(textRenderer.renderText(answer.answer(), size.getColumns() - PADDING * 2, BUTTON_HEIGHT, Color.BLACK, FONT_SIZE));
answersBuf.add(textRenderer.renderText(answer.answer(), size.getColumns() - PADDING * 2, BUTTON_HEIGHT, Color.BLACK, FONT_SIZE, false));
}
}

View File

@@ -4,7 +4,7 @@ import cz.jzitnik.client.annotations.EventHandler;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.events.DroppedItemRerender;
import cz.jzitnik.client.events.RerenderPart;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;

View File

@@ -15,7 +15,7 @@ import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.game.utils.Selectable;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.TerminalState;

View File

@@ -16,7 +16,7 @@ import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.RenderState;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.PlayerMovementState;

View File

@@ -11,7 +11,7 @@ import cz.jzitnik.client.events.RerenderScreen;
import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.TerminalState;
import cz.jzitnik.client.utils.RerenderUtils;

View File

@@ -7,7 +7,7 @@ import cz.jzitnik.client.events.FullRoomDraw;
import cz.jzitnik.client.events.RoomChangeEvent;
import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;

View File

@@ -6,6 +6,7 @@ import cz.jzitnik.client.game.objects.DroppedItem;
import cz.jzitnik.client.game.objects.GameObject;
import cz.jzitnik.client.ui.pixels.Empty;
import cz.jzitnik.client.ui.pixels.Pixel;
import cz.jzitnik.common.models.coordinates.RoomPart;
import lombok.Getter;
import java.util.ArrayList;
@@ -31,7 +32,7 @@ public class GameRoom {
@JsonIgnore
private final Set<DroppedItem> droppedItems = new HashSet<>();
@JsonIgnore
private final List<GameRoomPart> colliders = new ArrayList<>();
private final List<RoomPart> colliders = new ArrayList<>();
private GameRoom left;
private GameRoom right;
@@ -42,7 +43,7 @@ public class GameRoom {
public GameRoom(
@JsonProperty("id") String id,
@JsonProperty("objects") List<GameObject> objects,
@JsonProperty("colliders") List<GameRoomPart> colliders,
@JsonProperty("colliders") List<RoomPart> colliders,
@JsonProperty("mobs") List<Mob> mobs,
@JsonProperty("texture") ResourceManager.Resource texture
) {

View File

@@ -6,11 +6,13 @@ import cz.jzitnik.client.events.RerenderPart;
import cz.jzitnik.client.game.items.GameItem;
import cz.jzitnik.client.game.items.types.interfaces.WeaponInterface;
import cz.jzitnik.client.game.mobs.HittableMob;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.ui.Inventory;
import cz.jzitnik.client.utils.DependencyManager;
import cz.jzitnik.client.utils.events.Event;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.common.models.player.PlayerCreation;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@@ -29,7 +31,7 @@ public class Player {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final RoomCords playerCords;
private final GameRoomPart collider;
private final RoomPart collider;
private final GameItem[] inventory = new GameItem[Inventory.ITEMS_X * Inventory.ITEMS_Y];
@Setter
private PlayerRotation playerRotation = PlayerRotation.FRONT;
@@ -44,12 +46,17 @@ public class Player {
@JsonCreator
public Player(
@JsonProperty("playerCords") RoomCords playerCords,
@JsonProperty("collider") GameRoomPart collider
@JsonProperty("collider") RoomPart collider
) {
this.playerCords = playerCords;
this.collider = collider;
}
public Player(PlayerCreation playerCreation) {
this.playerCords = playerCreation.getPlayerCords();
this.collider = playerCreation.getCollider();
}
public void increaseStamina() {
stamina++;
}

View File

@@ -2,10 +2,10 @@ package cz.jzitnik.client.game.mobs;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.game.GameRoomPart;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.client.game.dialog.Dialog;
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.DialogState;
import cz.jzitnik.client.utils.events.EventManager;
import lombok.extern.slf4j.Slf4j;
@@ -16,7 +16,7 @@ import java.awt.image.BufferedImage;
public abstract class DialogMob extends Mob {
protected Dialog dialog;
public DialogMob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, GameRoomPart collider, Dialog dialog) {
public DialogMob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, RoomPart collider, Dialog dialog) {
super(texture, tasks, cords, collider);
this.dialog = dialog;
}

View File

@@ -3,10 +3,10 @@ package cz.jzitnik.client.game.mobs;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.RerenderPart;
import cz.jzitnik.client.game.GameRoomPart;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.client.utils.roomtasks.RoomTask;
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
@@ -68,7 +68,7 @@ public abstract class HittableMob extends Mob {
@InjectDependency
private RoomTaskScheduler roomTaskScheduler;
public HittableMob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, GameRoomPart collider, int health) {
public HittableMob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, RoomPart collider, int health) {
super(texture, tasks, cords, collider);
this.health = health;
}

View File

@@ -11,7 +11,8 @@ import cz.jzitnik.client.game.*;
import cz.jzitnik.client.game.items.GameItem;
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
import cz.jzitnik.client.game.objects.DroppedItem;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.events.Event;
import cz.jzitnik.client.utils.events.EventManager;
@@ -33,7 +34,7 @@ public class HittableMobDrops extends HittableMob {
@JsonProperty("texture") ResourceManager.Resource texture,
@JsonProperty("tasks") MobRoomTask[] tasks,
@JsonProperty("cords") RoomCords cords,
@JsonProperty("collider") GameRoomPart collider,
@JsonProperty("collider") RoomPart collider,
@JsonProperty("health") int health,
@JsonProperty("itemsDrops") GameItem[] itemsDrops,
@JacksonInject ResourceManager resourceManager

View File

@@ -3,10 +3,10 @@ package cz.jzitnik.client.game.mobs;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.game.GameRoomPart;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
public class HittableMobNoDrops extends HittableMob {
@JsonCreator
@@ -14,7 +14,7 @@ public class HittableMobNoDrops extends HittableMob {
@JsonProperty("texture") ResourceManager.Resource texture,
@JsonProperty("tasks") MobRoomTask[] tasks,
@JsonProperty("cords") RoomCords cords,
@JsonProperty("collider") GameRoomPart collider,
@JsonProperty("collider") RoomPart collider,
@JsonProperty("health") int health,
@JacksonInject ResourceManager resourceManager
) {

View File

@@ -4,10 +4,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.game.GameRoomPart;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
import cz.jzitnik.client.game.utils.Renderable;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.game.utils.Selectable;
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
import lombok.Getter;
@@ -34,7 +34,7 @@ public abstract class Mob implements Renderable, Selectable {
@JsonIgnore
protected final RoomCords cords;
@JsonIgnore
protected final GameRoomPart collider;
protected final RoomPart collider;
@InjectDependency
private RoomTaskScheduler roomTaskScheduler;
@@ -46,7 +46,7 @@ public abstract class Mob implements Renderable, Selectable {
roomTaskScheduler.registerNewMob(this, oldTasks);
}
public Mob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, GameRoomPart collider) {
public Mob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, RoomPart collider) {
this.texture = texture;
this.tasks = tasks == null ? new MobRoomTask[] {} : tasks;
this.cords = cords;

View File

@@ -10,7 +10,7 @@ import cz.jzitnik.client.config.MicrophoneConfig;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.mobs.Mob;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.MicrophoneState;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.TerminalState;

View File

@@ -7,7 +7,7 @@ import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.RenderStats;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.mobs.Mob;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.DependencyManager;
import cz.jzitnik.client.utils.events.EventManager;
import lombok.RequiredArgsConstructor;

View File

@@ -9,13 +9,13 @@ import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.config.Debugging;
import cz.jzitnik.client.events.MouseMoveEvent;
import cz.jzitnik.client.events.RerenderScreen;
import cz.jzitnik.client.game.GameRoomPart;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.mobs.Mob;
import cz.jzitnik.client.game.mobs.tasks.utils.AStarAlg;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.TerminalState;
import cz.jzitnik.client.utils.RerenderUtils;
@@ -73,7 +73,7 @@ public class MobFollowingPlayerTask extends MobRoomTask {
protected static void moveMob(RoomCords playerCords, Mob mob, GameState gameState, int speed, ResourceManager resourceManager, TerminalState terminalState, ScreenBuffer screenBuffer, Debugging debugging, EventManager eventManager) {
RoomCords mobCords = mob.getCords();
List<GameRoomPart> solidParts = gameState.getCurrentRoom().getColliders();
List<RoomPart> solidParts = gameState.getCurrentRoom().getColliders();
List<RoomCords> path = AStarAlg.findPath(mobCords, playerCords, solidParts, mob.getCollider());
if (path.size() > 1) {

View File

@@ -1,7 +1,7 @@
package cz.jzitnik.client.game.mobs.tasks.utils;
import cz.jzitnik.client.game.GameRoomPart;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomPart;
import cz.jzitnik.common.models.coordinates.RoomCords;
import java.util.*;
@@ -12,7 +12,7 @@ public class AStarAlg {
private static final int MIN_Y = 10;
private static final int MAX_Y = 113;
public static List<RoomCords> findPath(RoomCords start, RoomCords target, List<GameRoomPart> colliders, GameRoomPart mobCollider) {
public static List<RoomCords> findPath(RoomCords start, RoomCords target, List<RoomPart> colliders, RoomPart mobCollider) {
PriorityQueue<Node> openSet = new PriorityQueue<>(Comparator.comparingInt(n -> n.f));
Set<String> closedSet = new HashSet<>();
@@ -68,16 +68,16 @@ public class AStarAlg {
return neighbors;
}
private static boolean isValidPosition(int x, int y, List<GameRoomPart> colliders, GameRoomPart mobCollider) {
private static boolean isValidPosition(int x, int y, List<RoomPart> colliders, RoomPart mobCollider) {
if (x < MIN_X || x > MAX_X) return false;
if (y < MIN_Y || y > MAX_Y) return false;
var temp = new GameRoomPart(
var temp = new RoomPart(
new RoomCords(mobCollider.getStart().getX() + x, mobCollider.getStart().getY() + y),
new RoomCords(mobCollider.getEnd().getX() + x, mobCollider.getEnd().getY() + y)
);
for (GameRoomPart part : colliders) {
for (RoomPart part : colliders) {
if (part.isOverlapping(temp)) {
return false;
}

View File

@@ -19,7 +19,7 @@ import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.items.GameItem;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.TerminalState;
import cz.jzitnik.client.ui.Inventory;

View File

@@ -7,7 +7,7 @@ import cz.jzitnik.client.events.InventoryRerender;
import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.items.GameItem;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.game.utils.Selectable;
import cz.jzitnik.client.utils.events.EventManager;
import lombok.Getter;

View File

@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import cz.jzitnik.client.game.utils.Renderable;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.game.utils.Selectable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

View File

@@ -3,11 +3,15 @@ package cz.jzitnik.client.game.setup;
import cz.jzitnik.client.annotations.Dependency;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.SendSocketMessageEvent;
import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.setup.scenes.connect.ServerChoose;
import cz.jzitnik.client.utils.DependencyManager;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
import lombok.extern.slf4j.Slf4j;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;
@@ -32,7 +36,7 @@ public class GameSetup {
private DependencyManager dependencyManager;
public void setup() throws IOException {
//gameState.setScreen(new IntroScene(dependencyManager));
gameState.setScreen(new ServerChoose(dependencyManager));
ObjectReader roomsReader = objectMapper.readerFor(
new TypeReference<List<GameRoom>>() {
@@ -42,10 +46,6 @@ public class GameSetup {
resourceManager.getResourceAsStream("setup/rooms.yaml")
);
ObjectReader playerReader = objectMapper.readerFor(Player.class).with(dependencyManager);
Player player = playerReader.readValue(resourceManager.getResourceAsStream("setup/player.yaml"));
gameState.setCurrentRoom(rooms.getFirst());
gameState.setPlayer(player);
}
}

View File

@@ -0,0 +1,208 @@
package cz.jzitnik.client.game.setup.scenes.connect;
import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.input.KeyType;
import com.googlecode.lanterna.screen.TerminalScreen;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.KeyboardPressEvent;
import cz.jzitnik.client.events.MouseAction;
import cz.jzitnik.client.events.SendSocketMessageEvent;
import cz.jzitnik.client.screens.Screen;
import cz.jzitnik.client.screens.scenes.Scene;
import cz.jzitnik.client.socket.Client;
import cz.jzitnik.client.sound.SoundPlayer;
import cz.jzitnik.client.states.TerminalState;
import cz.jzitnik.client.ui.pixels.AlphaPixel;
import cz.jzitnik.client.ui.pixels.Empty;
import cz.jzitnik.client.ui.utils.Input;
import cz.jzitnik.client.utils.DependencyManager;
import cz.jzitnik.client.utils.TextRenderer;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
import jakarta.websocket.DeploymentException;
import java.awt.*;
import java.io.IOException;
public class ServerChoose extends Scene {
public ServerChoose(DependencyManager dependencyManager) {
GameMenuAudioScreen gameMenuScreen = new GameMenuAudioScreen();
ServerSelector serverSelector = new ServerSelector();
super(new Screen[]{gameMenuScreen, serverSelector}, new OnEndAction.Repeat());
dependencyManager.inject(this);
dependencyManager.inject(serverSelector);
}
private static class GameMenuAudioScreen extends Screen {
protected final SoundPlayer soundPlayer = new SoundPlayer();
protected boolean play = true;
@Override
public void fullRender() {
// No render here just basic audio playback
new Thread(() -> {
while (play) {
soundPlayer.playSound("audio/menu.ogg", 30, 100);
}
}).start();
}
@Override
public void handleMouseAction(MouseAction event) {
}
@Override
public void handleKeyboardAction(KeyboardPressEvent event) {
}
}
private static final class ServerSelector extends Screen {
private final StringBuilder ipBuffer = new StringBuilder();
private boolean connecting = false;
@InjectDependency
private EventManager eventManager;
@InjectDependency
private Client client;
@InjectState
private TerminalState terminalState;
@InjectDependency
private TextRenderer textRenderer;
private void renderInput(boolean refresh) {
var tg = terminalState.getTextGraphics();
TerminalScreen screen = terminalState.getTerminalScreen();
Input input = new Input(ipBuffer.toString(), 18, 100);
var inputBuffer = input.render(textRenderer);
TerminalSize termSize = screen.getTerminalSize();
int renderPixelWidth = inputBuffer[0].length;
int renderPixelHeight = inputBuffer.length;
int renderCharWidth = renderPixelWidth;
int renderCharHeight = (renderPixelHeight + 1) / 2;
int startX = (termSize.getColumns() - renderCharWidth) / 2;
int startY = (termSize.getRows() - renderCharHeight) / 2;
for (int y = 0; y < inputBuffer.length; y += 2) {
for (int x = 0; x < inputBuffer[y].length; x++) {
AlphaPixel bottomPixel;
AlphaPixel topPixel = inputBuffer[y][x];
if (y + 1 < inputBuffer.length) {
bottomPixel = inputBuffer[y + 1][x];
} else {
bottomPixel = new Empty();
}
int termX = startX + x;
int termY = startY + (y / 2);
tg.setBackgroundColor(topPixel instanceof Empty ? TextColor.ANSI.BLACK : topPixel.getColor());
tg.setForegroundColor(bottomPixel instanceof Empty ? TextColor.ANSI.BLACK : bottomPixel.getColor());
tg.setCharacter(termX, termY, '▄');
}
}
if (refresh) {
try {
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.DELTA);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void fullRender() {
TerminalScreen screen = terminalState.getTerminalScreen();
var tg = terminalState.getTextGraphics();
screen.clear();
TerminalSize terminalSize = screen.getTerminalSize();
for (int y = 0; y < terminalSize.getRows(); y += 1) {
for (int x = 0; x < terminalSize.getColumns(); x++) {
tg.setBackgroundColor(TextColor.ANSI.BLACK);
tg.setForegroundColor(TextColor.ANSI.BLACK);
tg.setCharacter(x, y, '▄');
}
}
AlphaPixel[][] selectServer = textRenderer.renderText("Enter server IP", terminalSize.getColumns(), 20, Color.WHITE, 15f, true);
int padY = 10;
for (int y = 0; y < selectServer.length; y += 2) {
for (int x = 0; x < selectServer[y].length; x++) {
AlphaPixel topPixel = selectServer[y][x];
AlphaPixel bottomPixel;
if (y + 1 < selectServer.length) {
bottomPixel = selectServer[y + 1][x];
} else {
bottomPixel = new Empty();
}
int termX = x;
int termY = padY / 2 + y / 2;
tg.setBackgroundColor(topPixel instanceof Empty ? TextColor.ANSI.BLACK : topPixel.getColor());
tg.setForegroundColor(bottomPixel instanceof Empty ? TextColor.ANSI.BLACK : bottomPixel.getColor());
tg.setCharacter(termX, termY, '▄');
}
}
renderInput(false);
try {
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.DELTA);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void handleKeyboardAction(KeyboardPressEvent event) {
if (connecting) {
return;
}
if (event.getKeyStroke().getKeyType() == KeyType.Enter) {
try {
connecting = true;
client.connect(ipBuffer.toString());
eventManager.emitEvent(new SendSocketMessageEvent(new CreateGame()));
} catch (DeploymentException | IOException e) {
connecting = false;
}
return;
}
if (event.getKeyStroke().getKeyType() == KeyType.Backspace) {
if (ipBuffer.isEmpty()) {
return;
}
ipBuffer.deleteCharAt(ipBuffer.length() - 1);
renderInput(true);
return;
}
if (event.getKeyStroke().getKeyType() == KeyType.Character) {
ipBuffer.append(event.getKeyStroke().getCharacter());
renderInput(true);
}
}
@Override
public void handleMouseAction(MouseAction event) {
}
}
}

View File

@@ -1,6 +1,7 @@
package cz.jzitnik.client.game.utils;
import cz.jzitnik.client.game.objects.Interactable;
import cz.jzitnik.common.models.coordinates.RoomCords;
import java.awt.image.BufferedImage;

View File

@@ -43,8 +43,8 @@ public class Client {
session.getBasicRemote().sendBinary(ByteBuffer.wrap(baos.toByteArray()));
}
public void connect() throws DeploymentException, IOException {
public void connect(String ip) throws DeploymentException, IOException {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.connectToServer(this, URI.create("ws://localhost:8025/ws"));
container.connectToServer(this, URI.create(String.format("ws://%s:8025/ws", ip)));
}
}

View File

@@ -0,0 +1,26 @@
package cz.jzitnik.client.socket.events;
import cz.jzitnik.client.annotations.SocketEventHandler;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.FullRoomDraw;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.common.socket.messages.game.creation.CreateGameResponse;
@SocketEventHandler(CreateGameResponse.class)
public class CreateGameHandler extends AbstractSocketEventHandler<CreateGameResponse> {
@InjectState
private GameState gameState;
@InjectDependency
private EventManager eventManager;
@Override
public void handle(CreateGameResponse event) {
gameState.setPlayer(new Player(event.getOwnerPlayer()));
gameState.setScreen(null);
eventManager.emitEvent(new FullRoomDraw());
}
}

View File

@@ -18,7 +18,7 @@ import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.items.GameItem;
import cz.jzitnik.client.game.items.types.InteractableItem;
import cz.jzitnik.client.game.objects.DroppedItem;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.states.TerminalState;
import cz.jzitnik.client.ui.pixels.ColoredPixel;

View File

@@ -0,0 +1,55 @@
package cz.jzitnik.client.ui.utils;
import com.googlecode.lanterna.TextColor;
import cz.jzitnik.client.ui.pixels.AlphaPixel;
import cz.jzitnik.client.ui.pixels.ColoredPixel;
import cz.jzitnik.client.ui.pixels.Empty;
import cz.jzitnik.client.utils.TextRenderer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.awt.*;
@AllArgsConstructor
@RequiredArgsConstructor
public class Input {
@Getter
private String contentBuffer;
private final int height;
private final int width;
public AlphaPixel[][] render(TextRenderer textRenderer) {
AlphaPixel[][] buffer = new AlphaPixel[height][width];
AlphaPixel[][] textBuf = new AlphaPixel[0][0];
if (!contentBuffer.isEmpty()) {
textBuf = textRenderer.renderTextSingleLine(contentBuffer, width - 4, height - 4, Color.WHITE, 15f, false, true);
}
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
buffer[y][x] = new ColoredPixel(new TextColor.RGB(255, 255, 255));
continue;
}
if (x == 1 || y == 1 || x == width - 2 || y == height - 2) {
buffer[y][x] = new Empty();
continue;
}
int realX = x - 2;
int realY = y - 2;
if (contentBuffer.isEmpty()) {
buffer[y][x] = new Empty();
} else {
buffer[y][x] = textBuf[realY][realX];
}
}
}
return buffer;
}
}

View File

@@ -10,7 +10,7 @@ import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.mobs.Mob;
import cz.jzitnik.client.game.objects.DroppedItem;
import cz.jzitnik.client.game.objects.GameObject;
import cz.jzitnik.client.game.utils.RoomCords;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.states.ScreenBuffer;
import cz.jzitnik.client.ui.pixels.ColoredPixel;
import cz.jzitnik.client.ui.pixels.Empty;

View File

@@ -23,7 +23,39 @@ public class TextRenderer {
@InjectDependency
private ResourceManager resourceManager;
public AlphaPixel[][] renderText(String text, int width, int height, Color textColor, float size) {
public AlphaPixel[][] renderTextSingleLine(String text, int width, int height, Color textColor, float size, boolean centeredHorizontally, boolean centeredVertically) {
Font font = loadFont(size);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = createGraphics(img, font, textColor);
FontMetrics fm = g2d.getFontMetrics();
int x;
int textWidth = fm.stringWidth(text);
if (centeredHorizontally) {
x = (width - textWidth) / 2;
} else {
if (textWidth > width) {
x = width - textWidth;
} else {
x = 0;
}
}
int y;
if (centeredVertically) {
y = ((height - fm.getHeight()) / 2) + fm.getAscent();
} else {
int verticalOffset = calculateVerticalOffset(text, font, fm.getFontRenderContext(), List.of(text));
y = fm.getAscent() - verticalOffset;
}
g2d.drawString(text, x, y);
g2d.dispose();
return convertToPixels(img, width, height);
}
public AlphaPixel[][] renderText(String text, int width, int height, Color textColor, float size, boolean centered) {
Font font = loadFont(size);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = createGraphics(img, font, textColor);
@@ -37,7 +69,14 @@ public class TextRenderer {
int y = fm.getAscent() - verticalOffset;
for (String line : lines) {
g2d.drawString(line, 0, y);
int x = 0;
if (centered) {
int lineWidth = fm.stringWidth(line);
x = (width - lineWidth) / 2;
}
g2d.drawString(line, x, y);
y += lineHeight;
}
g2d.dispose();

224
logs/general.log Normal file
View File

@@ -0,0 +1,224 @@
2026-02-01 12:16:30 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 69 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:16:31 [Thread-6] INFO cz.jzitnik.client.sound.SoundPlayer - [66] Line started.
2026-02-01 12:18:38 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 63 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:18:39 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:18:47 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 66 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:18:47 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:19:59 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 54 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:19:59 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:20:02 [pool-7-thread-5] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:03 [pool-7-thread-8] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:03 [pool-7-thread-3] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:03 [pool-7-thread-6] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:04 [pool-7-thread-8] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:04 [pool-7-thread-4] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:04 [pool-16-thread-2] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 12:20:05 [pool-16-thread-4] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 12:20:05 [pool-16-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:05 [pool-16-thread-6] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 12:20:06 [pool-16-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:07 [pool-7-thread-4] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:20:08 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:08 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:08 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Health: 9
2026-02-01 12:20:08 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:09 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:09 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:09 [pool-7-thread-5] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:09 [pool-7-thread-5] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:09 [pool-7-thread-5] DEBUG c.j.client.game.mobs.HittableMob - Health: 8
2026-02-01 12:20:09 [pool-7-thread-5] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:09 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:10 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:10 [pool-7-thread-8] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:10 [pool-7-thread-8] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:10 [pool-7-thread-8] DEBUG c.j.client.game.mobs.HittableMob - Health: 7
2026-02-01 12:20:10 [pool-7-thread-8] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:10 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:10 [pool-17-thread-2] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 12:20:10 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:10 [pool-7-thread-4] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:10 [pool-7-thread-4] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:10 [pool-7-thread-4] DEBUG c.j.client.game.mobs.HittableMob - Health: 6
2026-02-01 12:20:10 [pool-7-thread-4] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:10 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:11 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Health: 5
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:11 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:11 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:11 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:11 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:11 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Health: 4
2026-02-01 12:20:11 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:11 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:12 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:12 [pool-7-thread-3] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:12 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Health: 3
2026-02-01 12:20:12 [pool-7-thread-3] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:12 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:12 [pool-7-thread-2] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:12 [pool-7-thread-2] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:12 [pool-7-thread-2] DEBUG c.j.client.game.mobs.HittableMob - Health: 2
2026-02-01 12:20:12 [pool-7-thread-2] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:12 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:13 [pool-7-thread-4] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:13 [pool-7-thread-4] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:13 [pool-7-thread-4] DEBUG c.j.client.game.mobs.HittableMob - Health: 1
2026-02-01 12:20:13 [pool-7-thread-4] DEBUG c.j.client.game.mobs.HittableMob - Hitting start
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-8-thread-1] DEBUG c.j.client.game.mobs.HittableMob - Hitting end
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:13 [pool-17-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 12:20:13 [pool-7-thread-7] DEBUG cz.jzitnik.client.game.Player - Started swinging
2026-02-01 12:20:13 [pool-7-thread-7] DEBUG cz.jzitnik.client.game.Player - Selected item: null
2026-02-01 12:20:13 [pool-7-thread-7] DEBUG c.j.client.game.mobs.HittableMob - Health: 0
2026-02-01 12:20:14 [pool-11-thread-1] DEBUG cz.jzitnik.client.game.Player - Swinging done
2026-02-01 12:20:15 [pool-7-thread-7] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: true
2026-02-01 12:20:15 [pool-3-thread-1] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: false
2026-02-01 12:20:15 [pool-7-thread-5] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: true
2026-02-01 12:20:15 [pool-3-thread-1] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: false
2026-02-01 12:20:16 [pool-7-thread-3] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 12:33:53 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 59 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:33:53 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:34:21 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 63 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:34:21 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:34:50 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 65 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:34:51 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:35:59 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 62 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:36:00 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 12:36:27 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 55 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 12:36:28 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:40:58 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 68 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 14:40:59 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:41:55 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:42:52 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:43:48 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:44:45 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:55:16 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 75 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 14:55:17 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:56:06 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 53 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 14:56:07 [pool-7-thread-1] ERROR c.j.client.utils.events.EventManager - Error
java.lang.ArrayIndexOutOfBoundsException: Index 66 out of bounds for length 66
at cz.jzitnik.client.ui.utils.Input.render(Input.java:45)
at cz.jzitnik.client.game.setup.scenes.connect.ServerChoose$ServerSelector.fullRender(ServerChoose.java:111)
at cz.jzitnik.client.screens.scenes.Scene.render(Scene.java:62)
at cz.jzitnik.client.screens.scenes.Scene.fullRender(Scene.java:53)
at cz.jzitnik.client.events.handlers.TerminalResizeEventHandler.handle(TerminalResizeEventHandler.java:54)
at cz.jzitnik.client.events.handlers.TerminalResizeEventHandler.handle(TerminalResizeEventHandler.java:18)
at cz.jzitnik.client.utils.events.EventManager.lambda$handleEvent$0(EventManager.java:112)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
at java.base/java.lang.Thread.run(Thread.java:1474)
2026-02-01 14:56:07 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:56:30 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 71 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 14:56:31 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:56:52 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 63 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 14:56:53 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:57:50 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 14:58:35 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 60 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 14:58:36 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:01:08 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 64 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:01:09 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:01:23 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 63 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:01:24 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:02:27 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 57 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:02:28 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:02:36 [pool-7-thread-8] ERROR c.j.client.utils.events.EventManager - Error
java.lang.StringIndexOutOfBoundsException: Index -1 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
at java.base/java.lang.String.checkIndex(String.java:4904)
at java.base/java.lang.AbstractStringBuilder.deleteCharAt(AbstractStringBuilder.java:1081)
at java.base/java.lang.StringBuilder.deleteCharAt(StringBuilder.java:298)
at cz.jzitnik.client.game.setup.scenes.connect.ServerChoose$ServerSelector.handleKeyboardAction(ServerChoose.java:170)
at cz.jzitnik.client.screens.scenes.Scene.handleKeyboardAction(Scene.java:96)
at cz.jzitnik.client.events.handlers.KeyboardPressEventHandler.handle(KeyboardPressEventHandler.java:22)
at cz.jzitnik.client.events.handlers.KeyboardPressEventHandler.handle(KeyboardPressEventHandler.java:11)
at cz.jzitnik.client.utils.events.EventManager.lambda$handleEvent$0(EventManager.java:112)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
at java.base/java.lang.Thread.run(Thread.java:1474)
2026-02-01 15:04:50 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 61 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:04:51 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:05:10 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 58 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:05:11 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:05:51 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 66 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:05:52 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:06:48 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:07:44 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:08:41 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:08:49 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 69 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:08:50 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:09:01 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 58 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:09:02 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:09:21 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 57 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:09:22 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:09:33 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 58 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:09:34 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:10:30 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:11:23 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 62 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:11:24 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:11:42 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 73 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:11:42 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:11:49 [pool-7-thread-1] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:50 [pool-7-thread-4] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:50 [pool-7-thread-7] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:51 [pool-7-thread-2] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:51 [pool-7-thread-5] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:51 [pool-7-thread-7] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:52 [pool-16-thread-2] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 15:11:52 [pool-16-thread-6] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 15:11:53 [pool-16-thread-3] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 15:11:53 [pool-16-thread-3] DEBUG c.j.c.g.m.t.EnemyPlayerAttackingTask - Is dead: false
2026-02-01 15:11:53 [pool-16-thread-5] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 15:11:53 [pool-16-thread-5] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 15:11:53 [pool-16-thread-5] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 15:11:53 [pool-16-thread-5] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 15:11:53 [pool-7-thread-6] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:53 [pool-16-thread-1] DEBUG c.j.c.g.m.t.MobFollowingPlayerTask - Mob is effectively at the target or trapped.
2026-02-01 15:11:56 [pool-7-thread-6] DEBUG c.j.c.e.handlers.FullRoomDrawHandler - Rendering full room
2026-02-01 15:11:57 [pool-7-thread-8] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: true
2026-02-01 15:11:57 [pool-3-thread-1] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: false
2026-02-01 15:11:57 [pool-7-thread-7] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: true
2026-02-01 15:11:57 [pool-3-thread-1] DEBUG cz.jzitnik.client.ui.Inventory - Gonna doubleclick: false
2026-02-01 15:15:04 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 59 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:15:04 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.
2026-02-01 15:16:09 [cz.jzitnik.client.Main.main()] INFO org.reflections.Reflections - Reflections took 65 ms to scan 1 urls, producing 51 keys and 239 values
2026-02-01 15:16:09 [Thread-5] INFO cz.jzitnik.client.sound.SoundPlayer - [62] Line started.

14
pom.xml
View File

@@ -21,4 +21,18 @@
<maven.compiler.target>25</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<skip>true</skip>
<mainClass>none</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -12,6 +12,44 @@
<artifactId>server</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.42</version>
</path>
</annotationProcessorPaths>
<source>25</source>
<target>25</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>cz.jzitnik.server.Main</mainClass>
<classpathScope>compile</classpathScope>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>cz.jzitnik</groupId>

View File

@@ -11,7 +11,7 @@ import org.reflections.Reflections;
import java.util.*;
public class Main {
static void main() throws DeploymentException {
public static void main(String[] args) throws DeploymentException {
GlobalContext globalContext = new GlobalContext();
AppContext.set(globalContext);

View File

@@ -1,14 +1,32 @@
package cz.jzitnik.server.events.handlers;
import cz.jzitnik.common.models.player.PlayerCreation;
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
import cz.jzitnik.common.socket.messages.game.creation.CreateGameResponse;
import cz.jzitnik.server.annotations.EventHandler;
import cz.jzitnik.server.context.GlobalContext;
import cz.jzitnik.server.events.AbstractEventHandler;
import cz.jzitnik.server.game.Client;
import lombok.RequiredArgsConstructor;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectReader;
import tools.jackson.dataformat.yaml.YAMLFactory;
@RequiredArgsConstructor
@EventHandler(CreateGame.class)
public class CreateGameHandler extends AbstractEventHandler<CreateGame> {
private final GlobalContext globalContext;
@Override
public void handle(CreateGame event, Client client) {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
String pass = "nevim"; // TODO: Generate
ObjectReader playerReader = objectMapper.readerFor(PlayerCreation.class);
PlayerCreation player = playerReader.readValue(getClass().getClassLoader().getResourceAsStream("setup/player.yaml"));
CreateGameResponse gameResponse = new CreateGameResponse(pass, player);
client.session().sendMessage(gameResponse);
}
}

View File

@@ -1,7 +1,6 @@
package cz.jzitnik.server.socket;
import cz.jzitnik.common.socket.SocketMessage;
import cz.jzitnik.common.socket.messages.Test;
import jakarta.websocket.Session;
import lombok.Getter;
import lombok.RequiredArgsConstructor;