forked from MagicBane/Server
Bonus code removed.
This commit is contained in:
@@ -10,10 +10,13 @@
|
|||||||
package engine.db.handlers;
|
package engine.db.handlers;
|
||||||
|
|
||||||
import engine.Enum.ProfitType;
|
import engine.Enum.ProfitType;
|
||||||
|
import engine.gameManager.DbManager;
|
||||||
import engine.objects.*;
|
import engine.objects.*;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -27,57 +30,70 @@ public class dbNPCHandler extends dbHandlerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public NPC ADD_NPC(NPC toAdd, boolean isMob) {
|
public NPC ADD_NPC(NPC toAdd, boolean isMob) {
|
||||||
prepareCallable("CALL `npc_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
|
|
||||||
setLong(1, toAdd.getParentZoneID());
|
NPC npc = null;
|
||||||
setString(2, toAdd.getName());
|
|
||||||
setInt(3, toAdd.getContractID());
|
try (Connection connection = DbManager.getConnection();
|
||||||
setInt(4, toAdd.getGuildUUID());
|
PreparedStatement preparedStatement = connection.prepareStatement("CALL `npc_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||||
setFloat(5, toAdd.getSpawnX());
|
|
||||||
setFloat(6, toAdd.getSpawnY());
|
preparedStatement.setLong(1, toAdd.getParentZoneID());
|
||||||
setFloat(7, toAdd.getSpawnZ());
|
preparedStatement.setString(2, toAdd.getName());
|
||||||
setInt(8, toAdd.getLevel());
|
preparedStatement.setInt(3, toAdd.getContractID());
|
||||||
setFloat(9, toAdd.getBuyPercent());
|
preparedStatement.setInt(4, toAdd.getGuildUUID());
|
||||||
setFloat(10, toAdd.getSellPercent());
|
preparedStatement.setFloat(5, toAdd.getSpawnX());
|
||||||
if (toAdd.getBuilding() != null) {
|
preparedStatement.setFloat(6, toAdd.getSpawnY());
|
||||||
setInt(11, toAdd.getBuilding().getObjectUUID());
|
preparedStatement.setFloat(7, toAdd.getSpawnZ());
|
||||||
} else {
|
preparedStatement.setInt(8, toAdd.getLevel());
|
||||||
setInt(11, 0);
|
preparedStatement.setFloat(9, toAdd.getBuyPercent());
|
||||||
|
preparedStatement.setFloat(10, toAdd.getSellPercent());
|
||||||
|
|
||||||
|
if (toAdd.getBuilding() != null)
|
||||||
|
preparedStatement.setInt(11, toAdd.getBuilding().getObjectUUID());
|
||||||
|
else
|
||||||
|
preparedStatement.setInt(11, 0);
|
||||||
|
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
int objectUUID = (int) rs.getLong("UID");
|
||||||
|
|
||||||
|
if (objectUUID > 0)
|
||||||
|
npc = GET_NPC(objectUUID);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int objectUUID = (int) getUUID();
|
return npc;
|
||||||
if (objectUUID > 0) {
|
|
||||||
return GET_NPC(objectUUID);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int DELETE_NPC(final NPC npc) {
|
public int DELETE_NPC(final NPC npc) {
|
||||||
if (npc.isStatic()) {
|
|
||||||
return DELETE_STATIC_NPC(npc);
|
int row_count = 0;
|
||||||
}
|
|
||||||
|
|
||||||
npc.removeFromZone();
|
npc.removeFromZone();
|
||||||
prepareCallable("DELETE FROM `object` WHERE `UID` = ?");
|
|
||||||
setLong(1, (long) npc.getDBID());
|
|
||||||
return executeUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int DELETE_STATIC_NPC(final NPC npc) {
|
try (Connection connection = DbManager.getConnection();
|
||||||
npc.removeFromZone();
|
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||||
prepareCallable("DELETE FROM `_init_npc` WHERE `ID` = ?");
|
|
||||||
setInt(1, npc.getDBID());
|
preparedStatement.setLong(1, npc.getDBID());
|
||||||
return executeUpdate();
|
row_count = preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
return row_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<NPC> GET_ALL_NPCS_FOR_ZONE(Zone zone) {
|
public ArrayList<NPC> GET_ALL_NPCS_FOR_ZONE(Zone zone) {
|
||||||
prepareCallable("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;");
|
prepareCallable("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;");
|
||||||
setLong(1, (long) zone.getObjectUUID());
|
setLong(1, zone.getObjectUUID());
|
||||||
return getLargeObjectList();
|
return getLargeObjectList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NPC GET_NPC(final int objectUUID) {
|
public NPC GET_NPC(final int objectUUID) {
|
||||||
prepareCallable("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;");
|
prepareCallable("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;");
|
||||||
setLong(1, (long) objectUUID);
|
setLong(1, objectUUID);
|
||||||
return (NPC) getObjectSingle(objectUUID);
|
return (NPC) getObjectSingle(objectUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +110,7 @@ public class dbNPCHandler extends dbHandlerBase {
|
|||||||
|
|
||||||
public String SET_PROPERTY(final NPC n, String name, Object new_value) {
|
public String SET_PROPERTY(final NPC n, String name, Object new_value) {
|
||||||
prepareCallable("CALL npc_SETPROP(?,?,?)");
|
prepareCallable("CALL npc_SETPROP(?,?,?)");
|
||||||
setLong(1, (long) n.getDBID());
|
setLong(1, n.getDBID());
|
||||||
setString(2, name);
|
setString(2, name);
|
||||||
setString(3, String.valueOf(new_value));
|
setString(3, String.valueOf(new_value));
|
||||||
return getResult();
|
return getResult();
|
||||||
@@ -102,7 +118,7 @@ public class dbNPCHandler extends dbHandlerBase {
|
|||||||
|
|
||||||
public String SET_PROPERTY(final NPC n, String name, Object new_value, Object old_value) {
|
public String SET_PROPERTY(final NPC n, String name, Object new_value, Object old_value) {
|
||||||
prepareCallable("CALL npc_GETSETPROP(?,?,?,?)");
|
prepareCallable("CALL npc_GETSETPROP(?,?,?,?)");
|
||||||
setLong(1, (long) n.getDBID());
|
setLong(1, n.getDBID());
|
||||||
setString(2, name);
|
setString(2, name);
|
||||||
setString(3, String.valueOf(new_value));
|
setString(3, String.valueOf(new_value));
|
||||||
setString(4, String.valueOf(old_value));
|
setString(4, String.valueOf(old_value));
|
||||||
|
|||||||
Reference in New Issue
Block a user