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:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,117 @@
|
||||
package core.game.container;
|
||||
|
||||
import core.game.node.item.Item;
|
||||
|
||||
/**
|
||||
* Represents a container event.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class ContainerEvent {
|
||||
|
||||
/**
|
||||
* Represents a null item.
|
||||
*/
|
||||
public static final Item NULL_ITEM = new Item(0, 0);
|
||||
|
||||
/**
|
||||
* The array of changed items.
|
||||
*/
|
||||
private final Item[] items;
|
||||
|
||||
/**
|
||||
* Clears the container.
|
||||
*/
|
||||
private boolean clear;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code ContainerEvent} {@code Object}.
|
||||
* @param size The container size.
|
||||
*/
|
||||
public ContainerEvent(int size) {
|
||||
this.items = new Item[size];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags a null item on the given slot.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public void flagNull(int slot) {
|
||||
items[slot] = NULL_ITEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags an item on the given slot.
|
||||
* @param slot The slot.
|
||||
* @param item The item.
|
||||
*/
|
||||
public void flag(int slot, Item item) {
|
||||
items[slot] = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of item slots changed.
|
||||
* @return The amount of item slots that have changed.
|
||||
*/
|
||||
public int getChangeCount() {
|
||||
int count = 0;
|
||||
for (Item item : items) {
|
||||
if (item != null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the updated slots.
|
||||
* @return The slots array.
|
||||
*/
|
||||
public int[] getSlots() {
|
||||
int size = 0;
|
||||
int[] slots = new int[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null) {
|
||||
slots[size++] = i;
|
||||
}
|
||||
}
|
||||
int[] slot = new int[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
slot[i] = slots[i];
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the items.
|
||||
* @return The items.
|
||||
*/
|
||||
public Item[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags an empty container.
|
||||
*/
|
||||
public void flagEmpty() {
|
||||
this.clear = true;
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the clear.
|
||||
* @return The clear.
|
||||
*/
|
||||
public boolean isClear() {
|
||||
return clear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the clear flag.
|
||||
* @param clear The container is cleared.
|
||||
*/
|
||||
public void setClear(boolean clear) {
|
||||
this.clear = clear;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package core.game.container;
|
||||
|
||||
/**
|
||||
* Represents a container listener.
|
||||
* @author Emperor
|
||||
*/
|
||||
public interface ContainerListener {
|
||||
|
||||
/**
|
||||
* Updates the changed item slots in the container.
|
||||
* @param c The container we're listening to.
|
||||
* @param event The container event.
|
||||
*/
|
||||
void update(Container c, ContainerEvent event);
|
||||
|
||||
/**
|
||||
* Updates the entire container.
|
||||
* @param c The container.
|
||||
*/
|
||||
void refresh(Container c);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package core.game.container;
|
||||
|
||||
/**
|
||||
* Represents the container types.
|
||||
* @author Emperor
|
||||
*/
|
||||
public enum ContainerType {
|
||||
|
||||
/**
|
||||
* The default container type.
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* If the container is used for a shop.
|
||||
*/
|
||||
SHOP,
|
||||
|
||||
/**
|
||||
* The container should always stack items.
|
||||
*/
|
||||
ALWAYS_STACK,
|
||||
|
||||
/**
|
||||
* The container should never stack items.
|
||||
*/
|
||||
NEVER_STACK;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package core.game.container;
|
||||
|
||||
/**
|
||||
* The sort type of the container.
|
||||
* @author Emperor
|
||||
*/
|
||||
public enum SortType {
|
||||
|
||||
/**
|
||||
* Sort by item id (default).
|
||||
*/
|
||||
ID,
|
||||
|
||||
/**
|
||||
* Sort by item identification hash (bank).
|
||||
*/
|
||||
HASH
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package core.game.container.access;
|
||||
|
||||
import core.api.IfaceSettingsBuilder;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
import core.net.packet.PacketRepository;
|
||||
import core.net.packet.context.ContainerContext;
|
||||
import core.net.packet.out.ContainerPacket;
|
||||
|
||||
/**
|
||||
* Generates a set of items and options on an interface.
|
||||
* @date 5/02/2013
|
||||
* @author Stacx
|
||||
*/
|
||||
public class InterfaceContainer {
|
||||
|
||||
/**
|
||||
* The client script index for set_options.
|
||||
*/
|
||||
private static final int CLIENT_SCRIPT_INDEX = 150;
|
||||
|
||||
/**
|
||||
* This index will increase each time a set is generated.
|
||||
*/
|
||||
private static int index = 600; // 93
|
||||
|
||||
/**
|
||||
* Generates a container/array of items in an interface positioned on the
|
||||
* child index.
|
||||
* @param player , the player we generate this set for
|
||||
* @param itemArray , the container/array of items we want to display
|
||||
* @param options , the right-click options we want for the items
|
||||
* @param interfaceIndex , the interface index
|
||||
* @param childIndex , the child index of the interface where we display the
|
||||
* items at.
|
||||
* @return The container key.
|
||||
*/
|
||||
private static int generate(Player player, Item[] itemArray, String[] options, int interfaceIndex, int childIndex, int x, int y, int key) {
|
||||
Object[] clientScript = new Object[options.length + 7];
|
||||
player.getPacketDispatch().sendRunScript(CLIENT_SCRIPT_INDEX, generateScriptArguments(options.length), populateScript(clientScript, options, interfaceIndex << 16 | childIndex, x, y, key));
|
||||
int settings = new IfaceSettingsBuilder().enableAllOptions().build();
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, childIndex, interfaceIndex, 0, itemArray.length);
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, -1, -2, key, itemArray, itemArray.length, false));
|
||||
return increment();
|
||||
}
|
||||
|
||||
public static int generateOptions(Player player, String[] options, int interfaceIndex, int childIndex, int x, int y, int key){
|
||||
player.getPacketDispatch().sendRunScript(CLIENT_SCRIPT_INDEX, generateScriptArguments(options.length), populateScript(new Object[options.length + 7],options,interfaceIndex << 16 | childIndex, x, y, key));
|
||||
int settings = new IfaceSettingsBuilder().enableAllOptions().build();
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, childIndex, interfaceIndex, 0, 28);
|
||||
return increment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates options for the interface item container.
|
||||
* @param player The player.
|
||||
* @param interfaceId The interface id.
|
||||
* @param childId The child index.
|
||||
* @param itemLength The amount of items.
|
||||
* @param options The options.
|
||||
* @return The container key.
|
||||
*/
|
||||
public static int generate(Player player, int interfaceId, int childId, int itemLength, String... options) {
|
||||
return generate(player, interfaceId, childId, itemLength, 7, 3, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates options for the interface item container.
|
||||
* @param player The player.
|
||||
* @param interfaceId The interface id.
|
||||
* @param childId The child index.
|
||||
* @param itemLength The amount of items.
|
||||
* @param x The amount of items in a row.
|
||||
* @param y The amount of item rows.
|
||||
* @param options The options.
|
||||
* @return The container key.
|
||||
*/
|
||||
public static int generate(Player player, int interfaceId, int childId, int itemLength, int x, int y, String... options) {
|
||||
int key = increment();
|
||||
Object[] clientScript = new Object[options.length + 7];
|
||||
player.getPacketDispatch().sendRunScript(CLIENT_SCRIPT_INDEX, generateScriptArguments(options.length), populateScript(clientScript, options, interfaceId << 16 | childId, x, y, key));
|
||||
int settings = new IfaceSettingsBuilder().enableAllOptions().build();
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, childId, interfaceId, 0, itemLength);
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the current index.
|
||||
* @return The previous index.
|
||||
*/
|
||||
private static int increment() {
|
||||
if (index == 6999) {
|
||||
index = 600;
|
||||
}
|
||||
return index++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates an object array used as a script for the client
|
||||
* @param script , the array we want to populate
|
||||
* @param options , the right-click options for our items
|
||||
* @param hash , interfaceIndex << 16 | childIndex
|
||||
* @return script, the populated script
|
||||
*/
|
||||
private static Object[] populateScript(Object[] script, String[] options, int hash, int x, int y, int key) {
|
||||
int offset = 0;
|
||||
for (String option : options) {
|
||||
script[offset++] = option;
|
||||
}
|
||||
System.arraycopy(new Object[] { -1, 0, x, y, key, hash }, 0, script, offset, 6);
|
||||
return script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a script argument type string for the client (note: everything
|
||||
* but a "s" is integer for the run script packet)
|
||||
* @param length , the amount of options
|
||||
* @return the generated string.
|
||||
*/
|
||||
private static String generateScriptArguments(int length) {
|
||||
StringBuilder builder = new StringBuilder("IviiiI");
|
||||
while (length > 0) {
|
||||
builder.append("s");
|
||||
length--;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default method to generate and send an item array for the client.
|
||||
* @return The container key.
|
||||
*/
|
||||
public static int generateItems(Player player, Item[] itemArray, String[] options, int interfaceIndex, int childIndex) {
|
||||
return generateItems(player, itemArray, options, interfaceIndex, childIndex, 7, 3, increment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Default method to generate and send an item array for the client.
|
||||
* @return The container key.
|
||||
*/
|
||||
public static int generateItems(Player player, Item[] itemArray, String[] options, int interfaceIndex, int childIndex, int key) {
|
||||
return generateItems(player, itemArray, options, interfaceIndex, childIndex, 7, 3, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate the send items for the client with a specified
|
||||
* location for the items.
|
||||
* @param x , the x coordinate
|
||||
* @param y , the y coordinate
|
||||
* @return The container key.
|
||||
*/
|
||||
public static int generateItems(Player player, Item[] itemArray, String[] options, int interfaceIndex, int childIndex, int x, int y) {
|
||||
return generateItems(player, itemArray, options, interfaceIndex, childIndex, x, y, increment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate the send items for the client with a specified
|
||||
* location for the items.
|
||||
* @param x , the x coordinate
|
||||
* @param y , the y coordinate
|
||||
* @return The container key.
|
||||
*/
|
||||
public static int generateItems(Player player, Item[] itemArray, String[] options, int interfaceIndex, int childIndex, int x, int y, int key) {
|
||||
return generate(player, itemArray, options, interfaceIndex, childIndex, x, y, key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
package core.game.container.impl;
|
||||
|
||||
import core.api.IfaceSettingsBuilder;
|
||||
import core.game.container.access.InterfaceContainer;
|
||||
import kotlin.ranges.IntRange;
|
||||
import org.rs09.consts.Vars;
|
||||
import core.ServerConstants;
|
||||
import core.game.component.Component;
|
||||
import core.game.container.*;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.player.link.IronmanMode;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.system.config.ItemConfigParser;
|
||||
import core.game.world.GameWorld;
|
||||
import core.net.packet.PacketRepository;
|
||||
import core.net.packet.context.ContainerContext;
|
||||
import core.net.packet.out.ContainerPacket;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Represents the bank container.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class BankContainer extends Container {
|
||||
|
||||
/**
|
||||
* The bank container size.
|
||||
*/
|
||||
public static final int SIZE = ServerConstants.BANK_SIZE;
|
||||
|
||||
/**
|
||||
* The maximum amount of bank tabs
|
||||
*/
|
||||
public static final int TAB_SIZE = 11;
|
||||
|
||||
/**
|
||||
* The player reference.
|
||||
*/
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* The bank listener.
|
||||
*/
|
||||
private final BankListener listener;
|
||||
|
||||
/**
|
||||
* If the bank is open.
|
||||
*/
|
||||
private boolean open;
|
||||
|
||||
/**
|
||||
* The last x-amount entered.
|
||||
*/
|
||||
private int lastAmountX = 50;
|
||||
|
||||
/**
|
||||
* The current tab index.
|
||||
*/
|
||||
private int tabIndex = 10;
|
||||
|
||||
/**
|
||||
* The tab start indexes.
|
||||
*/
|
||||
private final int[] tabStartSlot = new int[TAB_SIZE];
|
||||
|
||||
/**
|
||||
* Construct a new {@code BankContainer} {@code Object}.
|
||||
* @param player The player reference.
|
||||
*/
|
||||
public BankContainer(Player player) {
|
||||
super(SIZE, ContainerType.ALWAYS_STACK, SortType.HASH);
|
||||
super.register(listener = new BankListener(player));
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to open the deposit box.
|
||||
*/
|
||||
public void openDepositBox() {
|
||||
player.getInterfaceManager().open(new Component(11)).setCloseEvent((player, c) -> {
|
||||
player.getInterfaceManager().openDefaultTabs();
|
||||
return true;
|
||||
});
|
||||
player.getInterfaceManager().removeTabs(0, 1, 2, 3, 4, 5, 6);
|
||||
refreshDepositBoxInterface();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the visual state of deposit box interface
|
||||
* forcing the client to re-draw the items
|
||||
*/
|
||||
public void refreshDepositBoxInterface()
|
||||
{
|
||||
InterfaceContainer.generateItems(
|
||||
player,
|
||||
player.getInventory().toArray(),
|
||||
new String[] {
|
||||
"Examine",
|
||||
"Deposit-X",
|
||||
"Deposit-All",
|
||||
"Deposit-10",
|
||||
"Deposit-5",
|
||||
"Deposit-1"
|
||||
}, 11, 15, 5, 7
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the bank.
|
||||
*/
|
||||
public void open() {
|
||||
if (open) {
|
||||
return;
|
||||
}
|
||||
if (player.getIronmanManager().checkRestriction(IronmanMode.ULTIMATE)) {
|
||||
return;
|
||||
}
|
||||
if (!player.getBankPinManager().isUnlocked() && !GameWorld.getSettings().isDevMode()) {
|
||||
player.getBankPinManager().openType(1);
|
||||
return;
|
||||
}
|
||||
player.getInterfaceManager().openComponent(762).setCloseEvent((player, c) -> {
|
||||
BankContainer.this.close();
|
||||
return true;
|
||||
});
|
||||
player.getInterfaceManager().openSingleTab(new Component(763));
|
||||
super.refresh();
|
||||
player.getInventory().getListeners().add(listener);
|
||||
player.getInventory().refresh();
|
||||
player.varpManager.get(1249).setVarbit(0,lastAmountX).send(player);
|
||||
int settings = new IfaceSettingsBuilder().enableOptions(new IntRange(0, 5)).enableExamine().enableSlotSwitch().build();
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, 0, 763, 0, 27);
|
||||
player.getPacketDispatch().sendRunScript(1451, "");
|
||||
open = true;
|
||||
setTabConfigurations();
|
||||
sendBankSpace();
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
if (open) {
|
||||
return;
|
||||
}
|
||||
if (player.getIronmanManager().checkRestriction(IronmanMode.ULTIMATE)) {
|
||||
return;
|
||||
}
|
||||
if (!player.getBankPinManager().isUnlocked() && !GameWorld.getSettings().isDevMode()) {
|
||||
player.getBankPinManager().openType(1);
|
||||
return;
|
||||
}
|
||||
player.getInterfaceManager().openComponent(762).setCloseEvent((player1, c) -> {
|
||||
BankContainer.this.close();
|
||||
return true;
|
||||
});
|
||||
refresh(listener);
|
||||
player.getInterfaceManager().openSingleTab(new Component(763));
|
||||
player.getInventory().getListeners().add(player.getBank().listener);
|
||||
player.getInventory().refresh();
|
||||
player.varpManager.get(1249).setVarbit(0,lastAmountX).send(player);
|
||||
player.getPacketDispatch().sendIfaceSettings(1278, 73, 762, 0, SIZE);
|
||||
int settings = new IfaceSettingsBuilder().enableOptions(new IntRange(0,5)).enableExamine().enableSlotSwitch().build();
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, 0, 763, 0, 27);
|
||||
player.getPacketDispatch().sendRunScript(1451, "");
|
||||
open = true;
|
||||
this.player.getBank().setTabConfigurations(player);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long save(ByteBuffer buffer) {
|
||||
buffer.putInt(lastAmountX);
|
||||
buffer.put((byte) tabStartSlot.length);
|
||||
for (int j : tabStartSlot) {
|
||||
buffer.putShort((short) j);
|
||||
}
|
||||
return super.save(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int parse(ByteBuffer buffer) {
|
||||
lastAmountX = buffer.getInt();
|
||||
int length = buffer.get() & 0xFF;
|
||||
for (int i = 0; i < length; i++) {
|
||||
tabStartSlot[i] = buffer.getShort();
|
||||
}
|
||||
return super.parse(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the bank.
|
||||
*/
|
||||
public void close() {
|
||||
open = false;
|
||||
player.getInventory().getListeners().remove(listener);
|
||||
player.getInterfaceManager().closeSingleTab();
|
||||
player.removeAttribute("search");
|
||||
player.getPacketDispatch().sendRunScript(571, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the bank container.
|
||||
* @param slot The item slot.
|
||||
* @param amount The amount.
|
||||
*/
|
||||
public void addItem(int slot, int amount) {
|
||||
if (slot < 0 || slot > player.getInventory().capacity() || amount < 1) {
|
||||
return;
|
||||
}
|
||||
Item item = player.getInventory().get(slot);
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.getDefinition().getConfiguration(ItemConfigParser.BANKABLE, true)) {
|
||||
player.sendMessage("A magical force prevents you from banking this item");
|
||||
return;
|
||||
}
|
||||
|
||||
int maximum = player.getInventory().getAmount(item);
|
||||
if (amount > maximum) {
|
||||
amount = maximum;
|
||||
}
|
||||
|
||||
item = new Item(item.getId(), amount, item.getCharge());
|
||||
boolean unnote = !item.getDefinition().isUnnoted();
|
||||
|
||||
Item add = unnote ? new Item(item.getDefinition().getNoteId(), amount, item.getCharge()) : item;
|
||||
if (unnote && !add.getDefinition().isUnnoted()) {
|
||||
add = item;
|
||||
}
|
||||
|
||||
int maxCount = super.getMaximumAdd(add);
|
||||
if (amount > maxCount) {
|
||||
add.setAmount(maxCount);
|
||||
item.setAmount(maxCount);
|
||||
if (maxCount < 1) {
|
||||
player.getPacketDispatch().sendMessage("There is not enough space left in your bank.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getInventory().remove(item, slot, true)) {
|
||||
int preferredSlot = -1;
|
||||
if (tabIndex != 0 && tabIndex != 10 && !super.contains(add.getId(), 1)) {
|
||||
preferredSlot = tabStartSlot[tabIndex] + getItemsInTab(tabIndex);
|
||||
insert(freeSlot(), preferredSlot, false);
|
||||
increaseTabStartSlots(tabIndex);
|
||||
}
|
||||
super.add(add, true, preferredSlot);
|
||||
setTabConfigurations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-opens the bank interface.
|
||||
*/
|
||||
public void reopen() {
|
||||
if (!open) {
|
||||
return;
|
||||
}
|
||||
player.getInterfaceManager().close();
|
||||
open();
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a item from the bank container and adds one to the inventory
|
||||
* container.
|
||||
* @param slot The slot.
|
||||
* @param amount The amount.
|
||||
*/
|
||||
public void takeItem(int slot, int amount) {
|
||||
if (slot < 0 || slot > super.capacity() || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
Item item = get(slot);
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
if (amount > item.getAmount()) {
|
||||
amount = item.getAmount(); // It always stacks in the bank.
|
||||
}
|
||||
item = new Item(item.getId(), amount, item.getCharge());
|
||||
int noteId = item.getDefinition().getNoteId();
|
||||
Item add = isNoteItems() && noteId > 0 ? new Item(noteId, amount, item.getCharge()) : item;
|
||||
int maxCount = player.getInventory().getMaximumAdd(add);
|
||||
if (amount > maxCount) {
|
||||
item.setAmount(maxCount);
|
||||
add.setAmount(maxCount);
|
||||
if (maxCount < 1) {
|
||||
player.getPacketDispatch().sendMessage("Not enough space in your inventory.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (isNoteItems() && noteId < 0) {
|
||||
player.getPacketDispatch().sendMessage("This item can't be withdrawn as a note.");
|
||||
add = item;
|
||||
}
|
||||
if (super.remove(item, slot, false)) {
|
||||
player.getInventory().add(add);
|
||||
}
|
||||
int tabId = getTabByItemSlot(slot);
|
||||
if (get(slot) == null) {
|
||||
decreaseTabStartSlots(tabId);
|
||||
}
|
||||
setTabConfigurations();
|
||||
shift();
|
||||
if (player.getAttribute("search", false)) {
|
||||
reopen();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the last x-amount entered.
|
||||
* @param amount The amount to set.
|
||||
*/
|
||||
public void updateLastAmountX(int amount) {
|
||||
this.lastAmountX = amount;
|
||||
player.varpManager.get(1249).setVarbit(0,amount).send(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tab the item slot is in.
|
||||
* @param itemSlot The item slot.
|
||||
* @return The tab index.
|
||||
*/
|
||||
public int getTabByItemSlot(int itemSlot) {
|
||||
int tabId = 0;
|
||||
for (int i = 0; i < tabStartSlot.length; i++) {
|
||||
if (itemSlot >= tabStartSlot[i]) {
|
||||
tabId = i;
|
||||
}
|
||||
}
|
||||
return tabId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases a tab's start slot.
|
||||
* @param startId The start id.
|
||||
*/
|
||||
public void increaseTabStartSlots(int startId) {
|
||||
for (int i = startId + 1; i < tabStartSlot.length; i++) {
|
||||
tabStartSlot[i]++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decreases a tab's start slot.
|
||||
* @param startId The start id.
|
||||
*/
|
||||
public void decreaseTabStartSlots(int startId) {
|
||||
if (startId == 10) {
|
||||
return;
|
||||
}
|
||||
for (int i = startId + 1; i < tabStartSlot.length; i++) {
|
||||
tabStartSlot[i]--;
|
||||
}
|
||||
if (getItemsInTab(startId) == 0) {
|
||||
collapseTab(startId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array index for a tab.
|
||||
* @param tabId The tab id.
|
||||
* @return The array index.
|
||||
*/
|
||||
public static int getArrayIndex(int tabId) {
|
||||
if (tabId == 41 || tabId == 74) {
|
||||
return 10;
|
||||
}
|
||||
int base = 39;
|
||||
for (int i = 1; i < 10; i++) {
|
||||
if (tabId == base) {
|
||||
return i;
|
||||
}
|
||||
base -= 2;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the bank space values on the interface.
|
||||
*/
|
||||
public void sendBankSpace() {
|
||||
player.getPacketDispatch().sendString(Integer.toString(capacity() - freeSlots()), 762, 97);
|
||||
player.getPacketDispatch().sendString(Integer.toString(capacity()), 762, 98);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapses a tab.
|
||||
* @param tabId The tab index.
|
||||
*/
|
||||
public void collapseTab(int tabId) {
|
||||
int size = getItemsInTab(tabId);
|
||||
Item[] tempTabItems = new Item[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
tempTabItems[i] = get(tabStartSlot[tabId] + i);
|
||||
replace(null, tabStartSlot[tabId] + i, false);
|
||||
}
|
||||
shift();
|
||||
for (int i = tabId; i < tabStartSlot.length - 1; i++) {
|
||||
tabStartSlot[i] = tabStartSlot[i + 1] - size;
|
||||
}
|
||||
tabStartSlot[10] = tabStartSlot[10] - size;
|
||||
for (int i = 0; i < size; i++) {
|
||||
int slot = freeSlot();
|
||||
replace(tempTabItems[i], slot, false);
|
||||
}
|
||||
refresh(); //We only refresh once.
|
||||
setTabConfigurations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tab configs.
|
||||
*/
|
||||
public void setTabConfigurations() {
|
||||
int value = getItemsInTab(1);
|
||||
value += getItemsInTab(2) << 10;
|
||||
value += getItemsInTab(3) << 20;
|
||||
player.getConfigManager().set(1246, value);
|
||||
value = getItemsInTab(4);
|
||||
value += getItemsInTab(5) << 10;
|
||||
value += getItemsInTab(6) << 20;
|
||||
player.getConfigManager().set(1247, value);
|
||||
value = -2013265920;
|
||||
value += (134217728 * (tabIndex == 10 ? 0 : tabIndex));
|
||||
value += getItemsInTab(7);
|
||||
value += getItemsInTab(8) << 10;
|
||||
player.getConfigManager().set(1248, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tab configs.
|
||||
*/
|
||||
public void setTabConfigurations(Player player) {
|
||||
int value = getItemsInTab(1);
|
||||
value += getItemsInTab(2) << 10;
|
||||
value += getItemsInTab(3) << 20;
|
||||
player.getConfigManager().set(1246, value);
|
||||
value = getItemsInTab(4);
|
||||
value += getItemsInTab(5) << 10;
|
||||
value += getItemsInTab(6) << 20;
|
||||
player.getConfigManager().set(1247, value);
|
||||
value = -2013265920;
|
||||
value += (134217728 * (tabIndex == 10 ? 0 : tabIndex));
|
||||
value += getItemsInTab(7);
|
||||
value += getItemsInTab(8) << 10;
|
||||
player.getConfigManager().set(1248, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of items in one tab.
|
||||
* @param tabId The tab index.
|
||||
* @return The amount of items in this tab.
|
||||
*/
|
||||
public int getItemsInTab(int tabId) {
|
||||
return tabStartSlot[tabId + 1] - tabStartSlot[tabId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the item can be added.
|
||||
* @param item the item.
|
||||
* @return {@code True} if so.
|
||||
*/
|
||||
public boolean canAdd(Item item) {
|
||||
return item.getDefinition().getConfiguration(ItemConfigParser.BANKABLE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last x-amount.
|
||||
* @return The last x-amount.
|
||||
*/
|
||||
public int getLastAmountX() {
|
||||
return lastAmountX;
|
||||
}
|
||||
|
||||
/**
|
||||
* If items have to be noted.
|
||||
* @return If items have to be noted {@code true}.
|
||||
*/
|
||||
public boolean isNoteItems() {
|
||||
return player.varpManager.getVarbit(Vars.VARBIT_IFACE_BANK_NOTE_MODE) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if items have to be noted.
|
||||
* @param noteItems If items have to be noted {@code true}.
|
||||
*/
|
||||
public void setNoteItems(boolean noteItems) {
|
||||
player.varpManager.flagSave(Vars.VARBIT_IFACE_BANK_NOTE_MODE, true);
|
||||
player.varpManager.setVarbit(Vars.VARBIT_IFACE_BANK_NOTE_MODE, noteItems ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tabStartSlot value.
|
||||
* @return The tabStartSlot.
|
||||
*/
|
||||
public int[] getTabStartSlot() {
|
||||
return tabStartSlot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tabIndex value.
|
||||
* @return The tabIndex.
|
||||
*/
|
||||
public int getTabIndex() {
|
||||
return tabIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tabIndex value.
|
||||
* @param tabIndex The tabIndex to set.
|
||||
*/
|
||||
public void setTabIndex(int tabIndex) {
|
||||
this.tabIndex = tabIndex;
|
||||
|
||||
/*
|
||||
* Kludge to update the interface
|
||||
* after dumping all to prevent
|
||||
* "invisible" items in slots.
|
||||
*/
|
||||
update(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the insert items value.
|
||||
* @param insertItems The insert items value.
|
||||
*/
|
||||
public void setInsertItems(boolean insertItems) {
|
||||
player.varpManager.setVarbit(Vars.VARBIT_IFACE_BANK_INSERT_MODE, insertItems ? 1 : 0);
|
||||
player.varpManager.flagSave(Vars.VARBIT_IFACE_BANK_INSERT_MODE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the insert items value.
|
||||
* @return {@code True} if inserting items mode is enabled.
|
||||
*/
|
||||
public boolean isInsertItems() {
|
||||
return player.varpManager.getVarbit(Vars.VARBIT_IFACE_BANK_INSERT_MODE) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the bank is opened.
|
||||
* @return {@code True} if so.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the bank container.
|
||||
* @author Emperor
|
||||
*/
|
||||
private static class BankListener implements ContainerListener {
|
||||
|
||||
/**
|
||||
* The player reference.
|
||||
*/
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Construct a new {@code BankListener} {@code Object}.
|
||||
* @param player The player reference.
|
||||
*/
|
||||
public BankListener(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Container c, ContainerEvent event) {
|
||||
if (c instanceof BankContainer) {
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 762, 64000, 95, event.getItems(), false, event.getSlots()));
|
||||
} else {
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 763, 64000, 93, event.getItems(), false, event.getSlots()));
|
||||
}
|
||||
player.getBank().setTabConfigurations();
|
||||
player.getBank().sendBankSpace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(Container c) {
|
||||
if (c instanceof BankContainer) {
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 762, 64000, 95, c.toArray(), c.capacity(), false));
|
||||
} else {
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 763, 64000, 93, c.toArray(), 28, false));
|
||||
}
|
||||
player.getBank().setTabConfigurations();
|
||||
player.getBank().sendBankSpace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
package core.game.container.impl;
|
||||
|
||||
import content.global.skill.skillcapeperks.SkillcapePerks;
|
||||
import core.game.container.Container;
|
||||
import core.game.container.ContainerEvent;
|
||||
import core.game.container.ContainerListener;
|
||||
import core.game.node.entity.combat.equipment.WeaponInterface;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.skill.Skills;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.world.update.flag.player.AppearanceFlag;
|
||||
import core.net.packet.PacketRepository;
|
||||
import core.net.packet.context.ContainerContext;
|
||||
import core.net.packet.out.ContainerPacket;
|
||||
import core.net.packet.out.WeightUpdate;
|
||||
import core.plugin.Plugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import core.game.interaction.InteractionListeners;
|
||||
import core.game.system.config.ItemConfigParser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Represents the equipment container.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class EquipmentContainer extends Container {
|
||||
/**
|
||||
* The equipment slots.
|
||||
*/
|
||||
public static final int SLOT_HAT = 0, SLOT_CAPE = 1, SLOT_AMULET = 2, SLOT_WEAPON = 3, SLOT_CHEST = 4, SLOT_SHIELD = 5, SLOT_LEGS = 7, SLOT_HANDS = 9, SLOT_FEET = 10, SLOT_RING = 12, SLOT_ARROWS = 13;
|
||||
|
||||
/**
|
||||
* The bonus names.
|
||||
*/
|
||||
private static final String[] BONUS_NAMES = { "Stab: ", "Slash: ", "Crush: ", "Magic: ", "Ranged: ", "Stab: ", "Slash: ", "Crush: ", "Magic: ", "Ranged: ", "Summoning: ", "Strength: ", "Prayer: " };
|
||||
|
||||
/**
|
||||
* The player.
|
||||
*/
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code EquipmentContainer} {@code Object}.
|
||||
* @param player The player.
|
||||
*/
|
||||
public EquipmentContainer(Player player) {
|
||||
super(14);
|
||||
this.player = player;
|
||||
register(new EquipmentListener(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Item item, boolean fire) {
|
||||
return add(item, fire, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the equipment container.
|
||||
* @param item The item to add.
|
||||
* @param fire If we should refresh.
|
||||
* @param fromInventory If the item is being equipped from the inventory.
|
||||
* @return {@code True} if succesful, {@code false} if not.
|
||||
*/
|
||||
public boolean add(Item item, boolean fire, boolean fromInventory) {
|
||||
return add(item, player.getInventory().getSlot(item), fire, fromInventory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the equipment container.
|
||||
* @param newItem The item to add.
|
||||
* @param inventorySlot The inventory slot of the item to add.
|
||||
* @param fire If we should refresh.
|
||||
* @param fromInventory If the item is being equipped from the inventory.
|
||||
* @return {@code True} if succesful, {@code false} if not.
|
||||
*/
|
||||
public boolean add(Item newItem, int inventorySlot, boolean fire, boolean fromInventory) {
|
||||
int equipmentSlot = newItem.getDefinition().getConfiguration(ItemConfigParser.EQUIP_SLOT, -1);
|
||||
if (!isEquippable(newItem, equipmentSlot)) return false;
|
||||
|
||||
ArrayList<Item> itemsToRemove = new ArrayList<>();
|
||||
|
||||
Item currentItem = super.get(equipmentSlot);
|
||||
if(currentItem != null) itemsToRemove.add(currentItem);
|
||||
|
||||
Item secondaryEquip = getSecondaryEquipIfApplicable(newItem, equipmentSlot);
|
||||
if(secondaryEquip != null) itemsToRemove.add(secondaryEquip);
|
||||
|
||||
if(fromInventory && !player.getInventory().remove(newItem, inventorySlot, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!itemsToRemove.isEmpty()) {
|
||||
ArrayList<Item> invalidatedEntries = new ArrayList<>();
|
||||
for(Item current : itemsToRemove) {
|
||||
if(current.getId() == newItem.getId() && current.getDefinition().isStackable()) {
|
||||
addStackableItemToExistingStack(newItem, fromInventory, equipmentSlot, current);
|
||||
invalidatedEntries.add(current);
|
||||
}
|
||||
}
|
||||
itemsToRemove.removeAll(invalidatedEntries);
|
||||
|
||||
if(itemsToRemove.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean successfullyRemovedAll = tryUnequipCurrent(itemsToRemove, newItem, inventorySlot);
|
||||
|
||||
if(!successfullyRemovedAll) {
|
||||
if (fromInventory) player.getInventory().add(newItem); //add the item back in case we weren't able to remove the currently equipped item(s)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
super.replace(newItem, equipmentSlot, fire);
|
||||
setWeaponInterfaceWeaponName(newItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isEquippable(Item newItem, int slot) {
|
||||
if (slot < 0) {
|
||||
return false;
|
||||
}
|
||||
return newItem.getDefinition().hasRequirement(player, true, true);
|
||||
}
|
||||
|
||||
private void setWeaponInterfaceWeaponName(Item newItem) {
|
||||
if (newItem.getSlot() == SLOT_WEAPON) {
|
||||
player.getPacketDispatch().sendString(newItem.getName(), 92, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tryUnequipCurrent(ArrayList<Item> current, Item newItem, int preferredSlot) {
|
||||
if(current.isEmpty()) return true;
|
||||
int freeSlots = player.getInventory().freeSlots();
|
||||
int neededSlots = getNeededSlotsToUnequip(current);
|
||||
|
||||
boolean hasSpaceForUnequippedItems = freeSlots >= neededSlots;
|
||||
|
||||
if(!hasSpaceForUnequippedItems) {
|
||||
player.getPacketDispatch().sendMessage("Not enough space in your inventory!");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean listenersSayWeCanUnequip = runUnequipHooks(current, newItem);
|
||||
|
||||
boolean allRemoved = true;
|
||||
for(Item item : current) {
|
||||
if(!remove(item)) {
|
||||
allRemoved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean allAdded = allRemoved;
|
||||
if(allRemoved) {
|
||||
for (Item item : current) {
|
||||
if (!player.getInventory().add(item, true, preferredSlot)) {
|
||||
allAdded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (listenersSayWeCanUnequip && allRemoved && allAdded) return true;
|
||||
else {
|
||||
//put things back if we couldn't remove everything
|
||||
for(Item item : current) {
|
||||
if(!containsItem(item)) {
|
||||
add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getNeededSlotsToUnequip(ArrayList<Item> current) {
|
||||
int neededSlots = 0;
|
||||
|
||||
for(Item item : current) {
|
||||
if(!item.getDefinition().isStackable()) {
|
||||
neededSlots++;
|
||||
} else {
|
||||
if(player.getInventory().getAmount(item.getId()) == 0) {
|
||||
neededSlots++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return neededSlots;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Item getSecondaryEquipIfApplicable(Item newItem, int equipmentSlot) {
|
||||
Item secondaryEquipItem = null;
|
||||
if (newItem.getDefinition().getConfiguration(ItemConfigParser.TWO_HANDED, false)) {
|
||||
secondaryEquipItem = get(SLOT_SHIELD);
|
||||
} else if (equipmentSlot == SLOT_SHIELD) {
|
||||
Item inSlot = player.getEquipment().get(SLOT_WEAPON);
|
||||
if(inSlot != null && inSlot.getDefinition().getConfiguration(ItemConfigParser.TWO_HANDED, false))
|
||||
secondaryEquipItem = get(SLOT_WEAPON);
|
||||
}
|
||||
return secondaryEquipItem;
|
||||
}
|
||||
|
||||
private boolean runUnequipHooks(ArrayList<Item> currentItems, Item newItem) {
|
||||
boolean canContinue = true;
|
||||
|
||||
for(Item currentItem : currentItems) {
|
||||
Plugin<Object> plugin = currentItem.getDefinition().getConfiguration("equipment", null);
|
||||
if (plugin != null) {
|
||||
Object object = plugin.fireEvent("unequip", player, currentItem, newItem);
|
||||
if (object != null && !((Boolean) object)) {
|
||||
canContinue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
canContinue = InteractionListeners.run(currentItem.getId(), player, currentItem, false);
|
||||
|
||||
if(!canContinue) break;
|
||||
}
|
||||
|
||||
return canContinue;
|
||||
}
|
||||
|
||||
private void addStackableItemToExistingStack(Item item, boolean fromInventory, int slot, Item current) {
|
||||
int amount = getMaximumAdd(item);
|
||||
if (item.getAmount() > amount) {
|
||||
amount += current.getAmount();
|
||||
} else {
|
||||
amount = current.getAmount() + item.getAmount();
|
||||
}
|
||||
Item transferItem = new Item(current.getId(), amount);
|
||||
if (fromInventory) {
|
||||
player.getInventory().remove(transferItem);
|
||||
}
|
||||
replace(transferItem, slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the equipment container.
|
||||
* @author Emperor
|
||||
*/
|
||||
private static class EquipmentListener implements ContainerListener {
|
||||
|
||||
/**
|
||||
* The player.
|
||||
*/
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code EquipmentContainer} {@code Object}.
|
||||
* @param player The player.
|
||||
*/
|
||||
public EquipmentListener(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Container c, ContainerEvent event) {
|
||||
int[] slots = event.getSlots();
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 387, 28, 94, event.getItems(), false, slots));
|
||||
update(c);
|
||||
boolean updateDefenceAnimation = false;
|
||||
for (int slot : slots) {
|
||||
if (slot == EquipmentContainer.SLOT_WEAPON) {
|
||||
player.getProperties().setAttackSpeed(c.getNew(slot).getDefinition().getConfiguration(ItemConfigParser.ATTACK_SPEED, 4));
|
||||
WeaponInterface inter = player.getExtension(WeaponInterface.class);
|
||||
if (inter == null) {
|
||||
break;
|
||||
}
|
||||
inter.updateInterface();
|
||||
updateDefenceAnimation = true;
|
||||
} else if (slot == EquipmentContainer.SLOT_SHIELD) {
|
||||
updateDefenceAnimation = true;
|
||||
}
|
||||
}
|
||||
if (updateDefenceAnimation) {
|
||||
player.getProperties().updateDefenceAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(Container c) {
|
||||
player.getProperties().setAttackSpeed(c.getNew(3).getDefinition().getConfiguration(ItemConfigParser.ATTACK_SPEED, 4));
|
||||
WeaponInterface inter = player.getExtension(WeaponInterface.class);
|
||||
if (inter != null) {
|
||||
inter.updateInterface();
|
||||
}
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 387, 28, 94, c.toArray(), 14, false));
|
||||
update(c);
|
||||
player.getProperties().updateDefenceAnimation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the bonuses, weight, animations, ...
|
||||
* @param c The container.
|
||||
*/
|
||||
public void update(Container c) {
|
||||
if (c.getNew(SLOT_SHIELD).getId() != 11283 && player.getAttribute("dfs_spec", false)) {
|
||||
player.removeAttribute("dfs_spec");
|
||||
player.getProperties().getCombatPulse().setHandler(null);
|
||||
if (!player.getSettings().isSpecialToggled()) {
|
||||
player.getConfigManager().set(301, 0);
|
||||
}
|
||||
}
|
||||
player.getAppearance().setAnimations();
|
||||
player.getUpdateMasks().register(new AppearanceFlag(player));
|
||||
player.getSettings().updateWeight();
|
||||
updateBonuses(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the bonuses.
|
||||
* @param player The player.
|
||||
*/
|
||||
public static void updateBonuses(Player player) {
|
||||
int[] bonuses = new int[15];
|
||||
for (Item item : player.getEquipment().toArray()) {
|
||||
if (item != null) {
|
||||
int[] bonus = item.getDefinition().getConfiguration(ItemConfigParser.BONUS, new int[15]);
|
||||
for (int i = 0; i < bonus.length; i++) {
|
||||
if (i == 14 && bonuses[i] != 0) {
|
||||
continue;
|
||||
}
|
||||
bonuses[i] += bonus[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
Item weapon = player.getEquipment().get(SLOT_WEAPON);
|
||||
if(weapon != null && weapon.getDefinition().getRequirement(Skills.STRENGTH) > 0 && SkillcapePerks.isActive(SkillcapePerks.FINE_ATTUNEMENT,player)){
|
||||
int[] bonus = weapon.getDefinition().getConfiguration(ItemConfigParser.BONUS, new int[15]);
|
||||
bonuses[11] += Math.ceil(bonus[11] * 0.20);
|
||||
}
|
||||
Item shield = player.getEquipment().get(SLOT_SHIELD);
|
||||
if(shield != null && SkillcapePerks.isActive(SkillcapePerks.GRAND_BULLWARK,player)){
|
||||
bonuses[5] += Math.ceil(bonuses[5] * 0.20);
|
||||
bonuses[6] += Math.ceil(bonuses[6] * 0.20);
|
||||
bonuses[7] += Math.ceil(bonuses[7] * 0.20);
|
||||
bonuses[9] += Math.ceil(bonuses[9] * 0.20);
|
||||
bonuses[10] += Math.ceil(bonuses[10] * 0.20);
|
||||
}
|
||||
if (shield != null && shield.getId() == 11283) {
|
||||
int increase = shield.getCharge() / 20;
|
||||
bonuses[5] += increase;
|
||||
bonuses[6] += increase;
|
||||
bonuses[7] += increase;
|
||||
bonuses[9] += increase;
|
||||
bonuses[10] += increase;
|
||||
}
|
||||
player.getProperties().setBonuses(bonuses);
|
||||
update(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the equipment stats interface.
|
||||
* @param player The player to update for.
|
||||
*/
|
||||
public static void update(Player player) {
|
||||
if (!player.getInterfaceManager().hasMainComponent(667)) {
|
||||
return;
|
||||
}
|
||||
PacketRepository.send(WeightUpdate.class, player.getPacketDispatch().getContext());
|
||||
int index = 0;
|
||||
int[] bonuses = player.getProperties().getBonuses();
|
||||
for (int i = 36; i < 50; i++) {
|
||||
if (i == 47) {
|
||||
continue;
|
||||
}
|
||||
int bonus = bonuses[index];
|
||||
String bonusValue = bonus > -1 ? ("+" + bonus) : Integer.toString(bonus);
|
||||
player.getPacketDispatch().sendString(BONUS_NAMES[index++] + bonusValue, 667, i);
|
||||
}
|
||||
player.getPacketDispatch().sendString("Attack bonus", 667, 34);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package core.game.container.impl;
|
||||
|
||||
import core.game.container.Container;
|
||||
import core.game.container.ContainerEvent;
|
||||
import core.game.container.ContainerListener;
|
||||
import content.global.skill.summoning.SummoningPouch;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
import core.net.packet.PacketRepository;
|
||||
import core.net.packet.context.ContainerContext;
|
||||
import core.net.packet.out.ContainerPacket;
|
||||
|
||||
/**
|
||||
* Handles the inventory container listening.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class InventoryListener implements ContainerListener {
|
||||
|
||||
/**
|
||||
* The player.
|
||||
*/
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code InventoryListener} {@code Object}.
|
||||
* @param player The player.
|
||||
*/
|
||||
public InventoryListener(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the required settings etc for the player when the container
|
||||
* updates.
|
||||
* @param c The container.
|
||||
*/
|
||||
public void update(Container c) {
|
||||
player.getSettings().updateWeight();
|
||||
boolean hadPouch = player.getFamiliarManager().isHasPouch();
|
||||
boolean pouch = false;
|
||||
for (Item item : c.toArray()) {
|
||||
if (item != null && SummoningPouch.get(item.getId()) != null) {
|
||||
pouch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
player.getFamiliarManager().setHasPouch(pouch);
|
||||
if (hadPouch != pouch && player.getSkullManager().isWilderness()) {
|
||||
player.getAppearance().sync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(Container c) {
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 149, 0, 93, c, false));
|
||||
update(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Container c, ContainerEvent event) {
|
||||
PacketRepository.send(ContainerPacket.class, new ContainerContext(player, 149, 0, 93, event.getItems(), false, event.getSlots()));
|
||||
update(c);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user