public class GarageItemsLoader { public static HashMap<String, Item> items; private…
- User
public class GarageItemsLoader { public static HashMap<String, Item> items; private static int index = 1;
public static void loadFromConfig(String turrets, String hulls, String colormaps, String inventory, String subscription) { if (items == null) { items = new HashMap(); }
for(int i = 0; i < 5; ++i) { StringBuilder builder = new StringBuilder(); Throwable var7 = null; Object var8 = null; try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(i == 3 ? colormaps : i == 2 ? hulls : i == 1 ? turrets : i == 0 ? inventory : subscription)), StandardCharsets.UTF_8)); String line; try { while((line = reader.readLine()) != null) { builder.append(line); } } finally { if (reader != null) { reader.close(); } } } catch (Throwable var18) { if (var7 == null) { var7 = var18; } else if (var7 != var18) { var7.addSuppressed(var18); } try { throw var7; } catch (Throwable throwable) { throwable.printStackTrace(); } } parseAndInitItems(builder.toString(), i == 3 ? ItemType.COLOR : i == 2 ? ItemType.ARMOR : i == 1 ? ItemType.WEAPON : i == 0 ? ItemType.INVENTORY : ItemType.PLUGIN); }} private static void parseAndInitItems(String json, ItemType typeItem) { JSONParser parser = new JSONParser();
try { Object obj = parser.parse(json); JSONObject jparser = (JSONObject)obj; JSONArray jarray = (JSONArray)jparser.get(“items”);
for(int i = 0; i < jarray.size(); ++i) { JSONObject item = (JSONObject)jarray.get(i); LocalizedString name = StringsLocalizationBundle.registerString((String)item.get(“name_ru”), (String)item.get(“name_en”)); LocalizedString description = StringsLocalizationBundle.registerString((String)item.get(“description_ru”), (String)item.get(“description_en”)); String id = (String)item.get(“id”); int priceM0 = Integer.parseInt((String)item.get(“price_m0”)); int priceM1 = typeItem != ItemType.COLOR && typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? Integer.parseInt((String)item.get(“price_m1”)) : priceM0; int priceM2 = typeItem != ItemType.COLOR && typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? Integer.parseInt((String)item.get(“price_m2”)) : priceM0; int priceM3 = typeItem != ItemType.COLOR && typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? Integer.parseInt((String)item.get(“price_m3”)) : priceM0; int rangM0 = Integer.parseInt((String)item.get(“rang_m0”)); int rangM1 = typeItem != ItemType.COLOR && typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? Integer.parseInt((String)item.get(“rang_m1”)) : rangM0; int rangM2 = typeItem != ItemType.COLOR && typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? Integer.parseInt((String)item.get(“rang_m2”)) : rangM0; int rangM3 = typeItem != ItemType.COLOR && typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? Integer.parseInt((String)item.get(“rang_m3”)) : rangM0; PropertyItem[] propertysItemM0 = null; PropertyItem[] propertysItemM1 = null; PropertyItem[] propertysItemM2 = null; PropertyItem[] propertysItemM3 = null; int countModification = typeItem == ItemType.COLOR ? 1 : (typeItem != ItemType.INVENTORY && typeItem != ItemType.PLUGIN ? 4 : (int)(long)item.get(“count_modifications”));
- Assistant
Чтобы добавить такой формат предмета, вам понадобится внести изменения в метод
parseAndInitItems.Сначала необходимо получить
modificationиз JSON объекта предмета:int modification = Integer.parseInt((String)item.get("modification"));Далее, вместо цикла
for(int m = 0; m < countModification; ++m)и условного оператораswitch(m), вы можете использовать условные операторы для каждой модификации, в зависимости от значенияmodification. Например:if (modification >= 0) { JSONArray propertys = (JSONArray)item.get("propertys_m0"); PropertyItem[] property = new PropertyItem[propertys.size()]; for(int p = 0; p < propertys.size(); ++p) { JSONObject prop = (JSONObject)propertys.get(p); property[p] = new PropertyItem(getType((String)prop.get("type")), (String)prop.get("value")); } propertysItemM0 = property; } if (modification >= 1) { JSONArray propertys = (JSONArray)item.get("propertys_m1"); PropertyItem[] property = new PropertyItem[propertys.size()]; for(int p = 0; p < propertys.size(); ++p) { JSONObject prop = (JSONObject)propertys.get(p); property[p] = new PropertyItem(getType((String)prop.get("type")), (String)prop.get("value")); } propertysItemM1 = property; } // То же самое для m2 и m3, если необходимо - User
покажи кодом только в методах который ты делаешь это полным кодом
- Assistant
- User
mods[1] = new ModificationInfo(id + "_m1", priceM1, rangM1); mods[1].propertys = propertysItemM1; mods[2] = new ModificationInfo(id + "_m2", priceM2, rangM2); mods[2].propertys = propertysItemM2; mods[3] = new ModificationInfo(id + "_m3", priceM3, rangM3); ошибка на price и rang
- Assistant
Из вашего вопроса неясно, откуда берутся переменные
priceM1,rangM1,priceM2,rangM2,priceM3иrangM3. Убедитесь, что они определены в вашем коде и имеют правильные значения. Проверьте, правильно ли вы извлекаете эти значения из JSON объекта предмета в соответствующих строках кода:int priceM1 = Integer.parseInt((String)item.get("price_m1")); int rangM1 = Integer.parseInt((String)item.get("rang_m1")); int priceM2 = Integer.parseInt((String)item.get("price_m2")); int rangM2 = Integer.parseInt((String)item.get("rang_m2")); int priceM3 = Integer.parseInt((String)item.get("price_m3")); int rangM3 = Integer.parseInt((String)item.get("
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.