From 0ed80d4850da79f47d168d1f4da246c4b8e2beba Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 02:32:50 +0400 Subject: [PATCH 1/8] Add mould related enums --- .../enums/CommisionType.java | 21 ++++++ .../easygiantsfoundry/enums/Mould.java | 69 +++++++++++++++++++ .../easygiantsfoundry/enums/MouldType.java | 7 ++ 3 files changed, 97 insertions(+) create mode 100644 src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java create mode 100644 src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java create mode 100644 src/main/java/com/toofifty/easygiantsfoundry/enums/MouldType.java diff --git a/src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java b/src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java new file mode 100644 index 0000000..43f5d47 --- /dev/null +++ b/src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java @@ -0,0 +1,21 @@ +package com.toofifty.easygiantsfoundry.enums; + +public enum CommisionType { + NONE, + NARROW, // 1 + LIGHT, // 2 + FLAT, // 3 + BROAD, // 4 + HEAVY, // 5 + SPIKED, // 6 + ; + + public static final CommisionType[] values = CommisionType.values(); + + public static CommisionType forVarbit(int varbitValue) { + if (varbitValue < 0 || varbitValue >= values.length) { + return NONE; + } + return CommisionType.values[varbitValue]; + } +} diff --git a/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java b/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java new file mode 100644 index 0000000..b3c234a --- /dev/null +++ b/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java @@ -0,0 +1,69 @@ +package com.toofifty.easygiantsfoundry.enums; + +import com.google.common.collect.ImmutableMap; +import lombok.AllArgsConstructor; + +import java.util.Map; + +import static com.toofifty.easygiantsfoundry.enums.CommisionType.*; +import static com.toofifty.easygiantsfoundry.enums.MouldType.*; + +@AllArgsConstructor +public enum Mould { + CHOPPER_FORTE("Chopper Forte", FORTE, ImmutableMap.of(BROAD, 4, LIGHT, 4, FLAT, 4)), + GALDIUS_RICASSO("Galdius Ricasso", FORTE, ImmutableMap.of(BROAD, 4, HEAVY, 4, FLAT, 4)), + DISARMING_FORTE("Disarming Forte", FORTE, ImmutableMap.of(NARROW, 4, LIGHT, 4, SPIKED, 4)), + MEDUSA_RICASSO("Medusa Ricasso", FORTE, ImmutableMap.of(BROAD, 8, HEAVY, 6, FLAT, 8)), + SERPENT_RICASSO("Serpent Ricasso", FORTE, ImmutableMap.of(NARROW, 6, LIGHT, 8, FLAT, 8)), + SERRATED_FORTE("Serrated Forte", FORTE, ImmutableMap.of(NARROW, 8, HEAVY, 8, SPIKED, 6)), + STILETTO_FORTE("Stiletto Forte", FORTE, ImmutableMap.of(NARROW, 8, LIGHT, 10, FLAT, 8)), + DEFENDER_BASE("Defender Base", FORTE, ImmutableMap.of(BROAD, 8, HEAVY, 10, FLAT, 8)), + JUGGERNAUT_FORTE("Juggernaut Forte", FORTE, ImmutableMap.of(BROAD, 4, HEAVY, 4, SPIKED, 16)), + CHOPPER_FORTE_1("Chopper Forte +1", FORTE, ImmutableMap.of(BROAD, 3, LIGHT, 4, FLAT, 18)), + SPIKER("Spiker!", FORTE, ImmutableMap.of(NARROW, 1, HEAVY, 2, SPIKED, 22)), + SAW_BLADE("Saw Blade", BLADE, ImmutableMap.of(BROAD, 4, LIGHT, 4, SPIKED, 4)), + DEFENDERS_EDGE("Defenders Edge", BLADE, ImmutableMap.of(BROAD, 4, HEAVY, 4, SPIKED, 4)), + FISH_BLADE("Fish Blade", BLADE, ImmutableMap.of(NARROW, 4, LIGHT, 4, FLAT, 4)), + MEDUSA_BLADE("Medusa Blade", BLADE, ImmutableMap.of(BROAD, 8, HEAVY, 8, FLAT, 6)), + STILETTO_BLADE("Stiletto Blade", BLADE, ImmutableMap.of(NARROW, 8, LIGHT, 6, FLAT, 8)), + GLADIUS_EDGE("Gladius Edge", BLADE, ImmutableMap.of(NARROW, 6, HEAVY, 8, FLAT, 8)), + FLAMBERGE_BLADE("Flamberge Blade", BLADE, ImmutableMap.of(NARROW, 8, LIGHT, 8, SPIKED, 10)), + SERPENT_BLADE("Serpent Blade", BLADE, ImmutableMap.of(NARROW, 10, LIGHT, 8, FLAT, 8)), + CLAYMORE_BLADE("Claymore Blade", BLADE, ImmutableMap.of(BROAD, 16, HEAVY, 4, FLAT, 4)), + FLEUR_DE_BLADE("Fleur de Blade", BLADE, ImmutableMap.of(BROAD, 4, HEAVY, 18, SPIKED, 1)), + CHOPPA("Choppa!", BLADE, ImmutableMap.of(BROAD, 1, LIGHT, 22, FLAT, 2)), + PEOPLE_POKER_POINT("People Poker Point", TIP, ImmutableMap.of(NARROW, 4, HEAVY, 4, FLAT, 4)), + CHOPPER_TIP("Chopper Tip", TIP, ImmutableMap.of(BROAD, 4, LIGHT, 4, SPIKED, 4)), + MEDUSAS_HEAD("Medusa's Head", TIP, ImmutableMap.of(BROAD, 4, HEAVY, 4, SPIKED, 4)), + SERPENTS_FANG("Serpent's Fang", TIP, ImmutableMap.of(NARROW, 8, LIGHT, 6, SPIKED, 8)), + GLADIUS_POINT("Gladius Point", TIP, ImmutableMap.of(NARROW, 8, HEAVY, 8, FLAT, 6)), + SAW_TIP("Saw Tip", TIP, ImmutableMap.of(BROAD, 6, HEAVY, 8, SPIKED, 8)), + CORRUPTED_POINT("Corrupted Point", TIP, ImmutableMap.of(NARROW, 8, LIGHT, 10, SPIKED, 8)), + DEFENDERS_TIP("Defenders Tip", TIP, ImmutableMap.of(BROAD, 10, HEAVY, 8, SPIKED, 8)), + SERRATED_TIPS("Serrated Tips", TIP, ImmutableMap.of(NARROW, 4, LIGHT, 16, SPIKED, 4)), + NEEDLE_POINT("Needle Point", TIP, ImmutableMap.of(NARROW, 18, LIGHT, 3, FLAT, 4)), + THE_POINT("The Point!", TIP, ImmutableMap.of(BROAD, 2, LIGHT, 1, FLAT, 22)), + ; + + private final String name; + private final MouldType mouldType; + private final Map typeToScore; + + public static final Mould[] values = Mould.values(); + + public static Mould forName(String text) { + for (Mould mould : values) { + if (mould.name.equalsIgnoreCase(text)) { + return mould; + } + } + return null; + } + + public int getScore(CommisionType type1, CommisionType type2) { + int score = 0; + score += typeToScore.getOrDefault(type1, 0); + score += typeToScore.getOrDefault(type2, 0); + return score; + } +} diff --git a/src/main/java/com/toofifty/easygiantsfoundry/enums/MouldType.java b/src/main/java/com/toofifty/easygiantsfoundry/enums/MouldType.java new file mode 100644 index 0000000..eb095e2 --- /dev/null +++ b/src/main/java/com/toofifty/easygiantsfoundry/enums/MouldType.java @@ -0,0 +1,7 @@ +package com.toofifty.easygiantsfoundry.enums; + +public enum MouldType { + FORTE, + BLADE, + TIP, +} From 735b6f4a71bb2d20b46cb14b09d8abf382d3bf7c Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 02:34:20 +0400 Subject: [PATCH 2/8] Add mould helper feature --- .../EasyGiantsFoundryPlugin.java | 21 ++++- .../easygiantsfoundry/MouldHelper.java | 91 +++++++++++++++++++ 2 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java diff --git a/src/main/java/com/toofifty/easygiantsfoundry/EasyGiantsFoundryPlugin.java b/src/main/java/com/toofifty/easygiantsfoundry/EasyGiantsFoundryPlugin.java index 1583ec1..bbbc7de 100644 --- a/src/main/java/com/toofifty/easygiantsfoundry/EasyGiantsFoundryPlugin.java +++ b/src/main/java/com/toofifty/easygiantsfoundry/EasyGiantsFoundryPlugin.java @@ -1,18 +1,18 @@ package com.toofifty.easygiantsfoundry; -import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; import net.runelite.api.InventoryID; -import net.runelite.api.ItemContainer; -import net.runelite.api.ItemID; import net.runelite.api.events.GameObjectDespawned; import net.runelite.api.events.GameObjectSpawned; import net.runelite.api.events.ItemContainerChanged; +import net.runelite.api.events.ScriptPostFired; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; +import javax.inject.Inject; + @Slf4j @PluginDescriptor( name = "Easy Giant's Foundry", @@ -35,6 +35,9 @@ public class EasyGiantsFoundryPlugin extends Plugin @Inject private EasyGiantsFoundryOverlay overlay; + @Inject + private MouldHelper mouldHelper; + @Override protected void startUp() { @@ -74,4 +77,16 @@ public class EasyGiantsFoundryPlugin extends Plugin state.reset(); } } + + @Subscribe + public void onScriptPostFired(ScriptPostFired event) + { + if (event.getScriptId() == MouldHelper.DRAW_MOULD_LIST_SCRIPT + || event.getScriptId() == MouldHelper.REDRAW_MOULD_LIST_SCRIPT + || event.getScriptId() == MouldHelper.SELECT_MOULD_SCRIPT + || event.getScriptId() == MouldHelper.RESET_MOULD_SCRIPT) + { + mouldHelper.selectBest(event.getScriptId()); + } + } } diff --git a/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java b/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java new file mode 100644 index 0000000..696c3d4 --- /dev/null +++ b/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java @@ -0,0 +1,91 @@ +package com.toofifty.easygiantsfoundry; + +import com.toofifty.easygiantsfoundry.enums.CommisionType; +import com.toofifty.easygiantsfoundry.enums.Mould; +import net.runelite.api.Client; +import net.runelite.api.ScriptID; +import net.runelite.api.widgets.Widget; +import net.runelite.client.callback.ClientThread; + +import javax.inject.Inject; +import java.util.*; + +public class MouldHelper +{ + static final int MOULD_LIST_PARENT = 47054857; + static final int DRAW_MOULD_LIST_SCRIPT = 6093; + static final int REDRAW_MOULD_LIST_SCRIPT = 6095; + static final int RESET_MOULD_SCRIPT = 6108; + public static final int SELECT_MOULD_SCRIPT = 6098; + private static final int SWORD_TYPE_1_VARBIT = 13907; // 4=Broad + private static final int SWORD_TYPE_2_VARBIT = 13908; // 3=Flat + private static final int DISABLED_TEXT_COLOR = 0x9f9f9f; + private static final int GREEN = 0xdc10d; + + @Inject + private Client client; + + @Inject + private ClientThread clientThread; + + public void selectBest(int scriptId) + { + Widget parent = client.getWidget(MOULD_LIST_PARENT); + if (parent == null || parent.getChildren() == null) + { + return; + } + + Map mouldToChild = getOptions(parent.getChildren()); + + int bestScore = -1; + Widget bestWidget = null; + CommisionType type1 = CommisionType.forVarbit(client.getVarbitValue(SWORD_TYPE_1_VARBIT)); + CommisionType type2 = CommisionType.forVarbit(client.getVarbitValue(SWORD_TYPE_2_VARBIT)); + for (Map.Entry entry : mouldToChild.entrySet()) { + Mould mould = entry.getKey(); + int score = mould.getScore(type1, type2); + if (score > bestScore) { + bestScore = score; + bestWidget = entry.getValue(); + } + } + if (bestWidget != null) { + bestWidget.setTextColor(GREEN); + } + + if (scriptId == DRAW_MOULD_LIST_SCRIPT || scriptId == REDRAW_MOULD_LIST_SCRIPT) + { + Widget scrollBar = client.getWidget(718, 11); + Widget scrollList = client.getWidget(718, 9); + if (scrollBar != null && scrollList != null) + { + int height = scrollList.getHeight(); + int scrollMax = scrollList.getScrollHeight(); + Widget finalBestWidget = bestWidget; + clientThread.invokeLater(() -> { + if (finalBestWidget != null) { + client.runScript( + ScriptID.UPDATE_SCROLLBAR, + scrollBar.getId(), + scrollList.getId(), + Math.min(finalBestWidget.getOriginalY() - 2, scrollMax - height)); + } + }); + } + } + } + + private Map getOptions(Widget[] children) { + Map mouldToChild = new LinkedHashMap<>(); + for (int i = 2; i < children.length; i += 17) + { + Widget child = children[i]; + Mould mould = Mould.forName(child.getText()); + if (mould != null && child.getTextColor() != DISABLED_TEXT_COLOR) { + mouldToChild.put(mould, child); + } + } + return mouldToChild; + } +} From 777e4fd36165cf0a36bb380d955e8910751d524c Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 02:45:41 +0400 Subject: [PATCH 3/8] Update authors --- runelite-plugin.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-plugin.properties b/runelite-plugin.properties index 0ef3afd..84e0aeb 100644 --- a/runelite-plugin.properties +++ b/runelite-plugin.properties @@ -1,5 +1,5 @@ displayName=Easy Giant's Foundry -author=Toofifty +author=Toofifty and Patrick support=https://github.com/Toofifty/easy-giantsfoundry description=Helpful overlays for the Giant's Foundry minigame tags=smithing,giant,foundry,giantsfoundry,minigame From cd000b68a794794d2e1134e3cba4050dea9b7ff3 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 02:45:59 +0400 Subject: [PATCH 4/8] Update version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 63fdf52..310b732 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ dependencies { } group = 'com.toofifty' -version = '1.0.0' +version = '1.0.1' sourceCompatibility = '1.8' tasks.withType(JavaCompile) { From 5632bc928d7085f9647beda367936cfb40ab29b1 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 23:56:49 +0400 Subject: [PATCH 5/8] Rename CommissionType --- .../java/com/toofifty/easygiantsfoundry/MouldHelper.java | 6 +++--- .../enums/{CommisionType.java => CommissionType.java} | 8 ++++---- .../java/com/toofifty/easygiantsfoundry/enums/Mould.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) rename src/main/java/com/toofifty/easygiantsfoundry/enums/{CommisionType.java => CommissionType.java} (55%) diff --git a/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java b/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java index 696c3d4..8b9cc1b 100644 --- a/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java +++ b/src/main/java/com/toofifty/easygiantsfoundry/MouldHelper.java @@ -1,6 +1,6 @@ package com.toofifty.easygiantsfoundry; -import com.toofifty.easygiantsfoundry.enums.CommisionType; +import com.toofifty.easygiantsfoundry.enums.CommissionType; import com.toofifty.easygiantsfoundry.enums.Mould; import net.runelite.api.Client; import net.runelite.api.ScriptID; @@ -40,8 +40,8 @@ public class MouldHelper int bestScore = -1; Widget bestWidget = null; - CommisionType type1 = CommisionType.forVarbit(client.getVarbitValue(SWORD_TYPE_1_VARBIT)); - CommisionType type2 = CommisionType.forVarbit(client.getVarbitValue(SWORD_TYPE_2_VARBIT)); + CommissionType type1 = CommissionType.forVarbit(client.getVarbitValue(SWORD_TYPE_1_VARBIT)); + CommissionType type2 = CommissionType.forVarbit(client.getVarbitValue(SWORD_TYPE_2_VARBIT)); for (Map.Entry entry : mouldToChild.entrySet()) { Mould mould = entry.getKey(); int score = mould.getScore(type1, type2); diff --git a/src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java b/src/main/java/com/toofifty/easygiantsfoundry/enums/CommissionType.java similarity index 55% rename from src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java rename to src/main/java/com/toofifty/easygiantsfoundry/enums/CommissionType.java index 43f5d47..5fec63f 100644 --- a/src/main/java/com/toofifty/easygiantsfoundry/enums/CommisionType.java +++ b/src/main/java/com/toofifty/easygiantsfoundry/enums/CommissionType.java @@ -1,6 +1,6 @@ package com.toofifty.easygiantsfoundry.enums; -public enum CommisionType { +public enum CommissionType { NONE, NARROW, // 1 LIGHT, // 2 @@ -10,12 +10,12 @@ public enum CommisionType { SPIKED, // 6 ; - public static final CommisionType[] values = CommisionType.values(); + public static final CommissionType[] values = CommissionType.values(); - public static CommisionType forVarbit(int varbitValue) { + public static CommissionType forVarbit(int varbitValue) { if (varbitValue < 0 || varbitValue >= values.length) { return NONE; } - return CommisionType.values[varbitValue]; + return CommissionType.values[varbitValue]; } } diff --git a/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java b/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java index b3c234a..41b2357 100644 --- a/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java +++ b/src/main/java/com/toofifty/easygiantsfoundry/enums/Mould.java @@ -5,7 +5,7 @@ import lombok.AllArgsConstructor; import java.util.Map; -import static com.toofifty.easygiantsfoundry.enums.CommisionType.*; +import static com.toofifty.easygiantsfoundry.enums.CommissionType.*; import static com.toofifty.easygiantsfoundry.enums.MouldType.*; @AllArgsConstructor @@ -47,7 +47,7 @@ public enum Mould { private final String name; private final MouldType mouldType; - private final Map typeToScore; + private final Map typeToScore; public static final Mould[] values = Mould.values(); @@ -60,7 +60,7 @@ public enum Mould { return null; } - public int getScore(CommisionType type1, CommisionType type2) { + public int getScore(CommissionType type1, CommissionType type2) { int score = 0; score += typeToScore.getOrDefault(type1, 0); score += typeToScore.getOrDefault(type2, 0); From 4262b18c00b36b51890fe5ebb89c9fe7eee96a1c Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 23:57:21 +0400 Subject: [PATCH 6/8] Revert "Update authors" This reverts commit 777e4fd36165cf0a36bb380d955e8910751d524c. --- runelite-plugin.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-plugin.properties b/runelite-plugin.properties index 84e0aeb..0ef3afd 100644 --- a/runelite-plugin.properties +++ b/runelite-plugin.properties @@ -1,5 +1,5 @@ displayName=Easy Giant's Foundry -author=Toofifty and Patrick +author=Toofifty support=https://github.com/Toofifty/easy-giantsfoundry description=Helpful overlays for the Giant's Foundry minigame tags=smithing,giant,foundry,giantsfoundry,minigame From e58c592becab444fc9ea7714d50c9fc2b0c6bfb8 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 9 Jun 2022 23:59:48 +0400 Subject: [PATCH 7/8] Update README.md with best mould feature --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab68253..1ccffb3 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ Helpful overlays for the Giant's Foundry minigame - Shows heat and progress as percentages - Shows number of actions required to move to the next stage -- Shows number of actions before gaining/losing too much heat \ No newline at end of file +- Shows number of actions before gaining/losing too much heat +- Shows best moulds to use \ No newline at end of file From 287dfd7c65ee256882aa9199bf5e8a2c6c872cdf Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 10 Jun 2022 00:02:45 +0400 Subject: [PATCH 8/8] Add contributors on README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ccffb3..ea60870 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,10 @@ Helpful overlays for the Giant's Foundry minigame - Shows heat and progress as percentages - Shows number of actions required to move to the next stage - Shows number of actions before gaining/losing too much heat -- Shows best moulds to use \ No newline at end of file +- Shows best moulds to use + + +## Contributors + +- [Patrick](https://github.com/pwatts6060 "Patrick's github") + * Best moulds interface feature