Project cleanup pre merge.
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||

|
||||
|
||||
# Magicbane Open-Source MMO Project
|
||||
|
||||
### *The Community written Shadowbane emulator*
|
||||
|
||||
[Magicbane](http://www.magicbane.com)
|
||||
</BR>
|
||||
[Public Repository](http://repo.magicbane.com)
|
||||
<BR>
|
||||
<magicbot@magicbane.com>
|
||||
|
||||
> Magicbane is an emulator for the long dead but much beloved Ubisoft MMO, [Shadowbane](https://en.wikipedia.org/wiki/Shadowbane).
|
||||
The project was founded in 2013 with the concept of free availability of gameplay; players unencumbered by any factor other than a desire to again play a game they once loved. A game where the developers do not play is guaranteed to be the fairest game.
|
||||
> Magicbane is an emulator for the long dead but much beloved Ubisoft
|
||||
> MMO, [Shadowbane](https://en.wikipedia.org/wiki/Shadowbane).
|
||||
> The project was founded in 2013 with the concept of free availability of gameplay; players unencumbered by any factor
|
||||
> other than a desire to again play a game they once loved. A game where the developers do not play is guaranteed to be
|
||||
> the fairest game.
|
||||
|
||||
The Magicbane Team has wanted to open source Shadowbane for half a decade. We are excited to now finally have the opportunity, along with some new technology, to truly democratize Shadowbane.
|
||||
The Magicbane Team has wanted to open source Shadowbane for half a decade. We are excited to now finally have the
|
||||
opportunity, along with some new technology, to truly democratize Shadowbane.
|
||||
|
||||
- Written in some 80k lines of Java 8 and bash.
|
||||
- Project with real infrastructure; Production and development servers supporting multiple containerized apps.
|
||||
@@ -20,11 +26,12 @@ The Magicbane Team has wanted to open source Shadowbane for half a decade. We a
|
||||
|
||||
## Contributing
|
||||
|
||||
- Project is released under an MIT license. Please see the LICENSE file.
|
||||
- Project is released under an MIT license. Please see the LICENSE file.
|
||||
- Inbound == Outbound.
|
||||
- IntelliJ is the supported IDE.
|
||||
- Write code today see it running on the Magicbane production server tomorrow.
|
||||
|
||||
## Support
|
||||
|
||||
Documentation is available through the Magicbane [Wiki](http://repo.magicbane.com/MagicBane/Server/wiki) and [Discord server](www.magicbane.com).
|
||||
Documentation is available through the Magicbane [Wiki](http://repo.magicbane.com/MagicBane/Server/wiki)
|
||||
and [Discord server](www.magicbane.com).
|
||||
@@ -24,7 +24,7 @@ public enum ChatChannel {
|
||||
ADMINLOG("MB_MAGICBOT_ADMINLOG");
|
||||
|
||||
public final String configName;
|
||||
public long channelID;
|
||||
public long channelID;
|
||||
public TextChannel textChannel;
|
||||
|
||||
ChatChannel(String configName) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
|
||||
import engine.Enum;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -18,6 +19,7 @@ public class DiscordAccount {
|
||||
public LocalDateTime registrationDate;
|
||||
public LocalDateTime lastUpdateRequest;
|
||||
public byte isDiscordAdmin;
|
||||
|
||||
public DiscordAccount() {
|
||||
|
||||
}
|
||||
|
||||
+149
-148
@@ -37,32 +37,32 @@ import java.util.regex.Pattern;
|
||||
import static discord.ChatChannel.ADMINLOG;
|
||||
|
||||
/*
|
||||
* MagicBot is many things to Magicbane...
|
||||
*
|
||||
* -Project Mascot
|
||||
* -Customer service and administration bot
|
||||
* -Benevolent dictator
|
||||
* -Investment manager.
|
||||
*
|
||||
* MagicBot will never beg you for money. He is a very
|
||||
* responsible robot. He was varnished but never garnished.
|
||||
* MagicBot does not for to overclock himself. His chips
|
||||
* will therefore never overcook.
|
||||
* MagicBot will never be a pitiful robot trying for to use
|
||||
* you as emotional support human.
|
||||
*
|
||||
* MagicBot is just not that sort of robot and Magicbane
|
||||
* just isn't that sort of project.
|
||||
*
|
||||
* MagicBot runs a Shaodowbane emulator not a Second Life emulator.
|
||||
*
|
||||
*/
|
||||
* MagicBot is many things to Magicbane...
|
||||
*
|
||||
* -Project Mascot
|
||||
* -Customer service and administration bot
|
||||
* -Benevolent dictator
|
||||
* -Investment manager.
|
||||
*
|
||||
* MagicBot will never beg you for money. He is a very
|
||||
* responsible robot. He was varnished but never garnished.
|
||||
* MagicBot does not for to overclock himself. His chips
|
||||
* will therefore never overcook.
|
||||
* MagicBot will never be a pitiful robot trying for to use
|
||||
* you as emotional support human.
|
||||
*
|
||||
* MagicBot is just not that sort of robot and Magicbane
|
||||
* just isn't that sort of project.
|
||||
*
|
||||
* MagicBot runs a Shaodowbane emulator not a Second Life emulator.
|
||||
*
|
||||
*/
|
||||
public class MagicBot extends ListenerAdapter {
|
||||
|
||||
public static JDA jda;
|
||||
public static Database database;
|
||||
public static final Pattern accountNameRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$");
|
||||
public static final Pattern passwordRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$");
|
||||
public static JDA jda;
|
||||
public static Database database;
|
||||
public static long discordServerID;
|
||||
public static long discordRoleID;
|
||||
|
||||
@@ -126,12 +126,136 @@ public class MagicBot extends ListenerAdapter {
|
||||
Runnable adminLogRunnable = () -> SendAdminLogUpdates();
|
||||
|
||||
ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
|
||||
exec.scheduleAtFixedRate(adminLogRunnable , 0, 1, TimeUnit.MINUTES);
|
||||
exec.scheduleAtFixedRate(adminLogRunnable, 0, 1, TimeUnit.MINUTES);
|
||||
|
||||
Logger.info("***MAGICBOT IS RUNNING***");
|
||||
|
||||
}
|
||||
|
||||
public static void sendResponse(MessageReceivedEvent event, String responseContent) {
|
||||
|
||||
// Send a formatted MagicBot response to a Discord user
|
||||
|
||||
String discordUserName;
|
||||
MessageChannel channel;
|
||||
|
||||
// Exit if discord is offline
|
||||
|
||||
if (jda.getStatus().equals(JDA.Status.CONNECTED) == false)
|
||||
return;
|
||||
|
||||
discordUserName = event.getAuthor().getName();
|
||||
channel = event.getMessage().getChannel();
|
||||
|
||||
channel.sendMessage(
|
||||
"```\n" + "Hello Player " + discordUserName + "\n\n" +
|
||||
responseContent + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```").queue();
|
||||
}
|
||||
|
||||
public static boolean isAdminEvent(MessageReceivedEvent event) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
List<DiscordAccount> discordAccounts;
|
||||
DiscordAccount discordAccount;
|
||||
|
||||
// Note that database errors will cause this to return false.
|
||||
// After the database is offline Avail status must be set
|
||||
// to true before any subsequent admin commands will function.
|
||||
|
||||
if (Database.online == false)
|
||||
return false;
|
||||
|
||||
discordAccounts = database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
if (discordAccounts.isEmpty())
|
||||
return false;
|
||||
|
||||
discordAccount = discordAccounts.get(0);
|
||||
return (discordAccount.isDiscordAdmin == 1);
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
|
||||
String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
StringBuilder passwordBuilder = new StringBuilder(length);
|
||||
Random random = new Random();
|
||||
|
||||
// Generate alphanumeric password of a given length.
|
||||
// Could not find a good method of generating a password
|
||||
// based upon a given regex.
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
passwordBuilder.append(ALPHABET.charAt(random.nextInt(ALPHABET.length())));
|
||||
|
||||
return new String(passwordBuilder);
|
||||
}
|
||||
|
||||
public static String readLogFile(String filePath, int lineCount) {
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "tail -n " + lineCount + " " + filePath);
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = null;
|
||||
String line = null;
|
||||
String logOutput = "";
|
||||
|
||||
try {
|
||||
process = builder.start();
|
||||
|
||||
InputStream is = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
logOutput += line + "\n";
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
return "Error while reading logfile";
|
||||
}
|
||||
|
||||
return logOutput;
|
||||
}
|
||||
|
||||
private static void junkbot(String command, String[] inString) {
|
||||
|
||||
String outString;
|
||||
Writer fileWriter;
|
||||
|
||||
if (inString == null)
|
||||
return;
|
||||
;
|
||||
|
||||
outString = command + String.join(" ", inString);
|
||||
outString += "\n";
|
||||
|
||||
try {
|
||||
fileWriter = new BufferedWriter(new FileWriter("junkbot.txt", true));
|
||||
fileWriter.append(outString);
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SendAdminLogUpdates() {
|
||||
HashMap<Integer, String> adminEvents = database.getAdminEvents();
|
||||
|
||||
for (int adminEvent : adminEvents.keySet()) {
|
||||
|
||||
// Set event as read
|
||||
database.setAdminEventAsRead(adminEvent);
|
||||
String outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
adminEvents.get(adminEvent) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
|
||||
if (ADMINLOG.textChannel.canTalk())
|
||||
ADMINLOG.textChannel.sendMessage(outString).queue();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
|
||||
@@ -142,7 +266,8 @@ public class MagicBot extends ListenerAdapter {
|
||||
|
||||
// Early exit if message sent to us by another bot or ourselves.
|
||||
|
||||
if (event.getAuthor().isBot()) return;
|
||||
if (event.getAuthor().isBot())
|
||||
return;
|
||||
|
||||
// Extract message and origin channel from event
|
||||
|
||||
@@ -247,49 +372,6 @@ public class MagicBot extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendResponse(MessageReceivedEvent event, String responseContent) {
|
||||
|
||||
// Send a formatted MagicBot response to a Discord user
|
||||
|
||||
String discordUserName;
|
||||
MessageChannel channel;
|
||||
|
||||
// Exit if discord is offline
|
||||
|
||||
if (jda.getStatus().equals(JDA.Status.CONNECTED) == false)
|
||||
return;
|
||||
|
||||
discordUserName = event.getAuthor().getName();
|
||||
channel = event.getMessage().getChannel();
|
||||
|
||||
channel.sendMessage(
|
||||
"```\n" + "Hello Player " + discordUserName + "\n\n" +
|
||||
responseContent + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```").queue();
|
||||
}
|
||||
|
||||
public static boolean isAdminEvent(MessageReceivedEvent event) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
List<DiscordAccount> discordAccounts;
|
||||
DiscordAccount discordAccount;
|
||||
|
||||
// Note that database errors will cause this to return false.
|
||||
// After the database is offline Avail status must be set
|
||||
// to true before any subsequent admin commands will function.
|
||||
|
||||
if (Database.online == false)
|
||||
return false;
|
||||
|
||||
discordAccounts = database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
if (discordAccounts.isEmpty())
|
||||
return false;
|
||||
|
||||
discordAccount = discordAccounts.get(0);
|
||||
return (discordAccount.isDiscordAdmin == 1);
|
||||
}
|
||||
|
||||
public void handleHelpRequest(MessageReceivedEvent event) {
|
||||
|
||||
// Help is kept here in the main class instead of a handler as a
|
||||
@@ -322,85 +404,4 @@ public class MagicBot extends ListenerAdapter {
|
||||
"#trash <blank>/detail/flush";
|
||||
sendResponse(event, helpString);
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
|
||||
String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
StringBuilder passwordBuilder = new StringBuilder(length);
|
||||
Random random = new Random();
|
||||
|
||||
// Generate alphanumeric password of a given length.
|
||||
// Could not find a good method of generating a password
|
||||
// based upon a given regex.
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
passwordBuilder.append(ALPHABET.charAt(random.nextInt(ALPHABET.length())));
|
||||
|
||||
return new String(passwordBuilder);
|
||||
}
|
||||
|
||||
public static String readLogFile(String filePath, int lineCount) {
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "tail -n " + lineCount + " " + filePath);
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = null;
|
||||
String line = null;
|
||||
String logOutput = "";
|
||||
|
||||
try {
|
||||
process = builder.start();
|
||||
|
||||
InputStream is = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
logOutput += line + "\n";
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
return "Error while reading logfile";
|
||||
}
|
||||
|
||||
return logOutput;
|
||||
}
|
||||
|
||||
private static void junkbot(String command, String[] inString) {
|
||||
|
||||
String outString;
|
||||
Writer fileWriter;
|
||||
|
||||
if (inString == null)
|
||||
return;
|
||||
;
|
||||
|
||||
outString = command + String.join(" ", inString);
|
||||
outString += "\n";
|
||||
|
||||
try {
|
||||
fileWriter = new BufferedWriter(new FileWriter("junkbot.txt", true));
|
||||
fileWriter.append(outString);
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SendAdminLogUpdates() {
|
||||
HashMap<Integer, String> adminEvents = database.getAdminEvents();
|
||||
|
||||
for (int adminEvent : adminEvents.keySet()) {
|
||||
|
||||
// Set event as read
|
||||
database.setAdminEventAsRead(adminEvent);
|
||||
String outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
adminEvents.get(adminEvent) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
|
||||
if (ADMINLOG.textChannel.canTalk())
|
||||
ADMINLOG.textChannel.sendMessage(outString).queue();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ public class ChatChannelHandler {
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else outString = chatText;
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else
|
||||
outString = chatText;
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DevRequestHandler {
|
||||
|
||||
switch (serverCommand) {
|
||||
|
||||
case "build" :
|
||||
case "build":
|
||||
commandString = "./mbdevbuild.sh";
|
||||
break;
|
||||
case "restart":
|
||||
@@ -61,11 +61,11 @@ public class DevRequestHandler {
|
||||
case "help":
|
||||
MagicBot.sendResponse(event,
|
||||
"#dev build <target> (blank==master) \n" +
|
||||
"#dev shutdown (Shutdown dev server)\n" +
|
||||
"#dev restart (Restarts the server)\n"+
|
||||
"#dev debug (Restarts server in debug mode)\n" +
|
||||
"#dev console # (Displays # lines from console)\n" +
|
||||
"#dev lastout (Displays output from last command) \n");
|
||||
"#dev shutdown (Shutdown dev server)\n" +
|
||||
"#dev restart (Restarts the server)\n" +
|
||||
"#dev debug (Restarts server in debug mode)\n" +
|
||||
"#dev console # (Displays # lines from console)\n" +
|
||||
"#dev lastout (Displays output from last command) \n");
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
@@ -77,18 +77,19 @@ public class DevRequestHandler {
|
||||
}
|
||||
|
||||
processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument + " > devLastOut");
|
||||
logString = String.join(" ",processBuilder.command().toArray(new String[0]));
|
||||
logString = String.join(" ", processBuilder.command().toArray(new String[0]));
|
||||
|
||||
try {
|
||||
processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
Logger.info(e.toString());
|
||||
}
|
||||
processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
Logger.info(e.toString());
|
||||
}
|
||||
|
||||
MagicBot.sendResponse(event, "Executed on dev: " + logString + "\n" +
|
||||
"Use #dev lastout to view results");
|
||||
"Use #dev lastout to view results");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private static String getLastOutput() {
|
||||
|
||||
String outString = null;
|
||||
|
||||
@@ -56,18 +56,18 @@ public class RegisterAccountHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate account name with regex
|
||||
// Validate account name with regex
|
||||
|
||||
accountName = args[0].replaceAll("\\s+", "");
|
||||
accountName = args[0].replaceAll("\\s+", "");
|
||||
|
||||
if (MagicBot.accountNameRegex.matcher(accountName).matches() == false) {
|
||||
if (MagicBot.accountNameRegex.matcher(accountName).matches() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied account name does not compute.\n" +
|
||||
"Account names must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied account name does not compute.\n" +
|
||||
"Account names must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountName.equalsIgnoreCase("accountname")) {
|
||||
MagicBot.sendResponse(event,
|
||||
|
||||
@@ -24,7 +24,7 @@ public class StatusRequestHandler {
|
||||
outString = "Server Status: ";
|
||||
|
||||
if (LoginServer.isPortInUse(Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue())))
|
||||
outString += "ONLINE\n";
|
||||
outString += "ONLINE\n";
|
||||
else
|
||||
outString += "OFFLINE\n";
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class TrashRequestHandler {
|
||||
|
||||
// Anounce event in septic tank channel
|
||||
|
||||
outString = "```\n" + trashCount + " Player Character were for to deleted due to verified cheatings. \n\n";
|
||||
outString = "```\n" + trashCount + " Player Character were for to deleted due to verified cheatings. \n\n";
|
||||
outString += MagicBot.database.getTrashList() + "\n\n";
|
||||
outString += RobotSpeak.getRobotInsult() + "\n```";
|
||||
|
||||
|
||||
+2786
-2786
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ public class HeightMap {
|
||||
float numOfBuckets = this.heightmapImage.getWidth() - 1;
|
||||
float calculatedWidth = this.fullExtentsX / numOfBuckets;
|
||||
this.bucketWidthX = calculatedWidth;
|
||||
this.bucketWidthY = this.bucketWidthX; // This makes no sense.
|
||||
this.bucketWidthY = this.bucketWidthX; // This makes no sense.
|
||||
|
||||
// Generate pixel array from image data
|
||||
|
||||
@@ -142,7 +142,7 @@ public class HeightMap {
|
||||
this.bucketWidthX = 1;
|
||||
this.bucketWidthY = 1;
|
||||
|
||||
this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY+1];
|
||||
this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY + 1];
|
||||
|
||||
for (int y = 0; y <= this.fullExtentsY; y++) {
|
||||
for (int x = 0; x <= this.fullExtentsX; x++) {
|
||||
@@ -153,7 +153,7 @@ public class HeightMap {
|
||||
|
||||
HeightMap.heightmapByLoadNum.put(this.zoneLoadID, this);
|
||||
}
|
||||
|
||||
|
||||
public HeightMap(Zone zone) {
|
||||
|
||||
this.heightMapID = 999999;
|
||||
@@ -180,7 +180,7 @@ public class HeightMap {
|
||||
this.bucketWidthX = 1;
|
||||
this.bucketWidthY = 1;
|
||||
|
||||
this.pixelColorValues = new int[this.fullExtentsX+1][this.fullExtentsY+1];
|
||||
this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY + 1];
|
||||
|
||||
for (int y = 0; y <= this.fullExtentsY; y++) {
|
||||
for (int x = 0; x <= this.fullExtentsX; x++) {
|
||||
@@ -197,97 +197,15 @@ public class HeightMap {
|
||||
HeightMap.PlayerCityHeightMap = new HeightMap();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void GenerateCustomHeightMap(Zone zone) {
|
||||
|
||||
HeightMap heightMap = new HeightMap(zone);
|
||||
|
||||
|
||||
HeightMap.heightmapByLoadNum.put(zone.getLoadNum(), heightMap);
|
||||
|
||||
}
|
||||
|
||||
public Vector2f getGridSquare(Vector2f zoneLoc) {
|
||||
|
||||
if (zoneLoc.x < 0)
|
||||
zoneLoc.setX(0);
|
||||
|
||||
if (zoneLoc.x > this.fullExtentsX - 1)
|
||||
zoneLoc.setX((this.fullExtentsX - 1) + .9999999f);
|
||||
|
||||
if (zoneLoc.y < 0)
|
||||
zoneLoc.setY(0);
|
||||
|
||||
if (zoneLoc.y > this.fullExtentsY - 1)
|
||||
zoneLoc.setY((this.fullExtentsY - 1) + .9999999f);
|
||||
|
||||
float xBucket = (zoneLoc.x / this.bucketWidthX);
|
||||
float yBucket = (zoneLoc.y / this.bucketWidthY);
|
||||
|
||||
return new Vector2f(xBucket, yBucket);
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector2f zoneLoc) {
|
||||
|
||||
Vector2f gridSquare;
|
||||
|
||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
||||
return -1;
|
||||
|
||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
||||
return -1;
|
||||
|
||||
int maxX = (int) (this.fullExtentsX / this.bucketWidthX);
|
||||
int maxY = (int) (this.fullExtentsY / this.bucketWidthY);
|
||||
|
||||
//flip the Y so it grabs from the bottom left instead of top left.
|
||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
||||
|
||||
gridSquare = getGridSquare(zoneLoc);
|
||||
|
||||
int gridX = (int) gridSquare.x;
|
||||
int gridY = (int) (gridSquare.y);
|
||||
|
||||
if (gridX > maxX)
|
||||
gridX = maxX;
|
||||
if (gridY > maxY)
|
||||
gridY = maxY;
|
||||
|
||||
float offsetX = (gridSquare.x - gridX);
|
||||
float offsetY = gridSquare.y - gridY;
|
||||
|
||||
//get height of the 4 vertices.
|
||||
|
||||
float topLeftHeight = 0;
|
||||
float topRightHeight = 0;
|
||||
float bottomLeftHeight = 0;
|
||||
float bottomRightHeight = 0;
|
||||
|
||||
int nextY = gridY +1;
|
||||
int nextX = gridX + 1;
|
||||
|
||||
if (nextY > maxY)
|
||||
nextY = gridY;
|
||||
|
||||
if (nextX > maxX)
|
||||
nextX = gridX;
|
||||
|
||||
topLeftHeight = pixelColorValues[gridX][gridY];
|
||||
topRightHeight = pixelColorValues[nextX][gridY];
|
||||
bottomLeftHeight = pixelColorValues[gridX][nextY];
|
||||
bottomRightHeight = pixelColorValues[nextX][nextY];
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
||||
|
||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
||||
|
||||
return interpolatedHeight;
|
||||
}
|
||||
|
||||
public static Zone getNextZoneWithTerrain(Zone zone) {
|
||||
|
||||
Zone nextZone = zone;
|
||||
@@ -505,48 +423,6 @@ public class HeightMap {
|
||||
return realWorldAltitude;
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) {
|
||||
|
||||
Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z);
|
||||
|
||||
Vector2f gridSquare;
|
||||
|
||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
||||
return -1;
|
||||
|
||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
||||
return -1;
|
||||
|
||||
//flip the Y so it grabs from the bottom left instead of top left.
|
||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
||||
|
||||
gridSquare = getGridSquare(zoneLoc);
|
||||
|
||||
int gridX = (int) gridSquare.x;
|
||||
int gridY = (int) (gridSquare.y);
|
||||
|
||||
float offsetX = (gridSquare.x - gridX);
|
||||
float offsetY = gridSquare.y - gridY;
|
||||
|
||||
//get height of the 4 vertices.
|
||||
|
||||
float topLeftHeight = pixelColorValues[gridX][gridY];
|
||||
float topRightHeight = pixelColorValues[gridX + 1][gridY];
|
||||
float bottomLeftHeight = pixelColorValues[gridX][gridY + 1];
|
||||
float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1];
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
||||
|
||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
||||
|
||||
return interpolatedHeight;
|
||||
}
|
||||
|
||||
public static float getOutsetHeight(float interpolatedAltitude, Zone zone, Vector3fImmutable worldLocation) {
|
||||
|
||||
Vector2f parentLoc;
|
||||
@@ -620,6 +496,170 @@ public class HeightMap {
|
||||
return outsetALt;
|
||||
}
|
||||
|
||||
public static Vector2f getGridOffset(Vector2f gridSquare) {
|
||||
|
||||
int floorX = (int) gridSquare.x;
|
||||
int floorY = (int) gridSquare.y;
|
||||
|
||||
return new Vector2f(gridSquare.x - floorX, gridSquare.y - floorY);
|
||||
|
||||
}
|
||||
|
||||
public static void loadAlHeightMaps() {
|
||||
|
||||
// Load the heightmaps into staging hashmap keyed by HashMapID
|
||||
|
||||
DbManager.HeightMapQueries.LOAD_ALL_HEIGHTMAPS();
|
||||
|
||||
//generate static player city heightmap.
|
||||
|
||||
HeightMap.GeneratePlayerCityHeightMap();
|
||||
|
||||
|
||||
// Clear all heightmap image data as it's no longer needed.
|
||||
|
||||
for (HeightMap heightMap : HeightMap.heightmapByLoadNum.values()) {
|
||||
heightMap.heightmapImage = null;
|
||||
}
|
||||
|
||||
Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached.");
|
||||
}
|
||||
|
||||
public static boolean isLocUnderwater(Vector3fImmutable currentLoc) {
|
||||
|
||||
float localAltitude = HeightMap.getWorldHeight(currentLoc);
|
||||
Zone zone = ZoneManager.findSmallestZone(currentLoc);
|
||||
|
||||
if (localAltitude < zone.getSeaLevel())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Vector2f getGridSquare(Vector2f zoneLoc) {
|
||||
|
||||
if (zoneLoc.x < 0)
|
||||
zoneLoc.setX(0);
|
||||
|
||||
if (zoneLoc.x > this.fullExtentsX - 1)
|
||||
zoneLoc.setX((this.fullExtentsX - 1) + .9999999f);
|
||||
|
||||
if (zoneLoc.y < 0)
|
||||
zoneLoc.setY(0);
|
||||
|
||||
if (zoneLoc.y > this.fullExtentsY - 1)
|
||||
zoneLoc.setY((this.fullExtentsY - 1) + .9999999f);
|
||||
|
||||
float xBucket = (zoneLoc.x / this.bucketWidthX);
|
||||
float yBucket = (zoneLoc.y / this.bucketWidthY);
|
||||
|
||||
return new Vector2f(xBucket, yBucket);
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector2f zoneLoc) {
|
||||
|
||||
Vector2f gridSquare;
|
||||
|
||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
||||
return -1;
|
||||
|
||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
||||
return -1;
|
||||
|
||||
int maxX = (int) (this.fullExtentsX / this.bucketWidthX);
|
||||
int maxY = (int) (this.fullExtentsY / this.bucketWidthY);
|
||||
|
||||
//flip the Y so it grabs from the bottom left instead of top left.
|
||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
||||
|
||||
gridSquare = getGridSquare(zoneLoc);
|
||||
|
||||
int gridX = (int) gridSquare.x;
|
||||
int gridY = (int) (gridSquare.y);
|
||||
|
||||
if (gridX > maxX)
|
||||
gridX = maxX;
|
||||
if (gridY > maxY)
|
||||
gridY = maxY;
|
||||
|
||||
float offsetX = (gridSquare.x - gridX);
|
||||
float offsetY = gridSquare.y - gridY;
|
||||
|
||||
//get height of the 4 vertices.
|
||||
|
||||
float topLeftHeight = 0;
|
||||
float topRightHeight = 0;
|
||||
float bottomLeftHeight = 0;
|
||||
float bottomRightHeight = 0;
|
||||
|
||||
int nextY = gridY + 1;
|
||||
int nextX = gridX + 1;
|
||||
|
||||
if (nextY > maxY)
|
||||
nextY = gridY;
|
||||
|
||||
if (nextX > maxX)
|
||||
nextX = gridX;
|
||||
|
||||
topLeftHeight = pixelColorValues[gridX][gridY];
|
||||
topRightHeight = pixelColorValues[nextX][gridY];
|
||||
bottomLeftHeight = pixelColorValues[gridX][nextY];
|
||||
bottomRightHeight = pixelColorValues[nextX][nextY];
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
||||
|
||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
||||
|
||||
return interpolatedHeight;
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) {
|
||||
|
||||
Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z);
|
||||
|
||||
Vector2f gridSquare;
|
||||
|
||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
||||
return -1;
|
||||
|
||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
||||
return -1;
|
||||
|
||||
//flip the Y so it grabs from the bottom left instead of top left.
|
||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
||||
|
||||
gridSquare = getGridSquare(zoneLoc);
|
||||
|
||||
int gridX = (int) gridSquare.x;
|
||||
int gridY = (int) (gridSquare.y);
|
||||
|
||||
float offsetX = (gridSquare.x - gridX);
|
||||
float offsetY = gridSquare.y - gridY;
|
||||
|
||||
//get height of the 4 vertices.
|
||||
|
||||
float topLeftHeight = pixelColorValues[gridX][gridY];
|
||||
float topRightHeight = pixelColorValues[gridX + 1][gridY];
|
||||
float bottomLeftHeight = pixelColorValues[gridX][gridY + 1];
|
||||
float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1];
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
||||
|
||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
||||
|
||||
return interpolatedHeight;
|
||||
}
|
||||
|
||||
private void generatePixelData() {
|
||||
|
||||
Color color;
|
||||
@@ -638,40 +678,11 @@ public class HeightMap {
|
||||
|
||||
}
|
||||
|
||||
public static Vector2f getGridOffset(Vector2f gridSquare) {
|
||||
|
||||
int floorX = (int) gridSquare.x;
|
||||
int floorY = (int) gridSquare.y;
|
||||
|
||||
return new Vector2f(gridSquare.x - floorX, gridSquare.y - floorY);
|
||||
|
||||
}
|
||||
|
||||
public float getScaledHeightForColor(float color) {
|
||||
|
||||
return (color / 256) * this.maxHeight;
|
||||
}
|
||||
|
||||
public static void loadAlHeightMaps() {
|
||||
|
||||
// Load the heightmaps into staging hashmap keyed by HashMapID
|
||||
|
||||
DbManager.HeightMapQueries.LOAD_ALL_HEIGHTMAPS();
|
||||
|
||||
//generate static player city heightmap.
|
||||
|
||||
HeightMap.GeneratePlayerCityHeightMap();
|
||||
|
||||
|
||||
// Clear all heightmap image data as it's no longer needed.
|
||||
|
||||
for (HeightMap heightMap : HeightMap.heightmapByLoadNum.values()) {
|
||||
heightMap.heightmapImage = null;
|
||||
}
|
||||
|
||||
Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached.");
|
||||
}
|
||||
|
||||
public float getBucketWidthX() {
|
||||
return bucketWidthX;
|
||||
}
|
||||
@@ -692,15 +703,4 @@ public class HeightMap {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public static boolean isLocUnderwater(Vector3fImmutable currentLoc) {
|
||||
|
||||
float localAltitude = HeightMap.getWorldHeight(currentLoc);
|
||||
Zone zone = ZoneManager.findSmallestZone(currentLoc);
|
||||
|
||||
if (localAltitude < zone.getSeaLevel())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,14 +38,128 @@ public enum InterestManager implements Runnable {
|
||||
private static long lastTime;
|
||||
private static boolean keepGoing = true;
|
||||
|
||||
public void shutdown() {
|
||||
this.keepGoing = false;
|
||||
}
|
||||
|
||||
InterestManager() {
|
||||
Logger.info(" Interest Management thread is running.");
|
||||
}
|
||||
|
||||
public static void forceLoad(AbstractWorldObject awo) {
|
||||
|
||||
AbstractNetMsg msg = null;
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
NPC npc;
|
||||
Corpse corpse;
|
||||
HashSet<AbstractWorldObject> toUpdate;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
msg = lsm;
|
||||
break;
|
||||
case Corpse:
|
||||
corpse = (Corpse) awo;
|
||||
lcm = new LoadCharacterMsg(corpse, false);
|
||||
msg = lcm;
|
||||
break;
|
||||
case NPC:
|
||||
npc = (NPC) awo;
|
||||
lcm = new LoadCharacterMsg(npc, false);
|
||||
msg = lcm;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
toUpdate = WorldGrid.getObjectsInRangePartial(awo.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER);
|
||||
|
||||
boolean send;
|
||||
|
||||
for (AbstractWorldObject tar : toUpdate) {
|
||||
PlayerCharacter player = (PlayerCharacter) tar;
|
||||
HashSet<AbstractWorldObject> loadedStaticObjects = player.getLoadedStaticObjects();
|
||||
send = false;
|
||||
|
||||
if (!loadedStaticObjects.contains(awo)) {
|
||||
loadedStaticObjects.add(awo);
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (send) {
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleSpecialUnload(Building building, ClientConnection origin) {
|
||||
|
||||
if (Regions.FurnitureRegionMap.get(building.getObjectUUID()) == null)
|
||||
return;
|
||||
|
||||
Regions buildingRegion = Regions.FurnitureRegionMap.get(building.getObjectUUID());
|
||||
|
||||
if (!buildingRegion.isOutside())
|
||||
return;
|
||||
|
||||
MoveToPointMsg moveMsg = new MoveToPointMsg(building);
|
||||
|
||||
if (origin != null)
|
||||
origin.sendMsg(moveMsg);
|
||||
}
|
||||
|
||||
public static void reloadCharacter(AbstractCharacter absChar) {
|
||||
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(absChar);
|
||||
LoadCharacterMsg lcm = new LoadCharacterMsg(absChar, false);
|
||||
|
||||
HashSet<AbstractWorldObject> toSend = WorldGrid.getObjectsInRangePartial(absChar.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE,
|
||||
MBServerStatics.MASK_PLAYER);
|
||||
|
||||
PlayerCharacter pc = null;
|
||||
|
||||
if (absChar.getObjectType().equals(GameObjectType.PlayerCharacter))
|
||||
pc = (PlayerCharacter) absChar;
|
||||
|
||||
for (AbstractWorldObject awo : toSend) {
|
||||
|
||||
PlayerCharacter pcc = (PlayerCharacter) awo;
|
||||
|
||||
if (pcc == null)
|
||||
continue;
|
||||
|
||||
ClientConnection cc = SessionManager.getClientConnection(pcc);
|
||||
|
||||
if (cc == null)
|
||||
continue;
|
||||
|
||||
if (pcc.getObjectUUID() == absChar.getObjectUUID())
|
||||
continue;
|
||||
|
||||
else {
|
||||
if (pc != null)
|
||||
if (pcc.getSeeInvis() < pc.getHidden())
|
||||
continue;
|
||||
|
||||
if (!cc.sendMsg(uom)) {
|
||||
String classType = uom.getClass().getSimpleName();
|
||||
Logger.error("Failed to send message ");
|
||||
}
|
||||
|
||||
if (!cc.sendMsg(lcm)) {
|
||||
String classType = lcm.getClass().getSimpleName();
|
||||
Logger.error("Failed to send message");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.keepGoing = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
beginLoadJob();
|
||||
@@ -84,6 +198,9 @@ public enum InterestManager implements Runnable {
|
||||
return dur;
|
||||
}
|
||||
|
||||
// Forces the loading of static objects (corpses and buildings).
|
||||
// Needed to override threshold limits on loading statics
|
||||
|
||||
private void updateAllPlayers() {
|
||||
// get all players
|
||||
|
||||
@@ -341,7 +458,7 @@ public enum InterestManager implements Runnable {
|
||||
|
||||
awonpc.playerAgroMap.put(player.getObjectUUID(), false);
|
||||
//MobileFSM.setAwake(awonpc, false);
|
||||
((Mob)awonpc).setCombatTarget(null);
|
||||
((Mob) awonpc).setCombatTarget(null);
|
||||
// IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000));
|
||||
// awonpc.enableIntelligence();
|
||||
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
|
||||
@@ -358,7 +475,7 @@ public enum InterestManager implements Runnable {
|
||||
|
||||
if (awonpc.isMob())
|
||||
//MobileFSM.setAwake(awonpc, false);
|
||||
((Mob)awonpc).setCombatTarget(null);
|
||||
((Mob) awonpc).setCombatTarget(null);
|
||||
// IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000));
|
||||
// awonpc.enableIntelligence();
|
||||
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
|
||||
@@ -385,76 +502,6 @@ public enum InterestManager implements Runnable {
|
||||
//JobScheduler.getInstance().scheduleJob(new LoadEffectsJob(players, origin), MBServerStatics.LOAD_OBJECT_DELAY);
|
||||
}
|
||||
|
||||
// Forces the loading of static objects (corpses and buildings).
|
||||
// Needed to override threshold limits on loading statics
|
||||
|
||||
public static void forceLoad(AbstractWorldObject awo) {
|
||||
|
||||
AbstractNetMsg msg = null;
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
NPC npc;
|
||||
Corpse corpse;
|
||||
HashSet<AbstractWorldObject> toUpdate;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
msg = lsm;
|
||||
break;
|
||||
case Corpse:
|
||||
corpse = (Corpse) awo;
|
||||
lcm = new LoadCharacterMsg(corpse, false);
|
||||
msg = lcm;
|
||||
break;
|
||||
case NPC:
|
||||
npc = (NPC) awo;
|
||||
lcm = new LoadCharacterMsg(npc, false);
|
||||
msg = lcm;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
toUpdate = WorldGrid.getObjectsInRangePartial(awo.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER);
|
||||
|
||||
boolean send;
|
||||
|
||||
for (AbstractWorldObject tar : toUpdate) {
|
||||
PlayerCharacter player = (PlayerCharacter) tar;
|
||||
HashSet<AbstractWorldObject> loadedStaticObjects = player.getLoadedStaticObjects();
|
||||
send = false;
|
||||
|
||||
if (!loadedStaticObjects.contains(awo)) {
|
||||
loadedStaticObjects.add(awo);
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (send) {
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleSpecialUnload(Building building, ClientConnection origin) {
|
||||
|
||||
if (Regions.FurnitureRegionMap.get(building.getObjectUUID()) == null)
|
||||
return;
|
||||
|
||||
Regions buildingRegion = Regions.FurnitureRegionMap.get(building.getObjectUUID());
|
||||
|
||||
if (!buildingRegion.isOutside())
|
||||
return;
|
||||
|
||||
MoveToPointMsg moveMsg = new MoveToPointMsg(building);
|
||||
|
||||
if (origin != null)
|
||||
origin.sendMsg(moveMsg);
|
||||
}
|
||||
|
||||
public synchronized void HandleLoadForEnterWorld(PlayerCharacter player) {
|
||||
|
||||
if (player == null)
|
||||
@@ -504,51 +551,4 @@ public enum InterestManager implements Runnable {
|
||||
Logger.error("InterestManager.updateAllMobilePlayers: " + player.getObjectUUID(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadCharacter(AbstractCharacter absChar) {
|
||||
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(absChar);
|
||||
LoadCharacterMsg lcm = new LoadCharacterMsg(absChar, false);
|
||||
|
||||
HashSet<AbstractWorldObject> toSend = WorldGrid.getObjectsInRangePartial(absChar.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE,
|
||||
MBServerStatics.MASK_PLAYER);
|
||||
|
||||
PlayerCharacter pc = null;
|
||||
|
||||
if (absChar.getObjectType().equals(GameObjectType.PlayerCharacter))
|
||||
pc = (PlayerCharacter) absChar;
|
||||
|
||||
for (AbstractWorldObject awo : toSend) {
|
||||
|
||||
PlayerCharacter pcc = (PlayerCharacter) awo;
|
||||
|
||||
if (pcc == null)
|
||||
continue;
|
||||
|
||||
ClientConnection cc = SessionManager.getClientConnection(pcc);
|
||||
|
||||
if (cc == null)
|
||||
continue;
|
||||
|
||||
if (pcc.getObjectUUID() == absChar.getObjectUUID())
|
||||
continue;
|
||||
|
||||
else {
|
||||
if (pc != null)
|
||||
if (pcc.getSeeInvis() < pc.getHidden())
|
||||
continue;
|
||||
|
||||
if (!cc.sendMsg(uom)) {
|
||||
String classType = uom.getClass().getSimpleName();
|
||||
Logger.error("Failed to send message ");
|
||||
}
|
||||
|
||||
if (!cc.sendMsg(lcm)) {
|
||||
String classType = lcm.getClass().getSimpleName();
|
||||
Logger.error("Failed to send message");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,8 @@ public enum RealmMap {
|
||||
// Spatial hashmap. Used for determining which Realm
|
||||
// a player is currently located within.
|
||||
|
||||
public static int[][] _realmImageMap;
|
||||
private static final HashMap<Color, Integer> _rgbToIDMap = new HashMap<>();
|
||||
public static int[][] _realmImageMap;
|
||||
|
||||
public static int getRealmIDByColor(Color color) {
|
||||
|
||||
|
||||
@@ -25,177 +25,177 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
public class WorldGrid {
|
||||
|
||||
public static ConcurrentHashMap<Integer,AbstractWorldObject>[][] DynamicGridMap;
|
||||
public static ConcurrentHashMap<Integer,AbstractWorldObject>[][] StaticGridMap;
|
||||
private static float dynamicBucketScale = 0.00390625f; // 256 bucket size, 1/256
|
||||
private static float staticBucketScale = 0.00390625f;
|
||||
public static void startLoadJob() {
|
||||
|
||||
Thread loadJobThread;
|
||||
|
||||
|
||||
loadJobThread = new Thread(InterestManager.INTERESTMANAGER);
|
||||
loadJobThread.setName("InterestManager");
|
||||
loadJobThread.start();
|
||||
}
|
||||
public static ConcurrentHashMap<Integer, AbstractWorldObject>[][] DynamicGridMap;
|
||||
public static ConcurrentHashMap<Integer, AbstractWorldObject>[][] StaticGridMap;
|
||||
private static float dynamicBucketScale = 0.00390625f; // 256 bucket size, 1/256
|
||||
private static float staticBucketScale = 0.00390625f;
|
||||
|
||||
public static boolean moveWorldObject(AbstractWorldObject awo, Vector3fImmutable location) {
|
||||
awo.setLoc(location);
|
||||
return true;
|
||||
}
|
||||
public static void startLoadJob() {
|
||||
|
||||
public static HashSet<AbstractWorldObject> getInRange(Vector3f loc, double r) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
return outbound;
|
||||
}
|
||||
Thread loadJobThread;
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartial(Vector3fImmutable loc, double r, int mask) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
float scale;
|
||||
|
||||
if ((mask & MBServerStatics.MASK_STATIC) != 0)
|
||||
scale = WorldGrid.staticBucketScale;
|
||||
else
|
||||
scale = WorldGrid.dynamicBucketScale;
|
||||
int gridX = (int) Math.abs(loc.x * scale);
|
||||
int gridZ = (int)Math.abs(loc.z * scale);
|
||||
int bucketSize = (int) (r *scale) + 1;
|
||||
//start at top left most corner to scan.
|
||||
int startingX = gridX - bucketSize;
|
||||
int startingZ = gridZ + bucketSize;
|
||||
|
||||
|
||||
|
||||
int limitX = Math.abs((int) (MBServerStatics.MAX_WORLD_WIDTH *scale));
|
||||
int limitZ = Math.abs((int) (MBServerStatics.MAX_WORLD_HEIGHT *scale)); //LimitZ is negative, remember to flip sign.
|
||||
|
||||
if (startingX < 0)
|
||||
startingX = 0;
|
||||
|
||||
if (startingZ < 0)
|
||||
startingZ = 0;
|
||||
|
||||
if (startingX > limitX)
|
||||
startingX = limitX;
|
||||
|
||||
if (startingZ > limitZ)
|
||||
startingZ = limitZ;
|
||||
|
||||
int endX = startingX + (bucketSize * 2);
|
||||
int endZ = startingZ - (bucketSize * 2);
|
||||
|
||||
if (endX < 0)
|
||||
endX = 0;
|
||||
|
||||
if (endZ < 0)
|
||||
endZ = 0;
|
||||
|
||||
if (endX > limitX)
|
||||
endX = limitX;
|
||||
|
||||
if (endZ > limitZ)
|
||||
endZ = limitZ;
|
||||
|
||||
int auditMob = 0;
|
||||
for (int x = startingX;x<=endX;x++){
|
||||
for (int z = startingZ;z >= endZ;z--){
|
||||
|
||||
ConcurrentHashMap<Integer,AbstractWorldObject> gridMap;
|
||||
|
||||
if ((MBServerStatics.MASK_STATIC & mask) != 0)
|
||||
gridMap = WorldGrid.StaticGridMap[x][z];
|
||||
else
|
||||
gridMap = WorldGrid.DynamicGridMap[x][z];
|
||||
for (AbstractWorldObject gridObject: gridMap.values()){
|
||||
if ((gridObject.getObjectTypeMask() & mask) == 0)
|
||||
continue;
|
||||
if (gridObject.getLoc().distanceSquared2D(loc) <= FastMath.sqr(r))
|
||||
outbound.add(gridObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartialNecroPets(Vector3fImmutable loc, double r) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
return outbound;
|
||||
}
|
||||
loadJobThread = new Thread(InterestManager.INTERESTMANAGER);
|
||||
loadJobThread.setName("InterestManager");
|
||||
loadJobThread.start();
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangeContains(Vector3fImmutable loc, double r, int mask) {
|
||||
HashSet<AbstractWorldObject> outbound = getObjectsInRangePartial(loc,r,mask);
|
||||
return outbound;
|
||||
}
|
||||
public static boolean moveWorldObject(AbstractWorldObject awo, Vector3fImmutable location) {
|
||||
awo.setLoc(location);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartial(AbstractWorldObject awo, double range, int mask) {
|
||||
return getObjectsInRangePartial(awo.getLoc(), range, mask);
|
||||
}
|
||||
public static HashSet<AbstractWorldObject> getInRange(Vector3f loc, double r) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
return outbound;
|
||||
}
|
||||
|
||||
|
||||
public static void InitializeGridObjects(){
|
||||
|
||||
int dynamicWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH *WorldGrid.dynamicBucketScale);
|
||||
int dynamicHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT*WorldGrid.dynamicBucketScale);
|
||||
|
||||
int staticWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH *WorldGrid.staticBucketScale);
|
||||
int staticHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT*WorldGrid.staticBucketScale);
|
||||
WorldGrid.DynamicGridMap = new ConcurrentHashMap[dynamicWidth+ 1][dynamicHeight + 1];
|
||||
WorldGrid.StaticGridMap = new ConcurrentHashMap[staticWidth + 1][staticHeight + 1];
|
||||
//create new hash maps for each bucket
|
||||
for (int x = 0; x<= staticWidth; x++)
|
||||
for (int y = 0; y<= staticHeight; y++){
|
||||
WorldGrid.StaticGridMap[x][y] = new ConcurrentHashMap<Integer,AbstractWorldObject>();
|
||||
}
|
||||
|
||||
for (int x = 0; x<= dynamicWidth; x++)
|
||||
for (int y = 0; y<= dynamicHeight; y++){
|
||||
WorldGrid.DynamicGridMap[x][y] = new ConcurrentHashMap<Integer,AbstractWorldObject>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void RemoveWorldObject(AbstractWorldObject gridObject){
|
||||
|
||||
if (gridObject == null)
|
||||
return;
|
||||
AbstractWorldObject.RemoveFromWorldGrid(gridObject);
|
||||
}
|
||||
|
||||
public static boolean addObject(AbstractWorldObject gridObject, float x, float z){
|
||||
|
||||
if (gridObject == null)
|
||||
return false;
|
||||
|
||||
if (x > MBServerStatics.MAX_WORLD_WIDTH)
|
||||
return false;
|
||||
|
||||
if (z < MBServerStatics.MAX_WORLD_HEIGHT)
|
||||
return false;
|
||||
|
||||
if (x < 0)
|
||||
return false;
|
||||
if (z > 0)
|
||||
return false;
|
||||
|
||||
int gridX;
|
||||
int gridZ;
|
||||
|
||||
if (gridObject.getGridObjectType().equals(GridObjectType.STATIC)){
|
||||
gridX = Math.abs((int) (x *WorldGrid.staticBucketScale));
|
||||
gridZ = Math.abs((int) (z*WorldGrid.staticBucketScale));
|
||||
}else{
|
||||
gridX = Math.abs((int) (x *WorldGrid.dynamicBucketScale));
|
||||
gridZ = Math.abs((int) (z*WorldGrid.dynamicBucketScale));
|
||||
}
|
||||
|
||||
|
||||
WorldGrid.RemoveWorldObject(gridObject);
|
||||
|
||||
return AbstractWorldObject.AddToWorldGrid(gridObject, gridX, gridZ);
|
||||
|
||||
|
||||
}
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartial(Vector3fImmutable loc, double r, int mask) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
float scale;
|
||||
|
||||
if ((mask & MBServerStatics.MASK_STATIC) != 0)
|
||||
scale = WorldGrid.staticBucketScale;
|
||||
else
|
||||
scale = WorldGrid.dynamicBucketScale;
|
||||
int gridX = (int) Math.abs(loc.x * scale);
|
||||
int gridZ = (int) Math.abs(loc.z * scale);
|
||||
int bucketSize = (int) (r * scale) + 1;
|
||||
//start at top left most corner to scan.
|
||||
int startingX = gridX - bucketSize;
|
||||
int startingZ = gridZ + bucketSize;
|
||||
|
||||
|
||||
int limitX = Math.abs((int) (MBServerStatics.MAX_WORLD_WIDTH * scale));
|
||||
int limitZ = Math.abs((int) (MBServerStatics.MAX_WORLD_HEIGHT * scale)); //LimitZ is negative, remember to flip sign.
|
||||
|
||||
if (startingX < 0)
|
||||
startingX = 0;
|
||||
|
||||
if (startingZ < 0)
|
||||
startingZ = 0;
|
||||
|
||||
if (startingX > limitX)
|
||||
startingX = limitX;
|
||||
|
||||
if (startingZ > limitZ)
|
||||
startingZ = limitZ;
|
||||
|
||||
int endX = startingX + (bucketSize * 2);
|
||||
int endZ = startingZ - (bucketSize * 2);
|
||||
|
||||
if (endX < 0)
|
||||
endX = 0;
|
||||
|
||||
if (endZ < 0)
|
||||
endZ = 0;
|
||||
|
||||
if (endX > limitX)
|
||||
endX = limitX;
|
||||
|
||||
if (endZ > limitZ)
|
||||
endZ = limitZ;
|
||||
|
||||
int auditMob = 0;
|
||||
for (int x = startingX; x <= endX; x++) {
|
||||
for (int z = startingZ; z >= endZ; z--) {
|
||||
|
||||
ConcurrentHashMap<Integer, AbstractWorldObject> gridMap;
|
||||
|
||||
if ((MBServerStatics.MASK_STATIC & mask) != 0)
|
||||
gridMap = WorldGrid.StaticGridMap[x][z];
|
||||
else
|
||||
gridMap = WorldGrid.DynamicGridMap[x][z];
|
||||
for (AbstractWorldObject gridObject : gridMap.values()) {
|
||||
if ((gridObject.getObjectTypeMask() & mask) == 0)
|
||||
continue;
|
||||
if (gridObject.getLoc().distanceSquared2D(loc) <= FastMath.sqr(r))
|
||||
outbound.add(gridObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartialNecroPets(Vector3fImmutable loc, double r) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangeContains(Vector3fImmutable loc, double r, int mask) {
|
||||
HashSet<AbstractWorldObject> outbound = getObjectsInRangePartial(loc, r, mask);
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartial(AbstractWorldObject awo, double range, int mask) {
|
||||
return getObjectsInRangePartial(awo.getLoc(), range, mask);
|
||||
}
|
||||
|
||||
|
||||
public static void InitializeGridObjects() {
|
||||
|
||||
int dynamicWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH * WorldGrid.dynamicBucketScale);
|
||||
int dynamicHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT * WorldGrid.dynamicBucketScale);
|
||||
|
||||
int staticWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH * WorldGrid.staticBucketScale);
|
||||
int staticHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT * WorldGrid.staticBucketScale);
|
||||
WorldGrid.DynamicGridMap = new ConcurrentHashMap[dynamicWidth + 1][dynamicHeight + 1];
|
||||
WorldGrid.StaticGridMap = new ConcurrentHashMap[staticWidth + 1][staticHeight + 1];
|
||||
//create new hash maps for each bucket
|
||||
for (int x = 0; x <= staticWidth; x++)
|
||||
for (int y = 0; y <= staticHeight; y++) {
|
||||
WorldGrid.StaticGridMap[x][y] = new ConcurrentHashMap<Integer, AbstractWorldObject>();
|
||||
}
|
||||
|
||||
for (int x = 0; x <= dynamicWidth; x++)
|
||||
for (int y = 0; y <= dynamicHeight; y++) {
|
||||
WorldGrid.DynamicGridMap[x][y] = new ConcurrentHashMap<Integer, AbstractWorldObject>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void RemoveWorldObject(AbstractWorldObject gridObject) {
|
||||
|
||||
if (gridObject == null)
|
||||
return;
|
||||
AbstractWorldObject.RemoveFromWorldGrid(gridObject);
|
||||
}
|
||||
|
||||
public static boolean addObject(AbstractWorldObject gridObject, float x, float z) {
|
||||
|
||||
if (gridObject == null)
|
||||
return false;
|
||||
|
||||
if (x > MBServerStatics.MAX_WORLD_WIDTH)
|
||||
return false;
|
||||
|
||||
if (z < MBServerStatics.MAX_WORLD_HEIGHT)
|
||||
return false;
|
||||
|
||||
if (x < 0)
|
||||
return false;
|
||||
if (z > 0)
|
||||
return false;
|
||||
|
||||
int gridX;
|
||||
int gridZ;
|
||||
|
||||
if (gridObject.getGridObjectType().equals(GridObjectType.STATIC)) {
|
||||
gridX = Math.abs((int) (x * WorldGrid.staticBucketScale));
|
||||
gridZ = Math.abs((int) (z * WorldGrid.staticBucketScale));
|
||||
} else {
|
||||
gridX = Math.abs((int) (x * WorldGrid.dynamicBucketScale));
|
||||
gridZ = Math.abs((int) (z * WorldGrid.dynamicBucketScale));
|
||||
}
|
||||
|
||||
|
||||
WorldGrid.RemoveWorldObject(gridObject);
|
||||
|
||||
return AbstractWorldObject.AddToWorldGrid(gridObject, gridX, gridZ);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void unloadObject(AbstractWorldObject awo) {
|
||||
|
||||
@@ -204,109 +204,109 @@ public class WorldGrid {
|
||||
DispatchMessage.sendToAllInRange(awo, uom);
|
||||
}
|
||||
|
||||
public static void loadObject(AbstractWorldObject awo) {
|
||||
public static void loadObject(AbstractWorldObject awo) {
|
||||
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building)awo);
|
||||
DispatchMessage.sendToAllInRange(awo, lsm);
|
||||
break;
|
||||
case NPC:
|
||||
lcm = new LoadCharacterMsg((NPC) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case Mob:
|
||||
lcm = new LoadCharacterMsg((Mob) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
default:
|
||||
// *** Refactor: Log error?
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (awo.getObjectType()) {
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
DispatchMessage.sendToAllInRange(awo, lsm);
|
||||
break;
|
||||
case NPC:
|
||||
lcm = new LoadCharacterMsg((NPC) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case Mob:
|
||||
lcm = new LoadCharacterMsg((Mob) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
default:
|
||||
// *** Refactor: Log error?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadObject(AbstractWorldObject awo, ClientConnection origin) {
|
||||
public static void loadObject(AbstractWorldObject awo, ClientConnection origin) {
|
||||
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
switch (awo.getObjectType()) {
|
||||
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building)awo);
|
||||
DispatchMessage.sendToAllInRange(awo, lsm);
|
||||
break;
|
||||
case NPC:
|
||||
lcm = new LoadCharacterMsg((NPC) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case Mob:
|
||||
lcm = new LoadCharacterMsg((Mob) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case PlayerCharacter:
|
||||
lcm = new LoadCharacterMsg((PlayerCharacter) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
default:
|
||||
// *** Refactor: Log error?
|
||||
break;
|
||||
}
|
||||
}
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
DispatchMessage.sendToAllInRange(awo, lsm);
|
||||
break;
|
||||
case NPC:
|
||||
lcm = new LoadCharacterMsg((NPC) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case Mob:
|
||||
lcm = new LoadCharacterMsg((Mob) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case PlayerCharacter:
|
||||
lcm = new LoadCharacterMsg((PlayerCharacter) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
default:
|
||||
// *** Refactor: Log error?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void unloadObject(AbstractWorldObject awo,
|
||||
ClientConnection origin) {
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(awo);
|
||||
DispatchMessage.sendToAllInRange(awo, uom);
|
||||
}
|
||||
public static void unloadObject(AbstractWorldObject awo,
|
||||
ClientConnection origin) {
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(awo);
|
||||
DispatchMessage.sendToAllInRange(awo, uom);
|
||||
}
|
||||
|
||||
public static void addObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
loadObject(awo, origin);
|
||||
}
|
||||
public static void addObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
loadObject(awo, origin);
|
||||
}
|
||||
|
||||
public static void removeObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
unloadObject(awo, origin);
|
||||
}
|
||||
public static void removeObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
unloadObject(awo, origin);
|
||||
}
|
||||
|
||||
public static void updateObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
unloadObject(awo, origin);
|
||||
loadObject(awo, origin);
|
||||
}
|
||||
public static void updateObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
unloadObject(awo, origin);
|
||||
loadObject(awo, origin);
|
||||
}
|
||||
|
||||
public static void updateObject(AbstractWorldObject awo) {
|
||||
if (awo == null)
|
||||
return;
|
||||
unloadObject(awo);
|
||||
loadObject(awo);
|
||||
}
|
||||
public static void updateObject(AbstractWorldObject awo) {
|
||||
if (awo == null)
|
||||
return;
|
||||
unloadObject(awo);
|
||||
loadObject(awo);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static void removeObject(AbstractWorldObject awo) {
|
||||
if (awo == null)
|
||||
return;
|
||||
unloadObject(awo);
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static void removeObject(AbstractWorldObject awo) {
|
||||
if (awo == null)
|
||||
return;
|
||||
unloadObject(awo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
package engine.ai;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
@@ -22,12 +23,15 @@ import engine.objects.*;
|
||||
import engine.powers.ActionsBase;
|
||||
import engine.powers.PowersBase;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static engine.math.FastMath.sqr;
|
||||
|
||||
public class MobileFSM {
|
||||
private static void AttackTarget(Mob mob, AbstractWorldObject target) {
|
||||
if (mob == null)
|
||||
@@ -36,8 +40,8 @@ public class MobileFSM {
|
||||
mob.setCombatTarget(null);
|
||||
return;
|
||||
}
|
||||
if(target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)){
|
||||
if(MobCast(mob)){
|
||||
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) {
|
||||
if (MobCast(mob)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -58,8 +62,9 @@ public class MobileFSM {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AttackPlayer(Mob mob, PlayerCharacter target) {
|
||||
if(!mob.canSee(target)){
|
||||
if (!mob.canSee(target)) {
|
||||
mob.setCombatTarget(null);
|
||||
return;
|
||||
}
|
||||
@@ -100,6 +105,7 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AttackBuilding(Mob mob, Building target) {
|
||||
if (target.getRank() == -1 || !target.isVulnerable() || BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null) {
|
||||
mob.setCombatTarget(null);
|
||||
@@ -140,6 +146,7 @@ public class MobileFSM {
|
||||
DispatchMessage.dispatchMsgToInterestArea(mob, ppm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AttackMob(Mob mob, Mob target) {
|
||||
if (mob.getRange() >= 30 && mob.isMoving())
|
||||
return;
|
||||
@@ -166,6 +173,7 @@ public class MobileFSM {
|
||||
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Patrol(Mob mob) {
|
||||
//make sure mob is out of combat stance
|
||||
if (mob.isCombat() && mob.getCombatTarget() == null) {
|
||||
@@ -174,7 +182,7 @@ public class MobileFSM {
|
||||
rwss.setPlayer(mob);
|
||||
DispatchMessage.sendToAllInRange(mob, rwss);
|
||||
}
|
||||
int patrolDelay = ThreadLocalRandom.current().nextInt((int)(MobileFSMManager.AI_PATROL_DIVISOR * 0.5f), MobileFSMManager.AI_PATROL_DIVISOR) + MobileFSMManager.AI_PATROL_DIVISOR;
|
||||
int patrolDelay = ThreadLocalRandom.current().nextInt((int) (MobileFSMManager.AI_PATROL_DIVISOR * 0.5f), MobileFSMManager.AI_PATROL_DIVISOR) + MobileFSMManager.AI_PATROL_DIVISOR;
|
||||
if (mob.stopPatrolTime + (patrolDelay * 1000) > System.currentTimeMillis())
|
||||
//early exit while waiting to patrol again
|
||||
return;
|
||||
@@ -183,18 +191,18 @@ public class MobileFSM {
|
||||
Building barracks = mob.building;
|
||||
if (barracks != null && barracks.patrolPoints != null && !barracks.getPatrolPoints().isEmpty()) {
|
||||
mob.patrolPoints = barracks.patrolPoints;
|
||||
} else{
|
||||
} else {
|
||||
randomGuardPatrolPoint(mob);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) {
|
||||
mob.lastPatrolPointIndex = 0;
|
||||
}
|
||||
if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) {
|
||||
mob.lastPatrolPointIndex = 0;
|
||||
}
|
||||
mob.destination = mob.patrolPoints.get(mob.lastPatrolPointIndex);
|
||||
mob.lastPatrolPointIndex += 1;
|
||||
MovementUtilities.aiMove(mob, mob.destination, true);
|
||||
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()){
|
||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
|
||||
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) {
|
||||
//make sure mob is out of combat stance
|
||||
if (minion.getKey().despawned == false) {
|
||||
@@ -214,6 +222,7 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canCast(Mob mob) {
|
||||
// Performs validation to determine if a
|
||||
// mobile in the proper state to cast.
|
||||
@@ -221,7 +230,7 @@ public class MobileFSM {
|
||||
return false;
|
||||
if (mob.mobPowers.isEmpty())
|
||||
return false;
|
||||
if(!mob.canSee((PlayerCharacter) mob.getCombatTarget())){
|
||||
if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) {
|
||||
mob.setCombatTarget(null);
|
||||
return false;
|
||||
}
|
||||
@@ -229,6 +238,7 @@ public class MobileFSM {
|
||||
mob.nextCastTime = System.currentTimeMillis();
|
||||
return mob.nextCastTime <= System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static boolean MobCast(Mob mob) {
|
||||
// Method picks a random spell from a mobile's list of powers
|
||||
// and casts it on the current target (or itself). Validation
|
||||
@@ -261,7 +271,7 @@ public class MobileFSM {
|
||||
int powerRank = mob.mobPowers.get(powerToken);
|
||||
PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
|
||||
//check for hit-roll
|
||||
if(mobPower.requiresHitRoll) {
|
||||
if (mobPower.requiresHitRoll) {
|
||||
if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget())) {
|
||||
return false;
|
||||
}
|
||||
@@ -286,11 +296,12 @@ public class MobileFSM {
|
||||
msg.setUnknown04(2);
|
||||
PowersManager.finishUseMobPower(msg, mob, 0, 0);
|
||||
// Default minimum seconds between cast = 10
|
||||
mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000);
|
||||
mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void MobCallForHelp(Mob mob) {
|
||||
boolean callGotResponse = false;
|
||||
if (mob.nextCallForHelp == 0) {
|
||||
@@ -311,6 +322,7 @@ public class MobileFSM {
|
||||
//wait 60 seconds to call for help again
|
||||
mob.nextCallForHelp = System.currentTimeMillis() + 60000;
|
||||
}
|
||||
|
||||
public static void DetermineAction(Mob mob) {
|
||||
if (mob == null)
|
||||
return;
|
||||
@@ -321,10 +333,10 @@ public class MobileFSM {
|
||||
}
|
||||
if (mob.despawned && mob.isPlayerGuard) {
|
||||
//override for guards
|
||||
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()){
|
||||
if(mob.npcOwner.isAlive() == false || ((Mob)mob.npcOwner).despawned == true){
|
||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) {
|
||||
if (mob.npcOwner.isAlive() == false || ((Mob) mob.npcOwner).despawned == true) {
|
||||
//minions don't respawn while guard captain is dead
|
||||
if(mob.isAlive() == false) {
|
||||
if (mob.isAlive() == false) {
|
||||
mob.deathTime = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
@@ -351,7 +363,7 @@ public class MobileFSM {
|
||||
}
|
||||
mob.updateLocation();
|
||||
CheckToSendMobHome(mob);
|
||||
if(mob.combatTarget != null && mob.combatTarget.isAlive() == false){
|
||||
if (mob.combatTarget != null && mob.combatTarget.isAlive() == false) {
|
||||
mob.setCombatTarget(null);
|
||||
}
|
||||
switch (mob.BehaviourType) {
|
||||
@@ -375,6 +387,7 @@ public class MobileFSM {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckForAggro(Mob aiAgent) {
|
||||
//looks for and sets mobs combatTarget
|
||||
if (!aiAgent.isAlive())
|
||||
@@ -405,10 +418,11 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckMobMovement(Mob mob) {
|
||||
if (!MovementUtilities.canMove(mob))
|
||||
return;
|
||||
switch(mob.BehaviourType){
|
||||
switch (mob.BehaviourType) {
|
||||
case Pet1:
|
||||
if (!mob.playerAgroMap.containsKey(mob.getOwner().getObjectUUID())) {
|
||||
//mob no longer has its owner loaded, translocate pet to owner
|
||||
@@ -425,27 +439,28 @@ public class MobileFSM {
|
||||
chaseTarget(mob);
|
||||
break;
|
||||
case GuardMinion:
|
||||
if (!mob.npcOwner.isAlive() || ((Mob)mob.npcOwner).despawned)
|
||||
if (!mob.npcOwner.isAlive() || ((Mob) mob.npcOwner).despawned)
|
||||
randomGuardPatrolPoint(mob);
|
||||
else{
|
||||
if(mob.getCombatTarget() != null){
|
||||
else {
|
||||
if (mob.getCombatTarget() != null) {
|
||||
chaseTarget(mob);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (mob.getCombatTarget() == null) {
|
||||
if(!mob.isMoving()) {
|
||||
if (!mob.isMoving()) {
|
||||
Patrol(mob);
|
||||
} else{
|
||||
} else {
|
||||
mob.stopPatrolTime = System.currentTimeMillis();
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
chaseTarget(mob);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckForRespawn(Mob aiAgent) {
|
||||
if (aiAgent.deathTime == 0) {
|
||||
aiAgent.setDeathTime(System.currentTimeMillis());
|
||||
@@ -479,14 +494,15 @@ public class MobileFSM {
|
||||
aiAgent.respawn();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckForAttack(Mob mob) {
|
||||
//checks if mob can attack based on attack timer and range
|
||||
if (mob.isAlive() == false)
|
||||
return;
|
||||
if(mob.getCombatTarget() == null){
|
||||
if (mob.getCombatTarget() == null) {
|
||||
return;
|
||||
}
|
||||
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter)mob.getCombatTarget()) == false) {
|
||||
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) == false) {
|
||||
mob.setCombatTarget(null);
|
||||
if (mob.isCombat()) {
|
||||
mob.setCombat(false);
|
||||
@@ -505,18 +521,18 @@ public class MobileFSM {
|
||||
if (System.currentTimeMillis() > mob.getLastAttackTime())
|
||||
AttackTarget(mob, mob.getCombatTarget());
|
||||
}
|
||||
|
||||
private static void CheckToSendMobHome(Mob mob) {
|
||||
if(mob.BehaviourType.isAgressive) {
|
||||
if(mob.isPlayerGuard())
|
||||
{
|
||||
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()){
|
||||
if (mob.BehaviourType.isAgressive) {
|
||||
if (mob.isPlayerGuard()) {
|
||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
|
||||
CheckForPlayerGuardAggro(mob);
|
||||
}
|
||||
} else {
|
||||
CheckForAggro(mob);
|
||||
}
|
||||
}
|
||||
if(mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob,mob.getCombatTarget(), MobileFSMManager.AI_BASE_AGGRO_RANGE * 0.5f)){
|
||||
if (mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob, mob.getCombatTarget(), MobileFSMManager.AI_BASE_AGGRO_RANGE * 0.5f)) {
|
||||
return;
|
||||
}
|
||||
if (mob.isPlayerGuard() && !mob.despawned) {
|
||||
@@ -525,7 +541,7 @@ public class MobileFSM {
|
||||
PowersBase recall = PowersManager.getPowerByToken(-1994153779);
|
||||
PowersManager.useMobPower(mob, mob, recall, 40);
|
||||
mob.setCombatTarget(null);
|
||||
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal() && mob.isAlive()){
|
||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal() && mob.isAlive()) {
|
||||
//guard captain pulls his minions home with him
|
||||
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) {
|
||||
PowersManager.useMobPower(minion.getKey(), minion.getKey(), recall, 40);
|
||||
@@ -533,20 +549,20 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(MovementUtilities.inRangeOfBindLocation(mob) == false) {
|
||||
} else if (MovementUtilities.inRangeOfBindLocation(mob) == false) {
|
||||
|
||||
PowersBase recall = PowersManager.getPowerByToken(-1994153779);
|
||||
PowersManager.useMobPower(mob, mob, recall, 40);
|
||||
mob.setCombatTarget(null);
|
||||
for (Entry playerEntry : mob.playerAgroMap.entrySet()) {
|
||||
PlayerCharacter.getFromCache((int)playerEntry.getKey()).setHateValue(0);
|
||||
PlayerCharacter.getFromCache((int) playerEntry.getKey()).setHateValue(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void chaseTarget(Mob mob) {
|
||||
mob.updateMovementState();
|
||||
if(mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false){
|
||||
if (mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false) {
|
||||
mob.setCombatTarget(null);
|
||||
return;
|
||||
}
|
||||
@@ -560,6 +576,7 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SafeGuardAggro(Mob mob) {
|
||||
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(mob, 100, MBServerStatics.MASK_MOB);
|
||||
for (AbstractWorldObject awoMob : awoList) {
|
||||
@@ -575,49 +592,55 @@ public class MobileFSM {
|
||||
mob.setCombatTarget(aggroMob);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GuardCaptainLogic(Mob mob) {
|
||||
if (mob.getCombatTarget() == null)
|
||||
CheckForPlayerGuardAggro(mob);
|
||||
CheckMobMovement(mob);
|
||||
CheckForAttack(mob);
|
||||
}
|
||||
|
||||
public static void GuardMinionLogic(Mob mob) {
|
||||
if (!mob.npcOwner.isAlive() && mob.getCombatTarget() == null) {
|
||||
CheckForPlayerGuardAggro(mob);
|
||||
}
|
||||
if(mob.npcOwner.getCombatTarget() != null)
|
||||
if (mob.npcOwner.getCombatTarget() != null)
|
||||
mob.setCombatTarget(mob.npcOwner.getCombatTarget());
|
||||
else
|
||||
else
|
||||
mob.setCombatTarget(null);
|
||||
CheckMobMovement(mob);
|
||||
CheckForAttack(mob);
|
||||
}
|
||||
|
||||
public static void GuardWallArcherLogic(Mob mob) {
|
||||
if (mob.getCombatTarget() == null)
|
||||
CheckForPlayerGuardAggro(mob);
|
||||
else
|
||||
CheckForAttack(mob);
|
||||
}
|
||||
|
||||
private static void PetLogic(Mob mob) {
|
||||
if (mob.getCombatTarget() != null && !mob.getCombatTarget().isAlive())
|
||||
mob.setCombatTarget(null);
|
||||
if (MovementUtilities.canMove(mob) && mob.BehaviourType.canRoam)
|
||||
CheckMobMovement(mob);
|
||||
CheckForAttack(mob);
|
||||
CheckForAttack(mob);
|
||||
}
|
||||
|
||||
private static void HamletGuardLogic(Mob mob) {
|
||||
if (mob.getCombatTarget() == null) {
|
||||
//safehold guard
|
||||
SafeGuardAggro(mob);
|
||||
} else{
|
||||
if(mob.combatTarget.isAlive() == false){
|
||||
} else {
|
||||
if (mob.combatTarget.isAlive() == false) {
|
||||
SafeGuardAggro(mob);
|
||||
}
|
||||
}
|
||||
CheckForAttack(mob);
|
||||
CheckForAttack(mob);
|
||||
}
|
||||
|
||||
private static void DefaultLogic(Mob mob) {
|
||||
if(mob.getObjectUUID() == 40548){
|
||||
if (mob.getObjectUUID() == 40548) {
|
||||
int thing = 0;
|
||||
}
|
||||
//check for players that can be aggroed if mob is agressive and has no target
|
||||
@@ -643,6 +666,7 @@ public class MobileFSM {
|
||||
if (!mob.BehaviourType.isWimpy && !mob.isMoving() && mob.combatTarget != null)
|
||||
CheckForAttack(mob);
|
||||
}
|
||||
|
||||
public static void CheckForPlayerGuardAggro(Mob mob) {
|
||||
//looks for and sets mobs combatTarget
|
||||
if (!mob.isAlive())
|
||||
@@ -673,14 +697,15 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean GuardCanAggro(Mob mob, PlayerCharacter target) {
|
||||
if (mob.getGuild().getNation().equals(target.getGuild().getNation()))
|
||||
return false;
|
||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) {
|
||||
if(((Mob)mob.npcOwner).building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true){
|
||||
if (((Mob) mob.npcOwner).building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true) {
|
||||
return true;
|
||||
}
|
||||
} else if(mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true){
|
||||
} else if (mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true) {
|
||||
return true;
|
||||
}
|
||||
//first check condemn list for aggro allowed (allies button is checked)
|
||||
@@ -697,7 +722,7 @@ public class MobileFSM {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else{
|
||||
} else {
|
||||
//allies button is not checked
|
||||
for (Entry<Integer, Condemned> entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) {
|
||||
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
|
||||
@@ -713,7 +738,8 @@ public class MobileFSM {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static void randomGuardPatrolPoint(Mob mob){
|
||||
|
||||
public static void randomGuardPatrolPoint(Mob mob) {
|
||||
if (mob.isMoving() == true) {
|
||||
//early exit for a mob who is already moving to a patrol point
|
||||
//while mob moving, update lastPatrolTime so that when they stop moving the 10 second timer can begin
|
||||
@@ -728,9 +754,9 @@ public class MobileFSM {
|
||||
float xPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
||||
float zPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
||||
Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc();
|
||||
mob.destination = new Vector3fImmutable(TreePos.x + xPoint,TreePos.y,TreePos.z + zPoint);
|
||||
mob.destination = new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint);
|
||||
MovementUtilities.aiMove(mob, mob.destination, true);
|
||||
if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()){
|
||||
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
|
||||
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) {
|
||||
//make sure mob is out of combat stance
|
||||
if (minion.getKey().despawned == false) {
|
||||
@@ -750,18 +776,19 @@ public class MobileFSM {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob){
|
||||
|
||||
public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob) {
|
||||
float CurrentHateValue = 0;
|
||||
if(mob.getCombatTarget() != null && mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter)){
|
||||
CurrentHateValue = ((PlayerCharacter)mob.getCombatTarget()).getHateValue();
|
||||
if (mob.getCombatTarget() != null && mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
|
||||
CurrentHateValue = ((PlayerCharacter) mob.getCombatTarget()).getHateValue();
|
||||
}
|
||||
AbstractWorldObject mostHatedTarget = null;
|
||||
for (Entry playerEntry : mob.playerAgroMap.entrySet()) {
|
||||
PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int)playerEntry.getKey());
|
||||
if(potentialTarget.equals(mob.getCombatTarget())){
|
||||
PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int) playerEntry.getKey());
|
||||
if (potentialTarget.equals(mob.getCombatTarget())) {
|
||||
continue;
|
||||
}
|
||||
if(potentialTarget != null && potentialTarget.getHateValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)){
|
||||
if (potentialTarget != null && potentialTarget.getHateValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)) {
|
||||
CurrentHateValue = potentialTarget.getHateValue();
|
||||
mostHatedTarget = potentialTarget;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@ public class MobileFSMManager {
|
||||
private static final MobileFSMManager INSTANCE = new MobileFSMManager();
|
||||
public static Duration executionTime = Duration.ofNanos(1);
|
||||
public static Duration executionMax = Duration.ofNanos(1);
|
||||
private volatile boolean alive;
|
||||
private long timeOfKill = -1;
|
||||
|
||||
//AI variables moved form mb_server_statics
|
||||
public static int AI_BASE_AGGRO_RANGE = 60;
|
||||
public static int AI_DROP_AGGRO_RANGE = 60;
|
||||
@@ -36,7 +33,9 @@ public class MobileFSMManager {
|
||||
public static int AI_THREAD_SLEEP = 1000;
|
||||
public static int AI_PATROL_DIVISOR = 15;
|
||||
public static int AI_POWER_DIVISOR = 20;
|
||||
public static float AI_MAX_ANGLE = 10f;
|
||||
public static float AI_MAX_ANGLE = 10f;
|
||||
private volatile boolean alive;
|
||||
private long timeOfKill = -1;
|
||||
|
||||
|
||||
private MobileFSMManager() {
|
||||
|
||||
@@ -405,7 +405,7 @@ public class CombatUtilities {
|
||||
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
|
||||
double min = agent.getMinDamageHandOne();
|
||||
double max = agent.getMaxDamageHandOne();
|
||||
if(agent.getEquip().get(1) != null) {
|
||||
if (agent.getEquip().get(1) != null) {
|
||||
if (agent.getEquip().get(1).getItemBase() != null) {
|
||||
dt = agent.getEquip().get(1).getItemBase().getDamageType();
|
||||
min = agent.getMinDamageHandOne();
|
||||
|
||||
@@ -14,161 +14,160 @@ import org.pmw.tinylog.Logger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class ControlledRunnable implements Runnable {
|
||||
protected boolean runCmd = false;
|
||||
protected boolean runStatus = false;
|
||||
private Thread thisThread;
|
||||
private final String threadName;
|
||||
// Runnable tracking
|
||||
private static final ArrayList<ControlledRunnable> runnables = new ArrayList<>();
|
||||
private final String threadName;
|
||||
protected boolean runCmd = false;
|
||||
protected boolean runStatus = false;
|
||||
private Thread thisThread;
|
||||
|
||||
public ControlledRunnable(String threadName) {
|
||||
super();
|
||||
this.threadName = threadName;
|
||||
ControlledRunnable.runnables.add(this);
|
||||
}
|
||||
/*
|
||||
* Main loop
|
||||
*/
|
||||
|
||||
/*
|
||||
* Main loop
|
||||
*/
|
||||
public ControlledRunnable(String threadName) {
|
||||
super();
|
||||
this.threadName = threadName;
|
||||
ControlledRunnable.runnables.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the method called when ControlledRunnable.thisThread.start() is
|
||||
* called.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (this._preRun() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runStatus = true;
|
||||
|
||||
if (this._Run() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._postRun() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _preRun() is called prior to the call to _Run(), but after _startup()
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _preRun();
|
||||
|
||||
/**
|
||||
* _Run() is called after _startup() and contains should contain the main
|
||||
* loop.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _Run();
|
||||
|
||||
/**
|
||||
* _postRun() is called after _Run() exits, not necessarily before
|
||||
* _shutdown()
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _postRun();
|
||||
|
||||
/*
|
||||
* Control
|
||||
*/
|
||||
|
||||
/**
|
||||
* startup() initializes the internal thread, sets the runCMD to true, and
|
||||
* calls _startup() prior to starting of the internal Thread.
|
||||
*/
|
||||
public void startup() {
|
||||
|
||||
this.thisThread = new Thread(this, this.threadName);
|
||||
this.runCmd = true;
|
||||
this._startup();
|
||||
this.thisThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called just before ControlledRunnable.thisThread.start()
|
||||
* is called.
|
||||
*/
|
||||
protected abstract void _startup();
|
||||
|
||||
/**
|
||||
* This method is called to request a shutdown of the runnable.
|
||||
*/
|
||||
public void shutdown() {
|
||||
this.runCmd = false;
|
||||
this._shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called just after ControlledRunnable.runCmd is set to
|
||||
* False.
|
||||
*/
|
||||
protected abstract void _shutdown();
|
||||
|
||||
/*
|
||||
* Getters n setters
|
||||
*/
|
||||
public boolean getRunCmd() {
|
||||
return runCmd;
|
||||
}
|
||||
|
||||
public boolean getRunStatus() {
|
||||
return runStatus;
|
||||
}
|
||||
|
||||
/*
|
||||
* Blockers
|
||||
*/
|
||||
public void blockTillRunStatus(boolean status) {
|
||||
while (this.runStatus != status) {
|
||||
try {
|
||||
System.out.println("BLOCKING");
|
||||
Thread.sleep(25L);
|
||||
} catch (InterruptedException e) {
|
||||
Logger.debug( e.getMessage());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the thisThread
|
||||
*/
|
||||
protected Thread getThisThread() {
|
||||
return thisThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the threadName
|
||||
*/
|
||||
public String getThreadName() {
|
||||
return threadName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Instance monitoring and tools
|
||||
*/
|
||||
|
||||
// Runnable tracking
|
||||
private static final ArrayList<ControlledRunnable> runnables = new ArrayList<>();
|
||||
|
||||
public static void shutdownAllRunnables() {
|
||||
for (ControlledRunnable cr : ControlledRunnable.runnables) {
|
||||
//Use Direct logging since JobManager is a runnable.
|
||||
public static void shutdownAllRunnables() {
|
||||
for (ControlledRunnable cr : ControlledRunnable.runnables) {
|
||||
//Use Direct logging since JobManager is a runnable.
|
||||
Logger.info("ControlledRunnable",
|
||||
"Sending Shutdown cmd to: " + cr.threadName);
|
||||
cr.shutdown();
|
||||
}
|
||||
}
|
||||
"Sending Shutdown cmd to: " + cr.threadName);
|
||||
cr.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the method called when ControlledRunnable.thisThread.start() is
|
||||
* called.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (this._preRun() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runStatus = true;
|
||||
|
||||
if (this._Run() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._postRun() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _preRun() is called prior to the call to _Run(), but after _startup()
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _preRun();
|
||||
|
||||
/*
|
||||
* Control
|
||||
*/
|
||||
|
||||
/**
|
||||
* _Run() is called after _startup() and contains should contain the main
|
||||
* loop.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _Run();
|
||||
|
||||
/**
|
||||
* _postRun() is called after _Run() exits, not necessarily before
|
||||
* _shutdown()
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _postRun();
|
||||
|
||||
/**
|
||||
* startup() initializes the internal thread, sets the runCMD to true, and
|
||||
* calls _startup() prior to starting of the internal Thread.
|
||||
*/
|
||||
public void startup() {
|
||||
|
||||
this.thisThread = new Thread(this, this.threadName);
|
||||
this.runCmd = true;
|
||||
this._startup();
|
||||
this.thisThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called just before ControlledRunnable.thisThread.start()
|
||||
* is called.
|
||||
*/
|
||||
protected abstract void _startup();
|
||||
|
||||
/**
|
||||
* This method is called to request a shutdown of the runnable.
|
||||
*/
|
||||
public void shutdown() {
|
||||
this.runCmd = false;
|
||||
this._shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called just after ControlledRunnable.runCmd is set to
|
||||
* False.
|
||||
*/
|
||||
protected abstract void _shutdown();
|
||||
|
||||
/*
|
||||
* Getters n setters
|
||||
*/
|
||||
public boolean getRunCmd() {
|
||||
return runCmd;
|
||||
}
|
||||
|
||||
public boolean getRunStatus() {
|
||||
return runStatus;
|
||||
}
|
||||
|
||||
/*
|
||||
* Blockers
|
||||
*/
|
||||
public void blockTillRunStatus(boolean status) {
|
||||
while (this.runStatus != status) {
|
||||
try {
|
||||
System.out.println("BLOCKING");
|
||||
Thread.sleep(25L);
|
||||
} catch (InterruptedException e) {
|
||||
Logger.debug(e.getMessage());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Instance monitoring and tools
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return the thisThread
|
||||
*/
|
||||
protected Thread getThisThread() {
|
||||
return thisThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the threadName
|
||||
*/
|
||||
public String getThreadName() {
|
||||
return threadName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,360 +25,358 @@ import static engine.Enum.RecordEventType;
|
||||
|
||||
public class BaneRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<BaneRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private RecordEventType eventType;
|
||||
private String cityHash;
|
||||
private String cityName;
|
||||
private String cityGuildHash;
|
||||
private String cityNationHash;
|
||||
private String baneDropperHash;
|
||||
private String baneGuildHash;
|
||||
private String baneNationHash;
|
||||
private DateTime baneLiveTime;
|
||||
private DateTime baneDropTime;
|
||||
private static final LinkedBlockingQueue<BaneRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private RecordEventType eventType;
|
||||
private String cityHash;
|
||||
private String cityName;
|
||||
private String cityGuildHash;
|
||||
private String cityNationHash;
|
||||
private String baneDropperHash;
|
||||
private String baneGuildHash;
|
||||
private String baneNationHash;
|
||||
private DateTime baneLiveTime;
|
||||
private DateTime baneDropTime;
|
||||
|
||||
private BaneRecord(Bane bane) {
|
||||
this.recordType = Enum.DataRecordType.BANE;
|
||||
this.eventType = RecordEventType.PENDING;
|
||||
}
|
||||
private BaneRecord(Bane bane) {
|
||||
this.recordType = Enum.DataRecordType.BANE;
|
||||
this.eventType = RecordEventType.PENDING;
|
||||
}
|
||||
|
||||
public static BaneRecord borrow(Bane bane, RecordEventType eventType) {
|
||||
BaneRecord baneRecord;
|
||||
public static BaneRecord borrow(Bane bane, RecordEventType eventType) {
|
||||
BaneRecord baneRecord;
|
||||
|
||||
baneRecord = recordPool.poll();
|
||||
baneRecord = recordPool.poll();
|
||||
|
||||
if (baneRecord == null) {
|
||||
baneRecord = new BaneRecord(bane);
|
||||
baneRecord.eventType = eventType;
|
||||
}
|
||||
else {
|
||||
baneRecord.recordType = Enum.DataRecordType.BANE;
|
||||
baneRecord.eventType = eventType;
|
||||
if (baneRecord == null) {
|
||||
baneRecord = new BaneRecord(bane);
|
||||
baneRecord.eventType = eventType;
|
||||
} else {
|
||||
baneRecord.recordType = Enum.DataRecordType.BANE;
|
||||
baneRecord.eventType = eventType;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
baneRecord.cityHash = bane.getCity().getHash();
|
||||
baneRecord.cityName = bane.getCity().getCityName();
|
||||
baneRecord.cityGuildHash = bane.getCity().getGuild().getHash();
|
||||
baneRecord.cityNationHash = bane.getCity().getGuild().getNation().getHash();
|
||||
baneRecord.cityHash = bane.getCity().getHash();
|
||||
baneRecord.cityName = bane.getCity().getCityName();
|
||||
baneRecord.cityGuildHash = bane.getCity().getGuild().getHash();
|
||||
baneRecord.cityNationHash = bane.getCity().getGuild().getNation().getHash();
|
||||
|
||||
|
||||
if (bane.getOwner() == null) {
|
||||
baneRecord.baneDropperHash = "ERRANT";
|
||||
baneRecord.baneGuildHash = "ERRANT";
|
||||
baneRecord.baneNationHash = "ERRANT";
|
||||
}
|
||||
else {
|
||||
baneRecord.baneDropperHash = DataWarehouse.hasher.encrypt(bane.getOwner().getObjectUUID()); // getPlayerCharacter didn't check hash first? OMFG
|
||||
if (bane.getOwner() == null) {
|
||||
baneRecord.baneDropperHash = "ERRANT";
|
||||
baneRecord.baneGuildHash = "ERRANT";
|
||||
baneRecord.baneNationHash = "ERRANT";
|
||||
} else {
|
||||
baneRecord.baneDropperHash = DataWarehouse.hasher.encrypt(bane.getOwner().getObjectUUID()); // getPlayerCharacter didn't check hash first? OMFG
|
||||
|
||||
|
||||
baneRecord.baneGuildHash = bane.getOwner().getGuild().getHash();
|
||||
baneRecord.baneNationHash = bane.getOwner().getGuild().getNation().getHash();
|
||||
baneRecord.baneGuildHash = bane.getOwner().getGuild().getHash();
|
||||
baneRecord.baneNationHash = bane.getOwner().getGuild().getNation().getHash();
|
||||
|
||||
|
||||
baneRecord.baneLiveTime = bane.getLiveDate();
|
||||
baneRecord.baneDropTime = bane.getPlacementDate();
|
||||
}
|
||||
baneRecord.baneLiveTime = bane.getLiveDate();
|
||||
baneRecord.baneDropTime = bane.getPlacementDate();
|
||||
}
|
||||
|
||||
|
||||
return baneRecord;
|
||||
}
|
||||
return baneRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildBanePushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
public static PreparedStatement buildBanePushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`event_number`, `city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
||||
java.util.Date sqlDateTime;
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`event_number`, `city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
||||
java.util.Date sqlDateTime;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("char_id"));
|
||||
outStatement.setString(5, rs.getString("offGuild_id"));
|
||||
outStatement.setString(6, rs.getString("offNat_id"));
|
||||
outStatement.setString(7, rs.getString("defGuild_id"));
|
||||
outStatement.setString(8, rs.getString("defNat_id"));
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("char_id"));
|
||||
outStatement.setString(5, rs.getString("offGuild_id"));
|
||||
outStatement.setString(6, rs.getString("offNat_id"));
|
||||
outStatement.setString(7, rs.getString("defGuild_id"));
|
||||
outStatement.setString(8, rs.getString("defNat_id"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(9, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, rs.getTimestamp("dropDatetime"));
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(9, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, rs.getTimestamp("dropDatetime"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(10, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("liveDateTime"));
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(10, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("liveDateTime"));
|
||||
|
||||
outStatement.setString(11, rs.getString("resolution"));
|
||||
outStatement.setString(11, rs.getString("resolution"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildBaneQueryStatement(Connection connection) throws SQLException {
|
||||
public static PreparedStatement buildBaneQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.baneIndex);
|
||||
return outStatement;
|
||||
}
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.baneIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static DateTime getLastBaneDateTime(City city) {
|
||||
public static DateTime getLastBaneDateTime(City city) {
|
||||
|
||||
DateTime outDateTime = null;
|
||||
DateTime outDateTime = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildDateTimeQueryStatement(connection, city);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildDateTimeQueryStatement(connection, city);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
outDateTime = new DateTime(rs.getTimestamp("endDatetime"));
|
||||
outDateTime = new DateTime(rs.getTimestamp("endDatetime"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return outDateTime;
|
||||
}
|
||||
return outDateTime;
|
||||
}
|
||||
|
||||
|
||||
private static PreparedStatement buildDateTimeQueryStatement (Connection connection, City city) throws SQLException {
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "SELECT `endDatetime` FROM `warehouse_banehistory` WHERE `city_id` = ? ORDER BY `endDatetime` DESC LIMIT 1";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, city.getHash());
|
||||
return outStatement;
|
||||
private static PreparedStatement buildDateTimeQueryStatement(Connection connection, City city) throws SQLException {
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "SELECT `endDatetime` FROM `warehouse_banehistory` WHERE `city_id` = ? ORDER BY `endDatetime` DESC LIMIT 1";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, city.getHash());
|
||||
return outStatement;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLiveDate(Bane bane, DateTime dateTime) {
|
||||
public static void updateLiveDate(Bane bane, DateTime dateTime) {
|
||||
|
||||
if (bane == null)
|
||||
return;
|
||||
if (bane == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) {
|
||||
|
||||
statement.execute();
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateLiveDateStatement(Connection connection, Bane bane, DateTime dateTime) throws SQLException {
|
||||
private static PreparedStatement buildUpdateLiveDateStatement(Connection connection, Bane bane, DateTime dateTime) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDatetime` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDatetime` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, new java.sql.Timestamp(dateTime.getMillis()));
|
||||
outStatement.setString(2, bane.getCity().getHash());
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, new java.sql.Timestamp(dateTime.getMillis()));
|
||||
outStatement.setString(2, bane.getCity().getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateResolutionStatement(Connection connection, Bane bane, RecordEventType eventType) throws SQLException {
|
||||
private static PreparedStatement buildUpdateResolutionStatement(Connection connection, Bane bane, RecordEventType eventType) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `endDatetime` = ?, `resolution` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `endDatetime` = ?, `resolution` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
|
||||
outStatement.setString(2, eventType.name());
|
||||
outStatement.setString(3, bane.getCity().getHash());
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
|
||||
outStatement.setString(2, eventType.name());
|
||||
outStatement.setString(3, bane.getCity().getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updateResolution(Bane bane, RecordEventType eventType) {
|
||||
public static void updateResolution(Bane bane, RecordEventType eventType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) {
|
||||
|
||||
statement.execute();
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBaneHistoryString() {
|
||||
public static String getBaneHistoryString() {
|
||||
|
||||
String outString;
|
||||
String queryString;
|
||||
String dividerString;
|
||||
String newLine = System.getProperty("line.separator");
|
||||
outString = "[LUA_BANES() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
queryString = "CALL `baneHistory`()";
|
||||
String outString;
|
||||
String queryString;
|
||||
String dividerString;
|
||||
String newLine = System.getProperty("line.separator");
|
||||
outString = "[LUA_BANES() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
queryString = "CALL `baneHistory`()";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = connection.prepareCall(queryString);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = connection.prepareCall(queryString);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
outString += "Magicbane unresolved banes: " + rs.getInt("PENDING") + '/' + rs.getInt("TOTAL") + newLine;
|
||||
outString += dividerString;
|
||||
outString += "Bane Resolution History" + newLine;
|
||||
outString += dividerString;
|
||||
outString += "Magicbane unresolved banes: " + rs.getInt("PENDING") + '/' + rs.getInt("TOTAL") + newLine;
|
||||
outString += dividerString;
|
||||
outString += "Bane Resolution History" + newLine;
|
||||
outString += dividerString;
|
||||
|
||||
outString += "Destruction: " + rs.getInt("DESTROY") + newLine;
|
||||
outString += "Capture: " + rs.getInt("CAPTURE") + newLine;
|
||||
outString += "Defended: " + rs.getInt("DEFEND") + newLine;
|
||||
}
|
||||
outString += "Destruction: " + rs.getInt("DESTROY") + newLine;
|
||||
outString += "Capture: " + rs.getInt("CAPTURE") + newLine;
|
||||
outString += "Defended: " + rs.getInt("DEFEND") + newLine;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static void updateDirtyRecords() {
|
||||
public static void updateDirtyRecords() {
|
||||
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` where `dirty` = 1";
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` where `dirty` = 1";
|
||||
|
||||
// Reset character delta
|
||||
// Reset character delta
|
||||
|
||||
WarehousePushThread.baneDelta = 0;
|
||||
WarehousePushThread.baneDelta = 0;
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
// Only update the index and dirty flag
|
||||
// if the remote database update succeeded
|
||||
// Only update the index and dirty flag
|
||||
// if the remote database update succeeded
|
||||
|
||||
if (updateDirtyRecord(rs) == true)
|
||||
WarehousePushThread.baneDelta++;
|
||||
else
|
||||
continue;
|
||||
if (updateDirtyRecord(rs) == true)
|
||||
WarehousePushThread.baneDelta++;
|
||||
else
|
||||
continue;
|
||||
|
||||
// Reset the dirty flag in the local database
|
||||
// Reset the dirty flag in the local database
|
||||
|
||||
rs.updateInt("dirty", 0);
|
||||
rs.updateRow();
|
||||
}
|
||||
rs.updateInt("dirty", 0);
|
||||
rs.updateRow();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error( e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateDirtyRecord(ResultSet rs) {
|
||||
private static boolean updateDirtyRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) {
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error( e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDateTime` = ?, `endDateTime` = ?, `resolution` = ? WHERE `event_number` = ?";
|
||||
java.util.Date sqlDateTime;
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDateTime` = ?, `endDateTime` = ?, `resolution` = ? WHERE `event_number` = ?";
|
||||
java.util.Date sqlDateTime;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
// Bind record data
|
||||
|
||||
sqlDateTime = rs.getTimestamp("liveDateTime");
|
||||
sqlDateTime = rs.getTimestamp("liveDateTime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(1, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(1, rs.getTimestamp("liveDateTime"));
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(1, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(1, rs.getTimestamp("liveDateTime"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("endDateTime");
|
||||
sqlDateTime = rs.getTimestamp("endDateTime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(2, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(2, rs.getTimestamp("endDateTime"));
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(2, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(2, rs.getTimestamp("endDateTime"));
|
||||
|
||||
outStatement.setString(3, rs.getString("resolution"));
|
||||
outStatement.setInt(4, rs.getInt("event_number"));
|
||||
outStatement.setString(3, rs.getString("resolution"));
|
||||
outStatement.setInt(4, rs.getInt("event_number"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityNationHash = null;
|
||||
this.baneDropperHash = null;
|
||||
this.baneGuildHash = null;
|
||||
this.baneNationHash = null;
|
||||
this.baneLiveTime = null;
|
||||
}
|
||||
void reset() {
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityNationHash = null;
|
||||
this.baneDropperHash = null;
|
||||
this.baneGuildHash = null;
|
||||
this.baneNationHash = null;
|
||||
this.baneLiveTime = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildBaneInsertStatement(connection)) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildBaneInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement buildBaneInsertStatement(Connection connection) throws SQLException {
|
||||
private PreparedStatement buildBaneInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.baneDropperHash);
|
||||
outStatement.setString(4, this.baneGuildHash);
|
||||
outStatement.setString(5, this.baneNationHash);
|
||||
outStatement.setString(6, this.cityGuildHash);
|
||||
outStatement.setString(7, this.cityNationHash);
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.baneDropperHash);
|
||||
outStatement.setString(4, this.baneGuildHash);
|
||||
outStatement.setString(5, this.baneNationHash);
|
||||
outStatement.setString(6, this.cityGuildHash);
|
||||
outStatement.setString(7, this.cityNationHash);
|
||||
|
||||
if (this.baneDropTime == null)
|
||||
outStatement.setNull(8, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(8, new java.sql.Timestamp(this.baneDropTime.getMillis()));
|
||||
if (this.baneDropTime == null)
|
||||
outStatement.setNull(8, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(8, new java.sql.Timestamp(this.baneDropTime.getMillis()));
|
||||
|
||||
if (this.baneLiveTime == null)
|
||||
outStatement.setNull(9, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, new java.sql.Timestamp(this.baneLiveTime.getMillis()));
|
||||
if (this.baneLiveTime == null)
|
||||
outStatement.setNull(9, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, new java.sql.Timestamp(this.baneLiveTime.getMillis()));
|
||||
|
||||
outStatement.setString(10, this.eventType.name());
|
||||
outStatement.setString(10, this.eventType.name());
|
||||
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
} // END CLASS
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ public class CharacterRecord extends DataRecord {
|
||||
|
||||
if (characterRecord == null) {
|
||||
characterRecord = new CharacterRecord(player);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
characterRecord.recordType = Enum.DataRecordType.CHARACTER;
|
||||
characterRecord.player = player;
|
||||
|
||||
|
||||
@@ -19,144 +19,143 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class CityRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<CityRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private City city;
|
||||
private String cityHash;
|
||||
private String cityGuildHash;
|
||||
private String cityName;
|
||||
private String cityMotto;
|
||||
private float locX;
|
||||
private float locY;
|
||||
private String zoneHash;
|
||||
private java.time.LocalDateTime establishedDatetime;
|
||||
private static final LinkedBlockingQueue<CityRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private City city;
|
||||
private String cityHash;
|
||||
private String cityGuildHash;
|
||||
private String cityName;
|
||||
private String cityMotto;
|
||||
private float locX;
|
||||
private float locY;
|
||||
private String zoneHash;
|
||||
private java.time.LocalDateTime establishedDatetime;
|
||||
|
||||
private CityRecord(City city) {
|
||||
this.recordType = Enum.DataRecordType.CITY;
|
||||
this.city = city;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
private CityRecord(City city) {
|
||||
this.recordType = Enum.DataRecordType.CITY;
|
||||
this.city = city;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static CityRecord borrow(City city, Enum.RecordEventType eventType) {
|
||||
CityRecord cityRecord;
|
||||
public static CityRecord borrow(City city, Enum.RecordEventType eventType) {
|
||||
CityRecord cityRecord;
|
||||
|
||||
cityRecord = recordPool.poll();
|
||||
cityRecord = recordPool.poll();
|
||||
|
||||
if (cityRecord == null) {
|
||||
cityRecord = new CityRecord(city);
|
||||
cityRecord.eventType = eventType;
|
||||
}
|
||||
else {
|
||||
cityRecord.recordType = Enum.DataRecordType.CITY;
|
||||
cityRecord.eventType = eventType;
|
||||
cityRecord.city = city;
|
||||
if (cityRecord == null) {
|
||||
cityRecord = new CityRecord(city);
|
||||
cityRecord.eventType = eventType;
|
||||
} else {
|
||||
cityRecord.recordType = Enum.DataRecordType.CITY;
|
||||
cityRecord.eventType = eventType;
|
||||
cityRecord.city = city;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (cityRecord.city.getHash() == null)
|
||||
cityRecord.city.setHash(DataWarehouse.hasher.encrypt(cityRecord.city.getObjectUUID()));
|
||||
if (cityRecord.city.getHash() == null)
|
||||
cityRecord.city.setHash(DataWarehouse.hasher.encrypt(cityRecord.city.getObjectUUID()));
|
||||
|
||||
cityRecord.cityHash = cityRecord.city.getHash();
|
||||
cityRecord.cityHash = cityRecord.city.getHash();
|
||||
|
||||
|
||||
cityRecord.cityName = cityRecord.city.getCityName();
|
||||
cityRecord.cityMotto = cityRecord.city.getMotto();
|
||||
cityRecord.cityName = cityRecord.city.getCityName();
|
||||
cityRecord.cityMotto = cityRecord.city.getMotto();
|
||||
|
||||
cityRecord.cityGuildHash = cityRecord.city.getGuild().getHash();
|
||||
cityRecord.cityGuildHash = cityRecord.city.getGuild().getHash();
|
||||
|
||||
cityRecord.locX = cityRecord.city.getTOL().getLoc().x;
|
||||
cityRecord.locY = -cityRecord.city.getTOL().getLoc().z; // flip sign on 'y' coordinate
|
||||
cityRecord.locX = cityRecord.city.getTOL().getLoc().x;
|
||||
cityRecord.locY = -cityRecord.city.getTOL().getLoc().z; // flip sign on 'y' coordinate
|
||||
|
||||
cityRecord.zoneHash = cityRecord.city.getParent().getHash();
|
||||
cityRecord.zoneHash = cityRecord.city.getParent().getHash();
|
||||
|
||||
if (cityRecord.eventType.equals(Enum.RecordEventType.CREATE))
|
||||
cityRecord.establishedDatetime = cityRecord.city.established;
|
||||
else
|
||||
cityRecord.establishedDatetime = java.time.LocalDateTime.now();
|
||||
if (cityRecord.eventType.equals(Enum.RecordEventType.CREATE))
|
||||
cityRecord.establishedDatetime = cityRecord.city.established;
|
||||
else
|
||||
cityRecord.establishedDatetime = java.time.LocalDateTime.now();
|
||||
|
||||
return cityRecord;
|
||||
}
|
||||
return cityRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCityPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
public static PreparedStatement buildCityPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`event_number`, `city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`event_number`, `city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("city_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_id"));
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("city_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_id"));
|
||||
|
||||
outStatement.setFloat(6, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(7, rs.getFloat("loc_y"));
|
||||
outStatement.setString(8, rs.getString("zone_id"));
|
||||
outStatement.setString(9, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("datetime"));
|
||||
outStatement.setFloat(6, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(7, rs.getFloat("loc_y"));
|
||||
outStatement.setString(8, rs.getString("zone_id"));
|
||||
outStatement.setString(9, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCityQueryStatement(Connection connection) throws SQLException {
|
||||
public static PreparedStatement buildCityQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_cityhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.cityIndex);
|
||||
return outStatement;
|
||||
}
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_cityhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.cityIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.city = null;
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityMotto = null;
|
||||
this.zoneHash = null;
|
||||
this.establishedDatetime = null;
|
||||
void reset() {
|
||||
this.city = null;
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityMotto = null;
|
||||
this.zoneHash = null;
|
||||
this.establishedDatetime = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildCityInsertStatement(connection)) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildCityInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement buildCityInsertStatement(Connection connection) throws SQLException {
|
||||
private PreparedStatement buildCityInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.cityMotto);
|
||||
outStatement.setString(4, this.cityGuildHash);
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.cityMotto);
|
||||
outStatement.setString(4, this.cityGuildHash);
|
||||
|
||||
outStatement.setFloat(5, this.locX);
|
||||
outStatement.setFloat(6, this.locY);
|
||||
outStatement.setString(7, this.zoneHash);
|
||||
outStatement.setString(8, this.eventType.name());
|
||||
outStatement.setTimestamp(9, Timestamp.valueOf(this.establishedDatetime));
|
||||
outStatement.setFloat(5, this.locX);
|
||||
outStatement.setFloat(6, this.locY);
|
||||
outStatement.setString(7, this.zoneHash);
|
||||
outStatement.setString(8, this.eventType.name());
|
||||
outStatement.setTimestamp(9, Timestamp.valueOf(this.establishedDatetime));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
|
||||
@@ -35,12 +35,12 @@ public class DataWarehouse implements Runnable {
|
||||
// If WarehousePush is disabled
|
||||
// then early exit
|
||||
|
||||
if ( ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) {
|
||||
if (ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) {
|
||||
Logger.info("Warehouse Remote Connection disabled along with push");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.info( "Configuring remote Database Connection Pool...");
|
||||
Logger.info("Configuring remote Database Connection Pool...");
|
||||
configureRemoteConnectionPool();
|
||||
}
|
||||
|
||||
@@ -188,6 +188,24 @@ public class DataWarehouse implements Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void configureRemoteConnectionPool() {
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
config.setMaximumPoolSize(1); // Only the server talks to remote, so yeah.
|
||||
config.setJdbcUrl(ConfigManager.MB_WAREHOUSE_ADDR.getValue());
|
||||
config.setUsername(ConfigManager.MB_WAREHOUSE_USER.getValue());
|
||||
config.setPassword(ConfigManager.MB_WAREHOUSE_PASS.getValue());
|
||||
config.addDataSourceProperty("characterEncoding", "utf8");
|
||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
|
||||
remoteConnectionPool = new HikariDataSource(config); // setup the connection pool
|
||||
|
||||
Logger.info("remote warehouse connection configured");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
// Working variable set
|
||||
@@ -201,7 +219,7 @@ public class DataWarehouse implements Runnable {
|
||||
RealmRecord realmRecord;
|
||||
MineRecord mineRecord;
|
||||
|
||||
Logger.info( "DataWarehouse is running.");
|
||||
Logger.info("DataWarehouse is running.");
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -261,7 +279,7 @@ public class DataWarehouse implements Runnable {
|
||||
mineRecord.release();
|
||||
break;
|
||||
default:
|
||||
Logger.error( "Unhandled record type");
|
||||
Logger.error("Unhandled record type");
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
@@ -269,22 +287,4 @@ public class DataWarehouse implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureRemoteConnectionPool() {
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
config.setMaximumPoolSize(1); // Only the server talks to remote, so yeah.
|
||||
config.setJdbcUrl(ConfigManager.MB_WAREHOUSE_ADDR.getValue());
|
||||
config.setUsername(ConfigManager.MB_WAREHOUSE_USER.getValue());
|
||||
config.setPassword(ConfigManager.MB_WAREHOUSE_PASS.getValue());
|
||||
config.addDataSourceProperty("characterEncoding", "utf8");
|
||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
|
||||
remoteConnectionPool = new HikariDataSource(config); // setup the connection pool
|
||||
|
||||
Logger.info("remote warehouse connection configured");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,144 +26,139 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class GuildRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<GuildRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private Guild guild;
|
||||
public String guildHash;
|
||||
private String guildName;
|
||||
private String charterName;
|
||||
private String GLHash;
|
||||
private String guildMotto;
|
||||
private int bgIcon;
|
||||
private int bgColour1;
|
||||
private int bgColour2;
|
||||
private int fgIcon;
|
||||
private int fgColour;
|
||||
public int guildID;
|
||||
private static final LinkedBlockingQueue<GuildRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
public static HashMap<Integer, GuildRecord> GuildRecordCache = null;
|
||||
public String guildHash;
|
||||
public int guildID;
|
||||
private Enum.RecordEventType eventType;
|
||||
private Guild guild;
|
||||
private String guildName;
|
||||
private String charterName;
|
||||
private String GLHash;
|
||||
private String guildMotto;
|
||||
private int bgIcon;
|
||||
private int bgColour1;
|
||||
private int bgColour2;
|
||||
private int fgIcon;
|
||||
private int fgColour;
|
||||
private java.time.LocalDateTime eventDatetime;
|
||||
|
||||
private java.time.LocalDateTime eventDatetime;
|
||||
|
||||
public static HashMap<Integer, GuildRecord> GuildRecordCache = null;
|
||||
|
||||
private GuildRecord(Guild guild) {
|
||||
this.recordType = Enum.DataRecordType.GUILD;
|
||||
this.guild = guild;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GuildRecord(ResultSet rs) throws SQLException {
|
||||
super();
|
||||
this.eventType = RecordEventType.valueOf(rs.getString("eventType"));
|
||||
this.guildHash = rs.getString("guild_id");
|
||||
this.guildName = rs.getString("guild_name");
|
||||
this.charterName = rs.getString("charter");
|
||||
GLHash = rs.getString("guild_founder");
|
||||
this.guildMotto = rs.getString("guild_motto");
|
||||
this.bgIcon = rs.getInt("bgicon");
|
||||
this.bgColour1 = rs.getInt("bgcoloura");
|
||||
this.bgColour2 = rs.getInt("bgcolourb");
|
||||
this.fgIcon = rs.getInt("fgicon");
|
||||
this.fgColour = rs.getInt("fgcolour");
|
||||
|
||||
java.sql.Timestamp eventTimeStamp = rs.getTimestamp("upgradeDate");
|
||||
|
||||
if (eventTimeStamp != null)
|
||||
this.eventDatetime = LocalDateTime.ofInstant(eventTimeStamp.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
private GuildRecord(Guild guild) {
|
||||
this.recordType = Enum.DataRecordType.GUILD;
|
||||
this.guild = guild;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
}
|
||||
|
||||
|
||||
public GuildRecord(ResultSet rs) throws SQLException {
|
||||
super();
|
||||
this.eventType = RecordEventType.valueOf(rs.getString("eventType"));
|
||||
this.guildHash = rs.getString("guild_id");
|
||||
this.guildName = rs.getString("guild_name");
|
||||
this.charterName = rs.getString("charter");
|
||||
GLHash = rs.getString("guild_founder");
|
||||
this.guildMotto = rs.getString("guild_motto");
|
||||
this.bgIcon = rs.getInt("bgicon");
|
||||
this.bgColour1 = rs.getInt("bgcoloura");
|
||||
this.bgColour2 = rs.getInt("bgcolourb");
|
||||
this.fgIcon = rs.getInt("fgicon");
|
||||
this.fgColour = rs.getInt("fgcolour");
|
||||
|
||||
public static GuildRecord borrow(Guild guild, Enum.RecordEventType eventType) {
|
||||
GuildRecord guildRecord;
|
||||
//add
|
||||
guildRecord = recordPool.poll();
|
||||
java.sql.Timestamp eventTimeStamp = rs.getTimestamp("upgradeDate");
|
||||
|
||||
if (guildRecord == null) {
|
||||
guildRecord = new GuildRecord(guild);
|
||||
guildRecord.eventType = eventType;
|
||||
}
|
||||
else {
|
||||
guildRecord.guild = guild;
|
||||
guildRecord.recordType = Enum.DataRecordType.GUILD;
|
||||
guildRecord.eventType = eventType;
|
||||
if (eventTimeStamp != null)
|
||||
this.eventDatetime = LocalDateTime.ofInstant(eventTimeStamp.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
guildRecord.guildHash = guildRecord.guild.getHash();
|
||||
guildRecord.guildID = guildRecord.guild.getObjectUUID();
|
||||
guildRecord.guildName = guildRecord.guild.getName();
|
||||
guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName();
|
||||
public static GuildRecord borrow(Guild guild, Enum.RecordEventType eventType) {
|
||||
GuildRecord guildRecord;
|
||||
//add
|
||||
guildRecord = recordPool.poll();
|
||||
|
||||
guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID());
|
||||
if (guildRecord == null) {
|
||||
guildRecord = new GuildRecord(guild);
|
||||
guildRecord.eventType = eventType;
|
||||
} else {
|
||||
guildRecord.guild = guild;
|
||||
guildRecord.recordType = Enum.DataRecordType.GUILD;
|
||||
guildRecord.eventType = eventType;
|
||||
|
||||
guildRecord.guildMotto = guildRecord.guild.getMotto();
|
||||
guildRecord.bgIcon = guildRecord.guild.getBgDesign();
|
||||
guildRecord.bgColour1 = guildRecord.guild.getBgc1();
|
||||
guildRecord.bgColour2 = guildRecord.guild.getBgc2();
|
||||
guildRecord.fgIcon = guildRecord.guild.getSymbol();
|
||||
guildRecord.fgColour = guildRecord.guild.getSc();
|
||||
}
|
||||
|
||||
if (guild.getOwnedCity() != null)
|
||||
guildRecord.eventDatetime = guild.getOwnedCity().established;
|
||||
else
|
||||
guildRecord.eventDatetime = LocalDateTime.now();
|
||||
guildRecord.guildHash = guildRecord.guild.getHash();
|
||||
guildRecord.guildID = guildRecord.guild.getObjectUUID();
|
||||
guildRecord.guildName = guildRecord.guild.getName();
|
||||
guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName();
|
||||
|
||||
return guildRecord;
|
||||
}
|
||||
guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID());
|
||||
|
||||
public static PreparedStatement buildGuildPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
guildRecord.guildMotto = guildRecord.guild.getMotto();
|
||||
guildRecord.bgIcon = guildRecord.guild.getBgDesign();
|
||||
guildRecord.bgColour1 = guildRecord.guild.getBgc1();
|
||||
guildRecord.bgColour2 = guildRecord.guild.getBgc2();
|
||||
guildRecord.fgIcon = guildRecord.guild.getSymbol();
|
||||
guildRecord.fgColour = guildRecord.guild.getSc();
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`event_number`, `guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
if (guild.getOwnedCity() != null)
|
||||
guildRecord.eventDatetime = guild.getOwnedCity().established;
|
||||
else
|
||||
guildRecord.eventDatetime = LocalDateTime.now();
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
return guildRecord;
|
||||
}
|
||||
|
||||
// Bind record data
|
||||
public static PreparedStatement buildGuildPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("guild_id"));
|
||||
outStatement.setString(3, rs.getString("guild_name"));
|
||||
outStatement.setString(4, rs.getString("guild_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_founder"));
|
||||
outStatement.setString(6, rs.getString("charter"));
|
||||
outStatement.setInt(7, rs.getInt("bgicon"));
|
||||
outStatement.setInt(8, rs.getInt("bgcoloura"));
|
||||
outStatement.setInt(9, rs.getInt("bgcolourb"));
|
||||
outStatement.setInt(10, rs.getInt("fgicon"));
|
||||
outStatement.setInt(11, rs.getInt("fgcolour"));
|
||||
outStatement.setString(12, rs.getString("eventtype"));
|
||||
outStatement.setTimestamp(13, rs.getTimestamp("datetime"));
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`event_number`, `guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
public static PreparedStatement buildGuildQueryStatement(Connection connection) throws SQLException {
|
||||
// Bind record data
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_guildhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.guildIndex);
|
||||
return outStatement;
|
||||
}
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("guild_id"));
|
||||
outStatement.setString(3, rs.getString("guild_name"));
|
||||
outStatement.setString(4, rs.getString("guild_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_founder"));
|
||||
outStatement.setString(6, rs.getString("charter"));
|
||||
outStatement.setInt(7, rs.getInt("bgicon"));
|
||||
outStatement.setInt(8, rs.getInt("bgcoloura"));
|
||||
outStatement.setInt(9, rs.getInt("bgcolourb"));
|
||||
outStatement.setInt(10, rs.getInt("fgicon"));
|
||||
outStatement.setInt(11, rs.getInt("fgcolour"));
|
||||
outStatement.setString(12, rs.getString("eventtype"));
|
||||
outStatement.setTimestamp(13, rs.getTimestamp("datetime"));
|
||||
|
||||
void reset() {
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
this.guild = null;
|
||||
this.guildHash = null;
|
||||
this.GLHash = null;
|
||||
this.guildMotto = null;
|
||||
this.charterName = null;
|
||||
this.eventDatetime = null;
|
||||
}
|
||||
public static PreparedStatement buildGuildQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_guildhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.guildIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public void write() {
|
||||
void reset() {
|
||||
|
||||
this.guild = null;
|
||||
this.guildHash = null;
|
||||
this.GLHash = null;
|
||||
this.guildMotto = null;
|
||||
this.charterName = null;
|
||||
this.eventDatetime = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildGuildInsertStatement(connection)) {
|
||||
@@ -176,33 +171,33 @@ public class GuildRecord extends DataRecord {
|
||||
|
||||
}
|
||||
|
||||
private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException {
|
||||
private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.guildHash);
|
||||
outStatement.setString(2, this.guildName);
|
||||
outStatement.setString(3, this.guildMotto);
|
||||
outStatement.setString(4, this.GLHash);
|
||||
outStatement.setString(5, this.charterName);
|
||||
outStatement.setString(1, this.guildHash);
|
||||
outStatement.setString(2, this.guildName);
|
||||
outStatement.setString(3, this.guildMotto);
|
||||
outStatement.setString(4, this.GLHash);
|
||||
outStatement.setString(5, this.charterName);
|
||||
|
||||
outStatement.setInt(6, this.bgIcon);
|
||||
outStatement.setInt(7, this.bgColour1);
|
||||
outStatement.setInt(8, this.bgColour2);
|
||||
outStatement.setInt(9, this.fgIcon);
|
||||
outStatement.setInt(10, this.fgColour);
|
||||
outStatement.setString(11, this.eventType.name());
|
||||
outStatement.setTimestamp(12, new java.sql.Timestamp( this.eventDatetime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
outStatement.setInt(6, this.bgIcon);
|
||||
outStatement.setInt(7, this.bgColour1);
|
||||
outStatement.setInt(8, this.bgColour2);
|
||||
outStatement.setInt(9, this.fgIcon);
|
||||
outStatement.setInt(10, this.fgColour);
|
||||
outStatement.setString(11, this.eventType.name());
|
||||
outStatement.setTimestamp(12, new java.sql.Timestamp(this.eventDatetime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
// public static void InitializeGuildRecords(){
|
||||
// GuildRecord.GuildRecordCache = DbManager.GuildQueries.GET_WAREHOUSE_GUILD_HISTORY();
|
||||
// }
|
||||
|
||||
@@ -47,8 +47,7 @@ public class MineRecord extends DataRecord {
|
||||
if (mineRecord == null) {
|
||||
mineRecord = new MineRecord();
|
||||
mineRecord.eventType = eventType;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mineRecord.recordType = Enum.DataRecordType.MINE;
|
||||
mineRecord.eventType = eventType;
|
||||
}
|
||||
@@ -58,8 +57,7 @@ public class MineRecord extends DataRecord {
|
||||
if (character.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
|
||||
player = (PlayerCharacter) character;
|
||||
mineRecord.charHash = player.getHash();
|
||||
}
|
||||
else
|
||||
} else
|
||||
mineRecord.charHash = character.getName();
|
||||
|
||||
DataWarehouse.hasher.encrypt(0);
|
||||
|
||||
@@ -28,286 +28,285 @@ import static engine.Enum.PvpHistoryType;
|
||||
|
||||
public class PvpRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<PvpRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private static final LinkedBlockingQueue<PvpRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private PlayerCharacter player;
|
||||
private PlayerCharacter victim;
|
||||
private Vector3fImmutable location;
|
||||
private boolean pvpExp;
|
||||
private PlayerCharacter player;
|
||||
private PlayerCharacter victim;
|
||||
private Vector3fImmutable location;
|
||||
private boolean pvpExp;
|
||||
|
||||
private PvpRecord(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
this.recordType = DataRecordType.PVP;
|
||||
this.player = player;
|
||||
this.victim = victim;
|
||||
this.location = new Vector3fImmutable(location);
|
||||
this.pvpExp = pvpExp;
|
||||
}
|
||||
private PvpRecord(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
this.recordType = DataRecordType.PVP;
|
||||
this.player = player;
|
||||
this.victim = victim;
|
||||
this.location = new Vector3fImmutable(location);
|
||||
this.pvpExp = pvpExp;
|
||||
}
|
||||
|
||||
public static PvpRecord borrow(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
public static PvpRecord borrow(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
|
||||
PvpRecord pvpRecord;
|
||||
PvpRecord pvpRecord;
|
||||
|
||||
pvpRecord = recordPool.poll();
|
||||
pvpRecord = recordPool.poll();
|
||||
|
||||
if (pvpRecord == null) {
|
||||
pvpRecord = new PvpRecord(player, victim, location, pvpExp);
|
||||
}
|
||||
else {
|
||||
pvpRecord.recordType = DataRecordType.PVP;
|
||||
pvpRecord.player = player;
|
||||
pvpRecord.victim = victim;
|
||||
pvpRecord.location = new Vector3fImmutable(location);
|
||||
pvpRecord.pvpExp = pvpExp;
|
||||
}
|
||||
if (pvpRecord == null) {
|
||||
pvpRecord = new PvpRecord(player, victim, location, pvpExp);
|
||||
} else {
|
||||
pvpRecord.recordType = DataRecordType.PVP;
|
||||
pvpRecord.player = player;
|
||||
pvpRecord.victim = victim;
|
||||
pvpRecord.location = new Vector3fImmutable(location);
|
||||
pvpRecord.pvpExp = pvpExp;
|
||||
}
|
||||
|
||||
return pvpRecord;
|
||||
}
|
||||
return pvpRecord;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildHistoryStatement(Connection connection, int charUUID, PvpHistoryType historyType) throws SQLException {
|
||||
private static PreparedStatement buildHistoryStatement(Connection connection, int charUUID, PvpHistoryType historyType) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "";
|
||||
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
queryString = "SELECT DISTINCT `victim_id`, `datetime` FROM warehouse_pvphistory where char_id = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
case DEATHS:
|
||||
queryString = "SELECT DISTINCT `char_id`,`datetime` FROM warehouse_pvphistory where `victim_id` = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
}
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
queryString = "SELECT DISTINCT `victim_id`, `datetime` FROM warehouse_pvphistory where char_id = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
case DEATHS:
|
||||
queryString = "SELECT DISTINCT `char_id`,`datetime` FROM warehouse_pvphistory where `victim_id` = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
}
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static LinkedList<Integer> getCharacterPvPHistory(int charUUID, PvpHistoryType historyType) {
|
||||
public static LinkedList<Integer> getCharacterPvPHistory(int charUUID, PvpHistoryType historyType) {
|
||||
|
||||
// Member variable declaration
|
||||
// Member variable declaration
|
||||
|
||||
LinkedList<Integer> outList = new LinkedList<>();
|
||||
LinkedList<Integer> outList = new LinkedList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]);
|
||||
break;
|
||||
case DEATHS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]);
|
||||
break;
|
||||
case DEATHS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildLuaHistoryQueryStatement(Connection connection, int charUUID) throws SQLException {
|
||||
private static PreparedStatement buildLuaHistoryQueryStatement(Connection connection, int charUUID) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "CALL `pvpHistory`(?)";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "CALL `pvpHistory`(?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static String getPvpHistoryString(int charUUID) {
|
||||
public static String getPvpHistoryString(int charUUID) {
|
||||
|
||||
String outString;
|
||||
String dividerString;
|
||||
String outString;
|
||||
String dividerString;
|
||||
|
||||
String newLine = System.getProperty("line.separator");
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
int killCount;
|
||||
int deathCount;
|
||||
float killRatio;
|
||||
int killCount;
|
||||
int deathCount;
|
||||
float killRatio;
|
||||
|
||||
outString += "Total Magicbane murdered souls: " + rs.getInt("TOTALDEATHS") + newLine;
|
||||
outString += dividerString;
|
||||
outString += String.format("%-8s %-8s %-8s %-8s %n", "Period", "Kills", "Deaths", "K/D");
|
||||
outString += dividerString;
|
||||
outString += "Total Magicbane murdered souls: " + rs.getInt("TOTALDEATHS") + newLine;
|
||||
outString += dividerString;
|
||||
outString += String.format("%-8s %-8s %-8s %-8s %n", "Period", "Kills", "Deaths", "K/D");
|
||||
outString += dividerString;
|
||||
|
||||
killCount = rs.getInt("KILLCOUNT");
|
||||
deathCount = rs.getInt("DEATHCOUNT");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
killCount = rs.getInt("KILLCOUNT");
|
||||
deathCount = rs.getInt("DEATHCOUNT");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
try {
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "Total", killCount, deathCount, killRatio);
|
||||
try {
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "Total", killCount, deathCount, killRatio);
|
||||
|
||||
killCount = rs.getInt("DAILYKILLS");
|
||||
deathCount = rs.getInt("DAILYDEATHS");
|
||||
killCount = rs.getInt("DAILYKILLS");
|
||||
deathCount = rs.getInt("DAILYDEATHS");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "24hrs", killCount, deathCount, killRatio);
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "24hrs", killCount, deathCount, killRatio);
|
||||
|
||||
killCount = rs.getInt("HOURLYKILLS");
|
||||
deathCount = rs.getInt("HOURLYDEATHS");
|
||||
killCount = rs.getInt("HOURLYKILLS");
|
||||
deathCount = rs.getInt("HOURLYDEATHS");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "1hr", killCount, deathCount, killRatio);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "1hr", killCount, deathCount, killRatio);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return outString;
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildPvpPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
public static PreparedStatement buildPvpPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`event_number`, `char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`event_number`, `char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("char_id"));
|
||||
outStatement.setString(3, rs.getString("char_guild_id"));
|
||||
outStatement.setString(4, rs.getString("char_nation_id"));
|
||||
outStatement.setInt(5, rs.getInt("char_level"));
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("char_id"));
|
||||
outStatement.setString(3, rs.getString("char_guild_id"));
|
||||
outStatement.setString(4, rs.getString("char_nation_id"));
|
||||
outStatement.setInt(5, rs.getInt("char_level"));
|
||||
|
||||
// Bind victim data
|
||||
// Bind victim data
|
||||
|
||||
outStatement.setString(6, rs.getString("victim_id"));
|
||||
outStatement.setString(7, rs.getString("victim_guild_id"));
|
||||
outStatement.setString(8, rs.getString("victim_nation_id"));
|
||||
outStatement.setInt(9, rs.getInt("victim_level"));
|
||||
outStatement.setString(6, rs.getString("victim_id"));
|
||||
outStatement.setString(7, rs.getString("victim_guild_id"));
|
||||
outStatement.setString(8, rs.getString("victim_nation_id"));
|
||||
outStatement.setInt(9, rs.getInt("victim_level"));
|
||||
|
||||
outStatement.setString(10, rs.getString("zone_id"));
|
||||
outStatement.setString(11, rs.getString("zone_name"));
|
||||
outStatement.setFloat(12, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(13, rs.getFloat("loc_y"));
|
||||
outStatement.setBoolean(14, rs.getBoolean("gave_exp"));
|
||||
outStatement.setTimestamp(15, rs.getTimestamp("datetime"));
|
||||
outStatement.setString(10, rs.getString("zone_id"));
|
||||
outStatement.setString(11, rs.getString("zone_name"));
|
||||
outStatement.setFloat(12, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(13, rs.getFloat("loc_y"));
|
||||
outStatement.setBoolean(14, rs.getBoolean("gave_exp"));
|
||||
outStatement.setTimestamp(15, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildPvpQueryStatement(Connection connection) throws SQLException {
|
||||
public static PreparedStatement buildPvpQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_pvphistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.pvpIndex);
|
||||
return outStatement;
|
||||
}
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_pvphistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.pvpIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.player = null;
|
||||
this.victim = null;
|
||||
this.location = Vector3fImmutable.ZERO;
|
||||
pvpExp = false;
|
||||
}
|
||||
void reset() {
|
||||
this.player = null;
|
||||
this.victim = null;
|
||||
this.location = Vector3fImmutable.ZERO;
|
||||
pvpExp = false;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
private PreparedStatement buildPvPInsertStatement(Connection connection) throws SQLException {
|
||||
private PreparedStatement buildPvPInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
Guild charGuild;
|
||||
Guild victimGuild;
|
||||
Zone zone;
|
||||
PreparedStatement outStatement = null;
|
||||
Guild charGuild;
|
||||
Guild victimGuild;
|
||||
Zone zone;
|
||||
PreparedStatement outStatement = null;
|
||||
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
charGuild = this.player.getGuild();
|
||||
victimGuild = this.victim.getGuild();
|
||||
charGuild = this.player.getGuild();
|
||||
victimGuild = this.victim.getGuild();
|
||||
|
||||
// Use a proxy in the situation where a char guild is null (errant)
|
||||
// Use a proxy in the situation where a char guild is null (errant)
|
||||
|
||||
|
||||
// Retrieve the zone name where the PvP event occurred
|
||||
|
||||
zone = ZoneManager.findSmallestZone(this.location);
|
||||
// Retrieve the zone name where the PvP event occurred
|
||||
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(this.player.getObjectUUID()));
|
||||
outStatement.setString(2, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID()));
|
||||
outStatement.setString(3, DataWarehouse.hasher.encrypt(charGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(4, this.player.getLevel());
|
||||
zone = ZoneManager.findSmallestZone(this.location);
|
||||
|
||||
// Bind victim data
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(this.player.getObjectUUID()));
|
||||
outStatement.setString(2, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID()));
|
||||
outStatement.setString(3, DataWarehouse.hasher.encrypt(charGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(4, this.player.getLevel());
|
||||
|
||||
outStatement.setString(5, DataWarehouse.hasher.encrypt(this.victim.getObjectUUID()));
|
||||
outStatement.setString(6, DataWarehouse.hasher.encrypt(victimGuild.getObjectUUID()));
|
||||
outStatement.setString(7, DataWarehouse.hasher.encrypt(victimGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(8, this.victim.getLevel());
|
||||
// Bind victim data
|
||||
|
||||
outStatement.setString(9, DataWarehouse.hasher.encrypt(zone.getObjectUUID()));
|
||||
outStatement.setString(10, zone.getName());
|
||||
outStatement.setFloat(11, this.location.getX());
|
||||
outStatement.setFloat(12, -this.location.getZ()); // flip sign on 'y' coordinate
|
||||
outStatement.setBoolean(13, this.pvpExp);
|
||||
outStatement.setTimestamp(14, Timestamp.valueOf(LocalDateTime.now()));
|
||||
outStatement.setString(5, DataWarehouse.hasher.encrypt(this.victim.getObjectUUID()));
|
||||
outStatement.setString(6, DataWarehouse.hasher.encrypt(victimGuild.getObjectUUID()));
|
||||
outStatement.setString(7, DataWarehouse.hasher.encrypt(victimGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(8, this.victim.getLevel());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
outStatement.setString(9, DataWarehouse.hasher.encrypt(zone.getObjectUUID()));
|
||||
outStatement.setString(10, zone.getName());
|
||||
outStatement.setFloat(11, this.location.getX());
|
||||
outStatement.setFloat(12, -this.location.getZ()); // flip sign on 'y' coordinate
|
||||
outStatement.setBoolean(13, this.pvpExp);
|
||||
outStatement.setTimestamp(14, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildPvPInsertStatement(connection)) {
|
||||
public void write() {
|
||||
|
||||
statement.execute();
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildPvPInsertStatement(connection)) {
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
statement.execute();
|
||||
|
||||
// Warehouse record for this pvp event written if code path reaches here.
|
||||
// Time to update the respective kill counters.
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
CharacterRecord.advanceKillCounter(this.player);
|
||||
CharacterRecord.advanceDeathCounter(this.victim);
|
||||
// Warehouse record for this pvp event written if code path reaches here.
|
||||
// Time to update the respective kill counters.
|
||||
|
||||
}
|
||||
CharacterRecord.advanceKillCounter(this.player);
|
||||
CharacterRecord.advanceDeathCounter(this.victim);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ public class RealmRecord extends DataRecord {
|
||||
if (realmRecord == null) {
|
||||
realmRecord = new RealmRecord(realm);
|
||||
realmRecord.eventType = eventType;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
realmRecord.recordType = Enum.DataRecordType.REALM;
|
||||
realmRecord.eventType = eventType;
|
||||
realmRecord.realm = realm;
|
||||
@@ -57,7 +56,7 @@ public class RealmRecord extends DataRecord {
|
||||
realmRecord.charterType = Enum.CharterType.getCharterTypeByID(realmRecord.realm.getCharterType()).name();
|
||||
|
||||
if (realmRecord.eventType.equals(Enum.RecordEventType.CAPTURE))
|
||||
realmRecord.eventDateTime = realm.ruledSince;
|
||||
realmRecord.eventDateTime = realm.ruledSince;
|
||||
else
|
||||
realmRecord.eventDateTime = LocalDateTime.now();
|
||||
|
||||
@@ -122,7 +121,7 @@ public class RealmRecord extends DataRecord {
|
||||
outStatement.setString(4, cityHash);
|
||||
outStatement.setString(5, guildHash);
|
||||
outStatement.setString(6, eventType.name());
|
||||
outStatement.setTimestamp(7, Timestamp.valueOf(this.eventDateTime));
|
||||
outStatement.setTimestamp(7, Timestamp.valueOf(this.eventDateTime));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
@@ -21,31 +21,31 @@ import java.util.ArrayList;
|
||||
|
||||
public class dbBoonHandler extends dbHandlerBase {
|
||||
|
||||
public dbBoonHandler() {
|
||||
}
|
||||
public dbBoonHandler() {
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Boon> GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) {
|
||||
public ArrayList<Boon> GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) {
|
||||
|
||||
ArrayList<Boon> boons = new ArrayList<>();
|
||||
Boon thisBoon;
|
||||
ArrayList<Boon> boons = new ArrayList<>();
|
||||
Boon thisBoon;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBaseUUID);
|
||||
preparedStatement.setInt(1, itemBaseUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
thisBoon = new Boon(rs);
|
||||
boons.add(thisBoon);
|
||||
}
|
||||
while (rs.next()) {
|
||||
thisBoon = new Boon(rs);
|
||||
boons.add(thisBoon);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return boons;
|
||||
}
|
||||
return boons;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,91 +24,91 @@ import java.sql.SQLException;
|
||||
|
||||
public class dbCSSessionHandler extends dbHandlerBase {
|
||||
|
||||
public dbCSSessionHandler() {
|
||||
this.localClass = CSSession.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
public dbCSSessionHandler() {
|
||||
this.localClass = CSSession.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) {
|
||||
public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
preparedStatement.setLong(2, acc.getObjectUUID());
|
||||
preparedStatement.setString(3, acc.discordAccount);
|
||||
preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet));
|
||||
preparedStatement.setString(5, machineID);
|
||||
preparedStatement.setString(1, secKey);
|
||||
preparedStatement.setLong(2, acc.getObjectUUID());
|
||||
preparedStatement.setString(3, acc.discordAccount);
|
||||
preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet));
|
||||
preparedStatement.setString(5, machineID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean DELETE_UNUSED_CSSESSION(String secKey) {
|
||||
public boolean DELETE_UNUSED_CSSESSION(String secKey) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean DELETE_CSSESSION(String secKey) {
|
||||
public boolean DELETE_CSSESSION(String secKey) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_CSSESSION(String secKey, int charID) {
|
||||
public boolean UPDATE_CSSESSION(String secKey, int charID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, charID);
|
||||
preparedStatement.setString(2, secKey);
|
||||
preparedStatement.setInt(1, charID);
|
||||
preparedStatement.setString(2, secKey);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CSSession GET_CSSESSION(String secKey) {
|
||||
public CSSession GET_CSSESSION(String secKey) {
|
||||
|
||||
CSSession css = null;
|
||||
CSSession css = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
preparedStatement.setString(1, secKey);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID"));
|
||||
if (rs.next())
|
||||
css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return css;
|
||||
}
|
||||
return css;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,152 +22,152 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbCharacterSkillHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterSkillHandler() {
|
||||
this.localClass = CharacterSkill.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
public dbCharacterSkillHandler() {
|
||||
this.localClass = CharacterSkill.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterSkill ADD_SKILL(CharacterSkill toAdd) {
|
||||
public CharacterSkill ADD_SKILL(CharacterSkill toAdd) {
|
||||
|
||||
CharacterSkill characterSkill = null;
|
||||
CharacterSkill characterSkill = null;
|
||||
|
||||
if (CharacterSkill.GetOwner(toAdd) == null || toAdd.getSkillsBase() == null) {
|
||||
Logger.error("dbCharacterSkillHandler.ADD_SKILL", toAdd.getObjectUUID() + " missing owner or skillsBase");
|
||||
return null;
|
||||
}
|
||||
if (CharacterSkill.GetOwner(toAdd) == null || toAdd.getSkillsBase() == null) {
|
||||
Logger.error("dbCharacterSkillHandler.ADD_SKILL", toAdd.getObjectUUID() + " missing owner or skillsBase");
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_skill` (`CharacterID`, `skillsBaseID`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_skill` (`CharacterID`, `skillsBaseID`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, CharacterSkill.GetOwner(toAdd).getObjectUUID());
|
||||
preparedStatement.setInt(2, toAdd.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(3, toAdd.getNumTrains());
|
||||
preparedStatement.setLong(1, CharacterSkill.GetOwner(toAdd).getObjectUUID());
|
||||
preparedStatement.setInt(2, toAdd.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(3, toAdd.getNumTrains());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterSkill = GET_SKILL(rs.getInt(1));
|
||||
if (rs.next())
|
||||
characterSkill = GET_SKILL(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
|
||||
public boolean DELETE_SKILL(final int objectUUID) {
|
||||
public boolean DELETE_SKILL(final int objectUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CharacterSkill GET_SKILL(final int objectUUID) {
|
||||
public CharacterSkill GET_SKILL(final int objectUUID) {
|
||||
|
||||
CharacterSkill characterSkill = (CharacterSkill) DbManager.getFromCache(Enum.GameObjectType.CharacterSkill, objectUUID);
|
||||
CharacterSkill characterSkill = (CharacterSkill) DbManager.getFromCache(Enum.GameObjectType.CharacterSkill, objectUUID);
|
||||
|
||||
if (characterSkill != null)
|
||||
return characterSkill;
|
||||
if (characterSkill != null)
|
||||
return characterSkill;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
characterSkill = (CharacterSkill) getObjectFromRs(rs);
|
||||
characterSkill = (CharacterSkill) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, CharacterSkill> GET_SKILLS_FOR_CHARACTER(final AbstractCharacter ac) {
|
||||
public ConcurrentHashMap<String, CharacterSkill> GET_SKILLS_FOR_CHARACTER(final AbstractCharacter ac) {
|
||||
|
||||
ConcurrentHashMap<String, CharacterSkill> characterSkills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
ConcurrentHashMap<String, CharacterSkill> characterSkills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
if (ac == null || (!(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))))
|
||||
return characterSkills;
|
||||
if (ac == null || (!(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))))
|
||||
return characterSkills;
|
||||
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) ac;
|
||||
int characterId = playerCharacter.getObjectUUID();
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) ac;
|
||||
int characterId = playerCharacter.getObjectUUID();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `CharacterID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterId);
|
||||
preparedStatement.setInt(1, characterId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
CharacterSkill cs = new CharacterSkill(rs, playerCharacter);
|
||||
if (cs.getSkillsBase() != null)
|
||||
characterSkills.put(cs.getSkillsBase().getName(), cs);
|
||||
}
|
||||
while (rs.next()) {
|
||||
CharacterSkill cs = new CharacterSkill(rs, playerCharacter);
|
||||
if (cs.getSkillsBase() != null)
|
||||
characterSkills.put(cs.getSkillsBase().getName(), cs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterSkills;
|
||||
}
|
||||
return characterSkills;
|
||||
}
|
||||
|
||||
|
||||
public void UPDATE_TRAINS(final CharacterSkill characterSkill) {
|
||||
public void UPDATE_TRAINS(final CharacterSkill characterSkill) {
|
||||
|
||||
if (!characterSkill.isTrained())
|
||||
return;
|
||||
if (!characterSkill.isTrained())
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setShort(1, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(2, characterSkill.getObjectUUID());
|
||||
preparedStatement.setShort(1, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(2, characterSkill.getObjectUUID());
|
||||
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterSkill characterSkill) {
|
||||
public void updateDatabase(final CharacterSkill characterSkill) {
|
||||
|
||||
if (characterSkill.getSkillsBase() == null) {
|
||||
Logger.error("Failed to find skillsBase for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
if (characterSkill.getSkillsBase() == null) {
|
||||
Logger.error("Failed to find skillsBase for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CharacterSkill.GetOwner(characterSkill) == null) {
|
||||
Logger.error("Failed to find owner for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
if (CharacterSkill.GetOwner(characterSkill) == null) {
|
||||
Logger.error("Failed to find owner for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `skillsBaseID`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `skillsBaseID`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID());
|
||||
preparedStatement.setShort(3, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(4, characterSkill.getObjectUUID());
|
||||
preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID());
|
||||
preparedStatement.setShort(3, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(4, characterSkill.getObjectUUID());
|
||||
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,146 +23,146 @@ import java.sql.SQLException;
|
||||
|
||||
public class dbContractHandler extends dbHandlerBase {
|
||||
|
||||
public dbContractHandler() {
|
||||
this.localClass = Contract.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
public dbContractHandler() {
|
||||
this.localClass = Contract.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Contract GET_CONTRACT(final int objectUUID) {
|
||||
public Contract GET_CONTRACT(final int objectUUID) {
|
||||
|
||||
Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID);
|
||||
Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID);
|
||||
|
||||
if (contract != null)
|
||||
return contract;
|
||||
if (contract != null)
|
||||
return contract;
|
||||
|
||||
if (objectUUID == 0)
|
||||
return null;
|
||||
if (objectUUID == 0)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract` WHERE `ID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
contract = (Contract) getObjectFromRs(rs);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
contract = (Contract) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
public void LOAD_CONTRACT_INVENTORY(final Contract contract) {
|
||||
public void LOAD_CONTRACT_INVENTORY(final Contract contract) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, contract.inventorySet);
|
||||
preparedStatement.setInt(1, contract.inventorySet);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
//handle item base
|
||||
int itemBaseID = rs.getInt("itembaseID");
|
||||
//handle item base
|
||||
int itemBaseID = rs.getInt("itembaseID");
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
|
||||
if (ib != null) {
|
||||
if (ib != null) {
|
||||
|
||||
MobEquipment me = new MobEquipment(ib, 0, 0);
|
||||
contract.getSellInventory().add(me);
|
||||
MobEquipment me = new MobEquipment(ib, 0, 0);
|
||||
contract.getSellInventory().add(me);
|
||||
|
||||
//handle magic effects
|
||||
String prefix = rs.getString("prefix");
|
||||
int pRank = rs.getInt("pRank");
|
||||
String suffix = rs.getString("suffix");
|
||||
int sRank = rs.getInt("sRank");
|
||||
//handle magic effects
|
||||
String prefix = rs.getString("prefix");
|
||||
int pRank = rs.getInt("pRank");
|
||||
String suffix = rs.getString("suffix");
|
||||
int sRank = rs.getInt("sRank");
|
||||
|
||||
if (prefix != null) {
|
||||
me.setPrefix(prefix, pRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
if (prefix != null) {
|
||||
me.setPrefix(prefix, pRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
|
||||
if (suffix != null) {
|
||||
me.setSuffix(suffix, sRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
if (suffix != null) {
|
||||
me.setSuffix(suffix, sRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) {
|
||||
public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, contract.getObjectUUID());
|
||||
preparedStatement.setInt(1, contract.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
int type = rs.getInt("type");
|
||||
int value = rs.getInt("value");
|
||||
int type = rs.getInt("type");
|
||||
int value = rs.getInt("value");
|
||||
|
||||
switch (type) {
|
||||
case 1:
|
||||
contract.getBuyItemType().add(value);
|
||||
break;
|
||||
case 2:
|
||||
contract.getBuySkillToken().add(value);
|
||||
break;
|
||||
case 3:
|
||||
contract.getBuyUnknownToken().add(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case 1:
|
||||
contract.getBuyItemType().add(value);
|
||||
break;
|
||||
case 2:
|
||||
contract.getBuySkillToken().add(value);
|
||||
break;
|
||||
case 3:
|
||||
contract.getBuyUnknownToken().add(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) {
|
||||
public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, slotbitvalue);
|
||||
preparedStatement.setInt(2, con.getContractID());
|
||||
preparedStatement.setLong(1, slotbitvalue);
|
||||
preparedStatement.setInt(2, con.getContractID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateDatabase(final Contract con) {
|
||||
public boolean updateDatabase(final Contract con) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, "
|
||||
+ "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, "
|
||||
+ "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, con.getContractID());
|
||||
preparedStatement.setString(2, con.getName());
|
||||
preparedStatement.setInt(3, con.getMobbaseID());
|
||||
preparedStatement.setInt(4, con.getClassID());
|
||||
preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(6, con.getIconID());
|
||||
preparedStatement.setInt(8, con.getObjectUUID());
|
||||
preparedStatement.setLong(7, con.getAllowedBuildings().toLong());
|
||||
preparedStatement.setInt(1, con.getContractID());
|
||||
preparedStatement.setString(2, con.getName());
|
||||
preparedStatement.setInt(3, con.getMobbaseID());
|
||||
preparedStatement.setInt(4, con.getClassID());
|
||||
preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(6, con.getIconID());
|
||||
preparedStatement.setInt(8, con.getObjectUUID());
|
||||
preparedStatement.setLong(7, con.getAllowedBuildings().toLong());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,277 +27,277 @@ public class dbEffectsBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbEffectsBaseHandler() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<EffectsBase> getAllEffectsBase() {
|
||||
public static ArrayList<EffectsBase> getAllEffectsBase() {
|
||||
|
||||
ArrayList<EffectsBase> effectList = new ArrayList<>();
|
||||
ArrayList<EffectsBase> effectList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) {
|
||||
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
EffectsBase effectBase = new EffectsBase(rs);
|
||||
effectList.add(effectBase);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
while (rs.next()) {
|
||||
EffectsBase effectBase = new EffectsBase(rs);
|
||||
effectList.add(effectBase);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return effectList;
|
||||
}
|
||||
return effectList;
|
||||
}
|
||||
|
||||
public static void cacheAllEffectModifiers() {
|
||||
public static void cacheAllEffectModifiers() {
|
||||
|
||||
String IDString;
|
||||
AbstractEffectModifier abstractEffectModifier = null;
|
||||
String IDString;
|
||||
AbstractEffectModifier abstractEffectModifier = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) {
|
||||
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
IDString = rs.getString("IDString");
|
||||
EffectsBase effectBase = PowersManager.getEffectByIDString(IDString);
|
||||
Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType"));
|
||||
IDString = rs.getString("IDString");
|
||||
EffectsBase effectBase = PowersManager.getEffectByIDString(IDString);
|
||||
Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType"));
|
||||
|
||||
//combine item prefix and suffix effect modifiers
|
||||
//combine item prefix and suffix effect modifiers
|
||||
|
||||
abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier);
|
||||
abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier);
|
||||
|
||||
if (abstractEffectModifier != null) {
|
||||
if (abstractEffectModifier != null) {
|
||||
|
||||
if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false)
|
||||
EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>());
|
||||
if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false)
|
||||
EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>());
|
||||
|
||||
EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier);
|
||||
EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException {
|
||||
switch (modifier) {
|
||||
case AdjustAboveDmgCap:
|
||||
abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs);
|
||||
break;
|
||||
case Ambidexterity:
|
||||
abstractEffectModifier = new AmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case AnimOverride:
|
||||
break;
|
||||
case ArmorPiercing:
|
||||
abstractEffectModifier = new ArmorPiercingEffectModifier(rs);
|
||||
break;
|
||||
case AttackDelay:
|
||||
abstractEffectModifier = new AttackDelayEffectModifier(rs);
|
||||
break;
|
||||
case Attr:
|
||||
abstractEffectModifier = new AttributeEffectModifier(rs);
|
||||
break;
|
||||
case BlackMantle:
|
||||
abstractEffectModifier = new BlackMantleEffectModifier(rs);
|
||||
break;
|
||||
case BladeTrails:
|
||||
abstractEffectModifier = new BladeTrailsEffectModifier(rs);
|
||||
break;
|
||||
case Block:
|
||||
abstractEffectModifier = new BlockEffectModifier(rs);
|
||||
break;
|
||||
case BlockedPowerType:
|
||||
abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs);
|
||||
break;
|
||||
case CannotAttack:
|
||||
abstractEffectModifier = new CannotAttackEffectModifier(rs);
|
||||
break;
|
||||
case CannotCast:
|
||||
abstractEffectModifier = new CannotCastEffectModifier(rs);
|
||||
break;
|
||||
case CannotMove:
|
||||
abstractEffectModifier = new CannotMoveEffectModifier(rs);
|
||||
break;
|
||||
case CannotTrack:
|
||||
abstractEffectModifier = new CannotTrackEffectModifier(rs);
|
||||
break;
|
||||
case Charmed:
|
||||
abstractEffectModifier = new CharmedEffectModifier(rs);
|
||||
break;
|
||||
case ConstrainedAmbidexterity:
|
||||
abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case DamageCap:
|
||||
abstractEffectModifier = new DamageCapEffectModifier(rs);
|
||||
break;
|
||||
case DamageShield:
|
||||
abstractEffectModifier = new DamageShieldEffectModifier(rs);
|
||||
break;
|
||||
case DCV:
|
||||
abstractEffectModifier = new DCVEffectModifier(rs);
|
||||
break;
|
||||
case Dodge:
|
||||
abstractEffectModifier = new DodgeEffectModifier(rs);
|
||||
break;
|
||||
case DR:
|
||||
abstractEffectModifier = new DREffectModifier(rs);
|
||||
break;
|
||||
case Durability:
|
||||
abstractEffectModifier = new DurabilityEffectModifier(rs);
|
||||
break;
|
||||
case ExclusiveDamageCap:
|
||||
abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case Fade:
|
||||
abstractEffectModifier = new FadeEffectModifier(rs);
|
||||
break;
|
||||
case Fly:
|
||||
abstractEffectModifier = new FlyEffectModifier(rs);
|
||||
break;
|
||||
case Health:
|
||||
abstractEffectModifier = new HealthEffectModifier(rs);
|
||||
break;
|
||||
case HealthFull:
|
||||
abstractEffectModifier = new HealthFullEffectModifier(rs);
|
||||
break;
|
||||
case HealthRecoverRate:
|
||||
abstractEffectModifier = new HealthRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case IgnoreDamageCap:
|
||||
abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case IgnorePassiveDefense:
|
||||
abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneTo:
|
||||
abstractEffectModifier = new ImmuneToEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToAttack:
|
||||
abstractEffectModifier = new ImmuneToAttackEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToPowers:
|
||||
abstractEffectModifier = new ImmuneToPowersEffectModifier(rs);
|
||||
break;
|
||||
case Invisible:
|
||||
abstractEffectModifier = new InvisibleEffectModifier(rs);
|
||||
break;
|
||||
case ItemName:
|
||||
abstractEffectModifier = new ItemNameEffectModifier(rs);
|
||||
if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty())
|
||||
break;
|
||||
if (effectBase != null)
|
||||
effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name));
|
||||
break;
|
||||
case Mana:
|
||||
abstractEffectModifier = new ManaEffectModifier(rs);
|
||||
break;
|
||||
case ManaFull:
|
||||
abstractEffectModifier = new ManaFullEffectModifier(rs);
|
||||
break;
|
||||
case ManaRecoverRate:
|
||||
abstractEffectModifier = new ManaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case MaxDamage:
|
||||
abstractEffectModifier = new MaxDamageEffectModifier(rs);
|
||||
break;
|
||||
case MeleeDamageModifier:
|
||||
abstractEffectModifier = new MeleeDamageEffectModifier(rs);
|
||||
break;
|
||||
case MinDamage:
|
||||
abstractEffectModifier = new MinDamageEffectModifier(rs);
|
||||
break;
|
||||
case NoMod:
|
||||
abstractEffectModifier = new NoModEffectModifier(rs);
|
||||
break;
|
||||
case OCV:
|
||||
abstractEffectModifier = new OCVEffectModifier(rs);
|
||||
break;
|
||||
case Parry:
|
||||
abstractEffectModifier = new ParryEffectModifier(rs);
|
||||
break;
|
||||
case PassiveDefense:
|
||||
abstractEffectModifier = new PassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case PowerCost:
|
||||
abstractEffectModifier = new PowerCostEffectModifier(rs);
|
||||
break;
|
||||
case PowerCostHealth:
|
||||
abstractEffectModifier = new PowerCostHealthEffectModifier(rs);
|
||||
break;
|
||||
case PowerDamageModifier:
|
||||
abstractEffectModifier = new PowerDamageEffectModifier(rs);
|
||||
break;
|
||||
case ProtectionFrom:
|
||||
abstractEffectModifier = new ProtectionFromEffectModifier(rs);
|
||||
break;
|
||||
case Resistance:
|
||||
abstractEffectModifier = new ResistanceEffectModifier(rs);
|
||||
break;
|
||||
case ScaleHeight:
|
||||
abstractEffectModifier = new ScaleHeightEffectModifier(rs);
|
||||
break;
|
||||
case ScaleWidth:
|
||||
abstractEffectModifier = new ScaleWidthEffectModifier(rs);
|
||||
break;
|
||||
case ScanRange:
|
||||
abstractEffectModifier = new ScanRangeEffectModifier(rs);
|
||||
break;
|
||||
case SeeInvisible:
|
||||
abstractEffectModifier = new SeeInvisibleEffectModifier(rs);
|
||||
break;
|
||||
case Silenced:
|
||||
abstractEffectModifier = new SilencedEffectModifier(rs);
|
||||
break;
|
||||
case Skill:
|
||||
abstractEffectModifier = new SkillEffectModifier(rs);
|
||||
break;
|
||||
case Slay:
|
||||
abstractEffectModifier = new SlayEffectModifier(rs);
|
||||
break;
|
||||
case Speed:
|
||||
abstractEffectModifier = new SpeedEffectModifier(rs);
|
||||
break;
|
||||
case SpireBlock:
|
||||
abstractEffectModifier = new SpireBlockEffectModifier(rs);
|
||||
break;
|
||||
case Stamina:
|
||||
abstractEffectModifier = new StaminaEffectModifier(rs);
|
||||
break;
|
||||
case StaminaFull:
|
||||
abstractEffectModifier = new StaminaFullEffectModifier(rs);
|
||||
break;
|
||||
case StaminaRecoverRate:
|
||||
abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case Stunned:
|
||||
abstractEffectModifier = new StunnedEffectModifier(rs);
|
||||
break;
|
||||
case Value:
|
||||
abstractEffectModifier = new ValueEffectModifier(rs);
|
||||
if (effectBase != null) {
|
||||
ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier;
|
||||
effectBase.setValue(valueEffect.minMod);
|
||||
}
|
||||
break;
|
||||
case WeaponProc:
|
||||
abstractEffectModifier = new WeaponProcEffectModifier(rs);
|
||||
break;
|
||||
case WeaponRange:
|
||||
abstractEffectModifier = new WeaponRangeEffectModifier(rs);
|
||||
break;
|
||||
case WeaponSpeed:
|
||||
abstractEffectModifier = new WeaponSpeedEffectModifier(rs);
|
||||
break;
|
||||
private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException {
|
||||
switch (modifier) {
|
||||
case AdjustAboveDmgCap:
|
||||
abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs);
|
||||
break;
|
||||
case Ambidexterity:
|
||||
abstractEffectModifier = new AmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case AnimOverride:
|
||||
break;
|
||||
case ArmorPiercing:
|
||||
abstractEffectModifier = new ArmorPiercingEffectModifier(rs);
|
||||
break;
|
||||
case AttackDelay:
|
||||
abstractEffectModifier = new AttackDelayEffectModifier(rs);
|
||||
break;
|
||||
case Attr:
|
||||
abstractEffectModifier = new AttributeEffectModifier(rs);
|
||||
break;
|
||||
case BlackMantle:
|
||||
abstractEffectModifier = new BlackMantleEffectModifier(rs);
|
||||
break;
|
||||
case BladeTrails:
|
||||
abstractEffectModifier = new BladeTrailsEffectModifier(rs);
|
||||
break;
|
||||
case Block:
|
||||
abstractEffectModifier = new BlockEffectModifier(rs);
|
||||
break;
|
||||
case BlockedPowerType:
|
||||
abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs);
|
||||
break;
|
||||
case CannotAttack:
|
||||
abstractEffectModifier = new CannotAttackEffectModifier(rs);
|
||||
break;
|
||||
case CannotCast:
|
||||
abstractEffectModifier = new CannotCastEffectModifier(rs);
|
||||
break;
|
||||
case CannotMove:
|
||||
abstractEffectModifier = new CannotMoveEffectModifier(rs);
|
||||
break;
|
||||
case CannotTrack:
|
||||
abstractEffectModifier = new CannotTrackEffectModifier(rs);
|
||||
break;
|
||||
case Charmed:
|
||||
abstractEffectModifier = new CharmedEffectModifier(rs);
|
||||
break;
|
||||
case ConstrainedAmbidexterity:
|
||||
abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case DamageCap:
|
||||
abstractEffectModifier = new DamageCapEffectModifier(rs);
|
||||
break;
|
||||
case DamageShield:
|
||||
abstractEffectModifier = new DamageShieldEffectModifier(rs);
|
||||
break;
|
||||
case DCV:
|
||||
abstractEffectModifier = new DCVEffectModifier(rs);
|
||||
break;
|
||||
case Dodge:
|
||||
abstractEffectModifier = new DodgeEffectModifier(rs);
|
||||
break;
|
||||
case DR:
|
||||
abstractEffectModifier = new DREffectModifier(rs);
|
||||
break;
|
||||
case Durability:
|
||||
abstractEffectModifier = new DurabilityEffectModifier(rs);
|
||||
break;
|
||||
case ExclusiveDamageCap:
|
||||
abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case Fade:
|
||||
abstractEffectModifier = new FadeEffectModifier(rs);
|
||||
break;
|
||||
case Fly:
|
||||
abstractEffectModifier = new FlyEffectModifier(rs);
|
||||
break;
|
||||
case Health:
|
||||
abstractEffectModifier = new HealthEffectModifier(rs);
|
||||
break;
|
||||
case HealthFull:
|
||||
abstractEffectModifier = new HealthFullEffectModifier(rs);
|
||||
break;
|
||||
case HealthRecoverRate:
|
||||
abstractEffectModifier = new HealthRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case IgnoreDamageCap:
|
||||
abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case IgnorePassiveDefense:
|
||||
abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneTo:
|
||||
abstractEffectModifier = new ImmuneToEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToAttack:
|
||||
abstractEffectModifier = new ImmuneToAttackEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToPowers:
|
||||
abstractEffectModifier = new ImmuneToPowersEffectModifier(rs);
|
||||
break;
|
||||
case Invisible:
|
||||
abstractEffectModifier = new InvisibleEffectModifier(rs);
|
||||
break;
|
||||
case ItemName:
|
||||
abstractEffectModifier = new ItemNameEffectModifier(rs);
|
||||
if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty())
|
||||
break;
|
||||
if (effectBase != null)
|
||||
effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name));
|
||||
break;
|
||||
case Mana:
|
||||
abstractEffectModifier = new ManaEffectModifier(rs);
|
||||
break;
|
||||
case ManaFull:
|
||||
abstractEffectModifier = new ManaFullEffectModifier(rs);
|
||||
break;
|
||||
case ManaRecoverRate:
|
||||
abstractEffectModifier = new ManaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case MaxDamage:
|
||||
abstractEffectModifier = new MaxDamageEffectModifier(rs);
|
||||
break;
|
||||
case MeleeDamageModifier:
|
||||
abstractEffectModifier = new MeleeDamageEffectModifier(rs);
|
||||
break;
|
||||
case MinDamage:
|
||||
abstractEffectModifier = new MinDamageEffectModifier(rs);
|
||||
break;
|
||||
case NoMod:
|
||||
abstractEffectModifier = new NoModEffectModifier(rs);
|
||||
break;
|
||||
case OCV:
|
||||
abstractEffectModifier = new OCVEffectModifier(rs);
|
||||
break;
|
||||
case Parry:
|
||||
abstractEffectModifier = new ParryEffectModifier(rs);
|
||||
break;
|
||||
case PassiveDefense:
|
||||
abstractEffectModifier = new PassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case PowerCost:
|
||||
abstractEffectModifier = new PowerCostEffectModifier(rs);
|
||||
break;
|
||||
case PowerCostHealth:
|
||||
abstractEffectModifier = new PowerCostHealthEffectModifier(rs);
|
||||
break;
|
||||
case PowerDamageModifier:
|
||||
abstractEffectModifier = new PowerDamageEffectModifier(rs);
|
||||
break;
|
||||
case ProtectionFrom:
|
||||
abstractEffectModifier = new ProtectionFromEffectModifier(rs);
|
||||
break;
|
||||
case Resistance:
|
||||
abstractEffectModifier = new ResistanceEffectModifier(rs);
|
||||
break;
|
||||
case ScaleHeight:
|
||||
abstractEffectModifier = new ScaleHeightEffectModifier(rs);
|
||||
break;
|
||||
case ScaleWidth:
|
||||
abstractEffectModifier = new ScaleWidthEffectModifier(rs);
|
||||
break;
|
||||
case ScanRange:
|
||||
abstractEffectModifier = new ScanRangeEffectModifier(rs);
|
||||
break;
|
||||
case SeeInvisible:
|
||||
abstractEffectModifier = new SeeInvisibleEffectModifier(rs);
|
||||
break;
|
||||
case Silenced:
|
||||
abstractEffectModifier = new SilencedEffectModifier(rs);
|
||||
break;
|
||||
case Skill:
|
||||
abstractEffectModifier = new SkillEffectModifier(rs);
|
||||
break;
|
||||
case Slay:
|
||||
abstractEffectModifier = new SlayEffectModifier(rs);
|
||||
break;
|
||||
case Speed:
|
||||
abstractEffectModifier = new SpeedEffectModifier(rs);
|
||||
break;
|
||||
case SpireBlock:
|
||||
abstractEffectModifier = new SpireBlockEffectModifier(rs);
|
||||
break;
|
||||
case Stamina:
|
||||
abstractEffectModifier = new StaminaEffectModifier(rs);
|
||||
break;
|
||||
case StaminaFull:
|
||||
abstractEffectModifier = new StaminaFullEffectModifier(rs);
|
||||
break;
|
||||
case StaminaRecoverRate:
|
||||
abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case Stunned:
|
||||
abstractEffectModifier = new StunnedEffectModifier(rs);
|
||||
break;
|
||||
case Value:
|
||||
abstractEffectModifier = new ValueEffectModifier(rs);
|
||||
if (effectBase != null) {
|
||||
ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier;
|
||||
effectBase.setValue(valueEffect.minMod);
|
||||
}
|
||||
break;
|
||||
case WeaponProc:
|
||||
abstractEffectModifier = new WeaponProcEffectModifier(rs);
|
||||
break;
|
||||
case WeaponRange:
|
||||
abstractEffectModifier = new WeaponRangeEffectModifier(rs);
|
||||
break;
|
||||
case WeaponSpeed:
|
||||
abstractEffectModifier = new WeaponSpeedEffectModifier(rs);
|
||||
break;
|
||||
|
||||
}
|
||||
return abstractEffectModifier;
|
||||
}
|
||||
}
|
||||
return abstractEffectModifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,152 +25,152 @@ public class dbItemBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbItemBaseHandler() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
|
||||
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
if (rs.getBoolean("fromUse"))
|
||||
itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
else
|
||||
itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
while (rs.next()) {
|
||||
if (rs.getBoolean("fromUse"))
|
||||
itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
else
|
||||
itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_ANIMATIONS(ItemBase itemBase) {
|
||||
public void LOAD_ANIMATIONS(ItemBase itemBase) {
|
||||
|
||||
ArrayList<Integer> tempList = new ArrayList<>();
|
||||
ArrayList<Integer> tempListOff = new ArrayList<>();
|
||||
ArrayList<Integer> tempList = new ArrayList<>();
|
||||
ArrayList<Integer> tempListOff = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int animation = rs.getInt("animation");
|
||||
boolean rightHand = rs.getBoolean("rightHand");
|
||||
while (rs.next()) {
|
||||
int animation = rs.getInt("animation");
|
||||
boolean rightHand = rs.getBoolean("rightHand");
|
||||
|
||||
if (rightHand)
|
||||
tempList.add(animation);
|
||||
else
|
||||
tempListOff.add(animation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
if (rightHand)
|
||||
tempList.add(animation);
|
||||
else
|
||||
tempListOff.add(animation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
itemBase.setAnimations(tempList);
|
||||
itemBase.setOffHandAnimations(tempListOff);
|
||||
}
|
||||
itemBase.setAnimations(tempList);
|
||||
itemBase.setOffHandAnimations(tempListOff);
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ITEMBASES() {
|
||||
public void LOAD_ALL_ITEMBASES() {
|
||||
|
||||
ItemBase itemBase;
|
||||
int recordsRead = 0;
|
||||
ItemBase itemBase;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
itemBase = new ItemBase(rs);
|
||||
ItemBase.addToCache(itemBase);
|
||||
}
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
itemBase = new ItemBase(rs);
|
||||
ItemBase.addToCache(itemBase);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
|
||||
}
|
||||
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
|
||||
int runeSetID;
|
||||
int runeBaseID;
|
||||
int recordsRead = 0;
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
|
||||
int runeSetID;
|
||||
int runeBaseID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) {
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
recordsRead++;
|
||||
|
||||
runeSetID = rs.getInt("runeSet");
|
||||
runeBaseID = rs.getInt("runeBase");
|
||||
runeSetID = rs.getInt("runeSet");
|
||||
runeBaseID = rs.getInt("runeBase");
|
||||
|
||||
if (runeSets.get(runeSetID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(runeSetID);
|
||||
runeList.add(runeSetID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
}
|
||||
}
|
||||
if (runeSets.get(runeSetID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(runeSetID);
|
||||
runeList.add(runeSetID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return runeSets;
|
||||
}
|
||||