Merging skill update 1

This commit is contained in:
Jules 2023-04-09 11:31:08 +02:00
parent 841264df95
commit 786d1881bf
9 changed files with 41 additions and 29 deletions

View File

@ -12,15 +12,19 @@ import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
import net.Indyuce.mmocore.api.event.unlocking.ItemLockedEvent;
import net.Indyuce.mmocore.api.event.unlocking.ItemUnlockedEvent;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.player.profess.Subclass;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.api.player.profess.skillbinding.BoundSkillInfo;
import net.Indyuce.mmocore.api.player.social.FriendRequest;
import net.Indyuce.mmocore.api.player.stats.PlayerStats;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.Indyuce.mmocore.api.quest.trigger.StatTrigger;
import net.Indyuce.mmocore.api.util.Closable;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.EXPSource;
@ -32,6 +36,8 @@ import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
import net.Indyuce.mmocore.party.provided.Party;
import net.Indyuce.mmocore.player.ClassDataContainer;
import net.Indyuce.mmocore.player.CombatHandler;
import net.Indyuce.mmocore.player.Unlockable;
@ -118,6 +124,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
* -Skill Books
*/
private final Set<String> unlockedItems= new HashSet<>();
/**
* Saves the amount of times the player has claimed some
* exp item in exp tables, for both exp tables used
@ -396,12 +403,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
* @return If the item was locked when calling this method.
*/
public boolean unlock(Unlockable unlockable) {
boolean wasLocked = unlockedItems.add(unlockable.getUnlockNamespacedKey());
final boolean wasLocked = unlockedItems.add(unlockable.getUnlockNamespacedKey());
// Call the event synchronously
if (wasLocked)
//Calls the event synchronously
Bukkit.getScheduler().runTask(MythicLib.plugin,
() -> Bukkit.getPluginManager().callEvent(new ItemUnlockedEvent(this, unlockable.getUnlockNamespacedKey())));
Bukkit.getScheduler().runTask(MythicLib.plugin, () -> Bukkit.getPluginManager().callEvent(new ItemUnlockedEvent(this, unlockable.getUnlockNamespacedKey())));
return wasLocked;
}
@ -1174,7 +1179,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
if (isOnline())
getStats().updateStats();
//Loads the classUnlockedSkills
// Loads the classUnlockedSkills
profess.getSkills()
.stream()
.filter(ClassSkill::isUnlockedByDefault)

View File

@ -5,9 +5,12 @@ import com.google.gson.JsonObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.player.ClassDataContainer;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import java.util.HashMap;
@ -311,14 +314,12 @@ public class SavedClassInformation {
player.setClass(profess);
player.unloadClassInfo(profess);
//This needs to be done at the end to make sure the MAX_HEALTH/MAX_MANA/... stats are loaded.
player.getPlayer().setHealth(Math.min(health, player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
// This needs to be done at the end to make sure the MAX_HEALTH/MAX_MANA/... stats are loaded.
player.getPlayer().setHealth(MMOCoreUtils.fixResource(health, player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
player.setMana(mana);
player.setStellium(stellium);
player.setStamina(stamina);
double health=this.health;
health = health == 0 ? 20 : health;
player.getPlayer().setHealth(Math.min(health,player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
// Updates level on exp bar
player.refreshVanillaExp();
}

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmocore.api.quest.trigger;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.skill.SkillBuff;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.api.Removable;
@ -19,6 +18,7 @@ public class SkillBuffTrigger extends Trigger implements Removable {
public SkillBuffTrigger(MMOLineConfig config) {
super(config);
config.validateKeys("modifier");
config.validateKeys("amount");
config.validateKeys("formula");
@ -27,10 +27,10 @@ public class SkillBuffTrigger extends Trigger implements Removable {
String skillModifier = config.getString("modifier");
String formula = config.getString("formula");
List<String> targetSkills = new ArrayList<>();
for (RegisteredSkill skill : MMOCore.plugin.skillManager.getAll()) {
for (RegisteredSkill skill : MMOCore.plugin.skillManager.getAll())
if (skill.matchesFormula(formula))
targetSkills.add(skill.getHandler().getId());
}
skillBuff = new SkillBuff(buffKey, skillModifier, targetSkills, amount);
}

View File

@ -39,6 +39,10 @@ public class MMOCoreUtils {
: caseOnWords(item.getType().name().replace("_", " "));
}
public static double fixResource(double current, double maxStat) {
return current == 0 ? maxStat : Math.min(current, maxStat);
}
public static String caseOnWords(String s) {
StringBuilder builder = new StringBuilder(s);
boolean isLastSpace = true;

View File

@ -1,4 +1,6 @@
package net.Indyuce.mmocore.api.player;
package net.Indyuce.mmocore.player;
import net.Indyuce.mmocore.api.player.PlayerData;
/**
* Some item that can be unlocked. All unlockables are saved in the

View File

@ -45,18 +45,20 @@ public class CastableSkill extends Skill {
// Cooldown check
if (skillMeta.getCaster().getData().getCooldownMap().isOnCooldown(this)) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.on-cooldown",
"cooldown",MythicLib.plugin.getMMOConfig().decimal.format(skillMeta.getCaster().getData().getCooldownMap().getCooldown(this))).send(playerData.getPlayer());
"cooldown", MythicLib.plugin.getMMOConfig().decimal.format(skillMeta.getCaster().getData().getCooldownMap().getCooldown(this))).send(playerData.getPlayer());
return false;
}
// Mana cost
if (playerData.getMana() < getModifier("mana",playerData.getMMOPlayerData())) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-mana", "mana-required",MythicLib.plugin.getMMOConfig().decimal.format((getModifier("mana",playerData.getMMOPlayerData())-playerData.getMana())),"mana", playerData.getProfess().getManaDisplay().getName()).send(playerData.getPlayer());
if (playerData.getMana() < getModifier("mana")) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-mana",
"mana-required", MythicLib.plugin.getMMOConfig().decimal.format((getModifier("mana") - playerData.getMana())),
"mana", playerData.getProfess().getManaDisplay().getName()).send(playerData.getPlayer());
return false;
}
// Stamina cost
if (playerData.getStamina() < getModifier("stamina",skillMeta.getCaster().getData())) {
if (playerData.getStamina() < getModifier("stamina")) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-stamina").send(playerData.getPlayer());
return false;
}
@ -77,11 +79,11 @@ public class CastableSkill extends Skill {
// Cooldown
double flatCooldownReduction = Math.max(0, Math.min(1, skillMeta.getCaster().getStat("COOLDOWN_REDUCTION") / 100));
CooldownInfo cooldownHandler = skillMeta.getCaster().getData().getCooldownMap().applyCooldown(this, getModifier("cooldown",casterData.getMMOPlayerData()));
CooldownInfo cooldownHandler = skillMeta.getCaster().getData().getCooldownMap().applyCooldown(this, getModifier("cooldown"));
cooldownHandler.reduceInitialCooldown(flatCooldownReduction);
casterData.giveMana(-getModifier("mana",skillMeta.getCaster().getData()), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveStamina(-getModifier("stamina",casterData.getMMOPlayerData()), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveMana(-getModifier("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveStamina(-getModifier("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
}
if (!getTrigger().isPassive())
@ -94,8 +96,7 @@ public class CastableSkill extends Skill {
}
@Override
public double getModifier(String mod, MMOPlayerData playerData) {
return playerData.getSkillBuffMap().getSkillInstance(getHandler().getId())
.getSkillModifier(mod).getTotal(skill.getModifier(mod, skillLevel));
public double getModifier(String mod) {
return skill.getModifier(mod, skillLevel);
}
}

View File

@ -5,9 +5,8 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.Unlockable;
import net.Indyuce.mmocore.player.Unlockable;
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;

View File

@ -34,7 +34,7 @@ public class Neptune_Gift extends SkillHandler<SimpleSkillResult> implements Lis
if (skill == null)
return;
event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getModifier("extra", PlayerData.get(event.getPlayer()).getMMOPlayerData()) / 100));
event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getModifier("extra") / 100));
}
}
}

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.Unlockable;
import net.Indyuce.mmocore.player.Unlockable;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance;
import org.apache.commons.lang.Validate;