Fixed skill buffs not applying on cooldown & other mods

This commit is contained in:
Jules 2023-10-16 01:40:38 +02:00
parent 160c5d5699
commit 6565d7106b
15 changed files with 92 additions and 64 deletions

View File

@ -176,8 +176,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
public void setupRemovableTrigger() {
//We remove all the stats and buffs associated to triggers.
getMMOPlayerData().getStatMap().getInstances().forEach(statInstance -> statInstance.removeIf(key -> key.startsWith(Trigger.TRIGGER_PREFIX)));
getMMOPlayerData().getSkillModifierMap().getInstances().forEach(skillModifierInstance -> skillModifierInstance.removeIf(key -> key.startsWith(Trigger.TRIGGER_PREFIX)));
getMMOPlayerData().getStatMap().getInstances().forEach(statInstance -> statInstance.removeIf(Trigger.STAT_MODIFIER_KEY::equals));
getMMOPlayerData().getSkillModifierMap().getInstances().forEach(skillModifierInstance -> skillModifierInstance.removeIf(Trigger.STAT_MODIFIER_KEY::equals));
if (profess.hasExperienceTable())
profess.getExperienceTable().claimRemovableTrigger(this, profess);
@ -250,7 +250,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
Iterator<StatModifier> iter = instance.getModifiers().iterator();
while (iter.hasNext()) {
StatModifier modifier = iter.next();
if (modifier.getKey().startsWith(StatTrigger.TRIGGER_PREFIX)) iter.remove();
if (modifier.getKey().startsWith(StatTrigger.STAT_MODIFIER_KEY)) iter.remove();
}
}
}
@ -357,7 +357,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
/**
* @return If the item is unlocked by the player
* This is used for skills that can be locked & unlocked.
* This is used for skills that can be locked & unlocked.
*/
public boolean hasUnlocked(Unlockable unlockable) {
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey());
@ -1017,7 +1017,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
/**
* @return If the PlayerEnterCastingModeEvent successfully put the player
* into casting mode, otherwise if the event is cancelled, returns false.
* into casting mode, otherwise if the event is cancelled, returns false.
*/
public boolean setSkillCasting() {
Validate.isTrue(!isCasting(), "Player already in casting mode");
@ -1036,7 +1036,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
/**
* @return If player successfully left skill casting i.e the Bukkit
* event has not been cancelled
* event has not been cancelled
*/
public boolean leaveSkillCasting() {
return leaveSkillCasting(false);
@ -1045,7 +1045,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
/**
* @param skipEvent Skip firing the exit event
* @return If player successfully left skill casting i.e the Bukkit
* event has not been cancelled
* event has not been cancelled
*/
public boolean leaveSkillCasting(boolean skipEvent) {
Validate.isTrue(isCasting(), "Player not in casting mode");
@ -1161,6 +1161,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
boundSkills.forEach((slot, info) -> info.close());
boundSkills.clear();
setupRemovableTrigger();
// Update stats
if (isOnline()) getStats().updateStats();
}
@ -1187,15 +1188,12 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
*/
public void bindSkill(int slot, @NotNull ClassSkill skill) {
Validate.notNull(skill, "Skill cannot be null");
if (slot < 0) return;
if (slot >= 0) {
// Unbinds the previous skill (important for passive skills)
unbindSkill(slot);
final SkillSlot skillSlot = getProfess().getSkillSlot(slot);
boundSkills.put(slot, new BoundSkillInfo(skillSlot, skill, this));
}
// Unbinds the previous skill (important for passive skills)
unbindSkill(slot);
final SkillSlot skillSlot = getProfess().getSkillSlot(slot);
boundSkills.put(slot, new BoundSkillInfo(skillSlot, skill, this));
}
public void unbindSkill(int slot) {
@ -1221,7 +1219,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
* checks if they could potentially upgrade to one of these
*
* @return If the player can change its current class to
* a subclass
* a subclass
*/
@Deprecated
public boolean canChooseSubclass() {

View File

@ -12,11 +12,6 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.player.stats.StatInfo;
import net.Indyuce.mmocore.skill.ClassSkill;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class PlayerStats {
private final PlayerData data;
@ -78,6 +73,8 @@ public class PlayerStats {
* see {@link PlayerData#reload()} for more info
*/
public synchronized void updateStats() {
// Update player stats
for (String stat : MMOCore.plugin.statManager.getRegistered()) {
final StatInstance instance = getMap().getInstance(stat);
final StatInstance.ModifierPacket packet = instance.newPacket();
@ -94,22 +91,17 @@ public class PlayerStats {
packet.runUpdate();
}
/*
* This is here because it requires updates for the same reasons
* as statistics (when the player level changes, when his class
* changes, when he logs on..)
*
* This updates the player's PASSIVE skills
*/
// Updates the player's unbindable passive skills.
final PassiveSkillMap skillMap = data.getMMOPlayerData().getPassiveSkillMap();
skillMap.removeModifiers("MMOCorePassiveSkillNotBound");
data.getProfess().getSkills()
.stream()
.filter((classSkill) -> !classSkill.needsBound()&&classSkill.getSkill().getTrigger().isPassive() && data.hasUnlocked(classSkill) && data.hasUnlockedLevel(classSkill))
data.getProfess().getSkills().stream()
.filter((classSkill) -> !classSkill.needsBound() && classSkill.getSkill().getTrigger().isPassive() && data.hasUnlocked(classSkill) && data.hasUnlockedLevel(classSkill))
.forEach(classSkill -> skillMap.addModifier(classSkill.toPassive(data)));
// This updates the player's class SCRIPTS
/*
* Updates the player's class scripts, which act just
* like non-bindable passive skills.
*/
skillMap.removeModifiers("MMOCoreClassScript");
for (PassiveSkill script : data.getProfess().getScripts())
skillMap.addModifier(script);

View File

@ -12,11 +12,9 @@ import net.Indyuce.mmocore.skill.RegisteredSkill;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SkillModifierTrigger extends Trigger implements Removable {
private final SkillModifier mod;
private final String buffKey = TRIGGER_PREFIX + "." + UUID.randomUUID();
private final double amount;
public SkillModifierTrigger(MMOLineConfig config) {
@ -34,7 +32,7 @@ public class SkillModifierTrigger extends Trigger implements Removable {
if (skill.matchesFormula(formula))
targetSkills.add(skill.getHandler());
mod = new SkillModifier(buffKey, skillModifier, targetSkills, amount, type);
mod = new SkillModifier(Trigger.STAT_MODIFIER_KEY, skillModifier, targetSkills, amount, type);
}
public List<SkillHandler<?>> getTargetSkills() {

View File

@ -7,12 +7,9 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.api.Removable;
import org.apache.commons.lang.Validate;
import java.util.UUID;
public class StatTrigger extends Trigger implements Removable {
private final StatModifier statModifier;
private final StatModifier modifier;
private final String stat;
private final String modifierKey = TRIGGER_PREFIX + "." + UUID.randomUUID();
private final double amount;
public StatTrigger(MMOLineConfig config) {
@ -25,14 +22,14 @@ public class StatTrigger extends Trigger implements Removable {
Validate.isTrue(type.equals("FLAT") || type.equals("RELATIVE"));
stat = config.getString("stat");
amount = config.getDouble("amount");
statModifier = new StatModifier(modifierKey, stat, amount, ModifierType.valueOf(type));
modifier = new StatModifier(Trigger.STAT_MODIFIER_KEY, stat, amount, ModifierType.valueOf(type));
}
@Override
public void apply(PlayerData player) {
StatModifier prevModifier = player.getMMOPlayerData().getStatMap().getInstance(stat).getModifier(modifierKey);
StatModifier prevModifier = player.getMMOPlayerData().getStatMap().getInstance(stat).getModifier(modifier.getUniqueId());
if (prevModifier == null)
statModifier.register(player.getMMOPlayerData());
modifier.register(player.getMMOPlayerData());
else {
prevModifier.unregister(player.getMMOPlayerData());
prevModifier.add(amount).register(player.getMMOPlayerData());
@ -41,6 +38,6 @@ public class StatTrigger extends Trigger implements Removable {
@Override
public void remove(PlayerData playerData) {
playerData.getMMOPlayerData().getStatMap().getInstance(stat).remove(modifierKey);
modifier.unregister(playerData.getMMOPlayerData());
}
}

View File

@ -7,7 +7,7 @@ import org.bukkit.Bukkit;
public abstract class Trigger {
public static String TRIGGER_PREFIX = "mmocore_trigger";
public static String STAT_MODIFIER_KEY = "mmocore_trigger";
private final long delay;
public Trigger(MMOLineConfig config) {

View File

@ -12,6 +12,7 @@ import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.skill.CastableSkill;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import org.bukkit.Bukkit;
@ -58,10 +59,11 @@ public class RPGPlaceholders extends PlaceholderExpansion {
public String onRequest(OfflinePlayer player, String identifier) {
if (!PlayerData.has(player.getUniqueId()))
return null;
final PlayerData playerData = PlayerData.get(player);
PlayerData playerData = PlayerData.get(player);
if (identifier.equals("mana_icon"))
return playerData.getProfess().getManaDisplay().getIcon();
if (identifier.equals("mana_name"))
return playerData.getProfess().getManaDisplay().getName();
@ -72,15 +74,19 @@ public class RPGPlaceholders extends PlaceholderExpansion {
String id = identifier.substring(12);
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(id), "Could not find skill with ID '" + id + "'");
return String.valueOf(playerData.getSkillLevel(skill));
} else if (identifier.startsWith("skill_modifier_") || identifier.startsWith("skill_parameter_")) {
String[] ids = (identifier.startsWith("skill_modifier_") ? identifier.substring(15) : identifier.substring(16)).split(":");
String parameterId = ids[0];
String skillId = ids[1];
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(skillId), "Could not find skill with ID '" + skillId + "'");
ClassSkill classSkill = playerData.getProfess().getSkill(skill);
double value = classSkill.toCastable(playerData).getParameter(parameterId);
}
else if (identifier.startsWith("skill_modifier_") || identifier.startsWith("skill_parameter_")) {
final String[] ids = (identifier.startsWith("skill_modifier_") ? identifier.substring(15) : identifier.substring(16)).split(":");
final String parameterId = ids[0];
final String skillId = ids[1];
final RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(skillId), "Could not find skill with ID '" + skillId + "'");
final CastableSkill castable = playerData.getProfess().getSkill(skill).toCastable(playerData);
final double value = playerData.getMMOPlayerData().getSkillModifierMap().calculateValue(castable, parameterId);
return MythicLib.plugin.getMMOConfig().decimal.format(value);
} else if (identifier.startsWith("attribute_points_spent_")) {
}
else if (identifier.startsWith("attribute_points_spent_")) {
String attributeId = identifier.substring(31);
PlayerAttributes.AttributeInstance attributeInstance = Objects.requireNonNull(playerData.getAttributes().getInstance(attributeId), "Could not find attribute with ID '" + attributeId + "'");
return String.valueOf(attributeInstance.getSpent());

View File

@ -65,15 +65,15 @@ public class CastableSkill extends Skill {
}
// Mana cost
if (playerData.getMana() < getParameter("mana")) {
if (playerData.getMana() < skillMeta.getParameter("mana")) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-mana",
"mana-required", MythicLib.plugin.getMMOConfig().decimal.format((getParameter("mana") - playerData.getMana())),
"mana-required", MythicLib.plugin.getMMOConfig().decimal.format((skillMeta.getParameter("mana") - playerData.getMana())),
"mana", playerData.getProfess().getManaDisplay().getName()).send(playerData.getPlayer());
return false;
}
// Stamina cost
if (playerData.getStamina() < getParameter("stamina")) {
if (playerData.getStamina() < skillMeta.getParameter("stamina")) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-stamina").send(playerData.getPlayer());
return false;
@ -95,11 +95,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, getParameter("cooldown"));
CooldownInfo cooldownHandler = skillMeta.getCaster().getData().getCooldownMap().applyCooldown(this, skillMeta.getParameter("cooldown"));
cooldownHandler.reduceInitialCooldown(flatCooldownReduction);
casterData.giveMana(-getParameter("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveStamina(-getParameter("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveMana(-skillMeta.getParameter("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveStamina(-skillMeta.getParameter("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
}
if (!getTrigger().isPassive())

View File

@ -4,6 +4,8 @@ import io.lumine.mythic.lib.player.skill.PassiveSkill;
import io.lumine.mythic.lib.skill.SkillMetadata;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import io.lumine.mythic.lib.skill.result.def.SimpleSkillResult;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
@ -33,7 +35,7 @@ public class Neptune_Gift extends SkillHandler<SimpleSkillResult> implements Lis
if (skill == null)
return;
event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getParameter("extra") / 100));
event.setAmount(event.getAmount() * (1 + event.getData().getMMOPlayerData().getSkillModifierMap().calculateValue(skill.getTriggeredSkill(), "extra") / 100));
}
}
}

View File

@ -35,15 +35,19 @@ skill-slots:
1:
name: "&aSkill Slot I"
unlocked-by-default: true
lore: []
2:
name: "&aSkill Slot II"
unlocked-by-default: true
lore: []
3:
name: "&aSkill Slot III"
unlocked-by-default: true
lore: []
4:
name: "&aSkill Slot IV"
unlocked-by-default: true
lore: []
# The maximum level players can reach
max-level: 100

View File

@ -26,15 +26,19 @@ skill-slots:
1:
name: "&aSkill Slot I"
unlocked-by-default: true
lore: []
2:
name: "&aSkill Slot II"
unlocked-by-default: true
lore: []
3:
name: "&aSkill Slot III"
unlocked-by-default: true
lore: []
4:
name: "&aSkill Slot IV"
unlocked-by-default: true
lore: []
# Experience sources for main class experience.
main-exp-sources:

View File

@ -42,15 +42,26 @@ skill-slots:
1:
name: "&aSkill Slot I"
unlocked-by-default: true
lore:
- ''
- '&a-50% Cooldown &7for Active Skills'
- '&a+30% Damage &7for Active Skills'
formula: "<ACTIVE>"
skill-buffs:
- 'skill_buff{modifier="cooldown";amount=-50;type="RELATIVE"}'
- 'skill_buff{modifier="damage";amount=30;type="RELATIVE"}'
2:
name: "&aSkill Slot II"
unlocked-by-default: true
lore: []
3:
name: "&aSkill Slot III"
unlocked-by-default: true
lore: []
4:
name: "&aSkill Slot IV"
unlocked-by-default: true
lore: []
# This is the default mana display options, however it is not mandatory
# to have it in your class config file. Other classes do not have this
@ -81,13 +92,13 @@ resource:
# Scales with max mana.
type: MAX
# Regen from 3 to 10% of max mana every second
value:
base: 3
per-level: .1
max: 10
# Only regen when out of combat.
off-combat: true
@ -116,7 +127,7 @@ skills:
FIRE_STORM:
level: 1
max-level: 30
# Specific skill modifiers based on class.
# Arcane mage's fire storm may deal more damage
# than an apprentice mage's fire storm.

View File

@ -37,15 +37,19 @@ skill-slots:
1:
name: "&aSkill Slot I"
unlocked-by-default: true
lore: []
2:
name: "&aSkill Slot II"
unlocked-by-default: true
lore: []
3:
name: "&aSkill Slot III"
unlocked-by-default: true
lore: []
4:
name: "&aSkill Slot IV"
unlocked-by-default: true
lore: []
skill-trees:
- 'general'

View File

@ -34,15 +34,19 @@ skill-slots:
1:
name: "&aSkill Slot I"
unlocked-by-default: true
lore: []
2:
name: "&aSkill Slot II"
unlocked-by-default: true
lore: []
3:
name: "&aSkill Slot III"
unlocked-by-default: true
lore: []
4:
name: "&aSkill Slot IV"
unlocked-by-default: true
lore: []
skill-trees:
- 'general'

View File

@ -37,15 +37,19 @@ skill-slots:
1:
name: "&aSkill Slot I"
unlocked-by-default: true
lore: []
2:
name: "&aSkill Slot II"
unlocked-by-default: true
lore: []
3:
name: "&aSkill Slot III"
unlocked-by-default: true
lore: []
4:
name: "&aSkill Slot IV"
unlocked-by-default: true
lore: []
skill-trees:
- 'general'

View File

@ -40,15 +40,19 @@ skill-slots:
1:
name: "Skill Slot I"
unlocked-by-default: true
lore: []
2:
name: "Skill Slot II"
unlocked-by-default: true
lore: []
3:
name: "Skill Slot III"
unlocked-by-default: true
lore: []
4:
name: "Skill Slot IV"
unlocked-by-default: true
lore: []
skill-trees:
- 'general'