Because of this outer loop:
Code:
for (Item item : p.getInventory().getItems()) {

Originally Posted by
Stephanie98
So each action should have 5 items processed per cast, but should still work for 4,3,2,1 items but not 0. How come it's only choosing one item thats what I don't understand.
Something like this might be what you're after.
Code:
package io.ruin.model.skills.magic.spells.lunar;
import io.ruin.model.item.Item;
import io.ruin.model.skills.magic.Spell;
import io.ruin.model.skills.magic.rune.Rune;
import io.ruin.model.skills.magic.rune.RuneRemoval;
import io.ruin.model.stat.StatType;
public class TanLeather extends Spell{
private enum Leather {
COWHIDE(1739, 1743),
GREEN_DRAGONHIDE(1753, 1745),
BLUE_DRAGONHIDE(1751, 2505),
RED_DRAGONHIDE(1749, 2507),
BLACK_DRAGONHIDE(1747, 2509);
private int leather, hide;
Leather(int hide, int leather) {
this.hide = hide;
this.leather = leather;
}
private static final Map<Integer, Leather> LOOKUP;
static {
Map<Integer, Leather> $values = new HashMap<>();
for (Leather leather : values()) {
$values.put(leather.hide, leather);
}
LOOKUP = $values;
}
static Leather forId(int id) {
return LOOKUP.get(id);
}
}
private static final int AMOUNT_TO_TAN = 5;
public TanLeather() {
Item[] required = {
Rune.ASTRAL.toItem(2),
Rune.NATURE.toItem(1),
Rune.FIRE.toItem(5)
};
clickAction = p -> {
if (!p.getStats().check(StatType.Magic, 78, "cast this spell"))
return;
p.startEvent(e -> {
int count = AMOUNT_TO_TAN;
RuneRemoval runes = null;
for (Item item : p.getInventory().getItems()) {
if (item == null) {
continue;
}
Leather leather = Leather.forId(item.getId());
if (leather == null) {
continue;
}
if (runes == null && (removal = RuneRemoval.get(p, required)) == null) {
p.sendMessage("You don't have enough runes to cast this spell.");
break;
}
item.setId(leather.leather);
runes.remove();
p.animate(4413);
p.graphics(746, 96, 0);
p.publicSound(2879);
p.getStats().addXp(StatType.Magic, 81, true);
e.delay(3);
if (--count <= 0) {
break;
}
}
if (count == AMOUNT_TO_TAN) {
p.sendMessage("You don't have any leather to tan.");
}
});
};
}
}
P.S. you'll need to import the map classes.