Update reputation from more reliable varp
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.toofifty.easygiantsfoundry;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import com.toofifty.easygiantsfoundry.enums.Stage;
|
||||
import javax.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
@@ -8,18 +10,24 @@ import net.runelite.api.GameObject;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.events.*;
|
||||
import net.runelite.api.events.GameObjectDespawned;
|
||||
import net.runelite.api.events.GameObjectSpawned;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.api.events.ScriptPostFired;
|
||||
import net.runelite.api.events.StatChanged;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import com.toofifty.easygiantsfoundry.enums.Stage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Slf4j
|
||||
@PluginDescriptor(
|
||||
@@ -42,12 +50,17 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
||||
|
||||
private static final int PREFORM = 27010;
|
||||
|
||||
private static final int REPUTATION_VARBIT = 3436;
|
||||
|
||||
private Stage oldStage;
|
||||
|
||||
private int lastBoost;
|
||||
|
||||
private boolean bonusNotified = false;
|
||||
|
||||
@Getter
|
||||
private int reputation;
|
||||
|
||||
@Inject
|
||||
private EasyGiantsFoundryState state;
|
||||
|
||||
@@ -81,15 +94,15 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
||||
@Inject
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Getter
|
||||
@Inject
|
||||
private PointsTracker pointsTracker;
|
||||
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
overlayManager.add(overlay2d);
|
||||
overlayManager.add(overlay3d);
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
reputation = client.getVarpValue(REPUTATION_VARBIT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +153,7 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
||||
|
||||
if (event.getGameState().equals(GameState.LOGGED_IN))
|
||||
{
|
||||
pointsTracker.load();
|
||||
reputation = client.getVarpValue(REPUTATION_VARBIT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +257,15 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
if (event.getVarpId() == REPUTATION_VARBIT)
|
||||
{
|
||||
reputation = client.getVarpValue(REPUTATION_VARBIT);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
protected void onConfigChanged(ConfigChanged configChanged)
|
||||
{
|
||||
@@ -264,12 +286,6 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
||||
checkBonus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWidgetLoaded(WidgetLoaded event)
|
||||
{
|
||||
pointsTracker.onWidgetLoaded(event.getGroupId());
|
||||
}
|
||||
|
||||
private void checkBonus()
|
||||
{
|
||||
if (!state.isEnabled() || state.getCurrentStage() == null
|
||||
|
||||
@@ -2,6 +2,11 @@ package com.toofifty.easygiantsfoundry;
|
||||
|
||||
import com.toofifty.easygiantsfoundry.enums.Heat;
|
||||
import com.toofifty.easygiantsfoundry.enums.Stage;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.overlay.OverlayPanel;
|
||||
@@ -9,12 +14,6 @@ import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.LineComponent;
|
||||
import net.runelite.client.ui.overlay.components.TitleComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
@Singleton
|
||||
public class FoundryOverlay2D extends OverlayPanel
|
||||
{
|
||||
@@ -98,12 +97,12 @@ public class FoundryOverlay2D extends OverlayPanel
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int points = plugin.getPointsTracker().getShopPoints();
|
||||
//
|
||||
// int points = plugin.getPointsTracker().getShopPoints();
|
||||
if (config.drawShopPoints())
|
||||
{
|
||||
panelComponent.getChildren().add(
|
||||
LineComponent.builder().left("Reputation").right(points + "").build()
|
||||
LineComponent.builder().left("Reputation").right(plugin.getReputation() + "").build()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.toofifty.easygiantsfoundry;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PointsTracker
|
||||
{
|
||||
private static final int SHOP_WIDGET = 753;
|
||||
private static final int CHAT_WIDGET = 229;
|
||||
private static final int SHOP_POINTS_TEXT = 13;
|
||||
private static final int CHAT_POINTS_TEXT = 1;
|
||||
private static final Pattern pattern = Pattern.compile("quality: (?<points>\\d+) Best");
|
||||
|
||||
@Getter
|
||||
private int shopPoints;
|
||||
|
||||
@Inject
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
ClientThread clientThread;
|
||||
|
||||
public void load()
|
||||
{
|
||||
Integer points = configManager.getRSProfileConfiguration(EasyGiantsFoundryConfig.GROUP, EasyGiantsFoundryConfig.POINTS_KEY, int.class);
|
||||
if (points != null)
|
||||
{
|
||||
shopPoints = points;
|
||||
}
|
||||
}
|
||||
|
||||
private void save()
|
||||
{
|
||||
configManager.setRSProfileConfiguration(EasyGiantsFoundryConfig.GROUP, EasyGiantsFoundryConfig.POINTS_KEY, shopPoints);
|
||||
}
|
||||
|
||||
public void onWidgetLoaded(int groupId)
|
||||
{
|
||||
if (groupId == SHOP_WIDGET)
|
||||
{
|
||||
clientThread.invokeLater(this::shopOpened);
|
||||
}
|
||||
else if (groupId == CHAT_WIDGET)
|
||||
{
|
||||
clientThread.invokeLater(this::chatBox);
|
||||
}
|
||||
}
|
||||
|
||||
private void chatBox()
|
||||
{
|
||||
Widget chat = client.getWidget(CHAT_WIDGET, CHAT_POINTS_TEXT);
|
||||
if (chat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String chatText = Text.sanitizeMultilineText(chat.getText());
|
||||
final Matcher matcher = pattern.matcher(chatText);
|
||||
if (matcher.find())
|
||||
{
|
||||
shopPoints += Integer.parseInt(matcher.group("points"));
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
private void shopOpened()
|
||||
{
|
||||
Widget shop = client.getWidget(SHOP_WIDGET, SHOP_POINTS_TEXT);
|
||||
if (shop != null && shop.getText() != null && Integer.parseInt(shop.getText()) != shopPoints)
|
||||
{
|
||||
shopPoints = Integer.parseInt(shop.getText());
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user