|
|
@ -19,7 +19,6 @@ import engine.server.MBServerStatics; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
|
|
import java.net.UnknownHostException; |
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
@ -37,68 +36,71 @@ public class dbWarehouseHandler extends dbHandlerBase { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException { |
|
|
|
|
|
|
|
String type = rs.getString("type"); |
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
|
|
|
case "building": |
|
|
|
|
|
|
|
Building building = new Building(rs); |
|
|
|
|
|
|
|
DbManager.addToCache(building); |
|
|
|
|
|
|
|
list.add(building); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "warehouse": |
|
|
|
|
|
|
|
Warehouse warehouse = new Warehouse(rs); |
|
|
|
|
|
|
|
DbManager.addToCache(warehouse); |
|
|
|
|
|
|
|
list.add(warehouse); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<AbstractGameObject> CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID, |
|
|
|
public ArrayList<AbstractGameObject> CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID, |
|
|
|
Vector3fImmutable location, float meshScale, int currentHP, |
|
|
|
Vector3fImmutable location, float meshScale, int currentHP, |
|
|
|
ProtectionState protectionState, int currentGold, int rank, |
|
|
|
ProtectionState protectionState, int currentGold, int rank, |
|
|
|
DateTime upgradeDate, int blueprintUUID, float w, float rotY) { |
|
|
|
DateTime upgradeDate, int blueprintUUID, float w, float rotY) { |
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("CALL `WAREHOUSE_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);"); |
|
|
|
ArrayList<AbstractGameObject> warehouseList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
setInt(1, parentZoneID); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
setInt(2, OwnerUUID); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("CALL `WAREHOUSE_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) { |
|
|
|
setString(3, name); |
|
|
|
|
|
|
|
setInt(4, meshUUID); |
|
|
|
preparedStatement.setInt(1, parentZoneID); |
|
|
|
setFloat(5, location.x); |
|
|
|
preparedStatement.setInt(2, OwnerUUID); |
|
|
|
setFloat(6, location.y); |
|
|
|
preparedStatement.setString(3, name); |
|
|
|
setFloat(7, location.z); |
|
|
|
preparedStatement.setInt(4, meshUUID); |
|
|
|
setFloat(8, meshScale); |
|
|
|
preparedStatement.setFloat(5, location.x); |
|
|
|
setInt(9, currentHP); |
|
|
|
preparedStatement.setFloat(6, location.y); |
|
|
|
setString(10, protectionState.name()); |
|
|
|
preparedStatement.setFloat(7, location.z); |
|
|
|
setInt(11, currentGold); |
|
|
|
preparedStatement.setFloat(8, meshScale); |
|
|
|
setInt(12, rank); |
|
|
|
preparedStatement.setInt(9, currentHP); |
|
|
|
|
|
|
|
preparedStatement.setString(10, protectionState.name()); |
|
|
|
if (upgradeDate != null) { |
|
|
|
preparedStatement.setInt(11, currentGold); |
|
|
|
setTimeStamp(13, upgradeDate.getMillis()); |
|
|
|
preparedStatement.setInt(12, rank); |
|
|
|
} else { |
|
|
|
|
|
|
|
setNULL(13, java.sql.Types.DATE); |
|
|
|
if (upgradeDate != null) |
|
|
|
} |
|
|
|
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis())); |
|
|
|
|
|
|
|
else |
|
|
|
setInt(14, blueprintUUID); |
|
|
|
preparedStatement.setNull(13, java.sql.Types.DATE); |
|
|
|
setFloat(15, w); |
|
|
|
|
|
|
|
setFloat(16, rotY); |
|
|
|
preparedStatement.setInt(14, blueprintUUID); |
|
|
|
|
|
|
|
preparedStatement.setFloat(15, w); |
|
|
|
ArrayList<AbstractGameObject> list = new ArrayList<>(); |
|
|
|
preparedStatement.setFloat(16, rotY); |
|
|
|
//System.out.println(this.cs.get().toString());
|
|
|
|
|
|
|
|
try { |
|
|
|
preparedStatement.execute(); |
|
|
|
boolean work = execute(); |
|
|
|
ResultSet rs = preparedStatement.getResultSet(); |
|
|
|
if (work) { |
|
|
|
|
|
|
|
ResultSet rs = this.callableStatement.get().getResultSet(); |
|
|
|
while (rs.next()) |
|
|
|
while (rs.next()) { |
|
|
|
addObject(warehouseList, rs); |
|
|
|
addObject(list, rs); |
|
|
|
|
|
|
|
} |
|
|
|
while (preparedStatement.getMoreResults()) { |
|
|
|
rs.close(); |
|
|
|
rs = preparedStatement.getResultSet(); |
|
|
|
} else { |
|
|
|
|
|
|
|
Logger.info("Warehouse Creation Failed: " + this.callableStatement.get().toString()); |
|
|
|
while (rs.next()) |
|
|
|
return list; //city creation failure
|
|
|
|
addObject(warehouseList, rs); |
|
|
|
} |
|
|
|
|
|
|
|
while (this.callableStatement.get().getMoreResults()) { |
|
|
|
|
|
|
|
ResultSet rs = this.callableStatement.get().getResultSet(); |
|
|
|
|
|
|
|
while (rs.next()) { |
|
|
|
|
|
|
|
addObject(list, rs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.info("Warehouse Creation Failed, SQLException: " + this.callableStatement.get().toString() + e.toString()); |
|
|
|
Logger.error(e); |
|
|
|
return list; //city creation failure
|
|
|
|
|
|
|
|
} catch (UnknownHostException e) { |
|
|
|
|
|
|
|
Logger.info("Warehouse Creation Failed, UnknownHostException: " + this.callableStatement.get().toString()); |
|
|
|
|
|
|
|
return list; //city creation failure
|
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
closeCallable(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return list; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return warehouseList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean updateLocks(final Warehouse wh, long locks) { |
|
|
|
public boolean updateLocks(final Warehouse wh, long locks) { |
|
|
@ -313,22 +315,6 @@ public class dbWarehouseHandler extends dbHandlerBase { |
|
|
|
return (executeUpdate() != 0); |
|
|
|
return (executeUpdate() != 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException, UnknownHostException { |
|
|
|
|
|
|
|
String type = rs.getString("type"); |
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
|
|
|
case "building": |
|
|
|
|
|
|
|
Building building = new Building(rs); |
|
|
|
|
|
|
|
DbManager.addToCache(building); |
|
|
|
|
|
|
|
list.add(building); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "warehouse": |
|
|
|
|
|
|
|
Warehouse warehouse = new Warehouse(rs); |
|
|
|
|
|
|
|
DbManager.addToCache(warehouse); |
|
|
|
|
|
|
|
list.add(warehouse); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<Transaction> GET_TRANSACTIONS_FOR_WAREHOUSE(final int warehouseUUID) { |
|
|
|
public ArrayList<Transaction> GET_TRANSACTIONS_FOR_WAREHOUSE(final int warehouseUUID) { |
|
|
|
ArrayList<Transaction> transactionsList = new ArrayList<>(); |
|
|
|
ArrayList<Transaction> transactionsList = new ArrayList<>(); |
|
|
|
prepareCallable("SELECT * FROM dyn_warehouse_transactions WHERE `warehouseUID` = ?;"); |
|
|
|
prepareCallable("SELECT * FROM dyn_warehouse_transactions WHERE `warehouseUID` = ?;"); |
|
|
|