Refactored item note/unnote on bank booth handling

QoL - only applies to bank booth, not banker NPCs
Added server config world.bank_booth_note_enabled (enabled by default) to toggle the QoL globally
Added server config world.bank_booth_note_uim (enabled by default) to toggle the QoL on ultimate ironmen only
This commit is contained in:
vddcore
2022-06-27 14:06:47 +00:00
committed by Ryan
parent d38f7d4282
commit ee5bc78b62
6 changed files with 53 additions and 174 deletions
@@ -1,114 +0,0 @@
package core.game.interaction.item.withobject;
import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.Node;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.IronmanMode;
import core.game.node.item.Item;
import core.game.world.map.Direction;
import core.game.world.map.Location;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* Handles the unnoting of noted items when used on a bank booth.
* @author Vexia
* @author Splinter
*/
@Initializable
public class BankUnnotePlugin extends UseWithHandler {
/**
* The bank booth ids.
*/
private static final int[] BOOTHS = new int[] { 2213, 3194, 5276, 6084, 10517, 11338, 11402, 11758, 12309, 12798, 14367, 16700, 18491, 19230, 20325, 20391, 22819, 24914, 25808, 26972, 27663, 28514, 29085, 30016, 34752, 35647, 36786 };
/**
* The banker ids,
*/
private static final int[] BANKERS = new int[] { 44, 45, 494, 495, 496, 497, 498, 499, 953, 1036, 1360, 2163, 2164, 2354, 2355, 2568, 2569, 2570, 3198, 3199, 3824, 5258, 5260, 5776, 5777, 5912, 5913, 6200, 6532, 6533, 6534, 6535, 6538, 7445, 7446, 7605 };
/**
* Constructs a new {@Code BankUnnotePlugin} {@Code Object}
*/
public BankUnnotePlugin() {
super();
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
for (int id : BOOTHS) {
addHandler(id, OBJECT_TYPE, this);
}
for (int id : BANKERS) {
addHandler(id, NPC_TYPE, this);
}
return this;
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
final Item item = event.getUsedItem();
if (!player.isAdmin() && (player.getIronmanManager().getMode() == IronmanMode.NONE || item.getDefinition().isUnnoted())) {
return false;
}
if (item.getDefinition().isStackable() && item.getDefinition().isUnnoted()) {
player.getPacketDispatch().sendMessage("You can't note stackable items.");
return true;
}
int amount = item.getAmount();
if (amount > player.getInventory().freeSlots()) {
amount = 28 - player.getInventory().freeSlots();
}
if (amount < 1 || player.getInventory().freeSlots() <= 0) {
player.sendMessage("Not enough inventory space.");
return true;
}
if (player.getInventory().freeSlots() >= amount) {
if (player.getInventory().remove(new Item(item.getId(), amount))) {
Item newItem = new Item(item.getNoteChange(), amount);
player.getInventory().add(newItem);
player.getDialogueInterpreter().sendItemMessage(newItem, "You exchange your noted items.");
player.lock(1);
return true;
}
} else {
int toAdd = player.getInventory().freeSlots();
if (player.getInventory().remove(new Item(item.getId(), toAdd))) {
Item newItem = new Item(item.getNoteChange(), toAdd);
player.getInventory().add(newItem);
player.getDialogueInterpreter().sendItemMessage(newItem, "You exchange your noted items.");
player.lock(1);
return true;
}
}
return false;
}
@Override
public Location getDestination(Player player, Node with) {
if (with instanceof NPC) {
NPC npc = (NPC) with;
if (npc.getAttribute("facing_booth", false)) {
Direction dir = npc.getDirection();
return npc.getLocation().transform(dir.getStepX() << 1, dir.getStepY() << 1, 0);
}
if (npc.getId() == 6533) {
return Location.create(3167, 3490, 0);// ge bankers.
} else if (npc.getId() == 6535) {
return Location.create(3162, 3489, 0);
} else if (npc.getId() == 4907) {
return npc.getLocation().transform(0, -2, 0);
}
}
return null;
}
@Override
public boolean isDynamic() {
return true;
}
}
@@ -16,7 +16,6 @@ import core.net.packet.PacketRepository;
import core.net.packet.context.PlayerContext;
import core.net.packet.out.ClearMinimapFlag;
import org.rs09.consts.Items;
import rs09.game.interaction.ItemOnBankBooth;
import rs09.game.interaction.InteractionListeners;
import rs09.game.node.entity.skill.farming.CompostBins;
import rs09.game.node.entity.skill.farming.FarmingPatch;
@@ -234,10 +233,7 @@ public class ItemActionPacket implements IncomingPacket {
if(PluginInteractionManager.handle(player,event)){
return;
}
if(object.getName().toLowerCase().contains("bank booth")){
new ItemOnBankBooth().handle(event);
return;
}
try {
UseWithHandler.run(event);
} catch (Exception e){
@@ -113,6 +113,12 @@ class ServerConstants {
@JvmField
var BANK_BOOTH_QUICK_OPEN: Boolean = false
@JvmField
var BANK_BOOTH_NOTE_ENABLED: Boolean = true
@JvmField
var BANK_BOOTH_NOTE_UIM: Boolean = true
@JvmField
var GE_AUTOSAVE_FREQUENCY = secondsToTicks(3600) //1 hour
@@ -1,54 +0,0 @@
package rs09.game.interaction
import core.game.interaction.DestinationFlag
import core.game.interaction.MovementPulse
import core.game.interaction.NodeUsageEvent
import core.game.interaction.UseWithHandler
import core.game.node.item.Item
import core.plugin.Plugin
class ItemOnBankBooth : UseWithHandler(0) {
override fun handle(event: NodeUsageEvent?): Boolean {
event ?: return false
val player = event.player
player.pulseManager.run(object : MovementPulse(player, event.usedWith, DestinationFlag.OBJECT) {
override fun pulse(): Boolean {
return handleNote(event)
}
}, "movement")
return true
}
fun handleNote(event: NodeUsageEvent?): Boolean {
event ?: return false
val item = event.usedItem
val player = event.player
if (item.noteChange != item.id) {
if (item.definition.isUnnoted) {
val amount = player.inventory.getAmount(item.id)
player.inventory.remove(Item(item.id, amount))
player.inventory.add(Item(item.noteChange, amount))
} else {
var amount = item.amount
if (amount > player.inventory.freeSlots()) {
amount = player.inventory.freeSlots()
}
player.inventory.remove(Item(item.id, amount))
player.inventory.add(Item(item.noteChange, amount))
}
return true
} else {
player.sendMessage("This item can't be noted.")
return true
}
}
override fun newInstance(arg: Any?): Plugin<Any> {
return this
}
override fun nodeAllowed(nodeId: Int): Boolean {
return true
}
}
@@ -1,11 +1,12 @@
package rs09.game.interaction.`object`
import api.openDialogue
import api.*
import core.game.content.dialogue.DialogueInterpreter
import core.game.node.Node
import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import core.game.node.entity.player.link.IronmanMode
import core.game.node.item.Item
import core.game.world.map.Direction
import core.game.world.map.Location
import org.rs09.consts.NPCs
@@ -127,9 +128,51 @@ class BankBoothHandler : InteractionListener {
return true
}
private fun attemptToConvertItems(player: Player, used: Node, with: Node): Boolean {
if (!ServerConstants.BANK_BOOTH_NOTE_UIM && player.ironmanManager.checkRestriction(IronmanMode.ULTIMATE)) {
return true
}
if (BankerNPC.checkLunarIsleRestriction(player, with)) {
tryInvokeBankerDialogue(player, with)
return true
}
val item = used as Item
if (item.noteChange != item.id) {
if (item.definition.isUnnoted) {
val amount = amountInInventory(player, item.id)
if (removeItem(player, Item(item.id, amount))) {
addItem(player, item.noteChange, amount)
}
} else {
var amount = item.amount
val freeSlotCount = freeSlots(player)
if (amount > freeSlotCount) {
amount = freeSlotCount
}
if (removeItem(player, Item(item.id, amount))) {
addItem(player, item.noteChange, amount)
}
}
return true
}
sendMessage(player, "This item can't be noted.")
return true
}
override fun defineListeners() {
on(BANK_BOOTHS, SCENERY, "use-quickly", "bank", handler = ::quickBankBoothUse)
on(BANK_BOOTHS, SCENERY, "use", handler = ::regularBankBoothUse)
on(BANK_BOOTHS, SCENERY, "collect", handler = ::collectBankBoothUse)
if (ServerConstants.BANK_BOOTH_NOTE_ENABLED) {
onUseAnyWith(SCENERY, *BANK_BOOTHS, handler = ::attemptToConvertItems)
}
}
}
@@ -118,6 +118,8 @@ object ServerConfigParser {
ServerConstants.PRELOAD_MAP = data.getBoolean("server.preload_map", false)
ServerConstants.REVENANT_POPULATION = data.getLong("world.revenant_population", 30L).toInt()
ServerConstants.BANK_BOOTH_QUICK_OPEN = data.getBoolean("world.bank_booth_quick_open", false)
ServerConstants.BANK_BOOTH_NOTE_ENABLED = data.getBoolean("world.bank_booth_note_enabled", true)
ServerConstants.BANK_BOOTH_NOTE_UIM = data.getBoolean("world.bank_booth_note_uim", true)
ServerConstants.DISCORD_GE_WEBHOOK = data.getString("server.discord_webhook", "")
}