Add barbarian assault game duration timer (#4590)

Shows the wave duration and game duration: https://imgur.com/a/HGVeZ2z

Closes #1152
This commit is contained in:
Jacob McElroy
2018-09-21 14:50:46 +08:00
committed by Tomas Slusny
parent 76c9e47c91
commit ddd4188a02
6 changed files with 155 additions and 109 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, Cameron <https://github.com/noremac201>
* Copyright (c) 2018, Jacob M <https://github.com/jacoblairm>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,4 +41,14 @@ public interface BarbarianAssaultConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "waveTimes",
name = "Show wave and game duration",
description = "Displays wave and game duration"
)
default boolean waveTimes()
{
return true;
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, Cameron <https://github.com/noremac201>
* Copyright (c) 2018, Jacob M <https://github.com/jacoblairm>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,18 +29,23 @@ import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.Font;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.ItemID;
import net.runelite.api.MenuEntry;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.kit.KitType;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@@ -49,22 +55,27 @@ import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Barbarian Assault",
description = "Show a timer to the next call change",
tags = {"minigame", "overlay"}
description = "Show a timer to the next call change and game/wave duration in chat.",
tags = {"minigame", "overlay", "timer"}
)
public class BarbarianAssaultPlugin extends Plugin
{
private final List<MenuEntry> entries = new ArrayList<>();
private static final int BA_ALL_KILLED_INDEX = 4;
private static final int BA_WAVE_NUM_INDEX = 2;
private static final String START_WAVE = "1";
private static final String ENDGAME_REWARD_NEEDLE_TEXT = "<br>5";
private Font font;
private Image clockImage;
private int inGameBit = 0;
private String currentWave = START_WAVE;
private GameTimer gameTime;
@Inject
private Client client;
@Inject
private ChatMessageManager chatMessageManager;
@Inject
private OverlayManager overlayManager;
@@ -94,30 +105,67 @@ public class BarbarianAssaultPlugin extends Plugin
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
gameTime = null;
currentWave = START_WAVE;
inGameBit = 0;
}
@Subscribe
public void onWidgetLoaded(WidgetLoaded event)
{
if (event.getGroupId() == WidgetID.BA_REWARD_GROUP_ID)
{
Widget rewardWidget = client.getWidget(WidgetInfo.BA_REWARD_TEXT);
if (config.waveTimes() && rewardWidget != null && rewardWidget.getText().contains(ENDGAME_REWARD_NEEDLE_TEXT) && gameTime != null)
{
announceTime("Game finished, duration: ", gameTime.getTime(false));
}
}
}
@Subscribe
public void onChatMessage(ChatMessage event)
{
if (event.getType() == ChatMessageType.SERVER
&& event.getMessage().startsWith("---- Wave:"))
{
String[] message = event.getMessage().split(" ");
currentWave = message[BA_WAVE_NUM_INDEX];
if (currentWave.equals(START_WAVE))
{
gameTime = new GameTimer();
}
else if (gameTime != null)
{
gameTime.setWaveStartTime();
}
}
}
@Subscribe
public void onGameTick(GameTick event)
{
if (client.getVar(Varbits.IN_GAME_BA) == 1 &&
overlay.getCurrentRound() == null &&
client.getLocalPlayer() != null)
if (client.getVar(Varbits.IN_GAME_BA) == 0 || client.getLocalPlayer() == null || overlay.getCurrentRound() != null)
{
switch (client.getLocalPlayer().getPlayerComposition().getEquipmentId(KitType.CAPE))
{
case ItemID.ATTACKER_ICON:
overlay.setCurrentRound(new Round(Role.ATTACKER));
break;
case ItemID.COLLECTOR_ICON:
overlay.setCurrentRound(new Round(Role.COLLECTOR));
break;
case ItemID.DEFENDER_ICON:
overlay.setCurrentRound(new Round(Role.DEFENDER));
break;
case ItemID.HEALER_ICON:
overlay.setCurrentRound(new Round(Role.HEALER));
break;
}
return;
}
switch (client.getLocalPlayer().getPlayerComposition().getEquipmentId(KitType.CAPE))
{
case ItemID.ATTACKER_ICON:
overlay.setCurrentRound(new Round(Role.ATTACKER));
break;
case ItemID.COLLECTOR_ICON:
overlay.setCurrentRound(new Round(Role.COLLECTOR));
break;
case ItemID.DEFENDER_ICON:
overlay.setCurrentRound(new Round(Role.DEFENDER));
break;
case ItemID.HEALER_ICON:
overlay.setCurrentRound(new Round(Role.HEALER));
break;
}
}
@@ -126,42 +174,35 @@ public class BarbarianAssaultPlugin extends Plugin
{
int inGame = client.getVar(Varbits.IN_GAME_BA);
if (inGameBit != inGame && inGameBit == 1)
if (inGameBit != inGame)
{
// end of game
overlay.setCurrentRound(null);
if (inGameBit == 1)
{
overlay.setCurrentRound(null);
if (config.waveTimes() && gameTime != null)
{
announceTime("Wave " + currentWave + " duration: ", gameTime.getTime(true));
}
}
}
inGameBit = inGame;
}
@Subscribe
public void onMessageEvent(ChatMessage event)
private void announceTime(String preText, String time)
{
if (event.getType() == ChatMessageType.SERVER
&& event.getMessage().startsWith("All of the Penance"))
{
String[] message = event.getMessage().split(" ");
Round round = overlay.getCurrentRound();
if (round != null)
{
switch (message[BA_ALL_KILLED_INDEX])
{
case "Healers":
round.setHealersKilled(true);
break;
case "Runners":
round.setRunnersKilled(true);
break;
case "Fighters":
round.setFightersKilled(true);
break;
case "Rangers":
round.setRangersKilled(true);
break;
}
}
}
final String chatMessage = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append(preText)
.append(ChatColorType.HIGHLIGHT)
.append(time)
.build();
chatMessageManager.queue(QueuedMessage.builder()
.type(ChatMessageType.GAME)
.runeLiteFormattedMessage(chatMessage)
.build());
}
public Font getFont()
@@ -173,4 +214,4 @@ public class BarbarianAssaultPlugin extends Plugin
{
return clockImage;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Cameron <https://github.com/noremac201>
* Copyright (c) 2018, Jacob M <https://github.com/jacoblairm>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,61 +24,51 @@
*/
package net.runelite.client.plugins.barbarianassault;
import java.util.HashMap;
import java.util.Map;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public enum Calls
class GameTimer
{
//Attacker Calls
RED_EGG("Red egg", "Tell-red"),
GREEN_EGG("Green egg", "Tell-green"),
BLUE_EGG("Blue egg", "Tell-blue"),
//Collector Calls
CONTROLLED("Controlled/Bullet/Wind", "Tell-controlled"),
ACCURATE("Accurate/Field/Water", "Tell-accurate"),
AGGRESSIVE("Aggressive/Blunt/Earth", "Tell-aggressive"),
DEFENSIVE("Defensive/Barbed/Fire", "Tell-defensive"),
//Healer Calls
TOFU("Tofu", "Tell-tofu"),
CRACKERS("Crackers", "Tell-crackers"),
WORMS("Worms", "Tell-worms"),
//Defender Calls
POIS_WORMS("Pois. Worms", "Tell-worms"),
POIS_TOFU("Pois. Tofu", "Tell-tofu"),
POIS_MEAT("Pois. Meat", "Tell-meat");
final private Instant startTime = Instant.now();
private Instant prevWave = startTime;
private final String call;
private final String option;
private static final Map<String, String> CALL_MENU = new HashMap<>();
static
String getTime(boolean waveTime)
{
for (Calls s : values())
final Instant now = Instant.now();
final Duration elapsed;
if (waveTime)
{
CALL_MENU.put(s.getCall(), s.getOption());
elapsed = Duration.between(prevWave, now);
}
else
{
elapsed = Duration.between(startTime, now).minusMillis(600);
}
return formatTime(LocalTime.ofSecondOfDay(elapsed.getSeconds()));
}
void setWaveStartTime()
{
prevWave = Instant.now();
}
private static String formatTime(LocalTime time)
{
if (time.getHour() > 0)
{
return time.format(DateTimeFormatter.ofPattern("HH:mm"));
}
else if (time.getMinute() > 9)
{
return time.format(DateTimeFormatter.ofPattern("mm:ss"));
}
else
{
return time.format(DateTimeFormatter.ofPattern("m:ss"));
}
}
Calls(String call, String option)
{
this.call = call;
this.option = option;
}
public String getCall()
{
return call;
}
public String getOption()
{
return option;
}
public static String getOption(String call)
{
return CALL_MENU.get(call);
}
}
}

View File

@@ -56,4 +56,4 @@ public enum Role
{
return name();
}
}
}