-
-
Notifications
You must be signed in to change notification settings - Fork 497
feat(Rs2Cannon): Added pickup and start for cannon fix(Rs2Equipment): doInvoke with option and target #1579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||||||||||||||
| import net.runelite.api.TileObject; | ||||||||||||||||||||||||||||||||||||||
| import net.runelite.api.VarPlayer; | ||||||||||||||||||||||||||||||||||||||
| import net.runelite.api.coords.WorldArea; | ||||||||||||||||||||||||||||||||||||||
| import net.runelite.api.gameval.VarPlayerID; | ||||||||||||||||||||||||||||||||||||||
| import net.runelite.client.plugins.cannon.CannonPlugin; | ||||||||||||||||||||||||||||||||||||||
| import net.runelite.client.plugins.microbot.Microbot; | ||||||||||||||||||||||||||||||||||||||
| import net.runelite.client.plugins.microbot.util.inventory.Rs2Inventory; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -32,6 +33,7 @@ public static boolean repair() { | |||||||||||||||||||||||||||||||||||||
| Microbot.status = "Repairing Cannon"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Rs2GameObject.interact(brokenCannon, "Repair"); | ||||||||||||||||||||||||||||||||||||||
| sleepUntil(() -> !Rs2GameObject.exists(brokenCannon.getId()),5000); | ||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -72,4 +74,65 @@ public static boolean refill(int cannonRefillAmount) { | |||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public static boolean pickup() { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Microbot.status = "Picking up Cannon"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| TileObject cannon = Rs2GameObject.findObject(new Integer[]{ObjectID.DWARF_MULTICANNON, ObjectID.DWARF_MULTICANNON_43027}); | ||||||||||||||||||||||||||||||||||||||
| if (cannon == null) return false; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Create centered WorldArea (3x3 area with cannon at center) | ||||||||||||||||||||||||||||||||||||||
| WorldArea cannonLocation = new WorldArea( | ||||||||||||||||||||||||||||||||||||||
| cannon.getWorldLocation().getX() - 1, | ||||||||||||||||||||||||||||||||||||||
| cannon.getWorldLocation().getY() - 1, | ||||||||||||||||||||||||||||||||||||||
| 3, 3, | ||||||||||||||||||||||||||||||||||||||
| cannon.getWorldLocation().getPlane() | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| if (!cannonLocation.toWorldPoint().equals(CannonPlugin.getCannonPosition().toWorldPoint())) return false; | ||||||||||||||||||||||||||||||||||||||
| Microbot.pauseAllScripts.compareAndSet(false, true); | ||||||||||||||||||||||||||||||||||||||
| int attempts = 0; | ||||||||||||||||||||||||||||||||||||||
| while (Rs2GameObject.exists(cannon.getId()) && Rs2Inventory.emptySlotCount() >= 4 && attempts < 3){ | ||||||||||||||||||||||||||||||||||||||
| Rs2GameObject.interact(cannon, "Pick-up"); | ||||||||||||||||||||||||||||||||||||||
| sleepUntil(() -> !Rs2GameObject.exists(cannon.getId()),5000); | ||||||||||||||||||||||||||||||||||||||
| if(!Rs2GameObject.exists(cannon.getId())){ | ||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| attempts++; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| Microbot.pauseAllScripts.compareAndSet(true, false); | ||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
102
to
104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pickup() always returns true even if pickup failed. If attempts exhaust or not enough slots, the method still returns true. Return success based on the cannon actually disappearing. - Microbot.pauseAllScripts.compareAndSet(true, false);
- return true;
+ Microbot.pauseAllScripts.compareAndSet(true, false);
+ return !Rs2GameObject.exists(cannon.getId());📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public static boolean start() { | ||||||||||||||||||||||||||||||||||||||
| if (!Rs2Inventory.hasItemAmount("cannonball", 30, true)) { | ||||||||||||||||||||||||||||||||||||||
| //System.out.println("Not enough cannonballs!"); | ||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Microbot.status = "Starting up Cannon"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| TileObject cannon = Rs2GameObject.findObject(new Integer[]{ObjectID.DWARF_MULTICANNON, ObjectID.DWARF_MULTICANNON_43027}); | ||||||||||||||||||||||||||||||||||||||
| if (cannon == null) return false; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Create centered WorldArea (3x3 area with cannon at center) | ||||||||||||||||||||||||||||||||||||||
| WorldArea cannonLocation = new WorldArea( | ||||||||||||||||||||||||||||||||||||||
| cannon.getWorldLocation().getX() - 1, | ||||||||||||||||||||||||||||||||||||||
| cannon.getWorldLocation().getY() - 1, | ||||||||||||||||||||||||||||||||||||||
| 3, 3, | ||||||||||||||||||||||||||||||||||||||
| cannon.getWorldLocation().getPlane() | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| if (!cannonLocation.toWorldPoint().equals(CannonPlugin.getCannonPosition().toWorldPoint())) return false; | ||||||||||||||||||||||||||||||||||||||
| int attempts = 0; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+118
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same center-vs-corner mismatch in start(). The position check compares the area’s SW corner, not the center. WorldArea cannonLocation = new WorldArea(
cannon.getWorldLocation().getX() - 1,
cannon.getWorldLocation().getY() - 1,
3, 3,
cannon.getWorldLocation().getPlane()
);
- if (!cannonLocation.toWorldPoint().equals(CannonPlugin.getCannonPosition().toWorldPoint())) return false;
+ var sw = cannonLocation.toWorldPoint();
+ var center = new net.runelite.api.coords.WorldPoint(sw.getX() + 1, sw.getY() + 1, sw.getPlane());
+ if (!center.equals(CannonPlugin.getCannonPosition().toWorldPoint())) return false;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| while (Microbot.getClientThread().runOnClientThreadOptional(() -> Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 0 && attempts < 3){ | ||||||||||||||||||||||||||||||||||||||
| Microbot.log("Starting Cannon"); | ||||||||||||||||||||||||||||||||||||||
| Rs2GameObject.interact(cannon, "Fire"); | ||||||||||||||||||||||||||||||||||||||
| sleepUntil(()-> Microbot.getClientThread().runOnClientThreadOptional(() -> Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 1048576); | ||||||||||||||||||||||||||||||||||||||
| sleep(250); | ||||||||||||||||||||||||||||||||||||||
| if (Microbot.getClientThread().runOnClientThreadOptional(() -> Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 1048576){ | ||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| attempts++; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+126
to
+137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. start() lacks pause/unpause symmetry and early return inside loop complicates it. Other cannon ops pauseAllScripts; start() should too, without leaking the paused state. - int attempts = 0;
- while (Microbot.getClientThread().runOnClientThreadOptional(() -> Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 0 && attempts < 3){
- Microbot.log("Starting Cannon");
- Rs2GameObject.interact(cannon, "Fire");
- sleepUntil(()-> Microbot.getClientThread().runOnClientThreadOptional(() -> Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 1048576);
- sleep(250);
- if (Microbot.getClientThread().runOnClientThreadOptional(() -> Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 1048576){
- return true;
- }
- attempts++;
- }
- return false;
+ Microbot.pauseAllScripts.compareAndSet(false, true);
+ boolean started = false;
+ int attempts = 0;
+ while (Microbot.getClientThread().runOnClientThreadOptional(() ->
+ Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 0 && attempts < 3) {
+ Microbot.log("Starting Cannon");
+ Rs2GameObject.interact(cannon, "Fire");
+ sleepUntil(() -> Microbot.getClientThread().runOnClientThreadOptional(() ->
+ Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 1048576);
+ sleep(250);
+ started = Microbot.getClientThread().runOnClientThreadOptional(() ->
+ Microbot.getClient().getVarpValue(VarPlayerID.MCANNONMULTI)).orElse(0) == 1048576;
+ if (started) break;
+ attempts++;
+ }
+ Microbot.pauseAllScripts.compareAndSet(true, false);
+ return started;
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.