这里出了什么问题?
错误:
java.lang.ArrayIndexOutOfBoundsException: 1
at com.rs.game.player.content.SlayerTask.getNewTask(SlayerTask.java:81)
SlayerTask.java的第81行:
this.currentTaskAmount = amount[Utils.random(low_tasks.length - 1)];
它反映的是:
this.currentTaskAmount = -2;
如果需要,总代码: 包com.rs.game.player.content;
import java.io.Serializable;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.utils.Utils;
import com.rs.game.npc.*;
public class SlayerTask implements Serializable {
private static final long serialVersionUID = -3885979679549716755L;
private transient static int[] low_tasks = { // 1 - 60
1648, //crawling hand - slay lvl 1 || Slayer Tower
1600, //cave crawler - slay lvl 10 || Fremmy dung
1612, //banshee - - slay lvl 15 || Slayer Tower
1632, //rockslug - - slay lvl 20 || Fremmy dung
1616, //basilisk - - slay lvl 40 || Fremmy dung
1640, 1637, //jelly - slay lvl 52 || Fremmy dung, Slayer Tower
1633 //Pyrefiend || Fremmy dung
};
private transient static int[] mid_tasks = {
1605, //abarrant spectre - slay lvl 60 || Slayer Tower
//dust devil - slay lvl 65 || Fremmy dung
//jungle strykewyrm - slay lvl 73 || Fremmy dung
1610, //gargoyle - slay lvl 75 || Fremmy dung
1627, //turoth || Fremmy dung
1609, //kurask || Fremmy dung
1643, //infernal mage || Fremmy dung
6215 // bloodveld || Slayer Tower
};
private transient static int[] high_tasks = {
//desert strykewyrm - slay lvl 77
1613, //nechryael - slay lvl 80 || Slayer Tower
1615, //abyssal demon - slay lvl 85 || Slayer Tower
//grifolapine - slay lvl 88
2783, //dark beast - slay lvl 90 || Slayer Tower
//ice strykewyrm - slay lvl 93
//ganodermic creatures - slay lvl 95
};
private transient static int[] amount = { 1};
private int currentTask = -1;
private int currentTaskAmount = 0;
private transient Player player;
public void setPlayer(Player player) {
this.player = player;
}
public void resetTask() {
this.currentTask = -1;
this.currentTaskAmount = -2;
}
public String getName() {
return NPCDefinitions.getNPCDefinitions(currentTask).getName();
}
public void getNewTask() {
if (player.getSkills().getLevel(Skills.SLAYER) >= 1 && player.getSkills().getLevel(Skills.SLAYER) <= 59) {
this.currentTask = low_tasks[Utils.random(low_tasks.length - 1)];
this.currentTaskAmount = amount[Utils.random(low_tasks.length - 1)];
player.getPackets().sendGameMessage("59<= Slayer level >= 1");
}
if (player.getSkills().getLevel(Skills.SLAYER) >= 60 && player.getSkills().getLevel(Skills.SLAYER) <= 76) {
this.currentTask = mid_tasks[Utils.random(mid_tasks.length - 1)];
this.currentTaskAmount = amount[Utils.random(mid_tasks.length - 1)];
player.getPackets().sendGameMessage("76<= Slayer level >= 60");
}
if (player.getSkills().getLevel(Skills.SLAYER) >= 77) {
this.currentTask = high_tasks[Utils.random(high_tasks.length - 1)];
this.currentTaskAmount = amount[Utils.random(high_tasks.length - 1)];
player.getPackets().sendGameMessage("Slayer level >= 77");
}
}
public int getCurrentTask() {
return currentTask;
}
public int getTaskAmount() {
return currentTaskAmount;
}
public void decreaseTask() {
this.currentTaskAmount--;
}
public boolean isComplete() {
return currentTaskAmount < 1;
}
public SlayerTask() {
}
}
我无法在谷歌上找到任何可以理解的内容。有人可以帮助我,这将是伟大的。
答案 0 :(得分:2)
您已在此处声明了长度为1的数组:
private transient static int[] amount = { 1};
但是,根据您的异常消息,您已传入1
的索引,该索引无效。唯一对此数组有效的索引是0
。
将数组修改为更长时间,或修改指数计算,使其不会产生1
。
答案 1 :(得分:0)
试试这个:
this.currentTask = (lowTasks.length > 1) ?
low_tasks[Utils.random(low_tasks.length - 1)] : lowTasks[0];