Browse Source

Migration to org.json

combat-2
MagicBot 8 months ago
parent
commit
ba47b30673
  1. 7
      src/engine/db/handlers/dbItemHandler.java
  2. 13
      src/engine/db/handlers/dbWarehouseHandler.java
  3. 2
      src/engine/gameManager/ForgeManager.java
  4. 4
      src/engine/loot/WorkOrder.java
  5. 8
      src/engine/objects/ItemTemplate.java
  6. 8
      src/engine/objects/Warehouse.java

7
src/engine/db/handlers/dbItemHandler.java

@ -17,8 +17,7 @@ import engine.objects.AbstractCharacter;
import engine.objects.CharacterItemManager; import engine.objects.CharacterItemManager;
import engine.objects.Item; import engine.objects.Item;
import engine.objects.ItemTemplate; import engine.objects.ItemTemplate;
import org.json.simple.JSONObject; import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -180,8 +179,6 @@ public class dbItemHandler extends dbHandlerBase {
public void LOAD_ITEM_TEMPLATES() { public void LOAD_ITEM_TEMPLATES() {
JSONParser jsonParser = new JSONParser();
HashMap<ItemType, Integer> templateTCountMap = new HashMap<>(); HashMap<ItemType, Integer> templateTCountMap = new HashMap<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
@ -190,7 +187,7 @@ public class dbItemHandler extends dbHandlerBase {
while (rs.next()) { while (rs.next()) {
int templateID = rs.getInt("id"); int templateID = rs.getInt("id");
JSONObject jsonObject = (JSONObject) jsonParser.parse(rs.getString("template")); JSONObject jsonObject = new JSONObject(rs.getString("template"));
ItemTemplate itemTemplate = new ItemTemplate(jsonObject); ItemTemplate itemTemplate = new ItemTemplate(jsonObject);
itemTemplate.template_id = templateID; itemTemplate.template_id = templateID;
ItemTemplate.templates.put(templateID, itemTemplate); ItemTemplate.templates.put(templateID, itemTemplate);

13
src/engine/db/handlers/dbWarehouseHandler.java

@ -9,19 +9,18 @@
package engine.db.handlers; package engine.db.handlers;
import engine.gameManager.DbManager;
import engine.mbEnums; import engine.mbEnums;
import engine.mbEnums.GameObjectType; import engine.mbEnums.GameObjectType;
import engine.mbEnums.TransactionType; import engine.mbEnums.TransactionType;
import engine.gameManager.DbManager;
import engine.objects.Building; import engine.objects.Building;
import engine.objects.City; import engine.objects.City;
import engine.objects.Transaction; import engine.objects.Transaction;
import engine.objects.Warehouse; import engine.objects.Warehouse;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.json.simple.JSONArray; import org.json.JSONArray;
import org.json.simple.JSONObject; import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -106,7 +105,7 @@ public class dbWarehouseHandler extends dbHandlerBase {
JSONArray locks = new JSONArray(); JSONArray locks = new JSONArray();
for (mbEnums.ResourceType resource : warehouse.locked) for (mbEnums.ResourceType resource : warehouse.locked)
locks.add(resource.name()); locks.put(resource.name());
warehouseJSON.put("locked", locks); warehouseJSON.put("locked", locks);
@ -127,15 +126,13 @@ public class dbWarehouseHandler extends dbHandlerBase {
public void LOAD_WAREHOUSES() { public void LOAD_WAREHOUSES() {
JSONParser jsonParser = new JSONParser();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_warehouse`;"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_warehouse`;");
ResultSet rs = preparedStatement.executeQuery()) { ResultSet rs = preparedStatement.executeQuery()) {
while (rs.next()) { while (rs.next()) {
int cityUID = rs.getInt("cityUUID"); int cityUID = rs.getInt("cityUUID");
JSONObject jsonObject = (JSONObject) jsonParser.parse(rs.getString("warehouse")); JSONObject jsonObject = new JSONObject(rs.getString("warehouse"));
City city = City.getCity(cityUID); City city = City.getCity(cityUID);
city.warehouse = new Warehouse(jsonObject); city.warehouse = new Warehouse(jsonObject);
city.warehouse.city = city; city.warehouse.city = city;

2
src/engine/gameManager/ForgeManager.java

@ -16,7 +16,7 @@ import engine.net.DispatchMessage;
import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.ItemProductionMsg;
import engine.objects.*; import engine.objects.*;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import org.json.simple.JSONObject; import org.json.JSONObject;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;

4
src/engine/loot/WorkOrder.java

@ -11,7 +11,7 @@ package engine.loot;
import engine.mbEnums; import engine.mbEnums;
import engine.objects.Item; import engine.objects.Item;
import engine.objects.NPC; import engine.objects.NPC;
import org.json.simple.JSONObject; import org.json.JSONObject;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@ -55,7 +55,7 @@ public class WorkOrder implements Delayed {
JSONObject jsonWorkOrder = new JSONObject(); JSONObject jsonWorkOrder = new JSONObject();
jsonWorkOrder.put("jsonWorkOrder", workOrder.workOrderID); jsonWorkOrder.put("workOrderID", workOrder.workOrderID);
jsonWorkOrder.put("vendor", workOrder.vendor.getObjectUUID()); jsonWorkOrder.put("vendor", workOrder.vendor.getObjectUUID());
jsonWorkOrder.put("slots_used", workOrder.slots_used); jsonWorkOrder.put("slots_used", workOrder.slots_used);
jsonWorkOrder.put("total_to_produce", workOrder.total_to_produce); jsonWorkOrder.put("total_to_produce", workOrder.total_to_produce);

8
src/engine/objects/ItemTemplate.java

@ -10,8 +10,8 @@ package engine.objects;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.mbEnums; import engine.mbEnums;
import org.json.simple.JSONArray; import org.json.JSONArray;
import org.json.simple.JSONObject; import org.json.JSONObject;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@ -194,7 +194,7 @@ public class ItemTemplate {
JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist"); JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist");
for (Object key : resist_json.keySet()) { for (String key : resist_json.keySet()) {
float resist = ((Double) resist_json.get(key)).floatValue(); float resist = ((Double) resist_json.get(key)).floatValue();
combat_attack_resist.put((String) key, resist); combat_attack_resist.put((String) key, resist);
} }
@ -488,7 +488,7 @@ public class ItemTemplate {
JSONObject rune_speed_json = (JSONObject) jsonObject.get("rune_speed"); JSONObject rune_speed_json = (JSONObject) jsonObject.get("rune_speed");
for (Object key : rune_speed_json.keySet()) { for (String key : rune_speed_json.keySet()) {
mbEnums.MovementType movementType = mbEnums.MovementType.valueOf((String) key); mbEnums.MovementType movementType = mbEnums.MovementType.valueOf((String) key);
float speed = ((Double) rune_speed_json.get(key)).floatValue(); float speed = ((Double) rune_speed_json.get(key)).floatValue();
rune_speed.put(movementType, speed); rune_speed.put(movementType, speed);

8
src/engine/objects/Warehouse.java

@ -19,8 +19,8 @@ import engine.net.client.ClientConnection;
import engine.net.client.msg.*; import engine.net.client.msg.*;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.json.simple.JSONArray; import org.json.JSONArray;
import org.json.simple.JSONObject; import org.json.JSONObject;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.SQLException; import java.sql.SQLException;
@ -56,8 +56,8 @@ public class Warehouse {
JSONObject resources = (JSONObject) warehouse.get("resources"); JSONObject resources = (JSONObject) warehouse.get("resources");
for (Object key : resources.keySet()) { for (String key : resources.keySet()) {
mbEnums.ResourceType resourceType = mbEnums.ResourceType.valueOf((String) key); mbEnums.ResourceType resourceType = mbEnums.ResourceType.valueOf(key);
int value = ((Long) resources.get(key)).intValue(); int value = ((Long) resources.get(key)).intValue();
this.resources.put(resourceType, value); this.resources.put(resourceType, value);
} }

Loading…
Cancel
Save