From db0426daeb06bb7c39774af39846a444810d53e2 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 23 Aug 2021 18:05:04 +0100 Subject: [PATCH] Added spelunking effect --- .../com/willfp/ecoskills/effects/Effects.java | 2 + .../effects/effects/EffectSpelunking.kt | 82 +++++++++++++++++++ .../src/main/resources/effects.yml | 29 ++++++- .../src/main/resources/skills/mining.yml | 11 +++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectSpelunking.kt diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java index 1e4ffa5..4bc3982 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java @@ -19,6 +19,7 @@ import com.willfp.ecoskills.effects.effects.EffectSeamlessMovement; import com.willfp.ecoskills.effects.effects.EffectSecondChance; import com.willfp.ecoskills.effects.effects.EffectSerratedStrikes; import com.willfp.ecoskills.effects.effects.EffectShamanism; +import com.willfp.ecoskills.effects.effects.EffectSpelunking; import com.willfp.ecoskills.effects.effects.EffectStrongImpact; import com.willfp.ecoskills.effects.effects.EffectVersatileTools; import org.bukkit.NamespacedKey; @@ -56,6 +57,7 @@ public class Effects { public static final Effect DAZZLE = new EffectDazzle(); public static final Effect STRONG_IMPACT = new EffectStrongImpact(); public static final Effect ENDANGERING = new EffectEndangering(); + public static final Effect SPELUNKING = new EffectSpelunking(); @ApiStatus.Internal public static void registerNewEffect(@NotNull final Effect effect) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectSpelunking.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectSpelunking.kt new file mode 100644 index 0000000..690e50e --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectSpelunking.kt @@ -0,0 +1,82 @@ +package com.willfp.ecoskills.effects.effects + +import com.willfp.eco.core.drops.DropQueue +import com.willfp.eco.util.NumberUtils +import com.willfp.ecoskills.effects.Effect +import com.willfp.ecoskills.getEffectLevel +import org.bukkit.Material +import org.bukkit.block.data.Ageable +import org.bukkit.enchantments.Enchantment +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.block.BlockDropItemEvent + +class EffectSpelunking: Effect( + "spelunking" +) { + override fun formatDescription(string: String, level: Int): String { + return string.replace("%chance%", NumberUtils.format(this.getChance(level))) + .replace("%multiplier%", this.getMultiplier(level).toString()) + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun handle(event: BlockDropItemEvent) { + val block = event.block + val player = event.player + + if (player.inventory.itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH)) { + return + } + + if (!config.getStrings("on-blocks").contains(block.type.name.lowercase())) { + return + } + + if (event.items.isEmpty()) { + return + } + + val level = player.getEffectLevel(this) + + val chance = getChance(level) + + val multiplier = getMultiplier(level) + + if (multiplier >= 2) { + for (i in 2..multiplier) { + DropQueue(player) + .addItems(*event.items.map { item -> item.itemStack }) + .push() + } + } + + if (NumberUtils.randFloat(0.0, 100.0) < chance) { + DropQueue(player) + .addItems(*event.items.map { item -> item.itemStack }) + .push() + } + } + + private fun getMultiplier(level: Int): Int { + val chance = config.getDouble("chance-per-level") * level + + var add = 2 + + if (chance % 100 == 0.0) { + add = 1 + } + + return (chance / 100).toInt() + add + } + + private fun getChance(level: Int): Double { + var chance = config.getDouble("chance-per-level") * level + + chance -= ((getMultiplier(level) - 2) * 100) + if (chance == 0.0) { + chance = 100.0 + } + + return chance + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/effects.yml b/eco-core/core-plugin/src/main/resources/effects.yml index 9c34862..d80cd9e 100644 --- a/eco-core/core-plugin/src/main/resources/effects.yml +++ b/eco-core/core-plugin/src/main/resources/effects.yml @@ -144,4 +144,31 @@ endangering: description: "&a%chance%%&8 chance to remove your opponents invulnerability frame" # The chance as a percentage - chance-per-level: 3 \ No newline at end of file + chance-per-level: 3 +spelunking: + description: "&a%chance%%&8 to get &a%multiplier%x&8 drops from ores" + + # The ores that can drop double + on-blocks: + - "nether_quartz_ore" + - "coal_ore" + - "deepslate_coal_ore" + - "iron_ore" + - "deepslate_iron_ore" + - "gold_ore" + - "deepslate_gold_ore" + - "gilded_blackstone" + - "lapis_lazuli_ore" + - "deepslate_lapis_lazuli_ore" + - "redstone_ore" + - "deepslate_redstone_ore" + - "emerald_ore" + - "deepslate_emerald_ore" + - "diamond_ore" + - "deepslate_diamond_ore" + + + # Chance is as a percentage; if the chance for a player is over 100 then it will always be double drops + # with a chance to get triple drops. Same goes if above 200, but then it will always be triple with a chance + # for quadruple. + chance-per-level: 4 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/skills/mining.yml b/eco-core/core-plugin/src/main/resources/skills/mining.yml index 019174b..97f0f1d 100644 --- a/eco-core/core-plugin/src/main/resources/skills/mining.yml +++ b/eco-core/core-plugin/src/main/resources/skills/mining.yml @@ -15,6 +15,8 @@ gui: - "&fEffects:" - "&8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" - " %ecoskills_versatile_tools_description%" + - "&8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" rewards: # The actual rewards to be given @@ -22,6 +24,7 @@ rewards: - "defense::2" - "ferocity::1:15:100" - "versatile_tools::1" + - "spelunking::1" # The chat messages to send on level up chat-messages: @@ -29,11 +32,15 @@ rewards: - " &8» &r&f+2 %ecoskills_defense_name%" - " &8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" - " %ecoskills_versatile_tools_description%" + - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" 15: - " &8» &r&f+2 %ecoskills_defense_name%" - " &8» &r&f+1 %ecoskills_ferocity_name%" - " &8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" - " %ecoskills_versatile_tools_description%" + - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" # The lore to show in the levels gui progression-lore: @@ -41,11 +48,15 @@ rewards: - " &8» &r&f+2 %ecoskills_defense_name%" - " &8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" - " %ecoskills_versatile_tools_description%" + - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" 15: - " &8» &r&f+2 %ecoskills_defense_name%" - " &8» &r&f+1 %ecoskills_ferocity_name%" - " &8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" - " %ecoskills_versatile_tools_description%" + - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" # The xp rewards for each block type # Specify with type:xp