From 585f984554c9b674f0b523e402f25747c602434c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 22 Aug 2024 15:52:28 -0400 Subject: [PATCH 01/16] Separate group for min/max --- src/engine/wpak/EffectsParser.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index 9c653c70..4244d921 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -236,10 +236,14 @@ public class EffectsParser { case Block: case Parry: case Dodge: + case WeaponRange: case ScanRange: + effectModifier.min = Float.parseFloat(modValues.get(1).trim()); + effectModifier.max = Float.parseFloat(modValues.get(2).trim()); + effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); + break; case ScaleHeight: case ScaleWidth: - case WeaponRange: effectModifier.min = Float.parseFloat(modValues.get(1).trim()); effectModifier.scale = Float.parseFloat(modValues.get(2).trim()); effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); From ecd72150038ffbd861c1d9b1db0ed83b1969bff0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 22 Aug 2024 16:01:42 -0400 Subject: [PATCH 02/16] Parsing cleanup work. --- src/engine/wpak/EffectsParser.java | 12 ++++-------- src/engine/wpak/data/EffectModifier.java | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index 4244d921..36b55f85 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -192,7 +192,7 @@ public class EffectsParser { case Stamina: effectModifier.min = Float.parseFloat(modValues.get(1).trim()); effectModifier.max = Float.parseFloat(modValues.get(2).trim()); - effectModifier.scale = Float.parseFloat(modValues.get(3).trim()); + effectModifier.value = Float.parseFloat(modValues.get(3).trim()); // Parameter 4 is always 0. effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(5).trim()); effectModifier.arg1 = modValues.get(6).trim(); @@ -211,7 +211,7 @@ public class EffectsParser { case Fade: case Durability: effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.scale = Float.parseFloat(modValues.get(2).trim()); + effectModifier.max = Float.parseFloat(modValues.get(2).trim()); effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); if (modValues.size() > 4) @@ -238,14 +238,10 @@ public class EffectsParser { case Dodge: case WeaponRange: case ScanRange: - effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.max = Float.parseFloat(modValues.get(2).trim()); - effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); - break; case ScaleHeight: case ScaleWidth: effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.scale = Float.parseFloat(modValues.get(2).trim()); + effectModifier.max = Float.parseFloat(modValues.get(2).trim()); effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); break; case ItemName: @@ -269,7 +265,7 @@ public class EffectsParser { case WeaponProc: effectModifier.min = Float.parseFloat(modValues.get(1).trim()); effectModifier.arg1 = modValues.get(2).trim(); - effectModifier.scale = Float.parseFloat(modValues.get(3).trim()); + effectModifier.max = Float.parseFloat(modValues.get(3).trim()); break; default: Logger.error("Unhandled type: " + effectModifier.type); diff --git a/src/engine/wpak/data/EffectModifier.java b/src/engine/wpak/data/EffectModifier.java index abb1b3ff..1262cd8f 100644 --- a/src/engine/wpak/data/EffectModifier.java +++ b/src/engine/wpak/data/EffectModifier.java @@ -14,7 +14,7 @@ public class EffectModifier { public mbEnums.ModType type; public float min; public float max; - public float scale; + public float value; public mbEnums.CompoundCurveType compoundCurveType; public String arg1; // ItemName "Masterwork" "" public String arg2; // ItemName "" "of the Defender" From f89ce2ee158a5e70e97e0add48d22ecd6d50e72a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 22 Aug 2024 16:06:56 -0400 Subject: [PATCH 03/16] Parsing cleanup work. --- src/engine/wpak/EffectsParser.java | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index 36b55f85..915f3cb6 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -165,24 +165,6 @@ public class EffectsParser { effectModifier.type = mbEnums.ModType.valueOf(modValues.get(0).trim()); switch (effectModifier.type) { - case BladeTrails: // No parm modifiers - case ImmuneToAttack: - case ImmuneToPowers: - case Ambidexterity: - case Silenced: - case IgnorePassiveDefense: - case Stunned: - case PowerCostHealth: - case Charmed: - case Fly: - case CannotMove: - case CannotTrack: - case CannotAttack: - case CannotCast: - case SpireBlock: - case Invisible: - case SeeInvisible: - break; case AnimOverride: effectModifier.min = Float.parseFloat(modValues.get(1).trim()); effectModifier.max = Float.parseFloat(modValues.get(2).trim()); @@ -267,6 +249,24 @@ public class EffectsParser { effectModifier.arg1 = modValues.get(2).trim(); effectModifier.max = Float.parseFloat(modValues.get(3).trim()); break; + case BladeTrails: // These tags have no parms or are not parsed + case ImmuneToAttack: + case ImmuneToPowers: + case Ambidexterity: + case Silenced: + case IgnorePassiveDefense: + case Stunned: + case PowerCostHealth: + case Charmed: + case Fly: + case CannotMove: + case CannotTrack: + case CannotAttack: + case CannotCast: + case SpireBlock: + case Invisible: + case SeeInvisible: + break; default: Logger.error("Unhandled type: " + effectModifier.type); break; From f4fc7fc75b7929664456af8e483b9cf030cf09a4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 22 Aug 2024 16:21:13 -0400 Subject: [PATCH 04/16] EffectDescription refactored out. --- src/engine/gameManager/PowersManager.java | 12 +- src/engine/powers/EffectsBase.java | 7 +- src/engine/wpak/EffectsParser.java | 38 ++--- src/engine/wpak/PowerActionParser.java | 136 +++++++++--------- src/engine/wpak/PowersParser.java | 10 +- .../data/{EffectEntry.java => Effect.java} | 11 +- src/engine/wpak/data/EffectDescription.java | 18 --- .../wpak/data/{PowerEntry.java => Power.java} | 6 +- ...PowerActionEntry.java => PowerAction.java} | 4 +- 9 files changed, 116 insertions(+), 126 deletions(-) rename src/engine/wpak/data/{EffectEntry.java => Effect.java} (83%) delete mode 100644 src/engine/wpak/data/EffectDescription.java rename src/engine/wpak/data/{PowerEntry.java => Power.java} (93%) rename src/engine/wpak/data/{PowerActionEntry.java => PowerAction.java} (95%) diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 6a24fae4..f0929ef1 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -34,7 +34,7 @@ import engine.server.MBServerStatics; import engine.wpak.EffectsParser; import engine.wpak.PowerActionParser; import engine.wpak.PowersParser; -import engine.wpak.data.EffectEntry; +import engine.wpak.data.Effect; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -120,7 +120,7 @@ public enum PowersManager { // Add EffectsBase ArrayList effectList = new ArrayList<>(); - for (EffectEntry entry : EffectsParser.effect_data.values()) { + for (Effect entry : EffectsParser.effect_data.values()) { EffectsBase effectBase = new EffectsBase(entry); effectList.add(effectBase); PowersManager.effectsBaseByToken.put(effectBase.getToken(), effectBase); @@ -981,7 +981,7 @@ public enum PowersManager { // if (!stackType.equals("IgnoreStack")) { if (target.getEffects().containsKey(stackType)) { // remove any existing power that overrides - Effect ef = target.getEffects().get(stackType); + engine.objects.Effect ef = target.getEffects().get(stackType); AbstractEffectJob effect = null; if (ef != null) { JobContainer jc = ef.getJobContainer(); @@ -1153,7 +1153,7 @@ public enum PowersManager { // if (!stackType.equals("IgnoreStack")) { if (target.getEffects().containsKey(stackType)) { // remove any existing power that overrides - Effect ef = target.getEffects().get(stackType); + engine.objects.Effect ef = target.getEffects().get(stackType); AbstractEffectJob effect = null; if (ef != null) { JobContainer jc = ef.getJobContainer(); @@ -1467,7 +1467,7 @@ public enum PowersManager { stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; if (target.getEffects().containsKey(stackType)) { // remove any existing power that overrides - Effect ef = target.getEffects().get(stackType); + engine.objects.Effect ef = target.getEffects().get(stackType); AbstractEffectJob effect = null; if (ef != null) { JobContainer jc = ef.getJobContainer(); @@ -1914,7 +1914,7 @@ public enum PowersManager { stackType = (stackType.equals("IgnoreStack")) ? Integer .toString(toRemove.getUUID()) : stackType; if (fromChant) { - Effect eff = awo.getEffects().get(stackType); + engine.objects.Effect eff = awo.getEffects().get(stackType); if (eff != null) eff.cancelJob(true); } else diff --git a/src/engine/powers/EffectsBase.java b/src/engine/powers/EffectsBase.java index ed1f3ce7..1939d8e0 100644 --- a/src/engine/powers/EffectsBase.java +++ b/src/engine/powers/EffectsBase.java @@ -26,12 +26,11 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.ApplyEffectMsg; import engine.objects.AbstractCharacter; import engine.objects.AbstractWorldObject; -import engine.objects.Effect; import engine.objects.PlayerCharacter; import engine.powers.effectmodifiers.AbstractEffectModifier; import engine.server.MBServerStatics; import engine.util.Hasher; -import engine.wpak.data.EffectEntry; +import engine.wpak.data.Effect; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -94,7 +93,7 @@ public class EffectsBase { } //EffectEntry constructor - public EffectsBase(EffectEntry entry) { + public EffectsBase(Effect entry) { this.IDString = entry.effect_id; this.name = entry.effect_name; this.token = Hasher.SBStringHash(entry.effect_name); @@ -433,7 +432,7 @@ public class EffectsBase { float duration = ab.getDurationInSeconds(trains); if (pb.getToken() == 1672601862) { - Effect eff = awo.getEffects().get("DeathShroud"); + engine.objects.Effect eff = awo.getEffects().get("DeathShroud"); if (eff != null) { diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index 915f3cb6..f887394b 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -11,7 +11,7 @@ package engine.wpak; import engine.gameManager.ConfigManager; import engine.mbEnums; import engine.wpak.data.ConditionEntry; -import engine.wpak.data.EffectEntry; +import engine.wpak.data.Effect; import engine.wpak.data.EffectModifier; import org.pmw.tinylog.Logger; @@ -25,7 +25,7 @@ import java.util.regex.Pattern; public class EffectsParser { public static String effectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg"; - public static HashMap effect_data = new HashMap<>(); + public static HashMap effect_data = new HashMap<>(); private static final Pattern EFFECT_REGEX = Pattern.compile("(?<=EFFECTBEGIN)(.+?)(?=EFFECTEND)", Pattern.DOTALL); private static final Pattern SOURCE_REGEX = Pattern.compile("(?<=SOURCEBEGIN)(.+?)(?=SOURCEEND)", Pattern.DOTALL); private static final Pattern MODS_REGEX = Pattern.compile("(?<=MODSBEGIN)(.+?)(?=MODSEND)", Pattern.DOTALL); @@ -51,21 +51,21 @@ public class EffectsParser { Matcher matcher = EFFECT_REGEX.matcher(fileContents); while (matcher.find()) { - EffectEntry effectEntry = parseEffectEntry(matcher.group()); - effect_data.put(effectEntry.effect_id, effectEntry); + Effect effect = parseEffectEntry(matcher.group()); + effect_data.put(effect.effect_id, effect); } } - private static EffectEntry parseEffectEntry(String effectData) { + private static Effect parseEffectEntry(String effectData) { - EffectEntry effectEntry = new EffectEntry(); + Effect effect = new Effect(); // Parse fields that lie outside the other tags - effectEntry.isItemEffect = effectData.contains("IsItemEffect"); - effectEntry.isSpireEffect = effectData.contains("IsSpireEffect"); - effectEntry.ignoreNoMod = effectData.contains("IgnoreNoMod"); - effectEntry.dontSave = effectData.contains("DontSave"); + effect.isItemEffect = effectData.contains("IsItemEffect"); + effect.isSpireEffect = effectData.contains("IsSpireEffect"); + effect.ignoreNoMod = effectData.contains("IgnoreNoMod"); + effect.dontSave = effectData.contains("DontSave"); // Remove all lines that contain a # and leading/trailing blank lines @@ -90,24 +90,24 @@ public class EffectsParser { while (matcher.find()) effectHeader.add(matcher.group().trim()); - effectEntry.effect_id = effectHeader.get(0); - effectEntry.effect_name = effectHeader.get(1); - effectEntry.effect_name = effectEntry.effect_name.replaceAll("\"", ""); + effect.effect_id = effectHeader.get(0); + effect.effect_name = effectHeader.get(1); + effect.effect_name = effect.effect_name.replaceAll("\"", ""); // Some effect mods have no icon // (SEEINVIS-SHADE "See Invis") if (effectHeader.size() == 3) - effectEntry.icon = Integer.parseInt(effectHeader.get(2)); + effect.icon = Integer.parseInt(effectHeader.get(2)); else - effectEntry.icon = 0; + effect.icon = 0; // Parse source entries matcher = SOURCE_REGEX.matcher(effectData); while (matcher.find()) - effectEntry.sources.add(matcher.group().trim()); + effect.sources.add(matcher.group().trim()); // Parse modifier entries @@ -117,7 +117,7 @@ public class EffectsParser { while (matcher.find()) { EffectModifier effectModifier = parseModEntry(matcher.group()); - effectEntry.mods.add(effectModifier); + effect.mods.add(effectModifier); } // Parse Conditions @@ -141,11 +141,11 @@ public class EffectsParser { while (iterator.hasNext()) conditionEntry.damageTypes.add(mbEnums.DamageType.valueOf(iterator.next().toUpperCase())); - effectEntry.conditions.add(conditionEntry); + effect.conditions.add(conditionEntry); } } - return effectEntry; + return effect; } private static EffectModifier parseModEntry(String modData) { diff --git a/src/engine/wpak/PowerActionParser.java b/src/engine/wpak/PowerActionParser.java index 6b669532..0815dd3b 100644 --- a/src/engine/wpak/PowerActionParser.java +++ b/src/engine/wpak/PowerActionParser.java @@ -10,8 +10,8 @@ package engine.wpak; import engine.gameManager.ConfigManager; import engine.mbEnums; -import engine.wpak.data.EffectDescription; -import engine.wpak.data.PowerActionEntry; +import engine.wpak.data.Effect; +import engine.wpak.data.PowerAction; import engine.wpak.data.StatTransfer; import engine.wpak.data.TrackEntry; import org.pmw.tinylog.Logger; @@ -51,15 +51,15 @@ public class PowerActionParser { while (matcher.find()) { - PowerActionEntry powerActionEntry = parsePowerActionEntry(matcher.group().trim()); + PowerAction powerAction = parsePowerActionEntry(matcher.group().trim()); } } - private static PowerActionEntry parsePowerActionEntry(String powerActionData) { + private static PowerAction parsePowerActionEntry(String powerActionData) { - PowerActionEntry powerActionEntry = new PowerActionEntry(); - EffectDescription effectDescription; + PowerAction powerAction = new PowerAction(); + Effect effect; StatTransfer statTransfer; TrackEntry trackEntry; @@ -81,34 +81,34 @@ public class PowerActionParser { headerData.add(matcher.group().trim()); Iterator headerIterator = headerData.iterator(); - powerActionEntry.action_id = headerIterator.next(); - powerActionEntry.action_type = headerIterator.next(); + powerAction.action_id = headerIterator.next(); + powerAction.action_type = headerIterator.next(); - switch (powerActionEntry.action_type) { + switch (powerAction.action_type) { case "RemoveEffect": - effectDescription = new EffectDescription(); - effectDescription.effect_id = headerIterator.next(); - powerActionEntry.effects.add(effectDescription); + effect = new Effect(); + effect.effect_id = headerIterator.next(); + powerAction.effects.add(effect); break; case "CreateMob": - powerActionEntry.petLevel = Integer.parseInt(headerIterator.next()); - powerActionEntry.petRace = Integer.parseInt(headerIterator.next()); + powerAction.petLevel = Integer.parseInt(headerIterator.next()); + powerAction.petRace = Integer.parseInt(headerIterator.next()); break; case "DamageOverTime": - effectDescription = new EffectDescription(); - effectDescription.effect_id = headerIterator.next(); - effectDescription.cycleDuration = Integer.parseInt(headerIterator.next()); - effectDescription.cycleDelay = Integer.parseInt(headerIterator.next()); - powerActionEntry.effects.add(effectDescription); + effect = new Effect(); + effect.effect_id = headerIterator.next(); + effect.cycleDuration = Integer.parseInt(headerIterator.next()); + effect.cycleDelay = Integer.parseInt(headerIterator.next()); + powerAction.effects.add(effect); break; case "ApplyEffects": int level = Integer.parseInt(headerIterator.next()); while (headerIterator.hasNext()) { - effectDescription = new EffectDescription(); - effectDescription.level = level; - effectDescription.effect_id = headerIterator.next(); - powerActionEntry.effects.add(effectDescription); + effect = new Effect(); + effect.level = level; + effect.effect_id = headerIterator.next(); + powerAction.effects.add(effect); } break; case "Transform": @@ -118,15 +118,15 @@ public class PowerActionParser { case "DirectDamage": case "SpireDisable": while (headerIterator.hasNext()) { - effectDescription = new EffectDescription(); - effectDescription.effect_id = headerIterator.next(); + effect = new Effect(); + effect.effect_id = headerIterator.next(); // Some applyEffect entries are naked withot a level if (headerData.size() > 3) - effectDescription.level = Integer.parseInt(headerIterator.next()); + effect.level = Integer.parseInt(headerIterator.next()); - powerActionEntry.effects.add(effectDescription); + powerAction.effects.add(effect); } break; case "TransferStat": @@ -139,7 +139,7 @@ public class PowerActionParser { statTransfer.toCurve = mbEnums.CompoundCurveType.valueOf(headerIterator.next()); statTransfer.fromStatBool = Boolean.parseBoolean(headerIterator.next()); statTransfer.toStatBool = Boolean.parseBoolean(headerIterator.next()); - powerActionEntry.statTransfer = statTransfer; + powerAction.statTransfer = statTransfer; break; case "TransferStatOT": statTransfer = new StatTransfer(); @@ -153,26 +153,26 @@ public class PowerActionParser { statTransfer.toStatBool = Boolean.parseBoolean(headerIterator.next()); statTransfer.transfer_action = headerIterator.next(); statTransfer.transfer_ticks = Integer.parseInt(headerIterator.next()); - powerActionEntry.statTransfer = statTransfer; + powerAction.statTransfer = statTransfer; break; case "Charm": - effectDescription = new EffectDescription(); - effectDescription.effect_id = headerIterator.next(); - effectDescription.level = Integer.parseInt(headerIterator.next()); - effectDescription.type = headerIterator.next(); - powerActionEntry.effects.add(effectDescription); + effect = new Effect(); + effect.effect_id = headerIterator.next(); + effect.level = Integer.parseInt(headerIterator.next()); + effect.type = headerIterator.next(); + powerAction.effects.add(effect); break; case "Block": - effectDescription = new EffectDescription(); - effectDescription.effect_id = headerIterator.next(); - effectDescription.level = Integer.parseInt(headerIterator.next()); - powerActionEntry.effects.add(effectDescription); + effect = new Effect(); + effect.effect_id = headerIterator.next(); + effect.level = Integer.parseInt(headerIterator.next()); + powerAction.effects.add(effect); break; case "Resurrect": - powerActionEntry.levelCap = Integer.parseInt(headerIterator.next()); + powerAction.levelCap = Integer.parseInt(headerIterator.next()); break; case "SetItemFlag": - powerActionEntry.itemFlag = mbEnums.ItemFlags.valueOf(headerIterator.next()); + powerAction.itemFlag = mbEnums.ItemFlags.valueOf(headerIterator.next()); break; case "Track": trackEntry = new TrackEntry(); @@ -182,7 +182,7 @@ public class PowerActionParser { trackEntry.type = headerIterator.next(); trackEntry.min = Integer.parseInt(headerIterator.next()); trackEntry.max = Integer.parseInt(headerIterator.next()); - powerActionEntry.trackEntry = trackEntry; + powerAction.trackEntry = trackEntry; break; case "Recall": // No arguments for these tags or not parsed case "Summon": @@ -198,7 +198,7 @@ public class PowerActionParser { case "Steal": break; default: - Logger.error("Unhandled type " + powerActionEntry.action_type + " for Pow4erAction: " + powerActionEntry.action_id); + Logger.error("Unhandled type " + powerAction.action_type + " for Pow4erAction: " + powerAction.action_id); break; } @@ -215,81 +215,81 @@ public class PowerActionParser { arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String bodyPart : arguments) - powerActionEntry.bodyparts.add(Integer.parseInt(bodyPart)); + powerAction.bodyparts.add(Integer.parseInt(bodyPart)); break; case "FEMALEBODYPARTS": arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String bodyPart : arguments) - powerActionEntry.femaleBodyParts.add(Integer.parseInt(bodyPart)); + powerAction.femaleBodyParts.add(Integer.parseInt(bodyPart)); break; case "SCALEFACTOR": arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String scaleFactor : arguments) - powerActionEntry.scaleFactor.add(Float.parseFloat(scaleFactor)); + powerAction.scaleFactor.add(Float.parseFloat(scaleFactor)); break; case "ISRESISTABLE": - powerActionEntry.isResistible = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.isResistible = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "ISAGGRESSIVE": - powerActionEntry.isAggressive = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.isAggressive = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "BLADETRAILS": - powerActionEntry.bladeTrails = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.bladeTrails = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "SHOULDSHOWWEAPONS": - powerActionEntry.shouldShowWeapons = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.shouldShowWeapons = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "SHOULDSHOWARMOR": - powerActionEntry.shouldShowArmor = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.shouldShowArmor = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "APPLYEFFECTBLANK": - powerActionEntry.applyEffectBlank = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.applyEffectBlank = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "WEAROFFEFFECTBLANK": - powerActionEntry.wearOffEffectBlank = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.wearOffEffectBlank = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "ATTACKANIMS": arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String animation : arguments) - powerActionEntry.attackAnimations.add(Integer.parseInt(animation)); + powerAction.attackAnimations.add(Integer.parseInt(animation)); break; case "REMOVEALL": - powerActionEntry.removeAll = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.removeAll = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "EFFECTID": - effectDescription = new EffectDescription(); - effectDescription.effect_id = lineValues.get(1).trim(); - powerActionEntry.effects.add(effectDescription); + effect = new Effect(); + effect.effect_id = lineValues.get(1).trim(); + powerAction.effects.add(effect); break; case "LEVELCAP": arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); - powerActionEntry.levelCap = Integer.parseInt(arguments.get(0)); + powerAction.levelCap = Integer.parseInt(arguments.get(0)); if (arguments.size() > 1) // Not all level caps have a curve - powerActionEntry.levelCurve = mbEnums.CompoundCurveType.valueOf(arguments.get(1)); + powerAction.levelCurve = mbEnums.CompoundCurveType.valueOf(arguments.get(1)); break; case "CLEARAGGRO": - powerActionEntry.clearAggro = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.clearAggro = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "TARGETBECOMESPET": - powerActionEntry.targetBecomesPet = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.targetBecomesPet = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "DESTROYOLDPET": - powerActionEntry.destroyOldPet = Boolean.parseBoolean(lineValues.get(1).trim()); + powerAction.destroyOldPet = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "DAMAGETYPE": - powerActionEntry.damageType = mbEnums.DamageType.valueOf(lineValues.get(1).trim().toUpperCase()); + powerAction.damageType = mbEnums.DamageType.valueOf(lineValues.get(1).trim().toUpperCase()); break; case "ROOTFSMID": - powerActionEntry.rootFsmID = mbEnums.MobBehaviourType.valueOf(lineValues.get(1).trim()); + powerAction.rootFsmID = mbEnums.MobBehaviourType.valueOf(lineValues.get(1).trim()); break; case "SPLASHDAMAGE": arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); - powerActionEntry.splashDamageMin = Integer.parseInt(arguments.get(0)); - powerActionEntry.splashDamageMax = Integer.parseInt(arguments.get(1)); + powerAction.splashDamageMin = Integer.parseInt(arguments.get(0)); + powerAction.splashDamageMax = Integer.parseInt(arguments.get(1)); break; case "APPLYEFFECTOTHER": case "APPLYEFFECTSELF": @@ -297,9 +297,9 @@ public class PowerActionParser { case "WEAROFFEFFECTSELF": break; default: - Logger.error("Unhandled variable type:" + key + " for powerAction: " + powerActionEntry.action_id); + Logger.error("Unhandled variable type:" + key + " for powerAction: " + powerAction.action_id); } } - return powerActionEntry; + return powerAction; } } diff --git a/src/engine/wpak/PowersParser.java b/src/engine/wpak/PowersParser.java index 15e6656b..e336d89b 100644 --- a/src/engine/wpak/PowersParser.java +++ b/src/engine/wpak/PowersParser.java @@ -49,14 +49,14 @@ public class PowersParser { while (matcher.find()) { - PowerEntry powerEntry = parsePowerEntry(matcher.group().trim()); + Power power = parsePowerEntry(matcher.group().trim()); } } - private static PowerEntry parsePowerEntry(String powerData) { + private static Power parsePowerEntry(String powerData) { - PowerEntry powerEntry = new PowerEntry(); + Power powerEntry = new Power(); StringBuilder conditionBuilder = new StringBuilder(); StringBuilder powerBuilder = new StringBuilder(); String conditionString; @@ -222,7 +222,7 @@ public class PowersParser { powerEntry.bladeTrails = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "EFFECTPREREQ": - EffectDescription effectPreReq = new EffectDescription(); + Effect effectPreReq = new Effect(); arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); effectPreReq.effect_id = arguments.get(9); effectPreReq.level = Integer.parseInt(arguments.get(1)); @@ -268,7 +268,7 @@ public class PowersParser { powerEntry.casterPulseParticle = Integer.parseInt(lineValues.get(1).trim()); break; case "TARGETEFFECTPREREQS_ORED": - EffectDescription preReq = new EffectDescription(); + Effect preReq = new Effect(); arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); preReq.effect_id = arguments.get(0); preReq.level = Integer.parseInt(arguments.get(1)); diff --git a/src/engine/wpak/data/EffectEntry.java b/src/engine/wpak/data/Effect.java similarity index 83% rename from src/engine/wpak/data/EffectEntry.java rename to src/engine/wpak/data/Effect.java index 9961faad..c24ac5c6 100644 --- a/src/engine/wpak/data/EffectEntry.java +++ b/src/engine/wpak/data/Effect.java @@ -11,7 +11,7 @@ package engine.wpak.data; import java.util.ArrayList; import java.util.HashSet; -public class EffectEntry { +public class Effect { public String effect_id; public String effect_name; public int icon; @@ -19,8 +19,17 @@ public class EffectEntry { public ArrayList mods = new ArrayList<>(); public ArrayList conditions = new ArrayList<>(); + // Additional variables outside of tags or parsed + // elsewhere from Effects.cfg + public boolean isItemEffect; public boolean isSpireEffect; public boolean ignoreNoMod; public boolean dontSave; + + public String type; + public int level; + public String message; + public int cycleDuration; + public int cycleDelay; } diff --git a/src/engine/wpak/data/EffectDescription.java b/src/engine/wpak/data/EffectDescription.java deleted file mode 100644 index c3c778f2..00000000 --- a/src/engine/wpak/data/EffectDescription.java +++ /dev/null @@ -1,18 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2024 -// www.magicbane.com - -package engine.wpak.data; - -public class EffectDescription { - public String effect_id; - public String type; - public int level; - public String message; - public int cycleDuration; - public int cycleDelay; -} diff --git a/src/engine/wpak/data/PowerEntry.java b/src/engine/wpak/data/Power.java similarity index 93% rename from src/engine/wpak/data/PowerEntry.java rename to src/engine/wpak/data/Power.java index 6a240726..01ea413c 100644 --- a/src/engine/wpak/data/PowerEntry.java +++ b/src/engine/wpak/data/Power.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; -public class PowerEntry { +public class Power { public String power_id; public String power; public ArrayList powers = new ArrayList<>(); @@ -49,7 +49,7 @@ public class PowerEntry { public String category; public boolean canCastWhileMoving = false; public boolean bladeTrails = false; - public ArrayList effectPreReqs = new ArrayList<>(); + public ArrayList effectPreReqs = new ArrayList<>(); public ArrayList equipmentPreReq = new ArrayList<>(); public EnumSet monsterRestricts = EnumSet.noneOf(mbEnums.MonsterType.class); public EnumSet monsterPrereqs = EnumSet.noneOf(mbEnums.MonsterType.class); @@ -61,7 +61,7 @@ public class PowerEntry { public int maxPlayerTargets; public boolean isAdminPower = false; public int casterPulseParticle; - public ArrayList targetEffectPrereqs = new ArrayList<>(); + public ArrayList targetEffectPrereqs = new ArrayList<>(); public boolean canCastWhileFlying = false; public boolean isProjectile = false; public HashMap conditions = new HashMap<>(); diff --git a/src/engine/wpak/data/PowerActionEntry.java b/src/engine/wpak/data/PowerAction.java similarity index 95% rename from src/engine/wpak/data/PowerActionEntry.java rename to src/engine/wpak/data/PowerAction.java index 0b2aeceb..d56a03f6 100644 --- a/src/engine/wpak/data/PowerActionEntry.java +++ b/src/engine/wpak/data/PowerAction.java @@ -12,13 +12,13 @@ import engine.mbEnums; import java.util.ArrayList; -public class PowerActionEntry { +public class PowerAction { // Header values public String action_id; public String action_type; - public ArrayList effects = new ArrayList<>(); + public ArrayList effects = new ArrayList<>(); public int petLevel; public int petRace; public StatTransfer statTransfer; From 3842cce1abb988ffb326fc91aceead8b14e396f7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 22 Aug 2024 16:34:05 -0400 Subject: [PATCH 05/16] Naming conventions set --- src/engine/wpak/EffectsParser.java | 58 +++++++++---------- src/engine/wpak/PowersParser.java | 4 +- src/engine/wpak/data/Effect.java | 2 +- ...EffectModifier.java => ModifierEntry.java} | 2 +- src/engine/wpak/data/Power.java | 2 +- .../data/{PowerData.java => PowerEntry.java} | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) rename src/engine/wpak/data/{EffectModifier.java => ModifierEntry.java} (97%) rename src/engine/wpak/data/{PowerData.java => PowerEntry.java} (97%) diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index f887394b..0d7999d7 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -12,7 +12,7 @@ import engine.gameManager.ConfigManager; import engine.mbEnums; import engine.wpak.data.ConditionEntry; import engine.wpak.data.Effect; -import engine.wpak.data.EffectModifier; +import engine.wpak.data.ModifierEntry; import org.pmw.tinylog.Logger; import java.io.IOException; @@ -116,8 +116,8 @@ public class EffectsParser { // Iterate effect entries from .wpak config data while (matcher.find()) { - EffectModifier effectModifier = parseModEntry(matcher.group()); - effect.mods.add(effectModifier); + ModifierEntry modifierEntry = parseModEntry(matcher.group()); + effect.mods.add(modifierEntry); } // Parse Conditions @@ -148,9 +148,9 @@ public class EffectsParser { return effect; } - private static EffectModifier parseModEntry(String modData) { + private static ModifierEntry parseModEntry(String modData) { - EffectModifier effectModifier = new EffectModifier(); + ModifierEntry modifierEntry = new ModifierEntry(); String[] modEntries = modData.trim().split("\n"); @@ -162,22 +162,22 @@ public class EffectsParser { while (matcher.find()) modValues.add(matcher.group().trim()); - effectModifier.type = mbEnums.ModType.valueOf(modValues.get(0).trim()); + modifierEntry.type = mbEnums.ModType.valueOf(modValues.get(0).trim()); - switch (effectModifier.type) { + switch (modifierEntry.type) { case AnimOverride: - effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.max = Float.parseFloat(modValues.get(2).trim()); + modifierEntry.min = Float.parseFloat(modValues.get(1).trim()); + modifierEntry.max = Float.parseFloat(modValues.get(2).trim()); break; case Health: case Mana: case Stamina: - effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.max = Float.parseFloat(modValues.get(2).trim()); - effectModifier.value = Float.parseFloat(modValues.get(3).trim()); + modifierEntry.min = Float.parseFloat(modValues.get(1).trim()); + modifierEntry.max = Float.parseFloat(modValues.get(2).trim()); + modifierEntry.value = Float.parseFloat(modValues.get(3).trim()); // Parameter 4 is always 0. - effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(5).trim()); - effectModifier.arg1 = modValues.get(6).trim(); + modifierEntry.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(5).trim()); + modifierEntry.arg1 = modValues.get(6).trim(); break; case Attr: case Resistance: @@ -192,12 +192,12 @@ public class EffectsParser { case Slay: case Fade: case Durability: - effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.max = Float.parseFloat(modValues.get(2).trim()); - effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); + modifierEntry.min = Float.parseFloat(modValues.get(1).trim()); + modifierEntry.max = Float.parseFloat(modValues.get(2).trim()); + modifierEntry.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); if (modValues.size() > 4) - effectModifier.arg1 = modValues.get(4).trim(); // Some HeathFull entries do not have an argument + modifierEntry.arg1 = modValues.get(4).trim(); // Some HeathFull entries do not have an argument break; case MeleeDamageModifier: case OCV: @@ -222,32 +222,32 @@ public class EffectsParser { case ScanRange: case ScaleHeight: case ScaleWidth: - effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.max = Float.parseFloat(modValues.get(2).trim()); - effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); + modifierEntry.min = Float.parseFloat(modValues.get(1).trim()); + modifierEntry.max = Float.parseFloat(modValues.get(2).trim()); + modifierEntry.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(3).trim()); break; case ItemName: case BlockedPowerType: case ImmuneTo: case BlackMantle: - effectModifier.arg1 = modValues.get(1).trim(); + modifierEntry.arg1 = modValues.get(1).trim(); // Some BlockedPowerType entries have only one argument if (modValues.size() > 2) - effectModifier.arg2 = modValues.get(2).trim(); + modifierEntry.arg2 = modValues.get(2).trim(); break; case NoMod: case ConstrainedAmbidexterity: case ProtectionFrom: case ExclusiveDamageCap: case IgnoreDamageCap: - effectModifier.arg1 = modValues.get(1).trim(); + modifierEntry.arg1 = modValues.get(1).trim(); break; case WeaponProc: - effectModifier.min = Float.parseFloat(modValues.get(1).trim()); - effectModifier.arg1 = modValues.get(2).trim(); - effectModifier.max = Float.parseFloat(modValues.get(3).trim()); + modifierEntry.min = Float.parseFloat(modValues.get(1).trim()); + modifierEntry.arg1 = modValues.get(2).trim(); + modifierEntry.max = Float.parseFloat(modValues.get(3).trim()); break; case BladeTrails: // These tags have no parms or are not parsed case ImmuneToAttack: @@ -268,12 +268,12 @@ public class EffectsParser { case SeeInvisible: break; default: - Logger.error("Unhandled type: " + effectModifier.type); + Logger.error("Unhandled type: " + modifierEntry.type); break; } } - return effectModifier; + return modifierEntry; } } diff --git a/src/engine/wpak/PowersParser.java b/src/engine/wpak/PowersParser.java index e336d89b..b722de3b 100644 --- a/src/engine/wpak/PowersParser.java +++ b/src/engine/wpak/PowersParser.java @@ -101,7 +101,7 @@ public class PowersParser { powerEntry.power_id = iterator.next(); powerEntry.power = iterator.next().replaceAll("\"", ""); - PowerData power = new PowerData(); + PowerEntry power = new PowerEntry(); power.power_type = mbEnums.PowerType.valueOf(iterator.next()); power.icon = Integer.parseInt(iterator.next()); power.powerBase = iterator.next().replaceAll("\"", ""); @@ -112,7 +112,7 @@ public class PowersParser { // Account for second definition if (nextValue.equals("SPELL") || nextValue.equals("SKILL")) { - power = new PowerData(); + power = new PowerEntry(); power.power_type = mbEnums.PowerType.valueOf(nextValue); power.icon = Integer.parseInt(iterator.next()); power.powerBase = iterator.next().replaceAll("\"", ""); diff --git a/src/engine/wpak/data/Effect.java b/src/engine/wpak/data/Effect.java index c24ac5c6..31c7af87 100644 --- a/src/engine/wpak/data/Effect.java +++ b/src/engine/wpak/data/Effect.java @@ -16,7 +16,7 @@ public class Effect { public String effect_name; public int icon; public HashSet sources = new HashSet<>(); - public ArrayList mods = new ArrayList<>(); + public ArrayList mods = new ArrayList<>(); public ArrayList conditions = new ArrayList<>(); // Additional variables outside of tags or parsed diff --git a/src/engine/wpak/data/EffectModifier.java b/src/engine/wpak/data/ModifierEntry.java similarity index 97% rename from src/engine/wpak/data/EffectModifier.java rename to src/engine/wpak/data/ModifierEntry.java index 1262cd8f..d67d8a00 100644 --- a/src/engine/wpak/data/EffectModifier.java +++ b/src/engine/wpak/data/ModifierEntry.java @@ -10,7 +10,7 @@ package engine.wpak.data; import engine.mbEnums; -public class EffectModifier { +public class ModifierEntry { public mbEnums.ModType type; public float min; public float max; diff --git a/src/engine/wpak/data/Power.java b/src/engine/wpak/data/Power.java index 01ea413c..90efcac5 100644 --- a/src/engine/wpak/data/Power.java +++ b/src/engine/wpak/data/Power.java @@ -17,7 +17,7 @@ import java.util.HashMap; public class Power { public String power_id; public String power; - public ArrayList powers = new ArrayList<>(); + public ArrayList powers = new ArrayList<>(); public mbEnums.PowerTargetType target_type; public int range; public mbEnums.AreaType areaType; diff --git a/src/engine/wpak/data/PowerData.java b/src/engine/wpak/data/PowerEntry.java similarity index 97% rename from src/engine/wpak/data/PowerData.java rename to src/engine/wpak/data/PowerEntry.java index af98c498..fb805faa 100644 --- a/src/engine/wpak/data/PowerData.java +++ b/src/engine/wpak/data/PowerEntry.java @@ -10,7 +10,7 @@ package engine.wpak.data; import engine.mbEnums; -public class PowerData { +public class PowerEntry { public mbEnums.PowerType power_type; public int icon; public String powerBase; From e082a0b49cf28edc8e4d54739e0def569d381626 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 15:18:40 -0400 Subject: [PATCH 06/16] Bane logic tweaking --- src/engine/objects/Building.java | 2 +- src/engine/workthreads/DestroyCityThread.java | 144 ++++++++---------- 2 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 5367c8f7..0a356546 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -561,7 +561,7 @@ public class Building extends AbstractWorldObject { BuildingManager.setRank(barracksBuilding, -1); } - // If the tree is R8 and deranking, we need to update it's + // If the tree is R8 and deranking, we need to update the // mesh along with buildings losing their health bonus if (this.rank == 8) { diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 9c5b2050..ae4ac2d8 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -53,120 +53,110 @@ public class DestroyCityThread implements Runnable { // Member variable assignment - cityZone = city.getParent(); - newParent = cityZone.parent; - formerGuild = city.getTOL().getGuild(); + try { + cityZone = city.getParent(); + newParent = cityZone.parent; + formerGuild = city.getTOL().getGuild(); - // Former guild loses it's tree! + // Former guild loses tree! - if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { + if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { - //Successful Update of guild + //Successful Update of guild - formerGuild.setGuildState(mbEnums.GuildState.Errant); - formerGuild.setNation(null); - formerGuild.setCityUUID(0); - GuildManager.updateAllGuildTags(formerGuild); - GuildManager.updateAllGuildBinds(formerGuild, null); - } + formerGuild.setGuildState(mbEnums.GuildState.Errant); + formerGuild.setNation(null); + formerGuild.setCityUUID(0); + GuildManager.updateAllGuildTags(formerGuild); + GuildManager.updateAllGuildBinds(formerGuild, null); + } - // By losing the tree, the former owners lose all of their subguilds. + // By losing the tree, the former owners lose all of their subguilds. - if (!formerGuild.getSubGuildList().isEmpty()) { + if (!formerGuild.getSubGuildList().isEmpty()) { - subGuildList = new ArrayList<>(); + subGuildList = new ArrayList<>(); - subGuildList.addAll(formerGuild.getSubGuildList()); + subGuildList.addAll(formerGuild.getSubGuildList()); - for (Guild subGuild : subGuildList) { - formerGuild.removeSubGuild(subGuild); + for (Guild subGuild : subGuildList) { + formerGuild.removeSubGuild(subGuild); + } } - } - Building tol = null; + // Build list of buildings within this parent zone - // Build list of buildings within this parent zone + for (Building cityBuilding : cityZone.zoneBuildingSet) { - for (Building cityBuilding : cityZone.zoneBuildingSet) { + // Sanity Check in case player deletes the building + // before this thread can get to it - // Sanity Check in case player deletes the building - // before this thread can get to it + if (cityBuilding == null) + continue; - if (cityBuilding == null) - continue; + // Do nothing with the banestone. It will be removed elsewhere - // Do nothing with the banestone. It will be removed elsewhere + if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) + continue; - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) - continue; + // All buildings are moved to a location relative + // to their new parent zone - // TOL is processed after all other structures in the city zone + localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.TOL)) { - tol = cityBuilding; - continue; - } - - // All buildings are moved to a location relative - // to their new parent zone + DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); + // All buildings are re-parented to a zone one node + // higher in the tree (continent) as we will be + // deleting the city zone very shortly. - DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) + cityBuilding.setParentZone(newParent); - // All buildings are re-parented to a zone one node - // higher in the tree (continent) as we will be - // deleting the city zone very shortly. + // No longer a tree, no longer any protection contract! - if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) - cityBuilding.setParentZone(newParent); + cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE); - // No longer a tree, no longer any protection contract! + // Remove warehouse entry if one exists. - cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE); + if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) { + DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); + city.warehouse = null; + } - // Remove warehouse entry if one exists. + if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) + || (cityBuilding.getBlueprint().isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { - if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) { - DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); - city.warehouse = null; + if (cityBuilding.getRank() != -1) + BuildingManager.setRank(cityBuilding, -1); + } } - // Destroy all remaining city assets - - if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { - - if (cityBuilding.getRank() != -1) - BuildingManager.setRank(cityBuilding, -1); + if (city.realm != null) { + city.realm.removeCity(city.getObjectUUID()); + city.realm = null; } - } - - // Destroy the tol - if (tol != null) - BuildingManager.setRank(tol, -1); + // It's now safe to delete the city zone from the database + // which will cause a cascade delete of everything else - if (city.realm != null) - city.realm.removeCity(city.getObjectUUID()); + if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { + Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); + return; + } - // It's now safe to delete the city zone from the database - // which will cause a cascade delete of everything else + // Refresh the city for map requests + City.lastCityUpdate = System.currentTimeMillis(); - if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { - Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); - return; + } catch (Exception e) { + Logger.error(e); } - // Refresh the city for map requests - - City.lastCityUpdate = System.currentTimeMillis(); - // Zone and city should vanish upon next reboot // if the codebase reaches here. From eff44c334d66366ae5d2f30cd2ab2612c707f54e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 15:26:14 -0400 Subject: [PATCH 07/16] Error trapping and output --- src/engine/workthreads/DestroyCityThread.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index ae4ac2d8..40c22605 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -58,6 +58,8 @@ public class DestroyCityThread implements Runnable { newParent = cityZone.parent; formerGuild = city.getTOL().getGuild(); + Logger.info("Destroy city thread started for: " + newParent.zoneName); + // Former guild loses tree! if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { From d304d0706c19d281d1e6bf2b7f20e8ade3c3b10c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 15:28:12 -0400 Subject: [PATCH 08/16] Owner set to null --- src/engine/workthreads/DestroyCityThread.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 40c22605..04b38e18 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -143,6 +143,8 @@ public class DestroyCityThread implements Runnable { city.realm = null; } + city.getTOL().setOwner(null); + // It's now safe to delete the city zone from the database // which will cause a cascade delete of everything else From 93befc088787127a59e89759959dc60407a9facd Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:13:22 -0400 Subject: [PATCH 09/16] Update to console output --- src/engine/objects/City.java | 4 ++-- src/engine/workthreads/DestroyCityThread.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 8f674de8..375bd854 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -1104,7 +1104,7 @@ public class City extends AbstractWorldObject { Thread destroyCityThread = new Thread(new DestroyCityThread(this)); - destroyCityThread.setName("destroyCity:" + this.getName()); + destroyCityThread.setName("destroyCity:" + this.getParent().zoneName); destroyCityThread.start(); } @@ -1112,7 +1112,7 @@ public class City extends AbstractWorldObject { Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); - transferCityThread.setName("TransferCity:" + this.getName()); + transferCityThread.setName("TransferCity:" + this.getParent().zoneName)); transferCityThread.start(); } diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 04b38e18..64ef509f 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -58,7 +58,7 @@ public class DestroyCityThread implements Runnable { newParent = cityZone.parent; formerGuild = city.getTOL().getGuild(); - Logger.info("Destroy city thread started for: " + newParent.zoneName); + Logger.info("Destroy city thread started for: " + cityZone.zoneName); // Former guild loses tree! @@ -164,6 +164,6 @@ public class DestroyCityThread implements Runnable { // Zone and city should vanish upon next reboot // if the codebase reaches here. - Logger.info(city.getParent().zoneName + " uuid:" + city.getObjectUUID() + "has been destroyed!"); + Logger.info(city.getParent().zoneName + " uuid: " + city.getObjectUUID() + " has been destroyed!"); } } From aaff28d720bc66961f92ad6a33da6116b55c6148 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:13:37 -0400 Subject: [PATCH 10/16] Update to console output --- src/engine/objects/City.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 375bd854..a4591532 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -1112,7 +1112,7 @@ public class City extends AbstractWorldObject { Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); - transferCityThread.setName("TransferCity:" + this.getParent().zoneName)); + transferCityThread.setName("TransferCity:" + this.getParent().zoneName); transferCityThread.start(); } From 4da089e9b880e728a94c8a299aa94594e067a0e0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:20:27 -0400 Subject: [PATCH 11/16] Update to thread logic --- src/engine/workthreads/DestroyCityThread.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 64ef509f..77453c71 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -88,6 +88,8 @@ public class DestroyCityThread implements Runnable { // Build list of buildings within this parent zone + ArrayList destroySet = new ArrayList<>(); + for (Building cityBuilding : cityZone.zoneBuildingSet) { // Sanity Check in case player deletes the building @@ -126,29 +128,27 @@ public class DestroyCityThread implements Runnable { city.warehouse = null; } - if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { + // Mark all auto protected buildings for destruction - if (cityBuilding.getRank() != -1) - BuildingManager.setRank(cityBuilding, -1); - } + if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) || (cityBuilding.getBlueprint().isWallPiece()) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) + destroySet.add(cityBuilding); } + // Destroy set of auto-protected buildings + + for (Building building : destroySet) + if (building.getRank() != -1) + BuildingManager.setRank(building, -1); + if (city.realm != null) { city.realm.removeCity(city.getObjectUUID()); city.realm = null; } - city.getTOL().setOwner(null); - // It's now safe to delete the city zone from the database // which will cause a cascade delete of everything else - if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { + if (!DbManager.ZoneQueries.DELETE_ZONE(cityZone)) { Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); return; } From 983dd46870fbeaed320af717d6654442f43d9f17 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:23:28 -0400 Subject: [PATCH 12/16] Update to thread logic --- src/engine/gameManager/BuildingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 8907339a..6292c457 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -798,7 +798,7 @@ public enum BuildingManager { // Attempt to write to database or delete the building // if we are destroying it. - if (rank == -1) + if (rank < 0) success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); else success = DbManager.BuildingQueries.updateBuildingRank(building, rank); From 62235497ad948265675cdca66fb4d9db126112fb Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:53:51 -0400 Subject: [PATCH 13/16] Returns all not just active mines --- src/engine/objects/Mine.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index dabfb557..553c1036 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -220,8 +220,7 @@ public class Mine extends AbstractGameObject { // Only inactive mines are returned. for (Mine mine : Mine.mineMap.keySet()) { - if (mine.owningGuild.getObjectUUID() == guildID && - mine.isActive == false) + if (mine.owningGuild.getObjectUUID() == guildID) mineList.add(mine); } return mineList; From 20c032fa4dd49149b424d8956eccf28551ca1d4e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 17:03:48 -0400 Subject: [PATCH 14/16] Hash value updated. --- src/engine/mbEnums.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/mbEnums.java b/src/engine/mbEnums.java index c75d7a05..1ef6443e 100644 --- a/src/engine/mbEnums.java +++ b/src/engine/mbEnums.java @@ -2732,7 +2732,7 @@ public class mbEnums { DIAMOND(1580010, 1540225085, -1730704107, 2000, 20), GALVOR(1580017, -1683992404, -1596311545, 2000, 5), IRON(1580002, -1673518119, 2504297, 2000, 20), - LUMBER(1580004, 1628412684, -1603256692, 10000, 100), + LUMBER(1580004, -1628412684, -1603256692, 10000, 100), MANDRAKE(1580007, 1519910613, 1191391799, 1000, 10), MITHRIL(1580021, 626743397, -1761257186, 500, 5), OAK(1580005, -1653034775, 74767, 3000, 30), From 668b61b734fdf176cf55515a0f9755a987eaaeaa Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 17:11:01 -0400 Subject: [PATCH 15/16] city.isDestroyed --- src/engine/objects/City.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index a4591532..52f09882 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -41,6 +41,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; public class City extends AbstractWorldObject { @@ -80,6 +81,7 @@ public class City extends AbstractWorldObject { private String hash; public Warehouse warehouse; public Realm realm; + public AtomicBoolean isDestroyed = new AtomicBoolean(false); /** * ResultSet Constructor @@ -1102,10 +1104,14 @@ public class City extends AbstractWorldObject { public final void destroy() { - Thread destroyCityThread = new Thread(new DestroyCityThread(this)); + if (this.isDestroyed.compareAndSet(false, true)) { - destroyCityThread.setName("destroyCity:" + this.getParent().zoneName); - destroyCityThread.start(); + Thread destroyCityThread = new Thread(new DestroyCityThread(this)); + + destroyCityThread.setName("destroyCity:" + this.getParent().zoneName); + destroyCityThread.start(); + } else + Logger.error("Attempt to destroy destroyed city"); } public final void transfer(AbstractCharacter newOwner) { From dfa646d8280786acfbe047e95c526bda408bfc0e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 17:31:28 -0400 Subject: [PATCH 16/16] Update to player city filter --- src/engine/objects/City.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 52f09882..a9fae4b6 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -308,6 +308,21 @@ public class City extends AbstractWorldObject { if (city.parentZone == null) continue; + // Can't teleport to something without a tree + + if (city.getTOL() == null) + continue; + + // No abandoned cities + + if (city.getTOL().getGuild().isEmptyGuild()) + continue; + + // No destroyed cities + + if (city.getTOL().getRank() == -1) + continue; + //can't repledge to a guild you're already part of if (repledge && city.getGuild().equals(playerCharacter.guild))