feat: Requirements for game

This commit is contained in:
2026-02-08 18:03:08 +01:00
parent 35918ac0ad
commit 6559cbe4c7
7 changed files with 68 additions and 14 deletions

View File

@@ -7,6 +7,7 @@ import cz.jzitnik.client.events.RoomChangeEvent;
import cz.jzitnik.client.events.SendSocketMessageEvent;
import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Requirement;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
@@ -14,6 +15,7 @@ import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -45,6 +47,20 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
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()) {
case LEFT -> playerCords.updateCords(155, playerCords.getY());
case RIGHT -> playerCords.updateCords(30, playerCords.getY());

View File

@@ -34,6 +34,9 @@ public class GameRoom {
@JsonIgnore
private final List<RoomPart> colliders = new ArrayList<>();
@JsonProperty("requirement")
private Requirement requirement;
private GameRoom left;
private GameRoom right;
private GameRoom up;

View File

@@ -0,0 +1,13 @@
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;
}
}

View File

@@ -36,8 +36,23 @@ public class ResourceManager {
APPLE("food/apple.png"),
DOORS("rooms/doors.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"),
STAMINA("ui/stamina.png"),
HEART("ui/heart.png");

View File

@@ -11,7 +11,8 @@ import cz.jzitnik.client.game.items.types.weapons.Sword;
)
@JsonSubTypes({
@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")
})
public interface ItemType<T> {
Class<T> getItemType();

View File

@@ -0,0 +1,8 @@
package cz.jzitnik.client.game.items.types;
public class Junk implements ItemType<Junk> {
@Override
public Class<Junk> getItemType() {
return Junk.class;
}
}

View File

@@ -54,11 +54,11 @@
texture: "ROOM1"
objects:
- objectType: "chest"
cords: { x: 100, y: 45 }
cords: { x: 140, y: 45 }
items:
- id: 1
name: "Dagger"
type: { name: "weapon_dagger", dealDamage: 2, attackCooldownMs: 300 }
type: { name: "weapon_sword", dealDamage: 2, attackCooldownMs: 300 } # TODO: Make it dagger
texture: "DAGGER"
- id: 2
name: "Bread"
@@ -69,15 +69,13 @@
type: { name: "junk" }
texture: "ROCK"
colliders:
- start: { x: 100, y: 45 }
end: { x: 140, y: 67 }
- start: { x: 140, y: 45 }
end: { x: 180, y: 67 }
west: "spawn"
east: "filler_1"
north: "klicnik"
south: "filler_south_1"
# =========================
# KEY KEEPER (QUEST NPC)
# =========================
@@ -134,7 +132,7 @@
itemsDrops:
- id: 200
name: "Beast Skin"
type: { name: "quest_item_boss_skin" }
type: { name: "junk" }
texture: "BOSS_SKIN"
tasks:
- type: "following_player"
@@ -155,12 +153,12 @@
# FINAL ROOM / EXIT
# =========================
- id: "final_room"
texture: "ROOM_EXIT"
texture: "ROOM1"
requirement:
item: "quest_item_final_key"
objects:
- objectType: "exit"
cords: { x: 140, y: 40 }
#objects:
# - objectType: "exit"
# cords: { x: 140, y: 40 }
west: null
east: null
north: null
@@ -235,7 +233,7 @@
items:
- id: 7
name: "Axe"
type: { name: "weapon_axe", dealDamage: 4, attackCooldownMs: 800 }
type: { name: "weapon_sword", dealDamage: 4, attackCooldownMs: 800 } # TODO: Make it an axe
texture: "AXE"
- id: 8
name: "Apple"