Skip to content

Commit

Permalink
Merge pull request #63 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to master --release
  • Loading branch information
Shynixn authored Nov 9, 2024
2 parents f7f6b16 + 238c09c commit 4c6413a
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 50 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.github.shynixn"
version = "1.10.0"
version = "1.11.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -197,7 +197,7 @@ tasks.register("pluginJarLegacy", com.github.jengelman.gradle.plugins.shadow.tas
tasks.register("languageFile") {
val kotlinSrcFolder = project.sourceSets.toList()[0].allJava.srcDirs.first { e -> e.endsWith("kotlin") }
val contractFile = kotlinSrcFolder.resolve("com/github/shynixn/mctennis/contract/Language.kt")
val resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.yaml")
val resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.yml")
val lines = resourceFile.readLines()

val contents = ArrayList<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ class MCTennisLanguageImpl() : Language, LanguageProviderImpl() {
override var freeVersionMessage: LanguageItem = LanguageItem()

override var commandPlaceHolderMessage: LanguageItem = LanguageItem()

override var queueTimeOutMessage: LanguageItem = LanguageItem().also {
it.text = "[&9MCTennis&f]&c Not enough players joined in time to start the game."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ interface Language : LanguageProvider {
var freeVersionMessage: LanguageItem

var commandPlaceHolderMessage: LanguageItem

var queueTimeOutMessage: LanguageItem
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ interface TennisGame {
*/
val servingTeam: Team

/**
* Gets the player who is serving.
*/
val servingPlayer : Player?

/**
* Ball.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PlayerData {
var wasSneaking: Boolean = false

/**
* Power Index.
* Power Level.
*/
var currentPower: Double = 4.0
var currentPowerLevel: Double = 1.0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.shynixn.mctennis.entity

class PowerLevelSettings {
/**
* Are power levels enabled.
*/
var enabled: Boolean = true

/**
* Amount of bars.
*/
var levelsAmount: Int = 5

/**
* How fast the power level increases.
*/
var increaseSteps: Double = 0.5

/**
* Multiplier of the base horizontal velocity.
*/
var powerLevelMultiplierPerLevel : Double = 1.0
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/github/shynixn/mctennis/entity/TennisArena.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class TennisArena : Element {
*/
var keepInventory: Boolean = false

/**
* Amount of seconds until the queue timeouts.
*/
var queueTimeOutSec: Int = 30

/**
* Leave spawnpoint.
*/
Expand All @@ -71,6 +76,16 @@ class TennisArena : Element {
*/
var blueTeamMeta: TeamMetadata = TeamMetadata()

/**
* PowerLevel when service
*/
var servePowerLevelSettings = PowerLevelSettings()

/**
* PowerLevel when playing.
*/
var defaultPowerLevelSettings = PowerLevelSettings()

/**
* All signs.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ class TennisBallSettings {
var item: Item = Item().also {
it.typeName = "PLAYER_HEAD,397"
it.durability = "3"
it.skinBase64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0="
it.skinBase64 =
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0="
}

var spawnOffsetFront: Double = 2.5

var spawnOffsetUp: Double = 0.5

var spawnOffsetLeft: Double = 0.0

// Ground
var horizontalBaseMultiplier: Double = 0.4

Expand Down Expand Up @@ -49,12 +56,12 @@ class TennisBallSettings {
/**
* RayTraceOffset.
*/
var rayTraceYOffset : Double = 0.0
var rayTraceYOffset: Double = 0.0

/**
* Render offset.
*/
var renderYOffset : Double = -0.3
var renderYOffset: Double = -0.3

/**
* Render visibility updates.
Expand All @@ -71,40 +78,10 @@ class TennisBallSettings {
*/
var clickHitBoxSize: Int = 3

/**
* Base Multiplier for the speed when spinning.
*/
var spinBaseMultiplier: Double = 1.0

/**
* Maximum spinning velocity.
*/
var maximumSpinningVelocity = 0.08

/**
* Maximum spin angle.
*/
var spinMaximum: Double = 60.0

/**
* Minimum spin angle
*/
var spinMinimum: Double = 0.0

/**
* Default spin.
*/
var spinDefault: Double = 20.0

/**
* Spin vertical
*/
var spinVertical: Double = 0.6

/**
* Minimum amount of cooldown milliseconds between two clicks.
*/
var clickCooldown: Int = 250
var clickCooldown: Int = 2000

/**
* Slime visibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class TennisBallImpl(
game?.lastHitPlayer = player

plugin.launch {
val prevDirection = player.eyeLocation.direction.toVector3d()
val strengthMultiplier = 1.0 + (multiplier * 0.1)
val kickVector =
player.eyeLocation.direction.toVector3d().normalize().multiply(settings.horizontalBaseMultiplier)
Expand Down
79 changes: 72 additions & 7 deletions src/main/kotlin/com/github/shynixn/mctennis/impl/TennisGameImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TennisGameImpl(
private val language: Language
) : TennisGame {
private var isDisposed = false
private var currentQueueTime = arena.queueTimeOutSec
private var isQueueTimeRunning = false

/**
* Tennis ball.
Expand Down Expand Up @@ -103,6 +105,8 @@ class TennisGameImpl(
*/
override var servingTeam: Team = Team.RED

override var servingPlayer: Player? = null

init {
plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) {
while (!isDisposed) {
Expand Down Expand Up @@ -164,9 +168,13 @@ class TennisGameImpl(
val playerData = PlayerData()
cachedData[player] = playerData

// Handle Queue Timeout.
queueTimeOut()

if (teamBluePlayers.size >= arena.minPlayersPerTeam && teamRedPlayers.size >= arena.minPlayersPerTeam && teamRedPlayers.size + teamBluePlayers.size > 0) {
if (gameState == GameState.LOBBY_IDLE) {
gameState = GameState.LOBBY_COUNTDOWN
isQueueTimeRunning = false
plugin.launch {
startGame()
}
Expand All @@ -176,6 +184,7 @@ class TennisGameImpl(
return joinResult
}


/**
* Leaves the given player.
*/
Expand Down Expand Up @@ -264,6 +273,7 @@ class TennisGameImpl(
if (teamBluePlayers.size < arena.minPlayersPerTeam || teamRedPlayers.size < arena.minPlayersPerTeam) {
language.sendMessageToPlayers(language.notEnoughPlayersMessage, getPlayers())
gameState = GameState.LOBBY_IDLE
queueTimeOut()
return
}
}
Expand Down Expand Up @@ -385,30 +395,41 @@ class TennisGameImpl(

private fun increasePunchPower() {
for (player in getPlayers()) {
var powerSettings = arena.defaultPowerLevelSettings

if (player == servingPlayer) {
powerSettings = arena.servePowerLevelSettings
}

val playerData = cachedData[player]

if (playerData == null) {
continue
}

if (!powerSettings.enabled) {
playerData.currentPowerLevel = 1.0
continue
}

if (player.isSneaking) {
if (playerData.wasSneaking) {
playerData.currentPower += 0.5
playerData.currentPowerLevel += powerSettings.increaseSteps
} else {
playerData.currentPower = 1.0
playerData.currentPowerLevel = 1.0
playerData.wasSneaking = true
}
} else {
playerData.wasSneaking = false
}

if (playerData.currentPower > 5.0) {
playerData.currentPower = 5.0
if (playerData.currentPowerLevel > powerSettings.levelsAmount) {
playerData.currentPowerLevel = powerSettings.levelsAmount.toDouble()
}

val builder = StringBuilder()

for (i in 0 until playerData.currentPower.toInt()) {
for (i in 0 until playerData.currentPowerLevel.toInt()) {
builder.append("")
}

Expand All @@ -418,12 +439,23 @@ class TennisGameImpl(

private suspend fun setBallForServingTeam(team: Team) {
teleportPlayersToSpawnpoint()
for (player in cachedData.keys) {
chatMessageService.sendActionBarMessage(player, "")
}

if (team == Team.RED && teamRedPlayers.size > 0) {
servingPlayer = teamRedPlayers[0]
} else if (team == Team.BLUE && teamBluePlayers.size > 0) {
servingPlayer = teamBluePlayers[0]
}

val teamMetaData = getTeamMetaFromTeam(team)
// Spawnpoint 0 is always serving.
val spawnpoint = teamMetaData.spawnpoints[0]
val ballspawnpoint = spawnpoint.copy().addRelativeFront(2.0).addRelativeUp(0.5)

val ballspawnpoint = spawnpoint.copy()
.addRelativeFront(arena.ballSettings.spawnOffsetFront)
.addRelativeUp(arena.ballSettings.spawnOffsetUp)
.addRelativeLeft(arena.ballSettings.spawnOffsetLeft)
ball = tennisBallFactory.createTennisBall(ballspawnpoint.toLocation(), arena.ballSettings, this)

delay(500)
Expand All @@ -443,6 +475,11 @@ class TennisGameImpl(
lastHitPlayer = teamRedPlayers[0]
}
}

plugin.launch {
delay(1500)
servingPlayer = null
}
}

/**
Expand Down Expand Up @@ -534,6 +571,7 @@ class TennisGameImpl(
cachedData.clear()
isDisposed = true
ball?.remove()
servingPlayer = null

if (sendEvent) {
val gameEndEvent = GameEndEvent(this)
Expand Down Expand Up @@ -680,4 +718,31 @@ class TennisGameImpl(
)
}
}

private fun queueTimeOut() {
currentQueueTime = arena.queueTimeOutSec

if (isQueueTimeRunning) {
return
}

isQueueTimeRunning = true
plugin.launch {
while (isQueueTimeRunning) {
currentQueueTime -= 1

if (currentQueueTime <= 0) {
isQueueTimeRunning = false
for (player in cachedData.keys.toTypedArray()) {
language.sendMessage(language.queueTimeOutMessage, player)
leave(player)
}
gameState = GameState.LOBBY_IDLE
return@launch
}

delay(20.ticks)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ class PacketListener @Inject constructor(
val player = event.player
val game = gameService.getByPlayer(player) ?: return@launch
val playerData = game.getPlayerData(player) ?: return@launch
physicObject.shoot(event.player, playerData.currentPower)

val powerSettings = if(game.servingPlayer == player){
game.arena.servePowerLevelSettings
}else{
game.arena.defaultPowerLevelSettings
}

val power = powerSettings.powerLevelMultiplierPerLevel * playerData.currentPowerLevel
physicObject.shoot(event.player, power)
}
}
}
Loading

0 comments on commit 4c6413a

Please sign in to comment.