Add sounds and fix Shotgun bug
This commit is contained in:
parent
a5ad5709c1
commit
d5e92e4fc6
9 changed files with 116 additions and 19 deletions
|
@ -3,6 +3,8 @@ package de.moritzruth.spigot_ttt
|
|||
import org.bukkit.Material
|
||||
|
||||
object ResourcePack {
|
||||
private const val NAMESPACE = "ttt:"
|
||||
|
||||
object Items {
|
||||
val textureless = Material.WHITE_STAINED_GLASS_PANE
|
||||
val deathReason = Material.GRAY_STAINED_GLASS_PANE
|
||||
|
@ -18,7 +20,7 @@ object ResourcePack {
|
|||
val jackal = Material.LIGHT_BLUE_STAINED_GLASS_PANE
|
||||
val sidekick = Material.BLUE_STAINED_GLASS_PANE
|
||||
|
||||
// Special Items
|
||||
// Special Item
|
||||
val cloakingDevice = Material.COBWEB
|
||||
val radar = Material.IRON_HELMET
|
||||
val teleporter = Material.SPRUCE_WOOD
|
||||
|
@ -41,5 +43,74 @@ object ResourcePack {
|
|||
object Sounds {
|
||||
const val error = "minecraft:block.anvil.break"
|
||||
const val grenadeExplode = "minecraft:entity.generic.explode"
|
||||
const val playerDeath = "${NAMESPACE}player_death"
|
||||
|
||||
object Item {
|
||||
private const val PREFIX = NAMESPACE + "item."
|
||||
|
||||
object Weapon {
|
||||
private const val PREFIX = Item.PREFIX + "weapon."
|
||||
|
||||
object Pistol {
|
||||
private const val PREFIX = Weapon.PREFIX + "pistol."
|
||||
|
||||
const val fire = "${PREFIX}fire"
|
||||
const val reload = "${PREFIX}reload"
|
||||
}
|
||||
|
||||
object Glock {
|
||||
private const val PREFIX = Weapon.PREFIX + "glock."
|
||||
|
||||
const val fire = "${PREFIX}fire"
|
||||
const val reload = "${PREFIX}reload"
|
||||
}
|
||||
|
||||
object Deagle {
|
||||
private const val PREFIX = Weapon.PREFIX + "deagle."
|
||||
|
||||
const val fire = "${PREFIX}fire"
|
||||
const val reload = "${PREFIX}reload"
|
||||
}
|
||||
|
||||
object Shotgun {
|
||||
private const val PREFIX = Weapon.PREFIX + "shotgun."
|
||||
|
||||
const val fire = "${PREFIX}fire"
|
||||
const val reload = "${PREFIX}reload"
|
||||
}
|
||||
|
||||
object Rifle {
|
||||
private const val PREFIX = Weapon.PREFIX + "rifle."
|
||||
|
||||
const val fire = "${PREFIX}fire"
|
||||
const val reload = "${PREFIX}reload"
|
||||
}
|
||||
|
||||
object Generic {
|
||||
private const val PREFIX = Weapon.PREFIX + "generic."
|
||||
|
||||
const val emptyMagazine = "${PREFIX}empty_magazine"
|
||||
}
|
||||
}
|
||||
|
||||
object CloakingDevice {
|
||||
private const val PREFIX = Item.PREFIX + "cloaking_device."
|
||||
|
||||
const val on = "${PREFIX}on"
|
||||
const val off = "${PREFIX}off"
|
||||
}
|
||||
|
||||
object BaseballBat {
|
||||
private const val PREFIX = Item.PREFIX + "baseball_bat."
|
||||
|
||||
const val hit = "${PREFIX}hit"
|
||||
}
|
||||
|
||||
object Knife {
|
||||
private const val PREFIX = Item.PREFIX + "knife."
|
||||
|
||||
const val hit = "${PREFIX}hit"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import de.moritzruth.spigot_ttt.items.Selectable
|
|||
import de.moritzruth.spigot_ttt.items.TTTItem
|
||||
import de.moritzruth.spigot_ttt.utils.applyMeta
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.SoundCategory
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.player.PlayerInteractEvent
|
||||
import org.bukkit.event.player.PlayerToggleSprintEvent
|
||||
|
@ -48,6 +49,8 @@ object CloakingDevice: TTTItem,
|
|||
|
||||
// To prevent jumping (amplifier 200)
|
||||
addPotionEffect(PotionEffect(PotionEffectType.JUMP, 1000000, 200, false, false))
|
||||
|
||||
playSound(location, ResourcePack.Sounds.Item.CloakingDevice.on, SoundCategory.PLAYERS, 1F, 1F)
|
||||
}
|
||||
|
||||
tttPlayer.invisible = true
|
||||
|
@ -56,13 +59,12 @@ object CloakingDevice: TTTItem,
|
|||
tttPlayer.player.apply {
|
||||
walkSpeed = 0.2F
|
||||
removePotionEffect(PotionEffectType.JUMP)
|
||||
playSound(location, ResourcePack.Sounds.Item.CloakingDevice.off, SoundCategory.PLAYERS, 1F, 1F)
|
||||
}
|
||||
|
||||
tttPlayer.invisible = false
|
||||
state.enabled = false
|
||||
}
|
||||
|
||||
// TODO: Play sound
|
||||
}
|
||||
|
||||
override val listener = object : TTTItemListener(this, true) {
|
||||
|
|
|
@ -37,7 +37,9 @@ abstract class Gun(
|
|||
val cooldown: Double,
|
||||
val magazineSize: Int,
|
||||
val reloadTime: Double,
|
||||
val itemMaterial: Material
|
||||
val itemMaterial: Material,
|
||||
val shootSound: String,
|
||||
val reloadSound: String
|
||||
): TTTItem, Selectable, DropHandler {
|
||||
override val itemStack = ItemStack(itemMaterial).applyMeta {
|
||||
setDisplayName(displayName)
|
||||
|
@ -68,8 +70,7 @@ abstract class Gun(
|
|||
return
|
||||
}
|
||||
|
||||
// TODO: Add sound
|
||||
GameManager.world.playSound(tttPlayer.player.location, Sound.BLOCK_IRON_DOOR_OPEN, SoundCategory.PLAYERS, 2f, 1.3f)
|
||||
GameManager.world.playSound(tttPlayer.player.location, shootSound, SoundCategory.PLAYERS, 1F, 1F)
|
||||
|
||||
state.remainingShots--
|
||||
updateLevel(tttPlayer)
|
||||
|
@ -106,7 +107,7 @@ abstract class Gun(
|
|||
|
||||
state.currentAction = Action.Reloading(this, itemStack, state, tttPlayer).also { it.start() }
|
||||
|
||||
// TODO: Add sound
|
||||
GameManager.world.playSound(tttPlayer.player.location, reloadSound, SoundCategory.PLAYERS, 1F, 1F)
|
||||
}
|
||||
|
||||
open fun computeActualDamage(tttPlayer: TTTPlayer, receiver: Player) = if (damage < 0 ) 1000.0 else damage
|
||||
|
@ -210,13 +211,17 @@ abstract class Gun(
|
|||
var currentAction: Action? = null
|
||||
var remainingShots = magazineSize
|
||||
|
||||
fun reset() { currentAction?.task?.cancel() }
|
||||
fun reset() { currentAction?.reset() }
|
||||
}
|
||||
|
||||
sealed class Action(var itemStack: ItemStack) {
|
||||
val startedAt = Instant.now()!!
|
||||
abstract var task: BukkitTask; protected set
|
||||
|
||||
open fun reset() {
|
||||
task.cancel()
|
||||
}
|
||||
|
||||
open class Reloading(
|
||||
private val gun: Gun,
|
||||
itemStack: ItemStack,
|
||||
|
|
|
@ -14,7 +14,9 @@ object Deagle: Gun(
|
|||
cooldown = 1.4,
|
||||
magazineSize = 8,
|
||||
reloadTime = 3.0,
|
||||
itemMaterial = ResourcePack.Items.deagle
|
||||
itemMaterial = ResourcePack.Items.deagle,
|
||||
shootSound = ResourcePack.Sounds.Item.Weapon.Deagle.fire,
|
||||
reloadSound = ResourcePack.Sounds.Item.Weapon.Deagle.reload
|
||||
), Spawning {
|
||||
override val type = TTTItem.Type.PISTOL_LIKE
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ object Glock: Gun(
|
|||
cooldown = 0.3,
|
||||
magazineSize = 20,
|
||||
reloadTime = 2.0,
|
||||
itemMaterial = ResourcePack.Items.glock
|
||||
itemMaterial = ResourcePack.Items.glock,
|
||||
shootSound = ResourcePack.Sounds.Item.Weapon.Glock.fire,
|
||||
reloadSound = ResourcePack.Sounds.Item.Weapon.Glock.reload
|
||||
), Spawning {
|
||||
override val type = TTTItem.Type.PISTOL_LIKE
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ object Pistol: Gun(
|
|||
cooldown = 0.8,
|
||||
magazineSize = 10,
|
||||
reloadTime = 2.0,
|
||||
itemMaterial = ResourcePack.Items.pistol
|
||||
itemMaterial = ResourcePack.Items.pistol,
|
||||
shootSound = ResourcePack.Sounds.Item.Weapon.Pistol.fire,
|
||||
reloadSound = ResourcePack.Sounds.Item.Weapon.Pistol.reload
|
||||
), Spawning {
|
||||
override val type = TTTItem.Type.PISTOL_LIKE
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ object Rifle: Gun(
|
|||
cooldown = 0.1,
|
||||
magazineSize = 40,
|
||||
reloadTime = 2.0,
|
||||
itemMaterial = ResourcePack.Items.rifle
|
||||
itemMaterial = ResourcePack.Items.rifle,
|
||||
shootSound = ResourcePack.Sounds.Item.Weapon.Rifle.fire,
|
||||
reloadSound = ResourcePack.Sounds.Item.Weapon.Rifle.reload
|
||||
), Spawning {
|
||||
override val type = TTTItem.Type.HEAVY_WEAPON
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.moritzruth.spigot_ttt.items.weapons.guns.impl
|
||||
|
||||
import de.moritzruth.spigot_ttt.ResourcePack
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.items.Spawning
|
||||
import de.moritzruth.spigot_ttt.items.TTTItem
|
||||
|
@ -10,6 +11,7 @@ import de.moritzruth.spigot_ttt.utils.heartsToHealth
|
|||
import de.moritzruth.spigot_ttt.utils.secondsToTicks
|
||||
import de.moritzruth.spigot_ttt.utils.startItemDamageProgress
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.SoundCategory
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
|
@ -23,11 +25,13 @@ object Shotgun: Gun(
|
|||
stateClass = State::class,
|
||||
displayName = "${ChatColor.YELLOW}${ChatColor.BOLD}Shotgun",
|
||||
damage = heartsToHealth(3.0),
|
||||
cooldown = 0.8,
|
||||
cooldown = 0.9,
|
||||
magazineSize = MAGAZINE_SIZE,
|
||||
reloadTime = RELOAD_TIME_PER_BULLET * MAGAZINE_SIZE,
|
||||
itemMaterial = ResourcePack.Items.shotgun,
|
||||
additionalLore = listOf("${ChatColor.RED}Weniger Schaden auf Distanz")
|
||||
additionalLore = listOf("${ChatColor.RED}Weniger Schaden auf Distanz"),
|
||||
shootSound = ResourcePack.Sounds.Item.Weapon.Shotgun.fire,
|
||||
reloadSound = ResourcePack.Sounds.Item.Weapon.Shotgun.reload
|
||||
), Spawning {
|
||||
override val type = TTTItem.Type.HEAVY_WEAPON
|
||||
|
||||
|
@ -35,7 +39,7 @@ object Shotgun: Gun(
|
|||
val distance = tttPlayer.player.location.distance(receiver.location)
|
||||
|
||||
return when {
|
||||
distance <= 2 -> heartsToHealth(10.0)
|
||||
distance <= 1 -> heartsToHealth(8.0)
|
||||
distance >= 14 -> 0.0
|
||||
distance > 8 -> heartsToHealth(1.5)
|
||||
else -> heartsToHealth(damage)
|
||||
|
@ -61,6 +65,7 @@ object Shotgun: Gun(
|
|||
|
||||
override fun reload(tttPlayer: TTTPlayer, itemStack: ItemStack, state: Gun.State) {
|
||||
val ownState = state as State
|
||||
if (ownState.currentAction != null) throw ActionInProgressError()
|
||||
if (ownState.remainingShots == magazineSize) return
|
||||
|
||||
ownState.currentAction = ReloadingAction(itemStack, ownState, tttPlayer).also { it.start() }
|
||||
|
@ -73,9 +78,8 @@ object Shotgun: Gun(
|
|||
when(val currentAction = ownState.currentAction) {
|
||||
is Action.Cooldown -> throw ActionInProgressError()
|
||||
is ReloadingAction -> {
|
||||
currentAction.reset()
|
||||
ownState.currentAction = null
|
||||
currentAction.updateTask.cancel()
|
||||
currentAction.task.cancel()
|
||||
|
||||
val damageMeta = item.itemMeta!! as Damageable
|
||||
damageMeta.damage = 0
|
||||
|
@ -91,6 +95,11 @@ object Shotgun: Gun(
|
|||
private class ReloadingAction(itemStack: ItemStack, state: State, tttPlayer: TTTPlayer): Action.Reloading(Shotgun, itemStack, state, tttPlayer) {
|
||||
lateinit var updateTask: BukkitTask
|
||||
|
||||
override fun reset() {
|
||||
task.cancel()
|
||||
updateTask.cancel()
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
task = startItemDamageProgress(
|
||||
itemStack,
|
||||
|
@ -102,7 +111,7 @@ object Shotgun: Gun(
|
|||
state.remainingShots++
|
||||
updateLevel(tttPlayer)
|
||||
|
||||
// TODO: Add sound
|
||||
GameManager.world.playSound(tttPlayer.player.location, reloadSound, SoundCategory.PLAYERS, 1F, 1F)
|
||||
|
||||
if (state.remainingShots == magazineSize) {
|
||||
this.updateTask.cancel()
|
||||
|
|
|
@ -21,7 +21,9 @@ object SidekickDeagle: Gun(
|
|||
cooldown = 1.0,
|
||||
magazineSize = 1,
|
||||
reloadTime = 0.0,
|
||||
itemMaterial = ResourcePack.Items.sidekickDeagle
|
||||
itemMaterial = ResourcePack.Items.sidekickDeagle,
|
||||
shootSound = ResourcePack.Sounds.Item.Weapon.Deagle.fire,
|
||||
reloadSound = ResourcePack.Sounds.Item.Weapon.Deagle.reload
|
||||
), Buyable {
|
||||
override val buyableBy = roles(Role.JACKAL)
|
||||
override val price = 1
|
||||
|
|
Reference in a new issue