CombatStyles: support for magic

UtilsScript: fix equipment check on equip()
This commit is contained in:
illumineawake 2021-07-25 16:56:08 +10:00
parent ee08f02d38
commit 0a36afb613
6 changed files with 46 additions and 10 deletions

View File

@ -23,7 +23,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
version = "4.2.8"
version = "4.2.9"
project.extra["PluginName"] = "iUtils"
project.extra["PluginDescription"] = "Illumine - Utils required for plugins to function with added automation"

View File

@ -5,7 +5,7 @@ import net.runelite.client.plugins.iutils.game.iPlayer;
import java.util.Arrays;
import java.util.stream.Stream;
public class PlayerStream extends ActorStream<iPlayer, PlayerStream> { // todo
public class PlayerStream extends ActorStream<iPlayer, PlayerStream> {
public PlayerStream(Stream<iPlayer> stream) {
super(stream);
}
@ -22,4 +22,12 @@ public class PlayerStream extends ActorStream<iPlayer, PlayerStream> { // todo
public PlayerStream withIndex(int... indices) {
return filter(n -> Arrays.stream(indices).anyMatch(index -> n.index() == index));
}
/**
* Returns a stream consisting of the elements of this stream with
* any of the given {@link iPlayer#index()}s
*/
public PlayerStream withoutIndex(int... indices) {
return filter(n -> Arrays.stream(indices).anyMatch(index -> n.index() != index));
}
}

View File

@ -54,6 +54,9 @@ public class CombatStyles {
case DEFENSIVE:
game.widget(593, 16).interact(0);
break;
case MAGIC:
game.widget(593, 26).interact(0);
return;
}
game.waitUntil(() -> currentStyle() == style);
game.openInterface(3);

View File

@ -44,6 +44,8 @@ public abstract class UtilsScript extends Plugin {
protected Prayers prayers;
@Inject
protected Injector injector;
@Inject
protected Bank bank;
protected void equip(int... ids) {
obtain(Arrays.stream(ids)
@ -54,6 +56,9 @@ public abstract class UtilsScript extends Plugin {
game.tick(2);
game.inventory().withId(ids).forEach(i -> {
if (equipment.isEquipped(i.id()))
return;
log.info("Equipping: {}", i.name());
i.interact(1);
game.tick(2);
@ -106,15 +111,26 @@ public abstract class UtilsScript extends Plugin {
}
protected void obtain(List<ItemQuantity> items) {
ItemQuantity[] itemArray = items.toArray(ItemQuantity[]::new);
if (hasItems(itemArray)) {
if (items.isEmpty() || hasItems(items)) {
return;
}
obtainBank(itemArray);
withdraw(itemArray);
game.tick(2);
bank().close();
game.tick(2);
obtain(items.toArray(ItemQuantity[]::new));
}
protected void obtain(List<ItemQuantity> items, boolean keepInventoryItems) {
if (items.isEmpty() || hasItems(items)) {
return;
}
if (keepInventoryItems) {
items.addAll(game.inventory().all().stream()
.map(i -> new ItemQuantity(i.id(), i.quantity()))
.collect(Collectors.toList())
);
log.info("Keeping items: {}", items.toString());
}
obtain(items.toArray(ItemQuantity[]::new));
}
protected void withdraw(ItemQuantity... items) {
@ -179,6 +195,15 @@ public abstract class UtilsScript extends Plugin {
return !any;
}
protected boolean hasItems(List<ItemQuantity> items) {
for (var item : items) {
if (equipment.quantity(item.id) < item.quantity && game.inventory().withId(item.id).quantity() < item.quantity) {
return false;
}
}
return true;
}
protected boolean hasItems(ItemQuantity... items) {
for (var item : items) {
if (equipment.quantity(item.id) < item.quantity && game.inventory().withId(item.id).quantity() < item.quantity) {

File diff suppressed because one or more lines are too long