Refactor reputation tracking
This commit is contained in:
@@ -8,15 +8,7 @@ import net.runelite.api.GameObject;
|
|||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.InventoryID;
|
import net.runelite.api.InventoryID;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.api.events.GameObjectDespawned;
|
import net.runelite.api.events.*;
|
||||||
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.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.client.Notifier;
|
import net.runelite.client.Notifier;
|
||||||
import net.runelite.client.callback.ClientThread;
|
import net.runelite.client.callback.ClientThread;
|
||||||
@@ -54,21 +46,6 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
|||||||
|
|
||||||
private static final int PREFORM = 27010;
|
private static final int PREFORM = 27010;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
private boolean increasePoints = false;
|
|
||||||
|
|
||||||
private Stage oldStage;
|
private Stage oldStage;
|
||||||
|
|
||||||
private int lastBoost;
|
private int lastBoost;
|
||||||
@@ -108,6 +85,10 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ConfigManager configManager;
|
private ConfigManager configManager;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Inject
|
||||||
|
private ReputationTracker reputationTracker;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp()
|
protected void startUp()
|
||||||
{
|
{
|
||||||
@@ -163,11 +144,7 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
|||||||
|
|
||||||
if (event.getGameState().equals(GameState.LOGGED_IN))
|
if (event.getGameState().equals(GameState.LOGGED_IN))
|
||||||
{
|
{
|
||||||
Integer points = configManager.getRSProfileConfiguration(config.GROUP, config.POINTS_KEY, int.class);
|
reputationTracker.load();
|
||||||
if (points != null)
|
|
||||||
{
|
|
||||||
shopPoints = points;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,37 +266,12 @@ public class EasyGiantsFoundryPlugin extends Plugin
|
|||||||
public void onGameTick(GameTick event)
|
public void onGameTick(GameTick event)
|
||||||
{
|
{
|
||||||
checkBonus();
|
checkBonus();
|
||||||
|
|
||||||
Widget chat = client.getWidget(CHAT_WIDGET, CHAT_POINTS_TEXT);
|
|
||||||
|
|
||||||
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());
|
|
||||||
storePoints();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat == null)
|
@Subscribe
|
||||||
|
public void onWidgetLoaded(WidgetLoaded event)
|
||||||
{
|
{
|
||||||
increasePoints = true;
|
reputationTracker.onWidgetLoaded(event.getGroupId());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String chatText = Text.sanitizeMultilineText(chat.getText());
|
|
||||||
final Matcher matcher = pattern.matcher(chatText);
|
|
||||||
if (increasePoints && matcher.find())
|
|
||||||
{
|
|
||||||
shopPoints += Integer.parseInt(matcher.group("points"));
|
|
||||||
storePoints();
|
|
||||||
increasePoints = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storePoints()
|
|
||||||
{
|
|
||||||
configManager.setRSProfileConfiguration(config.GROUP, config.POINTS_KEY, shopPoints);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBonus()
|
private void checkBonus()
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class FoundryOverlay2D extends OverlayPanel
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int points = plugin.getShopPoints();
|
int points = plugin.getReputationTracker().getShopPoints();
|
||||||
if (config.drawShopPoints())
|
if (config.drawShopPoints())
|
||||||
{
|
{
|
||||||
panelComponent.getChildren().add(
|
panelComponent.getChildren().add(
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.toofifty.easygiantsfoundry;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.widgets.Widget;
|
||||||
|
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 ReputationTracker
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
shopOpened();
|
||||||
|
}
|
||||||
|
else if (groupId == CHAT_WIDGET)
|
||||||
|
{
|
||||||
|
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