I didn't see it anywhere (might be blind). So here y'all go.
AshScattering.java
Code:
package com.rs.game.player.content;
import java.util.HashMap;
import java.util.Map;
import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
import com.rs.utils.Utils;
/**
*
* @author Ronan & Arham 4 for improvements
*
*/
public class AshScattering {
public enum Ash {
IMPIOUS(20264, 4, new Graphics(56)),
ACCURSED(20266, 12.5, new Graphics(47)),
INFERNAL(20268, 62.5, new Graphics(40));
private int id;
private double experience;
private Graphics graphics;
private static Map<Integer, Ash> ashes = new HashMap<Integer, Ash>();
private static Ash[] values = values();
public static Ash[] valuesCached() {
return values;
}
static {
for (Ash ash : valuesCached()) {
ashes.put(ash.getId(), ash);
}
}
public static Ash forId(int id) {
return ashes.get(id);
}
private Ash(int id, double experience, Graphics graphics) {
this.id = id;
this.experience = experience;
this.graphics = graphics;
}
public int getId() {
return id;
}
public double getExperience() {
return experience;
}
public Graphics getGraphics() {
return graphics;
}
public static boolean Scatter(final Player player, int slotId) {
final Item item = player.getInventory().getItem(slotId);
if (item == null || Ash.forId(item.getId()) == null)
return false;
if (player.getAshDelay() > Utils.currentTimeMillis())
return true;
final Ash ash = Ash.forId(item.getId());
player.addStopDelay(3);
player.setNextAnimation(new Animation(445));
player.setNextGraphics(ash.getGraphics());
WorldTasksManager.schedule(new WorldTask() {
@Override
public void run() {
player.getInventory().deleteItem(item.getId(), 1);
player.getPackets().sendGameMessage(
"You scatter the ashes in the wind.");
player.getSkills()
.addXp(Skills.PRAYER, ash.getExperience());
stop();
}
}, 2);
return false;
}
}
}
Player.java
Code:
public long getAshDelay() {
return ashDelay;
}
public void addAshDelay(long time) {
ashDelay = time + Utils.currentTimeMillis();
}
private transient long ashDelay;
InventoryOptionsHandler.java
Code:
Ash ash = Ash.forId(itemId);
if (ash != null) {
Ash.Scatter(player, slotId);
return;
}
It's my first snippet tbh.
OT: Thanks to Arham 4 for improvements
.