Well first you could do so much more with that difficulty enum, it could store the minimum and maximum amount of the task you get at that difficulty or even the slayer levels you must be around to get that task (so people with 99 slayer don't get men as a slayer task)
Also, you have a ton of static methods in the slayer class in which you pass in player, this is a good indication that you should probably instantiate the player class inside the Player consructor and store Slayer related variables inside the Slayer class
I.e. player.getSlayer().getSlayerPoints(); in which you can store slayerPoints, kills left, AND slayertask (which you'd save by index - plus you could remove all those getters inside SlayerTask). I mean just looking at it logically "slayerKills" sure is a member of Player but it is also a member of Slayer and can be grouped together with other slayer variables (also can be modified locally without all these getters (personally i'd split the enum and class) - i.e. you're having to do things like player.setSlayerKills when you really cold just be doing player.getSlayer().handleKill(npc) and it can do all the great logic stuff for you (also with easy access to all relevant variables - player's task, killAmount ect)
Code:
public class SlayerHolder {
private int taskAmount, totalTasks, slayerPoints;
/**
* SlayerHolder that they have, save the index
*/
private SlayerTask task;
public boolean assignTask(final int slayerLevel) {
if(taskAmount > 0)
return false;
task = SlayerTask.forLevel(slayerLevel);
taskAmount = task.getDifficulty().getAmount();
return true;
}
public int killedTask(final int npcid) {
if(task == null) return 0;
if(isTask(npcid)) {
if(--taskAmount == 0) {
totalTasks++;
slayerPoints += task.getDifficulty().getSlayerPoints() + handleTotalTasks();
}
return task.getXP();
}
return 0;
}
public boolean isTask(final int npcId) {
return task != null && task.getIds().contains(npcId) && taskAmount > 0;
}
public boolean resetTask() {
if(slayerPoints < 20)
return false;
slayerPoints -= 20;
taskAmount = 0;
return true;
}
//omitted
and something like
Code:
public enum SlayerTask {
/** The elite tasks */
GENERAL_GRAARDOR(27, Difficulty.ELITE, 1, 1100, 6260),
/** The hard tasks */
BLACK_DEMON(4,Difficulty.HARD, 1, 170,
84),
GORAK(5, Difficulty.HARD, 68, 120,
6218),
//omitted
private final Difficulty difficulty;
private final int slayerLevel, slayerXP, index; //might want to base slayerXp on npc combat level since multiple support
private final List<Integer> ids = new ArrayList<>();
private static final int EXP_MULTIPLIER = 14;
private SlayerTask(final int index,final Difficulty difficulty, final int slayerLevel, final int slayerXP, final int... ids) {
this.difficulty = difficulty;
this.slayerLevel = slayerLevel;
this.slayerXP = slayerXP * EXP_MULTIPLIER;
this.index = index;
for(int i : ids)
this.ids.add(i
);
}
public Difficulty getDifficulty() { return difficulty; }
public List<Integer> getIds() { return ids; }
public int getXP() { return slayerXP; }
public int getId() { return index; }
public static SlayerTask forLevel(final int slayerLevel) {
final SlayerTask task = values()[Misc.random(values().length - 1)];
if(slayerLevel >= task.slayerLevel && Math.abs(slayerLevel - task.difficulty.slayerLevel) <= 25) //ensure task is not too easy and they have the level for it
return task;
else return forLevel(slayerLevel);
}
static enum Difficulty {
EASY(10, 40, 0, 4),
MEDIUM(20, 80, 26, 6),
DIFFICULT(40, 100, 50, 7),
HARD(60, 150, 75, 8),
ELITE(5, 10, 99, 8);
private final int minAmount, maxAmount, slayerLevel, slayerPoints;
private Difficulty(final int minAmount, final int maxAmount, final int slayerLevel, final int slayerPoints) {
this.minAmount = minAmount;
this.maxAmount = maxAmount;
this.slayerLevel = slayerLevel;
this.slayerPoints = slayerPoints;
}
public int getAmount() {
return minAmount + Misc.random(maxAmount - minAmount);
}
public int getSlayerPoints() {
return slayerPoints;
}
}
@Override public String toString() {
return TextUtils.titleCase(super.toString().replaceAll("_", " ").toLowerCase());
}
//omitted
But you see how you don't have to actually call any methods from player to accomplish this?
Now this is the way it was done by me personally (even though I don't support every single piece of code its easier to stick with what's there)
Code:
@Override
public boolean clickObject(final Player player, final int type, final int npcId, final int slot, final int objId, final int a) {
if(type == ClickType.EAT) { //slayer gem
player.sendMessage("You have "+player.getSlayer().getTaskAmount()+ " "+player.getSlayer().getTask()+" npcs left to kill",
"You have "+player.getSlayer().getSlayerPoints()+" slayer points",
"You have completed "+player.getSlayer().getTotalTasks()+ " tasks");
return true;
}
if(type == ClickType.NPC_OPTION1) { // talk to slayer masker
DialogueManager.openDialogue(player, 174);
return true;
}
if(type == ClickType.NPC_DEATH) {
int slayerXP = player.getSlayer().killedTask(npcId);
if(slayerXP > 0) {
ContentEntity.addSkillXP(player, slayerXP, Skills.SLAYER);
if(player.getSlayer().getTaskAmount() == 0) {
player.sendf("You have completed %d tasks in a row and have %d slayer points", player.getSlayer().getTotalTasks(),player.getSlayer().getSlayerPoints());
}
}
return false;
}
//omitted