item charges: add Chronicle

This commit is contained in:
Unmoon
2020-10-01 16:04:06 +03:00
committed by Adam
parent 43bf4d60eb
commit f17a08ff9d
6 changed files with 149 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* Copyright (c) 2019, Aleios <https://github.com/aleios>
* Copyright (c) 2020, Unmoon <https://github.com/unmoon>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -450,4 +451,22 @@ public interface ItemChargeConfig extends Config
{
return false;
}
@ConfigItem(
keyName = "chronicle",
name = "",
description = "",
hidden = true
)
default int chronicle()
{
return -1;
}
@ConfigItem(
keyName = "chronicle",
name = "",
description = ""
)
void chronicle(int chronicle);
}

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2019, Aleios <https://github.com/aleios>
* Copyright (c) 2020, Unmoon <https://github.com/unmoon>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -115,6 +116,15 @@ class ItemChargeOverlay extends WidgetItemOverlay
charges = config.amuletOfBounty();
}
else if (itemId == ItemID.CHRONICLE)
{
if (!config.showTeleportCharges())
{
return;
}
charges = config.chronicle();
}
else
{
ItemWithCharge chargeItem = ItemWithCharge.findItem(itemId);

View File

@@ -2,6 +2,7 @@
* Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2018, Hydrox6 <ikada@protonmail.ch>
* Copyright (c) 2019, Aleios <https://github.com/aleios>
* Copyright (c) 2020, Unmoon <https://github.com/unmoon>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -60,6 +61,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.Text;
@PluginDescriptor(
name = "Item Charges",
@@ -75,7 +77,7 @@ public class ItemChargePlugin extends Plugin
"Your dodgy necklace protects you\\..*It has (\\d+) charges? left\\.");
private static final Pattern DODGY_BREAK_PATTERN = Pattern.compile(
"Your dodgy necklace protects you\\..*It then crumbles to dust\\.");
private static final String RING_OF_RECOIL_BREAK_MESSAGE = "<col=7f007f>Your Ring of Recoil has shattered.</col>";
private static final String RING_OF_RECOIL_BREAK_MESSAGE = "Your Ring of Recoil has shattered.";
private static final Pattern BINDING_CHECK_PATTERN = Pattern.compile(
"You have ([0-9]+|one) charges? left before your Binding necklace disintegrates\\.");
private static final Pattern BINDING_USED_PATTERN = Pattern.compile(
@@ -84,23 +86,33 @@ public class ItemChargePlugin extends Plugin
private static final Pattern RING_OF_FORGING_CHECK_PATTERN = Pattern.compile(
"You can smelt ([0-9]+|one) more pieces? of iron ore before a ring melts\\.");
private static final String RING_OF_FORGING_USED_TEXT = "You retrieve a bar of iron.";
private static final String RING_OF_FORGING_BREAK_TEXT = "<col=7f007f>Your Ring of Forging has melted.</col>";
private static final String RING_OF_FORGING_BREAK_TEXT = "Your Ring of Forging has melted.";
private static final Pattern AMULET_OF_CHEMISTRY_CHECK_PATTERN = Pattern.compile(
"Your amulet of chemistry has (\\d) charges? left\\."
);
private static final Pattern AMULET_OF_CHEMISTRY_USED_PATTERN = Pattern.compile(
"Your amulet of chemistry helps you create a \\d-dose potion\\. (?:<col=ff0000>)?It has (\\d|one) charges? left\\."
"Your amulet of chemistry helps you create a \\d-dose potion\\. It has (\\d|one) charges? left\\."
);
private static final Pattern AMULET_OF_CHEMISTRY_BREAK_PATTERN = Pattern.compile(
"Your amulet of chemistry helps you create a \\d-dose potion\\. (?:<col=ff0000>)?It then crumbles to dust\\."
"Your amulet of chemistry helps you create a \\d-dose potion\\. It then crumbles to dust\\."
);
private static final Pattern AMULET_OF_BOUNTY_CHECK_PATTERN = Pattern.compile(
"Your amulet of bounty has (\\d+) charges? left\\."
);
private static final Pattern AMULET_OF_BOUNTY_USED_PATTERN = Pattern.compile(
"Your amulet of bounty saves some seeds for you\\. (?:<col=ff0000>)?It has (\\d) charges? left\\."
"Your amulet of bounty saves some seeds for you\\. It has (\\d) charges? left\\."
);
private static final String AMULET_OF_BOUNTY_BREAK_TEXT = "Your amulet of bounty saves some seeds for you. <col=ff0000>It then crumbles to dust.</col>";
private static final String AMULET_OF_BOUNTY_BREAK_TEXT = "Your amulet of bounty saves some seeds for you. It then crumbles to dust.";
private static final Pattern CHRONICLE_ADD_PATTERN = Pattern.compile(
"You add (?:\\d+|a single) charges? to your book\\. It now has (\\d+|one) charges?\\."
);
private static final Pattern CHRONICLE_USE_AND_CHECK_PATTERN = Pattern.compile(
"Your book has (\\d+) charges left\\."
);
private static final String CHRONICLE_FULL_TEXT = "Your book is fully charged! It has 1,000 charges already.";
private static final String CHRONICLE_ONE_CHARGE_TEXT = "You have one charge left in your book.";
private static final String CHRONICLE_EMPTY_TEXT = "Your book has run out of charges.";
private static final String CHRONICLE_NO_CHARGES_TEXT = "Your book does not have any charges. Purchase some Teleport Cards from Diango.";
private static final int MAX_DODGY_CHARGES = 10;
private static final int MAX_BINDING_CHARGES = 16;
@@ -218,7 +230,7 @@ public class ItemChargePlugin extends Plugin
{
if (event.getType() == ChatMessageType.GAMEMESSAGE || event.getType() == ChatMessageType.SPAM)
{
String message = event.getMessage();
String message = Text.removeTags(event.getMessage());
Matcher dodgyCheckMatcher = DODGY_CHECK_PATTERN.matcher(message);
Matcher dodgyProtectMatcher = DODGY_PROTECT_PATTERN.matcher(message);
Matcher dodgyBreakMatcher = DODGY_BREAK_PATTERN.matcher(message);
@@ -230,6 +242,8 @@ public class ItemChargePlugin extends Plugin
Matcher amuletOfChemistryBreakMatcher = AMULET_OF_CHEMISTRY_BREAK_PATTERN.matcher(message);
Matcher amuletOfBountyCheckMatcher = AMULET_OF_BOUNTY_CHECK_PATTERN.matcher(message);
Matcher amuletOfBountyUsedMatcher = AMULET_OF_BOUNTY_USED_PATTERN.matcher(message);
Matcher chronicleAddMatcher = CHRONICLE_ADD_PATTERN.matcher(message);
Matcher chronicleUseAndCheckMatcher = CHRONICLE_USE_AND_CHECK_PATTERN.matcher(message);
if (config.recoilNotification() && message.contains(RING_OF_RECOIL_BREAK_MESSAGE))
{
@@ -346,6 +360,35 @@ public class ItemChargePlugin extends Plugin
updateRingOfForgingCharges(MAX_RING_OF_FORGING_CHARGES);
}
else if (chronicleAddMatcher.find())
{
final String match = chronicleAddMatcher.group(1);
if (match.equals("one"))
{
config.chronicle(1);
}
else
{
config.chronicle(Integer.parseInt(match));
}
}
else if (chronicleUseAndCheckMatcher.find())
{
config.chronicle(Integer.parseInt(chronicleUseAndCheckMatcher.group(1)));
}
else if (message.equals(CHRONICLE_ONE_CHARGE_TEXT))
{
config.chronicle(1);
}
else if (message.equals(CHRONICLE_EMPTY_TEXT) || message.equals(CHRONICLE_NO_CHARGES_TEXT))
{
config.chronicle(0);
}
else if (message.equals(CHRONICLE_FULL_TEXT))
{
config.chronicle(1000);
}
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, Mitchell <https://github.com/Mitchell-Kovacs>
* Copyright (c) 2020, Unmoon <https://github.com/unmoon>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -42,5 +43,6 @@ enum ItemChargeType
SACK,
RING_OF_FORGING,
GUTHIX_REST,
CHRONICLE,
POTION,
}

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2019, Tomas Slusny <slusnucky@gmail.com>
* Copyright (c) 2019, Aleios <https://github.com/aleios>
* Copyright (c) 2020, Unmoon <https://github.com/unmoon>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,6 +41,7 @@ enum ItemWithSlot
BINDING_NECKLACE(ItemChargeType.BINDING_NECKLACE, EquipmentInventorySlot.AMULET),
EXPLORER_RING(ItemChargeType.EXPLORER_RING, EquipmentInventorySlot.RING),
RING_OF_FORGING(ItemChargeType.RING_OF_FORGING, EquipmentInventorySlot.RING),
CHRONICLE(ItemChargeType.CHRONICLE, EquipmentInventorySlot.SHIELD),
TELEPORT(ItemChargeType.TELEPORT, EquipmentInventorySlot.WEAPON, EquipmentInventorySlot.AMULET, EquipmentInventorySlot.GLOVES, EquipmentInventorySlot.RING);
private final ItemChargeType type;

View File

@@ -72,6 +72,18 @@ public class ItemChargePluginTest
private static final String BREAK_AMULET_OF_CHEMISTRY_3_DOSES = "Your amulet of chemistry helps you create a 3-dose potion. It then crumbles to dust.";
private static final String BREAK_AMULET_OF_CHEMISTRY_2_DOSES = "Your amulet of chemistry helps you create a 2-dose potion. It then crumbles to dust.";
private static final String CHRONICLE_CHECK_CHARGES_FULL = "Your book has 1000 charges left.";
private static final String CHRONICLE_CHECK_CHARGES_ONE = "You have one charge left in your book.";
private static final String CHRONICLE_CHECK_CHARGES_EMPTY = "Your book has run out of charges.";
private static final String CHRONICLE_TELEPORT = "<col=ef1020>Your book has 999 charges left.</col>";
private static final String CHRONICLE_TELEPORT_ONE = "<col=ef1020>You have one charge left in your book.</col>";
private static final String CHRONICLE_TELEPORT_EMPTY = "<col=ef1020>Your book has run out of charges.</col>";
private static final String CHRONICLE_TELEPORT_FAIL = "Your book does not have any charges. Purchase some Teleport Cards from Diango.";
private static final String CHRONICLE_ADD_SINGLE_CHARGE = "You add a single charge to your book. It now has one charge.";
private static final String CHRONICLE_ADD_SINGLE_CHARGE_FULL = "You add a single charge to your book. It now has 1000 charges.";
private static final String CHRONICLE_ADD_MULTIPLE_CHARGES = "You add 5 charges to your book. It now has 5 charges.";
private static final String CHRONICLE_ADD_FULL = "Your book is fully charged! It has 1,000 charges already.";
@Mock
@Bind
private Client client;
@@ -198,5 +210,59 @@ public class ItemChargePluginTest
verify(config).amuletOfChemistry(eq(5));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_CHECK_CHARGES_FULL, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(1000));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_CHECK_CHARGES_ONE, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(1));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_CHECK_CHARGES_EMPTY, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(0));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(999));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT_ONE, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(1));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT_EMPTY, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(0));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT_FAIL, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(0));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_SINGLE_CHARGE, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(1));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_SINGLE_CHARGE_FULL, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(1000));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_MULTIPLE_CHARGES, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(5));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_FULL, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).chronicle(eq(1000));
reset(config);
}
}