Compare commits

..

11 Commits

Author SHA1 Message Date
MagicBot dfa646d828 Update to player city filter 2024-08-25 17:31:28 -04:00
MagicBot 668b61b734 city.isDestroyed 2024-08-25 17:11:01 -04:00
MagicBot 20c032fa4d Hash value updated. 2024-08-25 17:03:48 -04:00
MagicBot 62235497ad Returns all not just active mines 2024-08-25 16:53:51 -04:00
MagicBot 983dd46870 Update to thread logic 2024-08-25 16:23:28 -04:00
MagicBot 4da089e9b8 Update to thread logic 2024-08-25 16:20:27 -04:00
MagicBot aaff28d720 Update to console output 2024-08-25 16:13:37 -04:00
MagicBot 93befc0887 Update to console output 2024-08-25 16:13:22 -04:00
MagicBot d304d0706c Owner set to null 2024-08-25 15:28:12 -04:00
MagicBot eff44c334d Error trapping and output 2024-08-25 15:26:14 -04:00
MagicBot e082a0b49c Bane logic tweaking 2024-08-25 15:18:40 -04:00
19 changed files with 121 additions and 1012 deletions
+1 -1
View File
@@ -798,7 +798,7 @@ public enum BuildingManager {
// Attempt to write to database or delete the building // Attempt to write to database or delete the building
// if we are destroying it. // if we are destroying it.
if (rank == -1) if (rank < 0)
success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(building);
else else
success = DbManager.BuildingQueries.updateBuildingRank(building, rank); success = DbManager.BuildingQueries.updateBuildingRank(building, rank);
-10
View File
@@ -11,8 +11,6 @@ package engine.gameManager;
import engine.mbEnums; import engine.mbEnums;
import engine.server.login.LoginServer; import engine.server.login.LoginServer;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import engine.wpak.EffectsParser;
import engine.wpak.PowersParser;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -166,14 +164,6 @@ public enum ConfigManager {
Logger.info("Compiling regex"); Logger.info("Compiling regex");
regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue())); regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue()));
Logger.info("Loading WPAK data");
EffectsParser.parseWpakFile();
PowersParser.parseWpakFile();
return true; return true;
} }
+1 -58
View File
@@ -2732,7 +2732,7 @@ public class mbEnums {
DIAMOND(1580010, 1540225085, -1730704107, 2000, 20), DIAMOND(1580010, 1540225085, -1730704107, 2000, 20),
GALVOR(1580017, -1683992404, -1596311545, 2000, 5), GALVOR(1580017, -1683992404, -1596311545, 2000, 5),
IRON(1580002, -1673518119, 2504297, 2000, 20), IRON(1580002, -1673518119, 2504297, 2000, 20),
LUMBER(1580004, 1628412684, -1603256692, 10000, 100), LUMBER(1580004, -1628412684, -1603256692, 10000, 100),
MANDRAKE(1580007, 1519910613, 1191391799, 1000, 10), MANDRAKE(1580007, 1519910613, 1191391799, 1000, 10),
MITHRIL(1580021, 626743397, -1761257186, 500, 5), MITHRIL(1580021, 626743397, -1761257186, 500, 5),
OAK(1580005, -1653034775, 74767, 3000, 30), OAK(1580005, -1653034775, 74767, 3000, 30),
@@ -3022,62 +3022,5 @@ public class mbEnums {
PREFIX, PREFIX,
SUFFIX; SUFFIX;
} }
public enum PowerType {
None,
SPELL,
SKILL;
}
public enum CostType {
NONE,
HEALTH,
MANA,
STAMINA;
}
public enum AreaType {
NONE,
SPHERE,
POINTBLANK,
LINE,
CONE,
WALL;
}
public enum ExcludeType {
NONE,
CASTER,
GROUP,
GUILD,
NATION,
PLAYERS,
ALLBUTGROUP,
ALLBUTPETS;
}
public enum CastingModeType {
NONE,
COMBAT,
NONCOMBAT,
BOTH;
}
public enum TargetSelectType {
NONE,
CLICK,
GROUP,
GUILD,
NEARBYMOBS,
NAME;
}
public enum CategoryToPowerType {
None,
GreaterThanOrEqualTo,
GreaterThan,
Always
}
} }
+1 -1
View File
@@ -561,7 +561,7 @@ public class Building extends AbstractWorldObject {
BuildingManager.setRank(barracksBuilding, -1); 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 // mesh along with buildings losing their health bonus
if (this.rank == 8) { if (this.rank == 8) {
+25 -4
View File
@@ -41,6 +41,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
public class City extends AbstractWorldObject { public class City extends AbstractWorldObject {
@@ -80,6 +81,7 @@ public class City extends AbstractWorldObject {
private String hash; private String hash;
public Warehouse warehouse; public Warehouse warehouse;
public Realm realm; public Realm realm;
public AtomicBoolean isDestroyed = new AtomicBoolean(false);
/** /**
* ResultSet Constructor * ResultSet Constructor
@@ -306,6 +308,21 @@ public class City extends AbstractWorldObject {
if (city.parentZone == null) if (city.parentZone == null)
continue; 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 //can't repledge to a guild you're already part of
if (repledge && city.getGuild().equals(playerCharacter.guild)) if (repledge && city.getGuild().equals(playerCharacter.guild))
@@ -1102,17 +1119,21 @@ public class City extends AbstractWorldObject {
public final void destroy() { public final void destroy() {
Thread destroyCityThread = new Thread(new DestroyCityThread(this)); if (this.isDestroyed.compareAndSet(false, true)) {
destroyCityThread.setName("destroyCity:" + this.getName()); Thread destroyCityThread = new Thread(new DestroyCityThread(this));
destroyCityThread.start();
destroyCityThread.setName("destroyCity:" + this.getParent().zoneName);
destroyCityThread.start();
} else
Logger.error("Attempt to destroy destroyed city");
} }
public final void transfer(AbstractCharacter newOwner) { public final void transfer(AbstractCharacter newOwner) {
Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner));
transferCityThread.setName("TransferCity:" + this.getName()); transferCityThread.setName("TransferCity:" + this.getParent().zoneName);
transferCityThread.start(); transferCityThread.start();
} }
+1 -2
View File
@@ -220,8 +220,7 @@ public class Mine extends AbstractGameObject {
// Only inactive mines are returned. // Only inactive mines are returned.
for (Mine mine : Mine.mineMap.keySet()) { for (Mine mine : Mine.mineMap.keySet()) {
if (mine.owningGuild.getObjectUUID() == guildID && if (mine.owningGuild.getObjectUUID() == guildID)
mine.isActive == false)
mineList.add(mine); mineList.add(mine);
} }
return mineList; return mineList;
+1 -1
View File
@@ -76,7 +76,7 @@ public class WorldServer {
super(); super();
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) {
WorldServer worldServer; WorldServer worldServer;
+91 -97
View File
@@ -53,123 +53,117 @@ public class DestroyCityThread implements Runnable {
// Member variable assignment // Member variable assignment
cityZone = city.getParent(); try {
newParent = cityZone.parent; cityZone = city.getParent();
formerGuild = city.getTOL().getGuild(); newParent = cityZone.parent;
formerGuild = city.getTOL().getGuild();
// Former guild loses it's tree! Logger.info("Destroy city thread started for: " + cityZone.zoneName);
if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { // Former guild loses tree!
//Successful Update of guild if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) {
formerGuild.setGuildState(mbEnums.GuildState.Errant); //Successful Update of guild
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. formerGuild.setGuildState(mbEnums.GuildState.Errant);
formerGuild.setNation(null);
if (!formerGuild.getSubGuildList().isEmpty()) { formerGuild.setCityUUID(0);
GuildManager.updateAllGuildTags(formerGuild);
subGuildList = new ArrayList<>(); GuildManager.updateAllGuildBinds(formerGuild, null);
subGuildList.addAll(formerGuild.getSubGuildList());
for (Guild subGuild : subGuildList) {
formerGuild.removeSubGuild(subGuild);
}
}
Building tol = null;
// Build list of buildings within this parent zone
for (Building cityBuilding : cityZone.zoneBuildingSet) {
// Sanity Check in case player deletes the building
// before this thread can get to it
if (cityBuilding == null)
continue;
// Do nothing with the banestone. It will be removed elsewhere
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE))
continue;
// TOL is processed after all other structures in the city zone
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.TOL)) {
tol = cityBuilding;
continue;
} }
// All buildings are moved to a location relative // By losing the tree, the former owners lose all of their subguilds.
// to their new parent zone
localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); if (!formerGuild.getSubGuildList().isEmpty()) {
DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); subGuildList = new ArrayList<>();
// All buildings are re-parented to a zone one node subGuildList.addAll(formerGuild.getSubGuildList());
// higher in the tree (continent) as we will be
// deleting the city zone very shortly.
if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) for (Guild subGuild : subGuildList) {
cityBuilding.setParentZone(newParent); formerGuild.removeSubGuild(subGuild);
}
// No longer a tree, no longer any protection contract!
cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE);
// Remove warehouse entry if one exists.
if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) {
DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse);
city.warehouse = null;
} }
// Destroy all remaining city assets // Build list of buildings within this parent zone
if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) ArrayList<Building> destroySet = new ArrayList<>();
|| (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) for (Building cityBuilding : cityZone.zoneBuildingSet) {
BuildingManager.setRank(cityBuilding, -1);
// Sanity Check in case player deletes the building
// before this thread can get to it
if (cityBuilding == null)
continue;
// Do nothing with the banestone. It will be removed elsewhere
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE))
continue;
// All buildings are moved to a location relative
// to their new parent zone
localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent);
DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z);
// 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.
if (cityBuilding.getParentZoneID() != newParent.getParentZoneID())
cityBuilding.setParentZone(newParent);
// No longer a tree, no longer any protection contract!
cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE);
// Remove warehouse entry if one exists.
if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) {
DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse);
city.warehouse = null;
}
// Mark all auto protected buildings for destruction
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;
}
// 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)) {
Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID());
return;
}
// Refresh the city for map requests
City.lastCityUpdate = System.currentTimeMillis();
} catch (Exception e) {
Logger.error(e);
} }
// Destroy the tol
if (tol != null)
BuildingManager.setRank(tol, -1);
if (city.realm != null)
city.realm.removeCity(city.getObjectUUID());
// 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) {
Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID());
return;
}
// Refresh the city for map requests
City.lastCityUpdate = System.currentTimeMillis();
// Zone and city should vanish upon next reboot // Zone and city should vanish upon next reboot
// if the codebase reaches here. // 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!");
} }
} }
-259
View File
@@ -1,259 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak;
import engine.gameManager.ConfigManager;
import engine.mbEnums;
import engine.wpak.data.EffectEntry;
import engine.wpak.data.EffectModifier;
import org.pmw.tinylog.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EffectsParser {
public static String effectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg";
public static HashMap<String, EffectEntry> 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);
private static final Pattern CONDITIONS_REGEX = Pattern.compile("(?<=CONDITIONBEGIN)(.+?)(?=CONDITIONEND)", Pattern.DOTALL);
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*"); // Regex ignores spaces within quotes
public static void parseWpakFile() {
// Read .wpak file from disk
byte[] fileData = null;
try {
fileData = Files.readAllBytes(Paths.get(effectsPath));
} catch (IOException e) {
throw new RuntimeException(e);
}
String fileContents = new String(fileData);
// Iterate over effect entries from .wpak data
Matcher matcher = EFFECT_REGEX.matcher(fileContents);
while (matcher.find()) {
EffectEntry effectEntry = parseEffectEntry(matcher.group());
effect_data.put(effectEntry.effect_id, effectEntry);
}
}
private static EffectEntry parseEffectEntry(String effectData) {
EffectEntry effectEntry = new EffectEntry();
// Remove all lines that contain a # and leading/trailing blank lines
effectData = effectData.replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", "");
effectData = effectData.trim();
// Parse effect entry header
String firstLine;
ArrayList<String> effectHeader = new ArrayList<>();
// Some effects exist without sources/mods or conditions
// (ACID "MOB" 0)
if (effectData.indexOf('\n') > 0)
firstLine = effectData.substring(0, effectData.indexOf('\n'));
else
firstLine = effectData;
Matcher matcher = STRSPLIT_REGEX.matcher(firstLine);
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("\"", "");
// Some effect mods have no icon
// (SEEINVIS-SHADE "See Invis")
if (effectHeader.size() == 3)
effectEntry.icon = Integer.parseInt(effectHeader.get(2));
else
effectEntry.icon = 0;
// Parse source entries
matcher = SOURCE_REGEX.matcher(effectData);
while (matcher.find())
effectEntry.sources.add(matcher.group().trim());
// Parse modifier entries
matcher = MODS_REGEX.matcher(effectData);
// Iterate effect entries from .wpak config data
while (matcher.find()) {
EffectModifier effectModifier = parseModEntry(matcher.group());
effectEntry.mods.add(effectModifier);
}
// Parse Conditions
matcher = CONDITIONS_REGEX.matcher(effectData);
while (matcher.find()) {
String[] conditions = matcher.group().trim().split("\n");
for (String condition : conditions) {
String[] parameters = condition.trim().split("\\s+");
effectEntry.conditions.put(parameters[0], Float.parseFloat(parameters[1]));
}
}
return effectEntry;
}
private static EffectModifier parseModEntry(String modData) {
EffectModifier effectModifier = new EffectModifier();
String[] modEntries = modData.trim().split("\n");
for (String modEntry : modEntries) {
ArrayList<String> modValues = new ArrayList<>();
Matcher matcher = STRSPLIT_REGEX.matcher(modEntry.trim());
while (matcher.find())
modValues.add(matcher.group().trim());
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());
break;
case Health:
case Mana:
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());
// Parameter 4 is always 0.
effectModifier.compoundCurveType = mbEnums.CompoundCurveType.valueOf(modValues.get(5).trim());
effectModifier.arg1 = modValues.get(6).trim();
break;
case Attr:
case Resistance:
case Skill:
case HealthRecoverRate:
case ManaRecoverRate:
case StaminaRecoverRate:
case DamageShield:
case HealthFull:
case ManaFull:
case StaminaFull:
case Slay:
case Fade:
case Durability:
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());
if (modValues.size() > 4)
effectModifier.arg1 = modValues.get(4).trim(); // Some HeathFull entries do not have an argument
break;
case MeleeDamageModifier:
case OCV:
case DCV:
case AttackDelay:
case AdjustAboveDmgCap:
case DamageCap:
case ArmorPiercing:
case Speed:
case PowerDamageModifier:
case DR:
case PassiveDefense:
case MaxDamage:
case Value:
case WeaponSpeed:
case MinDamage:
case PowerCost:
case Block:
case Parry:
case Dodge:
case ScanRange:
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());
break;
case ItemName:
case BlockedPowerType:
case ImmuneTo:
case BlackMantle:
effectModifier.arg1 = modValues.get(1).trim();
// Some BlockedPowerType entries have only one argument
if (modValues.size() > 2)
effectModifier.arg2 = modValues.get(2).trim();
break;
case NoMod:
case ConstrainedAmbidexterity:
case ProtectionFrom:
case ExclusiveDamageCap:
case IgnoreDamageCap:
effectModifier.arg1 = modValues.get(1).trim();
break;
case WeaponProc:
effectModifier.min = Float.parseFloat(modValues.get(1).trim());
effectModifier.arg1 = modValues.get(2).trim();
effectModifier.scale = Float.parseFloat(modValues.get(3).trim());
break;
default:
Logger.error("Unhandled type: " + effectModifier.type);
break;
}
}
return effectModifier;
}
}
-57
View File
@@ -1,57 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak;
import engine.gameManager.ConfigManager;
import engine.wpak.data.PowerActionEntry;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PowerActionParser {
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*");
private static final Pattern POWER_ACTION_REGEX = Pattern.compile("(?<=POWERACTIONBEGIN)(.+?)(?=POWERACTIONEND)", Pattern.DOTALL);
private static final String powerActionPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/PowerActions.cfg";
public static void parseWpakFile() {
// Read .wpak file from disk
byte[] fileData;
try {
fileData = Files.readAllBytes(Paths.get(powerActionPath));
} catch (
IOException e) {
throw new RuntimeException(e);
}
String fileContents = new String(fileData);
// Iterate over power entries from .wpak data
Matcher matcher = POWER_ACTION_REGEX.matcher(fileContents);
while (matcher.find()) {
PowerActionEntry powerActionEntry = parsePowerActionEntry(matcher.group().trim());
}
}
private static PowerActionEntry parsePowerActionEntry(String powerActionData) {
PowerActionEntry powerActionEntry = new PowerActionEntry();
return powerActionEntry;
}
}
-316
View File
@@ -1,316 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak;
import engine.gameManager.ConfigManager;
import engine.mbEnums;
import engine.wpak.data.*;
import org.pmw.tinylog.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PowersParser {
private static final Pattern POWER_REGEX = Pattern.compile("(?<=POWERBEGIN)(.+?)(?=POWEREND)", Pattern.DOTALL);
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*");
private static final Pattern CONDITION_REGEX = Pattern.compile("(?<=CONDITIONBEGIN)(.+?)(?=CONDITIONEND)", Pattern.DOTALL);
private static final String powersPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Powers.cfg";
public static void parseWpakFile() {
// Read .wpak file from disk
byte[] fileData;
try {
fileData = Files.readAllBytes(Paths.get(powersPath));
} catch (IOException e) {
throw new RuntimeException(e);
}
String fileContents = new String(fileData);
// Iterate over power entries from .wpak data
Matcher matcher = POWER_REGEX.matcher(fileContents);
while (matcher.find()) {
PowerEntry powerEntry = parsePowerEntry(matcher.group().trim());
}
}
private static PowerEntry parsePowerEntry(String powerData) {
PowerEntry powerEntry = new PowerEntry();
try {
StringBuilder conditionString = new StringBuilder();
StringBuilder powerString = new StringBuilder();
int endPos = 0;
// Separate out any conditions from the power data
Matcher matcher = CONDITION_REGEX.matcher(powerData);
while (matcher.find()) {
conditionString.append(matcher.group().trim());
powerString.append(powerData, endPos, matcher.start());
endPos = matcher.end();
}
powerString.append(powerData.substring(endPos));
// Cleanup dangling tags and lines that contain a # and leading/trailing blank lines
powerString = new StringBuilder(powerString.toString().replaceAll("CONDITIONBEGINCONDITIONEND", ""));
powerString = new StringBuilder(powerString.toString().replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", ""));
conditionString = new StringBuilder(conditionString.toString().replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", ""));
// Parse header line in power data
String[] lineData = powerString.toString().trim().split("\n");
ArrayList<String> powerHeader = new ArrayList<>();
String headerString = lineData[0];
headerString = headerString.replace("\n", " ");
matcher = STRSPLIT_REGEX.matcher(headerString);
while (matcher.find())
powerHeader.add(matcher.group().trim());
java.util.Iterator<String> iterator = powerHeader.iterator();
powerEntry.power_id = iterator.next();
powerEntry.power = iterator.next().replaceAll("\"", "");
PowerData power = new PowerData();
power.power_type = mbEnums.PowerType.valueOf(iterator.next());
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
String nextValue = iterator.next();
// Account for second definition
if (nextValue.equals("SPELL") || nextValue.equals("SKILL")) {
power = new PowerData();
power.power_type = mbEnums.PowerType.valueOf(nextValue);
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(iterator.next());
} else
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(nextValue);
powerEntry.range = Integer.parseInt(iterator.next());
powerEntry.areaType = mbEnums.AreaType.valueOf(iterator.next());
powerEntry.areaRange = Integer.parseInt(iterator.next());
powerEntry.excludeType = mbEnums.ExcludeType.valueOf(iterator.next());
powerEntry.costType = mbEnums.CostType.valueOf(iterator.next());
powerEntry.cost = Float.parseFloat(iterator.next());
powerEntry.difficulty = Float.parseFloat(iterator.next());
powerEntry.precision = Float.parseFloat(iterator.next());
powerEntry.init_time = Float.parseFloat(iterator.next().replaceAll("(\\.0)+$", ""));
powerEntry.release_time = Float.parseFloat(iterator.next());
powerEntry.recycle_time = Float.parseFloat(iterator.next());
powerEntry.hitRollYN = Integer.parseInt(iterator.next());
powerEntry.castingMode = mbEnums.CastingModeType.valueOf(iterator.next());
powerEntry.initAmin = Integer.parseInt(iterator.next());
powerEntry.releaseAnim = Integer.parseInt(iterator.next());
powerEntry.targetSelect = mbEnums.TargetSelectType.valueOf(iterator.next());
// Process key value pairs after header
iterator = Arrays.stream(lineData).iterator();
iterator.next(); // Ignore header
while (iterator.hasNext()) {
String lineValue = iterator.next();
String[] lineValues = lineValue.split("=");
String key = lineValues[0].trim();
ActionEntry actionEntry;
String[] arguments;
Matcher matcher1;
ArrayList<String> args;
switch (key) {
case "ACTION":
actionEntry = new ActionEntry();
arguments = lineValues[1].trim().split("\\s+");
if (powerEntry.power_id.equals("HNT-050"))
Logger.error("debug");
actionEntry.effect_id = arguments[0];
actionEntry.minTrains = Integer.parseInt(arguments[1]);
actionEntry.maxTrains = Integer.parseInt(arguments[2]);
actionEntry.duration = Float.parseFloat(arguments[3]);
actionEntry.curve = mbEnums.CompoundCurveType.valueOf(arguments[4]);
actionEntry.stackingCategory = arguments[5];
actionEntry.stackingPriority = Integer.parseInt(arguments[6]);
actionEntry.categoryToPower = mbEnums.CategoryToPowerType.valueOf(arguments[7]);
powerEntry.actionEntries.add(actionEntry);
break;
case "MaxLevel":
powerEntry.maxLevel = Integer.parseInt(lineValues[1].trim());
break;
case "HateValue":
arguments = lineValues[1].trim().split("\\s+");
powerEntry.hateValue = Integer.parseInt(arguments[0]);
// Not all entries have a curve. Defaults to DefaultFlat;
if (arguments.length > 1)
powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]);
break;
case "LOOPANIMID":
powerEntry.loopAnimID = Integer.parseInt(lineValues[1].trim());
break;
case "GRANTOVERRIDEVAR":
powerEntry.grantOverrideVar = lineValues[1].trim();
break;
case "DESCRIPTION":
powerEntry.description.add(lineValues[1].trim());
break;
case "CATEGORY":
powerEntry.category = lineValues[1].trim();
break;
case "CURVE":
arguments = lineValues[1].trim().split("\\s+");
powerEntry.curves.put(arguments[0], mbEnums.CompoundCurveType.valueOf(arguments[1]));
break;
case "EQPREREQ":
EquipmentPreReq equipmentPreReq = new EquipmentPreReq();
matcher1 = STRSPLIT_REGEX.matcher(lineValues[1].trim());
args = new ArrayList<>();
while (matcher1.find())
args.add(matcher1.group().trim());
equipmentPreReq.slot = mbEnums.EquipSlotType.valueOf(args.get(0));
equipmentPreReq.skill = args.get(1).replaceAll("\"", "");
equipmentPreReq.level = Integer.parseInt(args.get(2));
powerEntry.equipmentPreReq = equipmentPreReq;
break;
case "CANCASTWHILEMOVING":
powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues[1].trim());
break;
case "CANCASTWHILEFLYING":
powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues[1].trim());
break;
case "BLADETRAILS":
powerEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim());
break;
case "EFFECTPREREQ":
EffectDescription effectPreReq = new EffectDescription();
arguments = lineValues[1].trim().split("\\s+");
effectPreReq.effect_id = arguments[9];
effectPreReq.level = Integer.parseInt(arguments[1]);
effectPreReq.message = arguments[2];
powerEntry.effectPreReqs.add(effectPreReq);
break;
case "MONSTERTYPERESTRICTS":
arguments = lineValues[1].trim().split("\\s+");
for (String restriction : arguments)
powerEntry.monsterRestricts.add(mbEnums.MonsterType.valueOf(restriction.trim()));
break;
case "MONSTERTYPEPREREQS":
arguments = lineValues[1].trim().split("\\s+");
for (String restriction : arguments)
powerEntry.monsterPrereqs.add(mbEnums.MonsterType.valueOf(restriction.trim()));
break;
case "SHOULDCHECKPATH":
powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues[1].trim());
break;
case "STICKY":
powerEntry.sticky = Boolean.parseBoolean(lineValues[1].trim());
break;
case "PULSEINFO":
arguments = lineValues[1].trim().split("\\s+");
powerEntry.pulseCycle = Integer.parseInt(arguments[0]);
powerEntry.pulseDuration = Integer.parseInt(arguments[1]);
break;
case "MAXNUMMOBTARGETS":
powerEntry.maxMobTargets = Integer.parseInt(lineValues[1].trim());
break;
case "MAXNUMPLAYERTARGETS":
powerEntry.maxPlayerTargets = Integer.parseInt(lineValues[1].trim());
break;
case "ISADMINPOWER":
powerEntry.isAdminPower = Boolean.parseBoolean(lineValues[1].trim());
break;
case "ISPROJECTILE":
powerEntry.isProjectile = Boolean.parseBoolean(lineValues[1].trim());
break;
case "CASTERSPULSEPARTICLE":
powerEntry.casterPulseParticle = Integer.parseInt(lineValues[1].trim());
break;
case "TARGETEFFECTPREREQS_ORED":
EffectDescription preReq = new EffectDescription();
arguments = lineValues[1].trim().split("\\s+");
preReq.effect_id = arguments[0];
preReq.level = Integer.parseInt(arguments[1]);
powerEntry.targetEffectPrereqs.add(preReq);
break;
case "SOUNDS": // Values not parsed
case "APPLYDAMAGESELF":
case "APPLYDAMAGECASTER":
case "APPLYDAMAGEOTHER":
case "APPLYDAMAGETARGET":
case "APPLYEFFECTSELF":
case "APPLYEFFECTOTHER":
case "APPLYEFFECTCASTER":
case "APPLYEFFECTTARGET":
case "FIZZLEOTHER":
case "FIZZLESELF":
case "INITSTRING":
case "SUCCESSOTHER":
case "SUCCESSSELF":
case "WEAROFFEFFECTOTHER":
case "WEAROFFEFFECTSELF":
break;
default:
Logger.error("Unhandled variable type:" + key + " for power: " + powerEntry.power_id);
}
}
// Parse power conditions
if (conditionString.toString().isEmpty() == false) {
String[] conditions = conditionString.toString().split("\n");
for (String condition : conditions) {
String[] parameters = condition.trim().split("\\s+");
powerEntry.conditions.put(parameters[0], Float.parseFloat(parameters[1]));
}
}
} catch (Exception e) {
Logger.error(powerEntry.power_id + " " + e);
}
return powerEntry;
}
}
-24
View File
@@ -1,24 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import engine.mbEnums;
public class ActionEntry {
public String effect_id;
public int minTrains;
public int maxTrains;
public float duration;
public String stackingCategory;
public mbEnums.CompoundCurveType curve;
public int stackingPriority;
public mbEnums.CategoryToPowerType categoryToPower;
}
@@ -1,15 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
public class EffectDescription {
public String effect_id;
public int level;
public String message;
}
-22
View File
@@ -1,22 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class EffectEntry {
public String effect_id;
public String effect_name;
public int icon;
public HashSet<String> sources = new HashSet<>();
public ArrayList<EffectModifier> mods = new ArrayList<>();
public HashMap<String, Float> conditions = new HashMap<>();
}
-22
View File
@@ -1,22 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import engine.mbEnums;
public class EffectModifier {
public mbEnums.ModType type;
public float min;
public float max;
public float scale;
public mbEnums.CompoundCurveType compoundCurveType;
public String arg1; // ItemName "Masterwork" ""
public String arg2; // ItemName "" "of the Defender"
}
-19
View File
@@ -1,19 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import engine.mbEnums;
public class EquipmentPreReq {
public mbEnums.EquipSlotType slot;
public String skill;
public int level;
}
@@ -1,18 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import java.util.ArrayList;
public class PowerActionEntry {
public String action_id;
public String action_type;
public ArrayList<EffectDescription> effects;
}
-17
View File
@@ -1,17 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import engine.mbEnums;
public class PowerData {
public mbEnums.PowerType power_type;
public int icon;
public String powerBase;
}
-69
View File
@@ -1,69 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak.data;
import engine.mbEnums;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
public class PowerEntry {
public String power_id;
public String power;
public ArrayList<PowerData> powers = new ArrayList<>();
public mbEnums.PowerTargetType target_type;
public int range;
public mbEnums.AreaType areaType;
public int areaRange;
public mbEnums.ExcludeType excludeType;
public mbEnums.CostType costType;
public float cost;
public float difficulty;
public float precision;
public float init_time;
public float release_time;
public float recycle_time;
public int hitRollYN;
public mbEnums.CastingModeType castingMode;
public int initAmin;
public int releaseAnim;
public mbEnums.TargetSelectType targetSelect;
// Additional key/value type power entries
public ArrayList<ActionEntry> actionEntries = new ArrayList<>();
public int maxLevel;
public int hateValue;
public mbEnums.CompoundCurveType hateCurve = mbEnums.CompoundCurveType.DefaultFlat;
public int loopAnimID;
public String grantOverrideVar;
public ArrayList<String> description = new ArrayList<>();
public HashMap<String, mbEnums.CompoundCurveType> curves = new HashMap<>();
public String category;
public boolean canCastWhileMoving = false;
public boolean bladeTrails = false;
public ArrayList<EffectDescription> effectPreReqs = new ArrayList<>();
public EquipmentPreReq equipmentPreReq;
public EnumSet<mbEnums.MonsterType> monsterRestricts = EnumSet.noneOf(mbEnums.MonsterType.class);
public EnumSet<mbEnums.MonsterType> monsterPrereqs = EnumSet.noneOf(mbEnums.MonsterType.class);
public boolean shouldCheckPath = false;
public boolean sticky = false;
public int pulseCycle;
public int pulseDuration;
public int maxMobTargets;
public int maxPlayerTargets;
public boolean isAdminPower = false;
public int casterPulseParticle;
public ArrayList<EffectDescription> targetEffectPrereqs = new ArrayList<>();
public boolean canCastWhileFlying = false;
public boolean isProjectile = false;
public HashMap<String, Float> conditions = new HashMap<>();
}