Refactor daily task indicator plugin

This commit is contained in:
Shaun Dreclin
2018-08-30 06:39:54 -04:00
committed by ShaunDreclin
parent 45cb0bcde7
commit f00a2aac39
5 changed files with 117 additions and 93 deletions

View File

@@ -36,6 +36,8 @@ public enum VarClientInt
{ {
TOOLTIP_TIMEOUT(1), TOOLTIP_TIMEOUT(1),
MEMBERSHIP_STATUS(103),
WORLD_MAP_SEARCH_FOCUSED(190); WORLD_MAP_SEARCH_FOCUSED(190);
private final int index; private final int index;

View File

@@ -45,6 +45,8 @@ public enum VarPlayer
IN_RAID_PARTY(1427), IN_RAID_PARTY(1427),
NMZ_REWARD_POINTS(1060),
/** /**
* Experience tracker goal start. * Experience tracker goal start.
*/ */

View File

@@ -349,10 +349,10 @@ public enum Varbits
/** /**
* Daily Tasks (Collection availability) * Daily Tasks (Collection availability)
*/ */
DAILY_HERB_BOX(3961), DAILY_HERB_BOXES_COLLECTED(3961),
DAILY_STAVES(4539), DAILY_STAVES_COLLECTED(4539),
DAILY_ESSENCE(4547), DAILY_ESSENCE_COLLECTED(4547),
DAILY_RUNES(4540), DAILY_RUNES_COLLECTED(4540),
/** /**
* Fairy Ring * Fairy Ring

View File

@@ -1,5 +1,7 @@
/* /*
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay> * Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
* Copyright (c) 2018, Shaun Dreclin <https://github.com/ShaunDreclin>
*
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -32,11 +34,10 @@ import net.runelite.client.config.ConfigItem;
public interface DailyTasksConfig extends Config public interface DailyTasksConfig extends Config
{ {
@ConfigItem( @ConfigItem(
position = 1,
keyName = "showHerbBoxes", keyName = "showHerbBoxes",
name = "Show Herb Boxes", name = "Show Herb Boxes",
description = "Configures whether or not to show a message when you can" + description = "Show a message when you can collect your daily herb boxes at NMZ."
" collect your daily herb boxes at NMZ",
position = 1
) )
default boolean showHerbBoxes() default boolean showHerbBoxes()
{ {
@@ -44,11 +45,10 @@ public interface DailyTasksConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 2,
keyName = "showStaves", keyName = "showStaves",
name = "Show Claimable Staves", name = "Show Claimable Staves",
description = "Configures whether or not to show a message when you can" + description = "Show a message when you can collect your daily battlestaves from Zaff."
" collect your daily staves from Zaff",
position = 2
) )
default boolean showStaves() default boolean showStaves()
{ {
@@ -56,11 +56,10 @@ public interface DailyTasksConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 3,
keyName = "showEssence", keyName = "showEssence",
name = "Show Claimable Essence", name = "Show Claimable Essence",
description = "Configures whether or not to show a message when you can" + description = "Show a message when you can collect your daily pure essence from Wizard Cromperty."
" collect your daily pure essence from Wizard Cromperty",
position = 3
) )
default boolean showEssence() default boolean showEssence()
{ {
@@ -68,11 +67,10 @@ public interface DailyTasksConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 4,
keyName = "showRunes", keyName = "showRunes",
name = "Show Claimable Random Runes", name = "Show Claimable Random Runes",
description = "Configures whether or not to show a message when you can" + description = "Show a message when you can collect your daily random runes from Lundail."
" collect your daily random runes from Lundail",
position = 4
) )
default boolean showRunes() default boolean showRunes()
{ {

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay> * Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
* Copyright (c) 2018, Shaun Dreclin <https://github.com/ShaunDreclin>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -30,8 +31,10 @@ import com.google.inject.Provides;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.VarClientInt;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.vars.AccountType; import net.runelite.api.vars.AccountType;
@@ -45,11 +48,24 @@ import net.runelite.client.plugins.PluginDescriptor;
@PluginDescriptor( @PluginDescriptor(
name = "Daily Task Indicator", name = "Daily Task Indicator",
description = "Show chat notifications for daily tasks upon login", description = "Show chat notifications for daily tasks upon login"
enabledByDefault = false
) )
public class DailyTasksPlugin extends Plugin public class DailyTasksPlugin extends Plugin
{ {
private static final int ONE_DAY = 86400000;
private static final String HERB_BOX_MESSAGE = "You have herb boxes waiting to be collected at NMZ.";
private static final int HERB_BOX_MAX = 15;
private static final int HERB_BOX_COST = 9500;
private static final String STAVES_MESSAGE = "You have battlestaves waiting to be collected from Zaff.";
private static final String ESSENCE_MESSAGE = "You have essence waiting to be collected from Wizard Cromperty.";
private static final String RUNES_MESSAGE = "You have random runes waiting to be collected from Lundail.";
private static final String RELOG_MESSAGE = " (Requires relog)";
@Inject @Inject
private Client client; private Client client;
@@ -59,7 +75,8 @@ public class DailyTasksPlugin extends Plugin
@Inject @Inject
private ChatMessageManager chatMessageManager; private ChatMessageManager chatMessageManager;
private boolean hasSentHerbMsg, hasSentStavesMsg, hasSentEssenceMsg, hasSentRunesMsg, check; private long lastReset;
private boolean loggingIn;
@Provides @Provides
DailyTasksConfig provideConfig(ConfigManager configManager) DailyTasksConfig provideConfig(ConfigManager configManager)
@@ -67,112 +84,117 @@ public class DailyTasksPlugin extends Plugin
return configManager.getConfig(DailyTasksConfig.class); return configManager.getConfig(DailyTasksConfig.class);
} }
@Override
protected void startUp() throws Exception
{
hasSentHerbMsg = hasSentStavesMsg = hasSentEssenceMsg = hasSentRunesMsg = false;
}
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
hasSentHerbMsg = hasSentStavesMsg = hasSentEssenceMsg = hasSentRunesMsg = false; lastReset = 0L;
} loggingIn = false;
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (event.getGroup().equals("dailytaskindicators"))
{
switch (event.getKey())
{
case "showHerbBoxes":
hasSentHerbMsg = false;
break;
case "showStaves":
hasSentStavesMsg = false;
break;
case "showEssence":
hasSentEssenceMsg = false;
break;
case "showRunes":
hasSentRunesMsg = false;
break;
}
}
} }
@Subscribe @Subscribe
public void onGameStateChanged(GameStateChanged event) public void onGameStateChanged(GameStateChanged event)
{ {
switch (event.getGameState()) if (event.getGameState() == GameState.LOGGING_IN)
{ {
case HOPPING: loggingIn = true;
case LOGGED_IN:
//load the varbits on first available tick
check = true;
break;
} }
} }
@Subscribe @Subscribe
public void onGameTick(GameTick event) public void onGameTick(GameTick event)
{ {
if (!check) long currentTime = System.currentTimeMillis();
{ boolean dailyReset = !loggingIn && currentTime - lastReset > ONE_DAY;
return;
}
check = false; if ((dailyReset || loggingIn)
&& client.getGameState() == GameState.LOGGED_IN
if (config.showHerbBoxes() && !hasSentHerbMsg && checkCanCollectHerbBox()) && client.getVar(VarClientInt.MEMBERSHIP_STATUS) == 1)
{ {
sendChatMessage("You have herb boxes waiting to be collected at NMZ."); // Round down to the nearest day
hasSentHerbMsg = true; lastReset = (long) Math.floor(currentTime / ONE_DAY) * ONE_DAY;
} loggingIn = false;
if (config.showStaves() && !hasSentStavesMsg && checkCanCollectStaves()) if (config.showHerbBoxes())
{ {
sendChatMessage("You have staves waiting to be collected from Zaff."); checkHerbBoxes(dailyReset);
hasSentStavesMsg = true; }
}
if (config.showEssence() && !hasSentEssenceMsg && checkCanCollectEssence()) if (config.showStaves())
{ {
sendChatMessage("You have pure essence waiting to be collected from Wizard Cromperty."); checkStaves(dailyReset);
hasSentEssenceMsg = true; }
}
if (config.showRunes() && !hasSentRunesMsg && checkCanCollectRunes()) if (config.showEssence())
{ {
sendChatMessage("You have random runes waiting to be collected from Lundail."); checkEssence(dailyReset);
hasSentRunesMsg = true; }
if (config.showRunes())
{
checkRunes(dailyReset);
}
} }
} }
private boolean checkCanCollectHerbBox() private void checkHerbBoxes(boolean dailyReset)
{ {
// Exclude ironmen from herb box notifications if (client.getAccountType() == AccountType.NORMAL
int value = client.getVar(Varbits.DAILY_HERB_BOX); && client.getVar(VarPlayer.NMZ_REWARD_POINTS) >= HERB_BOX_COST)
return client.getAccountType() == AccountType.NORMAL && value < 15; // < 15 can claim {
if (client.getVar(Varbits.DAILY_HERB_BOXES_COLLECTED) < HERB_BOX_MAX)
{
sendChatMessage(HERB_BOX_MESSAGE);
}
else if (dailyReset)
{
sendChatMessage(HERB_BOX_MESSAGE + RELOG_MESSAGE);
}
}
} }
private boolean checkCanCollectStaves() private void checkStaves(boolean dailyReset)
{ {
int value = client.getVar(Varbits.DAILY_STAVES); if (client.getVar(Varbits.DIARY_VARROCK_EASY) == 1)
return value == 0; // 1 = can't claim {
if (client.getVar(Varbits.DAILY_STAVES_COLLECTED) == 0)
{
sendChatMessage(STAVES_MESSAGE);
}
else if (dailyReset)
{
sendChatMessage(STAVES_MESSAGE + RELOG_MESSAGE);
}
}
} }
private boolean checkCanCollectEssence() private void checkEssence(boolean dailyReset)
{ {
int value = client.getVar(Varbits.DAILY_ESSENCE); if (client.getVar(Varbits.DIARY_ARDOUGNE_MEDIUM) == 1)
return value == 0; // 1 = can't claim {
if (client.getVar(Varbits.DAILY_ESSENCE_COLLECTED) == 0)
{
sendChatMessage(ESSENCE_MESSAGE);
}
else if (dailyReset)
{
sendChatMessage(ESSENCE_MESSAGE + RELOG_MESSAGE);
}
}
} }
private boolean checkCanCollectRunes() private void checkRunes(boolean dailyReset)
{ {
return client.getVar(Varbits.DIARY_WILDERNESS_EASY) == 1 if (client.getVar(Varbits.DIARY_WILDERNESS_EASY) == 1)
&& client.getVar(Varbits.DAILY_RUNES) == 0; {
if (client.getVar(Varbits.DAILY_RUNES_COLLECTED) == 0)
{
sendChatMessage(RUNES_MESSAGE);
}
else if (dailyReset)
{
sendChatMessage(RUNES_MESSAGE + RELOG_MESSAGE);
}
}
} }
private void sendChatMessage(String chatMessage) private void sendChatMessage(String chatMessage)