Refactored battlestaff crafting to follow authentic interfaces and timing
This commit is contained in:
@@ -1,122 +0,0 @@
|
||||
package content.global.skill.crafting;
|
||||
|
||||
/**
|
||||
* Represents a battlestave.
|
||||
* @author 'Vexia
|
||||
*/
|
||||
public enum BattleStaves {
|
||||
WATER(571, 1395, 54, 100, 215, 149),
|
||||
EARTH(575, 1399, 58, 112.5, 29415, 151),
|
||||
FIRE(569, 1393, 62, 125, 2153, 152),
|
||||
AIR(573, 1397, 66, 137.5, 2152, 150);
|
||||
|
||||
/**
|
||||
* The obelisk used.
|
||||
*/
|
||||
private final int obelisk;
|
||||
|
||||
/**
|
||||
* The product made.
|
||||
*/
|
||||
private final int product;
|
||||
|
||||
/**
|
||||
* The level needed to make the staff.
|
||||
*/
|
||||
private final int level;
|
||||
|
||||
/**
|
||||
* The exp gained.
|
||||
*/
|
||||
private final double exp;
|
||||
|
||||
/**
|
||||
* The object id.
|
||||
*/
|
||||
private final int objectId;
|
||||
|
||||
/**
|
||||
* The graphic id.
|
||||
*/
|
||||
private final int graphicId;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code BattleStaves} {@Code Object}
|
||||
* @param obelisk the obelisk.
|
||||
* @param product the product.
|
||||
* @param level the lever.
|
||||
* @param exp the experience.
|
||||
* @param objectId the id.
|
||||
* @param graphicId the id.
|
||||
*/
|
||||
BattleStaves(int obelisk, int product, int level, double exp, final int objectId, final int graphicId) {
|
||||
this.obelisk = obelisk;
|
||||
this.product = product;
|
||||
this.level = level;
|
||||
this.exp = exp;
|
||||
this.objectId = objectId;
|
||||
this.graphicId = graphicId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a battle stave by the id.
|
||||
* @param id the id.
|
||||
* @return the object.
|
||||
*/
|
||||
public static BattleStaves forId(int id) {
|
||||
for (BattleStaves staff : BattleStaves.values()) {
|
||||
if (staff.getObelisk() == id) {
|
||||
return staff;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the obelisk.
|
||||
* @return The obelisk.
|
||||
*/
|
||||
public int getObelisk() {
|
||||
return obelisk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the product.
|
||||
* @return The product.
|
||||
*/
|
||||
public int getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level.
|
||||
* @return The level.
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the objectId.
|
||||
* @return The objectId.
|
||||
*/
|
||||
public int getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the graphicId.
|
||||
* @return The graphicId.
|
||||
*/
|
||||
public int getGraphicId() {
|
||||
return graphicId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the exp.
|
||||
* @return The exp.
|
||||
*/
|
||||
public double getExp() {
|
||||
return exp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package content.global.skill.crafting
|
||||
|
||||
import core.api.*
|
||||
import core.game.interaction.IntType
|
||||
import core.game.interaction.InteractionListener
|
||||
import core.game.node.entity.player.link.diary.DiaryType
|
||||
import core.game.node.entity.skill.Skills
|
||||
import org.rs09.consts.Items
|
||||
import kotlin.math.min
|
||||
|
||||
class BattlestaffListener : InteractionListener {
|
||||
|
||||
private val battlestaff = Items.BATTLESTAFF_1391
|
||||
val orbs = BattlestaffProduct.values().map { it.requiredOrbItemId }.toIntArray()
|
||||
|
||||
override fun defineListeners() {
|
||||
onUseWith(IntType.ITEM, orbs, battlestaff) { player, used, with ->
|
||||
val product = BattlestaffProduct.productMap[used.id] ?: return@onUseWith true
|
||||
|
||||
if (!hasLevelDyn(player, Skills.CRAFTING, product.minimumLevel)) {
|
||||
sendMessage(player, "You need a Crafting level of ${product.minimumLevel} to make this.")
|
||||
return@onUseWith true
|
||||
}
|
||||
|
||||
// Avoids sending dialogue if only one can be created
|
||||
if (amountInInventory(player, used.id) == 1 || amountInInventory(player, with.id) == 1) {
|
||||
|
||||
if (removeItem(player, product.requiredOrbItemId) && removeItem(player, Items.BATTLESTAFF_1391)) {
|
||||
addItem(player, product.producedItemId, product.amountProduced)
|
||||
rewardXP(player, Skills.CRAFTING, product.experience)
|
||||
}
|
||||
|
||||
if (product.producedItemId == Items.AIR_BATTLESTAFF_1397) {
|
||||
player.achievementDiaryManager.finishTask(player, DiaryType.VARROCK, 2, 6)
|
||||
}
|
||||
|
||||
return@onUseWith true
|
||||
}
|
||||
|
||||
sendSkillDialogue(player) {
|
||||
withItems(product.producedItemId)
|
||||
create { _, amount ->
|
||||
|
||||
runTask(player, 2, amount) {
|
||||
if (amount < 1) return@runTask
|
||||
|
||||
if (removeItem(player, product.requiredOrbItemId) && removeItem(player, Items.BATTLESTAFF_1391)) {
|
||||
addItem(player, product.producedItemId, product.amountProduced)
|
||||
rewardXP(player, Skills.CRAFTING, product.experience)
|
||||
}
|
||||
|
||||
if (product.producedItemId == Items.AIR_BATTLESTAFF_1397) {
|
||||
player.achievementDiaryManager.finishTask(player, DiaryType.VARROCK, 2, 6)
|
||||
} else return@runTask
|
||||
}
|
||||
}
|
||||
|
||||
calculateMaxAmount { _ ->
|
||||
min(amountInInventory(player, with.id), amountInInventory(player, used.id))
|
||||
}
|
||||
}
|
||||
|
||||
return@onUseWith true
|
||||
}
|
||||
}
|
||||
|
||||
enum class BattlestaffProduct(
|
||||
val requiredOrbItemId: Int,
|
||||
val producedItemId: Int,
|
||||
val amountProduced: Int,
|
||||
val minimumLevel: Int,
|
||||
val experience: Double,
|
||||
) {
|
||||
WATER_BATTLESTAFF(Items.WATER_ORB_571, Items.WATER_BATTLESTAFF_1395, 1, 54, 100.0),
|
||||
EARTH_BATTLESTAFF(Items.EARTH_ORB_575, Items.EARTH_BATTLESTAFF_1399, 1, 58, 112.5),
|
||||
FIRE_BATTLESTAFF(Items.FIRE_ORB_569, Items.FIRE_BATTLESTAFF_1393, 1, 62, 125.0),
|
||||
AIR_BATTLESTAFF(Items.AIR_ORB_573, Items.AIR_BATTLESTAFF_1397, 1, 66, 137.5);
|
||||
|
||||
companion object {
|
||||
val productMap = HashMap<Int, BattlestaffProduct>()
|
||||
|
||||
init {
|
||||
for (product in BattlestaffProduct.values()) {
|
||||
productMap[product.requiredOrbItemId] = product
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package content.global.skill.crafting;
|
||||
|
||||
import core.game.node.entity.player.link.diary.DiaryType;
|
||||
import core.game.node.entity.skill.Skills;
|
||||
import core.game.interaction.NodeUsageEvent;
|
||||
import core.game.interaction.UseWithHandler;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
import core.plugin.Initializable;
|
||||
import core.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Represents the battle stave making plugin used for zaff.
|
||||
* @author 'Vexia
|
||||
* @version 1.0
|
||||
*/
|
||||
@Initializable
|
||||
public final class BattlestaveMakePlugin extends UseWithHandler {
|
||||
|
||||
/**
|
||||
* Represents the original staff item.
|
||||
*/
|
||||
private static final Item STAFF = new Item(1391, 1);
|
||||
|
||||
/**
|
||||
* Constructs a new {@code BattlestaveMakePlugin} {@code Object}.
|
||||
*/
|
||||
public BattlestaveMakePlugin() {
|
||||
super(STAFF.getId(), 573, 571, 575, 569);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
addHandler(573, ITEM_TYPE, this);
|
||||
addHandler(571, ITEM_TYPE, this);
|
||||
addHandler(575, ITEM_TYPE, this);
|
||||
addHandler(569, ITEM_TYPE, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(NodeUsageEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (event.getUsedItem().getId() != STAFF.getId()) {
|
||||
return false;
|
||||
}
|
||||
int id = event.getUsedItem().getId() == STAFF.getId() ? event.getUsedWith().getId() : event.getUsedItem().getId();
|
||||
final BattleStaves staff = BattleStaves.forId(id);
|
||||
if (staff == null)
|
||||
return true;
|
||||
if (player.getSkills().getLevel(Skills.CRAFTING) < staff.getLevel()) {
|
||||
player.getPacketDispatch().sendMessage("You need a crafting level of " + staff.getLevel() + " to make this.");
|
||||
return true;
|
||||
}
|
||||
player.getInventory().remove(STAFF);
|
||||
player.getInventory().remove(new Item(staff.getObelisk(), 1));
|
||||
player.getInventory().add(new Item(staff.getProduct(), 1));
|
||||
player.getSkills().addExperience(Skills.CRAFTING, staff.getExp(), true);
|
||||
// Craft an air battlestaff
|
||||
if (staff == BattleStaves.AIR) {
|
||||
player.getAchievementDiaryManager().finishTask(player, DiaryType.VARROCK, 2, 6);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user