Skip to content

Commit

Permalink
Fix hiscore lookup for ironman in chat commands
Browse files Browse the repository at this point in the history
Use correct ironman type when looking up hiscore with lvl/total
commands.

Fixes runelite#1936

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
Gamer1120 authored and johannajennekvist committed Jul 1, 2018
1 parent b174a8f commit 0eb2a37
Showing 1 changed file with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.AccountType;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ItemComposition;
import net.runelite.api.MessageNode;
import net.runelite.api.Varbits;
import net.runelite.api.events.SetMessage;
import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder;
Expand All @@ -50,6 +52,7 @@
import net.runelite.client.util.StackFormatter;
import net.runelite.http.api.hiscore.HiscoreClient;
import net.runelite.http.api.hiscore.HiscoreResult;
import net.runelite.http.api.hiscore.HiscoreEndpoint;
import net.runelite.http.api.hiscore.HiscoreSkill;
import net.runelite.http.api.hiscore.SingleHiscoreSkillResult;
import net.runelite.http.api.hiscore.Skill;
Expand Down Expand Up @@ -244,18 +247,31 @@ private void itemPriceLookup(MessageNode messageNode, String search)
private void playerSkillLookup(ChatMessageType type, SetMessage setMessage, String search)
{
search = SkillAbbreviations.getFullName(search);
final String player;
final HiscoreEndpoint ironmanStatus;

String player;
if (type.equals(ChatMessageType.PRIVATE_MESSAGE_SENT))
{
player = client.getLocalPlayer().getName();
ironmanStatus = getIronmanStatusByVarbit();
}
else
{
player = sanitize(setMessage.getName());

if (player.equals(client.getLocalPlayer().getName()))
{
// Get ironman btw status from varbit
ironmanStatus = getIronmanStatusByVarbit();
}
else
{
// Get ironman btw status from their icon in chat
ironmanStatus = getIronmanStatusByName(setMessage.getName());
}
}

HiscoreSkill skill;
final HiscoreSkill skill;
try
{
skill = HiscoreSkill.valueOf(search.toUpperCase());
Expand All @@ -267,7 +283,7 @@ private void playerSkillLookup(ChatMessageType type, SetMessage setMessage, Stri

try
{
SingleHiscoreSkillResult result = hiscoreClient.lookup(player, skill);
SingleHiscoreSkillResult result = hiscoreClient.lookup(player, skill, ironmanStatus);
Skill hiscoreSkill = result.getSkill();

String response = new ChatMessageBuilder()
Expand Down Expand Up @@ -411,4 +427,43 @@ private static String sanitize(String lookup)
String cleaned = lookup.contains("<img") ? lookup.substring(lookup.lastIndexOf('>') + 1) : lookup;
return cleaned.replace('\u00A0', ' ');
}

/**
* Looks up the ironman status of the local player. Does NOT work on other players.
* @return hiscore endpoint
*/
private HiscoreEndpoint getIronmanStatusByVarbit()
{
return toEndPoint(AccountType.fromVarbit(client.getVarbitValue(client.getVarps(), Varbits.IRONMAN_STATUS.getId())));
}

/**
* Returns the ironman status based on the symbol in the name of the player.
* @param name player name
* @return hiscore endpoint
*/
private static HiscoreEndpoint getIronmanStatusByName(final String name)
{
return toEndPoint(AccountType.fromName(name));
}

/**
* Converts account type to hiscore endpoint
* @param accountType account type
* @return hiscore endpoint
*/
private static HiscoreEndpoint toEndPoint(final AccountType accountType)
{
switch (accountType)
{
case IRONMAN:
return HiscoreEndpoint.IRONMAN;
case ULTIMATE_IRONMAN:
return HiscoreEndpoint.ULTIMATE_IRONMAN;
case HARDCORE_IRONMAN:
return HiscoreEndpoint.HARDCORE_IRONMAN;
default:
return HiscoreEndpoint.NORMAL;
}
}
}

0 comments on commit 0eb2a37

Please sign in to comment.