raids plugin: add option to show loot value
Co-authored-by: melkypie <melkypie@users.noreply.github.com>
This commit is contained in:
@@ -162,4 +162,15 @@ public interface RaidsConfig extends Config
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 12,
|
||||||
|
keyName = "showLootValue",
|
||||||
|
name = "Show Loot Value",
|
||||||
|
description = "Shows the value of your loot at the end of a raid"
|
||||||
|
)
|
||||||
|
default boolean showLootValue()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import net.runelite.api.ChatMessageType;
|
|||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.InstanceTemplates;
|
import net.runelite.api.InstanceTemplates;
|
||||||
|
import net.runelite.api.InventoryID;
|
||||||
|
import net.runelite.api.ItemContainer;
|
||||||
import net.runelite.api.MenuAction;
|
import net.runelite.api.MenuAction;
|
||||||
import net.runelite.api.MessageNode;
|
import net.runelite.api.MessageNode;
|
||||||
import net.runelite.api.NullObjectID;
|
import net.runelite.api.NullObjectID;
|
||||||
@@ -58,6 +60,8 @@ import net.runelite.api.VarPlayer;
|
|||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
import net.runelite.api.events.ChatMessage;
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.VarbitChanged;
|
import net.runelite.api.events.VarbitChanged;
|
||||||
|
import net.runelite.api.events.WidgetLoaded;
|
||||||
|
import net.runelite.api.widgets.WidgetID;
|
||||||
import net.runelite.client.callback.ClientThread;
|
import net.runelite.client.callback.ClientThread;
|
||||||
import net.runelite.client.chat.ChatColorType;
|
import net.runelite.client.chat.ChatColorType;
|
||||||
import net.runelite.client.chat.ChatCommandManager;
|
import net.runelite.client.chat.ChatCommandManager;
|
||||||
@@ -69,6 +73,7 @@ import net.runelite.client.eventbus.Subscribe;
|
|||||||
import net.runelite.client.events.ChatInput;
|
import net.runelite.client.events.ChatInput;
|
||||||
import net.runelite.client.events.ConfigChanged;
|
import net.runelite.client.events.ConfigChanged;
|
||||||
import net.runelite.client.events.OverlayMenuClicked;
|
import net.runelite.client.events.OverlayMenuClicked;
|
||||||
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.game.SpriteManager;
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
@@ -76,6 +81,7 @@ import net.runelite.client.plugins.raids.solver.Layout;
|
|||||||
import net.runelite.client.plugins.raids.solver.LayoutSolver;
|
import net.runelite.client.plugins.raids.solver.LayoutSolver;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
|
import net.runelite.client.util.QuantityFormatter;
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
import static net.runelite.client.util.Text.sanitize;
|
import static net.runelite.client.util.Text.sanitize;
|
||||||
import net.runelite.client.ws.PartyMember;
|
import net.runelite.client.ws.PartyMember;
|
||||||
@@ -144,6 +150,9 @@ public class RaidsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ScheduledExecutorService scheduledExecutorService;
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ItemManager itemManager;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Set<String> roomWhitelist = new HashSet<String>();
|
private final Set<String> roomWhitelist = new HashSet<String>();
|
||||||
|
|
||||||
@@ -163,6 +172,8 @@ public class RaidsPlugin extends Plugin
|
|||||||
@Getter
|
@Getter
|
||||||
private boolean inRaidChambers;
|
private boolean inRaidChambers;
|
||||||
|
|
||||||
|
private boolean chestOpened;
|
||||||
|
|
||||||
private RaidsTimer timer;
|
private RaidsTimer timer;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -195,6 +206,7 @@ public class RaidsPlugin extends Plugin
|
|||||||
inRaidChambers = false;
|
inRaidChambers = false;
|
||||||
raid = null;
|
raid = null;
|
||||||
timer = null;
|
timer = null;
|
||||||
|
chestOpened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -215,6 +227,44 @@ public class RaidsPlugin extends Plugin
|
|||||||
clientThread.invokeLater(() -> checkRaidPresence(true));
|
clientThread.invokeLater(() -> checkRaidPresence(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onWidgetLoaded(WidgetLoaded event)
|
||||||
|
{
|
||||||
|
if (event.getGroupId() != WidgetID.CHAMBERS_OF_XERIC_REWARD_GROUP_ID ||
|
||||||
|
!config.showLootValue() ||
|
||||||
|
chestOpened)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chestOpened = true;
|
||||||
|
|
||||||
|
ItemContainer rewardItemContainer = client.getItemContainer(InventoryID.CHAMBERS_OF_XERIC_CHEST);
|
||||||
|
if (rewardItemContainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long totalValue = Arrays.stream(rewardItemContainer.getItems())
|
||||||
|
.filter(item -> item.getId() > -1)
|
||||||
|
.mapToLong(item -> (long) itemManager.getItemPrice(item.getId()) * item.getQuantity())
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
String chatMessage = new ChatMessageBuilder()
|
||||||
|
.append(ChatColorType.NORMAL)
|
||||||
|
.append("Your loot is worth around ")
|
||||||
|
.append(ChatColorType.HIGHLIGHT)
|
||||||
|
.append(QuantityFormatter.formatNumber(totalValue))
|
||||||
|
.append(ChatColorType.NORMAL)
|
||||||
|
.append(" coins.")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
chatMessageManager.queue(QueuedMessage.builder()
|
||||||
|
.type(ChatMessageType.FRIENDSCHATNOTIFICATION)
|
||||||
|
.runeLiteFormattedMessage(chatMessage)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onVarbitChanged(VarbitChanged event)
|
public void onVarbitChanged(VarbitChanged event)
|
||||||
{
|
{
|
||||||
@@ -309,6 +359,7 @@ public class RaidsPlugin extends Plugin
|
|||||||
if (inRaidChambers)
|
if (inRaidChambers)
|
||||||
{
|
{
|
||||||
raid = buildRaid();
|
raid = buildRaid();
|
||||||
|
chestOpened = false;
|
||||||
|
|
||||||
if (raid == null)
|
if (raid == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,15 +30,27 @@ import com.google.inject.testing.fieldbinder.Bind;
|
|||||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.InventoryID;
|
||||||
|
import net.runelite.api.Item;
|
||||||
|
import net.runelite.api.ItemContainer;
|
||||||
|
import net.runelite.api.ItemID;
|
||||||
|
import net.runelite.api.events.WidgetLoaded;
|
||||||
|
import net.runelite.api.widgets.WidgetID;
|
||||||
|
import net.runelite.client.chat.ChatMessageManager;
|
||||||
|
import net.runelite.client.chat.QueuedMessage;
|
||||||
import net.runelite.client.config.ChatColorConfig;
|
import net.runelite.client.config.ChatColorConfig;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
|
import net.runelite.client.game.ItemManager;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
@@ -61,6 +73,14 @@ public class RaidsPluginTest
|
|||||||
@Bind
|
@Bind
|
||||||
RuneLiteConfig runeliteConfig;
|
RuneLiteConfig runeliteConfig;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
@Bind
|
||||||
|
ItemManager itemManager;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
@Bind
|
||||||
|
ChatMessageManager chatMessageManager;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@Bind
|
@Bind
|
||||||
RaidsConfig raidsConfig;
|
RaidsConfig raidsConfig;
|
||||||
@@ -119,4 +139,30 @@ public class RaidsPluginTest
|
|||||||
|
|
||||||
assertFalse(raidsPlugin.getRotationMatches());
|
assertFalse(raidsPlugin.getRotationMatches());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLootValue()
|
||||||
|
{
|
||||||
|
when(raidsConfig.showLootValue()).thenReturn(true);
|
||||||
|
|
||||||
|
ItemContainer itemContainer = mock(ItemContainer.class);
|
||||||
|
when(itemContainer.getItems()).thenReturn(new Item[]{
|
||||||
|
new Item(ItemID.TWISTED_BOW, 1),
|
||||||
|
new Item(ItemID.PURE_ESSENCE, 42)
|
||||||
|
});
|
||||||
|
when(client.getItemContainer(InventoryID.CHAMBERS_OF_XERIC_CHEST)).thenReturn(itemContainer);
|
||||||
|
|
||||||
|
when(itemManager.getItemPrice(ItemID.TWISTED_BOW)).thenReturn(1_100_000_000);
|
||||||
|
when(itemManager.getItemPrice(ItemID.PURE_ESSENCE)).thenReturn(6);
|
||||||
|
|
||||||
|
WidgetLoaded widgetLoaded = new WidgetLoaded();
|
||||||
|
widgetLoaded.setGroupId(WidgetID.CHAMBERS_OF_XERIC_REWARD_GROUP_ID);
|
||||||
|
raidsPlugin.onWidgetLoaded(widgetLoaded);
|
||||||
|
|
||||||
|
ArgumentCaptor<QueuedMessage> captor = ArgumentCaptor.forClass(QueuedMessage.class);
|
||||||
|
verify(chatMessageManager).queue(captor.capture());
|
||||||
|
|
||||||
|
QueuedMessage queuedMessage = captor.getValue();
|
||||||
|
assertEquals("<colNORMAL>Your loot is worth around <colHIGHLIGHT>1,100,000,252<colNORMAL> coins.", queuedMessage.getRuneLiteFormattedMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user