Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions src/main/java/studio/magemonkey/divinity/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import studio.magemonkey.divinity.stats.items.attributes.api.TypedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.BleedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DurabilityStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DynamicBuffStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.PenetrationStat;
import studio.magemonkey.divinity.stats.tiers.Tier;
import studio.magemonkey.divinity.types.ItemGroup;
import studio.magemonkey.divinity.types.ItemSubType;
Expand Down Expand Up @@ -69,6 +71,9 @@ public void setupAttributes() {
this.setupDamages();
this.setupDefense();
this.setupStats();
this.setupDamageBuffs();
this.setupDefenseBuffs();
this.setupPenetrations();
this.setupHand();
this.setupAmmo();
this.setupSockets();
Expand Down Expand Up @@ -210,6 +215,7 @@ private void setupStats() {
// servers carrying forward a pre-upgrade stats.yml that predates them, so upgrading
// servers get the new attributes working out of the box rather than silently disabled.
addMissingVanillaAttributeStatDefaults(cfg);
addMissingStatFoundationDefaults(cfg);

for (SimpleStat.Type statType : TypedStat.Type.values()) {
String path2 = statType.name() + ".";
Expand Down Expand Up @@ -277,6 +283,136 @@ private void addMissingStatDefault(
cfg.addMissing(path + ".capacity", capacity);
}

/**
* Seeds the stat-foundation entries (mana pool, CC, healing, and the reserved
* summon/projectile/bleed/stun placeholders) into general_stats.yml so servers upgrading
* with a pre-existing stats file still get them, the same way addMissingVanillaAttributeStatDefaults
* backfills the vanilla-attribute stats.
*/
private void addMissingStatFoundationDefaults(@NotNull JYML cfg) {
addMissingStatDefault(cfg, "MAX_MANA", "Max Mana", "&9▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "CC_RESISTANCE", "CC Resistance", "&e▸ %name%: &f%value% %condition%", 60.0);
addMissingStatDefault(cfg, "CC_DURATION", "CC Duration", "&e▸ %name%: &f%value% %condition%", -1.0);
addMissingStatDefault(cfg, "HEALING_CAST", "Healing Cast", "&a▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "HEALING_RECEIVED", "Healing Received", "&a▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "SKILL_EFFECTIVNESS", "Skill Effectivness",
"&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "SUMMON_POWER", "Summon power", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "SUMMON_HP", "Summon HP", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "SUMMON_DURATION", "Summon duration", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "PROJECTILE_COUNT", "Projectile Count", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "PROJECTILE_SPEED", "Projectile Speed", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "BLEED_STACKS", "Bleed Stacks", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "BLEED_DURATION", "Bleed Duration", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "BLEED_DAMAGEBUFF", "Bleed base", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "STUN_STACKS", "Stun Stacks", "&b▸ %name%: &f%value% %condition%", -1);
addMissingStatDefault(cfg, "STUN_DURATION", "Stun Duration", "&b▸ %name%: &f%value% %condition%", -1);
cfg.saveChanges();
}

private void setupDamageBuffs() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/damage_buffs_percent.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load damage_buffs_percent config: Configuration error");
e.printStackTrace();
return;
}

for (DamageAttribute dmg : ItemStats.getDamages()) {
String id = dmg.getId();
String path = id + ".";
cfg.addMissing(path + "enabled", true);
cfg.addMissing(path + "name", dmg.getName() + " Buff %");
cfg.addMissing(path + "format", "&3▸ %name%: &f%value%%condition%");
cfg.addMissing(path + "capacity", -1.0);
cfg.addMissing(path + "hook", Collections.singletonList(id));
}
cfg.saveChanges();

for (String buffId : cfg.getSection("")) {
if (!cfg.getBoolean(buffId + ".enabled")) continue;
String name = StringUT.color(cfg.getString(buffId + ".name", buffId));
String format = StringUT.color(cfg.getString(buffId + ".format", "&3▸ %name%: &f%value%"));
double cap = cfg.getDouble(buffId + ".capacity", -1D);
Set<String> hooks = new HashSet<>(cfg.getStringList(buffId + ".hook"));

DynamicBuffStat buff = new DynamicBuffStat(
DynamicBuffStat.BuffTarget.DAMAGE, buffId, name, format, hooks, cap);
ItemStats.registerDamageBuff(buff);
}
}

private void setupDefenseBuffs() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/defense_buffs_percent.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load defense_buffs_percent config: Configuration error");
e.printStackTrace();
return;
}

for (DefenseAttribute def : ItemStats.getDefenses()) {
String id = def.getId();
String path = id + ".";
cfg.addMissing(path + "enabled", true);
cfg.addMissing(path + "name", def.getName() + " Buff %");
cfg.addMissing(path + "format", "&9▸ %name%: &f%value%%condition%");
cfg.addMissing(path + "capacity", -1.0);
cfg.addMissing(path + "hook", Collections.singletonList(id));
}
cfg.saveChanges();

for (String buffId : cfg.getSection("")) {
if (!cfg.getBoolean(buffId + ".enabled")) continue;
String name = StringUT.color(cfg.getString(buffId + ".name", buffId));
String format = StringUT.color(cfg.getString(buffId + ".format", "&9▸ %name%: &f%value%"));
double cap = cfg.getDouble(buffId + ".capacity", -1D);
Set<String> hooks = new HashSet<>(cfg.getStringList(buffId + ".hook"));

DynamicBuffStat buff = new DynamicBuffStat(
DynamicBuffStat.BuffTarget.DEFENSE, buffId, name, format, hooks, cap);
ItemStats.registerDefenseBuff(buff);
}
}

private void setupPenetrations() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/penetration.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load penetration config: Configuration error");
e.printStackTrace();
return;
}

// Auto-generate a flat-pen entry for every registered damage type (if missing)
for (DamageAttribute dmg : ItemStats.getDamages()) {
String id = dmg.getId() + "_pen";
String path = id + ".";
cfg.addMissing(path + "enabled", true);
cfg.addMissing(path + "name", dmg.getName() + " Penetration");
cfg.addMissing(path + "format", "&c▸ %name%: &f%value%%condition%");
cfg.addMissing(path + "capacity", -1.0);
cfg.addMissing(path + "percent-pen", false);
cfg.addMissing(path + "hooks", Collections.singletonList(dmg.getId()));
}
cfg.saveChanges();

for (String penId : cfg.getSection("")) {
if (!cfg.getBoolean(penId + ".enabled")) continue;
String name = StringUT.color(cfg.getString(penId + ".name", penId));
String format = StringUT.color(cfg.getString(penId + ".format", "&c▸ %name%: &f%value%"));
double cap = cfg.getDouble(penId + ".capacity", -1D);
boolean percentPen = cfg.getBoolean(penId + ".percent-pen", false);
Set<String> hooks = new HashSet<>(cfg.getStringList(penId + ".hooks"));

new PenetrationStat(penId, name, format, hooks, percentPen, cap);
}
}

private void setupHand() {
JYML cfg;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import studio.magemonkey.divinity.stats.items.attributes.DefenseAttribute;
import studio.magemonkey.divinity.stats.items.attributes.api.SimpleStat;
import studio.magemonkey.divinity.stats.items.attributes.api.TypedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DynamicBuffStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.PenetrationStat;

public class PlaceholderAPIHK extends NHook<Divinity> {

Expand Down Expand Up @@ -71,15 +73,15 @@ public String onPlaceholderRequest(Player player, String tmp) {
SimpleStat.Type type = TypedStat.Type.valueOf(tt.toUpperCase());
return String.valueOf(NumberUT.round(EntityStats.get(player).getItemStat(type, true)));
} catch (IllegalArgumentException ex) {
return NULL;
return "0";
}
}

if (tmp.startsWith("damage_")) {
String tt = tmp.replace("damage_", "");
DamageAttribute dt = ItemStats.getDamageById(tt);
if (dt == null) {
return NULL;
return "0";
}
return String.valueOf(NumberUT.round(EntityStats.get(player).getDamageByType(dt)));
}
Expand All @@ -88,11 +90,32 @@ public String onPlaceholderRequest(Player player, String tmp) {
String tt = tmp.replace("defense_", "");
DefenseAttribute dt = ItemStats.getDefenseById(tt);
if (dt == null) {
return NULL;
return "0";
}
return String.valueOf(NumberUT.round(EntityStats.get(player).getDefenseByType(dt)));
}

if (tmp.startsWith("damagebuff_")) {
String tt = tmp.replace("damagebuff_", "");
DynamicBuffStat buff = ItemStats.getDamageBuff(tt);
if (buff == null) return "0";
return String.valueOf(NumberUT.round(EntityStats.get(player).getDynamicBuff(buff)));
}

if (tmp.startsWith("defensebuff_")) {
String tt = tmp.replace("defensebuff_", "");
DynamicBuffStat buff = ItemStats.getDefenseBuff(tt);
if (buff == null) return "0";
return String.valueOf(NumberUT.round(EntityStats.get(player).getDynamicBuff(buff)));
}

if (tmp.startsWith("penetration_")) {
String tt = tmp.replace("penetration_", "");
PenetrationStat pen = ItemStats.getPenetration(tt);
if (pen == null) return "0";
return String.valueOf(NumberUT.round(EntityStats.get(player).getPenetration(pen)));
}

if (tmp.startsWith("class_")) {
ClassManager classManager = plugin.getModuleCache().getClassManager();
if (classManager == null) return NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public Gem(@NotNull Divinity plugin, @NotNull JYML cfg) {
bMap.loadStats(cfg, path + "item-stats");
bMap.loadDamages(cfg, path + "damage-types");
bMap.loadDefenses(cfg, path + "defense-types");
bMap.loadDamageBuffs(cfg, path + "damage-buffs");
bMap.loadDefenseBuffs(cfg, path + "defense-buffs");
bMap.loadPenetrations(cfg, path + "penetrations");

this.bonusMap.put(lvl, bMap);

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/studio/magemonkey/divinity/stats/EntityStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import studio.magemonkey.divinity.stats.items.attributes.DefenseAttribute;
import studio.magemonkey.divinity.stats.items.attributes.api.SimpleStat;
import studio.magemonkey.divinity.stats.items.attributes.api.TypedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DynamicBuffStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.PenetrationStat;
import studio.magemonkey.divinity.utils.ItemUtils;

import java.util.*;
Expand Down Expand Up @@ -960,6 +962,36 @@ public double getItemStat(@NotNull SimpleStat.Type type, boolean safe, @Nullable
return value;
}

public double getPenetration(@NotNull PenetrationStat pen) {
List<ItemStack> equip = this.getEquipment();
List<BiFunction<Boolean, Double, Double>> bonuses = new ArrayList<>();
for (ItemStack item : equip) {
if (item == null || item.getType().isAir()) continue;
bonuses.addAll(pen.get(item, player));
}
bonuses.addAll(this.getBonuses(pen));
double value = BonusCalculator.SIMPLE_ADDITIVE.apply(0D, bonuses);
if (pen.getCapacity() >= 0 && value > pen.getCapacity()) {
value = pen.getCapacity();
}
return value;
}

public double getDynamicBuff(@NotNull DynamicBuffStat buff) {
List<ItemStack> equip = this.getEquipment();
List<BiFunction<Boolean, Double, Double>> bonuses = new ArrayList<>();
for (ItemStack item : equip) {
if (item == null || item.getType().isAir()) continue;
bonuses.addAll(buff.get(item, player));
}
bonuses.addAll(this.getBonuses(buff));
double value = BonusCalculator.SIMPLE_ADDITIVE.apply(0D, bonuses);
if (buff.getCapacity() >= 0 && value > buff.getCapacity()) {
value = buff.getCapacity();
}
return value;
}

@NotNull
private List<ItemStack> getEquipmentForStats(@Nullable ItemStack mainHandOverride) {
List<ItemStack> equip = this.getEquipment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ public class BonusCalculator {
return value * (1D + percent / 100D);
};

/**
* Sums the flat and percent channels directly instead of treating percent as a
* multiplier on the flat channel. Use this for stats whose "percent" bonuses are
* themselves the stat's value (e.g. a percent-based buff/penetration amount) rather
* than a modifier applied to some other base value — otherwise a percent-only bonus
* on a zero base would always evaluate to zero.
*/
public static final BiFunction<Double, List<BiFunction<Boolean, Double, Double>>, Double> SIMPLE_ADDITIVE =
(input, bonuses) -> {
double value = input;
double percent = 0D;

for (BiFunction<Boolean, Double, Double> bif : bonuses) {
value = bif.apply(false, value);
percent = bif.apply(true, percent);
}

return value + percent;
};

public static final BiFunction<Double, List<BiFunction<Boolean, Double, Double>>, Double> SIMPLE_BONUS =
(input, bonuses) -> {
double value = 0D;
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/studio/magemonkey/divinity/stats/bonus/BonusMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import studio.magemonkey.divinity.stats.items.attributes.*;
import studio.magemonkey.divinity.stats.items.attributes.api.SimpleStat;
import studio.magemonkey.divinity.stats.items.attributes.api.TypedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DynamicBuffStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.PenetrationStat;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -206,6 +208,57 @@ public void loadAmmo(@NotNull JYML cfg, @NotNull String path) {
}
}

public void loadDamageBuffs(@NotNull JYML cfg, @NotNull String path) {
for (String id : cfg.getSection(path)) {
DynamicBuffStat stat = ItemStats.getDamageBuff(id);
if (stat == null) continue;

String sVal = cfg.getString(path + "." + id);
if (sVal == null) continue;

String[] split = sVal.split("%", 2);
boolean perc = split.length == 2 && split[1].isEmpty();
double val = StringUT.getDouble(split[0], 0, true);

BiFunction<Boolean, Double, Double> func = (isBonus, apply) -> perc == isBonus ? apply + val : apply;
this.bonus.put(stat, func);
}
}

public void loadDefenseBuffs(@NotNull JYML cfg, @NotNull String path) {
for (String id : cfg.getSection(path)) {
DynamicBuffStat stat = ItemStats.getDefenseBuff(id);
if (stat == null) continue;

String sVal = cfg.getString(path + "." + id);
if (sVal == null) continue;

String[] split = sVal.split("%", 2);
boolean perc = split.length == 2 && split[1].isEmpty();
double val = StringUT.getDouble(split[0], 0, true);

BiFunction<Boolean, Double, Double> func = (isBonus, apply) -> perc == isBonus ? apply + val : apply;
this.bonus.put(stat, func);
}
}

public void loadPenetrations(@NotNull JYML cfg, @NotNull String path) {
for (String id : cfg.getSection(path)) {
PenetrationStat stat = ItemStats.getPenetration(id);
if (stat == null) continue;

String sVal = cfg.getString(path + "." + id);
if (sVal == null) continue;

String[] split = sVal.split("%", 2);
boolean perc = split.length == 2 && split[1].isEmpty();
double val = StringUT.getDouble(split[0], 0, true);

BiFunction<Boolean, Double, Double> func = (isBonus, apply) -> perc == isBonus ? apply + val : apply;
this.bonus.put(stat, func);
}
}

public void loadHands(@NotNull JYML cfg, @NotNull String path) {
for (String id : cfg.getSection(path)) {
HandAttribute stat;
Expand Down
Loading
Loading