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:
ASangarin 2020-10-29 20:16:05 +01:00
parent b33f8dea42
commit de92993645
3 changed files with 83 additions and 7 deletions

View File

@ -67,8 +67,19 @@ public class PlayerSkillData {
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) {
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() {

View File

@ -7,9 +7,15 @@ import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
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.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.LinearValue;
import net.Indyuce.mmocore.comp.anticheat.CheatType;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class MythicMobSkill extends Skill {
private final io.lumine.xikage.mythicmobs.skills.Skill skill;
@ -47,7 +54,7 @@ public class MythicMobSkill extends Skill {
setName(config.getString("name"));
setLore(config.getStringList("lore"));
for (String key : config.getKeys(false)) {
Object mod = config.get(key);
if (mod instanceof ConfigurationSection)
@ -56,12 +63,20 @@ public class MythicMobSkill extends Skill {
if (config.isConfigurationSection("disable-anti-cheat"))
for(String key : config.getConfigurationSection("").getKeys(false)) {
Optional<CheatType> optional = Enums.getIfPresent(CheatType.class, key.toUpperCase());
if(optional.isPresent() && config.isInt("disable-anti-cheat." + key))
antiCheat.put(optional.get(), config.getInt("disable-anti-cheat." + key));
Optional<CheatType> cheatType = Enums.getIfPresent(CheatType.class, key.toUpperCase());
if(cheatType.isPresent() && config.isInt("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 + "'!");
}
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
// TargetSkillResult(data, info, def(config.getDouble("range"), 50)) :
// (data, info) -> new SkillResult(data, info);
@ -71,6 +86,17 @@ public class MythicMobSkill extends Skill {
// 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() {
return skill.getInternalName();
}
@ -80,6 +106,7 @@ public class MythicMobSkill extends Skill {
SkillResult cast = new SkillResult(data, skill);
if (!cast.isSuccessful() || !data.isOnline())
return cast;
if(isPassive()) return cast;
List<Entity> targets = new ArrayList<>();
// 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
*/
data.getSkillData().cacheModifiers(this, cast);
if(MMOCore.plugin.hasAntiCheat()) MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), antiCheat);
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(),
data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1))
@ -98,7 +124,7 @@ public class MythicMobSkill extends Skill {
return cast;
}
/*
* used to load double modifiers from the config with a specific type, since
* modifiers have initially a type for mmocore default skills
@ -106,4 +132,37 @@ public class MythicMobSkill extends Skill {
private LinearValue readLinearValue(ConfigurationSection 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()));
}
}
}

View File

@ -0,0 +1,6 @@
package net.Indyuce.mmocore.comp.mythicmobs;
public enum PassiveSkillType {
PLAYER_ATTACK,
PLAYER_DAMAGE;
}