summaryrefslogtreewikicommitdiff
path: root/core/src/inv
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2026-03-26 23:15:33 -0400
committerFreya Murphy <freya@freyacat.org>2026-03-27 23:09:23 -0400
commitf8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch)
treed7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/inv
downloadkenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz
kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2
kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip
initial
Diffstat (limited to 'core/src/inv')
-rw-r--r--core/src/inv/BlockHunt.kt26
-rw-r--r--core/src/inv/Debug.kt49
-rw-r--r--core/src/inv/Teleport.kt58
3 files changed, 133 insertions, 0 deletions
diff --git a/core/src/inv/BlockHunt.kt b/core/src/inv/BlockHunt.kt
new file mode 100644
index 0000000..615c746
--- /dev/null
+++ b/core/src/inv/BlockHunt.kt
@@ -0,0 +1,26 @@
+package cat.freya.khs.inv
+
+import cat.freya.khs.Khs
+import cat.freya.khs.config.ItemConfig
+import cat.freya.khs.game.KhsMap
+import cat.freya.khs.player.Inventory
+
+const val BLOCKHUNT_TITLE_PREFIX = "Select a Block: "
+
+fun createBlockHuntPicker(plugin: Khs, map: KhsMap): Inventory? {
+ val blocks = map.config.blockHunt.blocks
+
+ // make inv
+ val rows = (blocks.size.toUInt() + 8u) / 9u
+ val size = minOf(rows * 9u, 9u)
+ val inv = plugin.shim.createInventory("$BLOCKHUNT_TITLE_PREFIX${map.name}", size) ?: return null
+
+ // add items
+ blocks
+ .map { plugin.shim.parseItem(ItemConfig(material = it)) }
+ .filterNotNull()
+ .withIndex()
+ .forEach { (i, item) -> inv.set(i.toUInt(), item) }
+
+ return inv
+}
diff --git a/core/src/inv/Debug.kt b/core/src/inv/Debug.kt
new file mode 100644
index 0000000..5e9d9d4
--- /dev/null
+++ b/core/src/inv/Debug.kt
@@ -0,0 +1,49 @@
+package cat.freya.khs.inv
+
+import cat.freya.khs.Khs
+import cat.freya.khs.config.ItemConfig
+import cat.freya.khs.game.Game
+import cat.freya.khs.player.Inventory
+import cat.freya.khs.player.Player
+
+const val DEBUG_TITLE = "Teleport"
+val BECOME_HIDER = ItemConfig("&6Become a &lHider", "LEATHER_CHESTPLATE")
+val BECOME_SEEKER = ItemConfig("&cBecome a &lSEEKER", "GOLDEN_CHESTPLATE")
+val BECOME_SPECTATOR = ItemConfig("&8Become a &lSPECTATOR", "IRON_CHESTPLATE")
+val DIE_IN_GAME = ItemConfig("&cDie in game", "SKELETON_SKULL")
+val REVEAL_DISGUISE = ItemConfig("&cReveal disguise", "BARRIER")
+
+fun becomeHider(plugin: Khs, player: Player) {
+ plugin.game.setTeam(player.uuid, Game.Team.HIDER)
+ plugin.game.loadHider(player)
+ if (plugin.game.status == Game.Status.SEEKING) plugin.game.giveHiderItems(player)
+}
+
+fun becomeSeeker(plugin: Khs, player: Player) {
+ plugin.game.setTeam(player.uuid, Game.Team.SEEKER)
+ plugin.game.loadSeeker(player)
+ if (plugin.game.status == Game.Status.SEEKING) plugin.game.giveSeekerItems(player)
+}
+
+fun becomeSpectator(plugin: Khs, player: Player) {
+ plugin.game.setTeam(player.uuid, Game.Team.SPECTATOR)
+ plugin.game.loadSpectator(player)
+}
+
+fun dieInGame(plugin: Khs, player: Player) {
+ val team = plugin.game.getTeam(player.uuid)
+ if (team == null || team == Game.Team.SPECTATOR) return
+ if (plugin.game.status != Game.Status.SEEKING) return
+ player.health = 0.1
+}
+
+fun createDebugMenu(plugin: Khs): Inventory? {
+ val inv = plugin.shim.createInventory(DEBUG_TITLE, 9u) ?: return null
+ val items = listOf(BECOME_HIDER, BECOME_SEEKER, BECOME_SPECTATOR, DIE_IN_GAME, REVEAL_DISGUISE)
+ items
+ .map { plugin.shim.parseItem(it) }
+ .filterNotNull()
+ .withIndex()
+ .forEach { (i, item) -> inv.set(i.toUInt(), item) }
+ return inv
+}
diff --git a/core/src/inv/Teleport.kt b/core/src/inv/Teleport.kt
new file mode 100644
index 0000000..2e5ddbb
--- /dev/null
+++ b/core/src/inv/Teleport.kt
@@ -0,0 +1,58 @@
+package cat.freya.khs.inv
+
+import cat.freya.khs.Khs
+import cat.freya.khs.config.ItemConfig
+import cat.freya.khs.game.Game
+import cat.freya.khs.player.Inventory
+import cat.freya.khs.player.Player
+import cat.freya.khs.world.Item
+
+const val TELEPORT_TITLE = "Teleport to players"
+
+fun createPageItem(plugin: Khs, page: UInt): Item? {
+ val config = ItemConfig("Page ${page + 1u}", "ENCHANTED_BOOK")
+ return plugin.shim.parseItem(config)
+}
+
+fun createPlayerItem(plugin: Khs, player: Player): Item? {
+ val team = plugin.game.getTeam(player.uuid) ?: return null
+ val teamName =
+ when (team) {
+ Game.Team.HIDER -> plugin.locale.game.team.hider
+ Game.Team.SEEKER -> plugin.locale.game.team.seeker
+ else -> ""
+ }
+ val config =
+ ItemConfig(
+ name = player.name,
+ material = "PLAYER_HEAD",
+ owner = player.name,
+ lore = listOf(teamName),
+ )
+ return plugin.shim.parseItem(config)
+}
+
+fun createTeleportMenu(plugin: Khs, page: UInt): Inventory? {
+ val pageSize = 7u
+ val offset = pageSize * page
+
+ // make items
+ val players = (plugin.game.seekerPlayers + plugin.game.hiderPlayers)
+ val items =
+ players.drop(offset.toInt()).take(pageSize.toInt()).mapNotNull {
+ createPlayerItem(plugin, it)
+ }
+ val prev = if (page > 0u) createPageItem(plugin, page - 1u) else null
+ val next =
+ if (players.size.toUInt() > offset + pageSize) createPageItem(plugin, page + 1u) else null
+
+ // create inv
+ val inv = plugin.shim.createInventory(TELEPORT_TITLE, 9u) ?: return null
+ for ((i, item) in items.withIndex()) {
+ inv.set(i.toUInt() + 1u, item)
+ }
+ if (prev != null) inv.set(0u, prev)
+ if (next != null) inv.set(8u, next)
+
+ return inv
+}