Skip to content

Commit

Permalink
Implement rest of mana abilities and critical
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Aug 14, 2023
1 parent 62b4a54 commit e0a257f
Show file tree
Hide file tree
Showing 17 changed files with 995 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public interface BlockXpSource extends XpSource {
*/
boolean requiresSupportBlock(SupportBlockType direction);

boolean isTrunk();

boolean isLeaf();

interface BlockXpSourceState {

Map<String, Object> getStateMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.aurelium.auraskills.bukkit.hooks;

import com.palmergames.bukkit.towny.object.TownyPermission;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import dev.aurelium.auraskills.common.AuraSkillsPlugin;
import dev.aurelium.auraskills.common.hooks.Hook;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

public class TownyHook extends Hook {

public TownyHook(AuraSkillsPlugin plugin) {
super(plugin);
}

public boolean canBreak(Player player, Block block) {
try {
return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.DESTROY);
} catch (Exception ignored) { }
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.aurelium.auraskills.bukkit.listeners;

import dev.aurelium.auraskills.api.ability.Abilities;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.common.config.Option;
import dev.aurelium.auraskills.common.user.User;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.metadata.FixedMetadataValue;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class CriticalHandler {

private final Random rand = new Random();
private final AuraSkills plugin;

public CriticalHandler(AuraSkills plugin) {
this.plugin = plugin;
}

public void applyCrit(EntityDamageByEntityEvent event, Player player, User user) {
if (!Abilities.CRIT_CHANCE.isEnabled()) {
return;
}

if (isCrit(user)) {
event.setDamage(event.getDamage() * getCritMultiplier(user));
player.setMetadata("skillsCritical", new FixedMetadataValue(plugin, true));
plugin.getScheduler().scheduleSync(() -> player.removeMetadata("skillsCritical", plugin), 50, TimeUnit.MILLISECONDS);
}
}

private boolean isCrit(User user) {
return rand.nextDouble() < (Abilities.CRIT_CHANCE.getValue(user.getAbilityLevel(Abilities.CRIT_CHANCE)) / 100);
}

private double getCritMultiplier(User user) {
if (Abilities.CRIT_DAMAGE.isEnabled()) {
double multiplier = Abilities.CRIT_DAMAGE.getValue(user.getAbilityLevel(Abilities.CRIT_DAMAGE)) / 100;
return plugin.configDouble(Option.CRITICAL_BASE_MULTIPLIER) * (1 + multiplier);
}
return plugin.configDouble(Option.CRITICAL_BASE_MULTIPLIER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.skills.archery.ArcheryAbilities;
import dev.aurelium.auraskills.bukkit.skills.archery.ChargedShot;
import dev.aurelium.auraskills.bukkit.skills.defense.Absorption;
import dev.aurelium.auraskills.bukkit.skills.defense.DefenseAbilities;
import dev.aurelium.auraskills.bukkit.skills.excavation.ExcavationAbilities;
import dev.aurelium.auraskills.bukkit.skills.farming.FarmingAbilities;
Expand All @@ -10,6 +12,7 @@
import dev.aurelium.auraskills.bukkit.skills.mining.MiningAbilities;
import dev.aurelium.auraskills.bukkit.trait.AttackDamageTrait;
import dev.aurelium.auraskills.bukkit.trait.DamageReductionTrait;
import dev.aurelium.auraskills.common.config.Option;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.mechanics.DamageType;
import org.bukkit.Material;
Expand All @@ -22,9 +25,11 @@
public class DamageListener implements Listener {

private final AuraSkills plugin;
private final CriticalHandler criticalHandler;

public DamageListener(AuraSkills plugin) {
this.plugin = plugin;
this.criticalHandler = new CriticalHandler(plugin);
}

@EventHandler(priority = EventPriority.HIGH)
Expand Down Expand Up @@ -71,6 +76,16 @@ public void onDamage(EntityDamageByEntityEvent event) {
if (damageType == DamageType.SWORD) {
abManager.getAbilityImpl(FightingAbilities.class).firstStrike(event, user, player);
}

// Apply critical
if (plugin.configBoolean(Option.valueOf("CRITICAL_ENABLED_" + damageType.name()))) {
criticalHandler.applyCrit(event, player, user);
}

// Charged shot
if (damageType == DamageType.BOW) {
plugin.getManaAbilityManager().getProvider(ChargedShot.class).applyChargedShot(event);
}
}

private void onDamaged(EntityDamageByEntityEvent event, Player player) {
Expand All @@ -81,7 +96,11 @@ private void onDamaged(EntityDamageByEntityEvent event, Player player) {
if (event.isCancelled()) return;
User user = plugin.getUser(player);

// Handles incoming damage reduction trait
// Handles absorption
plugin.getManaAbilityManager().getProvider(Absorption.class).handleAbsorption(event, player, user);
if (event.isCancelled()) return;

// Handles damage reduction trait
var damageReduction = plugin.getTraitManager().getTraitImpl(DamageReductionTrait.class);
damageReduction.onDamage(event, user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import dev.aurelium.auraskills.api.event.AuraSkillsListener;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.skills.archery.ChargedShot;
import dev.aurelium.auraskills.bukkit.skills.defense.Absorption;
import dev.aurelium.auraskills.bukkit.skills.excavation.Terraform;
import dev.aurelium.auraskills.bukkit.skills.farming.Replenish;
import dev.aurelium.auraskills.bukkit.skills.fighting.LightningBlade;
import dev.aurelium.auraskills.bukkit.skills.fishing.SharpHook;
import dev.aurelium.auraskills.bukkit.skills.foraging.Treecapitator;
import dev.aurelium.auraskills.bukkit.skills.mining.SpeedMine;
import dev.aurelium.auraskills.common.mana.ManaAbilityManager;
import org.bukkit.Bukkit;
Expand All @@ -25,8 +31,14 @@ public BukkitManaAbilityManager(AuraSkills plugin) {
}

private void registerProviders() {
registerProvider(new SpeedMine(plugin));
registerProvider(new Replenish(plugin));
registerProvider(new Treecapitator(plugin));
registerProvider(new SpeedMine(plugin));
registerProvider(new SharpHook(plugin));
registerProvider(new Terraform(plugin));
registerProvider(new ChargedShot(plugin));
registerProvider(new Absorption(plugin));
registerProvider(new LightningBlade(plugin));
}

private void registerProvider(ManaAbilityProvider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import dev.aurelium.auraskills.api.event.mana.ManaAbilityActivateEvent;
import dev.aurelium.auraskills.api.mana.ManaAbility;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.common.config.Option;
import dev.aurelium.auraskills.common.mana.ManaAbilityData;
import dev.aurelium.auraskills.common.message.type.ManaAbilityMessage;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.common.util.math.NumberUtil;
import dev.aurelium.auraskills.common.util.text.TextUtil;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
Expand All @@ -23,7 +25,7 @@ public abstract class ManaAbilityProvider implements Listener {
@Nullable
private final ManaAbilityMessage stopMessage;

ManaAbilityProvider(AuraSkills plugin, ManaAbility manaAbility, ManaAbilityMessage activateMessage, @Nullable ManaAbilityMessage stopMessage) {
public ManaAbilityProvider(AuraSkills plugin, ManaAbility manaAbility, ManaAbilityMessage activateMessage, @Nullable ManaAbilityMessage stopMessage) {
this.plugin = plugin;
this.manaAbility = manaAbility;
this.activateMessage = activateMessage;
Expand All @@ -34,6 +36,10 @@ public ManaAbility getManaAbility() {
return manaAbility;
}

public ManaAbilityMessage getActivateMessage() {
return activateMessage;
}

public abstract void onActivate(Player player, User user);

public abstract void onStop(Player player, User user);
Expand Down Expand Up @@ -67,9 +73,7 @@ protected boolean checkActivation(Player player) {

if (duration != 0) {
//Schedules stop
plugin.getScheduler().scheduleSync(() -> {
stop(player, user, data);
}, duration * 50L, TimeUnit.MILLISECONDS);
plugin.getScheduler().scheduleSync(() -> stop(player, user, data), duration * 50L, TimeUnit.MILLISECONDS);
} else {
stop(player, user, data);
}
Expand All @@ -93,6 +97,22 @@ protected boolean isDisabled() {
return !manaAbility.getSkill().isEnabled() || !manaAbility.isEnabled();
}

protected boolean failsChecks(Player player) {
if (plugin.getUser(player).getManaAbilityLevel(manaAbility) <= 0) {
return true;
}
if (plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
return true;
}
if (!player.hasPermission("auraskills.skill." + manaAbility.getSkill().name().toLowerCase(Locale.ROOT))) {
return true;
}
if (plugin.configBoolean(Option.DISABLE_IN_CREATIVE_MODE)) {
return player.getGameMode().equals(GameMode.CREATIVE);
}
return false;
}

protected boolean isReady(User user) {
return true;
}
Expand All @@ -105,11 +125,11 @@ protected double getValue(User user) {
return manaAbility.getValue(user.getManaAbilityLevel(manaAbility));
}

private int getDuration(User user) {
protected int getDuration(User user) {
return (int) Math.round(manaAbility.getValue(user.getManaAbilityLevel(manaAbility)) * 20);
}

private void consumeMana(Player player, User user, double manaConsumed) {
protected void consumeMana(Player player, User user, double manaConsumed) {
user.setMana(user.getMana() - manaConsumed);

plugin.getAbilityManager().sendMessage(player, TextUtil.replace(plugin.getMsg(activateMessage, user.getLocale())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ protected boolean isExcludedBlock(Block block) {
return false;
}

public String[] getMaterials() {
return materials;
}

@EventHandler
public void onReady(PlayerInteractEvent event) {
if (isDisabled()) return;
Expand Down
Loading

0 comments on commit e0a257f

Please sign in to comment.