Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2021-11-12 07:39:46 +01:00
5 changed files with 121 additions and 11 deletions

View File

@@ -22,7 +22,7 @@
* (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.plugins.runepouch;
package net.runelite.client.game;
import com.google.common.collect.ImmutableMap;
@@ -52,7 +52,7 @@ import static net.runelite.api.ItemID.STEAM_RUNE;
import static net.runelite.api.ItemID.WATER_RUNE;
import static net.runelite.api.ItemID.WRATH_RUNE;
public enum Runes
public enum RunepouchRune
{
AIR(1, AIR_RUNE),
WATER(2, WATER_RUNE),
@@ -85,25 +85,25 @@ public enum Runes
@Setter
private BufferedImage image;
private static final Map<Integer, Runes> runes;
private static final Map<Integer, RunepouchRune> runes;
static
{
ImmutableMap.Builder<Integer, Runes> builder = new ImmutableMap.Builder<>();
for (Runes rune : values())
ImmutableMap.Builder<Integer, RunepouchRune> builder = new ImmutableMap.Builder<>();
for (RunepouchRune rune : values())
{
builder.put(rune.getId(), rune);
}
runes = builder.build();
}
Runes(int id, int itemId)
RunepouchRune(int id, int itemId)
{
this.id = id;
this.itemId = itemId;
}
public static Runes getRune(int varbit)
public static RunepouchRune getRune(int varbit)
{
return runes.get(varbit);
}

View File

@@ -64,6 +64,7 @@ import net.runelite.api.Scene;
import net.runelite.api.ScriptID;
import net.runelite.api.Tile;
import net.runelite.api.TileObject;
import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ChatMessage;
@@ -95,6 +96,7 @@ import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.events.OverlayMenuClicked;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.RunepouchRune;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor;
@@ -143,6 +145,12 @@ public class ClueScrollPlugin extends Plugin
private static final Color HIGHLIGHT_HOVER_BORDER_COLOR = HIGHLIGHT_BORDER_COLOR.darker();
private static final Color HIGHLIGHT_FILL_COLOR = new Color(0, 255, 0, 20);
private static final String CLUE_TAG_NAME = "clue";
private static final Varbits[] RUNEPOUCH_AMOUNT_VARBITS = {
Varbits.RUNE_POUCH_AMOUNT1, Varbits.RUNE_POUCH_AMOUNT2, Varbits.RUNE_POUCH_AMOUNT3
};
private static final Varbits[] RUNEPOUCH_RUNE_VARBITS = {
Varbits.RUNE_POUCH_RUNE1, Varbits.RUNE_POUCH_RUNE2, Varbits.RUNE_POUCH_RUNE3
};
@Getter
private ClueScroll clue;
@@ -361,7 +369,36 @@ public class ClueScrollPlugin extends Plugin
return;
}
inventoryItems = event.getItemContainer().getItems();
if (event.getItemContainer().contains(ItemID.RUNE_POUCH) || event.getItemContainer().contains(ItemID.RUNE_POUCH_L))
{
// Clone the array so changes aren't passed back to the event.
inventoryItems = event.getItemContainer().getItems().clone();
List<Item> runePouchContents = getRunepouchContents();
if (!runePouchContents.isEmpty())
{
for (int i = 0; i < inventoryItems.length; i++)
{
Item invItem = inventoryItems[i];
for (Item rune : runePouchContents)
{
if (invItem.getId() == rune.getId())
{
inventoryItems[i] = new Item(invItem.getId(), rune.getQuantity() + invItem.getQuantity());
runePouchContents.remove(rune);
break;
}
}
}
inventoryItems = ArrayUtils.addAll(inventoryItems, runePouchContents.toArray(new Item[0]));
}
}
else
{
inventoryItems = event.getItemContainer().getItems();
}
// Check if item was removed from inventory
if (clue != null && clueItemId != null)
@@ -393,6 +430,30 @@ public class ClueScrollPlugin extends Plugin
}
}
private List<Item> getRunepouchContents()
{
List<Item> items = new ArrayList<>();
for (int i = 0; i < RUNEPOUCH_AMOUNT_VARBITS.length; i++)
{
int amount = client.getVar(RUNEPOUCH_AMOUNT_VARBITS[i]);
if (amount <= 0)
{
continue;
}
int varbId = client.getVar(RUNEPOUCH_RUNE_VARBITS[i]);
RunepouchRune rune = RunepouchRune.getRune(varbId);
if (rune == null)
{
continue;
}
Item item = new Item(rune.getItemId(), amount);
items.add(item);
}
return items;
}
@Subscribe
public void onNpcSpawned(final NpcSpawned event)
{

View File

@@ -143,7 +143,7 @@ public class SkillChallengeClue extends ClueScroll implements NpcClueScroll, Nam
new SkillChallengeClue("Equip a Dragon Scimitar.", true, any("Any Dragon Scimitar", item(ItemID.DRAGON_SCIMITAR), item(ItemID.DRAGON_SCIMITAR_OR))),
new SkillChallengeClue("Enchant some Dragonstone Jewellery.", "enchant a piece of dragonstone jewellery.",
xOfItem(ItemID.COSMIC_RUNE, 1),
any("Water Rune x15", xOfItem(ItemID.WATER_RUNE, 15), xOfItem(ItemID.MIST_RUNE, 15), xOfItem(ItemID.MUD_RUNE, 15), xOfItem(ItemID.STEAM_RUNE, 15), item(ItemID.STAFF_OF_WATER), item(ItemID.WATER_BATTLESTAFF), item(ItemID.MYSTIC_WATER_STAFF), item(ItemID.MUD_BATTLESTAFF), item(ItemID.MYSTIC_MUD_STAFF), item(ItemID.MIST_BATTLESTAFF), item(ItemID.MYSTIC_MIST_STAFF), item(ItemID.STEAM_BATTLESTAFF), item(ItemID.MYSTIC_STEAM_STAFF), item(ItemID.STEAM_BATTLESTAFF_12795), item(ItemID.MYSTIC_STEAM_STAFF_12796), item(ItemID.KODAI_WAND)),
any("Water Rune x15", xOfItem(ItemID.WATER_RUNE, 15), xOfItem(ItemID.MIST_RUNE, 15), xOfItem(ItemID.MUD_RUNE, 15), xOfItem(ItemID.STEAM_RUNE, 15), item(ItemID.STAFF_OF_WATER), item(ItemID.WATER_BATTLESTAFF), item(ItemID.MYSTIC_WATER_STAFF), item(ItemID.MUD_BATTLESTAFF), item(ItemID.MYSTIC_MUD_STAFF), item(ItemID.MIST_BATTLESTAFF), item(ItemID.MYSTIC_MIST_STAFF), item(ItemID.STEAM_BATTLESTAFF), item(ItemID.MYSTIC_STEAM_STAFF), item(ItemID.STEAM_BATTLESTAFF_12795), item(ItemID.MYSTIC_STEAM_STAFF_12796), item(ItemID.KODAI_WAND), item(ItemID.TOME_OF_WATER)),
any("Earth Rune x15", xOfItem(ItemID.EARTH_RUNE, 15), xOfItem(ItemID.DUST_RUNE, 15), xOfItem(ItemID.MUD_RUNE, 15), xOfItem(ItemID.LAVA_RUNE, 15), item(ItemID.STAFF_OF_EARTH), item(ItemID.EARTH_BATTLESTAFF), item(ItemID.MYSTIC_EARTH_STAFF), item(ItemID.MUD_BATTLESTAFF), item(ItemID.MYSTIC_MUD_STAFF), item(ItemID.DUST_BATTLESTAFF), item(ItemID.MYSTIC_DUST_STAFF), item(ItemID.LAVA_BATTLESTAFF), item(ItemID.MYSTIC_LAVA_STAFF), item(ItemID.LAVA_BATTLESTAFF_21198), item(ItemID.MYSTIC_LAVA_STAFF_21200)),
any("Unenchanted Dragonstone Jewellery", item(ItemID.DRAGONSTONE_RING), item(ItemID.DRAGON_NECKLACE), item(ItemID.DRAGONSTONE_BRACELET), item(ItemID.DRAGONSTONE_AMULET))),
new SkillChallengeClue("Craft a nature rune.", item(ItemID.PURE_ESSENCE)),

View File

@@ -35,6 +35,7 @@ import net.runelite.api.Point;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.RunepouchRune;
import static net.runelite.client.plugins.runepouch.config.RunePouchOverlayMode.BOTH;
import static net.runelite.client.plugins.runepouch.config.RunePouchOverlayMode.MOUSE_HOVER;
import net.runelite.client.ui.FontManager;
@@ -100,7 +101,7 @@ public class RunepouchOverlay extends WidgetItemOverlay
Varbits runeVarbit = RUNE_VARBITS[i];
int runeId = client.getVar(runeVarbit);
Runes rune = Runes.getRune(runeId);
RunepouchRune rune = RunepouchRune.getRune(runeId);
if (rune == null)
{
continue;
@@ -149,7 +150,7 @@ public class RunepouchOverlay extends WidgetItemOverlay
}
}
private BufferedImage getRuneImage(Runes rune)
private BufferedImage getRuneImage(RunepouchRune rune)
{
BufferedImage runeImg = rune.getImage();
if (runeImg != null)

View File

@@ -30,14 +30,22 @@ import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.Arrays;
import java.util.List;
import net.runelite.api.ChatMessageType;
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.NPC;
import net.runelite.api.NullObjectID;
import net.runelite.api.Player;
import net.runelite.api.Varbits;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
@@ -45,8 +53,11 @@ import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.banktags.TagManager;
import net.runelite.client.plugins.cluescrolls.clues.hotcold.HotColdLocation;
import net.runelite.client.ui.overlay.OverlayManager;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -183,4 +194,41 @@ public class ClueScrollPluginTest
plugin.onChatMessage(withdrawMessage);
assertNull(plugin.getActiveSTASHClue());
}
@Test
public void testThatRunepouchIsAddedToInventory()
{
ItemContainer container = mock(ItemContainer.class);
ItemContainerChanged event = new ItemContainerChanged(InventoryID.INVENTORY.getId(), container);
final Item[] inventory = {
new Item(ItemID.COINS_995, 100),
new Item(ItemID.MITHRIL_BAR, 1),
new Item(ItemID.MITHRIL_BAR, 1),
new Item(ItemID.MITHRIL_BAR, 1),
new Item(ItemID.SOUL_RUNE, 30),
new Item(ItemID.COSMIC_RUNE, 100),
new Item(ItemID.RUNE_POUCH, 1),
new Item(ItemID.SPADE, 1),
new Item(ItemID.CLUE_SCROLL_MASTER, 1)
};
when(container.getItems()).thenReturn(inventory);
when(container.contains(ItemID.RUNE_POUCH)).thenReturn(true);
when(client.getItemContainer(InventoryID.INVENTORY)).thenReturn(container);
when(client.getVar(Varbits.RUNE_POUCH_RUNE1)).thenReturn(9); // Cosmic Rune
when(client.getVar(Varbits.RUNE_POUCH_AMOUNT1)).thenReturn(20);
when(client.getVar(Varbits.RUNE_POUCH_RUNE3)).thenReturn(4); // Fire Rune
when(client.getVar(Varbits.RUNE_POUCH_AMOUNT3)).thenReturn(4000);
plugin.onItemContainerChanged(event);
assertFalse(Arrays.equals(inventory, plugin.getInventoryItems()));
List<Item> inventoryList = Arrays.asList(plugin.getInventoryItems());
assertThat(inventoryList, hasItem(new Item(ItemID.COSMIC_RUNE, 120)));
assertThat(inventoryList, hasItem(new Item(ItemID.FIRE_RUNE, 4000)));
}
}