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:
melkypie
2020-06-28 17:24:06 +03:00
committed by Adam
parent eb251a7e85
commit 1ee41dba5a
6 changed files with 76 additions and 109 deletions

View File

@@ -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());
}
}

View File

@@ -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());
}
}