mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-08 07:27:39 +01:00
Fixed an issue with elemental attacks
This commit is contained in:
parent
1d8c4e8daf
commit
b35a651c6d
@ -2,15 +2,12 @@ package net.Indyuce.mmoitems.api;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
|
||||||
import io.lumine.mythic.lib.player.PlayerMetadata;
|
import io.lumine.mythic.lib.player.PlayerMetadata;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||||
import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType;
|
import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.Debug;
|
|
||||||
|
|
||||||
import java.nio.file.WatchKey;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -23,12 +20,34 @@ import java.util.Random;
|
|||||||
public class ElementalAttack {
|
public class ElementalAttack {
|
||||||
private final PlayerMetadata attacker;
|
private final PlayerMetadata attacker;
|
||||||
private final PlayerData playerData;
|
private final PlayerData playerData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Percentage of the initial damage being dealt as elemental damage
|
||||||
|
*/
|
||||||
private final Map<Element, Double> relative = new HashMap<>();
|
private final Map<Element, Double> relative = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flat damage being dealt as elemental damage
|
||||||
|
*/
|
||||||
private final Map<Element, Double> absolute = new HashMap<>();
|
private final Map<Element, Double> absolute = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attack target saved because MI needs to
|
||||||
|
* access the defense stats from that entity
|
||||||
|
*/
|
||||||
private final LivingEntity target;
|
private final LivingEntity target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Damage that is not elemental
|
||||||
|
*/
|
||||||
|
private final double regularDamage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial attack damage (both regular and elemental)
|
||||||
|
*/
|
||||||
private final double initialDamage;
|
private final double initialDamage;
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
public ElementalAttack(PlayerMetadata attacker, NBTItem item, double initialDamage, LivingEntity target) {
|
public ElementalAttack(PlayerMetadata attacker, NBTItem item, double initialDamage, LivingEntity target) {
|
||||||
this.initialDamage = initialDamage;
|
this.initialDamage = initialDamage;
|
||||||
@ -36,13 +55,18 @@ public class ElementalAttack {
|
|||||||
this.attacker = attacker;
|
this.attacker = attacker;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
|
||||||
|
double regularDamage = initialDamage;
|
||||||
for (Element element : Element.values()) {
|
for (Element element : Element.values()) {
|
||||||
double damage = item.getStat(element.name() + "_DAMAGE");
|
double relativeDamage = item.getStat(element.name() + "_DAMAGE");
|
||||||
if (damage > 0) {
|
if (relativeDamage > 0) {
|
||||||
relative.put(element, damage);
|
double flatElemental = relativeDamage / 100 * initialDamage;
|
||||||
absolute.put(element, damage / 100 * initialDamage);
|
relative.put(element, relativeDamage);
|
||||||
|
absolute.put(element, flatElemental);
|
||||||
|
regularDamage -= flatElemental;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.regularDamage = regularDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDamageModifier() {
|
public double getDamageModifier() {
|
||||||
@ -61,21 +85,26 @@ public class ElementalAttack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Elemental attacks
|
// Elemental attacks
|
||||||
double p = 1;
|
double correctionCoeff = 1;
|
||||||
if (!playerData.isOnCooldown(CooldownType.ELEMENTAL_ATTACK))
|
if (!playerData.isOnCooldown(CooldownType.ELEMENTAL_ATTACK))
|
||||||
for (Element element : relative.keySet()) {
|
for (Element element : relative.keySet()) {
|
||||||
double relativeDamage = relative.get(element);
|
double relativeDamage = relative.get(element);
|
||||||
if (random.nextDouble() < (relativeDamage / 100 / p)) {
|
double independentProbability = relativeDamage / 100;
|
||||||
|
if (RANDOM.nextDouble() < independentProbability / correctionCoeff) {
|
||||||
|
|
||||||
|
// Perform elemental critical strike
|
||||||
playerData.applyCooldown(CooldownType.ELEMENTAL_ATTACK, 2);
|
playerData.applyCooldown(CooldownType.ELEMENTAL_ATTACK, 2);
|
||||||
element.getHandler().elementAttack(attacker, target, relativeDamage, absolute.get(element));
|
element.getHandler().elementAttack(attacker, target, relativeDamage, absolute.get(element));
|
||||||
|
|
||||||
|
// Multiply corresponding damage by 2
|
||||||
absolute.put(element, absolute.get(element) * 2);
|
absolute.put(element, absolute.get(element) * 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p -= relativeDamage / 100;
|
correctionCoeff -= independentProbability;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate final damage again
|
// Calculate final damage again
|
||||||
double finalDamage = 0;
|
double finalDamage = regularDamage;
|
||||||
|
|
||||||
for (Element element : absolute.keySet()) {
|
for (Element element : absolute.keySet()) {
|
||||||
double partialDamage = absolute.get(element);
|
double partialDamage = absolute.get(element);
|
||||||
|
Loading…
Reference in New Issue
Block a user