loot tracker: move cox loot value message from raids to loot tracker
Reverts commit bf0ff69e07.
Fixes the bug of double loot messages and adds the ability to use HA for loot value messages.
This commit is contained in:
@@ -138,4 +138,14 @@ public interface LootTrackerConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showRaidsLootValue",
|
||||
name = "Show chat message for raids loot",
|
||||
description = "Adds a chat message that displays the value of your loot at the end of the raid."
|
||||
)
|
||||
default boolean showRaidsLootValue()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,6 +547,30 @@ public class LootTrackerPlugin extends Plugin
|
||||
.map(item -> new ItemStack(item.getId(), item.getQuantity(), client.getLocalPlayer().getLocalLocation()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (config.showRaidsLootValue() && event.equals("Chambers of Xeric"))
|
||||
{
|
||||
long totalValue = items.stream()
|
||||
.filter(item -> item.getId() > -1)
|
||||
.mapToLong(item -> (long) (config.priceType() == LootTrackerPriceType.GRAND_EXCHANGE ?
|
||||
itemManager.getItemPrice(item.getId()) * item.getQuantity() :
|
||||
itemManager.getItemComposition(item.getId()).getHaPrice() * 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());
|
||||
}
|
||||
|
||||
if (items.isEmpty())
|
||||
{
|
||||
log.debug("No items to find for Event: {} | Container: {}", event, container);
|
||||
|
||||
@@ -178,17 +178,6 @@ public interface RaidsConfig extends Config
|
||||
|
||||
@ConfigItem(
|
||||
position = 13,
|
||||
keyName = "showLootValue",
|
||||
name = "Show Loot Value",
|
||||
description = "Shows the value of your loot at the end of a raid"
|
||||
)
|
||||
default boolean showLootValue()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 14,
|
||||
keyName = "screenshotHotkey",
|
||||
name = "Scouter screenshot hotkey",
|
||||
description = "Hotkey used to screenshot the scouting overlay"
|
||||
@@ -199,7 +188,7 @@ public interface RaidsConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 15,
|
||||
position = 14,
|
||||
keyName = "uploadScreenshot",
|
||||
name = "Upload scouting screenshot",
|
||||
description = "Uploads the scouting screenshot to Imgur or the clipboard"
|
||||
|
||||
@@ -51,8 +51,6 @@ import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.InstanceTemplates;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.ItemContainer;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.NullObjectID;
|
||||
@@ -67,8 +65,6 @@ import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
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.chat.ChatColorType;
|
||||
import net.runelite.client.chat.ChatCommandManager;
|
||||
@@ -84,7 +80,6 @@ import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.events.OverlayMenuClicked;
|
||||
import net.runelite.client.plugins.raids.events.RaidReset;
|
||||
import net.runelite.client.plugins.raids.events.RaidScouted;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -95,7 +90,6 @@ import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
import net.runelite.client.util.HotkeyListener;
|
||||
import net.runelite.client.util.ImageCapture;
|
||||
import net.runelite.client.util.QuantityFormatter;
|
||||
import net.runelite.client.util.Text;
|
||||
import static net.runelite.client.util.Text.sanitize;
|
||||
import net.runelite.client.ws.PartyMember;
|
||||
@@ -173,9 +167,6 @@ public class RaidsPlugin extends Plugin
|
||||
@Inject
|
||||
private ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
@Inject
|
||||
private ItemManager itemManager;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@@ -213,8 +204,6 @@ public class RaidsPlugin extends Plugin
|
||||
*/
|
||||
@Getter
|
||||
private int raidPartyID;
|
||||
|
||||
private boolean chestOpened;
|
||||
private RaidsTimer timer;
|
||||
boolean checkInRaid;
|
||||
private boolean loggedIn;
|
||||
@@ -269,44 +258,6 @@ public class RaidsPlugin extends Plugin
|
||||
updateLists();
|
||||
}
|
||||
|
||||
@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
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
@@ -482,7 +433,6 @@ public class RaidsPlugin extends Plugin
|
||||
updateInfoBoxState();
|
||||
boolean firstSolve = (raid == null);
|
||||
raid = buildRaid(raid);
|
||||
chestOpened = false;
|
||||
|
||||
if (raid == null)
|
||||
{
|
||||
@@ -1014,7 +964,6 @@ public class RaidsPlugin extends Plugin
|
||||
private void reset()
|
||||
{
|
||||
raid = null;
|
||||
chestOpened = false;
|
||||
updateInfoBoxState();
|
||||
eventBus.post(new RaidReset());
|
||||
}
|
||||
|
||||
@@ -37,15 +37,21 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemComposition;
|
||||
import net.runelite.api.ItemContainer;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.api.IterableHashTable;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import net.runelite.client.account.SessionManager;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.chat.QueuedMessage;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.ItemStack;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
@@ -57,9 +63,13 @@ import static org.junit.Assert.assertNull;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -202,4 +212,35 @@ public class LootTrackerPluginTest
|
||||
assertNull(lootTrackerPlugin.eventType);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoXRaidsLootValue()
|
||||
{
|
||||
when(lootTrackerConfig.showRaidsLootValue()).thenReturn(true);
|
||||
when(lootTrackerConfig.priceType()).thenReturn(LootTrackerPriceType.GRAND_EXCHANGE);
|
||||
|
||||
LootTrackerPlugin spyPlugin = Mockito.spy(lootTrackerPlugin);
|
||||
// Make sure we don't execute addLoot, so we don't have to mock LootTrackerPanel and everything else also
|
||||
doNothing().when(spyPlugin).addLoot(anyString(), anyInt(), any(LootRecordType.class), anyCollection());
|
||||
|
||||
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);
|
||||
spyPlugin.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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,32 +30,20 @@ import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
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.Notifier;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.chat.QueuedMessage;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.ImageCapture;
|
||||
import net.runelite.client.ws.PartyService;
|
||||
import net.runelite.http.api.chat.ChatClient;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@@ -78,14 +66,6 @@ public class RaidsPluginTest
|
||||
@Bind
|
||||
RuneLiteConfig runeliteConfig;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ItemManager itemManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ChatMessageManager chatMessageManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ImageCapture imageCapture;
|
||||
@@ -164,30 +144,4 @@ public class RaidsPluginTest
|
||||
|
||||
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