Skip to content

Commit

Permalink
loottracker: Show chat message after NPC and PVP kills
Browse files Browse the repository at this point in the history
This commit adds configs to display chat messages with the name and
value of NPC and/or PVP kills.
  • Loading branch information
Nightfirecat committed May 7, 2020
1 parent 24c7855 commit 9c77948
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,24 @@ default String getIgnoredEvents()
description = ""
)
void setIgnoredEvents(String key);

@ConfigItem(
keyName = "npcKillChatMessage",
name = "Show chat message for NPC kills",
description = "Adds a chat message with monster name and kill value when receiving loot from an NPC kill."
)
default boolean npcKillChatMessage()
{
return false;
}

@ConfigItem(
keyName = "pvpKillChatMessage",
name = "Show chat message for PVP kills",
description = "Adds a chat message with player name and kill value when receiving loot from a player kill."
)
default boolean pvpKillChatMessage()
{
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
import net.runelite.client.account.AccountSession;
import net.runelite.client.account.SessionManager;
import net.runelite.client.callback.ClientThread;
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.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
Expand All @@ -98,6 +102,7 @@
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.QuantityFormatter;
import net.runelite.client.util.Text;
import net.runelite.http.api.loottracker.GameItem;
import net.runelite.http.api.loottracker.LootAggregate;
Expand Down Expand Up @@ -189,6 +194,9 @@ public class LootTrackerPlugin extends Plugin
@Inject
private EventBus eventBus;

@Inject
private ChatMessageManager chatMessageManager;

private LootTrackerPanel panel;
private NavigationButton navButton;
@VisibleForTesting
Expand Down Expand Up @@ -394,6 +402,11 @@ public void onNpcLootReceived(final NpcLootReceived npcLootReceived)
final int combat = npc.getCombatLevel();

addLoot(name, combat, LootRecordType.NPC, items);

if (config.npcKillChatMessage())
{
lootReceivedChatMessage(items, "a " + name);
}
}

@Subscribe
Expand All @@ -411,6 +424,11 @@ public void onPlayerLootReceived(final PlayerLootReceived playerLootReceived)
final int combat = player.getCombatLevel();

addLoot(name, combat, LootRecordType.PLAYER, items);

if (config.pvpKillChatMessage())
{
lootReceivedChatMessage(items, name);
}
}

@Subscribe
Expand Down Expand Up @@ -840,4 +858,34 @@ private boolean isAtLMS()

return false;
}

private long getTotalPrice(Collection<ItemStack> items)
{
long totalPrice = 0;

for (final ItemStack itemStack : items)
{
totalPrice += (long) itemManager.getItemPrice(itemStack.getId()) * itemStack.getQuantity();
}

return totalPrice;
}

private void lootReceivedChatMessage(final Collection<ItemStack> items, final String name)
{
final String message = new ChatMessageBuilder()
.append(ChatColorType.HIGHLIGHT)
.append("You've killed ")
.append(name)
.append(" for ")
.append(QuantityFormatter.quantityToStackSize(getTotalPrice(items)))
.append(" loot.")
.build();

chatMessageManager.queue(
QueuedMessage.builder()
.type(ChatMessageType.CONSOLE)
.runeLiteFormattedMessage(message)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.account.SessionManager;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemStack;
import net.runelite.client.game.SpriteManager;
Expand Down Expand Up @@ -116,6 +117,10 @@ public class LootTrackerPluginTest
@Bind
private ItemManager itemManager;

@Mock
@Bind
private ChatMessageManager chatMessageManager;

@Before
public void setUp()
{
Expand Down

0 comments on commit 9c77948

Please sign in to comment.