Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
1.18 stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
emortal committed Dec 10, 2021
1 parent 3d2f617 commit 8cbce2a
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 82 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ dependencies {
// Use the Kotlin reflect library.
compileOnly(kotlin("reflect"))

implementation("com.github.emortaldev:particable:e98f138cda")
implementation("com.github.EmortalMC:Rayfast:07d8daf030")
compileOnly("com.github.Minestom:Minestom:cca614fea8")
compileOnly("com.github.EmortalMC:Immortal:ef116d2b19")
compileOnly("com.github.Minestom:Minestom:3843cacef5")
compileOnly("com.github.EmortalMC:Immortal:0fc8d6d833")


// import kotlinx serialization
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")

// Use the JUpiter test library.
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
}
tasks.withType<Test> {
useJUnitPlatform()
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/emortal/lazertag/LazerTagExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ class LazerTagExtension : Extension() {
GameOptions(
maxPlayers = 15,
minPlayers = 1,
canJoinDuringGame = true
canJoinDuringGame = true,
showScoreboard = false,
)
)

GunCommand.register()

logger.info("[LazerTagExtension] has been enabled!")
logger.info("[LazerTag] has been enabled!")
}

override fun terminate() {
GunCommand.unregister()

logger.info("[LazerTagExtension] has been disabled!")
logger.info("[LazerTag] has been disabled!")
}

}
2 changes: 1 addition & 1 deletion src/main/kotlin/emortal/lazertag/commands/GunCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package emortal.lazertag.commands

import emortal.lazertag.gun.Gun
import emortal.lazertag.gun.Gun.Companion.heldGun
import emortal.lazertag.gun.ProjectileGun
import net.minestom.server.command.builder.arguments.ArgumentType
import world.cepi.kstom.command.arguments.suggest
import world.cepi.kstom.command.kommand.Kommand
Expand All @@ -13,7 +14,6 @@ object GunCommand : Kommand({

syntax(gunArg) {
val gun = context.get(gunArg).joinToString(separator = " ")
println(gun)
player.heldGun = Gun.registeredMap[gun]
}
}, "gun")
49 changes: 27 additions & 22 deletions src/main/kotlin/emortal/lazertag/game/LazerTagGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import emortal.lazertag.gun.Gun.Companion.ammoTag
import emortal.lazertag.gun.Gun.Companion.heldGun
import emortal.lazertag.gun.Gun.Companion.lastShotTag
import emortal.lazertag.gun.Gun.Companion.reloadingTag
import emortal.lazertag.gun.ProjectileGun
import emortal.lazertag.utils.cancel
import emortal.lazertag.utils.setCooldown
import net.kyori.adventure.sound.Sound
import net.kyori.adventure.text.Component
Expand All @@ -35,6 +37,7 @@ import net.minestom.server.event.player.*
import net.minestom.server.instance.AnvilLoader
import net.minestom.server.instance.Instance
import net.minestom.server.item.ItemMetaBuilder
import net.minestom.server.message.Messenger.sendMessage
import net.minestom.server.scoreboard.Sidebar
import net.minestom.server.sound.SoundEvent
import net.minestom.server.tag.Tag
Expand All @@ -45,6 +48,7 @@ import world.cepi.kstom.adventure.asMini
import world.cepi.kstom.event.listenOnly
import world.cepi.kstom.item.and
import world.cepi.kstom.util.MinestomRunnable
import world.cepi.kstom.util.intersectAny
import world.cepi.kstom.util.playSound
import java.text.DecimalFormat
import java.time.Duration
Expand Down Expand Up @@ -89,7 +93,6 @@ class LazerTagGame(gameOptions: GameOptions) : PvpGame(gameOptions) {
player.setTag(deathsTag, 0)

player.respawnPoint = getRandomRespawnPosition()
if (player.instance!! != instance) player.setInstance(instance)

}

Expand Down Expand Up @@ -377,36 +380,37 @@ class LazerTagGame(gameOptions: GameOptions) : PvpGame(gameOptions) {
val shooter: Player = Manager.connection.getPlayer(UUID.fromString(entity.getTag(Gun.playerUUIDTag)))!!
val gun = Gun.registeredMap[entity.getTag(Gun.gunIdTag)!!] ?: return@listenOnly

if (gun !is ProjectileGun) return@listenOnly

// TODO: Better collisions
if (entity.velocity.x() == 0.0 || entity.velocity.y() == 0.0 || entity.velocity.z() == 0.0) {

if (entity.velocity.x == 0.0 || entity.velocity.y == 0.0 || entity.velocity.z == 0.0) {
gun.collide(shooter, entity)
return@listenOnly
}
if (entity.aliveTicks > 20 * 3) {
gun.collide(shooter, entity)
return@listenOnly
}
}

listenOnly<PlayerBlockBreakEvent> {
isCancelled = true
val intersectingPlayers = players
.filter { entity.boundingBox.intersect(it.boundingBox) && it.gameMode == GameMode.ADVENTURE }
// TODO: Make shooter not collide for first second .filter { it != shooter && }
if (intersectingPlayers.isEmpty()) return@listenOnly

gun.collideEntity(shooter, entity, intersectingPlayers)
}

cancel<PlayerBlockBreakEvent>()
cancel<InventoryPreClickEvent>()
cancel<PlayerBlockBreakEvent>()
cancel<PlayerBlockPlaceEvent>()
cancel<ItemDropEvent>()

listenOnly<PlayerChangeHeldSlotEvent> {
isCancelled = true
player.setHeldItemSlot(0)
}
listenOnly<InventoryPreClickEvent> {
isCancelled = true
}
listenOnly<PlayerBlockBreakEvent> {
isCancelled = true
}
listenOnly<PlayerBlockPlaceEvent> {
println("cancelled!")
isCancelled = true
}
listenOnly<ItemDropEvent> {
isCancelled = true
}

listenOnly<PlayerSwapItemEvent> {
isCancelled = true
Expand Down Expand Up @@ -441,7 +445,8 @@ class LazerTagGame(gameOptions: GameOptions) : PvpGame(gameOptions) {
Sound.Source.PLAYER,
1f,
1f
)
),
Sound.Emitter.self()
)
}.delay(Duration.ofMillis(50 * 3L)).schedule()

Expand All @@ -457,10 +462,10 @@ class LazerTagGame(gameOptions: GameOptions) : PvpGame(gameOptions) {
}

gun.renderAmmo(player, gun.ammo - i)
player.itemInMainHand = player.itemInMainHand.withMeta { meta: ItemMetaBuilder ->
meta.set(ammoTag, gun.ammo - i)
player.itemInMainHand = player.itemInMainHand.and {
this.set(ammoTag, gun.ammo - i)
}
player.playSound(Sound.sound(SoundEvent.ENTITY_ITEM_PICKUP, Sound.Source.PLAYER, 1f, 1f))
player.playSound(Sound.sound(SoundEvent.ENTITY_ITEM_PICKUP, Sound.Source.PLAYER, 1f, 1f), Sound.Emitter.self())

i--
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/emortal/lazertag/gun/BeeCannon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import net.minestom.server.entity.damage.DamageType
import net.minestom.server.item.ItemMetaBuilder
import net.minestom.server.item.Material
import net.minestom.server.sound.SoundEvent
import net.minestom.server.tag.Tag
import net.minestom.server.utils.time.TimeUnit
import world.cepi.kstom.Manager
import world.cepi.kstom.util.eyePosition
Expand All @@ -21,7 +20,7 @@ import world.cepi.particle.data.OffsetAndSpeed
import world.cepi.particle.showParticle
import kotlin.math.min

object BeeCannon : Gun("Bee Launcher") {
object BeeCannon : ProjectileGun("Bee Launcher") {

override val material: Material = Material.HONEYCOMB
override val color: TextColor = NamedTextColor.YELLOW
Expand Down Expand Up @@ -60,7 +59,7 @@ object BeeCannon : Gun("Bee Launcher") {
)
}.repeat(1, TimeUnit.SERVER_TICK).schedule()

projectile.setTag(Tag.Integer("taskID"), tickTask.id)
projectile.setTag(taskIdTag, tickTask.id)

val newAmmo = player.itemInMainHand.meta.getTag(ammoTag)!! - 1
renderAmmo(player, newAmmo)
Expand All @@ -71,22 +70,22 @@ object BeeCannon : Gun("Bee Launcher") {
return damageMap
}

override fun collide(player: Player, projectile: Entity) {
player.instance!!.showParticle(
override fun collide(shooter: Player, projectile: Entity) {
shooter.instance!!.showParticle(
Particle.particle(
type = ParticleType.EXPLOSION_EMITTER,
count = 1,
data = OffsetAndSpeed(0f, 0f, 0f, 0f),
),
projectile.position.asVec()
)
player.instance!!.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.PLAYER, 1f, 1f))
shooter.instance!!.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.PLAYER, 1f, 1f))

val boundingBox = projectile.boundingBox.expand(8.0, 8.0, 8.0)

Manager.scheduler.getTask(projectile.getTag(Tag.Integer("taskID"))!!).cancel()
Manager.scheduler.getTask(projectile.getTag(taskIdTag)!!).cancel()

player.instance!!.entities
shooter.instance!!.entities
.filterIsInstance<Player>()
.filter { it.gameMode == GameMode.ADVENTURE }
.filter { boundingBox.intersect(it.boundingBox) }
Expand All @@ -96,11 +95,11 @@ object BeeCannon : Gun("Bee Launcher") {

loopedPlayer.scheduleNextTick {
loopedPlayer.damage(
DamageType.fromPlayer(player),
DamageType.fromPlayer(shooter),
min(
damage / (projectile.getDistance(loopedPlayer) / 1.75).toFloat(),
damage
).coerceAtMost(if (loopedPlayer == player) 5f else 20f)
).coerceAtMost(if (loopedPlayer == shooter) 5f else 20f)
)
}
}
Expand Down
40 changes: 25 additions & 15 deletions src/main/kotlin/emortal/lazertag/gun/BeeShotgun.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ import net.minestom.server.tag.Tag
import net.minestom.server.utils.time.TimeUnit
import world.cepi.kstom.Manager
import world.cepi.kstom.util.eyePosition
import world.cepi.kstom.util.playSound
import world.cepi.kstom.util.spread
import world.cepi.particle.Particle
import world.cepi.particle.ParticleType
import world.cepi.particle.data.OffsetAndSpeed
import world.cepi.particle.showParticle
import kotlin.math.min

object BeeShotgun : Gun("Bee Keeper") {
object BeeShotgun : ProjectileGun("Bee Keeper") {

override val material: Material = Material.BEEHIVE
override val color: TextColor = NamedTextColor.YELLOW

override val damage = 6f
override val numberOfBullets = 7
override val spread = 0.2
override val spread = 0.15
override val cooldown = 700L
override val ammo = 4
override val reloadTime = 1500L
Expand All @@ -46,6 +48,8 @@ object BeeShotgun : Gun("Bee Keeper") {
val velocity = player.position.direction().spread(spread).mul(24.0)
projectile.velocity = velocity

projectile.boundingBox = projectile.boundingBox.expand(0.5, 0.5, 0.5)

projectile.setNoGravity(true)
projectile.setInstance(player.instance!!, player.eyePosition())

Expand All @@ -57,7 +61,7 @@ object BeeShotgun : Gun("Bee Keeper") {
//player.instance!!.sendParticle(ParticleUtils.particle(Particle.LARGE_SMOKE, projectile.position, Vec.ZERO, 1, 0f))
}.repeat(1, TimeUnit.SERVER_TICK).schedule()

projectile.setTag(Tag.Integer("taskID"), tickTask.id)
projectile.setTag(taskIdTag, tickTask.id)
}

val newAmmo = player.itemInMainHand.meta.getTag(ammoTag)!! - 1
Expand All @@ -69,28 +73,34 @@ object BeeShotgun : Gun("Bee Keeper") {
return HashMap()
}

override fun collide(player: Player, projectile: Entity) {
player.instance!!.showParticle(
override fun collide(shooter: Player, projectile: Entity) {
shooter.instance!!.showParticle(
Particle.particle(
type = ParticleType.EXPLOSION,
count = 1,
data = OffsetAndSpeed(0f, 0f, 0f, 0f),
),
projectile.position.asVec()
)
player.instance!!.playSound(Sound.sound(SoundEvent.ENTITY_BEE_STING, Sound.Source.PLAYER, 1f, 1f))
shooter.instance!!.playSound(Sound.sound(SoundEvent.ENTITY_ITEM_PICKUP, Sound.Source.PLAYER, 0.25f, 1.5f), projectile.position)

Manager.scheduler.getTask(projectile.getTag(taskIdTag)!!).cancel()

Manager.scheduler.getTask(projectile.getTag(Tag.Integer("taskID"))!!).cancel()
shooter.instance!!.players
.filter { it.gameMode == GameMode.ADVENTURE }
.filter { projectile.boundingBox.intersect(it.boundingBox) }
.forEach { loopedPlayer ->
if (loopedPlayer == shooter && projectile.aliveTicks < 20) return@forEach

val boundingBox = projectile.boundingBox.expand(5.0, 5.0, 5.0)
for (entity in player.instance!!.entities.filter { boundingBox.intersect(it.boundingBox) && it is Player && it.gameMode == GameMode.ADVENTURE }) {
entity.scheduleNextTick {
(entity as Player).damage(
DamageType.fromPlayer(player),
(damage / (projectile.getDistanceSquared(entity) / 1.75).toFloat()).coerceAtMost(damage)
)
shooter.instance!!.playSound(Sound.sound(SoundEvent.ENTITY_BEE_STING, Sound.Source.PLAYER, 1f, 1f), projectile.position)

loopedPlayer.scheduleNextTick {
loopedPlayer.damage(
DamageType.fromPlayer(shooter),
(damage / (projectile.getDistanceSquared(it) / 1.75).toFloat()).coerceAtMost(damage)
)
}
}
}

projectile.remove()
}
Expand Down
26 changes: 20 additions & 6 deletions src/main/kotlin/emortal/lazertag/gun/Crossbow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import net.kyori.adventure.text.format.TextColor
import net.minestom.server.entity.Entity
import net.minestom.server.entity.EntityType
import net.minestom.server.entity.Player
import net.minestom.server.entity.damage.DamageType
import net.minestom.server.entity.metadata.arrow.ArrowMeta
import net.minestom.server.entity.metadata.arrow.SpectralArrowMeta
import net.minestom.server.item.ItemMetaBuilder
import net.minestom.server.item.Material
Expand All @@ -17,7 +19,7 @@ import world.cepi.particle.ParticleType
import world.cepi.particle.data.OffsetAndSpeed
import world.cepi.particle.showParticle

object Crossbow : Gun("Crossbow") {
object Crossbow : ProjectileGun("Crossbow") {

override val material: Material = Material.BOW
override val color: TextColor = NamedTextColor.GOLD
Expand All @@ -32,8 +34,8 @@ object Crossbow : Gun("Crossbow") {
override fun shoot(player: Player): HashMap<Player, Float> {
val damageMap = HashMap<Player, Float>()

val projectile = Entity(EntityType.SPECTRAL_ARROW)
val projectilemeta = projectile.entityMeta as SpectralArrowMeta
val projectile = Entity(EntityType.ARROW)
val projectilemeta = projectile.entityMeta as ArrowMeta

val velocity = player.position.direction().mul(50.0)
projectile.velocity = velocity
Expand All @@ -52,21 +54,33 @@ object Crossbow : Gun("Crossbow") {
return damageMap
}

override fun collide(player: Player, projectile: Entity) {
player.instance!!.showParticle(
override fun collide(shooter: Player, projectile: Entity) {
shooter.instance!!.showParticle(
Particle.particle(
type = ParticleType.EXPLOSION,
count = 1,
data = OffsetAndSpeed(0f, 0f, 0f, 0f),
),
projectile.position.asVec()
)
player.instance!!.playSound(
shooter.instance!!.playSound(
Sound.sound(SoundEvent.ENTITY_ARROW_HIT, Sound.Source.PLAYER, 1f, 1f),
projectile.position
)

projectile.remove()
}

override fun collideEntity(shooter: Player, projectile: Entity, hitPlayers: Collection<Player>) {

hitPlayers.forEach {
it.scheduleNextTick { _ ->
it.damage(DamageType.fromPlayer(shooter), damage)
}
}

projectile.remove()

}

}
Loading

0 comments on commit 8cbce2a

Please sign in to comment.