Repository reorganisation
Unified kotlin and java into just src/main Unified the rs09 and core packages Took all content out of the core package, and placed it into the new content package Reorganised all source code relating to content to be easier to find and explore
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package content.global.skill.firemaking
|
||||
|
||||
import core.game.node.item.GroundItem
|
||||
import org.rs09.consts.Items
|
||||
import core.game.interaction.InteractionListener
|
||||
import core.game.interaction.IntType
|
||||
|
||||
class FiremakingListener : InteractionListener
|
||||
{
|
||||
val logs = intArrayOf(1511, 1521, 1513, 1515, 1517, 1519, 2862, 3438, 3440, 3442, 3444, 3446, 3448, 6211, 6213, 6332, 6333, 7404, 7405, 7406, 8934, 9067, 10328, 10329, 10808, 10810, 10812, 11035, 12581, 12583, 3125)
|
||||
|
||||
override fun defineListeners() {
|
||||
onUseWith(IntType.ITEM, Items.TINDERBOX_590, *logs) { player, _, with ->
|
||||
player.pulseManager.run(FireMakingPulse(player, with.asItem(), null))
|
||||
return@onUseWith true
|
||||
}
|
||||
onUseWith(IntType.GROUNDITEM, Items.TINDERBOX_590, *logs) { player, _, with ->
|
||||
player.pulseManager.run(FireMakingPulse(player, with.asItem(), with as GroundItem))
|
||||
return@onUseWith true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package content.global.skill.firemaking;
|
||||
|
||||
import core.game.event.LitFireEvent;
|
||||
import core.game.node.entity.skill.SkillPulse;
|
||||
import core.game.node.entity.skill.Skills;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.GroundItem;
|
||||
import core.game.node.item.GroundItemManager;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.node.scenery.Scenery;
|
||||
import core.game.node.scenery.SceneryBuilder;
|
||||
import core.game.world.GameWorld;
|
||||
import core.game.world.map.RegionManager;
|
||||
import core.game.world.update.flag.context.Animation;
|
||||
import core.game.world.update.flag.player.FaceLocationFlag;
|
||||
import core.tools.RandomFunction;
|
||||
|
||||
/**
|
||||
* Represents the pulse used to light a log.
|
||||
* @author 'Vexia
|
||||
*/
|
||||
public final class FireMakingPulse extends SkillPulse<Item> {
|
||||
|
||||
/**
|
||||
* Represents the animation to use.
|
||||
*/
|
||||
private static final Animation ANIMATION = new Animation(733);
|
||||
|
||||
/**
|
||||
* Represents the tinderbox item.
|
||||
*/
|
||||
private static final Item TINDERBOX = new Item(590);
|
||||
|
||||
/**
|
||||
* Represents the log being burned.
|
||||
*/
|
||||
private final Log fire;
|
||||
|
||||
/**
|
||||
* Represents the ground item.
|
||||
*/
|
||||
private GroundItem groundItem;
|
||||
|
||||
/**
|
||||
* Represents the ticks.
|
||||
*/
|
||||
private int ticks;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FireMaking}.
|
||||
* @param player the player.
|
||||
* @param node the node.
|
||||
* @param groundItem the ground item if not null.
|
||||
*/
|
||||
public FireMakingPulse(Player player, Item node, GroundItem groundItem) {
|
||||
super(player, node);
|
||||
this.fire = Log.forId(node.getId());
|
||||
if (groundItem == null) {
|
||||
this.groundItem = new GroundItem(node, player.getLocation(), player);
|
||||
player.setAttribute("remove-log", true);
|
||||
} else {
|
||||
this.groundItem = groundItem;
|
||||
player.removeAttribute("remove-log");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkRequirements() {
|
||||
if (fire == null) {
|
||||
return false;
|
||||
}
|
||||
if (RegionManager.getObject(player.getLocation()) != null || player.getZoneMonitor().isInZone("bank")) {
|
||||
player.getPacketDispatch().sendMessage("You can't light a fire here.");
|
||||
return false;
|
||||
}
|
||||
if (!player.getInventory().containsItem(TINDERBOX)) {
|
||||
player.getPacketDispatch().sendMessage("You do not have the required items to light this.");
|
||||
return false;
|
||||
}
|
||||
if (player.getSkills().getLevel(Skills.FIREMAKING) < fire.getLevel()) {
|
||||
player.getPacketDispatch().sendMessage("You need a firemaking level of " + fire.getLevel() + " to light this log.");
|
||||
return false;
|
||||
}
|
||||
if (player.getAttribute("remove-log", false)) {
|
||||
player.removeAttribute("remove-log");
|
||||
if (player.getInventory().remove(node)) {
|
||||
GroundItemManager.create(groundItem);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reward() {
|
||||
if (getLastFire() >= GameWorld.getTicks()) {
|
||||
createFire();
|
||||
return true;
|
||||
}
|
||||
if (ticks == 0) {
|
||||
player.animate(ANIMATION);
|
||||
}
|
||||
if (++ticks % 3 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (ticks % 12 == 0) {
|
||||
player.animate(ANIMATION);
|
||||
}
|
||||
if (!success()) {
|
||||
return false;
|
||||
}
|
||||
createFire();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the fire.
|
||||
*/
|
||||
public void createFire() {
|
||||
if (!groundItem.isActive()) {
|
||||
return;
|
||||
}
|
||||
// GameObject originalOnSpot =
|
||||
// RegionManager.getObject(player.getLocation());
|
||||
final Scenery object = new Scenery(fire.getFireId(), player.getLocation());
|
||||
SceneryBuilder.add(object, fire.getLife(), getAsh(player, fire, object));
|
||||
GroundItemManager.destroy(groundItem);
|
||||
player.moveStep();
|
||||
player.faceLocation(FaceLocationFlag.getFaceLocation(player, object));
|
||||
player.getSkills().addExperience(Skills.FIREMAKING,fire.getXp());
|
||||
|
||||
int playerRegion = player.getViewport().getRegion().getId();
|
||||
|
||||
setLastFire();
|
||||
player.dispatch(new LitFireEvent(fire.getLogId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(int type) {
|
||||
String name = node.getId() == 3125 ? "bones" : "logs";
|
||||
switch (type) {
|
||||
case 0:
|
||||
player.getPacketDispatch().sendMessage("You attempt to light the " + name + "..");
|
||||
break;
|
||||
case 1:
|
||||
player.getPacketDispatch().sendMessage("The fire catches and the " + name + " begin to burn.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last firemake.
|
||||
* @return the tick.
|
||||
*/
|
||||
public int getLastFire() {
|
||||
return player.getAttribute("last-firemake", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last fire.
|
||||
*/
|
||||
public void setLastFire() {
|
||||
player.setAttribute("last-firemake", GameWorld.getTicks() + 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ground item ash.
|
||||
* @param object the object.
|
||||
* @return {@code GroundItem} the itemm.
|
||||
*/
|
||||
public static GroundItem getAsh(final Player player, Log fire, final Scenery object) {
|
||||
final GroundItem ash = new GroundItem(new Item(592), object.getLocation(), player);
|
||||
ash.setDecayTime(fire.getLife() + 200);
|
||||
return ash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player gets rewarded.
|
||||
* @return {@code True} if so.
|
||||
*/
|
||||
private boolean success() {
|
||||
int level = 1 + player.getSkills().getLevel(Skills.FIREMAKING);
|
||||
double req = fire.getLevel();
|
||||
double successChance = Math.ceil((level * 50 - req * 15) / req / 3 * 4);
|
||||
int roll = RandomFunction.random(99);
|
||||
if (successChance >= roll) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package content.global.skill.firemaking;
|
||||
|
||||
import core.cache.def.impl.ItemDefinition;
|
||||
import core.game.interaction.OptionHandler;
|
||||
import core.game.node.Node;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.GroundItem;
|
||||
import core.game.node.item.Item;
|
||||
import core.plugin.Initializable;
|
||||
import core.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Represents the plugin used to light a log.
|
||||
* @author 'Vexia
|
||||
* @version 1.0
|
||||
*/
|
||||
@Initializable
|
||||
public final class LightLogPlugin extends OptionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(Player player, Node node, String option) {
|
||||
player.getPulseManager().run(new FireMakingPulse(player, ((Item) node), ((GroundItem) node)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
ItemDefinition.setOptionHandler("light", this);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package content.global.skill.firemaking;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Represents an enumeration of burnable logs.
|
||||
* @author 'Vexia
|
||||
*/
|
||||
public enum Log {
|
||||
NORMAL(1511, 1, 180, 2732, 40),
|
||||
ACHEY(2862, 1, 180, 2732, 40),
|
||||
OAK(1521, 15, 200, 2732, 60),
|
||||
WILLOW(1519, 30, 250, 2732, 90),
|
||||
TEAK(6333, 35, 300, 2732, 105),
|
||||
ARCTIC_PINE(10810, 42, 500, 2732, 125),
|
||||
MAPLE(1517, 45, 300, 2732, 135),
|
||||
MAHOGANY(6332, 50, 300, 2732, 157.5),
|
||||
EUCALYPTUS(12581, 58, 300, 2732, 193.5),
|
||||
YEW(1515, 60, 400, 2732, 202.5),
|
||||
MAGIC(1513, 75, 450, 2732, 303.8),
|
||||
CURSED_MAGIC(13567, 82, 650, 2732, 303.8),
|
||||
PURPLE(10329, 1, 200, 20001, 50),
|
||||
WHITE(10328, 1, 200, 20000, 50),
|
||||
BLUE(7406, 1, 200, 11406, 50),
|
||||
GREEN(7405, 1, 200, 11405, 50),
|
||||
RED(7404, 1, 200, 11404, 50),
|
||||
JOGRE(3125, 1, 200, 3862, 50);
|
||||
|
||||
public static HashMap<Integer,Log> logMap = new HashMap<>();
|
||||
static{
|
||||
Log[] logArray = Log.values();
|
||||
int logLength = logArray.length;
|
||||
for(int i = 0; i < logLength; i++){
|
||||
Log log = logArray[i];
|
||||
logMap.putIfAbsent(log.logId,log);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The log id.
|
||||
*/
|
||||
private final int logId;
|
||||
|
||||
/**
|
||||
* The level.
|
||||
*/
|
||||
private final int level;
|
||||
|
||||
/**
|
||||
* The life.
|
||||
*/
|
||||
private final int life;
|
||||
|
||||
/**
|
||||
* The fire id.
|
||||
*/
|
||||
private final int fireId;
|
||||
|
||||
/**
|
||||
* The exp gained.
|
||||
*/
|
||||
private final double xp;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FireMakingDefinitions.java} {@code Object}.
|
||||
* @param logId the log id.
|
||||
* @param level the level.
|
||||
* @param life the life.
|
||||
* @param fireId the fire id.
|
||||
* @param xp the experience.
|
||||
*/
|
||||
Log(int logId, int level, int life, int fireId, double xp) {
|
||||
this.logId = logId;
|
||||
this.level = level;
|
||||
this.life = life;
|
||||
this.fireId = fireId;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the logId.
|
||||
* @return The logId.
|
||||
*/
|
||||
public int getLogId() {
|
||||
return logId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level.
|
||||
* @return The level.
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the life.
|
||||
* @return The life.
|
||||
*/
|
||||
public int getLife() {
|
||||
return life;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fireId.
|
||||
* @return The fireId.
|
||||
*/
|
||||
public int getFireId() {
|
||||
return fireId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the xp.
|
||||
* @return The xp.
|
||||
*/
|
||||
public double getXp() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the log by the id.
|
||||
* @param id the id.
|
||||
* @return the log.
|
||||
*/
|
||||
public static Log forId(int id) {
|
||||
return logMap.get(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user