Compare commits
15 Commits
main
...
ac5a96eb19
| Author | SHA1 | Date | |
|---|---|---|---|
|
ac5a96eb19
|
|||
|
fc14e4081d
|
|||
|
ef14edffde
|
|||
|
bfcce054d5
|
|||
|
b72ac87098
|
|||
|
5193b4aba8
|
|||
|
6e665dbbdd
|
|||
|
743ad8e760
|
|||
|
aac651cf93
|
|||
|
f8d28acc33
|
|||
|
46981937ce
|
|||
|
cb488f9853
|
|||
|
da45765413
|
|||
|
eef269c853
|
|||
| 6335ab7e5c |
1
.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
logs
|
|
||||||
4
.idea/compiler.xml
generated
@@ -14,6 +14,7 @@
|
|||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<processorPath useClasspath="false">
|
<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" />
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.42/lombok-1.18.42.jar" />
|
||||||
</processorPath>
|
</processorPath>
|
||||||
<module name="common" />
|
<module name="common" />
|
||||||
</profile>
|
</profile>
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<processorPath useClasspath="false">
|
<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" />
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.42/lombok-1.18.42.jar" />
|
||||||
</processorPath>
|
</processorPath>
|
||||||
<module name="server" />
|
<module name="server" />
|
||||||
</profile>
|
</profile>
|
||||||
@@ -32,9 +34,9 @@
|
|||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<processorPath useClasspath="false">
|
<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" />
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.38/lombok-1.18.38.jar" />
|
||||||
</processorPath>
|
</processorPath>
|
||||||
<module name="game (1)" />
|
<module name="game (1)" />
|
||||||
<module name="game" />
|
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
2
.idea/misc.xml
generated
@@ -8,5 +8,5 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
||||||
37
README.md
@@ -1,37 +0,0 @@
|
|||||||
# Terminal Game
|
|
||||||
|
|
||||||
A multiplayer terminal-based game built with Java, utilizing WebSockets for communication and Lanterna for the text-based user interface.
|
|
||||||
|
|
||||||
## Project Structure
|
|
||||||
|
|
||||||
* **game**: Client application (TUI).
|
|
||||||
* **server**: WebSocket server.
|
|
||||||
* **common**: Shared libraries and logic.
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
* Java 25
|
|
||||||
* Maven
|
|
||||||
|
|
||||||
## How to Run
|
|
||||||
|
|
||||||
1. Build the project:
|
|
||||||
```bash
|
|
||||||
mvn clean install
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Start the server:
|
|
||||||
```bash
|
|
||||||
mvn compile exec:java -pl server -am
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Start the client (in a new terminal):
|
|
||||||
```bash
|
|
||||||
mvn compile exec:java -pl game -am
|
|
||||||
```
|
|
||||||
|
|
||||||
## Controls
|
|
||||||
|
|
||||||
* **Left Click**: Interact with objects and fight.
|
|
||||||
* **WASD**: Move the character.
|
|
||||||
* **CTRL**: Hold to run (sprint).
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package cz.jzitnik.common;
|
|
||||||
|
|
||||||
public class Config {
|
|
||||||
public static final int WORLD_PASSWORD_LENGTH = 5;
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ import lombok.Getter;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -17,13 +16,6 @@ public class RoomCords implements Cloneable, Serializable {
|
|||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
|
|
||||||
public RoomCords calculateCenter(BufferedImage texture) {
|
|
||||||
return new RoomCords(
|
|
||||||
x + texture.getWidth() / 2,
|
|
||||||
y + texture.getHeight() / 2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public RoomCords(
|
public RoomCords(
|
||||||
@JsonProperty("x") int x,
|
@JsonProperty("x") int x,
|
||||||
@@ -37,10 +29,6 @@ public class RoomCords implements Cloneable, Serializable {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCords(RoomCords roomCords) {
|
|
||||||
updateCords(roomCords.getX(), roomCords.getY());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCordsWithColliders(List<RoomPart> colliders, int x, int y, RoomPart playerCollider) {
|
public void updateCordsWithColliders(List<RoomPart> colliders, int x, int y, RoomPart playerCollider) {
|
||||||
var normalizedPlayerCollider = new RoomPart(
|
var normalizedPlayerCollider = new RoomPart(
|
||||||
new RoomCords(playerCollider.getStart().getX() + x, playerCollider.getStart().getY() + y),
|
new RoomCords(playerCollider.getStart().getX() + x, playerCollider.getStart().getY() + y),
|
||||||
|
|||||||
@@ -5,14 +5,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
import cz.jzitnik.common.models.coordinates.RoomCords;
|
||||||
import cz.jzitnik.common.models.coordinates.RoomPart;
|
import cz.jzitnik.common.models.coordinates.RoomPart;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public final class PlayerCreation implements Serializable {
|
public final class PlayerCreation implements Serializable {
|
||||||
@Setter
|
|
||||||
private int id;
|
|
||||||
private final RoomCords playerCords;
|
private final RoomCords playerCords;
|
||||||
private final RoomPart collider;
|
private final RoomPart collider;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.game;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record GameWin() implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.game;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record PlayerDeath(int playerId) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.game.connection;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record ConnectToAGame(String gamePass) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.game.connection;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record ConnectToAGameResponse(ResponseType responseType, PlayerCreation playerCreation, List<PlayerCreation> existingPlayers) implements SocketMessage {
|
|
||||||
private enum ResponseType {
|
|
||||||
GAME_DOES_NOT_EXIST,
|
|
||||||
SUCCESS
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectToAGameResponse() {
|
|
||||||
this(ResponseType.GAME_DOES_NOT_EXIST, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectToAGameResponse(PlayerCreation playerCreation, List<PlayerCreation> existingPlayers) {
|
|
||||||
this(ResponseType.SUCCESS, playerCreation, existingPlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean success() {
|
|
||||||
return responseType == ResponseType.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.items;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record ItemTookFromChest(
|
|
||||||
String roomId, // For faster lookup i guess
|
|
||||||
int id
|
|
||||||
) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.player;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record PlayerArrivalChange(int id, RoomCords playerCords, PlayerRotation playerRotation,
|
|
||||||
boolean arrived, boolean rerender) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.player;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record PlayerDisconnected(int playerId) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.player;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record PlayerJoined(PlayerCreation playerCreation) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.player;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record PlayerMove(RoomCords newCords, PlayerRotation playerRotation) implements SocketMessage {
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.player;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PlayerMovedInUrRoom implements SocketMessage {
|
|
||||||
private int playerId;
|
|
||||||
private RoomCords cords;
|
|
||||||
private PlayerRotation playerRotation;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.player;
|
|
||||||
|
|
||||||
public enum PlayerRotation {
|
|
||||||
FRONT, BACK, LEFT, RIGHT
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.room;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
|
|
||||||
public record MovePlayerRoom(String newRoomId, RoomCords oldCords, RoomCords newCords) implements SocketMessage {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package cz.jzitnik.common.socket.messages.room;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerRotation;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public record MovePlayerRoomResponse(Set<Registry> players) implements SocketMessage {
|
|
||||||
public record Registry(int id, RoomCords cords, PlayerRotation playerRotation) implements Serializable {}
|
|
||||||
|
|
||||||
public Optional<Registry> getById(int id) {
|
|
||||||
return players.stream().filter(registry -> registry.id == id).findFirst();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getIds() {
|
|
||||||
return players.stream().map(Registry::id).collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import cz.jzitnik.client.annotations.EventHandler;
|
|||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
import cz.jzitnik.client.events.RerenderScreen;
|
import cz.jzitnik.client.events.RerenderScreen;
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.dialog.Dialog;
|
import cz.jzitnik.client.game.dialog.Dialog;
|
||||||
import cz.jzitnik.client.game.dialog.OnEnd;
|
import cz.jzitnik.client.game.dialog.OnEnd;
|
||||||
import cz.jzitnik.client.states.DialogState;
|
import cz.jzitnik.client.states.DialogState;
|
||||||
@@ -23,8 +22,8 @@ import cz.jzitnik.client.utils.events.EventManager;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@EventHandler(Dialog.class)
|
@EventHandler(Dialog.class)
|
||||||
@@ -39,9 +38,6 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
|
|||||||
@InjectState
|
@InjectState
|
||||||
private ScreenBuffer screenBuffer;
|
private ScreenBuffer screenBuffer;
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
@InjectDependency
|
||||||
private EventManager eventManager;
|
private EventManager eventManager;
|
||||||
|
|
||||||
@@ -60,45 +56,32 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
|
|||||||
public static final int BUTTON_PADDING = 5;
|
public static final int BUTTON_PADDING = 5;
|
||||||
private static final float FONT_SIZE = 15f;
|
private static final float FONT_SIZE = 15f;
|
||||||
|
|
||||||
public static int calculateButtonHeight(Dialog dialog, GameState gameState) {
|
public static int calculateButtonHeight(Dialog dialog) {
|
||||||
if (dialog.getOnEnd() instanceof OnEnd.AskQuestion askQuestion) {
|
if (dialog.getOnEnd() instanceof OnEnd.AskQuestion(OnEnd.AskQuestion.Answer[] answers)) {
|
||||||
int count = askQuestion.answers(gameState).length;
|
return answers.length * BUTTON_HEIGHT + (answers.length - 1) * BUTTON_PADDING;
|
||||||
return count * BUTTON_HEIGHT + Math.max(0, count - 1) * BUTTON_PADDING;
|
} else {
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int getYStartButtons(TextRenderer textRenderer, Dialog dialog) {
|
public static int getYStartButtons(TextRenderer textRenderer, Dialog dialog) {
|
||||||
var textSize = textRenderer.measureText(
|
var textSize = textRenderer.measureText(dialog.getText(), WIDTH - PADDING * 2, FONT_SIZE);
|
||||||
dialog.getText(),
|
|
||||||
WIDTH - PADDING * 2,
|
|
||||||
FONT_SIZE
|
|
||||||
);
|
|
||||||
|
|
||||||
return PADDING + textSize.height + BUTTON_PADDING;
|
return PADDING + textSize.height + BUTTON_PADDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TerminalSize getSize(TextRenderer textRenderer, Dialog dialog, GameState gameState) {
|
public static TerminalSize getSize(TextRenderer textRenderer, Dialog dialog) {
|
||||||
var textSize = textRenderer.measureText(
|
var textSize = textRenderer.measureText(dialog.getText(), WIDTH - PADDING * 2, FONT_SIZE);
|
||||||
dialog.getText(),
|
|
||||||
WIDTH - PADDING * 2,
|
|
||||||
FONT_SIZE
|
|
||||||
);
|
|
||||||
|
|
||||||
int buttonsHeight = 0;
|
return new TerminalSize(300, PADDING + textSize.height + (
|
||||||
if (dialog.getOnEnd() instanceof OnEnd.AskQuestion) {
|
dialog.getOnEnd() instanceof OnEnd.AskQuestion ? BUTTON_PADDING + calculateButtonHeight(dialog) : 0
|
||||||
buttonsHeight = BUTTON_PADDING + calculateButtonHeight(dialog, gameState);
|
) + PADDING);
|
||||||
}
|
|
||||||
|
|
||||||
return new TerminalSize(
|
|
||||||
300,
|
|
||||||
PADDING + textSize.height + buttonsHeight + PADDING
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TerminalPosition getStart(TerminalSize terminalSize, TerminalSize size) {
|
public static TerminalPosition getStart(TerminalSize terminalSize, TerminalSize size) {
|
||||||
int startY = terminalSize.getRows() * 2 - MARGIN_BOTTOM - size.getRows();
|
int startY = terminalSize.getRows() * 2 - MARGIN_BOTTOM - size.getRows();
|
||||||
int startX = (terminalSize.getColumns() / 2) - (size.getColumns() / 2);
|
int startX = (terminalSize.getColumns() / 2) - (size.getColumns() / 2);
|
||||||
|
|
||||||
return new TerminalPosition(startX, startY);
|
return new TerminalPosition(startX, startY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,114 +89,58 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
|
|||||||
public void handle(Dialog event) {
|
public void handle(Dialog event) {
|
||||||
boolean onlyLast = dialogState.getCurrentDialog() == event;
|
boolean onlyLast = dialogState.getCurrentDialog() == event;
|
||||||
dialogState.setCurrentDialog(event);
|
dialogState.setCurrentDialog(event);
|
||||||
|
|
||||||
TerminalSize terminalSize = terminalState.getTerminalScreen().getTerminalSize();
|
TerminalSize terminalSize = terminalState.getTerminalScreen().getTerminalSize();
|
||||||
var overrideBuffer = screenBuffer.getGlobalOverrideBuffer();
|
var overrideBuffer = screenBuffer.getGlobalOverrideBuffer();
|
||||||
var size = getSize(textRenderer, event, gameState);
|
var size = getSize(textRenderer, event);
|
||||||
|
|
||||||
var start = getStart(terminalSize, size);
|
var start = getStart(terminalSize, size);
|
||||||
|
|
||||||
var animation = textRenderer.renderTypingAnimation(
|
var animation = textRenderer.renderTypingAnimation(event.getText(), size.getColumns() - PADDING * 2, size.getRows() - PADDING * 2, Color.WHITE, FONT_SIZE);
|
||||||
event.getText(),
|
var textSize = textRenderer.measureText(event.getText(), size.getColumns() - PADDING * 2, FONT_SIZE);
|
||||||
size.getColumns() - PADDING * 2,
|
|
||||||
size.getRows() - PADDING * 2,
|
|
||||||
Color.WHITE,
|
|
||||||
FONT_SIZE
|
|
||||||
);
|
|
||||||
|
|
||||||
var textSize = textRenderer.measureText(
|
|
||||||
event.getText(),
|
|
||||||
size.getColumns() - PADDING * 2,
|
|
||||||
FONT_SIZE
|
|
||||||
);
|
|
||||||
|
|
||||||
OnEnd onEnd = event.getOnEnd();
|
OnEnd onEnd = event.getOnEnd();
|
||||||
|
|
||||||
List<AlphaPixel[][]> answersBuf = new ArrayList<>();
|
List<AlphaPixel[][]> answersBuf = new ArrayList<>();
|
||||||
OnEnd.AskQuestion askQuestion = null;
|
|
||||||
|
|
||||||
if (onEnd instanceof OnEnd.AskQuestion aq) {
|
if (onEnd instanceof OnEnd.AskQuestion(
|
||||||
askQuestion = aq;
|
OnEnd.AskQuestion.Answer[] answers
|
||||||
for (OnEnd.AskQuestion.Answer answer : aq.answers(gameState)) {
|
)) {
|
||||||
answersBuf.add(
|
for (OnEnd.AskQuestion.Answer answer : answers) {
|
||||||
textRenderer.renderText(
|
answersBuf.add(textRenderer.renderText(answer.answer(), size.getColumns() - PADDING * 2, BUTTON_HEIGHT, Color.BLACK, FONT_SIZE, false));
|
||||||
answer.answer(),
|
|
||||||
size.getColumns() - PADDING * 2,
|
|
||||||
BUTTON_HEIGHT,
|
|
||||||
Color.BLACK,
|
|
||||||
FONT_SIZE,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogState.setRenderInProgress(true);
|
dialogState.setRenderInProgress(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (int i = onlyLast ? animation.length : 0; i <= animation.length; i++) {
|
for (int i = onlyLast ? animation.length : 0; i <= animation.length; i++) {
|
||||||
var buf = animation[Math.min(i, animation.length - 1)];
|
var buf = animation[Math.min(i, animation.length - 1)];
|
||||||
|
|
||||||
for (int y = 0; y < size.getRows(); y++) {
|
for (int y = 0; y < size.getRows(); y++) {
|
||||||
for (int x = 0; x < size.getColumns(); x++) {
|
for (int x = 0; x < size.getColumns(); x++) {
|
||||||
|
var textPixel = buf[Math.min(Math.max(0, y - PADDING), buf.length - 1)][Math.min(Math.max(0, x - PADDING), buf[0].length - 1)];
|
||||||
var textPixel = buf[
|
if (textPixel instanceof Empty || y < PADDING || x < PADDING || x >= size.getColumns() - PADDING || y >= size.getRows() - PADDING) {
|
||||||
Math.min(Math.max(0, y - PADDING), buf.length - 1)
|
if (i == animation.length && y - 2 > textSize.height + QUESTION_ACTIONS_GAP && onEnd instanceof OnEnd.AskQuestion(
|
||||||
][
|
OnEnd.AskQuestion.Answer[] answers
|
||||||
Math.min(Math.max(0, x - PADDING), buf[0].length - 1)
|
)) {
|
||||||
];
|
|
||||||
|
|
||||||
if (textPixel instanceof Empty
|
|
||||||
|| y < PADDING
|
|
||||||
|| x < PADDING
|
|
||||||
|| x >= size.getColumns() - PADDING
|
|
||||||
|| y >= size.getRows() - PADDING) {
|
|
||||||
|
|
||||||
if (i == animation.length
|
|
||||||
&& askQuestion != null
|
|
||||||
&& y - 2 > textSize.height + QUESTION_ACTIONS_GAP) {
|
|
||||||
|
|
||||||
var answers = askQuestion.answers(gameState);
|
|
||||||
|
|
||||||
int buttonsY = y - textSize.height - QUESTION_ACTIONS_GAP - 2;
|
int buttonsY = y - textSize.height - QUESTION_ACTIONS_GAP - 2;
|
||||||
int buttonIndex = buttonsY / (BUTTON_HEIGHT + BUTTON_PADDING);
|
int buttonIndex = buttonsY / (BUTTON_HEIGHT + BUTTON_PADDING);
|
||||||
int rest = buttonsY % (BUTTON_HEIGHT + BUTTON_PADDING);
|
int rest = buttonsY % (BUTTON_HEIGHT + BUTTON_PADDING);
|
||||||
|
|
||||||
if (buttonIndex < answers.length
|
if (buttonIndex < answers.length && rest < BUTTON_HEIGHT && x >= PADDING && x < size.getColumns() - PADDING) {
|
||||||
&& rest < BUTTON_HEIGHT
|
|
||||||
&& x >= PADDING
|
|
||||||
&& x < size.getColumns() - PADDING) {
|
|
||||||
|
|
||||||
int localY = rest - BUTTON_TEXT_PADDING;
|
int localY = rest - BUTTON_TEXT_PADDING;
|
||||||
int localX = x - PADDING - BUTTON_TEXT_PADDING;
|
int localX = x - PADDING - BUTTON_TEXT_PADDING;
|
||||||
|
|
||||||
var buttonBuf = answersBuf.get(buttonIndex);
|
var buttonBuf = answersBuf.get(buttonIndex);
|
||||||
var buttonTextPixel = buttonBuf[
|
var buttonTextPixel = buttonBuf[Math.min(Math.max(0, localY), buttonBuf.length - 1)][Math.min(Math.max(0, localX), buttonBuf[0].length - 1)];
|
||||||
Math.min(Math.max(0, localY), buttonBuf.length - 1)
|
|
||||||
][
|
|
||||||
Math.min(Math.max(0, localX), buttonBuf[0].length - 1)
|
|
||||||
];
|
|
||||||
|
|
||||||
if (buttonTextPixel instanceof Empty
|
if (buttonTextPixel instanceof Empty || localY < 0 || localX < 0 || localY >= buttonBuf.length || localX >= buttonBuf[0].length) {
|
||||||
|| localY < 0
|
overrideBuffer[start.getRow() + y][start.getColumn() + x] = new ColoredPixel(new TextColor.RGB(255, 255, 255), dialogState.getHoveredButtonIndex() == buttonIndex ? 0.8f : 0.6f);
|
||||||
|| localX < 0
|
|
||||||
|| localY >= buttonBuf.length
|
|
||||||
|| localX >= buttonBuf[0].length) {
|
|
||||||
|
|
||||||
overrideBuffer[start.getRow() + y][start.getColumn() + x] =
|
|
||||||
new ColoredPixel(
|
|
||||||
new TextColor.RGB(255, 255, 255),
|
|
||||||
dialogState.getHoveredButtonIndex() == buttonIndex ? 0.8f : 0.6f
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
overrideBuffer[start.getRow() + y][start.getColumn() + x] =
|
overrideBuffer[start.getRow() + y][start.getColumn() + x] = buttonTextPixel;
|
||||||
buttonTextPixel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
overrideBuffer[start.getRow() + y][start.getColumn() + x] =
|
overrideBuffer[start.getRow() + y][start.getColumn() + x] = new ColoredPixel(new TextColor.RGB(0, 0, 0), 0.6f);
|
||||||
new ColoredPixel(new TextColor.RGB(0, 0, 0), 0.6f);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,10 +152,7 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
|
|||||||
new RerenderScreen(
|
new RerenderScreen(
|
||||||
new RerenderScreen.ScreenPart(
|
new RerenderScreen.ScreenPart(
|
||||||
start,
|
start,
|
||||||
new TerminalPosition(
|
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
|
||||||
start.getColumn() + size.getColumns(),
|
|
||||||
start.getRow() + size.getRows()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -237,6 +161,7 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dialogState.setRenderInProgress(false);
|
dialogState.setRenderInProgress(false);
|
||||||
|
|
||||||
next(onEnd, start, size);
|
next(onEnd, start, size);
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -245,39 +170,31 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void next(OnEnd onEnd, TerminalPosition start, TerminalSize size) throws InterruptedException {
|
private void next(OnEnd onEnd, TerminalPosition start, TerminalSize size) throws InterruptedException {
|
||||||
Thread.sleep(1000);
|
|
||||||
|
|
||||||
if (onEnd instanceof OnEnd.Continue(Dialog nextDialog)) {
|
if (onEnd instanceof OnEnd.Continue(Dialog nextDialog)) {
|
||||||
clear(start, size);
|
Thread.sleep(1000);
|
||||||
eventManager.emitEvent(nextDialog);
|
|
||||||
|
|
||||||
} else if (onEnd instanceof OnEnd.RunCode runCode) {
|
|
||||||
Runnable runnable = runCode.getRunnable();
|
|
||||||
dependencyManager.inject(runnable);
|
|
||||||
runnable.run();
|
|
||||||
next(runCode.getOnEnd(), start, size);
|
|
||||||
} else if (onEnd instanceof OnEnd.End) {
|
|
||||||
clear(start, size);
|
|
||||||
dialogState.setCurrentDialog(null);
|
|
||||||
eventManager.emitEvent(
|
|
||||||
new RerenderScreen(
|
|
||||||
new RerenderScreen.ScreenPart(
|
|
||||||
start,
|
|
||||||
new TerminalPosition(
|
|
||||||
start.getColumn() + size.getColumns(),
|
|
||||||
start.getRow() + size.getRows()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clear(TerminalPosition start, TerminalSize size) {
|
|
||||||
for (int y = start.getRow(); y < start.getRow() + size.getRows(); y++) {
|
for (int y = start.getRow(); y < start.getRow() + size.getRows(); y++) {
|
||||||
for (int x = start.getColumn(); x < start.getColumn() + size.getColumns(); x++) {
|
for (int x = start.getColumn(); x < start.getColumn() + size.getColumns(); x++) {
|
||||||
screenBuffer.getGlobalOverrideBuffer()[y][x] = new Empty();
|
screenBuffer.getGlobalOverrideBuffer()[y][x] = new Empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextDialog == null) {
|
||||||
|
dialogState.setCurrentDialog(null);
|
||||||
|
eventManager.emitEvent(
|
||||||
|
new RerenderScreen(
|
||||||
|
new RerenderScreen.ScreenPart(
|
||||||
|
start,
|
||||||
|
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
eventManager.emitEvent(nextDialog);
|
||||||
|
}
|
||||||
|
} else if (onEnd instanceof OnEnd.RunCode(Runnable runnable, OnEnd end)) {
|
||||||
|
dependencyManager.inject(runnable);
|
||||||
|
runnable.run();
|
||||||
|
next(end, start, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
|
|||||||
int startX = start.getX();
|
int startX = start.getX();
|
||||||
int startY = start.getY();
|
int startY = start.getY();
|
||||||
|
|
||||||
RerenderUtils.rerenderPart(0, width - 1, 0, height - 1, startX, startY, currentRoom, room, player, screenBuffer, resourceManager, debugging, gameState.getOtherPlayers());
|
RerenderUtils.rerenderPart(0, width - 1, 0, height - 1, startX, startY, currentRoom, room, player, playerTexture, screenBuffer, resourceManager, debugging);
|
||||||
if (event.isFullRerender()) {
|
if (event.isFullRerender()) {
|
||||||
globalIOHandlerRepository.renderAll();
|
globalIOHandlerRepository.renderAll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,10 +177,10 @@ public class MouseMoveEventHandler extends AbstractEventHandler<MouseMoveEvent>
|
|||||||
currentRoom,
|
currentRoom,
|
||||||
room,
|
room,
|
||||||
player,
|
player,
|
||||||
|
playerTexture,
|
||||||
screenBuffer,
|
screenBuffer,
|
||||||
resourceManager,
|
resourceManager,
|
||||||
debugging,
|
debugging
|
||||||
gameState.getOtherPlayers()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
parts.add(new RerenderScreen.ScreenPart(
|
parts.add(new RerenderScreen.ScreenPart(
|
||||||
|
|||||||
@@ -8,8 +8,14 @@ import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
|||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
import cz.jzitnik.client.config.Debugging;
|
import cz.jzitnik.client.config.Debugging;
|
||||||
import cz.jzitnik.client.config.PlayerConfig;
|
import cz.jzitnik.client.config.PlayerConfig;
|
||||||
import cz.jzitnik.client.events.*;
|
import cz.jzitnik.client.events.MouseMoveEvent;
|
||||||
import cz.jzitnik.client.game.*;
|
import cz.jzitnik.client.events.PlayerMoveEvent;
|
||||||
|
import cz.jzitnik.client.events.RerenderScreen;
|
||||||
|
import cz.jzitnik.client.events.RoomChangeEvent;
|
||||||
|
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.common.models.coordinates.RoomCords;
|
import cz.jzitnik.common.models.coordinates.RoomCords;
|
||||||
import cz.jzitnik.client.states.RenderState;
|
import cz.jzitnik.client.states.RenderState;
|
||||||
import cz.jzitnik.client.states.ScreenBuffer;
|
import cz.jzitnik.client.states.ScreenBuffer;
|
||||||
@@ -20,8 +26,6 @@ import cz.jzitnik.client.utils.RerenderUtils;
|
|||||||
import cz.jzitnik.client.utils.events.AbstractEventHandler;
|
import cz.jzitnik.client.utils.events.AbstractEventHandler;
|
||||||
import cz.jzitnik.client.utils.events.Event;
|
import cz.jzitnik.client.utils.events.Event;
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerMove;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerRotation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -75,46 +79,46 @@ public class PlayerMoveEventHandler extends AbstractEventHandler<PlayerMoveEvent
|
|||||||
case 'w' -> {
|
case 'w' -> {
|
||||||
if (originalPlayerY <= 10) {
|
if (originalPlayerY <= 10) {
|
||||||
if (originalPlayerX >= 80 && originalPlayerX <= 105) {
|
if (originalPlayerX >= 80 && originalPlayerX <= 105) {
|
||||||
player.setPlayerRotation(PlayerRotation.BACK);
|
player.setPlayerRotation(Player.PlayerRotation.BACK);
|
||||||
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.TOP));
|
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.TOP));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX(), playerCords.getY() - moveStep, player.getCollider());
|
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX(), playerCords.getY() - moveStep, player.getCollider());
|
||||||
player.setPlayerRotation(PlayerRotation.BACK);
|
player.setPlayerRotation(Player.PlayerRotation.BACK);
|
||||||
}
|
}
|
||||||
case 'a' -> {
|
case 'a' -> {
|
||||||
if (originalPlayerX <= 30) {
|
if (originalPlayerX <= 30) {
|
||||||
if (originalPlayerY >= 35 && originalPlayerY <= 65) {
|
if (originalPlayerY >= 35 && originalPlayerY <= 65) {
|
||||||
player.setPlayerRotation(PlayerRotation.LEFT);
|
player.setPlayerRotation(Player.PlayerRotation.LEFT);
|
||||||
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.LEFT));
|
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.LEFT));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX() - moveStep, playerCords.getY(), player.getCollider());
|
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX() - moveStep, playerCords.getY(), player.getCollider());
|
||||||
player.setPlayerRotation(PlayerRotation.LEFT);
|
player.setPlayerRotation(Player.PlayerRotation.LEFT);
|
||||||
}
|
}
|
||||||
case 's' -> {
|
case 's' -> {
|
||||||
if (originalPlayerY >= 110) {
|
if (originalPlayerY >= 110) {
|
||||||
if (originalPlayerX >= 75 && originalPlayerX <= 105) {
|
if (originalPlayerX >= 75 && originalPlayerX <= 105) {
|
||||||
player.setPlayerRotation(PlayerRotation.FRONT);
|
player.setPlayerRotation(Player.PlayerRotation.FRONT);
|
||||||
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.BOTTOM));
|
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.BOTTOM));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX(), playerCords.getY() + moveStep, player.getCollider());
|
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX(), playerCords.getY() + moveStep, player.getCollider());
|
||||||
player.setPlayerRotation(PlayerRotation.FRONT);
|
player.setPlayerRotation(Player.PlayerRotation.FRONT);
|
||||||
}
|
}
|
||||||
case 'd' -> {
|
case 'd' -> {
|
||||||
if (originalPlayerX >= 155) {
|
if (originalPlayerX >= 155) {
|
||||||
if (originalPlayerY >= 40 && originalPlayerY <= 60) {
|
if (originalPlayerY >= 40 && originalPlayerY <= 60) {
|
||||||
player.setPlayerRotation(PlayerRotation.RIGHT);
|
player.setPlayerRotation(Player.PlayerRotation.RIGHT);
|
||||||
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.RIGHT));
|
eventManager.emitEvent(new RoomChangeEvent(FullRoomDrawHandler.DoorPosition.RIGHT));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX() + moveStep, playerCords.getY(), player.getCollider());
|
playerCords.updateCordsWithColliders(currentRoom.getColliders(), player.getPlayerCords().getX() + moveStep, playerCords.getY(), player.getCollider());
|
||||||
player.setPlayerRotation(PlayerRotation.RIGHT);
|
player.setPlayerRotation(Player.PlayerRotation.RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playerMovementState.setLastMovement(System.currentTimeMillis());
|
playerMovementState.setLastMovement(System.currentTimeMillis());
|
||||||
@@ -139,10 +143,9 @@ public class PlayerMoveEventHandler extends AbstractEventHandler<PlayerMoveEvent
|
|||||||
int startX = start.getX();
|
int startX = start.getX();
|
||||||
int startY = start.getY();
|
int startY = start.getY();
|
||||||
|
|
||||||
RerenderUtils.rerenderPart(forStartX, forEndX, forStartY, forEndY, startX, startY, currentRoom, room, player, screenBuffer, resourceManager, debugging, gameState.getOtherPlayers());
|
RerenderUtils.rerenderPart(forStartX, forEndX, forStartY, forEndY, startX, startY, currentRoom, room, player, playerTexture, screenBuffer, resourceManager, debugging);
|
||||||
|
|
||||||
eventManager.emitEvent(new Event[]{
|
eventManager.emitEvent(new Event[]{
|
||||||
new SendSocketMessageEvent(new PlayerMove(playerCords, player.getPlayerRotation())),
|
|
||||||
new MouseMoveEvent(null),
|
new MouseMoveEvent(null),
|
||||||
new RerenderScreen(
|
new RerenderScreen(
|
||||||
new RerenderScreen.ScreenPart[]{
|
new RerenderScreen.ScreenPart[]{
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ public class RerenderPartHandler extends AbstractEventHandler<RerenderPart> {
|
|||||||
currentRoom,
|
currentRoom,
|
||||||
room,
|
room,
|
||||||
gameState.getPlayer(),
|
gameState.getPlayer(),
|
||||||
|
gameState.getPlayer().getTexture(resourceManager),
|
||||||
screenBuffer,
|
screenBuffer,
|
||||||
resourceManager,
|
resourceManager,
|
||||||
debugging,
|
debugging
|
||||||
gameState.getOtherPlayers()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
eventManager.emitEvent(
|
eventManager.emitEvent(
|
||||||
|
|||||||
@@ -3,20 +3,16 @@ package cz.jzitnik.client.events.handlers;
|
|||||||
import cz.jzitnik.client.annotations.EventHandler;
|
import cz.jzitnik.client.annotations.EventHandler;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
|
import cz.jzitnik.client.events.FullRoomDraw;
|
||||||
import cz.jzitnik.client.events.RoomChangeEvent;
|
import cz.jzitnik.client.events.RoomChangeEvent;
|
||||||
import cz.jzitnik.client.events.SendSocketMessageEvent;
|
|
||||||
import cz.jzitnik.client.game.GameRoom;
|
import cz.jzitnik.client.game.GameRoom;
|
||||||
import cz.jzitnik.client.game.GameState;
|
import cz.jzitnik.client.game.GameState;
|
||||||
import cz.jzitnik.client.game.Requirement;
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
import cz.jzitnik.common.models.coordinates.RoomCords;
|
||||||
import cz.jzitnik.client.utils.events.AbstractEventHandler;
|
import cz.jzitnik.client.utils.events.AbstractEventHandler;
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
|
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
|
||||||
import cz.jzitnik.common.socket.messages.game.GameWin;
|
|
||||||
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -35,7 +31,6 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
|
|||||||
@Override
|
@Override
|
||||||
public void handle(RoomChangeEvent event) {
|
public void handle(RoomChangeEvent event) {
|
||||||
RoomCords playerCords = gameState.getPlayer().getPlayerCords();
|
RoomCords playerCords = gameState.getPlayer().getPlayerCords();
|
||||||
RoomCords oldCords = playerCords.clone();
|
|
||||||
GameRoom currentRoom = gameState.getCurrentRoom();
|
GameRoom currentRoom = gameState.getCurrentRoom();
|
||||||
GameRoom newRoom = switch (event.door()) {
|
GameRoom newRoom = switch (event.door()) {
|
||||||
case LEFT -> currentRoom.getLeft();
|
case LEFT -> currentRoom.getLeft();
|
||||||
@@ -48,20 +43,6 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newRoom.getRequirement() != null) {
|
|
||||||
Requirement requirement = newRoom.getRequirement();
|
|
||||||
String itemType = requirement.itemType();
|
|
||||||
if (Arrays.stream(gameState.getPlayer().getInventory()).noneMatch(item -> {
|
|
||||||
if (item == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item.getType().getItemType().getSimpleName().equals(itemType);
|
|
||||||
})) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event.door()) {
|
switch (event.door()) {
|
||||||
case LEFT -> playerCords.updateCords(155, playerCords.getY());
|
case LEFT -> playerCords.updateCords(155, playerCords.getY());
|
||||||
case RIGHT -> playerCords.updateCords(30, playerCords.getY());
|
case RIGHT -> playerCords.updateCords(30, playerCords.getY());
|
||||||
@@ -69,13 +50,10 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
|
|||||||
case BOTTOM -> playerCords.updateCords(playerCords.getX(), 10);
|
case BOTTOM -> playerCords.updateCords(playerCords.getX(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventManager.emitEvent(new SendSocketMessageEvent(new MovePlayerRoom(newRoom.getId(), oldCords, playerCords)));
|
|
||||||
|
|
||||||
gameState.setCurrentRoom(newRoom);
|
gameState.setCurrentRoom(newRoom);
|
||||||
if (newRoom.isEnd()) {
|
scheduler.schedule(() -> {
|
||||||
eventManager.emitEvent(new SendSocketMessageEvent(new GameWin()));
|
roomTaskScheduler.setupNewSchedulers(newRoom);
|
||||||
} else {
|
}, 200, TimeUnit.MILLISECONDS);
|
||||||
scheduler.schedule(() -> roomTaskScheduler.setupNewSchedulers(newRoom), 200, TimeUnit.MILLISECONDS);
|
eventManager.emitEvent(new FullRoomDraw());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package cz.jzitnik.client.game;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
public interface GamePlayer {
|
|
||||||
RoomCords getPlayerCords();
|
|
||||||
BufferedImage getTexture(ResourceManager resourceManager);
|
|
||||||
}
|
|
||||||
@@ -34,12 +34,6 @@ public class GameRoom {
|
|||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private final List<RoomPart> colliders = new ArrayList<>();
|
private final List<RoomPart> colliders = new ArrayList<>();
|
||||||
|
|
||||||
@JsonProperty("requirement")
|
|
||||||
private Requirement requirement;
|
|
||||||
|
|
||||||
@JsonProperty("end")
|
|
||||||
private boolean end;
|
|
||||||
|
|
||||||
private GameRoom left;
|
private GameRoom left;
|
||||||
private GameRoom right;
|
private GameRoom right;
|
||||||
private GameRoom up;
|
private GameRoom up;
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ import lombok.Getter;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@State
|
@State
|
||||||
public class GameState {
|
public class GameState {
|
||||||
@@ -20,24 +17,10 @@ public class GameState {
|
|||||||
@Setter
|
@Setter
|
||||||
private GameRoom currentRoom;
|
private GameRoom currentRoom;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private List<GameRoom> allRooms;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
private final List<OtherPlayer> otherPlayers = new ArrayList<>();
|
|
||||||
|
|
||||||
public List<OtherPlayer> getOtherPlayers() {
|
|
||||||
return otherPlayers.stream().filter(OtherPlayer::isVisible).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OtherPlayer> getAllOtherPlayers() {
|
|
||||||
return otherPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private Interactable interacting;
|
private Interactable interacting;
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package cz.jzitnik.client.game;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.game.mobs.HittableMob;
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerRotation;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class OtherPlayer implements GamePlayer {
|
|
||||||
private final int id;
|
|
||||||
private boolean hitAnimationOn = false;
|
|
||||||
private final RoomCords playerCords;
|
|
||||||
@Setter
|
|
||||||
private PlayerRotation playerRotation = PlayerRotation.FRONT;
|
|
||||||
@Setter
|
|
||||||
private boolean visible;
|
|
||||||
|
|
||||||
public OtherPlayer(PlayerCreation playerCreation) {
|
|
||||||
this.id = playerCreation.getId();
|
|
||||||
this.playerCords = playerCreation.getPlayerCords();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BufferedImage getTexture(ResourceManager resourceManager) {
|
|
||||||
BufferedImage resource = resourceManager.getResource(switch (playerRotation) {
|
|
||||||
case FRONT -> ResourceManager.Resource.PLAYER_FRONT;
|
|
||||||
case BACK -> ResourceManager.Resource.PLAYER_BACK;
|
|
||||||
case LEFT -> ResourceManager.Resource.PLAYER_LEFT;
|
|
||||||
case RIGHT -> ResourceManager.Resource.PLAYER_RIGHT;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (hitAnimationOn) {
|
|
||||||
return HittableMob.applyRedFactor(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package cz.jzitnik.client.game;
|
package cz.jzitnik.client.game;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import cz.jzitnik.client.events.RerenderPart;
|
import cz.jzitnik.client.events.RerenderPart;
|
||||||
import cz.jzitnik.client.game.items.GameItem;
|
import cz.jzitnik.client.game.items.GameItem;
|
||||||
import cz.jzitnik.client.game.items.types.interfaces.WeaponInterface;
|
import cz.jzitnik.client.game.items.types.interfaces.WeaponInterface;
|
||||||
@@ -11,7 +13,6 @@ import cz.jzitnik.client.utils.DependencyManager;
|
|||||||
import cz.jzitnik.client.utils.events.Event;
|
import cz.jzitnik.client.utils.events.Event;
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
import cz.jzitnik.common.models.player.PlayerCreation;
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerRotation;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -24,11 +25,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Player implements GamePlayer {
|
public class Player {
|
||||||
private final int id;
|
|
||||||
public static final int MAX_STAMINA = 20;
|
public static final int MAX_STAMINA = 20;
|
||||||
public static final int MAX_HEALTH = 30;
|
public static final int MAX_HEALTH = 30;
|
||||||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
|
||||||
private final RoomCords playerCords;
|
private final RoomCords playerCords;
|
||||||
private final RoomPart collider;
|
private final RoomPart collider;
|
||||||
@@ -43,10 +43,18 @@ public class Player implements GamePlayer {
|
|||||||
private boolean hitAnimationOn = false;
|
private boolean hitAnimationOn = false;
|
||||||
private ScheduledFuture<?> currentTimeoutHitAnimation = null;
|
private ScheduledFuture<?> currentTimeoutHitAnimation = null;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public Player(
|
||||||
|
@JsonProperty("playerCords") RoomCords playerCords,
|
||||||
|
@JsonProperty("collider") RoomPart collider
|
||||||
|
) {
|
||||||
|
this.playerCords = playerCords;
|
||||||
|
this.collider = collider;
|
||||||
|
}
|
||||||
|
|
||||||
public Player(PlayerCreation playerCreation) {
|
public Player(PlayerCreation playerCreation) {
|
||||||
this.playerCords = playerCreation.getPlayerCords();
|
this.playerCords = playerCreation.getPlayerCords();
|
||||||
this.collider = playerCreation.getCollider();
|
this.collider = playerCreation.getCollider();
|
||||||
this.id = playerCreation.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void increaseStamina() {
|
public void increaseStamina() {
|
||||||
@@ -64,8 +72,6 @@ public class Player implements GamePlayer {
|
|||||||
public boolean dealDamage(int amount, DependencyManager dependencyManager) {
|
public boolean dealDamage(int amount, DependencyManager dependencyManager) {
|
||||||
if (health - amount <= 0) {
|
if (health - amount <= 0) {
|
||||||
health = 0;
|
health = 0;
|
||||||
EventManager eventManager = dependencyManager.getDependencyOrThrow(EventManager.class);
|
|
||||||
eventManager.emitEvent(new cz.jzitnik.client.events.SendSocketMessageEvent(new cz.jzitnik.common.socket.messages.game.PlayerDeath(id)));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,4 +164,7 @@ public class Player implements GamePlayer {
|
|||||||
}, delayMs, TimeUnit.MILLISECONDS);
|
}, delayMs, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum PlayerRotation {
|
||||||
|
FRONT, BACK, LEFT, RIGHT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package cz.jzitnik.client.game;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
public record Requirement(String itemType) {
|
|
||||||
@JsonCreator
|
|
||||||
public Requirement(
|
|
||||||
@JsonProperty("item") String itemType
|
|
||||||
) {
|
|
||||||
this.itemType = itemType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,14 +23,6 @@ public class ResourceManager {
|
|||||||
ROOM2("rooms/2.png"),
|
ROOM2("rooms/2.png"),
|
||||||
ROOM3("rooms/3.png"),
|
ROOM3("rooms/3.png"),
|
||||||
ROOM4("rooms/4.png"),
|
ROOM4("rooms/4.png"),
|
||||||
ROOM5("rooms/5.png"),
|
|
||||||
ROOM6("rooms/6.png"),
|
|
||||||
ROOM7("rooms/7.png"),
|
|
||||||
ROOM8("rooms/8.png"),
|
|
||||||
ROOM9("rooms/9.png"),
|
|
||||||
ROOM10("rooms/10.png"),
|
|
||||||
ROOM11("rooms/11.png"),
|
|
||||||
ROOM12("rooms/12.png"),
|
|
||||||
ROOM_FROZEN("rooms/frozen.png"),
|
ROOM_FROZEN("rooms/frozen.png"),
|
||||||
|
|
||||||
PLAYER_FRONT("player/front.png"),
|
PLAYER_FRONT("player/front.png"),
|
||||||
@@ -44,23 +36,8 @@ public class ResourceManager {
|
|||||||
|
|
||||||
APPLE("food/apple.png"),
|
APPLE("food/apple.png"),
|
||||||
|
|
||||||
// TEMP TEXTURES JUST TO GET THE GAME WORKING
|
|
||||||
OLD_MAN("player/front.png"),
|
|
||||||
KEY_KEEPER("player/front.png"),
|
|
||||||
CAVE_BEAST("player/front.png"),
|
|
||||||
BLIND_HUNTER("player/front.png"),
|
|
||||||
ZOMBIE("player/front.png"),
|
|
||||||
|
|
||||||
RUSTY_SWORD("tools/wooden_sword.png"),
|
|
||||||
AXE("tools/wooden_sword.png"),
|
|
||||||
DAGGER("tools/wooden_sword.png"),
|
|
||||||
BREAD("food/apple.png"),
|
|
||||||
ROCK("food/apple.png"),
|
|
||||||
KEY("food/apple.png"),
|
|
||||||
BOSS_SKIN("tools/wooden_sword.png"),
|
|
||||||
|
|
||||||
// UI
|
|
||||||
DOORS("rooms/doors.png"),
|
DOORS("rooms/doors.png"),
|
||||||
|
|
||||||
STAMINA("ui/stamina.png"),
|
STAMINA("ui/stamina.png"),
|
||||||
HEART("ui/heart.png");
|
HEART("ui/heart.png");
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
package cz.jzitnik.client.game.dialog;
|
package cz.jzitnik.client.game.dialog;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import cz.jzitnik.client.utils.events.Event;
|
import cz.jzitnik.client.utils.events.Event;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequiredArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
public class Dialog implements Event {
|
public class Dialog implements Event {
|
||||||
/**
|
/**
|
||||||
* Characters per second
|
* Characters per second
|
||||||
*/
|
*/
|
||||||
private final int typingSpeed = 10;
|
private int typingSpeed = 10;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final OnEnd onEnd;
|
private final OnEnd onEnd;
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public Dialog(
|
|
||||||
@JsonProperty("text") String text,
|
|
||||||
@JsonProperty("onEnd") OnEnd onEnd
|
|
||||||
) {
|
|
||||||
this.text = text;
|
|
||||||
this.onEnd = onEnd;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,135 +1,13 @@
|
|||||||
package cz.jzitnik.client.game.dialog;
|
package cz.jzitnik.client.game.dialog;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
|
||||||
import cz.jzitnik.client.events.InventoryRerender;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.Player;
|
|
||||||
import cz.jzitnik.client.game.Requirement;
|
|
||||||
import cz.jzitnik.client.game.ResourceManager;
|
|
||||||
import cz.jzitnik.client.game.items.GameItem;
|
|
||||||
import cz.jzitnik.client.game.mobs.HittableMobDrops;
|
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@JsonTypeInfo(
|
|
||||||
use = JsonTypeInfo.Id.NAME,
|
|
||||||
property = "type"
|
|
||||||
)
|
|
||||||
@JsonSubTypes({
|
|
||||||
@JsonSubTypes.Type(value = OnEnd.Continue.class, name = "continue"),
|
|
||||||
@JsonSubTypes.Type(value = OnEnd.AskQuestion.class, name = "ask_question"),
|
|
||||||
@JsonSubTypes.Type(value = OnEnd.End.class, name = "end"),
|
|
||||||
@JsonSubTypes.Type(value = OnEnd.GiveItem.class, name = "give_item")
|
|
||||||
})
|
|
||||||
public interface OnEnd {
|
public interface OnEnd {
|
||||||
record End() implements OnEnd {
|
record RunCode(Runnable runnable, OnEnd onEnd) implements OnEnd {}
|
||||||
}
|
|
||||||
|
|
||||||
class GiveItem extends RunCode {
|
|
||||||
@JsonCreator
|
|
||||||
public GiveItem(
|
|
||||||
@JsonProperty("item") GameItem item,
|
|
||||||
@JsonProperty("then") OnEnd onEnd
|
|
||||||
) {
|
|
||||||
super(new Run(item), onEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
private static class Run implements Runnable {
|
|
||||||
private final GameItem item;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private ResourceManager resourceManager;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Player player = gameState.getPlayer();
|
|
||||||
var playerCords = player.getPlayerCords().calculateCenter(player.getTexture(resourceManager));
|
|
||||||
|
|
||||||
boolean addedIntoInventory = player.addItem(item);
|
|
||||||
|
|
||||||
if (!addedIntoInventory) {
|
|
||||||
eventManager.emitEvent(HittableMobDrops.dropItem(playerCords.getX(), playerCords.getY(), gameState.getCurrentRoom(), item));
|
|
||||||
} else {
|
|
||||||
eventManager.emitEvent(new InventoryRerender());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
class RunCode implements OnEnd {
|
|
||||||
private final Runnable runnable;
|
|
||||||
private final OnEnd onEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
record Continue(Dialog nextDialog) implements OnEnd {
|
record Continue(Dialog nextDialog) implements OnEnd {
|
||||||
@JsonCreator
|
|
||||||
public Continue(@JsonProperty("nextDialog") Dialog nextDialog) {
|
|
||||||
this.nextDialog = nextDialog;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
record AskQuestion(Answer[] answers) implements OnEnd {
|
record AskQuestion(Answer[] answers) implements OnEnd {
|
||||||
@JsonCreator
|
public record Answer(String answer, Dialog dialog) {
|
||||||
public AskQuestion(@JsonProperty("answers") Answer[] answers) {
|
|
||||||
this.answers = answers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public record Answer(
|
|
||||||
String answer,
|
|
||||||
Dialog dialog,
|
|
||||||
Optional<Requirement> requirement
|
|
||||||
) {
|
|
||||||
@JsonCreator
|
|
||||||
public Answer(
|
|
||||||
@JsonProperty("answer") String answer,
|
|
||||||
@JsonProperty("dialog") Dialog dialog,
|
|
||||||
@JsonProperty("requirement") Requirement requirement
|
|
||||||
) {
|
|
||||||
this(answer, dialog, Optional.ofNullable(requirement));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValid(GameState gameState) {
|
|
||||||
if (requirement.isPresent()) {
|
|
||||||
Requirement requirement = requirement().get();
|
|
||||||
if (requirement.itemType() != null) {
|
|
||||||
return Arrays.stream(gameState.getPlayer().getInventory()).anyMatch(item -> {
|
|
||||||
if (item == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item.getType().getItemType().getSimpleName().equals(requirement.itemType());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Answer[] answers(GameState gameState) {
|
|
||||||
return Arrays.stream(answers)
|
|
||||||
.filter(answer -> answer.isValid(gameState))
|
|
||||||
.toArray(Answer[]::new);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,17 +14,14 @@ public class GameItem implements Renderable {
|
|||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private final BufferedImage texture;
|
private final BufferedImage texture;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int id;
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public GameItem(
|
public GameItem(
|
||||||
@JsonProperty("id") int id,
|
|
||||||
@JsonProperty("name") String name,
|
@JsonProperty("name") String name,
|
||||||
@JsonProperty("type") ItemType<?> type,
|
@JsonProperty("type") ItemType<?> type,
|
||||||
@JsonProperty("texture") ResourceManager.Resource resource,
|
@JsonProperty("texture") ResourceManager.Resource resource,
|
||||||
@JacksonInject ResourceManager resourceManager
|
@JacksonInject ResourceManager resourceManager
|
||||||
) {
|
) {
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.texture = resourceManager.getResource(resource);
|
this.texture = resourceManager.getResource(resource);
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package cz.jzitnik.client.game.items.types;
|
|
||||||
|
|
||||||
public class BeastSkin implements ItemType<BeastSkin> {
|
|
||||||
@Override
|
|
||||||
public Class<BeastSkin> getItemType() {
|
|
||||||
return BeastSkin.class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,10 +11,7 @@ import cz.jzitnik.client.game.items.types.weapons.Sword;
|
|||||||
)
|
)
|
||||||
@JsonSubTypes({
|
@JsonSubTypes({
|
||||||
@JsonSubTypes.Type(value = Food.class, name = "food"),
|
@JsonSubTypes.Type(value = Food.class, name = "food"),
|
||||||
@JsonSubTypes.Type(value = Sword.class, name = "weapon_sword"),
|
@JsonSubTypes.Type(value = Sword.class, name = "weapon_sword")
|
||||||
@JsonSubTypes.Type(value = Junk.class, name = "junk"),
|
|
||||||
@JsonSubTypes.Type(value = Key.class, name = "key"),
|
|
||||||
@JsonSubTypes.Type(value = BeastSkin.class, name = "beast_skin"),
|
|
||||||
})
|
})
|
||||||
public interface ItemType<T> {
|
public interface ItemType<T> {
|
||||||
Class<T> getItemType();
|
Class<T> getItemType();
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package cz.jzitnik.client.game.items.types;
|
|
||||||
|
|
||||||
public class Junk implements ItemType<Junk> {
|
|
||||||
@Override
|
|
||||||
public Class<Junk> getItemType() {
|
|
||||||
return Junk.class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package cz.jzitnik.client.game.items.types;
|
|
||||||
|
|
||||||
public class Key implements ItemType<Key> {
|
|
||||||
@Override
|
|
||||||
public Class<Key> getItemType() {
|
|
||||||
return Key.class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
package cz.jzitnik.client.game.mobs;
|
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.annotations.injectors.InjectDependency;
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
import cz.jzitnik.client.game.ResourceManager;
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomPart;
|
import cz.jzitnik.common.models.coordinates.RoomPart;
|
||||||
import cz.jzitnik.client.game.dialog.Dialog;
|
import cz.jzitnik.client.game.dialog.Dialog;
|
||||||
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
|
import cz.jzitnik.client.game.mobs.tasks.MobRoomTask;
|
||||||
@@ -14,20 +10,14 @@ import cz.jzitnik.client.states.DialogState;
|
|||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DialogMob extends Mob {
|
public abstract class DialogMob extends Mob {
|
||||||
protected Dialog dialog;
|
protected Dialog dialog;
|
||||||
|
|
||||||
@JsonCreator
|
public DialogMob(BufferedImage texture, MobRoomTask[] tasks, RoomCords cords, RoomPart collider, Dialog dialog) {
|
||||||
public DialogMob(
|
super(texture, tasks, cords, collider);
|
||||||
@JsonProperty("texture") ResourceManager.Resource texture,
|
|
||||||
@JsonProperty("tasks") MobRoomTask[] tasks,
|
|
||||||
@JsonProperty("cords") RoomCords cords,
|
|
||||||
@JsonProperty("collider") RoomPart collider,
|
|
||||||
@JsonProperty("dialog") Dialog dialog,
|
|
||||||
@JacksonInject ResourceManager resourceManager
|
|
||||||
) {
|
|
||||||
super(resourceManager.getResource(texture), tasks, cords, collider);
|
|
||||||
this.dialog = dialog;
|
this.dialog = dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,10 @@ public class HittableMobDrops extends HittableMob {
|
|||||||
Player player = gameState.getPlayer();
|
Player player = gameState.getPlayer();
|
||||||
RoomCords enemyCords = getCords();
|
RoomCords enemyCords = getCords();
|
||||||
BufferedImage enemyTexture = getTexture();
|
BufferedImage enemyTexture = getTexture();
|
||||||
|
GameRoom currentRoom = gameState.getCurrentRoom();
|
||||||
|
|
||||||
int roomX = enemyCords.getX() + enemyTexture.getWidth() / 2;
|
int roomX = enemyCords.getX() + enemyTexture.getWidth() / 2;
|
||||||
int roomY = enemyCords.getY() + enemyTexture.getHeight() / 2;
|
int roomY = enemyCords.getY() + enemyTexture.getHeight() / 2;
|
||||||
GameRoom currentRoom = gameState.getCurrentRoom();
|
|
||||||
|
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
@@ -70,21 +71,17 @@ public class HittableMobDrops extends HittableMob {
|
|||||||
events.add(new InventoryRerender());
|
events.add(new InventoryRerender());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
events.add(dropItem(roomX, roomY, currentRoom, item));
|
double angle = ThreadLocalRandom.current().nextDouble(0, Math.PI * 2);
|
||||||
|
double radius = ThreadLocalRandom.current().nextDouble(0, DROP_ITEM_ON_GROUND_RADIUS);
|
||||||
|
int randomX = roomX + (int) (Math.cos(angle) * radius);
|
||||||
|
int randomY = roomY + (int) (Math.sin(angle) * radius);
|
||||||
|
RoomCords itemCords = new RoomCords(randomX, randomY);
|
||||||
|
DroppedItem droppedItem = new DroppedItem(currentRoom, itemCords, item);
|
||||||
|
currentRoom.getDroppedItems().add(droppedItem);
|
||||||
|
events.add(new DroppedItemRerender(droppedItem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventManager.emitEvent(events, this::afterKill);
|
eventManager.emitEvent(events, this::afterKill);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event dropItem(int x, int y, GameRoom currentRoom, GameItem item) {
|
|
||||||
double angle = ThreadLocalRandom.current().nextDouble(0, Math.PI * 2);
|
|
||||||
double radius = ThreadLocalRandom.current().nextDouble(0, DROP_ITEM_ON_GROUND_RADIUS);
|
|
||||||
int randomX = x + (int) (Math.cos(angle) * radius);
|
|
||||||
int randomY = y + (int) (Math.sin(angle) * radius);
|
|
||||||
RoomCords itemCords = new RoomCords(randomX, randomY);
|
|
||||||
DroppedItem droppedItem = new DroppedItem(currentRoom, itemCords, item);
|
|
||||||
currentRoom.getDroppedItems().add(droppedItem);
|
|
||||||
return new DroppedItemRerender(droppedItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class MobFollowingPlayerTask extends MobRoomTask {
|
|||||||
Player player = gameState.getPlayer();
|
Player player = gameState.getPlayer();
|
||||||
BufferedImage playerTexture = player.getTexture(resourceManager);
|
BufferedImage playerTexture = player.getTexture(resourceManager);
|
||||||
|
|
||||||
RerenderUtils.rerenderPart(forStartX, forEndX, forStartY, forEndY, startX, startY, gameState.getCurrentRoom(), room, player, screenBuffer, resourceManager, debugging, gameState.getOtherPlayers());
|
RerenderUtils.rerenderPart(forStartX, forEndX, forStartY, forEndY, startX, startY, gameState.getCurrentRoom(), room, player, playerTexture, screenBuffer, resourceManager, debugging);
|
||||||
|
|
||||||
eventManager.emitEvent(new Event[]{
|
eventManager.emitEvent(new Event[]{
|
||||||
new MouseMoveEvent(null),
|
new MouseMoveEvent(null),
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import cz.jzitnik.client.annotations.injectors.InjectConfig;
|
|||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
import cz.jzitnik.client.config.Debugging;
|
import cz.jzitnik.client.config.Debugging;
|
||||||
import cz.jzitnik.client.events.*;
|
import cz.jzitnik.client.events.InventoryRerender;
|
||||||
|
import cz.jzitnik.client.events.MouseAction;
|
||||||
|
import cz.jzitnik.client.events.RerenderPart;
|
||||||
|
import cz.jzitnik.client.events.RerenderScreen;
|
||||||
import cz.jzitnik.client.game.GameRoom;
|
import cz.jzitnik.client.game.GameRoom;
|
||||||
import cz.jzitnik.client.game.GameState;
|
import cz.jzitnik.client.game.GameState;
|
||||||
import cz.jzitnik.client.game.Player;
|
import cz.jzitnik.client.game.Player;
|
||||||
@@ -27,12 +30,9 @@ import cz.jzitnik.client.ui.pixels.Pixel;
|
|||||||
import cz.jzitnik.client.utils.RerenderUtils;
|
import cz.jzitnik.client.utils.RerenderUtils;
|
||||||
import cz.jzitnik.client.utils.UIRoomClickHandlerRepository;
|
import cz.jzitnik.client.utils.UIRoomClickHandlerRepository;
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.common.socket.messages.items.ItemTookFromChest;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -40,11 +40,8 @@ import java.util.List;
|
|||||||
public final class Chest extends GameObject implements UIClickHandler {
|
public final class Chest extends GameObject implements UIClickHandler {
|
||||||
private static final int RENDER_PADDING = 1;
|
private static final int RENDER_PADDING = 1;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final List<GameItem> items;
|
private final List<GameItem> items;
|
||||||
|
|
||||||
private boolean rendered;
|
|
||||||
|
|
||||||
private int listenerHashCode;
|
private int listenerHashCode;
|
||||||
|
|
||||||
private int actualDisplayStartX;
|
private int actualDisplayStartX;
|
||||||
@@ -104,6 +101,7 @@ public final class Chest extends GameObject implements UIClickHandler {
|
|||||||
Player player = gameState.getPlayer();
|
Player player = gameState.getPlayer();
|
||||||
|
|
||||||
BufferedImage roomTexture = resourceManager.getResource(currentRoom.getTexture());
|
BufferedImage roomTexture = resourceManager.getResource(currentRoom.getTexture());
|
||||||
|
BufferedImage playerTexture = player.getTexture(resourceManager);
|
||||||
BufferedImage chestTexture = getTexture();
|
BufferedImage chestTexture = getTexture();
|
||||||
|
|
||||||
var buffer = screenBuffer.getRenderedBuffer();
|
var buffer = screenBuffer.getRenderedBuffer();
|
||||||
@@ -143,7 +141,7 @@ public final class Chest extends GameObject implements UIClickHandler {
|
|||||||
renderMaxX = Math.max(renderMaxX, prevDisplayStartX + prevWidth);
|
renderMaxX = Math.max(renderMaxX, prevDisplayStartX + prevWidth);
|
||||||
|
|
||||||
clearPreviousUI(
|
clearPreviousUI(
|
||||||
currentRoom, roomTexture, player, resourceManager,
|
currentRoom, roomTexture, player, playerTexture,
|
||||||
buffer, overrideBuffer, start,
|
buffer, overrideBuffer, start,
|
||||||
guiStartY,
|
guiStartY,
|
||||||
prevGuiStartX,
|
prevGuiStartX,
|
||||||
@@ -167,14 +165,13 @@ public final class Chest extends GameObject implements UIClickHandler {
|
|||||||
guiStart.getRow() - start.getY(),
|
guiStart.getRow() - start.getY(),
|
||||||
guiEnd.getRow() - start.getY()
|
guiEnd.getRow() - start.getY()
|
||||||
));
|
));
|
||||||
rendered = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearPreviousUI(
|
private void clearPreviousUI(
|
||||||
GameRoom room,
|
GameRoom room,
|
||||||
BufferedImage roomTexture,
|
BufferedImage roomTexture,
|
||||||
Player player,
|
Player player,
|
||||||
ResourceManager resourceManager,
|
BufferedImage playerTexture,
|
||||||
Pixel[][] buffer,
|
Pixel[][] buffer,
|
||||||
Pixel[][] overrideBuffer,
|
Pixel[][] overrideBuffer,
|
||||||
RoomCords start,
|
RoomCords start,
|
||||||
@@ -191,11 +188,10 @@ public final class Chest extends GameObject implements UIClickHandler {
|
|||||||
null,
|
null,
|
||||||
new HashSet<>(),
|
new HashSet<>(),
|
||||||
player,
|
player,
|
||||||
resourceManager,
|
playerTexture,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
debugging,
|
debugging
|
||||||
gameState.getOtherPlayers()
|
|
||||||
).pixel();
|
).pixel();
|
||||||
|
|
||||||
buffer[y + start.getY()][x + start.getX()] = pixelToColored(pixel);
|
buffer[y + start.getY()][x + start.getX()] = pixelToColored(pixel);
|
||||||
@@ -261,23 +257,15 @@ public final class Chest extends GameObject implements UIClickHandler {
|
|||||||
if (!added) {
|
if (!added) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
eventManager.emitEvent(new InventoryRerender());
|
||||||
|
|
||||||
eventManager.emitEvent(new SendSocketMessageEvent(new ItemTookFromChest(gameState.getCurrentRoom().getId(), item.getId())));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleItemRemoval(GameItem item) {
|
|
||||||
items.remove(item);
|
items.remove(item);
|
||||||
|
|
||||||
if (!rendered) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
eventManager.emitEvent(new InventoryRerender());
|
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
uiRoomClickHandlerRepository.removeHandlerForCurrentRoom(listenerHashCode);
|
uiRoomClickHandlerRepository.removeHandlerForCurrentRoom(listenerHashCode);
|
||||||
}
|
}
|
||||||
render(true);
|
render(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,5 @@ public class GameSetup {
|
|||||||
);
|
);
|
||||||
|
|
||||||
gameState.setCurrentRoom(rooms.getFirst());
|
gameState.setCurrentRoom(rooms.getFirst());
|
||||||
gameState.setAllRooms(rooms);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package cz.jzitnik.client.game.setup.scenes;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.screens.DeathScreen;
|
|
||||||
import cz.jzitnik.client.screens.Screen;
|
|
||||||
import cz.jzitnik.client.screens.scenes.Scene;
|
|
||||||
|
|
||||||
public class DeathScene extends Scene {
|
|
||||||
public DeathScene() {
|
|
||||||
super(new Screen[]{new DeathScreen()}, new OnEndAction.Repeat());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package cz.jzitnik.client.game.setup.scenes;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.screens.WinScreen;
|
|
||||||
import cz.jzitnik.client.screens.Screen;
|
|
||||||
import cz.jzitnik.client.screens.scenes.Scene;
|
|
||||||
|
|
||||||
public class WinScene extends Scene {
|
|
||||||
public WinScene() {
|
|
||||||
super(new Screen[]{new WinScreen()}, new OnEndAction.Repeat());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package cz.jzitnik.client.game.setup.scenes.connect;
|
|||||||
|
|
||||||
import com.googlecode.lanterna.TerminalSize;
|
import com.googlecode.lanterna.TerminalSize;
|
||||||
import com.googlecode.lanterna.TextColor;
|
import com.googlecode.lanterna.TextColor;
|
||||||
import com.googlecode.lanterna.graphics.TextGraphics;
|
|
||||||
import com.googlecode.lanterna.input.KeyType;
|
import com.googlecode.lanterna.input.KeyType;
|
||||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
import com.googlecode.lanterna.screen.TerminalScreen;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
@@ -10,29 +9,23 @@ import cz.jzitnik.client.annotations.injectors.InjectState;
|
|||||||
import cz.jzitnik.client.events.KeyboardPressEvent;
|
import cz.jzitnik.client.events.KeyboardPressEvent;
|
||||||
import cz.jzitnik.client.events.MouseAction;
|
import cz.jzitnik.client.events.MouseAction;
|
||||||
import cz.jzitnik.client.events.SendSocketMessageEvent;
|
import cz.jzitnik.client.events.SendSocketMessageEvent;
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.screens.Screen;
|
import cz.jzitnik.client.screens.Screen;
|
||||||
import cz.jzitnik.client.screens.scenes.Scene;
|
import cz.jzitnik.client.screens.scenes.Scene;
|
||||||
import cz.jzitnik.client.socket.Client;
|
import cz.jzitnik.client.socket.Client;
|
||||||
import cz.jzitnik.client.sound.SoundPlayer;
|
import cz.jzitnik.client.sound.SoundPlayer;
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
import cz.jzitnik.client.states.TerminalState;
|
||||||
import cz.jzitnik.client.ui.Inventory;
|
|
||||||
import cz.jzitnik.client.ui.pixels.AlphaPixel;
|
import cz.jzitnik.client.ui.pixels.AlphaPixel;
|
||||||
import cz.jzitnik.client.ui.pixels.Empty;
|
import cz.jzitnik.client.ui.pixels.Empty;
|
||||||
import cz.jzitnik.client.ui.utils.Input;
|
import cz.jzitnik.client.ui.utils.Input;
|
||||||
import cz.jzitnik.client.utils.DependencyManager;
|
import cz.jzitnik.client.utils.DependencyManager;
|
||||||
import cz.jzitnik.client.utils.TextRenderer;
|
import cz.jzitnik.client.utils.TextRenderer;
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.common.socket.messages.game.connection.ConnectToAGame;
|
|
||||||
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
|
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
|
||||||
import jakarta.websocket.DeploymentException;
|
import jakarta.websocket.DeploymentException;
|
||||||
import cz.jzitnik.client.ui.utils.Button;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class ServerChoose extends Scene {
|
public class ServerChoose extends Scene {
|
||||||
public ServerChoose(DependencyManager dependencyManager) {
|
public ServerChoose(DependencyManager dependencyManager) {
|
||||||
GameMenuAudioScreen gameMenuScreen = new GameMenuAudioScreen();
|
GameMenuAudioScreen gameMenuScreen = new GameMenuAudioScreen();
|
||||||
@@ -85,12 +78,6 @@ public class ServerChoose extends Scene {
|
|||||||
@InjectDependency
|
@InjectDependency
|
||||||
private TextRenderer textRenderer;
|
private TextRenderer textRenderer;
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private DependencyManager dependencyManager;
|
|
||||||
|
|
||||||
private void renderInput(boolean refresh) {
|
private void renderInput(boolean refresh) {
|
||||||
var tg = terminalState.getTextGraphics();
|
var tg = terminalState.getTextGraphics();
|
||||||
TerminalScreen screen = terminalState.getTerminalScreen();
|
TerminalScreen screen = terminalState.getTerminalScreen();
|
||||||
@@ -149,12 +136,32 @@ public class ServerChoose extends Scene {
|
|||||||
|
|
||||||
AlphaPixel[][] selectServer = textRenderer.renderText("Enter server IP", terminalSize.getColumns(), 20, Color.WHITE, 15f, true);
|
AlphaPixel[][] selectServer = textRenderer.renderText("Enter server IP", terminalSize.getColumns(), 20, Color.WHITE, 15f, true);
|
||||||
|
|
||||||
render(selectServer, 0, 10, tg);
|
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);
|
renderInput(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.DELTA);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -171,10 +178,7 @@ public class ServerChoose extends Scene {
|
|||||||
connecting = true;
|
connecting = true;
|
||||||
client.connect(ipBuffer.toString());
|
client.connect(ipBuffer.toString());
|
||||||
|
|
||||||
Screen screen = new ActionSelector();
|
eventManager.emitEvent(new SendSocketMessageEvent(new CreateGame()));
|
||||||
dependencyManager.inject(screen);
|
|
||||||
gameState.setScreen(screen);
|
|
||||||
screen.fullRender();
|
|
||||||
} catch (DeploymentException | IOException e) {
|
} catch (DeploymentException | IOException e) {
|
||||||
connecting = false;
|
connecting = false;
|
||||||
}
|
}
|
||||||
@@ -191,7 +195,7 @@ public class ServerChoose extends Scene {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getKeyStroke().getKeyType() == KeyType.Character && !event.getKeyStroke().isCtrlDown()) {
|
if (event.getKeyStroke().getKeyType() == KeyType.Character) {
|
||||||
ipBuffer.append(event.getKeyStroke().getCharacter());
|
ipBuffer.append(event.getKeyStroke().getCharacter());
|
||||||
renderInput(true);
|
renderInput(true);
|
||||||
}
|
}
|
||||||
@@ -201,283 +205,4 @@ public class ServerChoose extends Scene {
|
|||||||
public void handleMouseAction(MouseAction event) {
|
public void handleMouseAction(MouseAction event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ActionSelector extends Screen {
|
|
||||||
@InjectDependency
|
|
||||||
private TextRenderer textRenderer;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
private int selectedIndex = -1;
|
|
||||||
|
|
||||||
@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[][] selectAction = textRenderer.renderText("Select action", terminalSize.getColumns(), 20, Color.WHITE, 15f, true);
|
|
||||||
|
|
||||||
render(selectAction, 0, 10, tg);
|
|
||||||
renderButtons();
|
|
||||||
|
|
||||||
try {
|
|
||||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int BUTTON_HEIGHT = 20;
|
|
||||||
private static final int BUTTON_WIDTH = 200;
|
|
||||||
private static final int BUTTON_GAP = 10;
|
|
||||||
private static final int BUTTON_COUNT = 2;
|
|
||||||
private static final int BUTTONS_HEIGHT = BUTTON_HEIGHT * BUTTON_COUNT + (BUTTON_COUNT - 1) * BUTTON_GAP;
|
|
||||||
|
|
||||||
private void renderButtons() {
|
|
||||||
var tg = terminalState.getTextGraphics();
|
|
||||||
TerminalSize terminalSize = terminalState.getTerminalScreen().getTerminalSize();
|
|
||||||
|
|
||||||
final int BUTTON_PAD_X = terminalSize.getColumns() / 2 - BUTTON_WIDTH / 2;
|
|
||||||
final int BUTTON_PAD_Y = terminalSize.getRows() - BUTTONS_HEIGHT / 2;
|
|
||||||
|
|
||||||
Button button = new Button(
|
|
||||||
Inventory.BORDER_COLOR,
|
|
||||||
Inventory.BACKGROUND_COLOR,
|
|
||||||
Inventory.BACKGROUND_COLOR_HOVERED,
|
|
||||||
Color.WHITE,
|
|
||||||
BUTTON_HEIGHT,
|
|
||||||
BUTTON_WIDTH,
|
|
||||||
1,
|
|
||||||
15f,
|
|
||||||
textRenderer
|
|
||||||
);
|
|
||||||
|
|
||||||
render(button.render("Create a world", selectedIndex == 0), BUTTON_PAD_X, BUTTON_PAD_Y, tg);
|
|
||||||
render(button.render("Connect to an existing world", selectedIndex == 1), BUTTON_PAD_X, BUTTON_PAD_Y + (BUTTON_HEIGHT + BUTTON_GAP), tg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseAction(MouseAction event) {
|
|
||||||
TerminalSize terminalSize = terminalState.getTerminalScreen().getTerminalSize();
|
|
||||||
|
|
||||||
final int BUTTON_START_X = terminalSize.getColumns() / 2 - BUTTON_WIDTH / 2;
|
|
||||||
final int BUTTON_START_Y = terminalSize.getRows() - BUTTONS_HEIGHT / 2;
|
|
||||||
final int BUTTON_END_X = BUTTON_START_X + BUTTON_WIDTH;
|
|
||||||
final int BUTTON_END_Y = BUTTON_START_Y + BUTTONS_HEIGHT;
|
|
||||||
|
|
||||||
final int TERMINAL_X = event.getPosition().getColumn();
|
|
||||||
final int TERMINAL_Y = event.getPosition().getRow() * 2;
|
|
||||||
|
|
||||||
final int SINGLE_BUTTON_HEIGHT = BUTTON_HEIGHT + BUTTON_GAP;
|
|
||||||
|
|
||||||
int index = (TERMINAL_Y - BUTTON_START_Y) / SINGLE_BUTTON_HEIGHT;
|
|
||||||
int rest = (TERMINAL_Y - BUTTON_START_Y) % SINGLE_BUTTON_HEIGHT;
|
|
||||||
|
|
||||||
if (!(TERMINAL_X >= BUTTON_START_X && TERMINAL_Y >= BUTTON_START_Y && TERMINAL_X < BUTTON_END_X && TERMINAL_Y < BUTTON_END_Y) || rest > BUTTON_HEIGHT) {
|
|
||||||
if (selectedIndex != -1) {
|
|
||||||
selectedIndex = -1;
|
|
||||||
renderButtons();
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event.getActionType()) {
|
|
||||||
case MOVE -> {
|
|
||||||
selectedIndex = index;
|
|
||||||
renderButtons();
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
case CLICK_RELEASE -> {
|
|
||||||
switch (index) {
|
|
||||||
case 0 -> eventManager.emitEvent(new SendSocketMessageEvent(new CreateGame()));
|
|
||||||
case 1 -> {
|
|
||||||
Screen screen = new ConnectWorld();
|
|
||||||
gameState.setScreen(screen);
|
|
||||||
screen.fullRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refresh() {
|
|
||||||
try {
|
|
||||||
terminalState.getTerminalScreen().refresh(com.googlecode.lanterna.screen.Screen.RefreshType.DELTA);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardAction(KeyboardPressEvent event) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static final class ConnectWorld extends Screen {
|
|
||||||
private final StringBuilder passBuffer = new StringBuilder();
|
|
||||||
private boolean connecting = false;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private TextRenderer textRenderer;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private DependencyManager dependencyManager;
|
|
||||||
|
|
||||||
private void renderInput(boolean refresh) {
|
|
||||||
var tg = terminalState.getTextGraphics();
|
|
||||||
TerminalScreen screen = terminalState.getTerminalScreen();
|
|
||||||
Input input = new Input(passBuffer.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 world password", terminalSize.getColumns(), 20, Color.WHITE, 15f, true);
|
|
||||||
|
|
||||||
render(selectServer, 0, 10, tg);
|
|
||||||
|
|
||||||
renderInput(false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardAction(KeyboardPressEvent event) {
|
|
||||||
if (connecting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getKeyStroke().getKeyType() == KeyType.Enter) {
|
|
||||||
connecting = true;
|
|
||||||
String pass = passBuffer.toString();
|
|
||||||
eventManager.emitEvent(new SendSocketMessageEvent(new ConnectToAGame(pass)));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getKeyStroke().getKeyType() == KeyType.Backspace) {
|
|
||||||
if (passBuffer.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
passBuffer.deleteCharAt(passBuffer.length() - 1);
|
|
||||||
renderInput(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getKeyStroke().getKeyType() == KeyType.Character && !event.getKeyStroke().isCtrlDown()) {
|
|
||||||
passBuffer.append(event.getKeyStroke().getCharacter());
|
|
||||||
renderInput(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseAction(MouseAction event) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void render(AlphaPixel[][] buffer, int padX, int padY, TextGraphics tg) {
|
|
||||||
for (int y = 0; y < buffer.length; y += 2) {
|
|
||||||
for (int x = 0; x < buffer[y].length; x++) {
|
|
||||||
AlphaPixel topPixel = buffer[y][x];
|
|
||||||
|
|
||||||
AlphaPixel bottomPixel;
|
|
||||||
if (y + 1 < buffer.length) {
|
|
||||||
bottomPixel = buffer[y + 1][x];
|
|
||||||
} else {
|
|
||||||
bottomPixel = new Empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
int termX = padX + 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, '▄');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package cz.jzitnik.client.screens;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.SGR;
|
|
||||||
import com.googlecode.lanterna.TextColor;
|
|
||||||
import com.googlecode.lanterna.graphics.TextGraphics;
|
|
||||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
|
||||||
import cz.jzitnik.client.events.KeyboardPressEvent;
|
|
||||||
import cz.jzitnik.client.events.MouseAction;
|
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class DeathScreen extends Screen {
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fullRender() {
|
|
||||||
TerminalScreen screen = terminalState.getTerminalScreen();
|
|
||||||
screen.clear();
|
|
||||||
TextGraphics tg = terminalState.getTextGraphics();
|
|
||||||
|
|
||||||
int termWidth = screen.getTerminalSize().getColumns();
|
|
||||||
int termHeight = screen.getTerminalSize().getRows();
|
|
||||||
|
|
||||||
String message = "GAME OVER";
|
|
||||||
tg.setForegroundColor(TextColor.ANSI.RED);
|
|
||||||
tg.enableModifiers(SGR.BOLD);
|
|
||||||
tg.putString((termWidth - message.length()) / 2, termHeight / 2, message);
|
|
||||||
|
|
||||||
try {
|
|
||||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseAction(MouseAction event) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardAction(KeyboardPressEvent event) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package cz.jzitnik.client.screens;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.SGR;
|
|
||||||
import com.googlecode.lanterna.TextColor;
|
|
||||||
import com.googlecode.lanterna.graphics.TextGraphics;
|
|
||||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
|
||||||
import cz.jzitnik.client.events.KeyboardPressEvent;
|
|
||||||
import cz.jzitnik.client.events.MouseAction;
|
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class WinScreen extends Screen {
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fullRender() {
|
|
||||||
TerminalScreen screen = terminalState.getTerminalScreen();
|
|
||||||
screen.clear();
|
|
||||||
TextGraphics tg = terminalState.getTextGraphics();
|
|
||||||
|
|
||||||
int termWidth = screen.getTerminalSize().getColumns();
|
|
||||||
int termHeight = screen.getTerminalSize().getRows();
|
|
||||||
|
|
||||||
String message = "YOU WON!";
|
|
||||||
tg.setForegroundColor(TextColor.ANSI.GREEN);
|
|
||||||
tg.enableModifiers(SGR.BOLD);
|
|
||||||
tg.putString((termWidth - message.length()) / 2, termHeight / 2, message);
|
|
||||||
|
|
||||||
try {
|
|
||||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseAction(MouseAction event) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardAction(KeyboardPressEvent event) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
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.TerminalResizeEvent;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.OtherPlayer;
|
|
||||||
import cz.jzitnik.client.game.Player;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
|
||||||
import cz.jzitnik.common.socket.messages.game.connection.ConnectToAGameResponse;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(ConnectToAGameResponse.class)
|
|
||||||
public class ConnectGameHandler extends AbstractSocketEventHandler<ConnectToAGameResponse> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(ConnectToAGameResponse event) {
|
|
||||||
if (!event.success()) {
|
|
||||||
log.debug("Error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gameState.setPlayer(new Player(event.playerCreation()));
|
|
||||||
gameState.getAllOtherPlayers().addAll(event.existingPlayers().stream().map(OtherPlayer::new).toList());
|
|
||||||
gameState.setScreen(null);
|
|
||||||
eventManager.emitEvent(new TerminalResizeEvent(terminalState.getTerminalScreen().getTerminalSize()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,30 +3,24 @@ package cz.jzitnik.client.socket.events;
|
|||||||
import cz.jzitnik.client.annotations.SocketEventHandler;
|
import cz.jzitnik.client.annotations.SocketEventHandler;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
import cz.jzitnik.client.events.TerminalResizeEvent;
|
import cz.jzitnik.client.events.FullRoomDraw;
|
||||||
import cz.jzitnik.client.game.GameState;
|
import cz.jzitnik.client.game.GameState;
|
||||||
import cz.jzitnik.client.game.Player;
|
import cz.jzitnik.client.game.Player;
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.common.socket.messages.game.creation.CreateGameResponse;
|
import cz.jzitnik.common.socket.messages.game.creation.CreateGameResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(CreateGameResponse.class)
|
@SocketEventHandler(CreateGameResponse.class)
|
||||||
public class CreateGameHandler extends AbstractSocketEventHandler<CreateGameResponse> {
|
public class CreateGameHandler extends AbstractSocketEventHandler<CreateGameResponse> {
|
||||||
@InjectState
|
@InjectState
|
||||||
private GameState gameState;
|
private GameState gameState;
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
@InjectDependency
|
@InjectDependency
|
||||||
private EventManager eventManager;
|
private EventManager eventManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(CreateGameResponse event) {
|
public void handle(CreateGameResponse event) {
|
||||||
log.debug("Game code: {}", event.getGamePassword());
|
|
||||||
gameState.setPlayer(new Player(event.getOwnerPlayer()));
|
gameState.setPlayer(new Player(event.getOwnerPlayer()));
|
||||||
gameState.setScreen(null);
|
gameState.setScreen(null);
|
||||||
eventManager.emitEvent(new TerminalResizeEvent(terminalState.getTerminalScreen().getTerminalSize()));
|
eventManager.emitEvent(new FullRoomDraw());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
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.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.setup.scenes.WinScene;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.common.socket.messages.game.GameWin;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(GameWin.class)
|
|
||||||
public class GameWinHandler extends AbstractSocketEventHandler<GameWin> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler roomTaskScheduler;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(GameWin event) {
|
|
||||||
log.debug("Game won!");
|
|
||||||
roomTaskScheduler.finalShutdown();
|
|
||||||
WinScene winScene = new WinScene();
|
|
||||||
gameState.setScreen(winScene);
|
|
||||||
try {
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
winScene.fullRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package cz.jzitnik.client.socket.events;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.annotations.SocketEventHandler;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
|
||||||
import cz.jzitnik.client.game.GameRoom;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.items.GameItem;
|
|
||||||
import cz.jzitnik.client.game.objects.Chest;
|
|
||||||
import cz.jzitnik.client.game.objects.GameObject;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.common.socket.messages.items.ItemTookFromChest;
|
|
||||||
|
|
||||||
@SocketEventHandler(ItemTookFromChest.class)
|
|
||||||
public class ItemTookFromChestHandler extends AbstractSocketEventHandler<ItemTookFromChest> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(ItemTookFromChest event) {
|
|
||||||
for (GameRoom room : gameState.getAllRooms()) {
|
|
||||||
if (!room.getId().equals(event.roomId())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (GameObject object : room.getObjects()) {
|
|
||||||
if (object instanceof Chest chest) {
|
|
||||||
var items = chest.getItems();
|
|
||||||
|
|
||||||
for (GameItem item : items) {
|
|
||||||
if (item.getId() != event.id()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
items.remove(item);
|
|
||||||
chest.handleItemRemoval(item);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
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.OtherPlayer;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
|
||||||
import cz.jzitnik.common.socket.messages.room.MovePlayerRoomResponse;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@SocketEventHandler(MovePlayerRoomResponse.class)
|
|
||||||
public class MovePlayerRoomResponseHandler extends AbstractSocketEventHandler<MovePlayerRoomResponse> {
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MovePlayerRoomResponse event) {
|
|
||||||
Set<Integer> ids = event.getIds();
|
|
||||||
|
|
||||||
for (OtherPlayer player : gameState.getAllOtherPlayers()) {
|
|
||||||
player.setVisible(ids.contains(player.getId()));
|
|
||||||
var playerRegistryOptional = event.getById(player.getId());
|
|
||||||
if (player.isVisible() && playerRegistryOptional.isPresent()) {
|
|
||||||
player.getPlayerCords().updateCords(playerRegistryOptional.get().cords());
|
|
||||||
player.setPlayerRotation(playerRegistryOptional.get().playerRotation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventManager.emitEvent(new FullRoomDraw());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package cz.jzitnik.client.socket.events;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.TerminalPosition;
|
|
||||||
import cz.jzitnik.client.annotations.SocketEventHandler;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectConfig;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
|
||||||
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.GameRoom;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.OtherPlayer;
|
|
||||||
import cz.jzitnik.client.game.ResourceManager;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.client.states.ScreenBuffer;
|
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
|
||||||
import cz.jzitnik.client.ui.Stats;
|
|
||||||
import cz.jzitnik.client.utils.RerenderUtils;
|
|
||||||
import cz.jzitnik.client.utils.events.Event;
|
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerArrivalChange;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(PlayerArrivalChange.class)
|
|
||||||
public class PlayerArrivalChangeHandler extends AbstractSocketEventHandler<PlayerArrivalChange> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private ResourceManager resourceManager;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private ScreenBuffer screenBuffer;
|
|
||||||
|
|
||||||
@InjectConfig
|
|
||||||
private Debugging debugging;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerArrivalChange event) {
|
|
||||||
log.debug("Player appear change: {}", event.id());
|
|
||||||
OtherPlayer otherPlayer = gameState.getAllOtherPlayers().stream().filter(otherPlayer1 -> otherPlayer1.getId() == event.id()).findFirst().get();
|
|
||||||
otherPlayer.setVisible(event.arrived());
|
|
||||||
otherPlayer.getPlayerCords().updateCords(event.playerCords());
|
|
||||||
otherPlayer.setPlayerRotation(event.playerRotation());
|
|
||||||
|
|
||||||
GameRoom currentRoom = gameState.getCurrentRoom();
|
|
||||||
BufferedImage playerTexture = otherPlayer.getTexture(resourceManager);
|
|
||||||
BufferedImage room = resourceManager.getResource(currentRoom.getTexture());
|
|
||||||
|
|
||||||
int forStartX = event.playerCords().getX();
|
|
||||||
int forStartY = event.playerCords().getY();
|
|
||||||
int forEndX = forStartX + playerTexture.getWidth();
|
|
||||||
int forEndY = forStartY + playerTexture.getHeight();
|
|
||||||
|
|
||||||
var start = RerenderUtils.getStart(room, terminalState.getTerminalScreen().getTerminalSize());
|
|
||||||
int startX = start.getX();
|
|
||||||
int startY = start.getY();
|
|
||||||
|
|
||||||
RerenderUtils.rerenderPart(forStartX, forEndX, forStartY, forEndY, startX, startY, currentRoom, room, gameState.getPlayer(), screenBuffer, resourceManager, debugging, gameState.getOtherPlayers());
|
|
||||||
|
|
||||||
eventManager.emitEvent(new Event[]{
|
|
||||||
new MouseMoveEvent(null),
|
|
||||||
new RerenderScreen(
|
|
||||||
new RerenderScreen.ScreenPart[]{
|
|
||||||
new RerenderScreen.ScreenPart(
|
|
||||||
new TerminalPosition(forStartX + startX, forStartY + startY),
|
|
||||||
new TerminalPosition(forEndX + 1 + startX, forEndY + startY)
|
|
||||||
),
|
|
||||||
new RerenderScreen.ScreenPart(
|
|
||||||
new TerminalPosition(Stats.OFFSET_X, Stats.OFFSET_X),
|
|
||||||
new TerminalPosition(Stats.OFFSET_X + Stats.WIDTH, Stats.OFFSET_Y + Stats.HEIGHT)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
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.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.setup.scenes.DeathScene;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.client.utils.DependencyManager;
|
|
||||||
import cz.jzitnik.common.socket.messages.game.PlayerDeath;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(PlayerDeath.class)
|
|
||||||
public class PlayerDeathHandler extends AbstractSocketEventHandler<PlayerDeath> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private DependencyManager dependencyManager;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler roomTaskScheduler;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerDeath event) {
|
|
||||||
log.debug("Player death: {}", event.playerId());
|
|
||||||
roomTaskScheduler.finalShutdown();
|
|
||||||
DeathScene deathScene = new DeathScene();
|
|
||||||
dependencyManager.inject(deathScene);
|
|
||||||
gameState.setScreen(deathScene);
|
|
||||||
deathScene.fullRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package cz.jzitnik.client.socket.events;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.annotations.SocketEventHandler;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerDisconnected;
|
|
||||||
|
|
||||||
@SocketEventHandler(PlayerDisconnected.class)
|
|
||||||
public class PlayerDisconnectedHandler extends AbstractSocketEventHandler<PlayerDisconnected> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerDisconnected event) {
|
|
||||||
gameState.getAllOtherPlayers().removeIf(player -> player.getId() == event.playerId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package cz.jzitnik.client.socket.events;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.annotations.SocketEventHandler;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.OtherPlayer;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerJoined;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(PlayerJoined.class)
|
|
||||||
public class PlayerJoinedHandler extends AbstractSocketEventHandler<PlayerJoined> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerJoined event) {
|
|
||||||
log.debug("Player joined: {}", event.playerCreation().getId());
|
|
||||||
gameState.getAllOtherPlayers().add(new OtherPlayer(event.playerCreation()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
package cz.jzitnik.client.socket.events;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.TerminalPosition;
|
|
||||||
import cz.jzitnik.client.annotations.SocketEventHandler;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectConfig;
|
|
||||||
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
|
||||||
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.GameRoom;
|
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.OtherPlayer;
|
|
||||||
import cz.jzitnik.client.game.ResourceManager;
|
|
||||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
|
||||||
import cz.jzitnik.client.states.ScreenBuffer;
|
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
|
||||||
import cz.jzitnik.client.ui.Stats;
|
|
||||||
import cz.jzitnik.client.utils.RerenderUtils;
|
|
||||||
import cz.jzitnik.client.utils.events.Event;
|
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerMovedInUrRoom;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@SocketEventHandler(PlayerMovedInUrRoom.class)
|
|
||||||
public class PlayerMovedInUrRoomHandler extends AbstractSocketEventHandler<PlayerMovedInUrRoom> {
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private ResourceManager resourceManager;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private ScreenBuffer screenBuffer;
|
|
||||||
|
|
||||||
@InjectConfig
|
|
||||||
private Debugging debugging;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private TerminalState terminalState;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerMovedInUrRoom event) {
|
|
||||||
log.debug("Player moved: {}", event.getPlayerId());
|
|
||||||
OtherPlayer otherPlayer = gameState.getAllOtherPlayers().stream().filter(otherPlayer1 -> otherPlayer1.getId() == event.getPlayerId()).findFirst().get();
|
|
||||||
otherPlayer.setPlayerRotation(event.getPlayerRotation());
|
|
||||||
|
|
||||||
var oldCords = otherPlayer.getPlayerCords();
|
|
||||||
var newCords = event.getCords();
|
|
||||||
|
|
||||||
GameRoom currentRoom = gameState.getCurrentRoom();
|
|
||||||
BufferedImage playerTexture = otherPlayer.getTexture(resourceManager);
|
|
||||||
BufferedImage room = resourceManager.getResource(currentRoom.getTexture());
|
|
||||||
int originalPlayerX = oldCords.getX();
|
|
||||||
int originalPlayerY = oldCords.getY();
|
|
||||||
int newPlayerX = newCords.getX();
|
|
||||||
int newPlayerY = newCords.getY();
|
|
||||||
|
|
||||||
int forStartX = Math.min(originalPlayerX, newPlayerX);
|
|
||||||
int forStartY = Math.min(originalPlayerY, newPlayerY);
|
|
||||||
int forEndX = Math.max(originalPlayerX, newPlayerX) + playerTexture.getWidth();
|
|
||||||
int forEndY = Math.max(originalPlayerY, newPlayerY) + playerTexture.getHeight();
|
|
||||||
|
|
||||||
var start = RerenderUtils.getStart(room, terminalState.getTerminalScreen().getTerminalSize());
|
|
||||||
int startX = start.getX();
|
|
||||||
int startY = start.getY();
|
|
||||||
|
|
||||||
otherPlayer.getPlayerCords().updateCords(newCords);
|
|
||||||
|
|
||||||
RerenderUtils.rerenderPart(forStartX, forEndX, forStartY, forEndY, startX, startY, currentRoom, room, gameState.getPlayer(), screenBuffer, resourceManager, debugging, gameState.getOtherPlayers());
|
|
||||||
|
|
||||||
eventManager.emitEvent(new Event[]{
|
|
||||||
new MouseMoveEvent(null),
|
|
||||||
new RerenderScreen(
|
|
||||||
new RerenderScreen.ScreenPart[]{
|
|
||||||
new RerenderScreen.ScreenPart(
|
|
||||||
new TerminalPosition(forStartX + startX, forStartY + startY),
|
|
||||||
new TerminalPosition(forEndX + 1 + startX, forEndY + startY)
|
|
||||||
),
|
|
||||||
new RerenderScreen.ScreenPart(
|
|
||||||
new TerminalPosition(Stats.OFFSET_X, Stats.OFFSET_X),
|
|
||||||
new TerminalPosition(Stats.OFFSET_X + Stats.WIDTH, Stats.OFFSET_Y + Stats.HEIGHT)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,6 @@ import cz.jzitnik.client.annotations.ui.UI;
|
|||||||
import cz.jzitnik.client.events.MouseAction;
|
import cz.jzitnik.client.events.MouseAction;
|
||||||
import cz.jzitnik.client.events.RerenderScreen;
|
import cz.jzitnik.client.events.RerenderScreen;
|
||||||
import cz.jzitnik.client.events.handlers.DialogEventHandler;
|
import cz.jzitnik.client.events.handlers.DialogEventHandler;
|
||||||
import cz.jzitnik.client.game.GameState;
|
|
||||||
import cz.jzitnik.client.game.dialog.OnEnd;
|
import cz.jzitnik.client.game.dialog.OnEnd;
|
||||||
import cz.jzitnik.client.states.DialogState;
|
import cz.jzitnik.client.states.DialogState;
|
||||||
import cz.jzitnik.client.states.ScreenBuffer;
|
import cz.jzitnik.client.states.ScreenBuffer;
|
||||||
@@ -28,57 +27,42 @@ import static cz.jzitnik.client.events.handlers.DialogEventHandler.*;
|
|||||||
@UI
|
@UI
|
||||||
@Dependency
|
@Dependency
|
||||||
public class DialogUI {
|
public class DialogUI {
|
||||||
|
|
||||||
@InjectState
|
@InjectState
|
||||||
private DialogState dialogState;
|
private DialogState dialogState;
|
||||||
|
|
||||||
@InjectState
|
@InjectState
|
||||||
private TerminalState terminalState;
|
private TerminalState terminalState;
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private ScreenBuffer screenBuffer;
|
|
||||||
|
|
||||||
@InjectState
|
|
||||||
private GameState gameState;
|
|
||||||
|
|
||||||
@InjectDependency
|
@InjectDependency
|
||||||
private TextRenderer textRenderer;
|
private TextRenderer textRenderer;
|
||||||
|
|
||||||
@InjectDependency
|
@InjectDependency
|
||||||
private EventManager eventManager;
|
private EventManager eventManager;
|
||||||
|
|
||||||
|
@InjectState
|
||||||
|
private ScreenBuffer screenBuffer;
|
||||||
|
|
||||||
@MouseHandler(MouseHandlerType.CLICK)
|
@MouseHandler(MouseHandlerType.CLICK)
|
||||||
public boolean handleClick(MouseAction mouseAction) {
|
public boolean handleClick(MouseAction mouseAction) {
|
||||||
if (dialogState.getCurrentDialog() == null || dialogState.isRenderInProgress()) {
|
if (dialogState.getCurrentDialog() == null || dialogState.isRenderInProgress()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dialog = dialogState.getCurrentDialog();
|
TerminalSize size = DialogEventHandler.getSize(textRenderer, dialogState.getCurrentDialog());
|
||||||
TerminalSize size = DialogEventHandler.getSize(textRenderer, dialog, gameState);
|
TerminalPosition start = DialogEventHandler.getStart(terminalState.getTerminalScreen().getTerminalSize(), size);
|
||||||
TerminalPosition start = DialogEventHandler.getStart(
|
|
||||||
terminalState.getTerminalScreen().getTerminalSize(),
|
|
||||||
size
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!(dialog.getOnEnd() instanceof OnEnd.AskQuestion askQuestion)) {
|
if (!(dialogState.getCurrentDialog().getOnEnd() instanceof OnEnd.AskQuestion(
|
||||||
|
OnEnd.AskQuestion.Answer[] answers
|
||||||
|
))) {
|
||||||
setHoveredButtonIndex(-1);
|
setHoveredButtonIndex(-1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var answers = askQuestion.answers(gameState);
|
|
||||||
|
|
||||||
TerminalPosition mouse = mouseAction.getPosition();
|
TerminalPosition mouse = mouseAction.getPosition();
|
||||||
TerminalPosition mouseNormalized = new TerminalPosition(
|
TerminalPosition mouseNormalized = new TerminalPosition(mouse.getColumn(), mouse.getRow() * 2);
|
||||||
mouse.getColumn(),
|
|
||||||
mouse.getRow() * 2
|
|
||||||
);
|
|
||||||
|
|
||||||
RerenderScreen.ScreenPart part = new RerenderScreen.ScreenPart(
|
RerenderScreen.ScreenPart part = new RerenderScreen.ScreenPart(
|
||||||
start,
|
start,
|
||||||
new TerminalPosition(
|
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
|
||||||
start.getColumn() + size.getColumns(),
|
|
||||||
start.getRow() + size.getRows()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!part.isWithin(mouseNormalized)) {
|
if (!part.isWithin(mouseNormalized)) {
|
||||||
@@ -86,13 +70,9 @@ public class DialogUI {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int buttonsStartY = DialogEventHandler.getYStartButtons(textRenderer, dialog);
|
int buttonsStartY = DialogEventHandler.getYStartButtons(textRenderer, dialogState.getCurrentDialog());
|
||||||
TerminalPosition localPosition = new TerminalPosition(
|
TerminalPosition localPosition = new TerminalPosition(mouseNormalized.getColumn() - start.getColumn(), mouseNormalized.getRow() - start.getRow() - buttonsStartY);
|
||||||
mouseNormalized.getColumn() - start.getColumn(),
|
int buttonsHeight = DialogEventHandler.calculateButtonHeight(dialogState.getCurrentDialog());
|
||||||
mouseNormalized.getRow() - start.getRow() - buttonsStartY
|
|
||||||
);
|
|
||||||
|
|
||||||
int buttonsHeight = DialogEventHandler.calculateButtonHeight(dialog, gameState);
|
|
||||||
|
|
||||||
if (localPosition.getRow() < 0 || localPosition.getRow() >= buttonsHeight) {
|
if (localPosition.getRow() < 0 || localPosition.getRow() >= buttonsHeight) {
|
||||||
setHoveredButtonIndex(-1);
|
setHoveredButtonIndex(-1);
|
||||||
@@ -102,27 +82,23 @@ public class DialogUI {
|
|||||||
int buttonIndex = localPosition.getRow() / (BUTTON_HEIGHT + BUTTON_PADDING);
|
int buttonIndex = localPosition.getRow() / (BUTTON_HEIGHT + BUTTON_PADDING);
|
||||||
int rest = localPosition.getRow() % (BUTTON_HEIGHT + BUTTON_PADDING);
|
int rest = localPosition.getRow() % (BUTTON_HEIGHT + BUTTON_PADDING);
|
||||||
|
|
||||||
if (buttonIndex < answers.length
|
if (buttonIndex < answers.length && rest < BUTTON_HEIGHT && localPosition.getColumn() >= PADDING && localPosition.getColumn() < size.getColumns() - PADDING) {
|
||||||
&& rest < BUTTON_HEIGHT
|
for (int y = start.getRow(); y < start.getRow() + size.getRows(); y++) {
|
||||||
&& localPosition.getColumn() >= PADDING
|
for (int x = start.getColumn(); x < start.getColumn() + size.getColumns(); x++) {
|
||||||
&& localPosition.getColumn() < size.getColumns() - PADDING) {
|
screenBuffer.getGlobalOverrideBuffer()[y][x] = new Empty();
|
||||||
|
}
|
||||||
clearDialog(start, size);
|
}
|
||||||
|
|
||||||
eventManager.emitEvent(
|
eventManager.emitEvent(
|
||||||
new Event[]{
|
new Event[]{
|
||||||
new RerenderScreen(
|
new RerenderScreen(
|
||||||
new RerenderScreen.ScreenPart(
|
new RerenderScreen.ScreenPart(
|
||||||
start,
|
start,
|
||||||
new TerminalPosition(
|
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
|
||||||
start.getColumn() + size.getColumns(),
|
|
||||||
start.getRow() + size.getRows()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
answers[buttonIndex].dialog()
|
answers[buttonIndex].dialog(),
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -136,32 +112,21 @@ public class DialogUI {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dialog = dialogState.getCurrentDialog();
|
TerminalSize size = DialogEventHandler.getSize(textRenderer, dialogState.getCurrentDialog());
|
||||||
TerminalSize size = DialogEventHandler.getSize(textRenderer, dialog, gameState);
|
TerminalPosition start = DialogEventHandler.getStart(terminalState.getTerminalScreen().getTerminalSize(), size);
|
||||||
TerminalPosition start = DialogEventHandler.getStart(
|
|
||||||
terminalState.getTerminalScreen().getTerminalSize(),
|
|
||||||
size
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!(dialog.getOnEnd() instanceof OnEnd.AskQuestion askQuestion)) {
|
if (!(dialogState.getCurrentDialog().getOnEnd() instanceof OnEnd.AskQuestion(
|
||||||
|
OnEnd.AskQuestion.Answer[] answers
|
||||||
|
))) {
|
||||||
setHoveredButtonIndex(-1);
|
setHoveredButtonIndex(-1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var answers = askQuestion.answers(gameState);
|
|
||||||
|
|
||||||
TerminalPosition mouse = mouseAction.getPosition();
|
TerminalPosition mouse = mouseAction.getPosition();
|
||||||
TerminalPosition mouseNormalized = new TerminalPosition(
|
TerminalPosition mouseNormalized = new TerminalPosition(mouse.getColumn(), mouse.getRow() * 2);
|
||||||
mouse.getColumn(),
|
|
||||||
mouse.getRow() * 2
|
|
||||||
);
|
|
||||||
|
|
||||||
RerenderScreen.ScreenPart part = new RerenderScreen.ScreenPart(
|
RerenderScreen.ScreenPart part = new RerenderScreen.ScreenPart(
|
||||||
start,
|
start,
|
||||||
new TerminalPosition(
|
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
|
||||||
start.getColumn() + size.getColumns(),
|
|
||||||
start.getRow() + size.getRows()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!part.isWithin(mouseNormalized)) {
|
if (!part.isWithin(mouseNormalized)) {
|
||||||
@@ -169,13 +134,9 @@ public class DialogUI {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int buttonsStartY = DialogEventHandler.getYStartButtons(textRenderer, dialog);
|
int buttonsStartY = DialogEventHandler.getYStartButtons(textRenderer, dialogState.getCurrentDialog());
|
||||||
TerminalPosition localPosition = new TerminalPosition(
|
TerminalPosition localPosition = new TerminalPosition(mouseNormalized.getColumn() - start.getColumn(), mouseNormalized.getRow() - start.getRow() - buttonsStartY);
|
||||||
mouseNormalized.getColumn() - start.getColumn(),
|
int buttonsHeight = DialogEventHandler.calculateButtonHeight(dialogState.getCurrentDialog());
|
||||||
mouseNormalized.getRow() - start.getRow() - buttonsStartY
|
|
||||||
);
|
|
||||||
|
|
||||||
int buttonsHeight = DialogEventHandler.calculateButtonHeight(dialog, gameState);
|
|
||||||
|
|
||||||
if (localPosition.getRow() < 0 || localPosition.getRow() >= buttonsHeight) {
|
if (localPosition.getRow() < 0 || localPosition.getRow() >= buttonsHeight) {
|
||||||
setHoveredButtonIndex(-1);
|
setHoveredButtonIndex(-1);
|
||||||
@@ -185,11 +146,7 @@ public class DialogUI {
|
|||||||
int buttonIndex = localPosition.getRow() / (BUTTON_HEIGHT + BUTTON_PADDING);
|
int buttonIndex = localPosition.getRow() / (BUTTON_HEIGHT + BUTTON_PADDING);
|
||||||
int rest = localPosition.getRow() % (BUTTON_HEIGHT + BUTTON_PADDING);
|
int rest = localPosition.getRow() % (BUTTON_HEIGHT + BUTTON_PADDING);
|
||||||
|
|
||||||
if (buttonIndex < answers.length
|
if (buttonIndex < answers.length && rest < BUTTON_HEIGHT && localPosition.getColumn() >= PADDING && localPosition.getColumn() < size.getColumns() - PADDING) {
|
||||||
&& rest < BUTTON_HEIGHT
|
|
||||||
&& localPosition.getColumn() >= PADDING
|
|
||||||
&& localPosition.getColumn() < size.getColumns() - PADDING) {
|
|
||||||
|
|
||||||
setHoveredButtonIndex(buttonIndex);
|
setHoveredButtonIndex(buttonIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -204,12 +161,4 @@ public class DialogUI {
|
|||||||
eventManager.emitEvent(dialogState.getCurrentDialog());
|
eventManager.emitEvent(dialogState.getCurrentDialog());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearDialog(TerminalPosition start, TerminalSize size) {
|
|
||||||
for (int y = start.getRow(); y < start.getRow() + size.getRows(); y++) {
|
|
||||||
for (int x = start.getColumn(); x < start.getColumn() + size.getColumns(); x++) {
|
|
||||||
screenBuffer.getGlobalOverrideBuffer()[y][x] = new Empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import cz.jzitnik.client.game.ResourceManager;
|
|||||||
import cz.jzitnik.client.game.items.GameItem;
|
import cz.jzitnik.client.game.items.GameItem;
|
||||||
import cz.jzitnik.client.game.items.types.InteractableItem;
|
import cz.jzitnik.client.game.items.types.InteractableItem;
|
||||||
import cz.jzitnik.client.game.objects.DroppedItem;
|
import cz.jzitnik.client.game.objects.DroppedItem;
|
||||||
import cz.jzitnik.client.ui.pixels.AlphaPixel;
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
import cz.jzitnik.common.models.coordinates.RoomCords;
|
||||||
import cz.jzitnik.client.states.ScreenBuffer;
|
import cz.jzitnik.client.states.ScreenBuffer;
|
||||||
import cz.jzitnik.client.states.TerminalState;
|
import cz.jzitnik.client.states.TerminalState;
|
||||||
@@ -51,17 +50,17 @@ public class Inventory {
|
|||||||
private static final int INNER_BORDER_WIDTH = 1;
|
private static final int INNER_BORDER_WIDTH = 1;
|
||||||
private static final int ITEM_SIZE = 16; // Characters
|
private static final int ITEM_SIZE = 16; // Characters
|
||||||
private static final int ITEM_PADDING = 2; // padding on each side
|
private static final int ITEM_PADDING = 2; // padding on each side
|
||||||
public static final AlphaPixel BORDER_COLOR =
|
public static final Pixel BORDER_COLOR =
|
||||||
new ColoredPixel(new TextColor.RGB(41, 29, 19));
|
new ColoredPixel(new TextColor.RGB(41, 29, 19));
|
||||||
public static final AlphaPixel BACKGROUND_COLOR =
|
public static final Pixel BACKGROUND_COLOR =
|
||||||
new ColoredPixel(new TextColor.RGB(61, 45, 29));
|
new ColoredPixel(new TextColor.RGB(61, 45, 29));
|
||||||
public static final AlphaPixel BACKGROUND_COLOR_HOVERED =
|
private static final Pixel BACKGROUND_COLOR_HOVERED =
|
||||||
new ColoredPixel(new TextColor.RGB(77, 56, 36));
|
new ColoredPixel(new TextColor.RGB(77, 56, 36));
|
||||||
private static final AlphaPixel BACKGROUND_COLOR_SELECTED =
|
private static final Pixel BACKGROUND_COLOR_SELECTED =
|
||||||
new ColoredPixel(new TextColor.RGB(95, 62, 32));
|
new ColoredPixel(new TextColor.RGB(95, 62, 32));
|
||||||
private static final AlphaPixel BACKGROUND_COLOR_EQUIPPED =
|
private static final Pixel BACKGROUND_COLOR_EQUIPPED =
|
||||||
new ColoredPixel(new TextColor.RGB(50, 145, 150));
|
new ColoredPixel(new TextColor.RGB(50, 145, 150));
|
||||||
private static final AlphaPixel BACKGROUND_COLOR_EQUIPPED_SELECTED =
|
private static final Pixel BACKGROUND_COLOR_EQUIPPED_SELECTED =
|
||||||
new ColoredPixel(new TextColor.RGB(58, 170, 176));
|
new ColoredPixel(new TextColor.RGB(58, 170, 176));
|
||||||
private static final int ITEM_SLOT_SIZE = ITEM_SIZE + ITEM_PADDING * 2;
|
private static final int ITEM_SLOT_SIZE = ITEM_SIZE + ITEM_PADDING * 2;
|
||||||
public static final int INVENTORY_WIDTH =
|
public static final int INVENTORY_WIDTH =
|
||||||
|
|||||||
@@ -10,8 +10,4 @@ public sealed abstract class AlphaPixel extends Pixel permits Empty, ColoredPixe
|
|||||||
super(color);
|
super(color);
|
||||||
this.alpha = alpha;
|
this.alpha = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTransparent() {
|
|
||||||
return alpha == 0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
package cz.jzitnik.client.ui.utils;
|
|
||||||
|
|
||||||
import cz.jzitnik.client.ui.pixels.AlphaPixel;
|
|
||||||
import cz.jzitnik.client.utils.TextRenderer;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public record Button(
|
|
||||||
AlphaPixel borderColor,
|
|
||||||
AlphaPixel backgroundColor,
|
|
||||||
AlphaPixel backgroundSelectedColor,
|
|
||||||
Color textColor,
|
|
||||||
int height,
|
|
||||||
int width,
|
|
||||||
int borderWidth,
|
|
||||||
float fontSize,
|
|
||||||
TextRenderer textRenderer
|
|
||||||
) {
|
|
||||||
public AlphaPixel[][] render(String text, boolean selected) {
|
|
||||||
AlphaPixel[][] buf = new AlphaPixel[height][width];
|
|
||||||
AlphaPixel[][] textBuf = textRenderer.renderTextSingleLine(text, width - borderWidth * 2, height - borderWidth * 2, textColor, fontSize, true, true);
|
|
||||||
|
|
||||||
for (int y = 0; y < height; y++) {
|
|
||||||
for (int x = 0; x < width; x++) {
|
|
||||||
if (x < borderWidth || y < borderWidth || x >= width - borderWidth || y >= height - borderWidth) {
|
|
||||||
buf[y][x] = borderColor;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x == borderWidth || y == borderWidth || x - 1 == width - borderWidth || y == height - borderWidth) {
|
|
||||||
buf[y][x] = selected ? backgroundSelectedColor : backgroundColor;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int textActualX = x - borderWidth - 1;
|
|
||||||
int textActualY = y - borderWidth - 1;
|
|
||||||
AlphaPixel textPixel = textBuf[textActualY][textActualX];
|
|
||||||
|
|
||||||
if (!textPixel.isTransparent()) {
|
|
||||||
buf[y][x] = textPixel;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[y][x] = selected ? backgroundSelectedColor : backgroundColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,6 @@ import tools.jackson.databind.*;
|
|||||||
import tools.jackson.dataformat.yaml.YAMLFactory;
|
import tools.jackson.dataformat.yaml.YAMLFactory;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -49,7 +48,7 @@ public class DependencyManager extends InjectableValues {
|
|||||||
|
|
||||||
// Construct all classes
|
// Construct all classes
|
||||||
for (Class<?> clazz : classes) {
|
for (Class<?> clazz : classes) {
|
||||||
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
for (var constructor : clazz.getDeclaredConstructors()) {
|
||||||
var paramTypes = constructor.getParameterTypes();
|
var paramTypes = constructor.getParameterTypes();
|
||||||
var params = new Object[paramTypes.length];
|
var params = new Object[paramTypes.length];
|
||||||
boolean suitable = true;
|
boolean suitable = true;
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import com.googlecode.lanterna.TerminalSize;
|
|||||||
import com.googlecode.lanterna.TextColor;
|
import com.googlecode.lanterna.TextColor;
|
||||||
import cz.jzitnik.client.config.Debugging;
|
import cz.jzitnik.client.config.Debugging;
|
||||||
import cz.jzitnik.client.events.handlers.FullRoomDrawHandler;
|
import cz.jzitnik.client.events.handlers.FullRoomDrawHandler;
|
||||||
import cz.jzitnik.client.game.*;
|
import cz.jzitnik.client.game.GameRoom;
|
||||||
|
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.Mob;
|
||||||
import cz.jzitnik.client.game.objects.DroppedItem;
|
import cz.jzitnik.client.game.objects.DroppedItem;
|
||||||
import cz.jzitnik.client.game.objects.GameObject;
|
import cz.jzitnik.client.game.objects.GameObject;
|
||||||
@@ -17,11 +19,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RerenderUtils {
|
public class RerenderUtils {
|
||||||
@@ -37,14 +36,14 @@ public class RerenderUtils {
|
|||||||
return new RoomCords(x, y);
|
return new RoomCords(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rerenderPart(int startX, int endX, int startY, int endY, int screenStartX, int screenStartY, GameRoom currentRoom, BufferedImage room, Player player, ScreenBuffer screenBuffer, ResourceManager resourceManager, Debugging debugging, List<OtherPlayer> otherPlayers) {
|
public static void rerenderPart(int startX, int endX, int startY, int endY, int screenStartX, int screenStartY, GameRoom currentRoom, BufferedImage room, Player player, BufferedImage playerTexture, ScreenBuffer screenBuffer, ResourceManager resourceManager, Debugging debugging) {
|
||||||
var buffer = screenBuffer.getRenderedBuffer();
|
var buffer = screenBuffer.getRenderedBuffer();
|
||||||
var overrideBuffer = currentRoom.getOverrideBuffer();
|
var overrideBuffer = currentRoom.getOverrideBuffer();
|
||||||
BufferedImage doors = resourceManager.getResource(ResourceManager.Resource.DOORS);
|
BufferedImage doors = resourceManager.getResource(ResourceManager.Resource.DOORS);
|
||||||
Set<FullRoomDrawHandler.DoorPosition> doorPositions = RerenderUtils.getDoorPositions(currentRoom);
|
Set<FullRoomDrawHandler.DoorPosition> doorPositions = RerenderUtils.getDoorPositions(currentRoom);
|
||||||
for (int x = startX; x <= endX; x++) {
|
for (int x = startX; x <= endX; x++) {
|
||||||
for (int y = startY; y <= endY; y++) {
|
for (int y = startY; y <= endY; y++) {
|
||||||
PixelResult pixelResult = getPixel(currentRoom, room, doors, doorPositions, player, resourceManager, x, y, debugging, otherPlayers);
|
PixelResult pixelResult = getPixel(currentRoom, room, doors, doorPositions, player, playerTexture, x, y, debugging);
|
||||||
int pixel = pixelResult.pixel();
|
int pixel = pixelResult.pixel();
|
||||||
|
|
||||||
int red = (pixel >> 16) & 0xff;
|
int red = (pixel >> 16) & 0xff;
|
||||||
@@ -64,23 +63,16 @@ public class RerenderUtils {
|
|||||||
public record PixelResult(int pixel, boolean isPlayer) {
|
public record PixelResult(int pixel, boolean isPlayer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PixelResult getPixel(GameRoom currentRoom, BufferedImage room, BufferedImage doors, Set<FullRoomDrawHandler.DoorPosition> doorPositions, Player player, ResourceManager resourceManager, int x, int y, Debugging debugging, List<OtherPlayer> visiblePlayer) {
|
public static PixelResult getPixel(GameRoom currentRoom, BufferedImage room, BufferedImage doors, Set<FullRoomDrawHandler.DoorPosition> doorPositions, Player player, BufferedImage playerTexture, int x, int y, Debugging debugging) {
|
||||||
float factor = 1.5f; // brightness multiplier
|
float factor = 1.5f; // brightness multiplier
|
||||||
if (debugging.renderColliders() && currentRoom.getColliders().stream().anyMatch(collider -> collider.isWithin(new RoomCords(x, y)))) {
|
if (debugging.renderColliders() && currentRoom.getColliders().stream().anyMatch(collider -> collider.isWithin(new RoomCords(x, y)))) {
|
||||||
return new PixelResult(0xFFFF0000, false);
|
return new PixelResult(0xFFFF0000, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<GamePlayer> players = Stream.concat(
|
if (x >= player.getPlayerCords().getX() && x < player.getPlayerCords().getX() + playerTexture.getWidth() - 1 && y >= player.getPlayerCords().getY() && y <= player.getPlayerCords().getY() + playerTexture.getHeight() - 1) {
|
||||||
Stream.of(player),
|
int relativeX = x - player.getPlayerCords().getX();
|
||||||
visiblePlayer.stream()
|
int relativeY = y - player.getPlayerCords().getY();
|
||||||
).toList();
|
|
||||||
|
|
||||||
var playerCollider = player.getCollider();
|
var playerCollider = player.getCollider();
|
||||||
for (GamePlayer player1 : players) {
|
|
||||||
var playerTexture = player1.getTexture(resourceManager);
|
|
||||||
if (x >= player1.getPlayerCords().getX() && x < player1.getPlayerCords().getX() + playerTexture.getWidth() - 1 && y >= player1.getPlayerCords().getY() && y <= player1.getPlayerCords().getY() + playerTexture.getHeight() - 1) {
|
|
||||||
int relativeX = x - player1.getPlayerCords().getX();
|
|
||||||
int relativeY = y - player1.getPlayerCords().getY();
|
|
||||||
|
|
||||||
if (debugging.renderPlayerCollider() && playerCollider.isWithin(new RoomCords(relativeX, relativeY))) {
|
if (debugging.renderPlayerCollider() && playerCollider.isWithin(new RoomCords(relativeX, relativeY))) {
|
||||||
return new PixelResult(0xFFFF0000, false);
|
return new PixelResult(0xFFFF0000, false);
|
||||||
@@ -93,7 +85,6 @@ public class RerenderUtils {
|
|||||||
return new PixelResult(pixel, true);
|
return new PixelResult(pixel, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (Mob object : currentRoom.getMobs()) {
|
for (Mob object : currentRoom.getMobs()) {
|
||||||
RoomCords startObjectCords = object.getCords();
|
RoomCords startObjectCords = object.getCords();
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public class EventManager extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public EventManager(Reflections reflections, DependencyManager dependencyManager) {
|
public EventManager(Reflections reflections, DependencyManager dependencyManager) {
|
||||||
this.dependencyManager = dependencyManager;
|
this.dependencyManager = dependencyManager;
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
renderColliders: true
|
renderColliders: false
|
||||||
renderPlayerCollider: true
|
renderPlayerCollider: false
|
||||||
showPlayerCordsLogs: true
|
showPlayerCordsLogs: false
|
||||||
@@ -1,331 +1,208 @@
|
|||||||
# =========================
|
|
||||||
# START ROOM
|
|
||||||
# Intro NPC explains the goal + starter chest
|
|
||||||
# =========================
|
|
||||||
- id: "spawn"
|
- id: "spawn"
|
||||||
texture: "ROOM11"
|
|
||||||
colliders:
|
|
||||||
- start: { x: 76, y: 45 }
|
|
||||||
end: { x: 155, y: 67 }
|
|
||||||
- start: { x: 40, y: 160 }
|
|
||||||
end: { x: 70, y: 190 }
|
|
||||||
- start: { x: 150, y: 160 }
|
|
||||||
end: { x: 185, y: 190 }
|
|
||||||
|
|
||||||
mobs:
|
|
||||||
- type: "dialog"
|
|
||||||
texture: "OLD_MAN"
|
|
||||||
cords: { x: 90, y: 90 }
|
|
||||||
collider:
|
|
||||||
start: { x: 0, y: 52 }
|
|
||||||
end: { x: 44, y: 78 }
|
|
||||||
dialog:
|
|
||||||
text: "You fell down here too? This cave is cursed..."
|
|
||||||
onEnd:
|
|
||||||
type: continue
|
|
||||||
nextDialog:
|
|
||||||
text: "The only way out is guarded by a beast deep inside."
|
|
||||||
onEnd:
|
|
||||||
type: continue
|
|
||||||
nextDialog:
|
|
||||||
text: "Kill it. Bring its skin to the Key Keeper."
|
|
||||||
onEnd:
|
|
||||||
type: continue
|
|
||||||
nextDialog:
|
|
||||||
text: "He will give you the key to the final gate."
|
|
||||||
onEnd: { type: end }
|
|
||||||
|
|
||||||
west: "empty_a"
|
|
||||||
east: "truhlaright"
|
|
||||||
south: null
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# LOOT ROOM 1
|
|
||||||
# =========================
|
|
||||||
- id: "truhlaright"
|
|
||||||
texture: "ROOM5"
|
|
||||||
colliders:
|
|
||||||
- start: { x: 90, y: 100 }
|
|
||||||
end: { x: 140, y: 145 }
|
|
||||||
- start: { x: 40, y: 70 }
|
|
||||||
end: { x: 80, y: 100 }
|
|
||||||
west: "spawn"
|
|
||||||
east: "filler_1"
|
|
||||||
north: "klicnik"
|
|
||||||
south: "filler_south_1"
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# KEY KEEPER (QUEST NPC)
|
|
||||||
# =========================
|
|
||||||
- id: "klicnik"
|
|
||||||
texture: "ROOM10"
|
|
||||||
mobs:
|
|
||||||
- type: "dialog"
|
|
||||||
texture: "KEY_KEEPER"
|
|
||||||
cords: { x: 90, y: 60 }
|
|
||||||
collider:
|
|
||||||
start: { x: 0, y: 52 }
|
|
||||||
end: { x: 44, y: 78 }
|
|
||||||
dialog:
|
|
||||||
text: "Want to leave? Bring me the beast's skin."
|
|
||||||
onEnd:
|
|
||||||
type: ask_question
|
|
||||||
answers:
|
|
||||||
- answer: "I have it"
|
|
||||||
requirement:
|
|
||||||
item: "BeastSkin"
|
|
||||||
dialog:
|
|
||||||
text: "Well done. Here is the key."
|
|
||||||
onEnd:
|
|
||||||
type: "give_item"
|
|
||||||
item:
|
|
||||||
id: 800
|
|
||||||
name: "Key"
|
|
||||||
type: { name: "key" }
|
|
||||||
texture: "APPLE"
|
|
||||||
then: { type: end }
|
|
||||||
- answer: "Not yet"
|
|
||||||
dialog:
|
|
||||||
text: "Then go back before it finds you."
|
|
||||||
onEnd: { type: end }
|
|
||||||
|
|
||||||
west: "filler_k_west"
|
|
||||||
east: "truhlarightright"
|
|
||||||
north: "final_room"
|
|
||||||
south: "truhlaright"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# BOSS ROOM
|
|
||||||
# =========================
|
|
||||||
- id: "boss"
|
|
||||||
texture: "ROOM3"
|
|
||||||
mobs:
|
|
||||||
- type: "hittable_drops"
|
|
||||||
texture: "CAVE_BEAST"
|
|
||||||
cords: { x: 100, y: 100 }
|
|
||||||
collider:
|
|
||||||
start: { x: 0, y: 52 }
|
|
||||||
end: { x: 44, y: 78 }
|
|
||||||
health: 40
|
|
||||||
itemsDrops:
|
|
||||||
- id: 200
|
|
||||||
name: "Beast Skin"
|
|
||||||
type: { name: "beast_skin" }
|
|
||||||
texture: "BOSS_SKIN"
|
|
||||||
tasks:
|
|
||||||
- type: "following_player"
|
|
||||||
speed: 2
|
|
||||||
updateRateMs: 80
|
|
||||||
- type: "attacking_player"
|
|
||||||
damage: 8
|
|
||||||
reach: 18
|
|
||||||
updateRateMs: 400
|
|
||||||
west: "filler_boss_west"
|
|
||||||
east: null
|
|
||||||
north: null
|
|
||||||
south: "empty_c"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# FINAL ROOM / EXIT
|
|
||||||
# =========================
|
|
||||||
- id: "final_room"
|
|
||||||
texture: "ROOM6"
|
|
||||||
requirement:
|
|
||||||
item: "Key"
|
|
||||||
end: true
|
|
||||||
west: null
|
|
||||||
east: null
|
|
||||||
north: null
|
|
||||||
south: "klicnik"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# COMBAT FILLER A (zombie)
|
|
||||||
# =========================
|
|
||||||
- id: "empty_a"
|
|
||||||
texture: "ROOM7"
|
|
||||||
mobs:
|
|
||||||
- type: "hittable_drops"
|
|
||||||
texture: "ZOMBIE"
|
|
||||||
cords: { x: 110, y: 100 }
|
|
||||||
collider:
|
|
||||||
start: { x: 0, y: 52 }
|
|
||||||
end: { x: 44, y: 78 }
|
|
||||||
health: 6
|
|
||||||
tasks:
|
|
||||||
- type: "following_player"
|
|
||||||
speed: 1
|
|
||||||
updateRateMs: 120
|
|
||||||
- type: "attacking_player"
|
|
||||||
damage: 2
|
|
||||||
reach: 15
|
|
||||||
updateRateMs: 700
|
|
||||||
west: "filler_2"
|
|
||||||
east: "spawn"
|
|
||||||
north: "empty_c"
|
|
||||||
south: "filler_deadend_1"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# COMBAT FILLER B (blind hunter)
|
|
||||||
# =========================
|
|
||||||
- id: "empty_c"
|
|
||||||
texture: "ROOM1"
|
texture: "ROOM1"
|
||||||
mobs:
|
mobs:
|
||||||
- type: "hittable_drops"
|
- type: "hittable_drops"
|
||||||
texture: "BLIND_HUNTER"
|
texture: "PLAYER_FRONT"
|
||||||
cords: { x: 100, y: 100 }
|
cords:
|
||||||
|
x: 100
|
||||||
|
y: 100
|
||||||
collider:
|
collider:
|
||||||
start: { x: 0, y: 52 }
|
start:
|
||||||
end: { x: 44, y: 78 }
|
x: 0
|
||||||
health: 20
|
y: 52
|
||||||
|
end:
|
||||||
|
x: 44
|
||||||
|
y: 78
|
||||||
|
health: 10
|
||||||
|
itemsDrops:
|
||||||
|
- name: "Apple"
|
||||||
|
type:
|
||||||
|
name: "food"
|
||||||
|
addHealth: 1
|
||||||
|
texture: "APPLE"
|
||||||
tasks:
|
tasks:
|
||||||
- type: "blind_following_player"
|
- type: "blind_following_player"
|
||||||
speed: 1
|
speed: 1
|
||||||
updateRateMs: 100
|
updateRateMs: 100
|
||||||
- type: "attacking_player"
|
- type: "attacking_player"
|
||||||
damage: 6
|
damage: 5
|
||||||
reach: 15
|
reach: 15
|
||||||
updateRateMs: 500
|
updateRateMs: 500
|
||||||
west: "filler_c_west"
|
west: "empty"
|
||||||
east: null
|
east: "truhlaright"
|
||||||
north: "boss"
|
north: null
|
||||||
south: "empty_a"
|
south: null
|
||||||
|
|
||||||
|
- id: "truhlaright"
|
||||||
|
texture: "ROOM1"
|
||||||
# =========================
|
|
||||||
# LOOT ROOM 2
|
|
||||||
# =========================
|
|
||||||
- id: "truhlarightright"
|
|
||||||
texture: "ROOM2"
|
|
||||||
objects:
|
objects:
|
||||||
- objectType: "chest"
|
- objectType: "chest"
|
||||||
cords: { x: 100, y: 45 }
|
cords:
|
||||||
|
x: 100
|
||||||
|
y: 45
|
||||||
items:
|
items:
|
||||||
- id: 7
|
- name: "Wooden sword"
|
||||||
name: "Axe"
|
type:
|
||||||
type: { name: "weapon_sword", dealDamage: 4, attackCooldownMs: 800 } # TODO: Make it an axe
|
name: "weapon_sword"
|
||||||
texture: "AXE"
|
dealDamage: 1
|
||||||
- id: 8
|
texture: "WOODEN_SWORD"
|
||||||
name: "Apple"
|
- name: "Apple"
|
||||||
type: { name: "food", addHealth: 2 }
|
type:
|
||||||
|
name: "food"
|
||||||
|
addHealth: 1
|
||||||
texture: "APPLE"
|
texture: "APPLE"
|
||||||
colliders:
|
colliders:
|
||||||
- start: { x: 100, y: 45 }
|
- start:
|
||||||
end: { x: 140, y: 67 }
|
x: 100
|
||||||
|
y: 45
|
||||||
|
end:
|
||||||
|
x: 140
|
||||||
|
y: 67
|
||||||
|
west: "spawn"
|
||||||
|
east: null
|
||||||
|
north: "klicnik"
|
||||||
|
south: null
|
||||||
|
|
||||||
|
- id: "empty"
|
||||||
|
texture: "ROOM1"
|
||||||
|
west: null
|
||||||
|
east: "spawn"
|
||||||
|
north: "truhlatop"
|
||||||
|
south: null
|
||||||
|
|
||||||
|
- id: "truhlatop"
|
||||||
|
texture: "ROOM1"
|
||||||
|
objects:
|
||||||
|
- objectType: "chest"
|
||||||
|
cords:
|
||||||
|
x: 100
|
||||||
|
y: 45
|
||||||
|
items:
|
||||||
|
- name: "Wooden sword"
|
||||||
|
type:
|
||||||
|
name: "weapon_sword"
|
||||||
|
dealDamage: 1
|
||||||
|
texture: "WOODEN_SWORD"
|
||||||
|
- name: "Apple"
|
||||||
|
type:
|
||||||
|
name: "food"
|
||||||
|
addHealth: 1
|
||||||
|
texture: "APPLE"
|
||||||
|
colliders:
|
||||||
|
- start:
|
||||||
|
x: 100
|
||||||
|
y: 45
|
||||||
|
end:
|
||||||
|
x: 140
|
||||||
|
y: 67
|
||||||
|
west: "empty2"
|
||||||
|
east: null
|
||||||
|
north: null
|
||||||
|
south: "empty"
|
||||||
|
|
||||||
|
- id: "empty2"
|
||||||
|
texture: "ROOM1"
|
||||||
|
west: null
|
||||||
|
east: "truhlatop"
|
||||||
|
north: "boss"
|
||||||
|
south: null
|
||||||
|
|
||||||
|
- id: "boss"
|
||||||
|
texture: "ROOM1"
|
||||||
|
mobs:
|
||||||
|
- type: "hittable_drops"
|
||||||
|
texture: "PLAYER_FRONT"
|
||||||
|
cords:
|
||||||
|
x: 100
|
||||||
|
y: 100
|
||||||
|
collider:
|
||||||
|
start:
|
||||||
|
x: 0
|
||||||
|
y: 52
|
||||||
|
end:
|
||||||
|
x: 44
|
||||||
|
y: 78
|
||||||
|
health: 10
|
||||||
|
itemsDrops:
|
||||||
|
- name: "Apple"
|
||||||
|
type:
|
||||||
|
name: "food"
|
||||||
|
addHealth: 1
|
||||||
|
texture: "APPLE"
|
||||||
|
tasks:
|
||||||
|
- type: "following_player"
|
||||||
|
speed: 1
|
||||||
|
updateRateMs: 100
|
||||||
|
- type: "attacking_player"
|
||||||
|
damage: 20
|
||||||
|
reach: 15
|
||||||
|
updateRateMs: 500
|
||||||
|
west: null
|
||||||
|
east: null
|
||||||
|
north: null
|
||||||
|
south: "empty2"
|
||||||
|
|
||||||
|
- id: "klicnik"
|
||||||
|
texture: "ROOM1"
|
||||||
|
mobs:
|
||||||
|
- type: "hittable_drops"
|
||||||
|
texture: "PLAYER_FRONT"
|
||||||
|
cords:
|
||||||
|
x: 100
|
||||||
|
y: 100
|
||||||
|
collider:
|
||||||
|
start:
|
||||||
|
x: 0
|
||||||
|
y: 52
|
||||||
|
end:
|
||||||
|
x: 44
|
||||||
|
y: 78
|
||||||
|
health: 10
|
||||||
|
itemsDrops:
|
||||||
|
- name: "Apple"
|
||||||
|
type:
|
||||||
|
name: "food"
|
||||||
|
addHealth: 1
|
||||||
|
texture: "APPLE"
|
||||||
|
tasks:
|
||||||
|
- type: "blind_following_player"
|
||||||
|
speed: 1
|
||||||
|
updateRateMs: 100
|
||||||
|
- type: "attacking_player"
|
||||||
|
damage: 5
|
||||||
|
reach: 15
|
||||||
|
updateRateMs: 500
|
||||||
|
west: null
|
||||||
|
east: "truhlarightright"
|
||||||
|
north: null
|
||||||
|
south: "truhlaright"
|
||||||
|
|
||||||
|
- id: "truhlarightright"
|
||||||
|
texture: "ROOM1"
|
||||||
west: "klicnik"
|
west: "klicnik"
|
||||||
east: "filler_rr_east"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
|
||||||
# EXTRA FILLER ROOMS (maze / dead ends)
|
|
||||||
# =========================
|
|
||||||
- id: "filler_1"
|
|
||||||
texture: "ROOM3"
|
|
||||||
west: "truhlaright"
|
|
||||||
east: "filler_1b"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_1b"
|
|
||||||
texture: "ROOM1"
|
|
||||||
west: "filler_1"
|
|
||||||
east: null
|
east: null
|
||||||
north: null
|
north: null
|
||||||
south: null
|
south: null
|
||||||
|
objects:
|
||||||
- id: "filler_2"
|
- objectType: "chest"
|
||||||
texture: "ROOM7"
|
cords:
|
||||||
west: null
|
x: 100
|
||||||
east: "empty_a"
|
y: 45
|
||||||
north: "filler_loop_1"
|
items:
|
||||||
south: null
|
- name: "Wooden sword"
|
||||||
|
type:
|
||||||
- id: "filler_loop_1"
|
name: "weapon_sword"
|
||||||
texture: "ROOM4"
|
dealDamage: 1
|
||||||
west: null
|
texture: "WOODEN_SWORD"
|
||||||
east: null
|
- name: "Apple"
|
||||||
north: "filler_loop_2"
|
type:
|
||||||
south: "filler_2"
|
name: "food"
|
||||||
|
addHealth: 1
|
||||||
- id: "filler_loop_2"
|
texture: "APPLE"
|
||||||
texture: "ROOM3"
|
colliders:
|
||||||
west: "filler_loop_3"
|
- start:
|
||||||
east: null
|
x: 100
|
||||||
north: null
|
y: 45
|
||||||
south: "filler_loop_1"
|
end:
|
||||||
|
x: 140
|
||||||
- id: "filler_loop_3"
|
y: 67
|
||||||
texture: "ROOM2"
|
|
||||||
west: null
|
|
||||||
east: "filler_loop_2"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_deadend_1"
|
|
||||||
texture: "ROOM1"
|
|
||||||
west: null
|
|
||||||
east: null
|
|
||||||
north: "empty_a"
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_k_west"
|
|
||||||
texture: "ROOM4"
|
|
||||||
west: "filler_k_west_2"
|
|
||||||
east: "klicnik"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_k_west_2"
|
|
||||||
texture: "ROOM3"
|
|
||||||
west: null
|
|
||||||
east: "filler_k_west"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_boss_west"
|
|
||||||
texture: "ROOM2"
|
|
||||||
west: null
|
|
||||||
east: "boss"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_c_west"
|
|
||||||
texture: "ROOM1"
|
|
||||||
west: null
|
|
||||||
east: "empty_c"
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_rr_east"
|
|
||||||
texture: "ROOM4"
|
|
||||||
west: "truhlarightright"
|
|
||||||
east: null
|
|
||||||
north: null
|
|
||||||
south: null
|
|
||||||
|
|
||||||
- id: "filler_south_1"
|
|
||||||
texture: "ROOM3"
|
|
||||||
west: null
|
|
||||||
east: null
|
|
||||||
north: "truhlaright"
|
|
||||||
south: "filler_south_2"
|
|
||||||
|
|
||||||
- id: "filler_south_2"
|
|
||||||
texture: "ROOM2"
|
|
||||||
west: null
|
|
||||||
east: null
|
|
||||||
north: "filler_south_1"
|
|
||||||
south: null
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 95 KiB |
224
logs/general.log
Normal 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.
|
||||||
@@ -2,53 +2,23 @@ package cz.jzitnik.server.context;
|
|||||||
|
|
||||||
import cz.jzitnik.server.game.Client;
|
import cz.jzitnik.server.game.Client;
|
||||||
import cz.jzitnik.server.events.EventManager;
|
import cz.jzitnik.server.events.EventManager;
|
||||||
import cz.jzitnik.server.game.Game;
|
import cz.jzitnik.server.socket.SocketSession;
|
||||||
import jakarta.websocket.Session;
|
import jakarta.websocket.Session;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.HashMap;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class GlobalContext {
|
public class GlobalContext {
|
||||||
@Getter
|
@Getter
|
||||||
private final HashMap<Session, Client> sessions = new HashMap<>();
|
private final HashMap<Session, Client> sessions = new HashMap<>();
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Set<Game> games = new HashSet<>();
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private EventManager eventManager;
|
private EventManager eventManager;
|
||||||
|
|
||||||
@Getter
|
public void registerClient(Session session) {
|
||||||
private final Properties properties;
|
Client client = new Client(new SocketSession(session));
|
||||||
|
sessions.put(session, client);
|
||||||
public void registerClient(Client client) {
|
|
||||||
sessions.put(client.getSession().getSession(), client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Game> getGame(String pass) {
|
|
||||||
return games.stream().filter(game -> game.getPassword().equals(pass)).findFirst();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalContext() {
|
|
||||||
Properties props = new Properties();
|
|
||||||
|
|
||||||
try (InputStream input = GlobalContext.class
|
|
||||||
.getClassLoader()
|
|
||||||
.getResourceAsStream("config.properties")) {
|
|
||||||
|
|
||||||
if (input == null) {
|
|
||||||
throw new RuntimeException("config.properties not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
props.load(input);
|
|
||||||
|
|
||||||
this.properties = props;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package cz.jzitnik.server.events;
|
package cz.jzitnik.server.events;
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
import cz.jzitnik.common.socket.SocketMessage;
|
||||||
import cz.jzitnik.server.context.GlobalContext;
|
|
||||||
import cz.jzitnik.server.game.Client;
|
import cz.jzitnik.server.game.Client;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public abstract class AbstractEventHandler<T extends SocketMessage> {
|
public abstract class AbstractEventHandler<T extends SocketMessage> {
|
||||||
protected final GlobalContext globalContext;
|
|
||||||
public abstract void handle(T event, Client client);
|
public abstract void handle(T event, Client client);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
|
||||||
import cz.jzitnik.common.socket.messages.game.connection.ConnectToAGame;
|
|
||||||
import cz.jzitnik.common.socket.messages.game.connection.ConnectToAGameResponse;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerArrivalChange;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerJoined;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerRotation;
|
|
||||||
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 cz.jzitnik.server.game.Player;
|
|
||||||
import tools.jackson.databind.ObjectMapper;
|
|
||||||
import tools.jackson.databind.ObjectReader;
|
|
||||||
import tools.jackson.dataformat.yaml.YAMLFactory;
|
|
||||||
|
|
||||||
@EventHandler(ConnectToAGame.class)
|
|
||||||
public class ConnectToAGameHandler extends AbstractEventHandler<ConnectToAGame> {
|
|
||||||
public ConnectToAGameHandler(GlobalContext globalContext) {
|
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(ConnectToAGame event, Client client) {
|
|
||||||
var gameOptional = globalContext.getGame(event.gamePass().toUpperCase());
|
|
||||||
|
|
||||||
if (gameOptional.isEmpty()) {
|
|
||||||
client.getSession().sendMessage(new ConnectToAGameResponse());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var game = gameOptional.get();
|
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
|
||||||
ObjectReader playerReader = objectMapper.readerFor(PlayerCreation.class);
|
|
||||||
PlayerCreation player = playerReader.readValue(getClass().getClassLoader().getResourceAsStream("setup/player.yaml"));
|
|
||||||
player.setId(game.getPlayers().size());
|
|
||||||
client.setPlayer(new Player(player));
|
|
||||||
client.setGame(game);
|
|
||||||
String defaultRoomId = globalContext.getProperties().getProperty("rooms.default");
|
|
||||||
client.getPlayer().setCurrentRoom(defaultRoomId);
|
|
||||||
|
|
||||||
client.getSession().sendMessage(new ConnectToAGameResponse(player, game.getPlayers().stream().map(client1 -> client1.getPlayer().toPlayerCreation()).toList()));
|
|
||||||
|
|
||||||
for (Client cl : game.getPlayers()) {
|
|
||||||
cl.getSession().sendMessage(new PlayerJoined(player));
|
|
||||||
|
|
||||||
if (cl.getPlayer().getCurrentRoom().equals(defaultRoomId)) {
|
|
||||||
cl.getSession().sendMessage(new PlayerArrivalChange(client.getPlayer().getId(), player.getPlayerCords(), PlayerRotation.FRONT, true, true));
|
|
||||||
client.getSession().sendMessage(new PlayerArrivalChange(cl.getPlayer().getId(), cl.getPlayer().getCords(), PlayerRotation.FRONT, true, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
game.getPlayers().add(client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
package cz.jzitnik.server.events.handlers;
|
||||||
|
|
||||||
import cz.jzitnik.common.Config;
|
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
import cz.jzitnik.common.models.player.PlayerCreation;
|
||||||
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
|
import cz.jzitnik.common.socket.messages.game.creation.CreateGame;
|
||||||
import cz.jzitnik.common.socket.messages.game.creation.CreateGameResponse;
|
import cz.jzitnik.common.socket.messages.game.creation.CreateGameResponse;
|
||||||
@@ -8,44 +7,26 @@ import cz.jzitnik.server.annotations.EventHandler;
|
|||||||
import cz.jzitnik.server.context.GlobalContext;
|
import cz.jzitnik.server.context.GlobalContext;
|
||||||
import cz.jzitnik.server.events.AbstractEventHandler;
|
import cz.jzitnik.server.events.AbstractEventHandler;
|
||||||
import cz.jzitnik.server.game.Client;
|
import cz.jzitnik.server.game.Client;
|
||||||
import cz.jzitnik.server.game.Game;
|
|
||||||
import cz.jzitnik.server.game.Player;
|
|
||||||
import cz.jzitnik.server.utils.PasswordGenerator;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import tools.jackson.databind.ObjectMapper;
|
import tools.jackson.databind.ObjectMapper;
|
||||||
import tools.jackson.databind.ObjectReader;
|
import tools.jackson.databind.ObjectReader;
|
||||||
import tools.jackson.dataformat.yaml.YAMLFactory;
|
import tools.jackson.dataformat.yaml.YAMLFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
@RequiredArgsConstructor
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@EventHandler(CreateGame.class)
|
@EventHandler(CreateGame.class)
|
||||||
public class CreateGameHandler extends AbstractEventHandler<CreateGame> {
|
public class CreateGameHandler extends AbstractEventHandler<CreateGame> {
|
||||||
public CreateGameHandler(GlobalContext globalContext) {
|
private final GlobalContext globalContext;
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(CreateGame event, Client client) {
|
public void handle(CreateGame event, Client client) {
|
||||||
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
||||||
String pass = PasswordGenerator.generatePassword(Config.WORLD_PASSWORD_LENGTH);
|
String pass = "nevim"; // TODO: Generate
|
||||||
int id = 0; // Owners id is always 0
|
|
||||||
|
|
||||||
ObjectReader playerReader = objectMapper.readerFor(PlayerCreation.class);
|
ObjectReader playerReader = objectMapper.readerFor(PlayerCreation.class);
|
||||||
PlayerCreation player = playerReader.readValue(getClass().getClassLoader().getResourceAsStream("setup/player.yaml"));
|
PlayerCreation player = playerReader.readValue(getClass().getClassLoader().getResourceAsStream("setup/player.yaml"));
|
||||||
player.setId(id);
|
|
||||||
|
|
||||||
client.setPlayer(new Player(player));
|
|
||||||
|
|
||||||
CreateGameResponse gameResponse = new CreateGameResponse(pass, player);
|
CreateGameResponse gameResponse = new CreateGameResponse(pass, player);
|
||||||
Game game = new Game(
|
|
||||||
pass,
|
|
||||||
new ArrayList<>(List.of(client))
|
|
||||||
);
|
|
||||||
client.setGame(game);
|
|
||||||
client.getPlayer().setCurrentRoom(globalContext.getProperties().getProperty("rooms.default"));
|
|
||||||
globalContext.getGames().add(game);
|
|
||||||
|
|
||||||
client.getSession().sendMessage(gameResponse);
|
client.session().sendMessage(gameResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.messages.game.GameWin;
|
|
||||||
import cz.jzitnik.server.annotations.EventHandler;
|
|
||||||
import cz.jzitnik.server.context.GlobalContext;
|
|
||||||
import cz.jzitnik.server.events.AbstractEventHandler;
|
|
||||||
import cz.jzitnik.server.game.Client;
|
|
||||||
|
|
||||||
@EventHandler(GameWin.class)
|
|
||||||
public class GameWinHandler extends AbstractEventHandler<GameWin> {
|
|
||||||
public GameWinHandler(GlobalContext globalContext) {
|
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(GameWin event, Client client) {
|
|
||||||
for (Client player : client.getGame().getPlayers()) {
|
|
||||||
player.getSession().sendMessage(new GameWin());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.messages.items.ItemTookFromChest;
|
|
||||||
import cz.jzitnik.server.annotations.EventHandler;
|
|
||||||
import cz.jzitnik.server.context.GlobalContext;
|
|
||||||
import cz.jzitnik.server.events.AbstractEventHandler;
|
|
||||||
import cz.jzitnik.server.game.Client;
|
|
||||||
|
|
||||||
@EventHandler(ItemTookFromChest.class)
|
|
||||||
public class ItemTookFromChestHandler extends AbstractEventHandler<ItemTookFromChest> {
|
|
||||||
public ItemTookFromChestHandler(GlobalContext globalContext) {
|
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(ItemTookFromChest event, Client client) {
|
|
||||||
client.getGame().getItemModifiers().add(event);
|
|
||||||
|
|
||||||
for (Client client1 : client.getGame().getPlayers()) {
|
|
||||||
client1.getSession().sendMessage(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerArrivalChange;
|
|
||||||
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
|
|
||||||
import cz.jzitnik.common.socket.messages.room.MovePlayerRoomResponse;
|
|
||||||
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.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@EventHandler(MovePlayerRoom.class)
|
|
||||||
public class MovePlayerRoomHandler extends AbstractEventHandler<MovePlayerRoom> {
|
|
||||||
public MovePlayerRoomHandler(GlobalContext globalContext) {
|
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MovePlayerRoom event, Client client) {
|
|
||||||
String oldRoomId = client.getPlayer().getCurrentRoom();
|
|
||||||
|
|
||||||
client.getSession().sendMessage(new MovePlayerRoomResponse(
|
|
||||||
client.getGame().getPlayers().stream().filter(player ->
|
|
||||||
player.getPlayer().getCurrentRoom().equals(event.newRoomId())
|
|
||||||
).map(client1 ->
|
|
||||||
new MovePlayerRoomResponse.Registry(
|
|
||||||
client1.getPlayer().getId(),
|
|
||||||
client1.getPlayer().getCords(),
|
|
||||||
client1.getPlayer().getPlayerRotation()
|
|
||||||
)
|
|
||||||
).collect(Collectors.toSet())
|
|
||||||
));
|
|
||||||
|
|
||||||
client.getPlayer().setCurrentRoom(event.newRoomId());
|
|
||||||
|
|
||||||
for (Client player : client.getGame().getPlayers()) {
|
|
||||||
if (player.getPlayer().getId() != client.getPlayer().getId()) {
|
|
||||||
if (player.getPlayer().getCurrentRoom().equals(oldRoomId)) {
|
|
||||||
log.debug("{}", event.oldCords());
|
|
||||||
player.getSession().sendMessage(new PlayerArrivalChange(client.getPlayer().getId(), event.oldCords(), client.getPlayer().getPlayerRotation(), false, true));
|
|
||||||
} else if (player.getPlayer().getCurrentRoom().equals(event.newRoomId())) {
|
|
||||||
player.getSession().sendMessage(new PlayerArrivalChange(client.getPlayer().getId(), event.newCords(), client.getPlayer().getPlayerRotation(), true, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.messages.game.PlayerDeath;
|
|
||||||
import cz.jzitnik.server.annotations.EventHandler;
|
|
||||||
import cz.jzitnik.server.context.GlobalContext;
|
|
||||||
import cz.jzitnik.server.events.AbstractEventHandler;
|
|
||||||
import cz.jzitnik.server.game.Client;
|
|
||||||
|
|
||||||
@EventHandler(PlayerDeath.class)
|
|
||||||
public class PlayerDeathHandler extends AbstractEventHandler<PlayerDeath> {
|
|
||||||
public PlayerDeathHandler(GlobalContext globalContext) {
|
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerDeath event, Client client) {
|
|
||||||
for (Client player : client.getGame().getPlayers()) {
|
|
||||||
player.getSession().sendMessage(new PlayerDeath(event.playerId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package cz.jzitnik.server.events.handlers;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerMove;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerMovedInUrRoom;
|
|
||||||
import cz.jzitnik.server.annotations.EventHandler;
|
|
||||||
import cz.jzitnik.server.context.GlobalContext;
|
|
||||||
import cz.jzitnik.server.events.AbstractEventHandler;
|
|
||||||
import cz.jzitnik.server.game.Client;
|
|
||||||
|
|
||||||
@EventHandler(PlayerMove.class)
|
|
||||||
public class PlayerMoveHandler extends AbstractEventHandler<PlayerMove> {
|
|
||||||
public PlayerMoveHandler(GlobalContext globalContext) {
|
|
||||||
super(globalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerMove event, Client client) {
|
|
||||||
client.getPlayer().getCords().updateCords(event.newCords());
|
|
||||||
client.getPlayer().setPlayerRotation(event.playerRotation());
|
|
||||||
|
|
||||||
for (Client player : client.getGame().getPlayers()) {
|
|
||||||
if (player.getPlayer().getCurrentRoom().equals(client.getPlayer().getCurrentRoom()) && player.getPlayer().getId() != client.getPlayer().getId()) {
|
|
||||||
player.getSession().sendMessage(new PlayerMovedInUrRoom(client.getPlayer().getId(), event.newCords(), event.playerRotation()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,5 @@
|
|||||||
package cz.jzitnik.server.game;
|
package cz.jzitnik.server.game;
|
||||||
|
|
||||||
import cz.jzitnik.server.socket.SocketSession;
|
import cz.jzitnik.server.socket.SocketSession;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
public record Client(SocketSession session) {}
|
||||||
public final class Client {
|
|
||||||
private final SocketSession session;
|
|
||||||
@Setter
|
|
||||||
private Player player;
|
|
||||||
@Setter
|
|
||||||
private Game game;
|
|
||||||
|
|
||||||
public Client(SocketSession session, Player player, Game game) {
|
|
||||||
this.session = session;
|
|
||||||
this.player = player;
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Client(SocketSession session, Player player) {
|
|
||||||
this(session, player, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,4 @@
|
|||||||
package cz.jzitnik.server.game;
|
package cz.jzitnik.server.game;
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.messages.items.ItemTookFromChest;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Game {
|
public class Game {
|
||||||
private String password;
|
|
||||||
private List<Client> players;
|
|
||||||
private final List<ItemTookFromChest> itemModifiers = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package cz.jzitnik.server.game;
|
|
||||||
|
|
||||||
import cz.jzitnik.common.models.coordinates.RoomCords;
|
|
||||||
import cz.jzitnik.common.models.player.PlayerCreation;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerRotation;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class Player {
|
|
||||||
private final int id;
|
|
||||||
private final RoomCords cords;
|
|
||||||
@Setter
|
|
||||||
private PlayerRotation playerRotation;
|
|
||||||
@Setter
|
|
||||||
private String currentRoom;
|
|
||||||
|
|
||||||
public Player(PlayerCreation creation) {
|
|
||||||
id = creation.getId();
|
|
||||||
cords = creation.getPlayerCords();
|
|
||||||
playerRotation = PlayerRotation.FRONT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerCreation toPlayerCreation() {
|
|
||||||
return new PlayerCreation(cords, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package cz.jzitnik.server.socket;
|
package cz.jzitnik.server.socket;
|
||||||
|
|
||||||
import cz.jzitnik.common.socket.SocketMessage;
|
import cz.jzitnik.common.socket.SocketMessage;
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerArrivalChange;
|
|
||||||
import cz.jzitnik.common.socket.messages.player.PlayerDisconnected;
|
|
||||||
import cz.jzitnik.server.game.Client;
|
import cz.jzitnik.server.game.Client;
|
||||||
import cz.jzitnik.server.context.GlobalContext;
|
import cz.jzitnik.server.context.GlobalContext;
|
||||||
import jakarta.websocket.*;
|
import jakarta.websocket.*;
|
||||||
@@ -20,8 +18,7 @@ public class WebSocket {
|
|||||||
@OnOpen
|
@OnOpen
|
||||||
public void onOpen(Session session, EndpointConfig config) {
|
public void onOpen(Session session, EndpointConfig config) {
|
||||||
this.globalContext = (GlobalContext) config.getUserProperties().get("globalContext");
|
this.globalContext = (GlobalContext) config.getUserProperties().get("globalContext");
|
||||||
|
globalContext.registerClient(session);
|
||||||
globalContext.registerClient(new Client(new SocketSession(session), null));
|
|
||||||
log.debug("Client connected: {}", session.getId());
|
log.debug("Client connected: {}", session.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,24 +36,7 @@ public class WebSocket {
|
|||||||
|
|
||||||
@OnClose
|
@OnClose
|
||||||
public void onClose(Session session, CloseReason reason) {
|
public void onClose(Session session, CloseReason reason) {
|
||||||
Client client = globalContext.getSessions().get(session);
|
System.out.println("Connection closed: " + reason);
|
||||||
client.getGame().getPlayers().remove(client);
|
|
||||||
|
|
||||||
for (Client otherClient : client.getGame().getPlayers()) {
|
|
||||||
if (otherClient.getPlayer().getCurrentRoom().equals(client.getPlayer().getCurrentRoom())) {
|
|
||||||
otherClient.getSession().sendMessage(new PlayerArrivalChange(
|
|
||||||
client.getPlayer().getId(),
|
|
||||||
client.getPlayer().getCords(),
|
|
||||||
client.getPlayer().getPlayerRotation(),
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
otherClient.getSession().sendMessage(new PlayerDisconnected(client.getPlayer().getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Connection closed: {}", reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnError
|
@OnError
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package cz.jzitnik.server.utils;
|
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
|
|
||||||
public class PasswordGenerator {
|
|
||||||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
||||||
private static final SecureRandom RANDOM = new SecureRandom();
|
|
||||||
|
|
||||||
public static String generatePassword(int length) {
|
|
||||||
if (length <= 0) {
|
|
||||||
throw new IllegalArgumentException("Password length must be greater than 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder password = new StringBuilder(length);
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
int index = RANDOM.nextInt(CHARACTERS.length());
|
|
||||||
password.append(CHARACTERS.charAt(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
return password.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
rooms.default=spawn
|
|
||||||