Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonP01 committed Dec 25, 2024
1 parent 6f637d1 commit 1f6dec3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,6 +53,7 @@ import mindustry.world.blocks.ConstructBlock.ConstructBuild

class EventListener(instances: InstanceManager) : ImperiumApplication.Listener {
private val validTiles = mutableListOf<Pair<Int, Int>>()
private val secondHandTiles = mutableListOf<Pair<Int, Int>>()
private val crates = mutableListOf<Triple<Int, Int, Int>>()
private var delayJob: Job? = null

Expand All @@ -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
Expand All @@ -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()) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1f6dec3

Please sign in to comment.