forked from Upstream/mmocore
PASSIVE SKILLS.
You can now turn your custom mythic mob skills into passives. This feature is WIP and will be improved and extended in the future!!
This commit is contained in:
parent
b33f8dea42
commit
de92993645
@ -67,8 +67,19 @@ public class PlayerSkillData {
|
|||||||
cacheModifier(mmSkill, "level", cast.getLevel());
|
cacheModifier(mmSkill, "level", cast.getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cacheModifiers(String skill, SkillResult cast) {
|
||||||
|
for (String modifier : cast.getSkill().getModifiers())
|
||||||
|
cacheModifier(skill, modifier, cast.getModifier(modifier));
|
||||||
|
|
||||||
|
cacheModifier(skill, "level", cast.getLevel());
|
||||||
|
}
|
||||||
|
|
||||||
public void cacheModifier(MythicMobSkill skill, String name, double value) {
|
public void cacheModifier(MythicMobSkill skill, String name, double value) {
|
||||||
cache.put(skill.getInternalName() + "." + name, new CachedModifier(value));
|
cacheModifier(skill.getInternalName(), name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cacheModifier(String skill, String name, double value) {
|
||||||
|
cache.put(skill + "." + name, new CachedModifier(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
@ -7,9 +7,15 @@ import java.util.Map;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
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;
|
||||||
@ -24,6 +30,7 @@ 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;
|
||||||
@ -56,12 +63,20 @@ 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.getConfigurationSection("").getKeys(false)) {
|
||||||
Optional<CheatType> optional = Enums.getIfPresent(CheatType.class, key.toUpperCase());
|
Optional<CheatType> cheatType = Enums.getIfPresent(CheatType.class, key.toUpperCase());
|
||||||
if(optional.isPresent() && config.isInt("disable-anti-cheat." + key))
|
if(cheatType.isPresent() && config.isInt("disable-anti-cheat." + key))
|
||||||
antiCheat.put(optional.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")) {
|
||||||
|
Optional<PassiveSkillType> passiveType = Enums.getIfPresent(PassiveSkillType.class, config.getString("passive-type").toUpperCase());
|
||||||
|
Validate.isTrue(passiveType.isPresent(), "Invalid 'passive-type' for MM skill: " + id);
|
||||||
|
setPassive();
|
||||||
|
Bukkit.getPluginManager().registerEvents(getListener(passiveType.get()), MMOCore.plugin);
|
||||||
|
}
|
||||||
|
|
||||||
// cast = config.getBoolean("target") ? (data, info) -> new
|
// cast = config.getBoolean("target") ? (data, info) -> new
|
||||||
// TargetSkillResult(data, info, def(config.getDouble("range"), 50)) :
|
// TargetSkillResult(data, info, def(config.getDouble("range"), 50)) :
|
||||||
// (data, info) -> new SkillResult(data, info);
|
// (data, info) -> new SkillResult(data, info);
|
||||||
@ -71,6 +86,17 @@ public class MythicMobSkill extends Skill {
|
|||||||
// return d == 0 ? def : d;
|
// return d == 0 ? def : d;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
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() {
|
||||||
return skill.getInternalName();
|
return skill.getInternalName();
|
||||||
}
|
}
|
||||||
@ -80,6 +106,7 @@ public class MythicMobSkill extends Skill {
|
|||||||
SkillResult cast = new SkillResult(data, skill);
|
SkillResult cast = new SkillResult(data, skill);
|
||||||
if (!cast.isSuccessful() || !data.isOnline())
|
if (!cast.isSuccessful() || !data.isOnline())
|
||||||
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)
|
||||||
@ -90,7 +117,6 @@ public class MythicMobSkill extends Skill {
|
|||||||
* 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()) MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), antiCheat);
|
||||||
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(),
|
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(),
|
||||||
data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1))
|
data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1))
|
||||||
@ -106,4 +132,37 @@ public class MythicMobSkill extends Skill {
|
|||||||
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,6 @@
|
|||||||
|
package net.Indyuce.mmocore.comp.mythicmobs;
|
||||||
|
|
||||||
|
public enum PassiveSkillType {
|
||||||
|
PLAYER_ATTACK,
|
||||||
|
PLAYER_DAMAGE;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user