9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-01 21:36:34 +00:00

Added spelunking effect

This commit is contained in:
Auxilor
2021-08-23 18:05:04 +01:00
parent 71d45142ed
commit db0426daeb
4 changed files with 123 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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
}
}

View File

@@ -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
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

View File

@@ -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