Skip to content

Commit

Permalink
Teams logic added to game engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendotgg committed Nov 29, 2023
1 parent c9a8b96 commit 2ede8f0
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 38 deletions.
64 changes: 50 additions & 14 deletions src/main/kotlin/gg/flyte/event/game/GameType.kt
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -23,7 +22,7 @@ enum class GameType(
val gameMode: GameMode,
val clazz: Class<out Game>,
val region: BoundingBox,
val spawns: List<MapLocation>,
val spawns: List<List<MapLocation>>, // Teams -> Spawns
val spectatorSpawn: MapLocation?
) {

Expand All @@ -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)
),
Expand All @@ -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)
),
Expand All @@ -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

Expand All @@ -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
)

Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/gg/flyte/event/game/TeamType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gg.flyte.event.game

enum class TeamType {

RED,
BLUE,
YELLOW,
GREEN

}
5 changes: 4 additions & 1 deletion src/main/kotlin/gg/flyte/event/game/main/MainGame.kt
Original file line number Diff line number Diff line change
@@ -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<Player>()
val points = mutableMapOf<UUID, Int>()

abstract fun onPlayerJoin(player: Player)
Expand Down
37 changes: 32 additions & 5 deletions src/main/kotlin/gg/flyte/event/game/main/MainGameEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TeamType, MutableList<Player>>? = 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(
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/gg/flyte/event/game/main/TeamGame.kt
Original file line number Diff line number Diff line change
@@ -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<TeamType, MutableList<Player>>

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

Expand All @@ -44,8 +45,6 @@ class BlockPartyGame : MainGame() {

private lateinit var music: RadioSongPlayer

private val alive = mutableListOf<Player>()

init {


Expand All @@ -66,8 +65,6 @@ class BlockPartyGame : MainGame() {
}

override fun start() {
alive.addAll(Bukkit.getOnlinePlayers())

tasks += repeat(4, 4) {
gameLoop()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player>()

init {
Bukkit.getOnlinePlayers().forEach {
alive.forEach {
points[it.uniqueId] = 0
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player>()
private val inMinecart = mutableListOf<Player>()
private val minecarts = mutableListOf<Minecart>()

Expand Down Expand Up @@ -66,8 +65,6 @@ class MusicalMinecartsGame : MainGame() {
).build()
)

alive.addAll(Bukkit.getOnlinePlayers())

newRound()
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/gg/flyte/event/game/main/type/PresentSnatchGame.kt
Original file line number Diff line number Diff line change
@@ -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")
}

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

0 comments on commit 2ede8f0

Please sign in to comment.