Merge pull request #288 from runelite-extended/raids

Update to Raids, fixes timer issue aswell.
This commit is contained in:
Lucwousin
2019-05-18 19:04:43 +02:00
committed by GitHub
4 changed files with 253 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Kamiel * Copyright (c) 2018, Kamiel
* Copyright (c) 2019, ganom <https://github.com/Ganom>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -35,8 +36,8 @@ public interface RaidsConfig extends Config
@ConfigItem( @ConfigItem(
position = 0, position = 0,
keyName = "raidsTimer", keyName = "raidsTimer",
name = "Level time tooltip", name = "Display elapsed raid time",
description = "Displays your level times as a tooltip on the points overlay" description = "Display elapsed raid time"
) )
default boolean raidsTimer() default boolean raidsTimer()
{ {
@@ -168,8 +169,7 @@ public interface RaidsConfig extends Config
position = 12, position = 12,
keyName = "enhanceScouterTitle", keyName = "enhanceScouterTitle",
name = "Enhance scouter title", name = "Enhance scouter title",
description = "Adds #combat and good puzzles to scouter title", description = "Adds #combat and good puzzles to scouter title"
hidden = true
) )
default boolean enhanceScouterTitle() default boolean enhanceScouterTitle()
{ {
@@ -288,6 +288,28 @@ public interface RaidsConfig extends Config
@ConfigItem( @ConfigItem(
position = 25, position = 25,
keyName = "hideVanguards",
name = "Hide Vanguard raids",
description = "Completely hides raids with Vanguards"
)
default boolean hideVanguards()
{
return false;
}
@ConfigItem(
position = 26,
keyName = "hideUnknownCombat",
name = "Hide Unknown combat raids",
description = "Completely hides raids with Unknown combat"
)
default boolean hideUnknownCombat()
{
return false;
}
@ConfigItem(
position = 27,
keyName = "layoutMessage", keyName = "layoutMessage",
name = "Send raid layout message when entering raid", name = "Send raid layout message when entering raid",
description = "Sends game message with raid layout on entering new raid" description = "Sends game message with raid layout on entering new raid"
@@ -298,7 +320,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 26, position = 28,
keyName = "displayFloorBreak", keyName = "displayFloorBreak",
name = "Layout floor break", name = "Layout floor break",
description = "Displays floor break in layout" description = "Displays floor break in layout"

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Kamiel * Copyright (c) 2018, Kamiel
* Copyright (c) 2019, ganom <https://github.com/Ganom>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -151,7 +152,10 @@ public class RaidsOverlay extends Overlay
boolean iceDemon = false; boolean iceDemon = false;
boolean tightrope = false; boolean tightrope = false;
boolean thieving = false; boolean thieving = false;
boolean vanguards = false;
boolean unknownCombat = false;
String puzzles = ""; String puzzles = "";
String roomName = "";
if (config.enhanceScouterTitle() || config.scavsBeforeIce() || sharable) if (config.enhanceScouterTitle() || config.scavsBeforeIce() || sharable)
{ {
for (Room layoutRoom : plugin.getRaid().getLayout().getRooms()) for (Room layoutRoom : plugin.getRaid().getLayout().getRooms())
@@ -168,9 +172,19 @@ public class RaidsOverlay extends Overlay
{ {
case COMBAT: case COMBAT:
combatCount++; combatCount++;
roomName = room.getBoss().getName();
switch (RaidRoom.Boss.fromString(roomName))
{
case VANGUARDS:
vanguards = true;
break;
case UNKNOWN:
unknownCombat = true;
break;
}
break; break;
case PUZZLE: case PUZZLE:
String roomName = room.getPuzzle().getName(); roomName = room.getPuzzle().getName();
switch (RaidRoom.Puzzle.fromString(roomName)) switch (RaidRoom.Puzzle.fromString(roomName))
{ {
case CRABS: case CRABS:
@@ -198,10 +212,11 @@ public class RaidsOverlay extends Overlay
{ {
puzzles = crabs ? "cr" : iceDemon ? "ri" : thieving ? "tr" : "?r"; puzzles = crabs ? "cr" : iceDemon ? "ri" : thieving ? "tr" : "?r";
} }
else if (config.hideRopeless())
if ((config.hideVanguards() && vanguards) || (config.hideRopeless() && !tightrope) || (config.hideUnknownCombat() && unknownCombat))
{ {
panelComponent.getChildren().add(TitleComponent.builder() panelComponent.getChildren().add(TitleComponent.builder()
.text("No Tightrope!") .text("Bad Raid!")
.color(Color.RED) .color(Color.RED)
.build()); .build());

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Kamiel * Copyright (c) 2018, Kamiel
* Copyright (c) 2019, ganom <https://github.com/Ganom>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -28,6 +29,7 @@ import com.google.inject.Binder;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@@ -48,6 +50,7 @@ import net.runelite.api.NullObjectID;
import static net.runelite.api.Perspective.SCENE_SIZE; import static net.runelite.api.Perspective.SCENE_SIZE;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.SpriteID; import net.runelite.api.SpriteID;
import static net.runelite.api.SpriteID.TAB_QUESTS_BROWN_RAIDING_PARTY;
import net.runelite.api.Tile; import net.runelite.api.Tile;
import net.runelite.api.VarPlayer; import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
@@ -96,6 +99,9 @@ import org.apache.commons.lang3.StringUtils;
public class RaidsPlugin extends Plugin 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 LEVEL_COMPLETE_MESSAGE = "level complete!";
private static final String RAID_COMPLETE_MESSAGE = "Congratulations - your raid is complete!";
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.##"); private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.##");
static final DecimalFormat POINTS_FORMAT = new DecimalFormat("#,###"); static final DecimalFormat POINTS_FORMAT = new DecimalFormat("#,###");
private static final String SPLIT_REGEX = "\\s*,\\s*"; private static final String SPLIT_REGEX = "\\s*,\\s*";
@@ -181,6 +187,7 @@ public class RaidsPlugin extends Plugin
private String tooltip; private String tooltip;
public boolean canShow; public boolean canShow;
private NavigationButton navButton; private NavigationButton navButton;
private RaidsTimer timer;
@Provides @Provides
RaidsConfig provideConfig(ConfigManager configManager) RaidsConfig provideConfig(ConfigManager configManager)
@@ -220,9 +227,11 @@ public class RaidsPlugin extends Plugin
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(pointsOverlay); overlayManager.remove(pointsOverlay);
clientToolbar.removeNavigation(navButton); clientToolbar.removeNavigation(navButton);
infoBoxManager.removeInfoBox(timer);
inRaidChambers = false; inRaidChambers = false;
widgetOverlay = null; widgetOverlay = null;
raid = null; raid = null;
timer = null;
final Widget widget = client.getWidget(WidgetInfo.RAIDS_POINTS_INFOBOX); final Widget widget = client.getWidget(WidgetInfo.RAIDS_POINTS_INFOBOX);
if (widget != null) if (widget != null)
@@ -240,6 +249,12 @@ public class RaidsPlugin extends Plugin
return; return;
} }
if (event.getKey().equals("raidsTimer"))
{
updateInfoBoxState();
return;
}
updateLists(); updateLists();
clientThread.invokeLater(() -> checkRaidPresence(true)); clientThread.invokeLater(() -> checkRaidPresence(true));
} }
@@ -274,26 +289,26 @@ public class RaidsPlugin extends Plugin
String message = Text.removeTags(event.getMessage()); String message = Text.removeTags(event.getMessage());
Matcher matcher; Matcher matcher;
matcher = LEVEL_COMPLETE_REGEX.matcher(message); if (config.raidsTimer() && message.startsWith(RAID_START_MESSAGE))
if (matcher.find())
{ {
String floor = matcher.group(1); timer = new RaidsTimer(spriteManager.getSprite(TAB_QUESTS_BROWN_RAIDING_PARTY, 0), this, Instant.now());
int time = timeToSeconds(matcher.group(2)); infoBoxManager.addInfoBox(timer);
if (floor.equals("Upper")) }
if (timer != null && message.contains(LEVEL_COMPLETE_MESSAGE))
{
timer.timeFloor();
}
if (message.startsWith(RAID_COMPLETE_MESSAGE))
{
if (timer != null)
{ {
upperTime = time; timer.timeOlm();
} timer.setStopped(true);
else if (floor.equals("Middle"))
{
middleTime = time;
}
else if (floor.equals("Lower"))
{
lowerTime = time;
} }
updateTooltip(); updateTooltip();
} }
matcher = RAID_COMPLETE_REGEX.matcher(message); matcher = RAID_COMPLETE_REGEX.matcher(message);
if (matcher.find()) if (matcher.find())
{ {
@@ -410,6 +425,7 @@ public class RaidsPlugin extends Plugin
if (force || inRaidChambers != setting) if (force || inRaidChambers != setting)
{ {
inRaidChambers = setting; inRaidChambers = setting;
updateInfoBoxState();
if (inRaidChambers) if (inRaidChambers)
{ {
@@ -434,14 +450,9 @@ public class RaidsPlugin extends Plugin
overlay.setScoutOverlayShown(true); overlay.setScoutOverlayShown(true);
sendRaidLayoutMessage(); sendRaidLayoutMessage();
} }
else else if (!config.scoutOverlayAtBank())
{ {
if (!config.scoutOverlayAtBank()) overlay.setScoutOverlayShown(false);
{
overlay.setScoutOverlayShown(false);
}
reset();
} }
} }
@@ -474,6 +485,30 @@ public class RaidsPlugin extends Plugin
.build()); .build());
} }
private void updateInfoBoxState()
{
if (timer == null)
{
return;
}
if (inRaidChambers && config.raidsTimer())
{
if (!infoBoxManager.getInfoBoxes().contains(timer))
{
infoBoxManager.addInfoBox(timer);
}
}
else
{
infoBoxManager.removeInfoBox(timer);
}
if (!inRaidChambers)
{
timer = null;
}
}
private void updateLists() private void updateLists()
{ {
@@ -817,7 +852,7 @@ public class RaidsPlugin extends Plugin
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
if (seconds >= 3600) if (seconds >= 3600)
{ {
builder.append((int) Math.floor(seconds / 3600)).append(";"); builder.append((int) Math.floor(seconds / 3600) + ";");
} }
seconds %= 3600; seconds %= 3600;
if (builder.toString().equals("")) if (builder.toString().equals(""))

View File

@@ -0,0 +1,150 @@
/*
* Copyright (c) 2018, Kamiel
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.raids;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import lombok.Setter;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.infobox.InfoBox;
public class RaidsTimer extends InfoBox
{
private final Instant startTime;
private Instant floorTime;
private LocalTime time;
private LocalTime firstFloorTime;
private LocalTime secondFloorTime;
private LocalTime thirdFloorTime;
private LocalTime olmTime;
@Setter
private boolean stopped;
public RaidsTimer(BufferedImage image, Plugin plugin, Instant startTime)
{
super(image, plugin);
this.startTime = startTime;
floorTime = startTime;
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 (thirdFloorTime == null)
{
thirdFloorTime = LocalTime.ofSecondOfDay(elapsed.getSeconds());
}
floorTime = Instant.now();
}
public void timeOlm()
{
Duration elapsed = Duration.between(floorTime, Instant.now());
olmTime = LocalTime.ofSecondOfDay(elapsed.getSeconds());
}
@Override
public String getText()
{
if (startTime == null)
{
return "";
}
if (!stopped)
{
Duration elapsed = Duration.between(startTime, Instant.now());
time = LocalTime.ofSecondOfDay(elapsed.getSeconds());
}
if (time.getHour() > 0)
{
return time.format(DateTimeFormatter.ofPattern("HH:mm"));
}
return time.format(DateTimeFormatter.ofPattern("mm:ss"));
}
@Override
public Color getTextColor()
{
if (stopped)
{
return Color.GREEN;
}
return Color.WHITE;
}
@Override
public String getTooltip()
{
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 (thirdFloorTime != null)
{
builder.append("</br>Third floor: ");
builder.append(thirdFloorTime.format(DateTimeFormatter.ofPattern("mm:ss")));
}
if (olmTime != null)
{
builder.append("</br>Olm: ");
builder.append(olmTime.format(DateTimeFormatter.ofPattern("mm:ss")));
}
return builder.toString();
}
}