Merge pull request #2239 from trimbe/barrows-chest-value

Add barrows chest value message
This commit is contained in:
Adam
2018-05-05 19:47:50 -04:00
committed by GitHub
6 changed files with 126 additions and 5 deletions

View File

@@ -29,7 +29,8 @@ public enum InventoryID
INVENTORY(93),
EQUIPMENT(94),
BANK(95),
PUZZLE_BOX(140);
PUZZLE_BOX(140),
BARROWS_REWARD(141);
private final int id;

View File

@@ -422,5 +422,6 @@ public class WidgetID
{
static final int BARROWS_BROTHERS = 8;
static final int BARROWS_POTENTIAL = 9;
static final int BARROWS_REWARD_INVENTORY = 3;
}
}

View File

@@ -254,7 +254,8 @@ public enum WidgetInfo
BARROWS_INFO(WidgetID.BARROWS_GROUP_ID, 0),
BARROWS_BROTHERS(WidgetID.BARROWS_GROUP_ID, WidgetID.Barrows.BARROWS_BROTHERS),
BARROWS_POTENTIAL(WidgetID.BARROWS_GROUP_ID, WidgetID.Barrows.BARROWS_POTENTIAL);
BARROWS_POTENTIAL(WidgetID.BARROWS_GROUP_ID, WidgetID.Barrows.BARROWS_POTENTIAL),
BARROWS_REWARD_INVENTORY(WidgetID.BARROWS_REWARD_GROUP_ID, WidgetID.Barrows.BARROWS_REWARD_INVENTORY);
private final int groupId;
private final int childId;

View File

@@ -32,6 +32,7 @@ import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -166,7 +167,7 @@ public class ItemManager
* @param itemIds array of item Ids
* @return a future called with the looked up prices
*/
public CompletableFuture<ItemPrice[]> getItemPriceBatch(List<Integer> itemIds)
public CompletableFuture<ItemPrice[]> getItemPriceBatch(Collection<Integer> itemIds)
{
final List<Integer> lookup = new ArrayList<>();
final List<ItemPrice> existing = new ArrayList<>();

View File

@@ -58,11 +58,22 @@ public interface BarrowsConfig extends Config
return true;
}
@ConfigItem(
keyName = "showChestValue",
name = "Show Value of Chests",
description = "Configure whether to show total exchange value of chest when opened",
position = 2
)
default boolean showChestValue()
{
return true;
}
@ConfigItem(
keyName = "brotherLocColor",
name = "Brother location color",
description = "Change the color of the name displayed on the minimap",
position = 2
position = 3
)
default Color brotherLocColor()
{
@@ -73,7 +84,7 @@ public interface BarrowsConfig extends Config
keyName = "deadBrotherLocColor",
name = "Dead Brother loc. color",
description = "Change the color of the name displayed on the minimap for a dead brother",
position = 3
position = 4
)
default Color deadBrotherLocColor()
{

View File

@@ -29,13 +29,23 @@ import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import static net.runelite.api.ItemID.COINS_995;
import net.runelite.api.ObjectID;
import net.runelite.api.WallObject;
import net.runelite.api.events.GameObjectChanged;
@@ -45,14 +55,24 @@ import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.WallObjectChanged;
import net.runelite.api.events.WallObjectDespawned;
import net.runelite.api.events.WallObjectSpawned;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.WidgetID;
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.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.util.StackFormatter;
import net.runelite.http.api.item.ItemPrice;
@PluginDescriptor(
name = "Barrows Brothers"
)
@Slf4j
public class BarrowsPlugin extends Plugin
{
@Getter(AccessLevel.PACKAGE)
@@ -89,6 +109,20 @@ public class BarrowsPlugin extends Plugin
return Arrays.asList(barrowsOverlay, brotherOverlay);
}
@Inject
private Client client;
@Inject
private ItemManager itemManager;
@Inject
private ChatMessageManager chatMessageManager;
@Inject
private BarrowsConfig config;
private long chestPrice;
@Override
protected void shutDown()
{
@@ -166,4 +200,76 @@ public class BarrowsPlugin extends Plugin
ladders.clear();
}
}
@Subscribe
public void onWidgetLoaded(WidgetLoaded event)
{
if (event.getGroupId() == WidgetID.BARROWS_REWARD_GROUP_ID && config.showChestValue())
{
ItemContainer barrowsRewardContainer = client.getItemContainer(InventoryID.BARROWS_REWARD);
Map<Integer, Integer> itemMap = new HashMap<>();
chestPrice = 0;
for (Item item : barrowsRewardContainer.getItems())
{
if (item.getId() != -1)
{
if (item.getId() == COINS_995)
{
chestPrice += item.getQuantity();
continue;
}
itemMap.put(item.getId(), item.getQuantity());
}
}
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemMap.keySet());
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) ->
{
if (ex != null)
{
log.debug("Error looking up item prices", ex);
return;
}
if (itemPrices == null)
{
log.debug("Error looking up item prices");
return;
}
log.debug("Price lookup is complete. {} prices.", itemPrices.length);
try
{
for (ItemPrice itemPrice : itemPrices)
{
if (itemPrice.getItem() == null)
{
continue; // cached no price
}
long itemStack = (long) itemPrice.getPrice() * (long) itemMap.get(itemPrice.getItem().getId());
chestPrice += itemStack;
}
final ChatMessageBuilder message = new ChatMessageBuilder()
.append(ChatColorType.HIGHLIGHT)
.append("Your chest is worth around ")
.append(StackFormatter.formatNumber(chestPrice))
.append(" coins.")
.append(ChatColorType.NORMAL);
chatMessageManager.queue(QueuedMessage.builder()
.type(ChatMessageType.EXAMINE_ITEM)
.runeLiteFormattedMessage(message.build())
.build());
}
catch (Exception ex2)
{
log.warn("error calculating price", ex2);
}
});
}
}
}