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

Added new effects and conditions, and added conditions to skills

This commit is contained in:
Auxilor
2023-05-17 15:05:54 +01:00
parent e721a02625
commit 4e8a9bb43e
17 changed files with 174 additions and 0 deletions

View File

@@ -8,12 +8,16 @@ import com.willfp.ecoskills.actionbar.ActionBarHandler
import com.willfp.ecoskills.commands.CommandEcoSkills
import com.willfp.ecoskills.commands.CommandSkills
import com.willfp.ecoskills.effects.Effects
import com.willfp.ecoskills.libreforge.ConditionHasMagic
import com.willfp.ecoskills.libreforge.ConditionHasSkillLevel
import com.willfp.ecoskills.libreforge.EffectAddStat
import com.willfp.ecoskills.libreforge.EffectAddStatTemporarily
import com.willfp.ecoskills.libreforge.EffectGiveMagic
import com.willfp.ecoskills.libreforge.EffectGiveSkillXp
import com.willfp.ecoskills.libreforge.EffectGiveSkillXpNaturally
import com.willfp.ecoskills.libreforge.EffectMakeSkillCrit
import com.willfp.ecoskills.libreforge.EffectMultiplyAllStats
import com.willfp.ecoskills.libreforge.EffectMultiplyMagic
import com.willfp.ecoskills.libreforge.EffectMultiplyStat
import com.willfp.ecoskills.libreforge.EffectMultiplyStatTemporarily
import com.willfp.ecoskills.libreforge.EffectSkillXpMultiplier
@@ -72,9 +76,13 @@ class EcoSkillsPlugin : LibreforgePlugin() {
com.willfp.libreforge.effects.Effects.register(EffectGiveSkillXp)
com.willfp.libreforge.effects.Effects.register(EffectMultiplyAllStats)
com.willfp.libreforge.effects.Effects.register(EffectMakeSkillCrit)
com.willfp.libreforge.effects.Effects.register(EffectGiveMagic)
com.willfp.libreforge.effects.Effects.register(EffectMultiplyMagic)
com.willfp.libreforge.effects.Effects.register(EffectGiveSkillXpNaturally)
com.willfp.libreforge.effects.Effects.register(EffectAddStatTemporarily(this))
com.willfp.libreforge.effects.Effects.register(EffectMultiplyStatTemporarily(this))
Conditions.register(ConditionHasSkillLevel)
Conditions.register(ConditionHasMagic)
Triggers.register(TriggerGainSkillXp)
Triggers.register(TriggerLevelUpSkill)
Filters.register(FilterSkill)

View File

@@ -0,0 +1,22 @@
package com.willfp.ecoskills.libreforge
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.api.getMagic
import com.willfp.ecoskills.magic.MagicTypes
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import org.bukkit.entity.Player
object ConditionHasMagic : Condition<NoCompileData>("has_magic") {
override val arguments = arguments {
require("type", "You must specify the magic type!")
require("amount", "You must specify the amount!")
}
override fun isMet(player: Player, config: Config, compileData: NoCompileData): Boolean {
val type = MagicTypes.getByID(config.getString("type").lowercase()) ?: return false
return player.getMagic(type) >= config.getIntFromExpression("amount", player)
}
}

View File

@@ -0,0 +1,31 @@
package com.willfp.ecoskills.libreforge
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.magic.MagicTypes
import com.willfp.ecoskills.magic.magic
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getIntFromExpression
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
object EffectGiveMagic : Effect<NoCompileData>("give_magic") {
override val parameters = setOf(
TriggerParameter.PLAYER
)
override val arguments = arguments {
require("type", "You must specify the magic type!")
require("amount", "You must specify the amount to add / subtract!")
}
override fun onTrigger(config: Config, data: TriggerData, compileData: NoCompileData): Boolean {
val player = data.player ?: return false
val type = MagicTypes.getByID(config.getString("type").lowercase()) ?: return false
player.magic[type] += config.getIntFromExpression("amount", data)
return true
}
}

View File

@@ -0,0 +1,32 @@
package com.willfp.ecoskills.libreforge
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.api.gainSkillXP
import com.willfp.ecoskills.skills.Skills
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getDoubleFromExpression
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
object EffectGiveSkillXpNaturally : Effect<NoCompileData>("give_skill_xp_naturally") {
override val parameters = setOf(
TriggerParameter.PLAYER
)
override val arguments = arguments {
require("amount", "You must specify the amount of xp to give!")
require("skill", "You must specify the skill to give xp for!")
}
override fun onTrigger(config: Config, data: TriggerData, compileData: NoCompileData): Boolean {
val player = data.player ?: return false
val skill = Skills.getByID(config.getString("skill")) ?: return false
player.gainSkillXP(skill, config.getDoubleFromExpression("amount", data))
return true
}
}

View File

@@ -0,0 +1,31 @@
package com.willfp.ecoskills.libreforge
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.magic.MagicTypes
import com.willfp.ecoskills.magic.magic
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getDoubleFromExpression
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
object EffectMultiplyMagic : Effect<NoCompileData>("multiply_magic") {
override val parameters = setOf(
TriggerParameter.PLAYER
)
override val arguments = arguments {
require("type", "You must specify the magic type!")
require("multiplier", "You must specify the multiplier!")
}
override fun onTrigger(config: Config, data: TriggerData, compileData: NoCompileData): Boolean {
val player = data.player ?: return false
val type = MagicTypes.getByID(config.getString("type").lowercase()) ?: return false
player.magic[type] = (player.magic[type] * config.getDoubleFromExpression("multiplier", data)).toInt()
return true
}
}

View File

@@ -28,6 +28,7 @@ import com.willfp.ecoskills.util.loadDescriptionPlaceholders
import com.willfp.libreforge.EmptyProvidedHolder
import com.willfp.libreforge.NamedValue
import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.counters.Counters
import com.willfp.libreforge.effects.executors.impl.NormalExecutorFactory
import com.willfp.libreforge.triggers.DispatchedTrigger
@@ -50,6 +51,11 @@ class Skill(
Counters.compile(it, ViolationContext(plugin, "Skill $id xp-gain-methods"))
}
val conditions = Conditions.compile(
config.getSubsections("conditions"),
ViolationContext(plugin, "Skill $id conditions")
)
private val xpFormula = config.getStringOrNull("xp-formula")
private val requirements = config.getDoublesOrNull("xp-requirements")

View File

@@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.integrations.afk.AFKManager
import com.willfp.ecoskills.api.gainSkillXP
import com.willfp.libreforge.EmptyProvidedHolder
import com.willfp.libreforge.counters.Accumulator
import org.bukkit.GameMode
import org.bukkit.entity.Player
@@ -23,6 +24,10 @@ class SkillXPAccumulator(
return
}
if (!skill.conditions.areMet(player, EmptyProvidedHolder)) {
return
}
player.gainSkillXP(skill, count)
}
}

View File

@@ -193,3 +193,7 @@ xp-gain-methods:
- granite
- andesite
- cobblestone
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -165,3 +165,7 @@ xp-gain-methods:
filters:
items:
- turtle_helmet
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -116,3 +116,7 @@ reward-messages:
xp-gain-methods:
- trigger: take_damage
multiplier: 1.44
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -143,3 +143,7 @@ xp-gain-methods:
multiplier: 0.33
filter:
from_spawner: false
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -120,3 +120,6 @@ xp-gain-methods:
- trigger: enchant_special # EcoEnchants integration, disable if not using.
multiplier: 175
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -118,3 +118,7 @@ xp-gain-methods:
args:
chance: 0.05
multiplier: 32
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -162,3 +162,7 @@ xp-gain-methods:
blocks:
- potatoes
- beetroot
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -100,3 +100,7 @@ reward-messages:
xp-gain-methods:
- trigger: catch_fish
multiplier: 0.1
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -262,3 +262,7 @@ xp-gain-methods:
player_placed: false
blocks:
- budding_amethyst
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]

View File

@@ -124,3 +124,7 @@ xp-gain-methods:
blocks:
- crimson_stem
- warped_stem
# Conditions that must be met to gain XP. While you can add conditions to xp
# gain methods, if you have many this can be annoying, so this is global.
conditions: [ ]