Dexter Morgan
Banned
- Nov 11, 2008
- 4,428
- 477
- 0
Server side:
Client side:
In class Client in
replace if statement
Search for
Below add
Code:
package com.elvarg.game.content.item;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import com.elvarg.game.World;
import com.elvarg.game.entity.impl.player.Player;
import com.elvarg.game.model.Item;
import com.elvarg.game.model.JsonIO;
import com.elvarg.game.model.ui.UserContainerInterface;
import com.elvarg.net.packet.interaction.PacketInteraction;
import com.elvarg.util.Misc;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
/**
*
* @author Dexter Morgan <http://www.rune-server.org/members/dexter+morgan/>
*
*/
public class RunePouch extends PacketInteraction {
private static final int INTERFACE_ID = 24_200;
private static final int POUCH_CONTAINER_ID = 24206;
private static final int INVENTORY_CONTAINER_ID = 24209;
private static final int MAX_POUCH_SIZE = 3;
public static final int RUNE_POUCH = 12791;
private enum Rune {
FIRE_RUNE(554),
WATER_RUNE(555),
AIR_RUNE(556),
EARTH_RUNE(557),
MIND_RUNE(558),
BODY_RUNE(559),
DEATH_RUNE(560),
NATURE_RUNE(561),
CHAOS_RUNE(562),
LAW_RUNE(563),
COSMIC_RUNE(564),
BLOOD_RUNE(565),
SOUL_RUNE(566),
ASTRAL(9075),
;
private int id;
Rune(int id) {
this.id = id;
}
private static final HashMap<Integer, Rune> FOR_ID = new HashMap<>();
static {
for (Rune r : values()) {
FOR_ID.put(r.id, r);
}
}
}
private static final Type REFERENCE = new TypeToken<HashMap<Rune, Integer>>() {
}.getType();
public static final JsonIO IO = new JsonIO("./data/saves/rune_pouch/") {
[MENTION=381607]Override[/MENTION]
public void init(String name, Gson builder, JsonObject reader) {
JsonElement element = reader.get("pouch");
HashMap<Rune, Integer> result = GSON.fromJson(element.toString(), REFERENCE);
Optional<Player> p = World.getPlayerByName(name);
if (!p.isPresent()) {
return;
}
p.get().runePouch.pouch.putAll(result);
}
[MENTION=381607]Override[/MENTION]
public JsonObject save(String name, Gson builder, JsonObject object) {
Optional<Player> p = World.getPlayerByName(name);
if (!p.isPresent()) {
return object;
}
object.add("pouch", builder.toJsonTree(p.get().runePouch.pouch, REFERENCE));
return object;
}
};
static {
new UserContainerInterface(POUCH_CONTAINER_ID) {
[MENTION=381607]Override[/MENTION]
public boolean handleOption(Player player, int id, int slot, int option, int amount) {
if (player.getInterfaceId() != INTERFACE_ID) {
return false;
}
takeOut(player, slot);
return true;
}
};
new UserContainerInterface(INVENTORY_CONTAINER_ID) {
[MENTION=381607]Override[/MENTION]
public boolean handleOption(Player player, int id, int slot, int option, int amount) {
if (player.getInterfaceId() != INTERFACE_ID) {
return false;
}
int existing = player.getInventory().getAmount(id);
if (existing == 0) {
return true;
}
store(player, new Item(id, existing));
open(player);
return true;
}
};
}
private HashMap<Rune, Integer> pouch = new HashMap<>();
private static void open(Player p) {
ArrayList<Item> pouch = new ArrayList<>();
for (Map.Entry<Rune, Integer> e : p.runePouch.pouch.entrySet()) {
pouch.add(new Item(e.getKey().id, e.getValue()));
}
p.getPacketSender().sendItemContainerList(pouch, POUCH_CONTAINER_ID);
p.getPacketSender().sendItemContainer(p.getInventory(), INVENTORY_CONTAINER_ID);
p.getPacketSender().sendInterface(INTERFACE_ID);
}
private static void store(Player p, Item item) {
Rune r = Rune.FOR_ID.getOrDefault(item.getId(), null);
if (r == null) {
p.getPacketSender().sendMessage("You can only store runes into the rune pouch.");
return;
}
if (!p.runePouch.pouch.containsKey(r) && p.runePouch.pouch.size() == MAX_POUCH_SIZE) {
p.getPacketSender().sendMessage("Your rune pouch is full.");
return;
}
if (!p.getInventory().contains(item)) {
return;
}
String name = item.getName();
int amount = item.getAmount();
p.getInventory().delete(item);
p.runePouch.pouch.merge(r, amount, Integer::sum);
p.getPacketSender().sendMessage("You store " + Misc.format(amount) + " " + name + " into the rune pouch.");
}
private static void takeOut(Player p, int slot) {
ArrayList<Rune> list = new ArrayList<>(p.runePouch.pouch.keySet());
Rune r = list.get(slot);
if (p.getInventory().getFreeSlots() > 0 || p.getInventory().contains(r.id)) {
int existing = p.runePouch.pouch.getOrDefault(r, 0);
if (existing == 0) {
return;
}
p.runePouch.pouch.remove(r);
p.getInventory().add(r.id, existing);
open(p);
} else {
p.getInventory().full();
}
}
private static void empty(Player p) {
HashMap<Rune, Integer> pouch = new HashMap<>(p.runePouch.pouch);
for (Map.Entry<Rune, Integer> e : pouch.entrySet()) {
Rune r = e.getKey();
int amount = e.getValue();
if (p.getInventory().getFreeSlots() > 0 || p.getInventory().contains(r.id)) {
p.runePouch.pouch.remove(r);
p.getInventory().add(r.id, amount);
}
}
}
public static boolean useRune(Player p, Item rune) {
Rune r = Rune.FOR_ID.getOrDefault(rune.getId(), null);
if (r == null) {
return false;
}
if (!p.runePouch.pouch.containsKey(r)) {
return false;
}
int existing = p.runePouch.pouch.getOrDefault(r, 0);
if (rune.getAmount() > existing) {
return false;
}
p.runePouch.pouch.put(r, existing - rune.getAmount());
return true;
}
[MENTION=381607]Override[/MENTION]
public boolean handleItemInteraction(Player player, Item item, int type) {
switch (item.getId()) {
case RUNE_POUCH:
if (type == 1) {
open(player);
} else if (type == 2) {
empty(player);
}
return true;
}
return false;
}
[MENTION=381607]Override[/MENTION]
public boolean handleItemOnItemInteraction(Player player, Item use, Item usedWith) {
if (usedWith.getId() == RUNE_POUCH) {
store(player, use);
return true;
}
return false;
}
}
Client side:
Code:
package com.runescape.cache.graphics.widget.impl.osrs.impl;
import com.runescape.cache.graphics.widget.impl.osrs.ClearOSRSBackground;
/**
*
* @author Dexter Morgan <http://www.rune-server.org/members/dexter+morgan/>
*
*/
public class RunePouchWidget extends ClearOSRSBackground {
public RunePouchWidget() {
super(24_200, "Rune Pouch", 400, 310);
super.closeX = 370;
}
[MENTION=381607]Override[/MENTION]
public void init() {
super.init();
add(addCenteredText("Pouch:", 1), 256, 50);
add(addBox(200, 65, false), 156, 65);
add(addItemContainer(3, 1, 0, 0, new String[] { "Take out" }, "pouch"), 208, 82);
add(addCenteredText("Inventory:", 1), 256, 135);
add(addBox(350, 140, false), 256 - 175, 150);
add(addItemContainer(7, 4, 10, 0, new String[] { "Add" }, "inventory"), 256 - (21 * 7), 158);
}
}
In class Client in
Code:
public int executeScript(Widget widget, int id) {
Code:
if (instruction == 4) {
Widget other = Widget.interfaceCache[script[counter++]];
int item = script[counter++];
if (item >= 0 && item < ItemDefinition.TOTAL_ITEMS
&& (!ItemDefinition.lookup(item).is_members_only || isMembers)) {
label: for (int slot = 0; slot < other.inventoryItemId.length; slot++) {
boolean hasPouch = false;
if (other.id == 3214) {
for (int inventory = 0; inventory < other.inventoryItemId.length; inventory++) {
if (other.inventoryItemId[inventory] == 12792) {
hasPouch = true;
}
}
}
if (other.id == 3214 && hasPouch) {
Widget runePouch = Widget.interfaceCache[24206];
for (int runePouchSlot = 0; runePouchSlot < runePouch.inventoryItemId.length; runePouchSlot++) {
if (runePouch.inventoryItemId[runePouchSlot] == item + 1) {
value += runePouch.inventoryAmounts[runePouchSlot];
break label;
}
}
}
if (other.inventoryItemId[slot] == item + 1) {
value += other.inventoryAmounts[slot];
}
}
}
}
Code:
package com.runescape.model.content.rune;
import java.util.ArrayList;
/**
*
* @author Dexter Morgan <http://www.rune-server.org/members/dexter+morgan/>
*
*/
public enum Rune {
FIRE_RUNE(554),
WATER_RUNE(555),
AIR_RUNE(556),
EARTH_RUNE(557),
MIND_RUNE(558),
BODY_RUNE(559),
DEATH_RUNE(560),
NATURE_RUNE(561),
CHAOS_RUNE(562),
LAW_RUNE(563),
COSMIC_RUNE(564),
BLOOD_RUNE(565),
SOUL_RUNE(566),
ASTRAL(9075),
;
private int id;
Rune(int id) {
this.id = id;
}
private static final ArrayList<Integer> IDS = new ArrayList<>();
static {
for (Rune r : values()) {
IDS.add(r.id);
}
}
public static boolean isRune(int id) {
return IDS.contains(id);
}
}
Search for
Code:
if (childInterface.inventoryAmounts[item] == 0) {
Below add
Code:
if (childInterface.id == 24209) {
if (!Rune.isRune(itemId)) {
itemOpacity = 95;
}
}