Sanity 435 Posted September 28, 2017 Report Share Posted September 28, 2017 I wanted to release my version of the firemaking skill, it may not be the best but its a script i felt happy enough to release to the public, it has clipped lighting to you can't walk into walls / unwanted places, it has all the log types (Excluding redwood) and has their exp, time to live, and log ids for convenience, the clipping order is West, East, South, North, and the chances that you burn a log was taken from arios' code so if anyone has the mathmatics for that i can add it on. It has checks to make sure the log hasn't been picked up and if it has it will halt all action and reward no experience. ashs on ground also work, and will be there for 60 seconds (should be there for the logs time to live + 200 ticks correct me if im wrong), if anyone has constructive critisim they can post below, pls no flamming if certain areas of the code are bad or can be improved, thanks everyone Start off by defining this in SkillsManager.java private int lastFireTime; and give its getters and setters public int getLastFireTime() { return lastFireTime; } public void setLastFireTime(int lastFireTime) { this.lastFireTime = lastFireTime; } now define Firemaking.java and place in package of choice package com.elvarg.world.content.skills.firemaking; import com.elvarg.GameConstants; import com.elvarg.engine.task.Task; import com.elvarg.engine.task.TaskManager; import com.elvarg.world.entity.impl.object.GameObject; import com.elvarg.world.entity.impl.object.ObjectHandler; import com.elvarg.world.entity.impl.player.Player; import com.elvarg.world.grounditems.GroundItemManager; import com.elvarg.world.model.Animation; import com.elvarg.world.model.GroundItem; import com.elvarg.world.model.Item; import com.elvarg.world.model.PlayerRights; import com.elvarg.world.model.Position; import com.elvarg.world.model.Skill; import com.elvarg.world.model.movement.MovementStatus; /** * The Firemaking class. * @author Oscar Morton <"S C A P E" on Rune-Server> * */ public class Firemaking { /** * The player */ Player player; /** * The log on the ground */ GroundItem groundlog; /** * The log with the data */ LogData log; /** * The fire object */ GameObject fire; /** * Ticks */ int ticks = 0; /** * Firemaking animation */ Animation ANIMATION = new Animation(733); /** * A ground item for the ash */ GroundItem ash; /** * The Original position */ Position OriginalPosition; /** * The light method to light the log, this is basicly the main method, i should spread it all out a bit. * Thats for you guys though :P * @param player the player whos lighting the log. * @param log the log thats getting lit on fire. */ public Firemaking(Player player, LogData log) { this.player = player; this.log = log; /** * Checks if you have even got the right firemaking level to light the log. */ if (player.getSkillManager().getCurrentLevel(Skill.FIREMAKING) < log.getLevel()) { player.getPacketSender().sendMessage("You need a firemaking level of " + log.getLevel() + " to light this."); return; } if (ObjectHandler.objectExists(player.getPosition())) { player.getPacketSender().sendMessage("You can't light a fire here."); return; } /** * Checks if they lit a log .5 ticks ago. */ if (System.currentTimeMillis() - player.getSkillManager().getLastFireTime()<(GameConstants.GAME_ENGINE_PROCESSING_CYCLE_RATE/2)) { return; } /** * Checks if the player has a tinderbox since the last time that the game checked. */ if (!player.getInventory().contains(new Item(590,1))) { player.getPacketSender().sendMessage("You need a tinderbox to light a fire."); return; } /** * The log that gets placed on the ground while the animation goes on. */ groundlog = new GroundItem(new Item(log.getLog()), player.getPosition(), player.getUsername(),player.getHostAddress(),false,5000,false,5000); GroundItemManager.add(groundlog, true);//Adds the log player.performAnimation(ANIMATION);//Plays the lighting animation player.getPacketSender().sendMessage("You attempt to light the logs.");//sends a message to the player //telling them they start to light. player.getInventory().delete(new Item(log.getLog()));//gets rid of the log in the inventory. fire = new GameObject(log.getFire(), player.getPosition());//makes the fire gameobject something. OriginalPosition = player.getPosition(); TaskManager.submit(new Task(1) {//submits a new task taking 1 game tick to perform and wont end until certain conditions are met. @Override protected void execute() { ticks++; if (groundlog == null || groundlog.hasBeenPickedUp() || player.getPosition() != OriginalPosition) { player.performAnimation(Animation.DEFAULT_RESET_ANIMATION); this.stop(); return; } if (ticks == 0) { player.performAnimation(ANIMATION); } if (++ticks % 3 != 0) { return; } if (ticks % 12 == 0) { player.performAnimation(ANIMATION); } if (!success()) { return; } createFire();//creates the fire this.stop(); return; } }); } private boolean success() {//checks the success, script taken from arios. int level = 1 + player.getSkillManager().getCurrentLevel(Skill.FIREMAKING); double hostRatio = Math.random() * log.getLevel(); double clientRatio = Math.random() * ((level - log.getLevel()) * (1 + (log.getLevel() * 0.01))); return hostRatio < clientRatio && !groundlog.hasBeenPickedUp(); } public void createFire() {//creates the fire TaskManager.submit(new Task(1) {//task taking 1 game tick to start @Override protected void execute() { if (groundlog.hasBeenPickedUp() != true) { player.getSkillManager().setLastFireTime(System.currentTimeMillis()); ObjectHandler.spawnGlobalObject(fire); player.performAnimation(Animation.DEFAULT_RESET_ANIMATION); if (player.getMovementQueue().canWalk(1, 0)) { player.getMovementQueue().walkStep(1, 0); } else { if (player.getMovementQueue().canWalk(-1, 0)) { player.getMovementQueue().walkStep(-1, 0); } else { if (player.getMovementQueue().canWalk(0, -1)) { player.getMovementQueue().walkStep(0, -1); } else { if (player.getMovementQueue().canWalk(0,1)) { player.getMovementQueue().walkStep(0, 1); } } } } player.setPositionToFace(fire.getPosition()); GroundItemManager.remove(groundlog, true); player.getSkillManager().addExperience(Skill.FIREMAKING, (int)log.getExperience() * (int)GameConstants.EXP_MULTIPLIER); if (player.getRights() == PlayerRights.DEVELOPER) { player.getPacketSender().sendMessage("[DEBUG]: You have lighten a log at ["+fire.getPosition()+"]."); } player.getPacketSender().sendMessage("You light a fire."); player.getMovementQueue().setMovementStatus(MovementStatus.NONE); ash = new GroundItem(new Item(592), fire.getPosition(), player.getUsername(),player.getHostAddress(),false,100,false,100); TaskManager.submit(new Task((int)log.getLife()) { @Override protected void execute() { ObjectHandler.despawnGlobalObject(fire); if (player.getRights() == PlayerRights.DEVELOPER) { player.getPacketSender().sendMessage("[DEBUG]: Your log at ["+fire.getPosition()+"] has despawned."); } ash(); this.stop(); return; } }); this.stop(); return; } } }); } public void ash() { GroundItemManager.add(ash, true); TaskManager.submit(new Task((100),false) { @Override protected void execute() { GroundItemManager.remove(ash, true); this.stop(); return; } }); return; } } and LogData.java package com.elvarg.world.content.skills; /** * Represents all our log data, for the firemaking skill. * @author Oscar Morton <S C A P E on RuneServer> * */ public enum LogData { LOG(1511, 1, 40, 26185,180), Achey_LOG(2862, 1, 40, 26185,180), OAK_LOG(1521, 15, 60, 26185,200), WILLOW_LOG(1519, 30, 90, 26185,300), TEAK_LOG(6333, 35, 105, 26185,450), ARCTIC_PINE_LOG(10810, 42, 125, 26185,500), MAPLE_LOG(1517, 45, 135, 26185,400), MAHOGANY_LOG(6332, 50, 157.5, 26185,400), YEW_LOG(1515, 60, 202.5, 26185,202.5), MAGIC_LOG(1513, 75, 303.8, 26185,303.8), BLUE_LOG(7406, 1, 250, 26576,180), GREEN_LOG(7405, 1, 250, 26575,180), RED_LOG(7404, 1, 250, 26186,180), WHITE_LOG(10328, 1, 250, 20000,180), PURPLE_LOG(10329, 1, 250, 20001,180); private int log; private int level; private double exp; private int fire; private double life; private LogData(int log, int level, double exp, int fire,double life) { this.log = log; this.level = level; this.exp = exp; this.fire = fire; this.life = life; } public double getLife() { return life; } public void setLife(double life) { this.life = life; } public int getLog() { return log; } public int getLevel() { return level; } public double getExperience() { return exp; } public int getFire() { return fire; } } and finally add this bit of code into your UseItemPacketListener.java for (final LogData log : LogData.values()) { if ((used.getId() == 590 && usedWith.getId() == log.getLog()) || (used.getId() == log.getLog() && usedWith.getId() == 590)) { new Firemaking(player,log); } } here is some footage while in game Link to comment Share on other sites More sharing options...
kennstro 1 Posted December 19, 2018 Report Share Posted December 19, 2018 thanks for this. Link to comment Share on other sites More sharing options...
LeakedMania 0 Posted March 22, 2019 Report Share Posted March 22, 2019 Amazing release dude. Link to comment Share on other sites More sharing options...
Ary3x 0 Posted February 14, 2022 Report Share Posted February 14, 2022 very nice! will use Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now