Originally Posted by
Andys1814
private final Firemaking firemaking = new Firemaking(this);
player.getFiremaking().createFire()
which is what most servers do
and if you mean you should just do "new Firemaking(player)" in the item on item packet listener, then he should just use a skill action system from the start lol
I get what you're saying, he is creating a new "Firemaking" object for each player, when;
The skill data belongs to the player, but the actions and methods of a skill however do not, so this could be done in a static context
where the player entity does not take ownership of the entire object we create and the methods they do not need ownership of.
I currently have it handled statically myself.
Code:
public class Firemaking {
public static void lightFire(final Player player, final Item item, final double experience, final int fireTimer) {
final GroundItem logs = new GroundItem(new Item(item.getId()),
player.getPosition(), player.getUsername(), player.getHostAddress(), false, 150, true, 120);
final GroundItem ashes = new GroundItem(SkillConstants.ASHES,
player.getPosition(), player.getUsername(), player.getHostAddress(), false, 150, true, 120);
final GameObject fire = new GameObject(5249, player.getPosition(), 10, 0, fireTimer) {
@Override
public void onDespawn() {
GroundItemManager.spawnGroundItem(player, ashes);
}
};
player.getMovementQueue().reset().setMovementStatus(MovementStatus.DISABLED);
player.performAnimation(SkillConstants.LIGHT_FIRE_ANIMATION);
player.getInventory().delete(item, item.getSlot());
GroundItemManager.spawnGroundItem(player, logs);
player.getAttributes().skillAnimationTimer.start(8);
player.getAttributes().setPerformingSkill(true);
TaskManager.submit(new Task(1, player, true) {
@Override
public void execute() {
final int level = player.getSkills().getMaxLevel(Skill.FIREMAKING);
final int differential = (level > 20 ? level / 10 : 1);
if (!isRunning())
stop();
if (player.getAttributes().skillAnimationTimer.finished()) {
player.getPacketSender().sendMessage("You failed to light the fire.");
player.getMovementQueue().setMovementStatus(MovementStatus.NONE);
stop();
}
if (Misc.inclusive(0, differential) == differential && !player.getAttributes().skillAnimationTimer.finished()) {
GroundItemManager.remove(logs, true);
ObjectHandler.spawnGlobalObject(fire);
player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
player.getMovementQueue().setMovementStatus(MovementStatus.NONE);
player.getSkills().addExperience(Skill.FIREMAKING, (int)(experience * 1.2));
MovementQueue.stepAway(player);
stop();
}
}
@Override
public void stop() {
player.getAttributes().finishSkillInteraction();
setEventRunning(false);
return;
}
});
}
}
There's only 1 other method in the class, but I feel its unique, so I don't really wanna post it
Other than that, just needs a better way of handling the ratio of which the player fails to light a log.
Obviously, yunno, like lower levels fail more frequently, and so on.
I just have it cheap-fixed with a random calculation for now.