Merge pull request #713 from Kamielvf/raids-plugin-update

Add more features to raids plugin
This commit is contained in:
Adam
2018-03-01 20:28:14 -05:00
committed by GitHub
6 changed files with 267 additions and 20 deletions

View File

@@ -179,6 +179,8 @@ public enum Varbits
* Raids * Raids
*/ */
IN_RAID(5432), IN_RAID(5432),
TOTAL_POINTS(5431),
PERSONAL_POINTS(5422),
/** /**
* Nightmare Zone * Nightmare Zone

View File

@@ -24,7 +24,9 @@
*/ */
package net.runelite.client.plugins.raids; package net.runelite.client.plugins.raids;
import com.google.common.base.Joiner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.Getter; import lombok.Getter;
import net.runelite.client.plugins.raids.solver.Layout; import net.runelite.client.plugins.raids.solver.Layout;
@@ -109,6 +111,11 @@ public class Raid
return combatRooms.toArray(new RaidRoom[combatRooms.size()]); return combatRooms.toArray(new RaidRoom[combatRooms.size()]);
} }
public String getRotationString()
{
return Joiner.on(",").join(Arrays.stream(getCombatRooms()).map(r -> r.getBoss().getName()).toArray());
}
public String toCode() public String toCode()
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@@ -36,6 +36,7 @@ import net.runelite.client.config.ConfigItem;
public interface RaidsConfig extends Config public interface RaidsConfig extends Config
{ {
@ConfigItem( @ConfigItem(
position = 0,
keyName = "raidsTimer", keyName = "raidsTimer",
name = "Display elapsed raid time", name = "Display elapsed raid time",
description = "Display elapsed raid time" description = "Display elapsed raid time"
@@ -46,6 +47,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 1,
keyName = "pointsMessage", keyName = "pointsMessage",
name = "Display points in chatbox after raid", name = "Display points in chatbox after raid",
description = "Display a message with total points, individual points and percentage at the end of a raid" description = "Display a message with total points, individual points and percentage at the end of a raid"
@@ -56,6 +58,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 2,
keyName = "scoutOverlay", keyName = "scoutOverlay",
name = "Show scout overlay", name = "Show scout overlay",
description = "Display an overlay that shows the current raid layout (when entering lobby)" description = "Display an overlay that shows the current raid layout (when entering lobby)"
@@ -66,6 +69,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 3,
keyName = "scoutOverlayAtBank", keyName = "scoutOverlayAtBank",
name = "Show scout overlay outside lobby", name = "Show scout overlay outside lobby",
description = "Keep the overlay active while at the raids area" description = "Keep the overlay active while at the raids area"
@@ -76,6 +80,18 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 4,
keyName = "whitelistedRooms",
name = "Whitelisted rooms",
description = "Display whitelisted rooms in green on the overlay. Separate with comma (full name)"
)
default String whitelistedRooms()
{
return "";
}
@ConfigItem(
position = 5,
keyName = "blacklistedRooms", keyName = "blacklistedRooms",
name = "Blacklisted rooms", name = "Blacklisted rooms",
description = "Display blacklisted rooms in red on the overlay. Separate with comma (full name)" description = "Display blacklisted rooms in red on the overlay. Separate with comma (full name)"
@@ -84,4 +100,48 @@ public interface RaidsConfig extends Config
{ {
return ""; return "";
} }
@ConfigItem(
position = 6,
keyName = "enableRotationWhitelist",
name = "Enable rotation whitelist",
description = "Enable the rotation whitelist"
)
default boolean enableRotationWhitelist()
{
return false;
}
@ConfigItem(
position = 7,
keyName = "whitelistedRotations",
name = "Whitelisted rotations",
description = "Warn when boss rotation doesn't match a whitelisted one. Add rotations like [tekton, muttadile, guardians]"
)
default String whitelistedRotations()
{
return "";
}
@ConfigItem(
position = 8,
keyName = "enableLayoutWhitelist",
name = "Enable layout whitelist",
description = "Enable the layout whitelist"
)
default boolean enableLayoutWhitelist()
{
return false;
}
@ConfigItem(
position = 9,
keyName = "whitelistedLayouts",
name = "Whitelisted layouts",
description = "Warn when layout doesn't match a whitelisted one. Add layouts like CFSCPPCSCF separated with comma"
)
default String whitelistedLayouts()
{
return "";
}
} }

View File

@@ -74,6 +74,26 @@ public class RaidsOverlay extends Overlay
panelComponent.setTitleColor(Color.WHITE); panelComponent.setTitleColor(Color.WHITE);
panelComponent.setTitle("Raid scouter"); panelComponent.setTitle("Raid scouter");
Color color = Color.WHITE;
String layout = plugin.getRaid().getLayout().toCode().replaceAll("#", "").replaceAll("¤", "");
if (config.enableLayoutWhitelist() && !plugin.getLayoutWhitelist().contains(layout.toLowerCase()))
{
color = Color.RED;
}
panelComponent.getLines().add(new PanelComponent.Line(
"Layout", Color.WHITE, layout, color
));
int bossMatches = 0;
int bossCount = 0;
if (config.enableRotationWhitelist())
{
bossMatches = plugin.getRotationMatches();
}
for (Room layoutRoom : plugin.getRaid().getLayout().getRooms()) for (Room layoutRoom : plugin.getRaid().getLayout().getRooms())
{ {
int position = layoutRoom.getPosition(); int position = layoutRoom.getPosition();
@@ -84,12 +104,18 @@ public class RaidsOverlay extends Overlay
continue; continue;
} }
Color color = Color.WHITE; color = Color.WHITE;
switch (room.getType()) switch (room.getType())
{ {
case COMBAT: case COMBAT:
if (plugin.getBlacklist().contains(room.getBoss().getName().toLowerCase())) bossCount++;
if (plugin.getRoomWhitelist().contains(room.getBoss().getName().toLowerCase()))
{
color = Color.GREEN;
}
else if (plugin.getRoomBlacklist().contains(room.getBoss().getName().toLowerCase())
|| config.enableRotationWhitelist() && bossCount > bossMatches)
{ {
color = Color.RED; color = Color.RED;
} }
@@ -100,7 +126,11 @@ public class RaidsOverlay extends Overlay
break; break;
case PUZZLE: case PUZZLE:
if (plugin.getBlacklist().contains(room.getPuzzle().getName().toLowerCase())) if (plugin.getRoomWhitelist().contains(room.getPuzzle().getName().toLowerCase()))
{
color = Color.GREEN;
}
else if (plugin.getRoomBlacklist().contains(room.getPuzzle().getName().toLowerCase()))
{ {
color = Color.RED; color = Color.RED;
} }

View File

@@ -35,17 +35,25 @@ import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.*; import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.InstanceTemplates;
import net.runelite.api.ObjectID;
import net.runelite.api.Point;
import net.runelite.api.Setting;
import net.runelite.api.Tile;
import net.runelite.api.Varbits;
import static net.runelite.api.Perspective.SCENE_SIZE; import static net.runelite.api.Perspective.SCENE_SIZE;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.VarbitChanged;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.chat.ChatColor; import net.runelite.client.chat.ChatColor;
import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageBuilder;
@@ -68,9 +76,12 @@ public class RaidsPlugin extends Plugin
{ {
private static final int LOBBY_PLANE = 3; private static final int LOBBY_PLANE = 3;
private static final String RAID_START_MESSAGE = "The raid has begun!"; private static final String RAID_START_MESSAGE = "The raid has begun!";
private static final String LEVEL_COMPLETE_MESSAGE = "level complete!";
private static final String RAID_COMPLETE_MESSAGE = "Congratulations - your raid is complete!"; private static final String RAID_COMPLETE_MESSAGE = "Congratulations - your raid is complete!";
private static final int TOTAL_POINTS = 0, PERSONAL_POINTS = 1, TEXT_CHILD = 4;
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.##"); private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.##");
private static final DecimalFormat POINTS_FORMAT = new DecimalFormat("#,###");
private static final String SPLIT_REGEX = "\\s*,\\s*";
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)\\]");
private BufferedImage raidsIcon; private BufferedImage raidsIcon;
private RaidsTimer timer; private RaidsTimer timer;
@@ -98,7 +109,16 @@ public class RaidsPlugin extends Plugin
private Raid raid; private Raid raid;
@Getter @Getter
private ArrayList<String> blacklist = new ArrayList<>(); private ArrayList<String> roomWhitelist = new ArrayList<>();
@Getter
private ArrayList<String> roomBlacklist = new ArrayList<>();
@Getter
private ArrayList<String> rotationWhitelist = new ArrayList<>();
@Getter
private ArrayList<String> layoutWhitelist = new ArrayList<>();
@Provides @Provides
RaidsConfig provideConfig(ConfigManager configManager) RaidsConfig provideConfig(ConfigManager configManager)
@@ -132,7 +152,7 @@ public class RaidsPlugin extends Plugin
cacheColors(); cacheColors();
} }
updateBlacklist(); updateLists();
} }
@Override @Override
@@ -157,9 +177,24 @@ public class RaidsPlugin extends Plugin
updateInfoBoxState(); updateInfoBoxState();
} }
if (event.getKey().equals("whitelistedRooms"))
{
updateList(roomWhitelist, config.whitelistedRooms());
}
if (event.getKey().equals("blacklistedRooms")) if (event.getKey().equals("blacklistedRooms"))
{ {
updateBlacklist(); updateList(roomBlacklist, config.blacklistedRooms());
}
if (event.getKey().equals("whitelistedRotations"))
{
updateList(rotationWhitelist, config.whitelistedRotations());
}
if (event.getKey().equals("whitelistedLayouts"))
{
updateList(layoutWhitelist, config.whitelistedLayouts());
} }
} }
@@ -222,19 +257,23 @@ public class RaidsPlugin extends Plugin
infoBoxManager.addInfoBox(timer); infoBoxManager.addInfoBox(timer);
} }
if (timer != null && message.contains(LEVEL_COMPLETE_MESSAGE))
{
timer.timeFloor();
}
if (message.startsWith(RAID_COMPLETE_MESSAGE)) if (message.startsWith(RAID_COMPLETE_MESSAGE))
{ {
if (timer != null) if (timer != null)
{ {
timer.timeFloor();
timer.setStopped(true); timer.setStopped(true);
} }
if (config.pointsMessage()) if (config.pointsMessage())
{ {
Widget raidsWidget = client.getWidget(WidgetInfo.RAIDS_POINTS_INFOBOX).getChild(TEXT_CHILD); int totalPoints = client.getSetting(Varbits.TOTAL_POINTS);
String[] raidPoints = raidsWidget.getText().split("<br>"); int personalPoints = client.getSetting(Varbits.PERSONAL_POINTS);
int totalPoints = Integer.parseInt(raidPoints[TOTAL_POINTS].replace(",", ""));
int personalPoints = Integer.parseInt(raidPoints[PERSONAL_POINTS].replace(",", ""));
double percentage = personalPoints / (totalPoints / 100.0); double percentage = personalPoints / (totalPoints / 100.0);
@@ -242,11 +281,11 @@ public class RaidsPlugin extends Plugin
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append("Total points: ") .append("Total points: ")
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
.append(raidPoints[TOTAL_POINTS]) .append(POINTS_FORMAT.format(totalPoints))
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append(", Personal points: ") .append(", Personal points: ")
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
.append(raidPoints[PERSONAL_POINTS]) .append(POINTS_FORMAT.format(personalPoints))
.append(ChatColorType.NORMAL) .append(ChatColorType.NORMAL)
.append(" (") .append(" (")
.append(ChatColorType.HIGHLIGHT) .append(ChatColorType.HIGHLIGHT)
@@ -284,10 +323,35 @@ public class RaidsPlugin extends Plugin
} }
} }
private void updateBlacklist() private void updateLists()
{ {
blacklist.clear(); updateList(roomWhitelist, config.blacklistedRooms());
blacklist.addAll(Arrays.asList(config.blacklistedRooms().toLowerCase().split("\\s*,\\s*"))); updateList(roomBlacklist, config.blacklistedRooms());
updateList(rotationWhitelist, config.whitelistedRotations());
updateList(layoutWhitelist, config.whitelistedLayouts());
}
private void updateList(ArrayList<String> list, String input)
{
list.clear();
if (list == rotationWhitelist)
{
Matcher m = ROTATION_REGEX.matcher(input);
while (m.find())
{
String rotation = m.group(1);
if (!list.contains(rotation))
{
list.add(rotation);
}
}
}
else
{
list.addAll(Arrays.asList(input.toLowerCase().split(SPLIT_REGEX)));
}
} }
private void cacheColors() private void cacheColors()
@@ -299,6 +363,43 @@ public class RaidsPlugin extends Plugin
.refreshAll(); .refreshAll();
} }
public int getRotationMatches()
{
String rotation = raid.getRotationString().toLowerCase();
String[] bosses = rotation.split(SPLIT_REGEX);
if (rotationWhitelist.contains(rotation))
{
return bosses.length;
}
for (String whitelisted : rotationWhitelist)
{
int matches = 0;
String[] whitelistedBosses = whitelisted.split(SPLIT_REGEX);
for (int i = 0; i < whitelistedBosses.length; i++)
{
if (i < bosses.length && whitelistedBosses[i].equals(bosses[i]))
{
matches++;
}
else
{
matches = 0;
break;
}
}
if (matches >= 2)
{
return matches;
}
}
return 0;
}
private Point findLobbyBase() private Point findLobbyBase()
{ {
Tile[][] tiles = client.getRegion().getTiles()[LOBBY_PLANE]; Tile[][] tiles = client.getRegion().getTiles()[LOBBY_PLANE];

View File

@@ -36,7 +36,11 @@ import net.runelite.client.ui.overlay.infobox.InfoBox;
public class RaidsTimer extends InfoBox public class RaidsTimer extends InfoBox
{ {
private final Instant startTime; private final Instant startTime;
private Instant floorTime;
private LocalTime time; private LocalTime time;
private LocalTime firstFloorTime;
private LocalTime secondFloorTime;
private LocalTime olmTime;
@Setter @Setter
private boolean stopped; private boolean stopped;
@@ -45,9 +49,30 @@ public class RaidsTimer extends InfoBox
{ {
super(image); super(image);
this.startTime = startTime; this.startTime = startTime;
floorTime = startTime;
stopped = false; stopped = false;
} }
public void timeFloor()
{
Duration elapsed = Duration.between(floorTime, Instant.now());
if (firstFloorTime == null)
{
firstFloorTime = LocalTime.ofSecondOfDay(elapsed.getSeconds());
}
else if (secondFloorTime == null)
{
secondFloorTime = LocalTime.ofSecondOfDay(elapsed.getSeconds());
}
else if (olmTime == null)
{
olmTime = LocalTime.ofSecondOfDay(elapsed.getSeconds());
}
floorTime = Instant.now();
}
@Override @Override
public String getText() public String getText()
{ {
@@ -84,6 +109,28 @@ public class RaidsTimer extends InfoBox
@Override @Override
public String getTooltip() public String getTooltip()
{ {
return "Elapsed raid time: " + time.format(DateTimeFormatter.ofPattern("HH:mm:ss")); StringBuilder builder = new StringBuilder();
builder.append("Elapsed raid time: ");
builder.append(time.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
if (firstFloorTime != null)
{
builder.append("</br>First floor: ");
builder.append(firstFloorTime.format(DateTimeFormatter.ofPattern("mm:ss")));
}
if (secondFloorTime != null)
{
builder.append("</br>Second floor: ");
builder.append(secondFloorTime.format(DateTimeFormatter.ofPattern("mm:ss")));
}
if (olmTime != null)
{
builder.append("</br>Olm: ");
builder.append(olmTime.format(DateTimeFormatter.ofPattern("mm:ss")));
}
return builder.toString();
} }
} }