Merge pull request #12430 from usa-usa-usa-usa/feature/update-tzhaar-timer

This commit is contained in:
Jordan
2020-09-20 21:53:35 -07:00
committed by GitHub
4 changed files with 51 additions and 14 deletions

View File

@@ -55,7 +55,7 @@ class ElapsedTimer extends InfoBox
} }
Duration time = Duration.between(startTime, lastTime == null ? Instant.now() : lastTime); Duration time = Duration.between(startTime, lastTime == null ? Instant.now() : lastTime);
final String formatString = time.toHours() > 0 ? "HH:mm" : "mm:ss"; final String formatString = "mm:ss";
return DurationFormatUtils.formatDuration(time.toMillis(), formatString, true); return DurationFormatUtils.formatDuration(time.toMillis(), formatString, true);
} }

View File

@@ -119,8 +119,8 @@ public class TimersPlugin extends Plugin
private static final int VENOM_VALUE_CUTOFF = -40; // Antivenom < -40 <= Antipoison < 0 private static final int VENOM_VALUE_CUTOFF = -40; // Antivenom < -40 <= Antipoison < 0
private static final int POISON_TICK_LENGTH = 30; private static final int POISON_TICK_LENGTH = 30;
private static final int FIGHT_CAVES_REGION_ID = 9551; static final int FIGHT_CAVES_REGION_ID = 9551;
private static final int INFERNO_REGION_ID = 9043; static final int INFERNO_REGION_ID = 9043;
private static final Pattern TZHAAR_WAVE_MESSAGE = Pattern.compile("Wave: (\\d+)"); private static final Pattern TZHAAR_WAVE_MESSAGE = Pattern.compile("Wave: (\\d+)");
private static final String TZHAAR_DEFEATED_MESSAGE = "You have been defeated!"; private static final String TZHAAR_DEFEATED_MESSAGE = "You have been defeated!";
private static final Pattern TZHAAR_COMPLETE_MESSAGE = Pattern.compile("Your (TzTok-Jad|TzKal-Zuk) kill count is:"); private static final Pattern TZHAAR_COMPLETE_MESSAGE = Pattern.compile("Your (TzTok-Jad|TzKal-Zuk) kill count is:");
@@ -679,7 +679,16 @@ public class TimersPlugin extends Plugin
int wave = Integer.parseInt(matcher.group(1)); int wave = Integer.parseInt(matcher.group(1));
if (wave == 1) if (wave == 1)
{ {
config.tzhaarStartTime(now); if (isInInferno())
{
// The first wave message of the inferno comes six seconds after the ingame timer starts counting
config.tzhaarStartTime(now.minus(Duration.ofSeconds(6)));
}
else
{
config.tzhaarStartTime(now);
}
createTzhaarTimer(); createTzhaarTimer();
} }
} }

View File

@@ -48,13 +48,13 @@ public class ElapsedTimerTest
assertEquals("05:00", timerText(fiveMinutesAgo, null)); assertEquals("05:00", timerText(fiveMinutesAgo, null));
assertEquals("55:00", timerText(oneHourAgo, fiveMinutesAgo)); assertEquals("55:00", timerText(oneHourAgo, fiveMinutesAgo));
assertEquals("59:55", timerText(oneHourAgo, fiveSecondsAgo)); assertEquals("59:55", timerText(oneHourAgo, fiveSecondsAgo));
assertEquals("01:00", timerText(oneHourAgo, now)); assertEquals("60:00", timerText(oneHourAgo, now));
assertEquals("01:00", timerText(oneHourAgo, null)); assertEquals("60:00", timerText(oneHourAgo, null));
assertEquals("04:00", timerText(fiveHoursAgo, oneHourAgo)); assertEquals("240:00", timerText(fiveHoursAgo, oneHourAgo));
assertEquals("04:55", timerText(fiveHoursAgo, fiveMinutesAgo)); assertEquals("295:00", timerText(fiveHoursAgo, fiveMinutesAgo));
assertEquals("04:59", timerText(fiveHoursAgo, fiveSecondsAgo)); assertEquals("299:55", timerText(fiveHoursAgo, fiveSecondsAgo));
assertEquals("05:00", timerText(fiveHoursAgo, now)); assertEquals("300:00", timerText(fiveHoursAgo, now));
assertEquals("05:00", timerText(fiveHoursAgo, null)); assertEquals("300:00", timerText(fiveHoursAgo, null));
} }
private static String timerText(final Instant startTime, final Instant lastTime) private static String timerText(final Instant startTime, final Instant lastTime)

View File

@@ -63,8 +63,6 @@ import org.mockito.stubbing.Answer;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class TimersPluginTest public class TimersPluginTest
{ {
private static final int FIGHT_CAVES_REGION_ID = 9551;
@Inject @Inject
private TimersPlugin timersPlugin; private TimersPlugin timersPlugin;
@@ -270,7 +268,7 @@ public class TimersPluginTest
public void testTzhaarTimer() public void testTzhaarTimer()
{ {
when(timersConfig.showTzhaarTimers()).thenReturn(true); when(timersConfig.showTzhaarTimers()).thenReturn(true);
when(client.getMapRegions()).thenReturn(new int[]{FIGHT_CAVES_REGION_ID}); when(client.getMapRegions()).thenReturn(new int[]{TimersPlugin.FIGHT_CAVES_REGION_ID});
class InstantRef class InstantRef
{ {
@@ -327,4 +325,34 @@ public class TimersPluginTest
verify(infoBoxManager, times(3)).removeInfoBox(captor.capture()); verify(infoBoxManager, times(3)).removeInfoBox(captor.capture());
verify(infoBoxManager, times(3)).addInfoBox(captor.capture()); verify(infoBoxManager, times(3)).addInfoBox(captor.capture());
} }
@Test
public void testInfernoTimerStartOffset()
{
when(timersConfig.showTzhaarTimers()).thenReturn(true);
when(client.getMapRegions()).thenReturn(new int[]{TimersPlugin.INFERNO_REGION_ID});
class InstantRef
{
Instant i;
}
InstantRef startTime = new InstantRef();
when(timersConfig.tzhaarStartTime()).then(a -> startTime.i);
doAnswer((Answer<Void>) invocationOnMock ->
{
Object argument = invocationOnMock.getArguments()[0];
startTime.i = (Instant) argument;
return null;
}).when(timersConfig).tzhaarStartTime(nullable(Instant.class));
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef1020>Wave: 1</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager, times(1)).addInfoBox(captor.capture());
assertTrue(captor.getValue() instanceof ElapsedTimer);
ElapsedTimer timer = (ElapsedTimer) captor.getValue();
assertEquals("00:06", timer.getText());
}
} }