Skip to content

Commit

Permalink
fix: Use the new dropMeta info for showing item guesses [skip ci] (#2399
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DonkeyBlaster committed May 5, 2024
1 parent b43bbe6 commit 81337ca
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public GearInfo deserialize(JsonElement jsonElement, Type jsonType, JsonDeserial

int powderSlots = JsonUtils.getNullableJsonInt(json, "powderSlots");

GearMetaInfo metaInfo = parseMetaInfo(json, displayName, internalName, type);
GearMetaInfo metaInfo = parseMetaInfo(json, internalName, type);
GearRequirements requirements = parseRequirements(json, type);
FixedStats fixedStats = parseFixedStats(json);
List<Pair<StatType, StatPossibleValues>> variableStats = parseVariableStats(json, "identifications");
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/com/wynntils/models/gear/GearModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.wynntils.models.wynnitem.parsing.CraftedItemParseResults;
import com.wynntils.models.wynnitem.parsing.WynnItemParseResult;
import com.wynntils.models.wynnitem.parsing.WynnItemParser;
import com.wynntils.models.wynnitem.type.ItemObtainType;
import com.wynntils.utils.type.CappedValue;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -73,10 +74,10 @@ && canBeGearBox(gear)

public boolean canBeGearBox(GearInfo gear) {
// If an item is pre-identified, it cannot be in a gear box
// If all the ways we can obtain this is by merchants, it cannot be in a gear box
// Also check that the item has a source that can drop boxed items
return !gear.metaInfo().preIdentified()
&& gear.metaInfo().obtainInfo().stream()
.anyMatch(o -> !o.sourceType().isMerchant());
.anyMatch(x -> ItemObtainType.BOXED_ITEMS.contains(x.sourceType()));
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2023.
* Copyright © Wynntils 2023-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.models.gear.type;
Expand All @@ -13,7 +13,6 @@
// The api name is normally the same as the name, but if not, the api name is given
// by apiName
public record GearMetaInfo(
GearDropRestrictions dropRestrictions,
GearRestrictions restrictions,
ItemMaterial material,
List<ItemObtainInfo> obtainInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2023.
* Copyright © Wynntils 2023-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.models.rewards;
Expand All @@ -14,7 +14,6 @@
import com.wynntils.core.components.Managers;
import com.wynntils.core.net.Download;
import com.wynntils.core.net.UrlId;
import com.wynntils.models.gear.type.GearDropRestrictions;
import com.wynntils.models.gear.type.GearMetaInfo;
import com.wynntils.models.gear.type.GearRestrictions;
import com.wynntils.models.gear.type.GearTier;
Expand Down Expand Up @@ -105,7 +104,7 @@ public CharmInfo deserialize(JsonElement jsonElement, Type jsonType, JsonDeseria
throw new RuntimeException("Invalid Wynncraft data: charm has no tier");
}

GearMetaInfo metaInfo = parseMetaInfo(json, displayName, internalName);
GearMetaInfo metaInfo = parseMetaInfo(json, internalName);
CharmRequirements requirements = parseCharmRequirements(json);

// Base stats are parsed the same way as variable stats
Expand All @@ -114,22 +113,14 @@ public CharmInfo deserialize(JsonElement jsonElement, Type jsonType, JsonDeseria
return new CharmInfo(displayName, tier, metaInfo, requirements, variableStats);
}

private GearMetaInfo parseMetaInfo(JsonObject json, String name, String apiName) {
GearDropRestrictions dropRestrictions = parseDropRestrictions(json);
private GearMetaInfo parseMetaInfo(JsonObject json, String apiName) {
GearRestrictions restrictions = parseRestrictions(json);
ItemMaterial material = parseOtherMaterial(json);

List<ItemObtainInfo> obtainInfo = parseObtainInfo(json, name);
List<ItemObtainInfo> obtainInfo = parseObtainInfo(json);

return new GearMetaInfo(
dropRestrictions,
restrictions,
material,
obtainInfo,
Optional.empty(),
Optional.empty(),
true,
false);
restrictions, material, obtainInfo, Optional.empty(), Optional.empty(), true, false);
}

private ItemMaterial parseOtherMaterial(JsonObject json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.wynntils.core.components.Models;
import com.wynntils.core.net.Download;
import com.wynntils.core.net.UrlId;
import com.wynntils.models.gear.type.GearDropRestrictions;
import com.wynntils.models.gear.type.GearMetaInfo;
import com.wynntils.models.gear.type.GearRestrictions;
import com.wynntils.models.gear.type.GearTier;
Expand Down Expand Up @@ -117,7 +116,7 @@ public TomeInfo deserialize(JsonElement jsonElement, Type jsonType, JsonDeserial
throw new RuntimeException("Invalid Wynncraft data: tome has no tome variant");
}

GearMetaInfo metaInfo = parseMetaInfo(json, displayName, internalName);
GearMetaInfo metaInfo = parseMetaInfo(json, internalName);
TomeRequirements requirements = parseTomeRequirements(json);

JsonObject identifications = JsonUtils.getNullableJsonObject(json, "identifications");
Expand Down Expand Up @@ -171,22 +170,14 @@ private List<Pair<StatType, Integer>> parseStaticBaseStats(JsonObject json) {
return list;
}

private GearMetaInfo parseMetaInfo(JsonObject json, String name, String apiName) {
GearDropRestrictions dropRestrictions = parseDropRestrictions(json);
private GearMetaInfo parseMetaInfo(JsonObject json, String apiName) {
GearRestrictions restrictions = parseRestrictions(json);
ItemMaterial material = parseOtherMaterial(json);

List<ItemObtainInfo> obtainInfo = parseObtainInfo(json, name);
List<ItemObtainInfo> obtainInfo = parseObtainInfo(json);

return new GearMetaInfo(
dropRestrictions,
restrictions,
material,
obtainInfo,
Optional.empty(),
Optional.empty(),
true,
false);
restrictions, material, obtainInfo, Optional.empty(), Optional.empty(), true, false);
}

private ItemMaterial parseOtherMaterial(JsonObject json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.wynntils.models.elements.type.Element;
import com.wynntils.models.elements.type.Skill;
import com.wynntils.models.gear.type.GearAttackSpeed;
import com.wynntils.models.gear.type.GearDropRestrictions;
import com.wynntils.models.gear.type.GearMajorId;
import com.wynntils.models.gear.type.GearMetaInfo;
import com.wynntils.models.gear.type.GearRequirements;
Expand Down Expand Up @@ -71,12 +70,11 @@ protected GearType parseType(JsonObject json) {
return GearType.fromString(typeString);
}

protected GearMetaInfo parseMetaInfo(JsonObject json, String name, String apiName, GearType type) {
GearDropRestrictions dropRestrictions = parseDropRestrictions(json);
protected GearMetaInfo parseMetaInfo(JsonObject json, String apiName, GearType type) {
GearRestrictions restrictions = parseRestrictions(json);
ItemMaterial material = parseMaterial(json, type);

List<ItemObtainInfo> obtainInfo = parseObtainInfo(json, name);
List<ItemObtainInfo> obtainInfo = parseObtainInfo(json);

Optional<StyledText> loreOpt = parseLore(json);
Optional<String> apiNameOpt = Optional.ofNullable(apiName);
Expand All @@ -85,23 +83,12 @@ protected GearMetaInfo parseMetaInfo(JsonObject json, String name, String apiNam
boolean preIdentifiedItem = JsonUtils.getNullableJsonBoolean(json, "identified");

return new GearMetaInfo(
dropRestrictions,
restrictions,
material,
obtainInfo,
loreOpt,
apiNameOpt,
allowCraftsman,
preIdentifiedItem);
restrictions, material, obtainInfo, loreOpt, apiNameOpt, allowCraftsman, preIdentifiedItem);
}

protected List<ItemObtainInfo> parseObtainInfo(JsonObject json, String name) {
protected List<ItemObtainInfo> parseObtainInfo(JsonObject json) {
List<ItemObtainInfo> obtainInfo = new ArrayList<>();

// Add crowd-sourced information
List<ItemObtainInfo> obtainCrowdSourced = Models.WynnItem.getObtainInfo(name);
obtainInfo.addAll(obtainCrowdSourced);

// Add API-obtained information
String apiObtainName =
JsonUtils.getNullableJsonString(JsonUtils.getNullableJsonObject(json, "dropMeta"), "name");
Expand Down Expand Up @@ -146,13 +133,6 @@ protected Optional<StyledText> parseLore(JsonObject json) {
return Optional.of(StyledText.fromString(lore));
}

protected GearDropRestrictions parseDropRestrictions(JsonObject json) {
String restrictions = JsonUtils.getNullableJsonString(json, "dropRestriction");
if (restrictions == null) return GearDropRestrictions.NORMAL;

return GearDropRestrictions.fromString(restrictions);
}

protected GearRestrictions parseRestrictions(JsonObject json) {
String restrictions = JsonUtils.getNullableJsonString(json, "restrictions");
if (restrictions == null) return GearRestrictions.NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,23 @@ public enum ItemObtainType {
QIRA_HIVE_MERCHANT("hive", "Qira Hive Merchant", true),
QUEST("quest", "Quest"),
RAID("raid", "Raid"),
SECRET_DISCOVER("discovery", "Secret Discovery"),
SECRET_DISCOVERY("discovery", "Secret Discovery"),
SPECIAL_MOB_DROP("specialdrop", "Specific Mob Drop"),
UNOBTAINABLE("unobtainable", "Unobtainable");

// All sources that possibly drop boxed items
public static final List<ItemObtainType> BOXED_ITEMS = List.of(
LOOT_CHEST,
NORMAL_MOB_DROP,
BOSS_ALTAR,
MINIBOSS,
DUNGEON_RAIN,
FORGERY_CHEST,
RAID,
SECRET_DISCOVERY,
SPECIAL_MOB_DROP,
UNKNOWN); // API does not specify drops for many old boxed items yet

private final List<String> apiNames;
private final String displayName;
private final boolean isMerchant;
Expand Down

0 comments on commit 81337ca

Please sign in to comment.