Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/main/java/io/luna/game/model/def/EquipmentDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public static final class Requirement {
private final String name;

/**
* The internal skill id resolved from {@link #name}.
* The minimum level required.
*/
private final int id;
private final int level;

/**
* The minimum level required.
* The internal skill id resolved from {@link #name}.
*/
private final int level;
private int id;

/**
* Creates a new {@link Requirement} from JSON data.
Expand All @@ -56,13 +56,20 @@ public static final class Requirement {
* <li>{@code name}: skill name</li>
* <li>{@code level}: required level</li>
* </ul>
*
* Note: This constructor is unused, as the requirements are created by gson instantiating via reflection.
* @param jsonReq The requirement JSON object.
*/
public Requirement(JsonObject jsonReq) {
name = jsonReq.get("name").getAsString();
id = Skill.getId(name);
level = jsonReq.get("level").getAsInt();
assignSkillId();
}

/**
* Assigns the internal skill identifier based on the {@link #name}.
*/
public void assignSkillId() {
id = Skill.getId(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.logging.log4j.Logger;

import java.nio.file.Paths;
import java.util.Arrays;

import static org.apache.logging.log4j.util.Unbox.box;

Expand Down Expand Up @@ -40,6 +41,7 @@ public EquipmentDefinition convert(JsonObject token) {
boolean fullBody = token.get("full_body?").getAsBoolean();
boolean fullHelmet = token.get("full_helmet?").getAsBoolean();
Requirement[] requirements = GsonUtils.getAsType(token.get("requirements"), Requirement[].class);
Arrays.stream(requirements).forEach(Requirement::assignSkillId);
int[] bonuses = GsonUtils.getAsType(token.get("bonuses"), int[].class);
return new EquipmentDefinition(id, index, twoHanded, fullBody, fullHelmet, requirements, bonuses);
}
Expand Down
Loading