Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ nb-configuration.xml
nbproject/
public/**
/CreatePluginDocs.ps1
.worktrees/
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@Slf4j
public class FletchingPlugin extends Plugin {

public static final String version = "1.6.4";
public static final String version = "1.7.0";

@Inject
private FletchingConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class FletchingScript extends Script {
// The fletching interface widget group ID
private static final int FLETCHING_WIDGET_GROUP_ID = 17694736;

private static final String FLETCHING_KNIFE = "fletching knife";
private static final String KNIFE = "knife";

ProgressiveFletchingModel model = new ProgressiveFletchingModel();

String primaryItemToFletch = "";
Expand Down Expand Up @@ -68,7 +71,7 @@ public void run(FletchingConfig config) {

boolean hasRequirementsToFletch;
boolean hasRequirementsToBank;
primaryItemToFletch = fletchingMode.getItemName();
primaryItemToFletch = usesKnife() ? getPreferredKnife() : fletchingMode.getItemName();

if (fletchingMode == FletchingMode.PROGRESSIVE) {
secondaryItemToFletch = model.getFletchingMaterial().getLogItemName();
Expand Down Expand Up @@ -105,7 +108,11 @@ public void run(FletchingConfig config) {
}

private void bankItems(FletchingConfig config) {
Rs2Bank.openBank();
if (!Rs2Bank.isOpen()) {
if (!Rs2Bank.openBank()) {
return; // Bank didn't open, retry next iteration
}
}

// Deposit items based on the fletching mode
switch (fletchingMode) {
Expand All @@ -130,7 +137,9 @@ private void bankItems(FletchingConfig config) {
}

// Check if the primary item is available
if (!Rs2Bank.hasItem(primaryItemToFletch) && !Rs2Inventory.hasItem(primaryItemToFletch)) {
boolean hasPrimaryInBank = usesKnife() ? bankHasAnyKnife() : Rs2Bank.hasItem(primaryItemToFletch);
boolean hasPrimaryInInventory = usesKnife() ? hasAnyKnife() : Rs2Inventory.hasItem(primaryItemToFletch);
if (!hasPrimaryInBank && !hasPrimaryInInventory) {
Rs2Bank.closeBank();
Microbot.status = "[Shutting down] - Reason: " + primaryItemToFletch + " not found in the bank.";
Microbot.showMessage(Microbot.status);
Expand All @@ -139,12 +148,12 @@ private void bankItems(FletchingConfig config) {
}

// Ensure the inventory isn't full without the primary item
if (!Rs2Inventory.hasItem(primaryItemToFletch)) {
if (!hasPrimaryInInventory) {
Rs2Bank.depositAll();
}

// Withdraw the primary item if not already in the inventory
if (!Rs2Inventory.hasItem(primaryItemToFletch)) {
if (!hasPrimaryInInventory) {
Rs2Bank.withdrawX(primaryItemToFletch, fletchingMode.getAmount(), true);
}

Expand Down Expand Up @@ -181,7 +190,8 @@ private void bankItems(FletchingConfig config) {
}

// Final check to ensure both items are in the inventory
if (!Rs2Inventory.hasItem(primaryItemToFletch) || !Rs2Inventory.hasItem(secondaryItemToFletch)) {
boolean hasPrimaryFinal = usesKnife() ? hasAnyKnife() : Rs2Inventory.hasItem(primaryItemToFletch);
if (!hasPrimaryFinal || !Rs2Inventory.hasItem(secondaryItemToFletch)) {
Microbot.log("waiting for inventory changes.");
Rs2Inventory.waitForInventoryChanges(5000);
}
Expand All @@ -192,7 +202,8 @@ private void bankItems(FletchingConfig config) {


private void fletch(FletchingConfig config) {
Rs2Inventory.combineClosest(primaryItemToFletch, secondaryItemToFletch);
String itemToUse = usesKnife() ? getKnifeInInventory() : primaryItemToFletch;
Rs2Inventory.combineClosest(itemToUse, secondaryItemToFletch);
sleepUntil(() -> Rs2Widget.getWidget(FLETCHING_WIDGET_GROUP_ID) != null, 5000);
char option;
if (fletchingMode == FletchingMode.PROGRESSIVE || fletchingMode == FletchingMode.PROGRESSIVE_STRUNG) {
Expand All @@ -204,10 +215,11 @@ private void fletch(FletchingConfig config) {
Rs2Keyboard.keyPress(option);
}

Rs2Bank.preHover();

sleepUntil(() -> !Rs2Inventory.hasItem(secondaryItemToFletch), 60000);
Rs2Antiban.actionCooldown();
Rs2Antiban.takeMicroBreakByChance();
Rs2Bank.preHover();
}

private boolean configChecks(FletchingConfig config) {
Expand All @@ -219,6 +231,34 @@ private boolean configChecks(FletchingConfig config) {
return true;
}

private String getPreferredKnife() {
if (Rs2Inventory.hasItem(FLETCHING_KNIFE) || Rs2Bank.hasItem(FLETCHING_KNIFE)) {
return FLETCHING_KNIFE;
}
return KNIFE;
}

private boolean hasAnyKnife() {
return Rs2Inventory.hasItem(FLETCHING_KNIFE) || Rs2Inventory.hasItem(KNIFE);
}

private String getKnifeInInventory() {
if (Rs2Inventory.hasItem(FLETCHING_KNIFE)) {
return FLETCHING_KNIFE;
}
return KNIFE;
}

private boolean bankHasAnyKnife() {
return Rs2Bank.hasItem(FLETCHING_KNIFE) || Rs2Bank.hasItem(KNIFE);
}

private boolean usesKnife() {
return fletchingMode == FletchingMode.UNSTRUNG
|| fletchingMode == FletchingMode.UNSTRUNG_STRUNG
|| fletchingMode == FletchingMode.PROGRESSIVE;
}

public void calculateItemToFletch() {
int level = Microbot.getClient().getRealSkillLevel(Skill.FLETCHING);
FletchingItem item = null;
Expand Down
Loading