diff --git a/src/main/kotlin/gg/flyte/event/game/GameType.kt b/src/main/kotlin/gg/flyte/event/game/GameType.kt index c83ecc4..fae9219 100644 --- a/src/main/kotlin/gg/flyte/event/game/GameType.kt +++ b/src/main/kotlin/gg/flyte/event/game/GameType.kt @@ -1,15 +1,14 @@ package gg.flyte.event.game import gg.flyte.event.game.lobby.type.PresentHuntGame -import gg.flyte.event.game.main.MainGame import gg.flyte.event.game.main.type.KingOfTheHillGame import gg.flyte.event.game.main.type.MusicalMinecartsGame +import gg.flyte.event.game.main.type.PresentSnatchGame import gg.flyte.event.game.main.type.SledRacingGame import gg.flyte.event.util.MapLocation import net.kyori.adventure.text.Component import org.bukkit.GameMode import org.bukkit.util.BoundingBox -import javax.naming.ldap.PagedResultsResponseControl enum class GameCategory { LOBBY, @@ -23,7 +22,7 @@ enum class GameType( val gameMode: GameMode, val clazz: Class, val region: BoundingBox, - val spawns: List, + val spawns: List>, // Teams -> Spawns val spectatorSpawn: MapLocation? ) { @@ -40,7 +39,9 @@ enum class GameType( MapLocation(599, 126, 817) ), listOf( - MapLocation(616, 111, 800) + listOf( + MapLocation(616, 111, 800) + ) ), MapLocation(635, 112, 828, 145, 0) ), @@ -56,7 +57,9 @@ enum class GameType( MapLocation(-174, 79, 103) ), listOf( - MapLocation(-133, 80, 100, 90, 0) + listOf( + MapLocation(-133, 80, 100, 90, 0) + ) ), MapLocation(-151, 80, 92) ), @@ -72,18 +75,47 @@ enum class GameType( MapLocation(832, 104, 627) ), listOf( - MapLocation(811, 98, 604, -45, -5), - MapLocation(831, 100, 600, 3, 0), - MapLocation(845, 103, 606, 40, 7), - MapLocation(855, 100, 622, 60, 5), - MapLocation(855, 101, 640, 135, 3), - MapLocation(845, 101, 656, 151, 3), - MapLocation(814, 100, 644, -135, 2), - MapLocation(803, 96, 624, -90, -7), + listOf( + MapLocation(811, 98, 604, -45, -5), + MapLocation(831, 100, 600, 3, 0), + MapLocation(845, 103, 606, 40, 7), + MapLocation(855, 100, 622, 60, 5), + MapLocation(855, 101, 640, 135, 3), + MapLocation(845, 101, 656, 151, 3), + MapLocation(814, 100, 644, -135, 2), + MapLocation(803, 96, 624, -90, -7), + ) ), MapLocation(731, 142, 528, -45, 15) ), + PRESENT_SNATCH( + GameCategory.MAIN, + Component.text("Present Snatch"), + Component.text("awooga"), + GameMode.ADVENTURE, + PresentSnatchGame::class.java, + BoundingBox.of( + MapLocation(0, 0, 0), + MapLocation(0, 0, 0), + ), + listOf( + listOf( + MapLocation(0, 0, 0), + ), + listOf( + MapLocation(0, 0, 0), + ), + listOf( + MapLocation(0, 0, 0), + ), + listOf( + MapLocation(0, 0, 0), + ), + ), + MapLocation(0, 0, 0) + ), + // LOBBY GAMES @@ -97,7 +129,11 @@ enum class GameType( MapLocation(413, 300, 624), MapLocation(791, 35, 311) ), - listOf(MapLocation(611, 94, 502, 45, -3)), + listOf( + listOf( + MapLocation(611, 94, 502, 45, -3) + ), + ), null ) diff --git a/src/main/kotlin/gg/flyte/event/game/TeamType.kt b/src/main/kotlin/gg/flyte/event/game/TeamType.kt new file mode 100644 index 0000000..a79c9b9 --- /dev/null +++ b/src/main/kotlin/gg/flyte/event/game/TeamType.kt @@ -0,0 +1,10 @@ +package gg.flyte.event.game + +enum class TeamType { + + RED, + BLUE, + YELLOW, + GREEN + +} \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/event/game/main/MainGame.kt b/src/main/kotlin/gg/flyte/event/game/main/MainGame.kt index 5476c5d..0b7b3f2 100644 --- a/src/main/kotlin/gg/flyte/event/game/main/MainGame.kt +++ b/src/main/kotlin/gg/flyte/event/game/main/MainGame.kt @@ -1,13 +1,16 @@ package gg.flyte.event.game.main import gg.flyte.event.game.Game +import gg.flyte.event.game.GameType import org.bukkit.entity.Player import java.util.* -abstract class MainGame : Game() { +abstract class MainGame(type: GameType) : Game() { + lateinit var type: GameType var state = MainGameState.COUNTDOWN + val alive = mutableListOf() val points = mutableMapOf() abstract fun onPlayerJoin(player: Player) diff --git a/src/main/kotlin/gg/flyte/event/game/main/MainGameEngine.kt b/src/main/kotlin/gg/flyte/event/game/main/MainGameEngine.kt index 320e812..1701c7d 100644 --- a/src/main/kotlin/gg/flyte/event/game/main/MainGameEngine.kt +++ b/src/main/kotlin/gg/flyte/event/game/main/MainGameEngine.kt @@ -2,6 +2,7 @@ package gg.flyte.event.game.main import gg.flyte.event.ChristmasEvent.Companion.LOBBY_SPAWN import gg.flyte.event.game.GameType +import gg.flyte.event.game.TeamType import gg.flyte.event.game.lobby.LobbyGameEngine import gg.flyte.twilight.event.TwilightListener import gg.flyte.twilight.extension.applyForEach @@ -36,12 +37,38 @@ object MainGameEngine { LobbyGameEngine.stopGame(player, game) } - Bukkit.getOnlinePlayers().applyForEach { - teleport(MainGameEngine.type!!.spawns.random()) - gameMode = MainGameEngine.type!!.gameMode + var teams: MutableMap>? = null + if (type!!.spawns.size > 1) { + teams = mutableMapOf() + + val shuffledPlayers = Bukkit.getOnlinePlayers().shuffled() + val teamSize = shuffledPlayers.size / type!!.spawns.size + for ((index, spawn) in type!!.spawns.withIndex()) { + val startIndex = index * teamSize + val endIndex = (index + 1) * teamSize + val team = shuffledPlayers.subList(startIndex, endIndex) + teams[TeamType.entries[index]] = team.toMutableList() + + team.applyForEach { + teleport(spawn.random()) + gameMode = MainGameEngine.type!!.gameMode + } + } + } else { + Bukkit.getOnlinePlayers().applyForEach { + teleport(MainGameEngine.type!!.spawns[0].random()) + gameMode = MainGameEngine.type!!.gameMode + } } - game = (type!!.clazz.getDeclaredConstructor().newInstance() as MainGame).apply { events() } + game = (type!!.clazz.getDeclaredConstructor().newInstance() as MainGame).apply { + alive.addAll(Bukkit.getOnlinePlayers()) + events() + + if (teams != null) { + (this as TeamGame).teams = teams + } + } Bukkit.broadcast( text().append( @@ -113,7 +140,7 @@ object MainGameEngine { text().append( CHAT_SPLITTER, newline(), - text("Game ended!"), + text("Game ended! info about who won here"), newline(), CHAT_SPLITTER ).build() diff --git a/src/main/kotlin/gg/flyte/event/game/main/TeamGame.kt b/src/main/kotlin/gg/flyte/event/game/main/TeamGame.kt new file mode 100644 index 0000000..3be3064 --- /dev/null +++ b/src/main/kotlin/gg/flyte/event/game/main/TeamGame.kt @@ -0,0 +1,11 @@ +package gg.flyte.event.game.main + +import gg.flyte.event.game.GameType +import gg.flyte.event.game.TeamType +import org.bukkit.entity.Player + +abstract class TeamGame(type: GameType) : MainGame(type) { + + lateinit var teams: MutableMap> + +} \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/event/game/main/type/BlockPartyGame.kt b/src/main/kotlin/gg/flyte/event/game/main/type/BlockPartyGame.kt index 723c083..d8d1be4 100644 --- a/src/main/kotlin/gg/flyte/event/game/main/type/BlockPartyGame.kt +++ b/src/main/kotlin/gg/flyte/event/game/main/type/BlockPartyGame.kt @@ -5,6 +5,7 @@ import gg.flyte.event.game.main.MainGameEngine import gg.flyte.event.util.NBSSongType import com.xxmicloxx.NoteBlockAPI.model.RepeatMode import com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer +import gg.flyte.event.game.GameType import gg.flyte.twilight.event.event import gg.flyte.twilight.extension.applyForEach import gg.flyte.twilight.scheduler.repeat @@ -19,7 +20,7 @@ import org.bukkit.event.player.PlayerDropItemEvent import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.potion.PotionEffectType -class BlockPartyGame : MainGame() { +class BlockPartyGame : MainGame(GameType.MUSICAL_MINECARTS) {// CHnage to block party private val squares = listOf() @@ -44,8 +45,6 @@ class BlockPartyGame : MainGame() { private lateinit var music: RadioSongPlayer - private val alive = mutableListOf() - init { @@ -66,8 +65,6 @@ class BlockPartyGame : MainGame() { } override fun start() { - alive.addAll(Bukkit.getOnlinePlayers()) - tasks += repeat(4, 4) { gameLoop() } diff --git a/src/main/kotlin/gg/flyte/event/game/main/type/KingOfTheHillGame.kt b/src/main/kotlin/gg/flyte/event/game/main/type/KingOfTheHillGame.kt index 594d9c8..0df83aa 100644 --- a/src/main/kotlin/gg/flyte/event/game/main/type/KingOfTheHillGame.kt +++ b/src/main/kotlin/gg/flyte/event/game/main/type/KingOfTheHillGame.kt @@ -28,15 +28,13 @@ import org.bukkit.inventory.ItemStack import java.text.DecimalFormat import java.time.Duration -class KingOfTheHillGame : MainGame() { +class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) { private val RESPAWN_Y = 78 private var GAME_SECONDS = 120 - private var alive = mutableListOf() - init { - Bukkit.getOnlinePlayers().forEach { + alive.forEach { points[it.uniqueId] = 0 } } @@ -105,7 +103,6 @@ class KingOfTheHillGame : MainGame() { itemMeta = meta } - alive.addAll(Bukkit.getOnlinePlayers()) alive.applyForEach { getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 10.0; health = 10.0 @@ -143,7 +140,7 @@ class KingOfTheHillGame : MainGame() { } else { player.apply { health = player.health - 2 - teleport(GameType.KING_OF_THE_HILL.spawns[0]) + teleport(GameType.KING_OF_THE_HILL.spawns[0].random()) sendMessage("you fell, lost another life") } } diff --git a/src/main/kotlin/gg/flyte/event/game/main/type/MusicalMinecartsGame.kt b/src/main/kotlin/gg/flyte/event/game/main/type/MusicalMinecartsGame.kt index 2a0aaec..f6f3460 100644 --- a/src/main/kotlin/gg/flyte/event/game/main/type/MusicalMinecartsGame.kt +++ b/src/main/kotlin/gg/flyte/event/game/main/type/MusicalMinecartsGame.kt @@ -25,11 +25,10 @@ import org.bukkit.scheduler.BukkitTask import kotlin.math.roundToInt import kotlin.random.Random -class MusicalMinecartsGame : MainGame() { +class MusicalMinecartsGame : MainGame(GameType.MUSICAL_MINECARTS) { private lateinit var music: RadioSongPlayer - private val alive = mutableListOf() private val inMinecart = mutableListOf() private val minecarts = mutableListOf() @@ -66,8 +65,6 @@ class MusicalMinecartsGame : MainGame() { ).build() ) - alive.addAll(Bukkit.getOnlinePlayers()) - newRound() } @@ -82,7 +79,7 @@ class MusicalMinecartsGame : MainGame() { Bukkit.getOnlinePlayers().applyForEach { playSound(Sound.BLOCK_NOTE_BLOCK_BASEDRUM) } // SPAWNING MINECARTS - val potentialSpawnLocations = GameType.MUSICAL_MINECARTS.region.getLocations(ChristmasEvent.WORLD) + val potentialSpawnLocations = type.region.getLocations(ChristmasEvent.WORLD) kotlin.repeat((alive.size * 0.66).roundToInt()) { minecarts += potentialSpawnLocations.random().spawnEntity(EntityType.MINECART) as Minecart } @@ -121,7 +118,7 @@ class MusicalMinecartsGame : MainGame() { if (inMinecart.contains(player)) { points[player.uniqueId] = points.getOrDefault(player.uniqueId, 0) + 1 } else { - player.teleport(GameType.MUSICAL_MINECARTS.spectatorSpawn!!) + player.teleport(type.spectatorSpawn!!) player.playSound(Sound.ENTITY_PLAYER_DEATH) iterator.remove() } diff --git a/src/main/kotlin/gg/flyte/event/game/main/type/PresentSnatchGame.kt b/src/main/kotlin/gg/flyte/event/game/main/type/PresentSnatchGame.kt new file mode 100644 index 0000000..2547d31 --- /dev/null +++ b/src/main/kotlin/gg/flyte/event/game/main/type/PresentSnatchGame.kt @@ -0,0 +1,33 @@ +package gg.flyte.event.game.main.type + +import gg.flyte.event.game.GameType +import gg.flyte.event.game.main.TeamGame +import org.bukkit.entity.Player + +class PresentSnatchGame : TeamGame(GameType.PRESENT_SNATCH) { + + override fun events() { + // right click presents + // disable damage of presents if theyre entities + // + } + + override fun start() { + // spawn presents at mid/around the map + // start timer + } + + override fun stop() { + // remove all presents if theyre entities + // remeber to use MainGameEngine.stop() when stopping (cases: timer ends, too many players leave) + } + + override fun onPlayerJoin(player: Player) { + TODO("Not yet implemented") + } + + override fun onPlayerQuit(player: Player) { + TODO("Not yet implemented") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/event/game/main/type/SledRacingGame.kt b/src/main/kotlin/gg/flyte/event/game/main/type/SledRacingGame.kt index 8de1457..1002a2c 100644 --- a/src/main/kotlin/gg/flyte/event/game/main/type/SledRacingGame.kt +++ b/src/main/kotlin/gg/flyte/event/game/main/type/SledRacingGame.kt @@ -1,6 +1,7 @@ package gg.flyte.event.game.main.type import gg.flyte.event.ChristmasEvent +import gg.flyte.event.game.GameType import gg.flyte.event.game.main.MainGame import gg.flyte.event.game.main.MainGameEngine import gg.flyte.event.util.MapLocation @@ -19,7 +20,7 @@ import org.bukkit.event.entity.EntityDamageEvent import org.bukkit.event.vehicle.VehicleExitEvent import org.bukkit.util.BoundingBox -class SledRacingGame : MainGame() { +class SledRacingGame : MainGame(GameType.SLED_RACING) { private val STARTING_WALL = BoundingBox.of( MapLocation(-136, 80, 95),