|
|
|
@ -10,10 +10,13 @@
@@ -10,10 +10,13 @@
|
|
|
|
|
package engine.db.handlers; |
|
|
|
|
|
|
|
|
|
import engine.Enum.ProfitType; |
|
|
|
|
import engine.gameManager.DbManager; |
|
|
|
|
import engine.objects.*; |
|
|
|
|
import org.joda.time.DateTime; |
|
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
|
import java.sql.PreparedStatement; |
|
|
|
|
import java.sql.ResultSet; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -27,57 +30,70 @@ public class dbNPCHandler extends dbHandlerBase {
@@ -27,57 +30,70 @@ public class dbNPCHandler extends dbHandlerBase {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public NPC ADD_NPC(NPC toAdd, boolean isMob) { |
|
|
|
|
prepareCallable("CALL `npc_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); |
|
|
|
|
setLong(1, toAdd.getParentZoneID()); |
|
|
|
|
setString(2, toAdd.getName()); |
|
|
|
|
setInt(3, toAdd.getContractID()); |
|
|
|
|
setInt(4, toAdd.getGuildUUID()); |
|
|
|
|
setFloat(5, toAdd.getSpawnX()); |
|
|
|
|
setFloat(6, toAdd.getSpawnY()); |
|
|
|
|
setFloat(7, toAdd.getSpawnZ()); |
|
|
|
|
setInt(8, toAdd.getLevel()); |
|
|
|
|
setFloat(9, toAdd.getBuyPercent()); |
|
|
|
|
setFloat(10, toAdd.getSellPercent()); |
|
|
|
|
if (toAdd.getBuilding() != null) { |
|
|
|
|
setInt(11, toAdd.getBuilding().getObjectUUID()); |
|
|
|
|
} else { |
|
|
|
|
setInt(11, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int objectUUID = (int) getUUID(); |
|
|
|
|
if (objectUUID > 0) { |
|
|
|
|
return GET_NPC(objectUUID); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int DELETE_NPC(final NPC npc) { |
|
|
|
|
if (npc.isStatic()) { |
|
|
|
|
return DELETE_STATIC_NPC(npc); |
|
|
|
|
NPC npc = null; |
|
|
|
|
|
|
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("CALL `npc_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { |
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, toAdd.getParentZoneID()); |
|
|
|
|
preparedStatement.setString(2, toAdd.getName()); |
|
|
|
|
preparedStatement.setInt(3, toAdd.getContractID()); |
|
|
|
|
preparedStatement.setInt(4, toAdd.getGuildUUID()); |
|
|
|
|
preparedStatement.setFloat(5, toAdd.getSpawnX()); |
|
|
|
|
preparedStatement.setFloat(6, toAdd.getSpawnY()); |
|
|
|
|
preparedStatement.setFloat(7, toAdd.getSpawnZ()); |
|
|
|
|
preparedStatement.setInt(8, toAdd.getLevel()); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
npc.removeFromZone(); |
|
|
|
|
prepareCallable("DELETE FROM `object` WHERE `UID` = ?"); |
|
|
|
|
setLong(1, (long) npc.getDBID()); |
|
|
|
|
return executeUpdate(); |
|
|
|
|
return npc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private int DELETE_STATIC_NPC(final NPC npc) { |
|
|
|
|
public int DELETE_NPC(final NPC npc) { |
|
|
|
|
|
|
|
|
|
int row_count = 0; |
|
|
|
|
|
|
|
|
|
npc.removeFromZone(); |
|
|
|
|
prepareCallable("DELETE FROM `_init_npc` WHERE `ID` = ?"); |
|
|
|
|
setInt(1, npc.getDBID()); |
|
|
|
|
return executeUpdate(); |
|
|
|
|
|
|
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { |
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, npc.getDBID()); |
|
|
|
|
row_count = preparedStatement.executeUpdate(); |
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return row_count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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` = ?;"); |
|
|
|
|
setLong(1, (long) zone.getObjectUUID()); |
|
|
|
|
setLong(1, zone.getObjectUUID()); |
|
|
|
|
return getLargeObjectList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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` = ?;"); |
|
|
|
|
setLong(1, (long) objectUUID); |
|
|
|
|
setLong(1, objectUUID); |
|
|
|
|
return (NPC) getObjectSingle(objectUUID); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -94,7 +110,7 @@ public class dbNPCHandler extends dbHandlerBase {
@@ -94,7 +110,7 @@ public class dbNPCHandler extends dbHandlerBase {
|
|
|
|
|
|
|
|
|
|
public String SET_PROPERTY(final NPC n, String name, Object new_value) { |
|
|
|
|
prepareCallable("CALL npc_SETPROP(?,?,?)"); |
|
|
|
|
setLong(1, (long) n.getDBID()); |
|
|
|
|
setLong(1, n.getDBID()); |
|
|
|
|
setString(2, name); |
|
|
|
|
setString(3, String.valueOf(new_value)); |
|
|
|
|
return getResult(); |
|
|
|
@ -102,7 +118,7 @@ public class dbNPCHandler extends dbHandlerBase {
@@ -102,7 +118,7 @@ public class dbNPCHandler extends dbHandlerBase {
|
|
|
|
|
|
|
|
|
|
public String SET_PROPERTY(final NPC n, String name, Object new_value, Object old_value) { |
|
|
|
|
prepareCallable("CALL npc_GETSETPROP(?,?,?,?)"); |
|
|
|
|
setLong(1, (long) n.getDBID()); |
|
|
|
|
setLong(1, n.getDBID()); |
|
|
|
|
setString(2, name); |
|
|
|
|
setString(3, String.valueOf(new_value)); |
|
|
|
|
setString(4, String.valueOf(old_value)); |
|
|
|
|