From 69e2630d77e5d0726dda083d9eba5425ad617691 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 25 Jan 2025 14:15:27 -0600 Subject: [PATCH] PlayerCombatStats dex penalty applied correctly --- src/engine/db/handlers/dbItemBaseHandler.java | 15 +++++++ src/engine/objects/ItemBase.java | 8 +++- src/engine/objects/PlayerCombatStats.java | 41 +++++++++++++++---- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/engine/db/handlers/dbItemBaseHandler.java b/src/engine/db/handlers/dbItemBaseHandler.java index bf12b434..6e953375 100644 --- a/src/engine/db/handlers/dbItemBaseHandler.java +++ b/src/engine/db/handlers/dbItemBaseHandler.java @@ -45,6 +45,21 @@ public class dbItemBaseHandler extends dbHandlerBase { } } + public void LOAD_DEX_REDUCTION(ItemBase itemBase) { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_dexpenalty` WHERE `ID` = ?")) { + + preparedStatement.setInt(1, itemBase.getUUID()); + ResultSet rs = preparedStatement.executeQuery(); + + itemBase.dexReduction = rs.getFloat("item_bulk_factor"); + + } catch (SQLException e) { + Logger.error(e); + } + } + public void LOAD_ANIMATIONS(ItemBase itemBase) { ArrayList tempList = new ArrayList<>(); diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index 7baa4d34..b6bda4bb 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -76,6 +76,8 @@ public class ItemBase { private ArrayList animations = new ArrayList<>(); private ArrayList offHandAnimations = new ArrayList<>(); + public float dexReduction = 0.0f; + /** * ResultSet Constructor */ @@ -151,7 +153,7 @@ public class ItemBase { } initBakedInStats(); initializeHashes(); - + initDexReduction(); } public static void addToCache(ItemBase itemBase) { @@ -319,6 +321,10 @@ public class ItemBase { DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this); } + private void initDexReduction(){ + DbManager.ItemBaseQueries.LOAD_DEX_REDUCTION(this); + } + //TODO fix this later. Shouldn't be gotten from item base public int getMagicValue() { return this.value; diff --git a/src/engine/objects/PlayerCombatStats.java b/src/engine/objects/PlayerCombatStats.java index c9ead995..a8942d5c 100644 --- a/src/engine/objects/PlayerCombatStats.java +++ b/src/engine/objects/PlayerCombatStats.java @@ -110,7 +110,7 @@ public class PlayerCombatStats { String skill = "Unarmed Combat"; String mastery = "Unarmed Combat Mastery"; - int primaryStat = this.owner.statDexCurrent; + int primaryStat = getDexAfterPenalty(this.owner); if(weapon != null) { skill= weapon.getItemBase().getSkillRequired(); mastery = weapon.getItemBase().getMastery(); @@ -185,8 +185,7 @@ public class PlayerCombatStats { atr += 1; atr = (float) Math.ceil(atr); }else { - float dexterity = this.owner.statDexBase; - dexterity += this.owner.bonuses.getFloat(Enum.ModType.Attr, Enum.SourceType.Dexterity); + float dexterity = getDexAfterPenalty(this.owner); atr = dexterity / 2; atr += skillLevel * 4; atr += masteryLevel * 3; @@ -215,7 +214,7 @@ public class PlayerCombatStats { public void calculateMin(boolean mainHand) { Item weapon; float baseDMG = 1; - int primaryStat = this.owner.statDexCurrent; + int primaryStat = getDexAfterPenalty(this.owner); int secondaryStat = this.owner.statStrCurrent; double weaponSkill = 5; double weaponMastery = 5; @@ -235,7 +234,7 @@ public class PlayerCombatStats { mastery = weapon.getItemBase().getMastery(); if (weapon.getItemBase().isStrBased()) { primaryStat = this.owner.statStrCurrent; - secondaryStat = this.owner.statDexCurrent; + secondaryStat = getDexAfterPenalty(this.owner); } for(Effect eff : weapon.effects.values()){ for(AbstractEffectModifier mod : eff.getEffectModifiers()){ @@ -292,7 +291,7 @@ public class PlayerCombatStats { // + 0.0022*Secondary Stat + 0.028*(Secondary Stat-0.75)^0.5 + 0.0075*(Weapon Skill + Weapon Mastery)) Item weapon; double baseDMG = 5; - int primaryStat = this.owner.statDexCurrent; + int primaryStat = getDexAfterPenalty(this.owner); int secondaryStat = this.owner.statStrCurrent; double weaponSkill = 5; double weaponMastery = 5; @@ -311,7 +310,7 @@ public class PlayerCombatStats { mastery = weapon.getItemBase().getMastery(); if (weapon.getItemBase().isStrBased()) { primaryStat = this.owner.statStrCurrent; - secondaryStat = this.owner.statDexCurrent; + secondaryStat = getDexAfterPenalty(this.owner); } for(Effect eff : weapon.effects.values()){ for(AbstractEffectModifier mod : eff.getEffectModifiers()){ @@ -541,7 +540,7 @@ public class PlayerCombatStats { if(this.owner.skills.containsKey(masteryName)) masterySkill = this.owner.skills.get(masteryName).getModifiedAmount(); - float dexterity = this.owner.statDexCurrent;//this.owner.statDexBase; + float dexterity = getDexAfterPenalty(this.owner); //dexterity += this.owner.bonuses.getFloat(Enum.ModType.Attr, Enum.SourceType.Dexterity); float luckyRune = 1.0f; @@ -616,7 +615,7 @@ public class PlayerCombatStats { if (skillBase.getStrMod() > 0) statMod += (float) skillBase.getStrMod() * (float) pc.getStatStrCurrent() / 100f; if (skillBase.getDexMod() > 0) - statMod += (float) skillBase.getDexMod() * (float) pc.getStatDexCurrent() / 100f; + statMod += (float) skillBase.getDexMod() * (float) getDexAfterPenalty(pc) / 100f; if (skillBase.getConMod() > 0) statMod += (float) skillBase.getConMod() * (float) pc.getStatConCurrent() / 100f; if (skillBase.getIntMod() > 0) @@ -668,4 +667,28 @@ public class PlayerCombatStats { return modifiedAmount; } + + public static int getDexAfterPenalty(PlayerCharacter pc){ + if(pc.charItemManager == null) + return pc.statDexCurrent; + + float dex = pc.statDexBase; + if(pc.bonuses != null) + dex += pc.bonuses.getFloat(Enum.ModType.Attr, Enum.SourceType.Dexterity); + + float penaltyFactor = 0.0f; + for(Item equipped : pc.charItemManager.getEquipped().values()){ + ItemBase ib = equipped.getItemBase(); + if(ib.isHeavyArmor() || ib.isLightArmor() || ib.isMediumArmor()){ + penaltyFactor += (ib.dexReduction); + } + } + + if(penaltyFactor > 0) + penaltyFactor *= 0.01f; + + float totalPenalty = dex * (1 + penaltyFactor); + + return Math.round(dex - totalPenalty); + } }