Fix pest control shield state checks (#4977)

Closes #4974.

An update for mobile broke checking the shield widgets for hidden. They never technically hide until the game is over.
This commit is contained in:
Ron Young
2018-08-18 06:44:08 -05:00
committed by Tomas Slusny
parent 10401713b1
commit faa3f03b35
3 changed files with 54 additions and 18 deletions

View File

@@ -46,6 +46,26 @@ public class Game
private final PortalContext yellow = new PortalContext(YELLOW);
private final PortalContext red = new PortalContext(RED);
public void fall(String color)
{
if (color.equalsIgnoreCase("purple"))
{
fall(purple);
}
else if (color.equalsIgnoreCase("red"))
{
fall(red);
}
else if (color.equalsIgnoreCase("yellow"))
{
fall(yellow);
}
else if (color.equalsIgnoreCase("blue"))
{
fall(blue);
}
}
public void fall(PortalContext portal)
{
if (!portal.isShielded())

View File

@@ -32,6 +32,8 @@ import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.Arrays;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.NPC;
@@ -55,6 +57,7 @@ public class PestControlOverlay extends Overlay
private final Client client;
// Pest control game
@Getter(AccessLevel.PACKAGE)
private Game game;
@Inject
@@ -121,24 +124,6 @@ public class PestControlOverlay extends Overlay
assert yellowShield != null;
assert redShield != null;
// Check for fallen portals
if (purpleShield.isHidden())
{
game.fall(purple);
}
if (blueShield.isHidden())
{
game.fall(blue);
}
if (yellowShield.isHidden())
{
game.fall(yellow);
}
if (redShield.isHidden())
{
game.fall(red);
}
// Check for dead portals
if (isZero(purpleHealth))
{

View File

@@ -24,7 +24,14 @@
*/
package net.runelite.client.plugins.pestcontrol;
import com.google.common.eventbus.Subscribe;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.events.SetMessage;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
@@ -39,9 +46,14 @@ public class PestControlPlugin extends Plugin
@Inject
private OverlayManager overlayManager;
@Inject
private Client client;
@Inject
private PestControlOverlay overlay;
private Pattern pattern = Pattern.compile("The ([a-z]+), [^ ]+ portal shield has dropped!", Pattern.CASE_INSENSITIVE);
@Override
protected void startUp() throws Exception
{
@@ -53,4 +65,23 @@ public class PestControlPlugin extends Plugin
{
overlayManager.remove(overlay);
}
@Subscribe
private void onSetMessage(SetMessage setMessage)
{
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
{
return;
}
if (overlay.getGame() != null && setMessage.getType() == ChatMessageType.SERVER)
{
Matcher matcher = pattern.matcher(setMessage.getValue());
if (matcher.lookingAt())
{
overlay.getGame().fall(matcher.group(1));
}
}
}
}