Skip to content

Commit

Permalink
Fix many source and mana ability related things
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Aug 12, 2023
1 parent 0a22f6f commit 62b4a54
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,41 +129,41 @@ public boolean optionBoolean(String key) {

@Override
public boolean optionBoolean(String key, boolean def) {
return false;
return provider.optionBoolean(this, key, def);
}

@Override
public int optionInt(String key) {
return 0;
return provider.optionInt(this, key);
}

@Override
public int optionInt(String key, int def) {
return 0;
return provider.optionInt(this, key, def);
}

@Override
public double optionDouble(String key) {
return 0;
return provider.optionDouble(this, key);
}

@Override
public double optionDouble(String key, double def) {
return 0;
return provider.optionDouble(this, key, def);
}

@Override
public String optionString(String key) {
return null;
return provider.optionString(this, key);
}

@Override
public String optionString(String key, String def) {
return null;
return provider.optionString(this, key, def);
}

@Override
public List<String> optionStringList(String key) {
return null;
return provider.optionStringList(this, key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public CommandRegistrar(AuraSkills plugin) {

public PaperCommandManager registerCommands() {
var manager = new PaperCommandManager(plugin);
manager = new PaperCommandManager(plugin);
manager.enableUnstableAPI("help");
manager.usePerIssuerLocale(true, false);
manager.getCommandReplacements().addReplacement("skills_alias", "skills|sk|skill");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public void onBreak(BlockBreakEvent event) {
LootTable table = plugin.getLootTableManager().getLootTable(skill);
if (table == null) return;
for (LootPool pool : table.getPools()) {
// Ignore non-applicable sources
if (provider != null && !provider.isApplicable(pool, source)) {
continue;
}
// Calculate chance for pool
double chance;
if (provider != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.archyx.lootmanager.loot.LootPool;
import dev.aurelium.auraskills.api.event.loot.LootDropEvent;
import dev.aurelium.auraskills.api.source.XpSource;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.loot.handler.BlockLootHandler;
import dev.aurelium.auraskills.common.user.User;
Expand All @@ -20,4 +21,6 @@ public SkillLootProvider(AuraSkills plugin, BlockLootHandler handler) {

public abstract LootDropEvent.Cause getCause(LootPool pool);

public abstract boolean isApplicable(LootPool pool, XpSource source);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import dev.aurelium.auraskills.api.event.mana.ManaAbilityActivateEvent;
import dev.aurelium.auraskills.api.mana.ManaAbility;
import dev.aurelium.auraskills.api.source.XpSource;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.common.mana.ManaAbilityData;
import dev.aurelium.auraskills.common.message.type.ManaAbilityMessage;
import dev.aurelium.auraskills.common.source.SourceTag;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.math.NumberUtil;
import dev.aurelium.auraskills.common.util.text.TextUtil;
Expand Down Expand Up @@ -107,10 +105,6 @@ protected double getValue(User user) {
return manaAbility.getValue(user.getManaAbilityLevel(manaAbility));
}

protected boolean hasTag(XpSource source, SourceTag tag) {
return plugin.getSkillManager().getSourcesWithTag(tag).contains(source);
}

private int getDuration(User user) {
return (int) Math.round(manaAbility.getValue(user.getManaAbilityLevel(manaAbility)) * 20);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.aurelium.auraskills.api.trait.Trait;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.menus.common.AbstractItem;
import dev.aurelium.auraskills.bukkit.trait.TraitImpl;
import dev.aurelium.auraskills.common.message.type.MenuMessage;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.math.NumberUtil;
Expand Down Expand Up @@ -78,10 +79,13 @@ private String getSkillsLeveledBy(Stat stat, Locale locale) {
public String getStatDescriptors(Stat stat, User user, Locale locale) {
StringBuilder sb = new StringBuilder();
for (Trait trait : stat.getTraits()) {
TraitImpl impl = plugin.getTraitManager().getTraitImpl(trait);
if (impl == null) continue;

sb.append(stat.getColor(locale))
.append(trait.getDisplayName(locale))
.append(": ")
.append(NumberUtil.format1(user.getEffectiveTraitLevel(trait)))
.append(impl.getMenuDisplay(user.getEffectiveTraitLevel(trait), trait))
.append("\n");
}
if (!sb.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.archyx.lootmanager.loot.LootPool;
import dev.aurelium.auraskills.api.ability.Abilities;
import dev.aurelium.auraskills.api.event.loot.LootDropEvent;
import dev.aurelium.auraskills.api.source.XpSource;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.loot.handler.BlockLootHandler;
import dev.aurelium.auraskills.bukkit.loot.provider.SkillLootProvider;
import dev.aurelium.auraskills.common.source.SourceTag;
import dev.aurelium.auraskills.common.user.User;

public class ExcavationLootProvider extends SkillLootProvider {
Expand Down Expand Up @@ -37,4 +39,11 @@ public LootDropEvent.Cause getCause(LootPool pool) {
}
return cause;
}

@Override
public boolean isApplicable(LootPool pool, XpSource source) {
if (pool.getName().equals("rare") && !plugin.getSkillManager().hasTag(source, SourceTag.METAL_DETECTOR_APPLICABLE)) {
return false;
} else return !pool.getName().equals("epic") || plugin.getSkillManager().hasTag(source, SourceTag.LUCKY_SPADES_APPLICABLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void activationListener(BlockBreakEvent event) {
BlockXpSource source = sourcePair.first();
if (source == null) return;

if (hasTag(source, SourceTag.SPEED_MINE_APPLICABLE) && isHoldingMaterial(player)) {
if (plugin.getSkillManager().hasTag(source, SourceTag.SPEED_MINE_APPLICABLE) && isHoldingMaterial(player)) {
checkActivation(player);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.aurelium.auraskills.bukkit.skills.farming.FarmingAbilities;
import dev.aurelium.auraskills.bukkit.skills.foraging.ForagingAbilities;
import dev.aurelium.auraskills.bukkit.skills.mining.MiningAbilities;
import dev.aurelium.auraskills.common.source.SourceTag;
import dev.aurelium.auraskills.common.source.SourceType;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.data.Pair;
Expand Down Expand Up @@ -66,25 +67,26 @@ public void onInteract(PlayerInteractEvent event) {
if (failsChecks(event, player, block.getLocation(), skill)) return;

plugin.getLevelManager().addXp(user, skill, source.getXp());
applyAbilities(skill, player, user, block);
applyAbilities(skill, player, user, block, source);
}

private void applyAbilities(Skill skill, Player player, User user, Block block) {
var manager = plugin.getAbilityManager();
if (skill.getAbilities().contains(Abilities.BOUNTIFUL_HARVEST)) {
manager.getAbilityImpl(FarmingAbilities.class).bountifulHarvest(player, user, block);
private void applyAbilities(Skill skill, Player player, User user, Block block, BlockXpSource source) {
var abilities = plugin.getAbilityManager();
var tags = plugin.getSkillManager();
if (skill.getAbilities().contains(Abilities.BOUNTIFUL_HARVEST) && tags.hasTag(source, SourceTag.BOUNTIFUL_HARVEST_APPLICABLE)) {
abilities.getAbilityImpl(FarmingAbilities.class).bountifulHarvest(player, user, block);
}
if (skill.getAbilities().contains(Abilities.TRIPLE_HARVEST)) {
manager.getAbilityImpl(FarmingAbilities.class).tripleHarvest(player, user, block);
if (skill.getAbilities().contains(Abilities.TRIPLE_HARVEST) && tags.hasTag(source, SourceTag.TRIPLE_HARVEST_APPLICABLE)) {
abilities.getAbilityImpl(FarmingAbilities.class).tripleHarvest(player, user, block);
}
if (skill.getAbilities().contains(Abilities.LUMBERJACK)) {
manager.getAbilityImpl(ForagingAbilities.class).lumberjack(player, user, block);
if (skill.getAbilities().contains(Abilities.LUMBERJACK) && tags.hasTag(source, SourceTag.LUMBERJACK_APPLICABLE)) {
abilities.getAbilityImpl(ForagingAbilities.class).lumberjack(player, user, block);
}
if (skill.getAbilities().contains(Abilities.LUCKY_MINER)) {
manager.getAbilityImpl(MiningAbilities.class).luckyMiner(player, user, block);
if (skill.getAbilities().contains(Abilities.LUCKY_MINER) && tags.hasTag(source, SourceTag.LUCKY_MINER_APPLICABLE)) {
abilities.getAbilityImpl(MiningAbilities.class).luckyMiner(player, user, block);
}
if (skill.getAbilities().contains(Abilities.BIGGER_SCOOP)) {
manager.getAbilityImpl(ExcavationAbilities.class).biggerScoop(player, user, block);
if (skill.getAbilities().contains(Abilities.BIGGER_SCOOP) && tags.hasTag(source, SourceTag.BIGGER_SCOOP_APPLICABLE)) {
abilities.getAbilityImpl(ExcavationAbilities.class).biggerScoop(player, user, block);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class AnvilDiscountTrait extends TraitImpl {

AnvilDiscountTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.ANVIL_DISCOUNT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class AttackDamageTrait extends TraitImpl {

AttackDamageTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.ATTACK_DAMAGE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public BukkitTraitManager(AuraSkills plugin) {

public void registerTraitImplementations() {
registerTraitImpl(new HpTrait(plugin));
registerTraitImpl(new RegenTrait(plugin));
registerTraitImpl(new HealthRegenTrait(plugin));
registerTraitImpl(new ManaRegenTrait(plugin));
registerTraitImpl(new LuckTrait(plugin));
registerTraitImpl(new DoubleDropTrait(plugin));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@
import dev.aurelium.auraskills.api.trait.Traits;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.math.NumberUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class DamageReductionTrait extends TraitImpl {

DamageReductionTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.DAMAGE_REDUCTION);
}

@Override
public double getBaseLevel(Player player, Trait trait) {
return 0;
}

@Override
public String getMenuDisplay(double value, Trait trait) {
return NumberUtil.format1(getReductionValue(value) * 100) + "%";
}

public void onDamage(EntityDamageByEntityEvent event, User user) {
double reduction = user.getBonusTraitLevel(Traits.DAMAGE_REDUCTION);
event.setDamage(event.getDamage() * (1 - (-1.0 * Math.pow(1.01, -1.0 * reduction) + 1)));
double reduction = user.getEffectiveTraitLevel(Traits.DAMAGE_REDUCTION);
event.setDamage(event.getDamage() * (1 - getReductionValue(reduction)));
}

private double getReductionValue(double value) {
return -1.0 * Math.pow(1.01, -1.0 * value) + 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DoubleDropTrait extends TraitImpl {
private final Random r = new Random();

DoubleDropTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.DOUBLE_DROP);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ExperienceBonusTrait extends TraitImpl {

ExperienceBonusTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.EXPERIENCE_BONUS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import java.util.concurrent.TimeUnit;

public class RegenTrait extends TraitImpl {
public class HealthRegenTrait extends TraitImpl {

public RegenTrait(AuraSkills plugin) {
super(plugin);
public HealthRegenTrait(AuraSkills plugin) {
super(plugin, Traits.HUNGER_REGEN, Traits.SATURATION_REGEN);
startHungerRegen();
startSaturationRegen();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HpTrait extends TraitImpl implements AuraSkillsListener {
private static final double threshold = 0.1;

HpTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.HP);
loadHearts(plugin.getConfig());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class LuckTrait extends TraitImpl {

LuckTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.LUCK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class ManaRegenTrait extends TraitImpl {

ManaRegenTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.MANA_REGEN);
startRegen();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
public class MaxManaTrait extends TraitImpl {

MaxManaTrait(AuraSkills plugin) {
super(plugin);
super(plugin, Traits.MAX_MANA);
}

@Override
public double getBaseLevel(Player player, Trait trait) {
return Traits.MAX_MANA.optionDouble("base");
return 20;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.user.BukkitUser;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.math.NumberUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;

Expand All @@ -25,6 +26,10 @@ public Set<Trait> getTraits() {

public abstract double getBaseLevel(Player player, Trait trait);

public String getMenuDisplay(double value, Trait trait) {
return NumberUtil.format1(value);
}

public final void reload(User user, Trait trait) {
reload(((BukkitUser) user).getPlayer(), trait);
}
Expand Down
4 changes: 2 additions & 2 deletions bukkit/src/main/resources/messages/messages_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,8 @@ traits:
name: Anvil Discount
max_mana:
name: Max Mana
defense:
name: Defense
damage_reduction:
name: Damage Reduction
units:
mana: Mana
hp: HP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum TraitMessage implements MessageKey {
EXPERIENCE_BONUS_NAME,
ANVIL_DISCOUNT_NAME,
MAX_MANA_NAME,
DEFENSE_NAME;
DAMAGE_REDUCTION_NAME;

private final String path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,8 @@ public List<XpSource> getSourcesWithTag(SourceTag tag) {
return sourceTagMap.getOrDefault(tag, new ArrayList<>());
}

public boolean hasTag(XpSource source, SourceTag tag) {
return sourceTagMap.getOrDefault(tag, new ArrayList<>()).contains(source);
}

}
Loading

0 comments on commit 62b4a54

Please sign in to comment.