Add tree gun
This commit is contained in:
parent
b81e6913fc
commit
3e1ce8cc4e
15 changed files with 201 additions and 30 deletions
|
@ -36,6 +36,7 @@ object Resourcepack {
|
|||
// Weapons
|
||||
val deagle = Material.IRON_HOE
|
||||
val sidekickDeagle = Material.GOLDEN_HOE
|
||||
val treeGun = Material.OAK_SAPLING
|
||||
val glock = Material.STONE_HOE
|
||||
val pistol = Material.WOODEN_HOE
|
||||
val shotgun = Material.IRON_AXE
|
||||
|
|
|
@ -17,7 +17,7 @@ class AbortCommand: CommandExecutor {
|
|||
}
|
||||
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (GameManager.phase === null) {
|
||||
if (GameManager.phase == null) {
|
||||
val tttWorld = GameManager.tttWorld
|
||||
if (tttWorld == null)
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Zurzeit läuft kein Spiel.")
|
||||
|
|
|
@ -97,8 +97,6 @@ object GameManager {
|
|||
fun reset() {
|
||||
CorpseManager.destroyAll()
|
||||
ItemManager.reset()
|
||||
tttWorld?.unload()
|
||||
tttWorld = null
|
||||
}
|
||||
|
||||
fun abortGame(broadcast: Boolean = false) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.bukkit.event.EventHandler
|
|||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.Action
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
import org.bukkit.event.entity.PlayerDeathEvent
|
||||
|
@ -84,6 +85,11 @@ object GeneralGameListener : Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onEntityDamageByBlock(event: EntityDamageByBlockEvent) {
|
||||
println(event.damager?.type)
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
fun onEntityDamageHighest(event: EntityDamageEvent) {
|
||||
if (event.entity !is Player) return
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.moritzruth.spigot_ttt.game.GameListener
|
|||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.*
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.weapons.BaseballBat
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.weapons.Fireball
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.weapons.Knife
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.weapons.guns.*
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
|
@ -30,7 +31,7 @@ object ItemManager {
|
|||
val ITEMS: Set<TTTItem<*>> = setOf(
|
||||
Deagle, Glock, Pistol, Rifle, SidekickDeagle, BaseballBat, Knife, CloakingDevice, Defibrillator,
|
||||
EnderPearl, FakeCorpse, Fireball, HealingPotion, MartyrdomGrenade, Radar, SecondChance, Teleporter,
|
||||
Shotgun, Radar, SecondChance, BoomBody
|
||||
Shotgun, Radar, SecondChance, BoomBody, TreeGun
|
||||
)
|
||||
|
||||
val listeners get () = ITEMS.mapNotNull { it.listener }.plus(listener)
|
||||
|
|
|
@ -41,9 +41,12 @@ open class TTTItem<InstanceT: TTTItem.Instance>(
|
|||
it.carrier?.removeItem(it.tttItem, removeInstance = false)
|
||||
it.remove()
|
||||
}
|
||||
|
||||
instancesByUUID.clear()
|
||||
}
|
||||
|
||||
open fun onReset() {}
|
||||
|
||||
fun createInstance(): InstanceT = instanceType.primaryConstructor!!.call()
|
||||
.also { instancesByUUID[it.uuid] = it }
|
||||
|
||||
|
|
|
@ -87,6 +87,8 @@ object Radar: TTTItem<Radar.Instance>(
|
|||
|
||||
override fun reset() {
|
||||
task.cancel()
|
||||
active = false
|
||||
carrier?.let { resendEntityMetadata(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.moritzruth.spigot_ttt.game.items.impl
|
|||
|
||||
import de.moritzruth.spigot_ttt.Resourcepack
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.corpses.TTTCorpse
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItem
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItemListener
|
||||
import de.moritzruth.spigot_ttt.game.players.*
|
||||
|
@ -11,13 +12,13 @@ import de.moritzruth.spigot_ttt.utils.hideInfo
|
|||
import de.moritzruth.spigot_ttt.utils.nextTick
|
||||
import de.moritzruth.spigot_ttt.utils.setAllToItem
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.boss.BarColor
|
||||
import org.bukkit.boss.BarStyle
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
import org.bukkit.inventory.Inventory
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
import java.time.Duration
|
||||
|
@ -55,13 +56,13 @@ object SecondChance: TTTItem<SecondChance.Instance>(
|
|||
var timeoutAction: TimeoutAction? = null
|
||||
lateinit var tttPlayer: TTTPlayer
|
||||
|
||||
fun possiblyTrigger() {
|
||||
if (Random.nextBoolean()) trigger()
|
||||
fun possiblyTrigger(tttCorpse: TTTCorpse?) {
|
||||
if (Random.nextBoolean()) trigger(tttCorpse)
|
||||
}
|
||||
|
||||
private fun trigger() {
|
||||
private fun trigger(tttCorpse: TTTCorpse?) {
|
||||
preventRoundEnd = true
|
||||
timeoutAction = TimeoutAction(this)
|
||||
timeoutAction = TimeoutAction(this, tttCorpse)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
|
@ -72,8 +73,7 @@ object SecondChance: TTTItem<SecondChance.Instance>(
|
|||
tttPlayer = carrier
|
||||
}
|
||||
|
||||
class TimeoutAction(private val instance: Instance) {
|
||||
val deathLocation: Location = instance.requireCarrier().player.location
|
||||
class TimeoutAction(private val instance: Instance, val tttCorpse: TTTCorpse?) {
|
||||
private val startedAt = Instant.now()!!
|
||||
private var bossBar = plugin.server.createBossBar(
|
||||
"${ChatColor.GREEN}${ChatColor.BOLD}Second Chance",
|
||||
|
@ -82,7 +82,13 @@ object SecondChance: TTTItem<SecondChance.Instance>(
|
|||
).also { it.addPlayer(instance.tttPlayer.player) }
|
||||
|
||||
init {
|
||||
instance.tttPlayer.player.openInventory(chooseSpawnInventory)
|
||||
openInventory()
|
||||
}
|
||||
|
||||
fun openInventory() {
|
||||
instance.tttPlayer.player.openInventory(
|
||||
if (tttCorpse == null) chooseSpawnWithoutCorpseInventory else chooseSpawnInventory
|
||||
)
|
||||
}
|
||||
|
||||
private var task: BukkitTask = plugin.server.scheduler.runTaskTimer(plugin, fun() {
|
||||
|
@ -120,6 +126,23 @@ object SecondChance: TTTItem<SecondChance.Instance>(
|
|||
setDisplayName("${ChatColor.GREEN}${ChatColor.BOLD}Bei der Leiche")
|
||||
})
|
||||
|
||||
setCommonItems()
|
||||
}
|
||||
|
||||
private val chooseSpawnWithoutCorpseInventory = plugin.server.createInventory(
|
||||
null,
|
||||
InventoryType.CHEST,
|
||||
"${ChatColor.DARK_RED}${ChatColor.BOLD}Second Chance"
|
||||
).apply {
|
||||
setAllToItem(setOf(0, 1, 2, 9, 10, 11, 18, 19, 20), ItemStack(ON_CORPSE).applyMeta {
|
||||
hideInfo()
|
||||
setDisplayName("${ChatColor.GREEN}${ChatColor.BOLD}Bei der Leiche ${ChatColor.RED}(NICHT VERFÜGBAR)")
|
||||
})
|
||||
|
||||
setCommonItems()
|
||||
}
|
||||
|
||||
private fun Inventory.setCommonItems() {
|
||||
setAllToItem(setOf(3, 4, 5, 12, 13, 14, 21, 22, 23), ItemStack(Resourcepack.Items.textureless).applyMeta {
|
||||
hideInfo()
|
||||
setDisplayName("${ChatColor.RESET}${ChatColor.BOLD}Wo möchtest du spawnen?")
|
||||
|
@ -135,16 +158,16 @@ object SecondChance: TTTItem<SecondChance.Instance>(
|
|||
@EventHandler
|
||||
fun onTTTPlayerTrueDeath(event: TTTPlayerTrueDeathEvent) {
|
||||
val instance = getInstance(event.tttPlayer) ?: return
|
||||
instance.possiblyTrigger()
|
||||
instance.possiblyTrigger(event.tttCorpse)
|
||||
event.winnerRoleGroup = PlayerManager.getOnlyRemainingRoleGroup()
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onInventoryClose(event: InventoryCloseEvent) {
|
||||
if (event.inventory == chooseSpawnInventory) {
|
||||
if (event.inventory === chooseSpawnInventory || event.inventory === chooseSpawnWithoutCorpseInventory) {
|
||||
nextTick {
|
||||
handleWithInstance(event) { instance ->
|
||||
instance.tttPlayer.player.openInventory(chooseSpawnInventory)
|
||||
instance.timeoutAction?.openInventory()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,14 +175,14 @@ object SecondChance: TTTItem<SecondChance.Instance>(
|
|||
|
||||
@EventHandler
|
||||
fun onInventoryClick(event: InventoryClickEvent) {
|
||||
if (event.clickedInventory != chooseSpawnInventory) return
|
||||
if (event.inventory !== chooseSpawnInventory && event.inventory !== chooseSpawnWithoutCorpseInventory) return
|
||||
|
||||
handleWithInstance(event) { instance ->
|
||||
val timeoutAction = instance.timeoutAction!!
|
||||
|
||||
val location = when (event.currentItem?.type) {
|
||||
ON_SPAWN -> GameManager.world.spawnLocation
|
||||
ON_CORPSE -> timeoutAction.deathLocation
|
||||
ON_CORPSE -> timeoutAction.tttCorpse?.location ?: return@handleWithInstance
|
||||
else -> return@handleWithInstance
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package de.moritzruth.spigot_ttt.game.items.impl
|
||||
package de.moritzruth.spigot_ttt.game.items.impl.weapons
|
||||
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.items.ClickEvent
|
||||
|
@ -12,8 +12,6 @@ import de.moritzruth.spigot_ttt.utils.clearHeldItemSlot
|
|||
import de.moritzruth.spigot_ttt.utils.createKillExplosion
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.SoundCategory
|
||||
import org.bukkit.entity.EntityType
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent
|
|
@ -4,10 +4,10 @@ import de.moritzruth.spigot_ttt.Resourcepack
|
|||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.items.ClickEvent
|
||||
import de.moritzruth.spigot_ttt.game.items.LoreHelper
|
||||
import de.moritzruth.spigot_ttt.game.items.SpawnProbability
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItem
|
||||
import de.moritzruth.spigot_ttt.game.players.DeathReason
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.items.SpawnProbability
|
||||
import de.moritzruth.spigot_ttt.utils.applyMeta
|
||||
import de.moritzruth.spigot_ttt.utils.hideInfo
|
||||
import de.moritzruth.spigot_ttt.utils.startExpProgressTask
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
package de.moritzruth.spigot_ttt.game.items.impl.weapons.guns
|
||||
|
||||
import de.moritzruth.spigot_ttt.Resourcepack
|
||||
import de.moritzruth.spigot_ttt.game.players.DeathReason
|
||||
import de.moritzruth.spigot_ttt.game.players.Role
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.players.roles
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.secondsToTicks
|
||||
import de.moritzruth.spigot_ttt.utils.sendActionBarMessage
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.block.BlockFace
|
||||
import org.bukkit.block.Sign
|
||||
import org.bukkit.block.data.type.WallSign
|
||||
import org.bukkit.potion.PotionEffect
|
||||
import org.bukkit.potion.PotionEffectType
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
|
||||
object TreeGun: Gun(
|
||||
type = Type.SPECIAL,
|
||||
instanceType = Instance::class,
|
||||
shopInfo = ShopInfo(
|
||||
buyableBy = roles(Role.JACKAL, Role.TRAITOR),
|
||||
buyLimit = 2,
|
||||
price = 1
|
||||
),
|
||||
displayName = "${ChatColor.DARK_GREEN}${ChatColor.BOLD}Tree Gun",
|
||||
itemLore = listOf(
|
||||
"",
|
||||
"${ChatColor.GOLD}Verwandelt einen Spieler nach",
|
||||
"${ChatColor.GOLD}kurzer Zeit in einen Baum",
|
||||
"",
|
||||
"${ChatColor.RED}Nur ein Schuss"
|
||||
),
|
||||
appendLore = false,
|
||||
damage = 0.1, // Not really
|
||||
cooldown = 1.0,
|
||||
magazineSize = 1,
|
||||
reloadTime = 0.0,
|
||||
material = Resourcepack.Items.treeGun,
|
||||
shootSound = Resourcepack.Sounds.Item.Weapon.Pistol.fire,
|
||||
reloadSound = Resourcepack.Sounds.Item.Weapon.Pistol.reload
|
||||
) {
|
||||
private val transmutingPlayers = mutableSetOf<TransmutingPlayer>()
|
||||
|
||||
data class TransmutingPlayer(
|
||||
val tttPlayer: TTTPlayer,
|
||||
val killer: TTTPlayer,
|
||||
val task: BukkitTask
|
||||
)
|
||||
|
||||
override fun onReset() {
|
||||
transmutingPlayers.forEach { it.task.cancel() }
|
||||
}
|
||||
|
||||
private fun spawnTree(tttPlayer: TTTPlayer) {
|
||||
val centerLocation = tttPlayer.player.location
|
||||
|
||||
for (y in 0..3) {
|
||||
centerLocation.clone().add(0.0, y.toDouble(), 0.0).block.type = Material.OAK_WOOD
|
||||
}
|
||||
|
||||
for (y in 2..3) {
|
||||
for (x in -1..1) {
|
||||
for (z in -1..1) {
|
||||
if (z == 0 && x == 0) continue
|
||||
|
||||
centerLocation.clone()
|
||||
.add(x.toDouble(), y.toDouble(), z.toDouble())
|
||||
.block.type = Material.OAK_LEAVES
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centerLocation.clone().add(0.0, 4.0, 0.0).block.type = Material.OAK_LEAVES
|
||||
|
||||
val signBlock = centerLocation.clone().add(1.0, 1.0, 0.0).block
|
||||
signBlock.type = Material.OAK_WALL_SIGN
|
||||
val data = signBlock.blockData as WallSign
|
||||
data.facing = BlockFace.EAST
|
||||
signBlock.blockData = data
|
||||
|
||||
val state = signBlock.state as Sign
|
||||
state.setLine(1, "${ChatColor.BLACK}${ChatColor.BOLD}R.I.P.")
|
||||
state.setLine(2, tttPlayer.player.name)
|
||||
state.update()
|
||||
}
|
||||
|
||||
fun startTransmuting(tttPlayer: TTTPlayer, killer: TTTPlayer) {
|
||||
transmutingPlayers.add(TransmutingPlayer(
|
||||
tttPlayer,
|
||||
killer,
|
||||
plugin.server.scheduler.runTaskLater(plugin, fun() {
|
||||
spawnTree(tttPlayer)
|
||||
tttPlayer.damage(
|
||||
1000.0,
|
||||
DeathReason.Item(TreeGun),
|
||||
killer,
|
||||
scream = false,
|
||||
spawnCorpse = false
|
||||
)
|
||||
}, secondsToTicks(6).toLong())
|
||||
))
|
||||
|
||||
tttPlayer.player.addPotionEffect(PotionEffect(
|
||||
PotionEffectType.SLOW,
|
||||
1000000,
|
||||
3,
|
||||
false,
|
||||
false
|
||||
))
|
||||
}
|
||||
|
||||
class Instance: Gun.Instance(TreeGun) {
|
||||
override fun reload() {
|
||||
requireCarrier().player.sendActionBarMessage("${ChatColor.RED}Du kannst diese Waffe nicht nachladen")
|
||||
}
|
||||
|
||||
override fun onHit(tttPlayer: TTTPlayer, hitTTTPlayer: TTTPlayer) {
|
||||
startTransmuting(hitTTTPlayer, tttPlayer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,22 +66,35 @@ class TTTPlayer(player: Player, role: Role, val tttClass: TTTClassCompanion = TT
|
|||
tttClassInstance.init()
|
||||
}
|
||||
|
||||
fun damage(damage: Double, reason: DeathReason, damager: TTTPlayer, scream: Boolean = true) {
|
||||
fun damage(
|
||||
damage: Double,
|
||||
reason: DeathReason,
|
||||
damager: TTTPlayer,
|
||||
scream: Boolean = true,
|
||||
spawnCorpse: Boolean = true
|
||||
) {
|
||||
if (!alive) return
|
||||
|
||||
val event = TTTPlayerDamageEvent(this, damage, reason).call()
|
||||
val finalHealth = player.health - event.damage
|
||||
|
||||
if (finalHealth <= 0.0) onDeath(reason, damager, scream)
|
||||
if (finalHealth <= 0.0) onDeath(reason, damager, scream, spawnCorpse)
|
||||
else player.damage(damage)
|
||||
}
|
||||
|
||||
fun onDeath(reason: DeathReason, killer: TTTPlayer?, scream: Boolean = true) {
|
||||
fun onDeath(
|
||||
reason: DeathReason,
|
||||
killer: TTTPlayer?,
|
||||
scream: Boolean = true,
|
||||
spawnCorpse: Boolean = true
|
||||
) {
|
||||
if (!alive) return
|
||||
|
||||
alive = false
|
||||
ignoreNextInteract = false
|
||||
player.gameMode = GameMode.SPECTATOR
|
||||
player.activePotionEffects.forEach { activePotionEffect -> player.removePotionEffect(activePotionEffect.type) }
|
||||
|
||||
Shop.clear(this)
|
||||
|
||||
var reallyScream = scream
|
||||
|
@ -106,7 +119,8 @@ class TTTPlayer(player: Player, role: Role, val tttClass: TTTClassCompanion = TT
|
|||
|
||||
reallyScream = event.scream
|
||||
} else {
|
||||
val tttCorpse = TTTCorpse.spawn(this, reason)
|
||||
val tttCorpse = if (spawnCorpse) TTTCorpse.spawn(this, reason) else null
|
||||
|
||||
credits = 0
|
||||
|
||||
val onlyRemainingRoleGroup = PlayerManager.getOnlyRemainingRoleGroup()
|
||||
|
@ -204,7 +218,6 @@ class TTTPlayer(player: Player, role: Role, val tttClass: TTTClassCompanion = TT
|
|||
player.level = 0
|
||||
player.exp = 0F
|
||||
player.allowFlight = player.gameMode == GameMode.CREATIVE
|
||||
player.foodLevel = 20
|
||||
|
||||
clearInventory(false)
|
||||
tttClassInstance.reset()
|
||||
|
|
|
@ -10,7 +10,7 @@ class TTTPlayerTrueDeathEvent(
|
|||
val location: Location,
|
||||
val killer: TTTPlayer?,
|
||||
val scream: Boolean = true,
|
||||
val tttCorpse: TTTCorpse,
|
||||
val tttCorpse: TTTCorpse?,
|
||||
var winnerRoleGroup: RoleGroup? = null
|
||||
): Event() {
|
||||
override fun getHandlers(): HandlerList {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.moritzruth.spigot_ttt.game.worlds
|
||||
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.ConfigurationFile
|
||||
import org.bukkit.World
|
||||
|
@ -21,8 +22,7 @@ class TTTWorld(private val sourceWorldDir: File) {
|
|||
val spawnLocations = SpawnLocationsManager(this)
|
||||
|
||||
init {
|
||||
if (world != null) unloadWorld()
|
||||
if (worldDir.exists()) worldDir.deleteRecursively()
|
||||
if (world != null) GameManager.tttWorld = this
|
||||
}
|
||||
|
||||
fun load() {
|
||||
|
|
|
@ -2,7 +2,7 @@ package de.moritzruth.spigot_ttt.utils
|
|||
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.classes.impl.Stuntman
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.Fireball
|
||||
import de.moritzruth.spigot_ttt.game.items.impl.weapons.Fireball
|
||||
import de.moritzruth.spigot_ttt.game.players.DeathReason
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import org.bukkit.Location
|
||||
|
|
Reference in a new issue