Merge branch 'dumpcontainer-fix-kt' into 'master'
Fix hang when depositing inventory or equipped items See merge request 2009scape/2009scape!281
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
package core.game.content.dialogue;
|
||||
|
||||
import core.game.container.Container;
|
||||
import core.game.container.impl.BankContainer;
|
||||
import core.game.container.impl.EquipmentContainer;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.plugin.Initializable;
|
||||
import core.game.node.item.Item;
|
||||
import core.plugin.Plugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents the dialogue plugin used to handle the deposit all/deposit inventory/etc button
|
||||
* @author Splinter
|
||||
*/
|
||||
@Initializable
|
||||
public final class DumpContainer extends DialoguePlugin {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code DumpContainer} {@code Object}.
|
||||
*/
|
||||
public DumpContainer() {
|
||||
/**
|
||||
* empty.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code DumpBOBDialogue} {@code Object}.
|
||||
* @param player the player.
|
||||
*/
|
||||
public DumpContainer(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialoguePlugin newInstance(Player player) {
|
||||
return new DumpContainer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open(Object... args) {
|
||||
options("Deposit Inventory", "Deposit Equipment", "Deposit Beast of Burden", "Cancel");
|
||||
stage = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(int interfaceId, int buttonId) {
|
||||
if (stage == 0) {
|
||||
switch (buttonId) {
|
||||
case 1:
|
||||
if (player.getInventory().isEmpty()) {
|
||||
player.getPacketDispatch().sendMessage("You have nothing to deposit.");
|
||||
return true;
|
||||
} else {
|
||||
dump(player.getInventory());
|
||||
}
|
||||
end();
|
||||
break;
|
||||
case 2:
|
||||
if (player.getEquipment().isEmpty()) {
|
||||
player.getPacketDispatch().sendMessage("You have nothing to deposit.");
|
||||
return true;
|
||||
} else {
|
||||
dump(player.getEquipment());
|
||||
}
|
||||
end();
|
||||
break;
|
||||
case 3:
|
||||
player.getFamiliarManager().dumpBob();
|
||||
end();
|
||||
break;
|
||||
case 4:
|
||||
end();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIds() {
|
||||
return new int[] { 628371 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a container.
|
||||
* @param inventory the player's inventory.
|
||||
* @author ceik
|
||||
*/
|
||||
public void dump(Container inventory) {
|
||||
BankContainer bank = player.getBank();
|
||||
Arrays.stream(inventory.toArray()).filter(Objects::nonNull).forEach(item -> {
|
||||
if(!bank.hasSpaceFor(item)){
|
||||
player.getPacketDispatch().sendMessage("You have no more space in your bank.");
|
||||
return;
|
||||
}
|
||||
if(!bank.canAdd(item)){
|
||||
player.getPacketDispatch().sendMessage("A magical force prevents you from banking your " + item.getName() + ".");
|
||||
} else {
|
||||
if(inventory instanceof EquipmentContainer){
|
||||
Object pluginobj = item.getDefinition().getHandlers().get("equipment");
|
||||
if(pluginobj != null && pluginobj instanceof Plugin){
|
||||
Plugin<Item> plugin = (Plugin<Item>) pluginobj;
|
||||
plugin.fireEvent("unequip",player,item);
|
||||
}
|
||||
}
|
||||
inventory.remove(item);
|
||||
bank.add(item.getDefinition().isUnnoted() ? item : new Item(item.getNoteChange(), item.getAmount()));
|
||||
}
|
||||
});
|
||||
inventory.update();
|
||||
bank.update();
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import core.game.world.update.flag.context.Animation;
|
||||
import core.plugin.Initializable;
|
||||
import core.plugin.Plugin;
|
||||
import kotlin.Unit;
|
||||
import rs09.game.content.dialogue.DumpContainer;
|
||||
import rs09.game.ge.GrandExchangeOffer;
|
||||
import rs09.game.world.GameWorld;
|
||||
|
||||
@@ -325,7 +326,7 @@ public final class BankingPlugin extends OptionHandler {
|
||||
case 762:
|
||||
switch (button) {
|
||||
case 18:
|
||||
p.getDialogueInterpreter().open(628371);
|
||||
p.getDialogueInterpreter().open(new DumpContainer().getID());
|
||||
return true;
|
||||
case 23:
|
||||
p.getDialogueInterpreter().sendOptions("Select an Option", "Check bank value", "Banking assistance", "Close");
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package rs09.game.content.dialogue
|
||||
|
||||
import core.game.container.Container
|
||||
import core.game.container.impl.EquipmentContainer
|
||||
import core.game.content.dialogue.DialoguePlugin
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.Item
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
|
||||
@Initializable
|
||||
/**
|
||||
* Represents the dialogue plugin used to handle the deposit all/deposit inventory/etc button
|
||||
* @author Splinter
|
||||
* @author James Triantafylos
|
||||
*/
|
||||
class DumpContainer(player: Player? = null) : DialoguePlugin(player) {
|
||||
val ID = 628371
|
||||
|
||||
override fun newInstance(player: Player?): DialoguePlugin {
|
||||
return DumpContainer(player)
|
||||
}
|
||||
|
||||
override fun open(vararg args: Any?): Boolean {
|
||||
options("Deposit Inventory", "Deposit Equipment", "Deposit Beast of Burden", "Cancel")
|
||||
return true
|
||||
}
|
||||
|
||||
override fun handle(interfaceId: Int, buttonId: Int): Boolean {
|
||||
when (buttonId) {
|
||||
1 -> {
|
||||
if (player.inventory.isEmpty) {
|
||||
player.packetDispatch.sendMessage("You have nothing in your inventory to deposit.")
|
||||
} else {
|
||||
dump(player.inventory)
|
||||
}
|
||||
}
|
||||
2 -> {
|
||||
if (player.equipment.isEmpty) {
|
||||
player.packetDispatch.sendMessage("You have no equipment to deposit.")
|
||||
} else {
|
||||
dump(player.equipment)
|
||||
}
|
||||
}
|
||||
3 -> {
|
||||
player.familiarManager.dumpBob()
|
||||
}
|
||||
4 -> {
|
||||
}
|
||||
}
|
||||
end()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getIds(): IntArray {
|
||||
return intArrayOf(ID)
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a container.
|
||||
* @param inventory the player's inventory.
|
||||
* @author ceik
|
||||
* @author James Triantafylos
|
||||
*/
|
||||
fun dump(inventory: Container) {
|
||||
val bank = player.bank
|
||||
for (item: Item in inventory.toArray().filterNotNull()) {
|
||||
if (!bank.hasSpaceFor(item)) {
|
||||
player.packetDispatch.sendMessage("You have no more space in your bank.")
|
||||
return
|
||||
}
|
||||
if (!bank.canAdd(item)) {
|
||||
player.packetDispatch.sendMessage("A magical force prevents you from banking your " + item.name + ".")
|
||||
} else {
|
||||
if (inventory is EquipmentContainer) {
|
||||
val plugin = item.definition.handlers["equipment"]
|
||||
if (plugin != null && plugin is Plugin<*>) {
|
||||
plugin.fireEvent("unequip", player, item)
|
||||
}
|
||||
}
|
||||
inventory.remove(item)
|
||||
bank.add(if (item.definition.isUnnoted) item else Item(item.noteChange, item.amount))
|
||||
}
|
||||
}
|
||||
inventory.update()
|
||||
bank.update()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user