forked from Upstream/mmocore
Fixed passive skill binding
This commit is contained in:
parent
a0f0a38b34
commit
5c97b2520a
@ -1109,36 +1109,56 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
return slot >= boundSkills.size() ? null : boundSkills.get(slot);
|
return slot >= boundSkills.size() ? null : boundSkills.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundPassiveSkill(int slot, PassiveSkill skill) {
|
/**
|
||||||
|
* Registers a passive skill in the list. This method guarantees interface
|
||||||
|
* between ML passive skills and the MMOCore list.
|
||||||
|
*
|
||||||
|
* @param slot Slot to which you're binding the skill.
|
||||||
|
* Use -1 to force-register the skill
|
||||||
|
* @param skill Skill being bound
|
||||||
|
*/
|
||||||
|
public void bindPassiveSkill(int slot, @NotNull PassiveSkill skill) {
|
||||||
Validate.notNull(skill, "Skill cannot be null");
|
Validate.notNull(skill, "Skill cannot be null");
|
||||||
if (boundPassiveSkills.size() < getProfess().getMaxBoundActiveSkills())
|
final int maxBound = getProfess().getMaxBoundActiveSkills();
|
||||||
|
if (slot > 0 && boundPassiveSkills.size() >= maxBound) {
|
||||||
|
final @NotNull PassiveSkill current = boundPassiveSkills.set(slot, skill);
|
||||||
|
if (current != null)
|
||||||
|
current.unregister(mmoData);
|
||||||
|
skill.register(mmoData);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boundPassiveSkills.add(skill);
|
boundPassiveSkills.add(skill);
|
||||||
else
|
skill.register(mmoData);
|
||||||
boundPassiveSkills.set(slot, skill);
|
|
||||||
boundPassiveSkills.get(slot).register(getMMOPlayerData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPassiveSkillBound(int slot) {
|
public boolean hasPassiveSkillBound(int slot) {
|
||||||
return slot < boundPassiveSkills.size();
|
return slot < boundPassiveSkills.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public PassiveSkill getBoundPassiveSkill(int slot) {
|
public PassiveSkill getBoundPassiveSkill(int slot) {
|
||||||
return slot >= boundPassiveSkills.size() ? null : boundPassiveSkills.get(slot);
|
return slot >= boundPassiveSkills.size() ? null : boundPassiveSkills.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPassiveBoundSkill(PassiveSkill skill) {
|
@Deprecated
|
||||||
boundPassiveSkills.add(skill);
|
public void setBoundSkill(int slot, ClassSkill skill) {
|
||||||
skill.register(getMMOPlayerData());
|
bindActiveSkill(slot, skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundSkill(int slot, ClassSkill skill) {
|
/**
|
||||||
|
* Binds a skill to the player.
|
||||||
|
*
|
||||||
|
* @param slot Slot to which you're binding the skill.
|
||||||
|
* Use -1 to force-register the skill
|
||||||
|
* @param skill Skill being bound
|
||||||
|
*/
|
||||||
|
public void bindActiveSkill(int slot, ClassSkill skill) {
|
||||||
Validate.notNull(skill, "Skill cannot be null");
|
Validate.notNull(skill, "Skill cannot be null");
|
||||||
if (boundSkills.size() < getProfess().getMaxBoundActiveSkills())
|
if (slot > 0 && boundSkills.size() >= getProfess().getMaxBoundActiveSkills())
|
||||||
boundSkills.add(skill);
|
|
||||||
else
|
|
||||||
boundSkills.set(slot, skill);
|
boundSkills.set(slot, skill);
|
||||||
|
else
|
||||||
|
boundSkills.add(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbindSkill(int slot) {
|
public void unbindSkill(int slot) {
|
||||||
@ -1149,7 +1169,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
PassiveSkill skill = boundPassiveSkills.get(slot);
|
PassiveSkill skill = boundPassiveSkills.get(slot);
|
||||||
skill.unregister(getMMOPlayerData());
|
skill.unregister(getMMOPlayerData());
|
||||||
boundPassiveSkills.remove(slot);
|
boundPassiveSkills.remove(slot);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClassSkill> getBoundSkills() {
|
public List<ClassSkill> getBoundSkills() {
|
||||||
|
@ -358,16 +358,6 @@ public class SkillList extends EditableInventory {
|
|||||||
@Override
|
@Override
|
||||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||||
|
|
||||||
/*
|
|
||||||
if (skillSlots.contains(event.getRawSlot())
|
|
||||||
&& event.getRawSlot() != ((SkillItem) getEditable().getByFunction("skill")).selectedSkillSlot) {
|
|
||||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
|
|
||||||
playerData.skillGuiDisplayOffset = (playerData.skillGuiDisplayOffset + (event.getRawSlot() - 13)) % skills.size();
|
|
||||||
open();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (item.getFunction().equals("skill")) {
|
if (item.getFunction().equals("skill")) {
|
||||||
int index = skillSlots.size() * page + skillSlots.indexOf(context.getSlot());
|
int index = skillSlots.size() * page + skillSlots.indexOf(context.getSlot());
|
||||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
|
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
|
||||||
@ -377,8 +367,6 @@ public class SkillList extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.getFunction().equals("reallocation")) {
|
if (item.getFunction().equals("reallocation")) {
|
||||||
|
|
||||||
|
|
||||||
int spent = getPlayerData().countSkillPointsWhenReallocate();
|
int spent = getPlayerData().countSkillPointsWhenReallocate();
|
||||||
|
|
||||||
if (spent < 1) {
|
if (spent < 1) {
|
||||||
@ -455,7 +443,7 @@ public class SkillList extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||||
playerData.setBoundPassiveSkill(index, selected.toPassive(playerData));
|
playerData.bindPassiveSkill(index, selected.toPassive(playerData));
|
||||||
open();
|
open();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -497,7 +485,7 @@ public class SkillList extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||||
playerData.setBoundSkill(index, selected);
|
playerData.bindActiveSkill(index, selected);
|
||||||
open();
|
open();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
if (data.getProfess().hasSkill(id)) {
|
if (data.getProfess().hasSkill(id)) {
|
||||||
ClassSkill skill = data.getProfess().getSkill(id);
|
ClassSkill skill = data.getProfess().getSkill(id);
|
||||||
if (skill.getSkill().getTrigger().isPassive())
|
if (skill.getSkill().getTrigger().isPassive())
|
||||||
data.addPassiveBoundSkill(skill.toPassive(data));
|
data.bindPassiveSkill(-1, skill.toPassive(data));
|
||||||
else
|
else
|
||||||
data.getBoundSkills().add(skill);
|
data.getBoundSkills().add(skill);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
if (data.getProfess().hasSkill(id)) {
|
if (data.getProfess().hasSkill(id)) {
|
||||||
ClassSkill skill = data.getProfess().getSkill(id);
|
ClassSkill skill = data.getProfess().getSkill(id);
|
||||||
if (skill.getSkill().getTrigger().isPassive())
|
if (skill.getSkill().getTrigger().isPassive())
|
||||||
data.addPassiveBoundSkill(skill.toPassive(data));
|
data.bindPassiveSkill(-1, skill.toPassive(data));
|
||||||
else
|
else
|
||||||
data.getBoundSkills().add(skill);
|
data.getBoundSkills().add(skill);
|
||||||
|
|
||||||
|
@ -5,14 +5,12 @@ import io.lumine.mythic.lib.player.cooldown.CooldownObject;
|
|||||||
import io.lumine.mythic.lib.player.modifier.ModifierSource;
|
import io.lumine.mythic.lib.player.modifier.ModifierSource;
|
||||||
import io.lumine.mythic.lib.player.skill.PassiveSkill;
|
import io.lumine.mythic.lib.player.skill.PassiveSkill;
|
||||||
import io.lumine.mythic.lib.script.condition.Condition;
|
import io.lumine.mythic.lib.script.condition.Condition;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
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.gui.api.item.Placeholders;
|
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -121,10 +119,9 @@ public class ClassSkill implements CooldownObject {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Be careful, this method creates a new UUID each time it is called. Need to be remembered when trying to unregister passive skill
|
* Be careful, this method creates a new UUID each time it
|
||||||
* from PassiveSkillMap.
|
* is called. It needs to be saved somewhere when trying to
|
||||||
*
|
* unregister the passive skill from the skill map later on.
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public PassiveSkill toPassive(PlayerData caster) {
|
public PassiveSkill toPassive(PlayerData caster) {
|
||||||
Validate.isTrue(skill.getTrigger().isPassive(), "Skill is active");
|
Validate.isTrue(skill.getTrigger().isPassive(), "Skill is active");
|
||||||
|
Loading…
Reference in New Issue
Block a user