From bcb65141bd2fa03ea81e0c0a568285609128492c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 23 Aug 2021 14:21:44 +0100 Subject: [PATCH] Added endangering effect --- .../com/willfp/ecoskills/effects/Effects.java | 2 + .../effects/effects/EffectEndangering.kt | 52 +++++++++++++++++++ .../src/main/resources/effects.yml | 7 ++- .../src/main/resources/skills/combat.yml | 25 +++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEndangering.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 66e0d07..1e4ffa5 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 @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.ecoskills.effects.effects.EffectAcceleratedEscape; import com.willfp.ecoskills.effects.effects.EffectBountifulHarvest; +import com.willfp.ecoskills.effects.effects.EffectEndangering; import com.willfp.ecoskills.effects.effects.EffectInfernalResistance; import com.willfp.ecoskills.effects.effects.EffectCraftsmanship; import com.willfp.ecoskills.effects.effects.EffectDazzle; @@ -54,6 +55,7 @@ public class Effects { public static final Effect INFERNAL_RESISTANCE = new EffectInfernalResistance(); public static final Effect DAZZLE = new EffectDazzle(); public static final Effect STRONG_IMPACT = new EffectStrongImpact(); + public static final Effect ENDANGERING = new EffectEndangering(); @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/EffectEndangering.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEndangering.kt new file mode 100644 index 0000000..bff597a --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEndangering.kt @@ -0,0 +1,52 @@ +package com.willfp.ecoskills.effects.effects + +import com.willfp.eco.util.NumberUtils +import com.willfp.ecoskills.effects.Effect +import com.willfp.ecoskills.getEffectLevel +import org.bukkit.entity.LivingEntity +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageByEntityEvent + + +class EffectEndangering : Effect( + "endangering" +) { + override fun formatDescription(string: String, level: Int): String { + return string.replace("%chance%", NumberUtils.format(config.getDouble("chance-per-level") * level)) + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun handle(event: EntityDamageByEntityEvent) { + var player = event.damager + val victim = event.entity + + if (victim !is LivingEntity) { + return + } + + if (player is Projectile) { + if (player.shooter !is Player) { + return + } else { + player = player.shooter as Player + } + } + + if (player !is Player) { + return + } + + val level = player.getEffectLevel(this) + + if (NumberUtils.randFloat(0.0, 100.0) >= config.getDouble("chance-per-level") * level) { + return + } + + this.plugin.run { + victim.noDamageTicks = 0 + } + } +} \ 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 41d9667..9c34862 100644 --- a/eco-core/core-plugin/src/main/resources/effects.yml +++ b/eco-core/core-plugin/src/main/resources/effects.yml @@ -139,4 +139,9 @@ strong_impact: # The damage multiplier multiplier: 3 # The chance to deal 3x damage, per level - chance-per-level: 0.2 \ No newline at end of file + chance-per-level: 0.2 +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 diff --git a/eco-core/core-plugin/src/main/resources/skills/combat.yml b/eco-core/core-plugin/src/main/resources/skills/combat.yml index 9a61ccc..460b8a8 100644 --- a/eco-core/core-plugin/src/main/resources/skills/combat.yml +++ b/eco-core/core-plugin/src/main/resources/skills/combat.yml @@ -19,6 +19,8 @@ gui: - " %ecoskills_dazzle_description%" - "&8» &r&6Strong Impact %ecoskills_strong_impact_numeral%" - " %ecoskills_strong_impact_description%" + - "&8» &r&6Endangering %ecoskills_endangering_numeral%" + - " %ecoskills_endangering_description%" rewards: # The actual rewards to be given @@ -28,6 +30,7 @@ rewards: - "serrated_strikes::1" - "dazzle::1" - "strong_impact::1:10:100" + - "endangering::1:20:100" # The chat messages to send on level up chat-messages: @@ -54,6 +57,17 @@ rewards: - " %ecoskills_dazzle_description%" - " &8» &r&6Strong Impact %ecoskills_strong_impact_numeral%" - " %ecoskills_strong_impact_description%" + 20: + - " &8» &r&f+2 %ecoskills_strength_name%" + - " &8» &r&f+1 %ecoskills_ferocity_name%" + - " &8» &r&6Serrated Strikes %ecoskills_serrated_strikes_numeral%" + - " %ecoskills_serrated_strikes_description%" + - " &8» &r&6Dazzle %ecoskills_dazzle_numeral%" + - " %ecoskills_dazzle_description%" + - " &8» &r&6Strong Impact %ecoskills_strong_impact_numeral%" + - " %ecoskills_strong_impact_description%" + - " &8» &r&6Endangering %ecoskills_endangering_numeral%" + - " %ecoskills_endangering_description%" # The lore to show in the levels gui progression-lore: @@ -81,6 +95,17 @@ rewards: - " %ecoskills_dazzle_description%" - " &8» &r&6Strong Impact %ecoskills_strong_impact_numeral%" - " %ecoskills_strong_impact_description%" + 20: + - " &8» &r&f+2 %ecoskills_strength_name%" + - " &8» &r&f+1 %ecoskills_ferocity_name%" + - " &8» &r&6Serrated Strikes %ecoskills_serrated_strikes_numeral%" + - " %ecoskills_serrated_strikes_description%" + - " &8» &r&6Dazzle %ecoskills_dazzle_numeral%" + - " %ecoskills_dazzle_description%" + - " &8» &r&6Strong Impact %ecoskills_strong_impact_numeral%" + - " %ecoskills_strong_impact_description%" + - " &8» &r&6Endangering %ecoskills_endangering_numeral%" + - " %ecoskills_endangering_description%" # The experience to give for each hp of a killed enemy