Jump to content

Conditional Combat Style Switcher


Recommended Posts

Posted (edited)

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
Posted

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
Posted (edited)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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