achievementdiary: Split requirements into multiple classes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Abex
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class CombatLevelRequirement implements Requirement
|
||||
{
|
||||
private final int level;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return level + " " + "Combat";
|
||||
}
|
||||
}
|
||||
@@ -25,17 +25,19 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
class DiaryRequirement
|
||||
{
|
||||
private final String task;
|
||||
private final Requirement[] skillRequirements;
|
||||
private final List<Requirement> requirements;
|
||||
|
||||
DiaryRequirement(String task, Requirement[] skillRequirements)
|
||||
DiaryRequirement(String task, Requirement[] requirements)
|
||||
{
|
||||
this.task = task;
|
||||
this.skillRequirements = skillRequirements;
|
||||
this.requirements = ImmutableList.copyOf(requirements);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -35,7 +34,6 @@ import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.ScriptID;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
@@ -55,7 +53,6 @@ import net.runelite.client.plugins.achievementdiary.diaries.MorytaniaDiaryRequir
|
||||
import net.runelite.client.plugins.achievementdiary.diaries.VarrockDiaryRequirement;
|
||||
import net.runelite.client.plugins.achievementdiary.diaries.WesternDiaryRequirement;
|
||||
import net.runelite.client.plugins.achievementdiary.diaries.WildernessDiaryRequirement;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@Slf4j
|
||||
@@ -66,6 +63,8 @@ import net.runelite.client.util.Text;
|
||||
)
|
||||
public class DiaryRequirementsPlugin extends Plugin
|
||||
{
|
||||
private static final String AND_JOINER = ", ";
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -233,66 +232,49 @@ public class DiaryRequirementsPlugin extends Plugin
|
||||
// returns a map of task -> level requirements
|
||||
private Map<String, String> buildRequirements(Collection<DiaryRequirement> requirements)
|
||||
{
|
||||
Map<String, String> lineIndexRequirementMap = new HashMap<>();
|
||||
Map<String, String> reqs = new HashMap<>();
|
||||
for (DiaryRequirement req : requirements)
|
||||
{
|
||||
String reqTask = req.getTask();
|
||||
List<RequirementStringBuilder> requirementBuilders = new ArrayList<>();
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("<col=ffffff>(");
|
||||
|
||||
for (Requirement i : req.getSkillRequirements())
|
||||
assert req.getRequirements().size() > 0;
|
||||
for (Requirement ireq : req.getRequirements())
|
||||
{
|
||||
RequirementStringBuilder requirementStringBuilder = new RequirementStringBuilder(i);
|
||||
|
||||
Skill skill = i.getSkill();
|
||||
int realSkillLevel;
|
||||
if (skill == null && i.getCustomRequirement().equals("Combat"))
|
||||
{
|
||||
realSkillLevel = client.getLocalPlayer().getCombatLevel();
|
||||
}
|
||||
else
|
||||
{
|
||||
realSkillLevel = client.getRealSkillLevel(skill);
|
||||
}
|
||||
List<Integer> altRealSkillLevels = null;
|
||||
if (i.getAltRequirements() != null)
|
||||
{
|
||||
altRealSkillLevels = new ArrayList<>();
|
||||
for (Requirement j : i.getAltRequirements())
|
||||
{
|
||||
altRealSkillLevels.add(client.getRealSkillLevel(j.getSkill()));
|
||||
}
|
||||
}
|
||||
|
||||
if (requirementStringBuilder.hasLevelRequirement(realSkillLevel, altRealSkillLevels))
|
||||
{
|
||||
requirementStringBuilder.strikeThroughRequirement();
|
||||
}
|
||||
else
|
||||
{
|
||||
requirementStringBuilder.colorRedRequirement();
|
||||
}
|
||||
requirementBuilders .add(requirementStringBuilder);
|
||||
boolean satifisfied = satisfiesRequirement(ireq);
|
||||
b.append(satifisfied ? "<col=000080><str>" : "<col=800000>");
|
||||
b.append(ireq.toString());
|
||||
b.append(satifisfied ? "</str>" : "<col=000080>");
|
||||
b.append(AND_JOINER);
|
||||
}
|
||||
|
||||
lineIndexRequirementMap.put(reqTask, combine(requirementBuilders ));
|
||||
b.delete(b.length() - AND_JOINER.length(), b.length());
|
||||
|
||||
b.append("<col=ffffff>)");
|
||||
|
||||
reqs.put(req.getTask(), b.toString());
|
||||
}
|
||||
return lineIndexRequirementMap;
|
||||
return reqs;
|
||||
}
|
||||
|
||||
private String combine(List<RequirementStringBuilder> list)
|
||||
private boolean satisfiesRequirement(Requirement r)
|
||||
{
|
||||
StringBuilder requirementsString = new StringBuilder();
|
||||
requirementsString.append(ColorUtil.prependColorTag(" (", Color.WHITE));
|
||||
for (RequirementStringBuilder req : list)
|
||||
if (r instanceof OrRequirement)
|
||||
{
|
||||
requirementsString.append(ColorUtil.colorTag(new Color(0x80)))
|
||||
.append(req.getRequirementString())
|
||||
.append(", ");
|
||||
return ((OrRequirement) r).getRequirements()
|
||||
.stream()
|
||||
.anyMatch(this::satisfiesRequirement);
|
||||
}
|
||||
requirementsString.deleteCharAt(requirementsString.length() - 1);
|
||||
requirementsString.deleteCharAt(requirementsString.length() - 2);
|
||||
requirementsString.append(ColorUtil.prependColorTag(")", Color.WHITE));
|
||||
|
||||
return requirementsString.toString();
|
||||
if (r instanceof SkillRequirement)
|
||||
{
|
||||
SkillRequirement s = (SkillRequirement) r;
|
||||
return client.getRealSkillLevel(s.getSkill()) >= s.getLevel();
|
||||
}
|
||||
if (r instanceof CombatLevelRequirement)
|
||||
{
|
||||
return client.getLocalPlayer().getCombatLevel() >= ((CombatLevelRequirement) r).getLevel();
|
||||
}
|
||||
log.warn("Unknown requirement {}", r);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Abex
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
public class OrRequirement implements Requirement
|
||||
{
|
||||
@Getter
|
||||
private final List<Requirement> requirements;
|
||||
|
||||
public OrRequirement(Requirement... reqs)
|
||||
{
|
||||
this.requirements = ImmutableList.copyOf(reqs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return Joiner.on(" or ").join(requirements);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* Copyright (c) 2019 Abex
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -23,30 +23,6 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Skill;
|
||||
|
||||
@Getter
|
||||
public class Requirement
|
||||
public interface Requirement
|
||||
{
|
||||
private final Skill skill;
|
||||
private final String customRequirement;
|
||||
private final int levelRequirement;
|
||||
private final Requirement[] altRequirements;
|
||||
|
||||
public Requirement(Skill skill, int levelRequirement, Requirement... altRequirements)
|
||||
{
|
||||
this.skill = skill;
|
||||
this.customRequirement = null;
|
||||
this.levelRequirement = levelRequirement;
|
||||
this.altRequirements = altRequirements;
|
||||
}
|
||||
|
||||
public Requirement(String customRequirement, int levelRequirement, Requirement... altRequirements)
|
||||
{
|
||||
this.skill = null;
|
||||
this.customRequirement = customRequirement;
|
||||
this.levelRequirement = levelRequirement;
|
||||
this.altRequirements = altRequirements;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Marshall <https://github.com/marshdevs>
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
|
||||
class RequirementStringBuilder
|
||||
{
|
||||
private final Requirement requirement;
|
||||
@Getter
|
||||
private String requirementString;
|
||||
|
||||
RequirementStringBuilder(Requirement requirement)
|
||||
{
|
||||
this.requirement = requirement;
|
||||
|
||||
int levelRequirement = requirement.getLevelRequirement();
|
||||
Skill skill = requirement.getSkill();
|
||||
Requirement[] altRequirements = requirement.getAltRequirements();
|
||||
|
||||
StringBuilder requirementStringBuilder = new StringBuilder()
|
||||
.append(levelRequirement)
|
||||
.append(" ")
|
||||
.append(skill != null ? skill.getName() : requirement.getCustomRequirement());
|
||||
for (Requirement i : altRequirements)
|
||||
{
|
||||
requirementStringBuilder.append(" or ")
|
||||
.append(i.getLevelRequirement())
|
||||
.append(" ")
|
||||
.append(i.getSkill().getName());
|
||||
}
|
||||
this.requirementString = requirementStringBuilder.toString();
|
||||
}
|
||||
|
||||
void strikeThroughRequirement()
|
||||
{
|
||||
this.requirementString = "<str>" + this.requirementString + "</str>";
|
||||
}
|
||||
|
||||
void colorRedRequirement()
|
||||
{
|
||||
this.requirementString = ColorUtil.wrapWithColorTag(this.requirementString, new Color(0x800000));
|
||||
}
|
||||
|
||||
boolean hasLevelRequirement(int realSkillLevel, List<Integer> altRealSkillLevels)
|
||||
{
|
||||
return hasLevelRequirement(requirement, realSkillLevel, altRealSkillLevels);
|
||||
}
|
||||
|
||||
private static boolean hasLevelRequirement(Requirement requirement, int realSkillLevel, List<Integer> altRealSkillLevels)
|
||||
{
|
||||
int levelRequirement = requirement.getLevelRequirement();
|
||||
Requirement[] altRequirements = requirement.getAltRequirements();
|
||||
|
||||
boolean hasReq = (realSkillLevel >= levelRequirement);
|
||||
if (altRequirements != null && altRealSkillLevels != null)
|
||||
{
|
||||
int reqCounter = 0;
|
||||
for (Requirement i : altRequirements)
|
||||
{
|
||||
hasReq = (hasReq || hasLevelRequirement(i, altRealSkillLevels.get(reqCounter), null));
|
||||
reqCounter++;
|
||||
}
|
||||
}
|
||||
return hasReq;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Abex
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.achievementdiary;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.runelite.api.Skill;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class SkillRequirement implements Requirement
|
||||
{
|
||||
private final Skill skill;
|
||||
private final int level;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return level + " " + skill.getName();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user