Merge pull request #11782 from deathbeam/remove-untrabeable
Merge UntradeableItemMapping and ItemMapping
This commit is contained in:
@@ -32,6 +32,7 @@ import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -290,7 +291,7 @@ public class ItemManager
|
||||
* Look up an item's price
|
||||
*
|
||||
* @param itemID item id
|
||||
* @param ignoreUntradeableMap should the price returned ignore the {@link UntradeableItemMapping}
|
||||
* @param ignoreUntradeableMap should the price returned ignore items that are not tradeable for coins in regular way
|
||||
* @return item price
|
||||
*/
|
||||
public int getItemPrice(int itemID, boolean ignoreUntradeableMap)
|
||||
@@ -311,24 +312,31 @@ public class ItemManager
|
||||
}
|
||||
itemID = WORN_ITEMS.getOrDefault(itemID, itemID);
|
||||
|
||||
if (!ignoreUntradeableMap)
|
||||
{
|
||||
UntradeableItemMapping p = UntradeableItemMapping.map(ItemVariationMapping.map(itemID));
|
||||
if (p != null)
|
||||
{
|
||||
return getItemPrice(p.getPriceID()) * p.getQuantity();
|
||||
}
|
||||
}
|
||||
|
||||
int price = 0;
|
||||
for (int mappedID : ItemMapping.map(itemID))
|
||||
|
||||
final Collection<ItemMapping> mappedItems = ItemMapping.map(itemID);
|
||||
|
||||
if (mappedItems == null)
|
||||
{
|
||||
ItemPrice ip = itemPrices.get(mappedID);
|
||||
final ItemPrice ip = itemPrices.get(itemID);
|
||||
|
||||
if (ip != null)
|
||||
{
|
||||
price += ip.getPrice();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (final ItemMapping mappedItem : mappedItems)
|
||||
{
|
||||
if (ignoreUntradeableMap && mappedItem.isUntradeable())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
price += getItemPrice(mappedItem.getTradeableItem(), ignoreUntradeableMap) * mappedItem.getQuantity();
|
||||
}
|
||||
}
|
||||
|
||||
return price;
|
||||
}
|
||||
|
||||
@@ -28,12 +28,14 @@ package net.runelite.client.game;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.Getter;
|
||||
import static net.runelite.api.ItemID.*;
|
||||
|
||||
/**
|
||||
* Converts untradeable items to it's tradeable counterparts
|
||||
*/
|
||||
@Getter
|
||||
public enum ItemMapping
|
||||
{
|
||||
// Barrows equipment
|
||||
@@ -249,6 +251,9 @@ public enum ItemMapping
|
||||
ITEM_CRYSTAL_BOW(CRYSTAL_WEAPON_SEED, CRYSTAL_BOW, CRYSTAL_BOW_24123, CRYSTAL_BOW_INACTIVE),
|
||||
ITEM_CRYSTAL_HALBERD(CRYSTAL_WEAPON_SEED, CRYSTAL_HALBERD, CRYSTAL_HALBERD_24125, CRYSTAL_HALBERD_INACTIVE),
|
||||
ITEM_CRYSTAL_SHIELD(CRYSTAL_WEAPON_SEED, CRYSTAL_SHIELD, CRYSTAL_SHIELD_24127, CRYSTAL_SHIELD_INACTIVE),
|
||||
ITEM_CRYSTAL_HELMET(CRYSTAL_ARMOUR_SEED, CRYSTAL_HELM, CRYSTAL_HELM_INACTIVE),
|
||||
ITEM_CRYSTAL_LEGS(CRYSTAL_ARMOUR_SEED, 2L, CRYSTAL_LEGS, CRYSTAL_LEGS_INACTIVE),
|
||||
ITEM_CRYSTAL_BODY(CRYSTAL_ARMOUR_SEED, 3L, CRYSTAL_BODY, CRYSTAL_BODY_INACTIVE),
|
||||
|
||||
// Bird nests
|
||||
ITEM_BIRD_NEST(BIRD_NEST_5075, BIRD_NEST, BIRD_NEST_5071, BIRD_NEST_5072, BIRD_NEST_5073, BIRD_NEST_5074, BIRD_NEST_7413, BIRD_NEST_13653, BIRD_NEST_22798, BIRD_NEST_22800, CLUE_NEST_EASY, CLUE_NEST_MEDIUM, CLUE_NEST_HARD, CLUE_NEST_ELITE),
|
||||
@@ -256,11 +261,38 @@ public enum ItemMapping
|
||||
// Ancestral robes
|
||||
ITEM_ANCESTRAL_HAT(ANCESTRAL_HAT, TWISTED_ANCESTRAL_HAT),
|
||||
ITEM_ANCESTRAL_ROBE_TOP(ANCESTRAL_ROBE_TOP, TWISTED_ANCESTRAL_ROBE_TOP),
|
||||
ITEM_ANCESTRAL_ROBE_BOTTOM(ANCESTRAL_ROBE_BOTTOM, TWISTED_ANCESTRAL_ROBE_BOTTOM);
|
||||
ITEM_ANCESTRAL_ROBE_BOTTOM(ANCESTRAL_ROBE_BOTTOM, TWISTED_ANCESTRAL_ROBE_BOTTOM),
|
||||
|
||||
private static final Multimap<Integer, Integer> MAPPINGS = HashMultimap.create();
|
||||
// Graceful
|
||||
ITEM_MARK_OF_GRACE(AMYLASE_CRYSTAL, true, 10L, MARK_OF_GRACE),
|
||||
ITEM_GRACEFUL_HOOD(MARK_OF_GRACE, true, 28L, GRACEFUL_HOOD),
|
||||
ITEM_GRACEFUL_TOP(MARK_OF_GRACE, true, 44L, GRACEFUL_TOP),
|
||||
ITEM_GRACEFUL_LEGS(MARK_OF_GRACE, true, 48L, GRACEFUL_LEGS),
|
||||
ITEM_GRACEFUL_GLOVES(MARK_OF_GRACE, true, 24L, GRACEFUL_GLOVES),
|
||||
ITEM_GRACEFUL_BOOTS(MARK_OF_GRACE, true, 32L, GRACEFUL_BOOTS),
|
||||
ITEM_GRACEFUL_CAPE(MARK_OF_GRACE, true, 32L, GRACEFUL_CAPE),
|
||||
|
||||
// 10 golden nuggets = 100 soft clay
|
||||
ITEM_GOLDEN_NUGGET(SOFT_CLAY, true, 10L, GOLDEN_NUGGET),
|
||||
ITEM_PROSPECTOR_HELMET(GOLDEN_NUGGET, true, 32L, PROSPECTOR_HELMET),
|
||||
ITEM_PROSPECTOR_JACKET(GOLDEN_NUGGET, true, 48L, PROSPECTOR_JACKET),
|
||||
ITEM_PROSPECTOR_LEGS(GOLDEN_NUGGET, true, 40L, PROSPECTOR_LEGS),
|
||||
ITEM_PROSPECTOR_BOOTS(GOLDEN_NUGGET, true, 24L, PROSPECTOR_BOOTS),
|
||||
|
||||
// Converted to coins
|
||||
ITEM_TATTERED_PAGE(COINS_995, true, 1000L, TATTERED_MOON_PAGE, TATTERED_SUN_PAGE, TATTERED_TEMPLE_PAGE),
|
||||
ITEM_LONG_BONE(COINS_995, true, 1000L, LONG_BONE),
|
||||
ITEM_CURVED_BONE(COINS_995, true, 2000L, CURVED_BONE),
|
||||
ITEM_PERFECT_SHELL(COINS_995, true, 600L, PERFECT_SHELL),
|
||||
ITEM_PERFECT_SNAIL_SHELL(COINS_995, true, 600L, PERFECT_SNAIL_SHELL),
|
||||
ITEM_SNAIL_SHELL(COINS_995, true, 600L, SNAIL_SHELL),
|
||||
ITEM_TORTOISE_SHELL(COINS_995, true, 250L, TORTOISE_SHELL);
|
||||
|
||||
private static final Multimap<Integer, ItemMapping> MAPPINGS = HashMultimap.create();
|
||||
private final int tradeableItem;
|
||||
private final int[] untradableItems;
|
||||
private final long quantity;
|
||||
private final boolean untradeable;
|
||||
|
||||
static
|
||||
{
|
||||
@@ -268,15 +300,35 @@ public enum ItemMapping
|
||||
{
|
||||
for (int itemId : item.untradableItems)
|
||||
{
|
||||
MAPPINGS.put(itemId, item.tradeableItem);
|
||||
if (item.untradeable)
|
||||
{
|
||||
for (final Integer variation : ItemVariationMapping.getVariations(itemId))
|
||||
{
|
||||
MAPPINGS.put(variation, item);
|
||||
}
|
||||
}
|
||||
|
||||
MAPPINGS.put(itemId, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemMapping(int tradeableItem, int... untradableItems)
|
||||
ItemMapping(int tradeableItem, boolean untradeable, long quantity, int... untradableItems)
|
||||
{
|
||||
this.tradeableItem = tradeableItem;
|
||||
this.untradableItems = untradableItems;
|
||||
this.quantity = quantity;
|
||||
this.untradeable = untradeable;
|
||||
}
|
||||
|
||||
ItemMapping(int tradeableItem, long quantity, int... untradableItems)
|
||||
{
|
||||
this(tradeableItem, false, quantity, untradableItems);
|
||||
}
|
||||
|
||||
ItemMapping(int tradeableItem, int... untradableItems)
|
||||
{
|
||||
this(tradeableItem, 1L, untradableItems);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,33 +337,16 @@ public enum ItemMapping
|
||||
* @param itemId the item id
|
||||
* @return the collection
|
||||
*/
|
||||
public static Collection<Integer> map(int itemId)
|
||||
@Nullable
|
||||
public static Collection<ItemMapping> map(int itemId)
|
||||
{
|
||||
final Collection<Integer> mapping = MAPPINGS.get(itemId);
|
||||
final Collection<ItemMapping> mapping = MAPPINGS.get(itemId);
|
||||
|
||||
if (mapping == null || mapping.isEmpty())
|
||||
if (mapping.isEmpty())
|
||||
{
|
||||
return Collections.singleton(itemId);
|
||||
return null;
|
||||
}
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map an item from its untradeable version to its tradeable version
|
||||
*
|
||||
* @param itemId
|
||||
* @return
|
||||
*/
|
||||
public static int mapFirst(int itemId)
|
||||
{
|
||||
final Collection<Integer> mapping = MAPPINGS.get(itemId);
|
||||
|
||||
if (mapping == null || mapping.isEmpty())
|
||||
{
|
||||
return itemId;
|
||||
}
|
||||
|
||||
return mapping.iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.game;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.runelite.api.ItemID;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum UntradeableItemMapping
|
||||
{
|
||||
MARK_OF_GRACE(ItemID.MARK_OF_GRACE, 10, ItemID.AMYLASE_CRYSTAL),
|
||||
GRACEFUL_HOOD(ItemID.GRACEFUL_HOOD, 28, ItemID.MARK_OF_GRACE),
|
||||
GRACEFUL_TOP(ItemID.GRACEFUL_TOP, 44, ItemID.MARK_OF_GRACE),
|
||||
GRACEFUL_LEGS(ItemID.GRACEFUL_LEGS, 48, ItemID.MARK_OF_GRACE),
|
||||
GRACEFUL_GLOVES(ItemID.GRACEFUL_GLOVES, 24, ItemID.MARK_OF_GRACE),
|
||||
GRACEFUL_BOOTS(ItemID.GRACEFUL_BOOTS, 32, ItemID.MARK_OF_GRACE),
|
||||
GRACEFUL_CAPE(ItemID.GRACEFUL_CAPE, 32, ItemID.MARK_OF_GRACE),
|
||||
|
||||
// 10 golden nuggets = 100 soft clay
|
||||
GOLDEN_NUGGET(ItemID.GOLDEN_NUGGET, 10, ItemID.SOFT_CLAY),
|
||||
PROSPECTOR_HELMET(ItemID.PROSPECTOR_HELMET, 32, ItemID.GOLDEN_NUGGET),
|
||||
PROSPECTOR_JACKET(ItemID.PROSPECTOR_JACKET, 48, ItemID.GOLDEN_NUGGET),
|
||||
PROSPECTOR_LEGS(ItemID.PROSPECTOR_LEGS, 40, ItemID.GOLDEN_NUGGET),
|
||||
PROSPECTOR_BOOTS(ItemID.PROSPECTOR_BOOTS, 24, ItemID.GOLDEN_NUGGET),
|
||||
|
||||
CRYSTAL_HELMET(ItemID.CRYSTAL_HELM, 1, ItemID.CRYSTAL_ARMOUR_SEED),
|
||||
CRYSTAL_HELMET_INACTIVE(ItemID.CRYSTAL_HELM_INACTIVE, 1, ItemID.CRYSTAL_ARMOUR_SEED),
|
||||
CRYSTAL_LEGS(ItemID.CRYSTAL_LEGS, 2, ItemID.CRYSTAL_ARMOUR_SEED),
|
||||
CRYSTAL_LEGS_INACTIVE(ItemID.CRYSTAL_LEGS_INACTIVE, 2, ItemID.CRYSTAL_ARMOUR_SEED),
|
||||
CRYSTAL_BODY(ItemID.CRYSTAL_BODY, 3, ItemID.CRYSTAL_ARMOUR_SEED),
|
||||
CRYSTAL_BODY_INACTIVE(ItemID.CRYSTAL_BODY_INACTIVE, 3, ItemID.CRYSTAL_ARMOUR_SEED),
|
||||
|
||||
TATTERED_MOON_PAGE(ItemID.TATTERED_MOON_PAGE, 1000, ItemID.COINS_995),
|
||||
TATTERED_SUN_PAGE(ItemID.TATTERED_SUN_PAGE, 1000, ItemID.COINS_995),
|
||||
TATTERED_TEMPLE_PAGE(ItemID.TATTERED_TEMPLE_PAGE, 1000, ItemID.COINS_995),
|
||||
|
||||
LONG_BONE(ItemID.LONG_BONE, 1000, ItemID.COINS_995),
|
||||
CURVED_BONE(ItemID.CURVED_BONE, 2000, ItemID.COINS_995),
|
||||
PERFECT_SHELL(ItemID.PERFECT_SHELL, 600, ItemID.COINS_995),
|
||||
PERFECT_SNAIL_SHELL(ItemID.PERFECT_SNAIL_SHELL, 600, ItemID.COINS_995),
|
||||
SNAIL_SHELL(ItemID.SNAIL_SHELL, 600, ItemID.COINS_995),
|
||||
TORTOISE_SHELL(ItemID.TORTOISE_SHELL, 250, ItemID.COINS_995);
|
||||
|
||||
private static final ImmutableMap<Integer, UntradeableItemMapping> UNTRADEABLE_RECLAIM_MAP;
|
||||
|
||||
private final int itemID;
|
||||
private final int quantity;
|
||||
private final int priceID;
|
||||
|
||||
static
|
||||
{
|
||||
ImmutableMap.Builder<Integer, UntradeableItemMapping> map = ImmutableMap.builder();
|
||||
for (UntradeableItemMapping p : values())
|
||||
{
|
||||
map.put(p.getItemID(), p);
|
||||
}
|
||||
UNTRADEABLE_RECLAIM_MAP = map.build();
|
||||
}
|
||||
|
||||
public static UntradeableItemMapping map(int itemId)
|
||||
{
|
||||
return UNTRADEABLE_RECLAIM_MAP.get(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user