diff --git a/src/engine/db/handlers/dbEffectsBaseHandler.java b/src/engine/db/handlers/dbEffectsBaseHandler.java index f7cf2bac..b2452eb9 100644 --- a/src/engine/db/handlers/dbEffectsBaseHandler.java +++ b/src/engine/db/handlers/dbEffectsBaseHandler.java @@ -9,8 +9,11 @@ package engine.db.handlers; +import engine.Enum; import engine.gameManager.DbManager; +import engine.gameManager.PowersManager; import engine.powers.EffectsBase; +import engine.powers.effectmodifiers.*; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -18,6 +21,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashSet; public class dbEffectsBaseHandler extends dbHandlerBase { @@ -45,4 +49,254 @@ public class dbEffectsBaseHandler extends dbHandlerBase { return effectList; } + public static void cacheAllEffectModifiers() { + + String IDString; + AbstractEffectModifier abstractEffectModifier = null; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) { + + ResultSet rs = prepareStatement.executeQuery(); + + while (rs.next()) { + + IDString = rs.getString("IDString"); + EffectsBase effectBase = PowersManager.getEffectByIDString(IDString); + Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType")); + + //combine item prefix and suffix effect modifiers + + abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier); + + if (abstractEffectModifier != null) { + + if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false) + EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>()); + + EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier); + + } + + } + + } catch (Exception e) { + Logger.error(e); + } + + } + + private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException { + switch (modifier) { + case AdjustAboveDmgCap: + abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs); + break; + case Ambidexterity: + abstractEffectModifier = new AmbidexterityEffectModifier(rs); + break; + case AnimOverride: + break; + case ArmorPiercing: + abstractEffectModifier = new ArmorPiercingEffectModifier(rs); + break; + case AttackDelay: + abstractEffectModifier = new AttackDelayEffectModifier(rs); + break; + case Attr: + abstractEffectModifier = new AttributeEffectModifier(rs); + break; + case BlackMantle: + abstractEffectModifier = new BlackMantleEffectModifier(rs); + break; + case BladeTrails: + abstractEffectModifier = new BladeTrailsEffectModifier(rs); + break; + case Block: + abstractEffectModifier = new BlockEffectModifier(rs); + break; + case BlockedPowerType: + abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs); + break; + case CannotAttack: + abstractEffectModifier = new CannotAttackEffectModifier(rs); + break; + case CannotCast: + abstractEffectModifier = new CannotCastEffectModifier(rs); + break; + case CannotMove: + abstractEffectModifier = new CannotMoveEffectModifier(rs); + break; + case CannotTrack: + abstractEffectModifier = new CannotTrackEffectModifier(rs); + break; + case Charmed: + abstractEffectModifier = new CharmedEffectModifier(rs); + break; + case ConstrainedAmbidexterity: + abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs); + break; + case DamageCap: + abstractEffectModifier = new DamageCapEffectModifier(rs); + break; + case DamageShield: + abstractEffectModifier = new DamageShieldEffectModifier(rs); + break; + case DCV: + abstractEffectModifier = new DCVEffectModifier(rs); + break; + case Dodge: + abstractEffectModifier = new DodgeEffectModifier(rs); + break; + case DR: + abstractEffectModifier = new DREffectModifier(rs); + break; + case Durability: + abstractEffectModifier = new DurabilityEffectModifier(rs); + break; + case ExclusiveDamageCap: + abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs); + break; + case Fade: + abstractEffectModifier = new FadeEffectModifier(rs); + break; + case Fly: + abstractEffectModifier = new FlyEffectModifier(rs); + break; + case Health: + abstractEffectModifier = new HealthEffectModifier(rs); + break; + case HealthFull: + abstractEffectModifier = new HealthFullEffectModifier(rs); + break; + case HealthRecoverRate: + abstractEffectModifier = new HealthRecoverRateEffectModifier(rs); + break; + case IgnoreDamageCap: + abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs); + break; + case IgnorePassiveDefense: + abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs); + break; + case ImmuneTo: + abstractEffectModifier = new ImmuneToEffectModifier(rs); + break; + case ImmuneToAttack: + abstractEffectModifier = new ImmuneToAttackEffectModifier(rs); + break; + case ImmuneToPowers: + abstractEffectModifier = new ImmuneToPowersEffectModifier(rs); + break; + case Invisible: + abstractEffectModifier = new InvisibleEffectModifier(rs); + break; + case ItemName: + abstractEffectModifier = new ItemNameEffectModifier(rs); + if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty()) + break; + if (effectBase != null) + effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name)); + break; + case Mana: + abstractEffectModifier = new ManaEffectModifier(rs); + break; + case ManaFull: + abstractEffectModifier = new ManaFullEffectModifier(rs); + break; + case ManaRecoverRate: + abstractEffectModifier = new ManaRecoverRateEffectModifier(rs); + break; + case MaxDamage: + abstractEffectModifier = new MaxDamageEffectModifier(rs); + break; + case MeleeDamageModifier: + abstractEffectModifier = new MeleeDamageEffectModifier(rs); + break; + case MinDamage: + abstractEffectModifier = new MinDamageEffectModifier(rs); + break; + case NoMod: + abstractEffectModifier = new NoModEffectModifier(rs); + break; + case OCV: + abstractEffectModifier = new OCVEffectModifier(rs); + break; + case Parry: + abstractEffectModifier = new ParryEffectModifier(rs); + break; + case PassiveDefense: + abstractEffectModifier = new PassiveDefenseEffectModifier(rs); + case PowerCost: + abstractEffectModifier = new PowerCostEffectModifier(rs); + break; + case PowerCostHealth: + abstractEffectModifier = new PowerCostHealthEffectModifier(rs); + break; + case PowerDamageModifier: + abstractEffectModifier = new PowerDamageEffectModifier(rs); + break; + case ProtectionFrom: + abstractEffectModifier = new ProtectionFromEffectModifier(rs); + break; + case Resistance: + abstractEffectModifier = new ResistanceEffectModifier(rs); + break; + case ScaleHeight: + abstractEffectModifier = new ScaleHeightEffectModifier(rs); + break; + case ScaleWidth: + abstractEffectModifier = new ScaleWidthEffectModifier(rs); + break; + case ScanRange: + abstractEffectModifier = new ScanRangeEffectModifier(rs); + break; + case SeeInvisible: + abstractEffectModifier = new SeeInvisibleEffectModifier(rs); + break; + case Silenced: + abstractEffectModifier = new SilencedEffectModifier(rs); + break; + case Skill: + abstractEffectModifier = new SkillEffectModifier(rs); + break; + case Slay: + abstractEffectModifier = new SlayEffectModifier(rs); + break; + case Speed: + abstractEffectModifier = new SpeedEffectModifier(rs); + break; + case SpireBlock: + abstractEffectModifier = new SpireBlockEffectModifier(rs); + break; + case Stamina: + abstractEffectModifier = new StaminaEffectModifier(rs); + break; + case StaminaFull: + abstractEffectModifier = new StaminaFullEffectModifier(rs); + break; + case StaminaRecoverRate: + abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs); + break; + case Stunned: + abstractEffectModifier = new StunnedEffectModifier(rs); + break; + case Value: + abstractEffectModifier = new ValueEffectModifier(rs); + if (effectBase != null) { + ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier; + effectBase.setValue(valueEffect.minMod); + } + break; + case WeaponProc: + abstractEffectModifier = new WeaponProcEffectModifier(rs); + break; + case WeaponRange: + abstractEffectModifier = new WeaponRangeEffectModifier(rs); + break; + case WeaponSpeed: + abstractEffectModifier = new WeaponSpeedEffectModifier(rs); + break; + + } + return abstractEffectModifier; + } } diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 57af50ae..eeaf9c47 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -124,7 +124,7 @@ public enum PowersManager { EffectsBase.getFailConditions(PowersManager.effectsBaseByIDString); // Add Modifiers to Effects - AbstractEffectModifier.getAllEffectModifiers(); + dbEffectsBaseHandler.cacheAllEffectModifiers(); // Add Source Types to Effects PowersManager.addAllSourceTypes(); diff --git a/src/engine/powers/effectmodifiers/AbstractEffectModifier.java b/src/engine/powers/effectmodifiers/AbstractEffectModifier.java index 6a8f385d..464141d9 100644 --- a/src/engine/powers/effectmodifiers/AbstractEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AbstractEffectModifier.java @@ -11,17 +11,15 @@ package engine.powers.effectmodifiers; import engine.Enum.ModType; import engine.Enum.SourceType; -import engine.gameManager.DbManager; -import engine.gameManager.PowersManager; import engine.jobs.AbstractEffectJob; -import engine.objects.*; +import engine.objects.AbstractCharacter; +import engine.objects.AbstractWorldObject; +import engine.objects.Building; +import engine.objects.Item; import engine.powers.EffectsBase; -import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; public abstract class AbstractEffectModifier { @@ -30,7 +28,7 @@ public abstract class AbstractEffectModifier { protected int UUID; protected String IDString; protected String effectType; - protected float minMod; + public float minMod; protected float maxMod; protected float percentMod; protected float ramp; @@ -60,257 +58,6 @@ public abstract class AbstractEffectModifier { this.string2 = rs.getString("string2"); } - public static ArrayList getAllEffectModifiers() { - PreparedStatementShared ps = null; - ArrayList out = new ArrayList<>(); - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_effectmod"); - ResultSet rs = ps.executeQuery(); - String IDString; - AbstractEffectModifier aem = null; - while (rs.next()) { - IDString = rs.getString("IDString"); - int token = DbManager.hasher.SBStringHash(IDString); - - EffectsBase eb = PowersManager.getEffectByIDString(IDString); - - ModType modifier = ModType.GetModType(rs.getString("modType")); - - //combine item prefix and suffix effect modifiers - switch (modifier){ - case AdjustAboveDmgCap: - aem = new AdjustAboveDmgCapEffectModifier(rs); - break; - case Ambidexterity: - aem = new AmbidexterityEffectModifier(rs); - break; - case AnimOverride: - break; - case ArmorPiercing: - aem = new ArmorPiercingEffectModifier(rs); - break; - case AttackDelay: - aem = new AttackDelayEffectModifier(rs); - break; - case Attr: - aem = new AttributeEffectModifier(rs); - break; - case BlackMantle: - aem = new BlackMantleEffectModifier(rs); - break; - case BladeTrails: - aem = new BladeTrailsEffectModifier(rs); - break; - case Block: - aem = new BlockEffectModifier(rs); - break; - case BlockedPowerType: - aem = new BlockedPowerTypeEffectModifier(rs); - break; - case CannotAttack: - aem = new CannotAttackEffectModifier(rs); - break; - case CannotCast: - aem = new CannotCastEffectModifier(rs); - break; - case CannotMove: - aem = new CannotMoveEffectModifier(rs); - break; - case CannotTrack: - aem = new CannotTrackEffectModifier(rs); - break; - case Charmed: - aem = new CharmedEffectModifier(rs); - break; - case ConstrainedAmbidexterity: - aem = new ConstrainedAmbidexterityEffectModifier(rs); - break; - case DamageCap: - aem = new DamageCapEffectModifier(rs); - break; - case DamageShield: - aem = new DamageShieldEffectModifier(rs); - break; - case DCV: - aem = new DCVEffectModifier(rs); - break; - case Dodge: - aem = new DodgeEffectModifier(rs); - break; - case DR: - aem = new DREffectModifier(rs); - break; - case Durability: - aem = new DurabilityEffectModifier(rs); - break; - case ExclusiveDamageCap: - aem = new ExclusiveDamageCapEffectModifier(rs); - break; - case Fade: - aem = new FadeEffectModifier(rs); - break; - case Fly: - aem = new FlyEffectModifier(rs); - break; - case Health: - aem = new HealthEffectModifier(rs); - break; - case HealthFull: - aem = new HealthFullEffectModifier(rs); - break; - case HealthRecoverRate: - aem = new HealthRecoverRateEffectModifier(rs); - break; - case IgnoreDamageCap: - aem = new IgnoreDamageCapEffectModifier(rs); - break; - case IgnorePassiveDefense: - aem = new IgnorePassiveDefenseEffectModifier(rs); - break; - case ImmuneTo: - aem = new ImmuneToEffectModifier(rs); - break; - case ImmuneToAttack: - aem = new ImmuneToAttackEffectModifier(rs); - break; - case ImmuneToPowers: - aem = new ImmuneToPowersEffectModifier(rs); - break; - case Invisible: - aem = new InvisibleEffectModifier(rs); - break; - case ItemName: - aem = new ItemNameEffectModifier(rs); - if ((((ItemNameEffectModifier)aem).name.isEmpty())) - break; - if (eb != null) - eb.setName((((ItemNameEffectModifier)aem).name)); - break; - case Mana: - aem = new ManaEffectModifier(rs); - break; - case ManaFull: - aem = new ManaFullEffectModifier(rs); - break; - case ManaRecoverRate: - aem = new ManaRecoverRateEffectModifier(rs); - break; - case MaxDamage: - aem = new MaxDamageEffectModifier(rs); - break; - case MeleeDamageModifier: - aem = new MeleeDamageEffectModifier(rs); - break; - case MinDamage: - aem = new MinDamageEffectModifier(rs); - break; - case NoMod: - aem = new NoModEffectModifier(rs); - break; - case OCV: - aem = new OCVEffectModifier(rs); - break; - case Parry: - aem = new ParryEffectModifier(rs); - break; - case PassiveDefense: - aem = new PassiveDefenseEffectModifier(rs); - case PowerCost: - aem = new PowerCostEffectModifier(rs); - break; - case PowerCostHealth: - aem = new PowerCostHealthEffectModifier(rs); - break; - case PowerDamageModifier: - aem = new PowerDamageEffectModifier(rs); - break; - case ProtectionFrom: - aem = new ProtectionFromEffectModifier(rs); - break; - case Resistance: - aem = new ResistanceEffectModifier(rs); - break; - case ScaleHeight: - aem = new ScaleHeightEffectModifier(rs); - break; - case ScaleWidth: - aem = new ScaleWidthEffectModifier(rs); - break; - case ScanRange: - aem = new ScanRangeEffectModifier(rs); - break; - case SeeInvisible: - aem = new SeeInvisibleEffectModifier(rs); - break; - case Silenced: - aem = new SilencedEffectModifier(rs); - break; - case Skill: - aem = new SkillEffectModifier(rs); - break; - case Slay: - aem = new SlayEffectModifier(rs); - break; - case Speed: - aem = new SpeedEffectModifier(rs); - break; - case SpireBlock: - aem = new SpireBlockEffectModifier(rs); - break; - case Stamina: - aem = new StaminaEffectModifier(rs); - break; - case StaminaFull: - aem = new StaminaFullEffectModifier(rs); - break; - case StaminaRecoverRate: - aem = new StaminaRecoverRateEffectModifier(rs); - break; - case Stunned: - aem = new StunnedEffectModifier(rs); - break; - case Value: - aem = new ValueEffectModifier(rs); - if (eb != null){ - ValueEffectModifier valueEffect = (ValueEffectModifier)aem; - eb.setValue(valueEffect.minMod); - } - break; - case WeaponProc: - aem = new WeaponProcEffectModifier(rs); - break; - case WeaponRange: - aem = new WeaponRangeEffectModifier(rs); - break; - case WeaponSpeed: - aem = new WeaponSpeedEffectModifier(rs); - break; - - } - - if (aem != null){ - - - if (EffectsBase.modifiersMap.containsKey(eb.getIDString()) == false) - EffectsBase.modifiersMap.put(eb.getIDString(), new HashSet<>()); - EffectsBase.modifiersMap.get(eb.getIDString()).add(aem); - - } - } - rs.close(); - } catch (Exception e) { - Logger.error( e); - } finally { - ps.release(); - } - return out; - } - - - - - - public int getUUID() { return this.UUID; diff --git a/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java b/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java index 16b91db3..e7d6c9c1 100644 --- a/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java @@ -21,7 +21,7 @@ import java.sql.SQLException; public class ItemNameEffectModifier extends AbstractEffectModifier { - String name = ""; + public String name = ""; public ItemNameEffectModifier(ResultSet rs) throws SQLException { super(rs);