diff --git a/runelite-api/src/main/java/net/runelite/api/VarClientInt.java b/runelite-api/src/main/java/net/runelite/api/VarClientInt.java index 4701c83f09..a4bb531e92 100644 --- a/runelite-api/src/main/java/net/runelite/api/VarClientInt.java +++ b/runelite-api/src/main/java/net/runelite/api/VarClientInt.java @@ -36,6 +36,8 @@ public enum VarClientInt { TOOLTIP_TIMEOUT(1), + MEMBERSHIP_STATUS(103), + WORLD_MAP_SEARCH_FOCUSED(190); private final int index; diff --git a/runelite-api/src/main/java/net/runelite/api/VarPlayer.java b/runelite-api/src/main/java/net/runelite/api/VarPlayer.java index 1d58863a22..721c9c04e6 100644 --- a/runelite-api/src/main/java/net/runelite/api/VarPlayer.java +++ b/runelite-api/src/main/java/net/runelite/api/VarPlayer.java @@ -45,6 +45,8 @@ public enum VarPlayer IN_RAID_PARTY(1427), + NMZ_REWARD_POINTS(1060), + /** * Experience tracker goal start. */ diff --git a/runelite-api/src/main/java/net/runelite/api/Varbits.java b/runelite-api/src/main/java/net/runelite/api/Varbits.java index e1eef25127..628e1a8235 100644 --- a/runelite-api/src/main/java/net/runelite/api/Varbits.java +++ b/runelite-api/src/main/java/net/runelite/api/Varbits.java @@ -349,10 +349,10 @@ public enum Varbits /** * Daily Tasks (Collection availability) */ - DAILY_HERB_BOX(3961), - DAILY_STAVES(4539), - DAILY_ESSENCE(4547), - DAILY_RUNES(4540), + DAILY_HERB_BOXES_COLLECTED(3961), + DAILY_STAVES_COLLECTED(4539), + DAILY_ESSENCE_COLLECTED(4547), + DAILY_RUNES_COLLECTED(4540), /** * Fairy Ring diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksConfig.java index 5d8162f51c..9ead9f8744 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksConfig.java @@ -1,5 +1,7 @@ /* * Copyright (c) 2018, Infinitay + * Copyright (c) 2018, Shaun Dreclin + * * All rights reserved. * * 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 { @ConfigItem( + position = 1, keyName = "showHerbBoxes", name = "Show Herb Boxes", - description = "Configures whether or not to show a message when you can" + - " collect your daily herb boxes at NMZ", - position = 1 + description = "Show a message when you can collect your daily herb boxes at NMZ." ) default boolean showHerbBoxes() { @@ -44,11 +45,10 @@ public interface DailyTasksConfig extends Config } @ConfigItem( + position = 2, keyName = "showStaves", name = "Show Claimable Staves", - description = "Configures whether or not to show a message when you can" + - " collect your daily staves from Zaff", - position = 2 + description = "Show a message when you can collect your daily battlestaves from Zaff." ) default boolean showStaves() { @@ -56,11 +56,10 @@ public interface DailyTasksConfig extends Config } @ConfigItem( + position = 3, keyName = "showEssence", name = "Show Claimable Essence", - description = "Configures whether or not to show a message when you can" + - " collect your daily pure essence from Wizard Cromperty", - position = 3 + description = "Show a message when you can collect your daily pure essence from Wizard Cromperty." ) default boolean showEssence() { @@ -68,11 +67,10 @@ public interface DailyTasksConfig extends Config } @ConfigItem( + position = 4, keyName = "showRunes", name = "Show Claimable Random Runes", - description = "Configures whether or not to show a message when you can" + - " collect your daily random runes from Lundail", - position = 4 + description = "Show a message when you can collect your daily random runes from Lundail." ) default boolean showRunes() { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksPlugin.java index 46e8c3c549..710f00a07c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/dailytaskindicators/DailyTasksPlugin.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Infinitay + * Copyright (c) 2018, Shaun Dreclin * All rights reserved. * * 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 net.runelite.api.ChatMessageType; 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.events.ConfigChanged; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; import net.runelite.api.vars.AccountType; @@ -45,11 +48,24 @@ import net.runelite.client.plugins.PluginDescriptor; @PluginDescriptor( name = "Daily Task Indicator", - description = "Show chat notifications for daily tasks upon login", - enabledByDefault = false + description = "Show chat notifications for daily tasks upon login" ) 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 private Client client; @@ -59,7 +75,8 @@ public class DailyTasksPlugin extends Plugin @Inject private ChatMessageManager chatMessageManager; - private boolean hasSentHerbMsg, hasSentStavesMsg, hasSentEssenceMsg, hasSentRunesMsg, check; + private long lastReset; + private boolean loggingIn; @Provides DailyTasksConfig provideConfig(ConfigManager configManager) @@ -67,112 +84,117 @@ public class DailyTasksPlugin extends Plugin return configManager.getConfig(DailyTasksConfig.class); } - @Override - protected void startUp() throws Exception - { - hasSentHerbMsg = hasSentStavesMsg = hasSentEssenceMsg = hasSentRunesMsg = false; - } - @Override protected void shutDown() throws Exception { - hasSentHerbMsg = hasSentStavesMsg = hasSentEssenceMsg = hasSentRunesMsg = 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; - } - } + lastReset = 0L; + loggingIn = false; } @Subscribe public void onGameStateChanged(GameStateChanged event) { - switch (event.getGameState()) + if (event.getGameState() == GameState.LOGGING_IN) { - case HOPPING: - case LOGGED_IN: - //load the varbits on first available tick - check = true; - break; + loggingIn = true; } } @Subscribe public void onGameTick(GameTick event) { - if (!check) - { - return; - } - - check = false; + long currentTime = System.currentTimeMillis(); + boolean dailyReset = !loggingIn && currentTime - lastReset > ONE_DAY; - if (config.showHerbBoxes() && !hasSentHerbMsg && checkCanCollectHerbBox()) + if ((dailyReset || loggingIn) + && client.getGameState() == GameState.LOGGED_IN + && client.getVar(VarClientInt.MEMBERSHIP_STATUS) == 1) { - sendChatMessage("You have herb boxes waiting to be collected at NMZ."); - hasSentHerbMsg = true; - } + // Round down to the nearest day + lastReset = (long) Math.floor(currentTime / ONE_DAY) * ONE_DAY; + loggingIn = false; - if (config.showStaves() && !hasSentStavesMsg && checkCanCollectStaves()) - { - sendChatMessage("You have staves waiting to be collected from Zaff."); - hasSentStavesMsg = true; - } + if (config.showHerbBoxes()) + { + checkHerbBoxes(dailyReset); + } - if (config.showEssence() && !hasSentEssenceMsg && checkCanCollectEssence()) - { - sendChatMessage("You have pure essence waiting to be collected from Wizard Cromperty."); - hasSentEssenceMsg = true; - } + if (config.showStaves()) + { + checkStaves(dailyReset); + } - if (config.showRunes() && !hasSentRunesMsg && checkCanCollectRunes()) - { - sendChatMessage("You have random runes waiting to be collected from Lundail."); - hasSentRunesMsg = true; + if (config.showEssence()) + { + checkEssence(dailyReset); + } + + if (config.showRunes()) + { + checkRunes(dailyReset); + } } } - private boolean checkCanCollectHerbBox() + private void checkHerbBoxes(boolean dailyReset) { - // Exclude ironmen from herb box notifications - int value = client.getVar(Varbits.DAILY_HERB_BOX); - return client.getAccountType() == AccountType.NORMAL && value < 15; // < 15 can claim + if (client.getAccountType() == AccountType.NORMAL + && client.getVar(VarPlayer.NMZ_REWARD_POINTS) >= HERB_BOX_COST) + { + 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); - return value == 0; // 1 = can't claim + if (client.getVar(Varbits.DIARY_VARROCK_EASY) == 1) + { + 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); - return value == 0; // 1 = can't claim + if (client.getVar(Varbits.DIARY_ARDOUGNE_MEDIUM) == 1) + { + 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 - && client.getVar(Varbits.DAILY_RUNES) == 0; + if (client.getVar(Varbits.DIARY_WILDERNESS_EASY) == 1) + { + if (client.getVar(Varbits.DAILY_RUNES_COLLECTED) == 0) + { + sendChatMessage(RUNES_MESSAGE); + } + else if (dailyReset) + { + sendChatMessage(RUNES_MESSAGE + RELOG_MESSAGE); + } + } } private void sendChatMessage(String chatMessage)