forked from Upstream/mmocore
!Small passive skills/resource regen cleanup + comments
This commit is contained in:
parent
de92993645
commit
93069c7d1a
@ -54,8 +54,8 @@ public class SavedClassInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(PlayerData player) {
|
public SavedClassInformation(PlayerData player) {
|
||||||
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(),
|
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints(),
|
||||||
player.getAttributeReallocationPoints(), player.getAttributes().mapPoints(), player.mapSkillLevels());
|
player.getAttributes().mapPoints(), player.mapSkillLevels());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(DefaultPlayerData data) {
|
public SavedClassInformation(DefaultPlayerData data) {
|
||||||
@ -66,14 +66,15 @@ public class SavedClassInformation {
|
|||||||
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, new HashMap<>(), new HashMap<>());
|
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, new HashMap<>(), new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SavedClassInformation(int l, int e, int sp, int ap, int arp, Map<String, Integer> a, Map<String, Integer> s) {
|
private SavedClassInformation(int level, int experience, int skillPoints, int attributePoints, int attributeReallocationPoints,
|
||||||
this.level = l;
|
Map<String, Integer> attributes, Map<String, Integer> skills) {
|
||||||
this.experience = e;
|
this.level = level;
|
||||||
this.skillPoints = sp;
|
this.experience = experience;
|
||||||
this.attributePoints = ap;
|
this.skillPoints = skillPoints;
|
||||||
this.attributeReallocationPoints = arp;
|
this.attributePoints = attributePoints;
|
||||||
this.attributes = a;
|
this.attributeReallocationPoints = attributeReallocationPoints;
|
||||||
this.skills = s;
|
this.attributes = attributes;
|
||||||
|
this.skills = skills;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLevel() {
|
public int getLevel() {
|
||||||
|
@ -11,17 +11,22 @@ import net.Indyuce.mmocore.api.player.stats.StatType;
|
|||||||
|
|
||||||
public enum PlayerResource {
|
public enum PlayerResource {
|
||||||
|
|
||||||
HEALTH(StatType.HEALTH_REGENERATION, ClassOption.OFF_COMBAT_HEALTH_REGEN, (data) -> data.getPlayer().getHealth(), (data) -> data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), (data, d) -> data.heal(d)),
|
HEALTH(StatType.HEALTH_REGENERATION, ClassOption.OFF_COMBAT_HEALTH_REGEN, (data) -> data.getPlayer().getHealth(),
|
||||||
MANA(StatType.MANA_REGENERATION, ClassOption.OFF_COMBAT_MANA_REGEN, (data) -> data.getMana(), (data) -> data.getStats().getStat(StatType.MAX_MANA), (data, d) -> data.giveMana(d)),
|
(data) -> data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), (data, d) -> data.heal(d)),
|
||||||
STAMINA(StatType.STAMINA_REGENERATION, ClassOption.OFF_COMBAT_STAMINA_REGEN, (data) -> data.getStamina(), (data) -> data.getStats().getStat(StatType.MAX_STAMINA), (data, d) -> data.giveStamina(d)),
|
MANA(StatType.MANA_REGENERATION, ClassOption.OFF_COMBAT_MANA_REGEN, (data) -> data.getMana(),
|
||||||
STELLIUM(StatType.STELLIUM_REGENERATION, ClassOption.OFF_COMBAT_STELLIUM_REGEN, (data) -> data.getStellium(), (data) -> data.getStats().getStat(StatType.MAX_STELLIUM), (data, d) -> data.giveStellium(d));
|
(data) -> data.getStats().getStat(StatType.MAX_MANA), (data, d) -> data.giveMana(d)),
|
||||||
|
STAMINA(StatType.STAMINA_REGENERATION, ClassOption.OFF_COMBAT_STAMINA_REGEN, (data) -> data.getStamina(),
|
||||||
|
(data) -> data.getStats().getStat(StatType.MAX_STAMINA), (data, d) -> data.giveStamina(d)),
|
||||||
|
STELLIUM(StatType.STELLIUM_REGENERATION, ClassOption.OFF_COMBAT_STELLIUM_REGEN, (data) -> data.getStellium(),
|
||||||
|
(data) -> data.getStats().getStat(StatType.MAX_STELLIUM), (data, d) -> data.giveStellium(d));
|
||||||
|
|
||||||
private final StatType regenStat;
|
private final StatType regenStat;
|
||||||
private final ClassOption offCombatRegen;
|
private final ClassOption offCombatRegen;
|
||||||
private final Function<PlayerData, Double> current, max;
|
private final Function<PlayerData, Double> current, max;
|
||||||
private final BiConsumer<PlayerData, Double> regen;
|
private final BiConsumer<PlayerData, Double> regen;
|
||||||
|
|
||||||
private PlayerResource(StatType regenStat, ClassOption offCombatRegen, Function<PlayerData, Double> current, Function<PlayerData, Double> max, BiConsumer<PlayerData, Double> regen) {
|
private PlayerResource(StatType regenStat, ClassOption offCombatRegen, Function<PlayerData, Double> current, Function<PlayerData, Double> max,
|
||||||
|
BiConsumer<PlayerData, Double> regen) {
|
||||||
this.regenStat = regenStat;
|
this.regenStat = regenStat;
|
||||||
this.offCombatRegen = offCombatRegen;
|
this.offCombatRegen = offCombatRegen;
|
||||||
this.current = current;
|
this.current = current;
|
||||||
@ -29,37 +34,42 @@ public enum PlayerResource {
|
|||||||
this.regen = regen;
|
this.regen = regen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* stat which correspondons to resource regeneration
|
* @return Stat which corresponds to resource regeneration
|
||||||
*/
|
*/
|
||||||
public StatType getRegenStat() {
|
public StatType getRegenStat() {
|
||||||
return regenStat;
|
return regenStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* class option which determines whether or not resource should be
|
* @return Class option which determines whether or not resource should be
|
||||||
* regenerated off combat only
|
* regenerated off combat only
|
||||||
*/
|
*/
|
||||||
public ClassOption getOffCombatRegen() {
|
public ClassOption getOffCombatRegen() {
|
||||||
return offCombatRegen;
|
return offCombatRegen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* get current resource of player
|
* @return Current resource of the given player
|
||||||
*/
|
*/
|
||||||
public double getCurrent(PlayerData player) {
|
public double getCurrent(PlayerData player) {
|
||||||
return current.apply(player);
|
return current.apply(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* get max resource of player
|
* @return Max amount of that resource of the given player
|
||||||
*/
|
*/
|
||||||
public double getMax(PlayerData player) {
|
public double getMax(PlayerData player) {
|
||||||
return max.apply(player);
|
return max.apply(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* regenerate resource of player (TRIGGERS A BUKKIT/CUSTOM EVENT)
|
* Regens a player resource. Whatever resource, a bukkit event is triggered
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* Player to regen
|
||||||
|
* @param amount
|
||||||
|
* Amount to regen
|
||||||
*/
|
*/
|
||||||
public void regen(PlayerData player, double amount) {
|
public void regen(PlayerData player, double amount) {
|
||||||
regen.accept(player, amount);
|
regen.accept(player, amount);
|
||||||
|
@ -10,25 +10,25 @@ import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
|||||||
|
|
||||||
public class ResourceHandler {
|
public class ResourceHandler {
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* resource regeneration only applies when player is off combat
|
* Resource should only regenerate when the player is out of combat
|
||||||
*/
|
*/
|
||||||
private final boolean offCombatOnly;
|
private final boolean offCombatOnly;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* percentage of scaling which the player regenerates every second
|
* Percentage of scaling which the player regenerates every second
|
||||||
*/
|
*/
|
||||||
private final LinearValue scalar;
|
private final LinearValue scalar;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* whether the resource regeneration scales on missing or max resource. if
|
* Whether the resource regeneration scales on missing or max resource. if
|
||||||
* TYPE is null, then there is no special regeneration.
|
* TYPE is null, then there is no special regeneration.
|
||||||
*/
|
*/
|
||||||
private final HandlerType type;
|
private final HandlerType type;
|
||||||
private final PlayerResource resource;
|
private final PlayerResource resource;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* used when there is no special resource regeneration
|
* Used when there is no special resource regeneration
|
||||||
*/
|
*/
|
||||||
public ResourceHandler(PlayerResource resource) {
|
public ResourceHandler(PlayerResource resource) {
|
||||||
this(resource, null, null, false);
|
this(resource, null, null, false);
|
||||||
@ -38,15 +38,11 @@ public class ResourceHandler {
|
|||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
offCombatOnly = config.getBoolean("off-combat");
|
offCombatOnly = config.getBoolean("off-combat");
|
||||||
|
|
||||||
if(config.contains("type")) {
|
|
||||||
Validate.isTrue(config.contains("type"), "Could not find resource regen scaling type");
|
Validate.isTrue(config.contains("type"), "Could not find resource regen scaling type");
|
||||||
type = HandlerType.valueOf(config.getString("type").toUpperCase());
|
type = HandlerType.valueOf(config.getString("type").toUpperCase());
|
||||||
} else type = null;
|
|
||||||
|
|
||||||
if(type != null) {
|
|
||||||
Validate.notNull(config.getConfigurationSection("value"), "Could not find resource regen value config section");
|
Validate.notNull(config.getConfigurationSection("value"), "Could not find resource regen value config section");
|
||||||
scalar = new LinearValue(config.getConfigurationSection("value"));
|
scalar = new LinearValue(config.getConfigurationSection("value"));
|
||||||
} else scalar = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceHandler(PlayerResource resource, HandlerType type, LinearValue scalar, boolean offCombatOnly) {
|
public ResourceHandler(PlayerResource resource, HandlerType type, LinearValue scalar, boolean offCombatOnly) {
|
||||||
@ -56,8 +52,14 @@ public class ResourceHandler {
|
|||||||
this.offCombatOnly = offCombatOnly;
|
this.offCombatOnly = offCombatOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* REGENERATION FORMULAS HERE.
|
* Apply regeneration formulas: first calculates base resource regen due to
|
||||||
|
* the player stats and then apply the special resource regeneration due to
|
||||||
|
* the player class
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* Player regenerating
|
||||||
|
* @return The amount of resource which should be regenerated EVERY SECOND
|
||||||
*/
|
*/
|
||||||
public double getRegen(PlayerData player) {
|
public double getRegen(PlayerData player) {
|
||||||
double d = 0;
|
double d = 0;
|
||||||
@ -74,13 +76,14 @@ public class ResourceHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum HandlerType {
|
public enum HandlerType {
|
||||||
/*
|
|
||||||
* resource regeneration scales on max resource
|
/**
|
||||||
|
* Resource regeneration scales on max resource
|
||||||
*/
|
*/
|
||||||
MAX((player, resource) -> resource.getMax(player)),
|
MAX((player, resource) -> resource.getMax(player)),
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* resource regeneration scales on missing resource
|
* Resource regeneration scales on missing resource
|
||||||
*/
|
*/
|
||||||
MISSING((player, resource) -> resource.getMax(player) - resource.getCurrent(player));
|
MISSING((player, resource) -> resource.getMax(player) - resource.getCurrent(player));
|
||||||
|
|
||||||
|
@ -6,67 +6,100 @@ import java.util.Map;
|
|||||||
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
|
import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
|
||||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicMobSkill;
|
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: any method which return longs returns milliseconds.
|
||||||
|
*
|
||||||
|
* @author cympe
|
||||||
|
*/
|
||||||
public class PlayerSkillData {
|
public class PlayerSkillData {
|
||||||
private final Map<String, Long> cooldowns = new HashMap<>();
|
private final Map<String, Long> cooldowns = new HashMap<>();
|
||||||
private final PlayerData data;
|
private final PlayerData data;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* MythicMobs skill damage is handled via math formula which can retrieve
|
* MythicMobs skill damage is handled via math formula which can retrieve
|
||||||
* PAPI placeholders. when a skill is cast, all skill modifiers are cached
|
* PAPI placeholders. When a skill is cast, all skill modifiers are cached
|
||||||
* into that map: 1- for easier and faster access 2- it removes interference
|
* into that map: 1- for easier and faster access 2- it removes interference
|
||||||
* for example when stats are calculating not when the spell is cast but
|
* for example when stats are calculating not when the spell is cast but
|
||||||
* rather when the spell hits
|
* rather when the spell hits
|
||||||
*/
|
*/
|
||||||
private final Map<String, CachedModifier> cache = new HashMap<>();
|
private final Map<String, CachedModifier> cache = new HashMap<>();
|
||||||
|
|
||||||
// public int ambers;
|
|
||||||
|
|
||||||
public PlayerSkillData(PlayerData data) {
|
public PlayerSkillData(PlayerData data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* any method which returns long RETURNS milliseconds (cooldowns are either
|
|
||||||
* stored in double when it's the actual value or in long when it's precise
|
|
||||||
* up to 3 digits)
|
|
||||||
*/
|
|
||||||
public long getCooldown(SkillInfo skill) {
|
public long getCooldown(SkillInfo skill) {
|
||||||
return Math.max(0, lastCast(skill.getSkill()) - System.currentTimeMillis() + (long) (1000. * skill.getModifier("cooldown", data.getSkillLevel(skill.getSkill()))));
|
return Math.max(0, lastCast(skill.getSkill()) - System.currentTimeMillis()
|
||||||
|
+ (long) (1000. * skill.getModifier("cooldown", data.getSkillLevel(skill.getSkill()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param skill
|
||||||
|
* Skill that was cast
|
||||||
|
* @return Last time stamp the skill was cast or 0 if never
|
||||||
|
*/
|
||||||
public long lastCast(Skill skill) {
|
public long lastCast(Skill skill) {
|
||||||
return cooldowns.containsKey(skill.getId()) ? cooldowns.get(skill.getId()) : 0;
|
return cooldowns.containsKey(skill.getId()) ? cooldowns.get(skill.getId()) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the last time the player cast the skill at current time
|
||||||
|
*
|
||||||
|
* @param skill
|
||||||
|
* Skill being cast
|
||||||
|
*/
|
||||||
public void setLastCast(Skill skill) {
|
public void setLastCast(Skill skill) {
|
||||||
setLastCast(skill, System.currentTimeMillis());
|
setLastCast(skill, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the last time the player cast the skill at given time
|
||||||
|
*
|
||||||
|
* @param ms
|
||||||
|
* Time stammp
|
||||||
|
* @param skill
|
||||||
|
* Skill being cast
|
||||||
|
*/
|
||||||
public void setLastCast(Skill skill, long ms) {
|
public void setLastCast(Skill skill, long ms) {
|
||||||
cooldowns.put(skill.getId(), ms);
|
cooldowns.put(skill.getId(), ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reduces the remaining cooldown of a specific skill
|
||||||
|
*
|
||||||
|
* @param skill
|
||||||
|
* Skill cast
|
||||||
|
* @param value
|
||||||
|
* Amount of skill cooldown instant reduction.
|
||||||
|
* @param relative
|
||||||
|
* If the cooldown reduction is relative to the remaining
|
||||||
|
* cooldown. If set to true, instant reduction is equal to
|
||||||
|
* (value) * (skill cooldown). If set to false, instant reduction
|
||||||
|
* is the given flat value
|
||||||
|
*/
|
||||||
public void reduceCooldown(SkillInfo skill, double value, boolean relative) {
|
public void reduceCooldown(SkillInfo skill, double value, boolean relative) {
|
||||||
cooldowns.put(skill.getSkill().getId(), lastCast(skill.getSkill()) + (long) (relative ? value * getCooldown(skill) : value * 1000));
|
long reduction = (long) (relative ? value * (double) getCooldown(skill) : value * 1000.);
|
||||||
|
cooldowns.put(skill.getSkill().getId(), lastCast(skill.getSkill()) + reduction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void resetData() {
|
|
||||||
// ambers = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public double getCachedModifier(String name) {
|
public double getCachedModifier(String name) {
|
||||||
return cache.containsKey(name) ? cache.get(name).getValue() : 0;
|
return cache.containsKey(name) ? cache.get(name).getValue() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cacheModifiers(MythicMobSkill mmSkill, SkillResult cast) {
|
public void cacheModifiers(MythicMobSkill skill, SkillResult cast) {
|
||||||
for (String modifier : cast.getSkill().getModifiers())
|
cacheModifiers(skill.getInternalName(), cast);
|
||||||
cacheModifier(mmSkill, modifier, cast.getModifier(modifier));
|
|
||||||
|
|
||||||
cacheModifier(mmSkill, "level", cast.getLevel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches all modifiers from a cast skill in the map
|
||||||
|
*
|
||||||
|
* @param skill
|
||||||
|
* Skill identifier being used as reference in the map
|
||||||
|
* @param cast
|
||||||
|
* Skill being cast
|
||||||
|
*/
|
||||||
public void cacheModifiers(String skill, SkillResult cast) {
|
public void cacheModifiers(String skill, SkillResult cast) {
|
||||||
for (String modifier : cast.getSkill().getModifiers())
|
for (String modifier : cast.getSkill().getModifiers())
|
||||||
cacheModifier(skill, modifier, cast.getModifier(modifier));
|
cacheModifier(skill, modifier, cast.getModifier(modifier));
|
||||||
@ -74,14 +107,24 @@ public class PlayerSkillData {
|
|||||||
cacheModifier(skill, "level", cast.getLevel());
|
cacheModifier(skill, "level", cast.getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cacheModifier(MythicMobSkill skill, String name, double value) {
|
/**
|
||||||
cacheModifier(skill.getInternalName(), name, value);
|
* Caches a specific modifier
|
||||||
}
|
*
|
||||||
|
* @param skill
|
||||||
|
* The identifier of the skill being cast
|
||||||
|
* @param name
|
||||||
|
* Modifier name
|
||||||
|
* @param value
|
||||||
|
* Modifier value
|
||||||
|
*/
|
||||||
public void cacheModifier(String skill, String name, double value) {
|
public void cacheModifier(String skill, String name, double value) {
|
||||||
cache.put(skill + "." + name, new CachedModifier(value));
|
cache.put(skill + "." + name, new CachedModifier(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empties cached modifiers. Modifiers should time out one minute after the
|
||||||
|
* skill was cast
|
||||||
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
for (Iterator<CachedModifier> iterator = cache.values().iterator(); iterator.hasNext();)
|
for (Iterator<CachedModifier> iterator = cache.values().iterator(); iterator.hasNext();)
|
||||||
if (iterator.next().isTimedOut())
|
if (iterator.next().isTimedOut())
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package net.Indyuce.mmocore.comp.mythicmobs;
|
|
||||||
|
|
||||||
public enum PassiveSkillType {
|
|
||||||
PLAYER_ATTACK,
|
|
||||||
PLAYER_DAMAGE;
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.comp.mythicmobs;
|
package net.Indyuce.mmocore.comp.mythicmobs.skill;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -11,11 +11,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
|
|
||||||
import com.google.common.base.Enums;
|
import com.google.common.base.Enums;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
@ -30,7 +25,6 @@ import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
|||||||
import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
|
import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
|
||||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||||
import net.Indyuce.mmocore.comp.anticheat.CheatType;
|
import net.Indyuce.mmocore.comp.anticheat.CheatType;
|
||||||
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
|
|
||||||
|
|
||||||
public class MythicMobSkill extends Skill {
|
public class MythicMobSkill extends Skill {
|
||||||
private final io.lumine.xikage.mythicmobs.skills.Skill skill;
|
private final io.lumine.xikage.mythicmobs.skills.Skill skill;
|
||||||
@ -62,19 +56,19 @@ public class MythicMobSkill extends Skill {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.isConfigurationSection("disable-anti-cheat"))
|
if (config.isConfigurationSection("disable-anti-cheat"))
|
||||||
for(String key : config.getConfigurationSection("").getKeys(false)) {
|
for (String key : config.getKeys(false)) {
|
||||||
Optional<CheatType> cheatType = Enums.getIfPresent(CheatType.class, key.toUpperCase());
|
Optional<CheatType> cheatType = Enums.getIfPresent(CheatType.class, key.toUpperCase());
|
||||||
if(cheatType.isPresent() && config.isInt("disable-anti-cheat." + key))
|
if (cheatType.isPresent() && config.isInt("disable-anti-cheat." + key))
|
||||||
antiCheat.put(cheatType.get(), config.getInt("disable-anti-cheat." + key));
|
antiCheat.put(cheatType.get(), config.getInt("disable-anti-cheat." + key));
|
||||||
else MMOCore.log(Level.WARNING, "Invalid Anti-Cheat configuration for '" + id + "'!");
|
else
|
||||||
|
MMOCore.log(Level.WARNING, "Invalid Anti-Cheat configuration for '" + id + "'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.isString("passive-type")) {
|
||||||
if(config.isString("passive-type")) {
|
|
||||||
Optional<PassiveSkillType> passiveType = Enums.getIfPresent(PassiveSkillType.class, config.getString("passive-type").toUpperCase());
|
Optional<PassiveSkillType> passiveType = Enums.getIfPresent(PassiveSkillType.class, config.getString("passive-type").toUpperCase());
|
||||||
Validate.isTrue(passiveType.isPresent(), "Invalid 'passive-type' for MM skill: " + id);
|
Validate.isTrue(passiveType.isPresent(), "Invalid passive skill type");
|
||||||
setPassive();
|
setPassive();
|
||||||
Bukkit.getPluginManager().registerEvents(getListener(passiveType.get()), MMOCore.plugin);
|
Bukkit.getPluginManager().registerEvents(passiveType.get().getListener(this), MMOCore.plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cast = config.getBoolean("target") ? (data, info) -> new
|
// cast = config.getBoolean("target") ? (data, info) -> new
|
||||||
@ -82,19 +76,8 @@ public class MythicMobSkill extends Skill {
|
|||||||
// (data, info) -> new SkillResult(data, info);
|
// (data, info) -> new SkillResult(data, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
// private double def(double d, double def) {
|
public Map<CheatType, Integer> getAntiCheat() {
|
||||||
// return d == 0 ? def : d;
|
return antiCheat;
|
||||||
// }
|
|
||||||
|
|
||||||
private MythicMobSkillPassive getListener(PassiveSkillType type) {
|
|
||||||
switch(type) {
|
|
||||||
case PLAYER_ATTACK:
|
|
||||||
return new PlayerAttackPassive();
|
|
||||||
case PLAYER_DAMAGE:
|
|
||||||
return new PlayerDamagePassive();
|
|
||||||
}
|
|
||||||
MMOCore.log(Level.SEVERE, "Something went wrong adding a passive skill! (" + getInternalName() + ")");
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInternalName() {
|
public String getInternalName() {
|
||||||
@ -104,9 +87,8 @@ public class MythicMobSkill extends Skill {
|
|||||||
@Override
|
@Override
|
||||||
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
||||||
SkillResult cast = new SkillResult(data, skill);
|
SkillResult cast = new SkillResult(data, skill);
|
||||||
if (!cast.isSuccessful() || !data.isOnline())
|
if (!cast.isSuccessful() || !data.isOnline() || isPassive())
|
||||||
return cast;
|
return cast;
|
||||||
if(isPassive()) return cast;
|
|
||||||
|
|
||||||
List<Entity> targets = new ArrayList<>();
|
List<Entity> targets = new ArrayList<>();
|
||||||
// targets.add(cast instanceof TargetSkillResult ? ((TargetSkillResult)
|
// targets.add(cast instanceof TargetSkillResult ? ((TargetSkillResult)
|
||||||
@ -114,55 +96,24 @@ public class MythicMobSkill extends Skill {
|
|||||||
targets.add(data.getPlayer());
|
targets.add(data.getPlayer());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* cache placeholders so they can be retrieved later by MythicMobs math formulas
|
* cache placeholders so they can be retrieved later by MythicMobs math
|
||||||
|
* formulas
|
||||||
*/
|
*/
|
||||||
data.getSkillData().cacheModifiers(this, cast);
|
data.getSkillData().cacheModifiers(this, cast);
|
||||||
if(MMOCore.plugin.hasAntiCheat()) MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), antiCheat);
|
if (MMOCore.plugin.hasAntiCheat())
|
||||||
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(),
|
MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), antiCheat);
|
||||||
data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1))
|
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(), data.getPlayer(),
|
||||||
|
data.getPlayer().getEyeLocation(), targets, null, 1))
|
||||||
cast.abort(CancelReason.OTHER);
|
cast.abort(CancelReason.OTHER);
|
||||||
|
|
||||||
return cast;
|
return cast;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* used to load double modifiers from the config with a specific type, since
|
* Used to load double modifiers from the config with a specific type, since
|
||||||
* modifiers have initially a type for mmocore default skills
|
* modifiers have initially a type for mmocore default skills
|
||||||
*/
|
*/
|
||||||
private LinearValue readLinearValue(ConfigurationSection section) {
|
private LinearValue readLinearValue(ConfigurationSection section) {
|
||||||
return section.getBoolean("int") ? new IntegerLinearValue(section) : new LinearValue(section);
|
return section.getBoolean("int") ? new IntegerLinearValue(section) : new LinearValue(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract class MythicMobSkillPassive implements Listener {
|
|
||||||
protected void castSkill(PlayerData data) {
|
|
||||||
if (!data.getProfess().hasSkill(getId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SkillResult cast = data.cast(data.getProfess().getSkill(getId()));
|
|
||||||
if (!cast.isSuccessful())
|
|
||||||
return;
|
|
||||||
|
|
||||||
data.getSkillData().cacheModifiers(getInternalName(), cast);
|
|
||||||
if(MMOCore.plugin.hasAntiCheat()) MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), antiCheat);
|
|
||||||
List<Entity> targets = new ArrayList<>();
|
|
||||||
targets.add(data.getPlayer());
|
|
||||||
MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class PlayerAttackPassive extends MythicMobSkillPassive {
|
|
||||||
@EventHandler
|
|
||||||
private void playerAttack(PlayerAttackEvent event) {
|
|
||||||
castSkill(event.getData().getMMOCore());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class PlayerDamagePassive extends MythicMobSkillPassive {
|
|
||||||
@EventHandler
|
|
||||||
private void playerDamage(EntityDamageEvent event) {
|
|
||||||
if(event.getEntityType() != EntityType.PLAYER)
|
|
||||||
return;
|
|
||||||
castSkill(PlayerData.get((Player) event.getEntity()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package net.Indyuce.mmocore.comp.mythicmobs.skill;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public enum PassiveSkillType {
|
||||||
|
PLAYER_ATTACK,
|
||||||
|
PLAYER_DAMAGE;
|
||||||
|
|
||||||
|
public Listener getListener(MythicMobSkill skill) {
|
||||||
|
if (this == PLAYER_ATTACK)
|
||||||
|
return new PlayerAttackSkillHandler(skill);
|
||||||
|
if (this == PLAYER_DAMAGE)
|
||||||
|
return new PlayerDamageSkillHandler(skill);
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package net.Indyuce.mmocore.comp.mythicmobs.skill;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import io.lumine.xikage.mythicmobs.MythicMobs;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import net.Indyuce.mmocore.api.skill.SkillResult;
|
||||||
|
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
|
||||||
|
|
||||||
|
public class PlayerAttackSkillHandler implements Listener {
|
||||||
|
private final MythicMobSkill skill;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to handle passive skills which trigger when a player attacks another
|
||||||
|
* entity
|
||||||
|
*
|
||||||
|
* @param skill
|
||||||
|
* Passive skill info
|
||||||
|
*/
|
||||||
|
public PlayerAttackSkillHandler(MythicMobSkill skill) {
|
||||||
|
this.skill = skill;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void playerAttack(PlayerAttackEvent event) {
|
||||||
|
castSkill(event.getData().getMMOCore(), event.getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has an extra parameter compared to PlayerDamageSkillHandler because the
|
||||||
|
* hit entity is added to the MythicMobs target list
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* Player casting the skill
|
||||||
|
* @param target
|
||||||
|
* Entity hit
|
||||||
|
*/
|
||||||
|
public void castSkill(PlayerData data, LivingEntity target) {
|
||||||
|
if (!data.getProfess().hasSkill(skill.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId()));
|
||||||
|
if (!cast.isSuccessful())
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.getSkillData().cacheModifiers(skill.getInternalName(), cast);
|
||||||
|
if (MMOCore.plugin.hasAntiCheat())
|
||||||
|
MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat());
|
||||||
|
List<Entity> targets = new ArrayList<>();
|
||||||
|
targets.add(data.getPlayer());
|
||||||
|
targets.add(target);
|
||||||
|
MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(),
|
||||||
|
targets, null, 1);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package net.Indyuce.mmocore.comp.mythicmobs.skill;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
|
||||||
|
import io.lumine.xikage.mythicmobs.MythicMobs;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import net.Indyuce.mmocore.api.skill.SkillResult;
|
||||||
|
|
||||||
|
public class PlayerDamageSkillHandler implements Listener {
|
||||||
|
private final MythicMobSkill skill;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to handle passive skills which trigger when a player is attacked by
|
||||||
|
* another entity
|
||||||
|
*
|
||||||
|
* @param skill
|
||||||
|
* Passive skill info
|
||||||
|
*/
|
||||||
|
public PlayerDamageSkillHandler(MythicMobSkill skill) {
|
||||||
|
this.skill = skill;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void playerDamage(EntityDamageEvent event) {
|
||||||
|
if (event.getEntityType() == EntityType.PLAYER)
|
||||||
|
castSkill(PlayerData.get((Player) event.getEntity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void castSkill(PlayerData data) {
|
||||||
|
if (!data.getProfess().hasSkill(skill.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId()));
|
||||||
|
if (!cast.isSuccessful())
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.getSkillData().cacheModifiers(skill.getInternalName(), cast);
|
||||||
|
if (MMOCore.plugin.hasAntiCheat())
|
||||||
|
MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat());
|
||||||
|
List<Entity> targets = new ArrayList<>();
|
||||||
|
targets.add(data.getPlayer());
|
||||||
|
MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(),
|
||||||
|
targets, null, 1);
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@ import net.Indyuce.mmocore.MMOCore;
|
|||||||
import net.Indyuce.mmocore.api.ConfigFile;
|
import net.Indyuce.mmocore.api.ConfigFile;
|
||||||
import net.Indyuce.mmocore.api.skill.Skill;
|
import net.Indyuce.mmocore.api.skill.Skill;
|
||||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicMobSkill;
|
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
|
||||||
|
|
||||||
public class SkillManager {
|
public class SkillManager {
|
||||||
private final Map<String, Skill> skills = new LinkedHashMap<>();
|
private final Map<String, Skill> skills = new LinkedHashMap<>();
|
||||||
|
@ -9,7 +9,6 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
|
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
|
||||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||||
@ -80,7 +79,6 @@ public abstract class PlayerDataManager {
|
|||||||
|
|
||||||
public abstract void remove(PlayerData data);
|
public abstract void remove(PlayerData data);
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class DefaultPlayerData {
|
public class DefaultPlayerData {
|
||||||
private final int level, classPoints, skillPoints, attributePoints, attrReallocPoints;
|
private final int level, classPoints, skillPoints, attributePoints, attrReallocPoints;
|
||||||
|
|
||||||
@ -99,5 +97,25 @@ public abstract class PlayerDataManager {
|
|||||||
attributePoints = 0;
|
attributePoints = 0;
|
||||||
attrReallocPoints = 0;
|
attrReallocPoints = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSkillPoints() {
|
||||||
|
return skillPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getClassPoints() {
|
||||||
|
return classPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAttrReallocPoints() {
|
||||||
|
return attrReallocPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAttributePoints() {
|
||||||
|
return attributePoints;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user