mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
stat component weird stuff
This commit is contained in:
parent
7446e1137c
commit
20d1a13f5c
@ -172,7 +172,7 @@ public class ItemStats {
|
||||
UPGRADE = new UpgradeStat(),
|
||||
DOWNGRADE_ON_BREAK = new BooleanStat("BREAK_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade when Broken", new String[]{"If this item's durability reaches 0,", "it will be fully repaired but also", "downgraded by one level.", "", "&cIt will only break if it cannot be", "&cdowngraded further", "", "Requires to define an &6Upgrade Template", "Required to define &6Custom Durability"}, new String[] { "piercing", "slashing", "blunt", "offhand", "range", "tool", "armor", "consumable", "accessory" }),
|
||||
DOWNGRADE_ON_DEATH = new BooleanStat("DEATH_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade on Death", new String[]{"If the wearer of this item dies, it may", "downgrade (based on &6Death Downgrade", "&6Chance &7stat)", "", "Required to define an &6Upgrade Template", "Requires keep-inventory gamerule. "}, new String[] { "piercing", "slashing", "blunt", "offhand", "range", "tool", "armor", "consumable", "accessory" }),
|
||||
DOWNGRADE_ON_DEATH_CHANCE = new EvilDoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", new String[]{"Probability that an item with &cDowngrade ", "&con Death&7 will be downgraded when the", "player dies. ", "", "Exceeding 100% will for sure downgrade", "one item, and roll again to downgrade", "another (with the excess probability).", "&6The same item wont be downgraded twice."}, new String[]{"!miscellaneous", "!block", "all"}),
|
||||
DOWNGRADE_ON_DEATH_CHANCE = new DoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", new String[]{"Probability that an item with &cDowngrade ", "&con Death&7 will be downgraded when the", "player dies. ", "", "Exceeding 100% will for sure downgrade", "one item, and roll again to downgrade", "another (with the excess probability).", "&6The same item wont be downgraded twice."}, new String[]{"!miscellaneous", "!block", "all"}, false),
|
||||
|
||||
// Unique Item Stats
|
||||
SKULL_TEXTURE = new SkullTextureStat(),
|
||||
|
@ -0,0 +1,6 @@
|
||||
package net.Indyuce.mmoitems.stat.component;
|
||||
|
||||
public interface Mergeable<T extends StatComponent> {
|
||||
|
||||
public void merge(T t);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package net.Indyuce.mmoitems.stat.component;
|
||||
|
||||
public abstract class StatComponent {
|
||||
private final String path;
|
||||
|
||||
public StatComponent(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package net.Indyuce.mmoitems.stat.component;
|
||||
|
||||
public interface Upgradable {
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package net.Indyuce.mmoitems.stat.component.type;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.component.StatComponent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class AbstractObjectComponent extends StatComponent {
|
||||
public AbstractObjectComponent(String path) {
|
||||
super(path);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public StatComponent findComponent(String path) {
|
||||
String[] split = path.split("\\.");
|
||||
|
||||
AbstractObjectComponent current = this;
|
||||
int n = split.length - 1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
StatComponent next = getComponent(split[i]);
|
||||
if (next == null || !(next instanceof AbstractObjectComponent))
|
||||
return null;
|
||||
|
||||
current = (AbstractObjectComponent) next;
|
||||
}
|
||||
|
||||
return current.getComponent(split[n]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract StatComponent getComponent(String path);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.Indyuce.mmoitems.stat.component.type;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.component.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.component.StatComponent;
|
||||
|
||||
public class DoubleComponent extends StatComponent implements Mergeable<DoubleComponent> {
|
||||
private double value;
|
||||
|
||||
public DoubleComponent(String path) {
|
||||
super(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(DoubleComponent component) {
|
||||
value += component.value;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package net.Indyuce.mmoitems.stat.component.type;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.component.StatComponent;
|
||||
import net.Indyuce.mmoitems.stat.component.Upgradable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ObjectComponent extends AbstractObjectComponent implements Upgradable {
|
||||
private final Map<String, StatComponent> components = new HashMap<>();
|
||||
|
||||
public ObjectComponent(String path) {
|
||||
super(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public StatComponent getComponent(String path) {
|
||||
return components.get(path);
|
||||
}
|
||||
|
||||
public void forEachComponent(Consumer<StatComponent> action) {
|
||||
for (StatComponent component : components.values())
|
||||
action.accept(component);
|
||||
}
|
||||
|
||||
public Set<String> getComponentKeys() {
|
||||
return components.keySet();
|
||||
}
|
||||
}
|
@ -39,15 +39,23 @@ import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class DoubleStat extends ItemStat implements Upgradable, Previewable {
|
||||
private static final DecimalFormat digit = new DecimalFormat("0.####");
|
||||
private final boolean moreIsBetter;
|
||||
|
||||
public DoubleStat(String id, Material mat, String name, String[] lore) {
|
||||
super(id, mat, name, lore, new String[] { "!miscellaneous", "!block", "all" });
|
||||
}
|
||||
private static final DecimalFormat digit = new DecimalFormat("0.####");
|
||||
|
||||
public DoubleStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) {
|
||||
super(id, mat, name, lore, types, materials);
|
||||
}
|
||||
public DoubleStat(String id, Material mat, String name, String[] lore) {
|
||||
this(id, mat, name, lore, new String[]{"!miscellaneous", "!block", "all"}, true);
|
||||
}
|
||||
|
||||
public DoubleStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) {
|
||||
this(id, mat, name, lore, types, true, materials);
|
||||
}
|
||||
|
||||
public DoubleStat(String id, Material mat, String name, String[] lore, String[] types, boolean moreIsBetter, Material... materials) {
|
||||
super(id, mat, name, lore, types, materials);
|
||||
|
||||
this.moreIsBetter = moreIsBetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If this stat supports negatives stat values
|
||||
@ -67,7 +75,7 @@ public class DoubleStat extends ItemStat implements Upgradable, Previewable {
|
||||
* Usually, a greater magnitude of stat benefits the player (more health, more attack damage).
|
||||
* <p>However, its not impossible for a stat to be evil instead, who knows?
|
||||
*/
|
||||
public boolean moreIsBetter() { return true; }
|
||||
public boolean moreIsBetter() { return moreIsBetter; }
|
||||
|
||||
@Override
|
||||
public RandomStatData whenInitialized(Object object) {
|
||||
@ -109,7 +117,7 @@ public class DoubleStat extends ItemStat implements Upgradable, Previewable {
|
||||
|
||||
// Display in lore
|
||||
if (value != 0 || upgradeShift != 0) {
|
||||
String loreInsert = formatPath(MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter(), value * multiplyWhenDisplaying());
|
||||
String loreInsert = formatPath(MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter, value * multiplyWhenDisplaying());
|
||||
if (upgradeShift != 0)
|
||||
loreInsert += MythicLib.plugin.parseColors(UpgradeTemplate.getUpgradeChangeSuffix(plus(upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying())));
|
||||
item.getLore().insert(getPath(), loreInsert);
|
||||
|
@ -1,11 +0,0 @@
|
||||
package net.Indyuce.mmoitems.stat.type;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class EvilDoubleStat extends DoubleStat {
|
||||
|
||||
public EvilDoubleStat(String id, Material mat, String name, String[] lore) { super(id, mat, name, lore); }
|
||||
public EvilDoubleStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { super(id, mat, name, lore, types, materials); }
|
||||
|
||||
@Override public boolean moreIsBetter() { return false; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user