Jump to content

Conditional Combat Style Switcher


luciuspragg

Recommended Posts

Here's a simple method that will change combat styles using whatever conditions you want, just call the method and pass it an enum of type style corresponding to what you want to switch to:

enum style {
	ATTACK, DEFENSE, STRENGTH;
}
public void combatSwitch(style changeStyle) {
	switch (changeStyle) {
	case ATTACK:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 3).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 0;
					}
				}.sleep();
			}
		}
		break;

	case STRENGTH:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 7).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 1;
					}
				}.sleep();
			}
		}
		break;
		
	case DEFENSE:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 15).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 3;
					}
				}.sleep();
			}
		}
		break;
	}
}

Example usage: 

//checking if strength is a certain level
if (skills.getDynamic(Skill.STRENGTH) < 40 && getConfigs().get(43) != 1) {
	changeStyle = style.STRENGTH;
	combatSwitch(changeStyle);
}

Hope this is of help to somebody!

Kudos to @ProjectPact and @HeyImJamie for the suggestions.

Edited by luciuspragg
Link to comment
Share on other sites

Looks good, but may I suggest making it a more 'universal' method? I've edited slightly on here so there may be a few errors etc, but this gives you an idea. This way instead of editing the method everytime to edit it to your combat style, you can just select which style you want. You could even make an AttackStyle enum for readability, rather than using ints.

public boolean switchCombatStyle(int combatStyle) {
	int style = getConfigs().get(43);
	if (combatStyle == style) {
		return true;
	}

	switch (combatStyle) {
	case 0:
	RS2Widget attButton = getWidgets().get(593, 3);
	if (attButton != null && getTabs().open(Tab.ATTACK)) {
		if (attButton.interact()) {
			// sleep until style equals desired.
		}
	}
	break;

	case 1:
	RS2Widget strButton = getWidgets().get(593, 7);
	etc
	break;

	case 2:
	break;

	case 3:
	RS2Widget defButton = getWidgets().get(593, 15);
	etc
	break;
	}

	return combatStyle == getConfgs().get(43);
}

 

  • Like 1
  • Heart 1
Link to comment
Share on other sites

I had originally written it as a standalone one task thing instead of a more universal method so I decided to go ahead and take both of your suggestions into account:

public void combatSwitch(style changeStyle) {
	switch (changeStyle) {
	case ATTACK:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 3).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 0;
					}
				}.sleep();
			}
		}
		break;

	case STRENGTH:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 7).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 1;
					}
				}.sleep();
			}
		}
		break;
		
	case DEFENSE:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 15).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 3;
					}
				}.sleep();
			}
		}
		break;
	}
}

Using:

enum style {
	ATTACK, DEFENSE, STRENGTH;
}

Thanks again for the suggestions!

Edited by luciuspragg
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...