From 1f6dec3b966a206a677ffcfe0811acc634ecea59 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 25 Dec 2024 03:59:16 +0200 Subject: [PATCH] wip --- .../imperium/mindustry/event/EventListener.kt | 82 +++++++++++++------ .../mindustry/misc/MindustryExtensions.kt | 16 ++++ 2 files changed, 75 insertions(+), 23 deletions(-) diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/event/EventListener.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/event/EventListener.kt index c9ad7d6b..3c842c11 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/event/EventListener.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/event/EventListener.kt @@ -33,6 +33,8 @@ import com.xpdustry.imperium.mindustry.command.annotation.ClientSide import com.xpdustry.imperium.mindustry.command.annotation.Flag import com.xpdustry.imperium.mindustry.command.annotation.Scope import com.xpdustry.imperium.mindustry.game.MenuToPlayEvent +import com.xpdustry.imperium.mindustry.misc.isErekirDistribution +import com.xpdustry.imperium.mindustry.misc.isSerpuloDistribution import kotlin.random.Random import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.Job @@ -51,6 +53,7 @@ import mindustry.world.blocks.ConstructBlock.ConstructBuild class EventListener(instances: InstanceManager) : ImperiumApplication.Listener { private val validTiles = mutableListOf>() + private val secondHandTiles = mutableListOf>() private val crates = mutableListOf>() private var delayJob: Job? = null @@ -72,6 +75,33 @@ class EventListener(instances: InstanceManager) : ImperiumApplication.Listener { delayJob = null } + @TaskHandler(interval = 10L, unit = MindustryTimeUnit.SECONDS) + fun registerValidTiles() { + for (x in 0..Vars.world.width()) { + for (y in 0..Vars.world.height()) { + if (checkValid(x, y, false)) { + validTiles.add(x to y) + } + } + } + } + + @TaskHandler(interval = 10L, unit = MindustryTimeUnit.SECONDS) + fun registerSecondHandTiles() { + for (x in 0..Vars.world.width()) { + for (y in 0..Vars.world.height()) { + if (checkValid(x, y, true)) { + secondHandTiles.add(x to y) + } + } + } + } + + // @TaskHandler(interval = 1L, unit = MindustryTimeUnit.SECONDS) + fun crateRarityLabel() { + // TODO: Markers + } + @ImperiumCommand(["crate"], Rank.ADMIN) @Scope(MindustryGamemode.EVENT) @ClientSide @@ -81,16 +111,22 @@ class EventListener(instances: InstanceManager) : ImperiumApplication.Listener { y: Int = 0, @Flag rarity: Int = 0 ) { + sender.sendMessage("Spawned crate at $x, $y with rarity $rarity") generateCrate(x, y, rarity) } fun onCrateGenerate() { - val localValidTiles = validTiles.toMutableList() - if (localValidTiles.isEmpty()) { - return LOGGER.error("How is the entire map full??") - Events.fire(GameOverEvent(Team.derelict)) - Call.sendMessage( - "[scarlet]The map has ended due to no valid tiles left to spawn crates!") + if (validTiles.isEmpty()) { + if (secondHandTiles.isEmpty()) { + return + LOGGER.error("How is the entire map full??") + Events.fire(GameOverEvent(Team.derelict)) + Call.announce( + "[scarlet]The map has ended due to no valid tiles left to spawn crates!") + } + val localValidTiles = secondHandTiles.toMutableList() + } else { + val localValidTiles = validTiles.toMutableList() } while (localValidTiles.isNotEmpty()) { @@ -106,17 +142,7 @@ class EventListener(instances: InstanceManager) : ImperiumApplication.Listener { LOGGER.error( "Failed to generate crate: No valid tiles left.") // tmp log, shout at players instead registerValidTiles() - } - - @TaskHandler(interval = 10L, unit = MindustryTimeUnit.SECONDS) - fun registerValidTiles() { - for (x in 0..Vars.world.width()) { - for (y in 0..Vars.world.height()) { - if (checkValid(x, y)) { - validTiles.add(x to y) - } - } - } + registerSecondHandTiles() } fun generateCrate(x: Int, y: Int, rarity: Int) { @@ -125,7 +151,8 @@ class EventListener(instances: InstanceManager) : ImperiumApplication.Listener { tile.setNet(Blocks.vault) crates.add(Triple(x, y, newRarity)) - Call.label("Event Vault", Float.MAX_VALUE, (x * 8).toFloat(), (y * 8).toFloat()) + // TODO: Make this a marker/effect for rarity (outline) + Call.label("Event Vault\nRarity: $rarity", Float.MAX_VALUE, (x * 8).toFloat(), (y * 8).toFloat()) } @EventHandler @@ -167,11 +194,20 @@ class EventListener(instances: InstanceManager) : ImperiumApplication.Listener { tile.setNet(Blocks.air) } - fun checkValid(x: Int, y: Int): Boolean { - return (x - 1..x + 1).all { x1 -> - (y - 1..y + 1).all { y1 -> - val tile = Vars.world.tile(x1, y1) - tile != null && tile.block() == Blocks.air + fun checkValid(x: Int, y: Int, replace: Boolean): Boolean { + if(!replace) { + return (x - 1..x + 1).all { x1 -> + (y - 1..y + 1).all { y1 -> + val tile = Vars.world.tile(x1, y1) + tile != null && tile.block() == Blocks.air + } + } + } else { + return (x - 1..x + 1).all { x1 -> + (y - 1..y + 1).all { y1 -> + val tile = Vars.world.tile(x1, y1) + tile != null && (tile.block() == Blocks.air || tile.block().isSerpuloDistribution() || tile.block().isErekirDistribution) + } } } } diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/misc/MindustryExtensions.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/misc/MindustryExtensions.kt index 20f832ff..7bddb563 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/misc/MindustryExtensions.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/misc/MindustryExtensions.kt @@ -28,6 +28,16 @@ import mindustry.game.Gamemode import mindustry.gen.Building import mindustry.net.Administration import mindustry.world.Block +import mindustry.world.blocks.distribution.Conveyor +import mindustry.world.blocks.distribution.StackConveyor +import mindustry.world.blocks.distribution.Duct +import mindustry.world.blocks.distribution.Router +import mindustry.world.blocks.distribution.DuctRouter +import mindustry.world.blocks.distribution.Junction +import mindustry.world.blocks.distribution.OverflowDuct +import mindustry.world.blocks.distribution.OverflowGate +import mindustry.world.blocks.distribution.Sorter +import mindustry.world.blocks.distribution.StackRouter import mindustry.world.blocks.sandbox.ItemSource import mindustry.world.blocks.sandbox.ItemVoid import mindustry.world.blocks.sandbox.LiquidSource @@ -98,3 +108,9 @@ val Block.isSourceBlock: Boolean val Block.isVoidBlock: Boolean get() = this is ItemVoid || this is LiquidVoid || this is PowerVoid + +val Block.isErekirDistribution: Boolean + get() = this is Duct || this is DuctRouter || this is OverflowDuct || this is StackConveyor || this is StackRouter + +val Block.isSerpuloDistribution: Boolean + get() = this is Conveyor || this is StackConveyor || this is Junction || this is Sorter || this is Router || this is OverflowGate \ No newline at end of file