Code:
package palidino76.rs2.io;
import palidino76.rs2.player.items.*;
import palidino76.rs2.player.Player;
import palidino76.rs2.*;
import palidino76.rs2.util.Misc;
public class Frames {
public void connecttofserver(Player p){
if(p == null || p.stream == null || p.disconnected[0]){
return;
}
p.stream.createFrame(115);
p.stream.writeByte(2);
}
public void sendSentPrivateMessage(Player p, long name, String message) {
byte[] bytes = new byte[message.length()];
Misc.encryptPlayerChat(bytes, 0, 0, message.length(), message.getBytes());
p.stream.createFrameVarSize(89);
p.stream.writeQWord(name);
p.stream.writeByte(message.length());
p.stream.writeBytes(bytes, bytes.length, 0);
p.stream.endFrameVarSize();
}
private static int messageCounter = 6;
public void sendReceivedPrivateMessage(Player p, long name, int rights, String message) {
int id = messageCounter++;
if(id > 16000000) {
id = 1;
}
byte[] bytes = new byte[message.length()+1];
bytes[0] = (byte) message.length();
Misc.encryptPlayerChat(bytes, 0, 1, message.length(), message.getBytes());
p.stream.createFrameVarSize(178);
p.stream.writeQWord(name);
p.stream.writeWord(1);
p.stream.writeByte(((id << 16) & 0xFF));
p.stream.writeByte(((id << 8 ) & 0xFF));
p.stream.writeByte(((id ) & 0xFF));
p.stream.writeByte(rights);
p.stream.writeBytes(bytes, bytes.length, 0);
p.stream.endFrameVarSize();
}
/**
*HD
*/
public void setTabhd(Player p, int tabId, int childId) {
setInterface(p, 1, 746, tabId, childId);
// System.out.println("Tabs Useing hd == "+ String.valueOf(p.useingHD));
}
public void setOverlayhd(Player p, int childId) {
setInterface(p, 1, 746, 5, childId);
}
public void removeOverlayhd(Player p) {
setInterface(p, 1, 746, 5, 56);
}
public void showInterfacehd(Player p, int childId) {
setInterface(p, 0, 746, 3, childId);
setInterface(p, 0, 746, 8, childId);
p.interfaceId = childId;
}
public void removeShownInterfacehd(Player p) {
setInterface(p, 1, 746, 3, 56);
p.interfaceId = -1;
}
/**
*
* Removing Normal interfaces
*
*/
public void RemovesetInterfaces(Player p) {
if (p == null || p.disconnected[0]) {
return;
}
setTab(p, 6, 670);
setTab(p, 11, 670); // Chat options
setTab(p, 68, 670); // Chatbox
setTab(p, 64, 670); // HP bar
setTab(p, 65, 670); // Prayer bar
setTab(p, 66, 670); // Energy bar
setTab(p, 67, 670);
setConfig(p, 1160, -1);
setTab(p, 8, 670); // Playername on chat
setTab(p, 73, 670); // Attack tab
setTab(p, 74, 670); // Skill tab
setTab(p, 75, 670); // Quest tab
setTab(p, 76, 670); // Inventory tab
setTab(p, 77, 670); // Equipment tab
setTab(p, 78, 670); // Prayer tab
setTab(p, 79, 670); // Magic tab
setTab(p, 80, 670); // Summoning tab <- Enabled
setTab(p, 81, 670); // Friend tab
setTab(p, 82, 670); // Ignore tab
setTab(p, 83, 670); // Clan tab
setTab(p, 84, 670); // Setting tab
setTab(p, 85, 670); // Emote tab
setTab(p, 86, 670); // Music tab
setTab(p, 87, 670); // Logout tab
setString(p, "Click here to log out<br>of DragonScape 508", 182, 0);
if(p.questStage >= 1)
{
setString(p, "<col=00fff0>Learning the Basics", 259, 2);
}
else
setString(p, "Learning the Basics", 259, 2);
}
public void setFullScreenInterfaces(Player p) {
if (p == null || p.disconnected[0]) {
return;
}
RemovesetInterfaces(p);
setInterface(p, 1, 549, 0, 746);
setInterface(p, 1, 746, 13, 748); //energy orb
setInterface(p, 1, 746, 14, 749); //energy orb
setInterface(p, 1, 746, 15, 750); //energy orb
setInterface(p, 1, 746, 16, 747); //summing orb
setInterface(p, 1, 746, 18, 751); //things below chatbox
setInterface(p, 1, 752, 8, 137); //chatbox
setInterface(p, 1, 746, 65, 752); //chatbox 752
setInterface(p, 1, 549, 0, 746); // Main interface
setInterface(p, 1, 746, 87, 92); // Attack tab
setInterface(p, 1, 746, 88, 320); // Skill tab
setInterface(p, 1, 746, 89, 274); // Quest tab
setInterface(p, 1, 746, 90, 149); // Inventory tab
setInterface(p, 1, 746, 91, 387); // Equipment tab
setInterface(p, 1, 746, 92, 271); // Prayer tab
setInterface(p, 1, 746, 93, 193); // Magic tab
setInterface(p, 1, 746, 94, 662); // Summoning tab
setInterface(p, 1, 746, 95, 550); // Friend tab
setInterface(p, 1, 746, 96, 551); // Ignore tab
setInterface(p, 1, 746, 97, 589); // Clan tab
setInterface(p, 1, 746, 98, 261); // Setting tab
setInterface(p, 1, 746, 99, 464); // Emote tab
setInterface(p, 1, 746, 100, 187); // Music tab
setInterface(p, 1, 746, 101, 182); // Logout tab
setInterface(p, 1, 752, 8, 137); // Chatbox
setInterface(p, 1, 746, 65, 752); // Chatbox 752
setInterface(p, 1, 746, 18, 751); // Settings below chatbox
setInterface(p, 1, 746, 13, 748); // HP orb
setInterface(p, 1, 746, 14, 749); // Prayer orb
setInterface(p, 1, 746, 15, 750); // Energy orb
setInterface(p, 1, 746, 12, 747); // Summoning orb
}
/**
*End of hd
*/
public void sendFriend(Player p, long name, int world) {
p.stream.createFrameVarSize(154);
p.stream.writeQWord(name);
p.stream.writeWord(world);
p.stream.writeByte(1);
if(world != 0) {
if(world == 66) {
p.stream.writeString("Online");
} else {
p.stream.writeString("RuneScape " + world);
}
}
p.stream.endFrameVarSize();
}
public void sendIgnores(Player p, long[] ignores) {
p.stream.createFrameVarSizeWord(240);
for(long ignore : ignores) {
p.stream.writeQWord(ignore);
}
p.stream.endFrameVarSizeWord();
}
/**
* Plays music for the player
* @param p The player the music will play for.
* @param song The musicId.
*/
public void playMusic(Player p, int Id) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.stream.createFrame(146);
p.stream.writeWordBigEndianA(Id);
}
public void setNPCId(Player p, int npcId, int interfaceId, int childId) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.stream.createFrame(6);
p.stream.writeWordBigEndian(interfaceId);
p.stream.writeWordBigEndian(childId);
p.stream.writeWordBigEndian(npcId);
}
public void animateInterfaceId(Player p, int emoteId, int interfaceId, int childId) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.stream.createFrame(245);
p.stream.writeWordBigEndian(interfaceId);
p.stream.writeWordBigEndian(childId);
p.stream.writeWord(emoteId);
}
public void addSoundEffect(Player player, int soundId, int bytes, int delay) {
for (Player p : Server.engine.players) {
if (p == null || player == null)
continue;
p.getByteVector().createFrame(119);
p.getByteVector().writeWord(soundId);
p.getByteVector().writeByte(bytes);
p.getByteVector().writeWord(delay);
}
}
public void playSoundInArea(int playX, int playY, int distance, int soundId, int j, int delay) {
for (Player p : Engine.players) {
if(p == null || p.stream == null || p.disconnected[0]){
continue;
}
if (Misc.getDistance(playX, playY, p.absX, p.absY) <= distance) {
p.stream.createFrame(119);
p.stream.writeWord(soundId);
p.stream.writeByte(j);
p.stream.writeWord(delay);
}
}
}
public void playSound(Player p, int soundId, int j, int delay) {
if(p == null || p.stream == null || p.disconnected[0]){
return;
}
p.stream.createFrame(119);
p.stream.writeWord(soundId);
p.stream.writeByte(j);
p.stream.writeWord(delay);
}
public void setHintIcon(Player p, int targetType, int targetId, int arrowId, int playerModel) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.stream.createFrame(227);
int offset = p.stream.outOffset;
p.stream.writeByte(targetType);
p.stream.writeByte(arrowId);
if (targetType == 1 || targetType == 10) {
p.stream.writeWord(targetId);
p.stream.outOffset += 3;
}
p.stream.writeWord(playerModel);
for (int i = (p.stream.outOffset - offset); i < 9; i++) {
p.stream.writeByte(0);
}
}
public void addObject(Player p, int objectId, int height, int objectX, int objectY, int face, int type) {
sendCoords(p, (objectX - ((p.mapRegionX - 6) * 8)), (objectY - ((p.mapRegionY - 6) * 8)));
int ot = ((type << 2) + (face & 3));
p.getByteVector().createFrame(30);
p.getByteVector().writeWordBigEndian(objectId);
p.getByteVector().writeByteA(0);
p.getByteVector().writeByteC(ot);
}
public void addStaticObject(int objectId, int height, int objectX, int objectY, int face, int type) {
for (Player p : Server.engine.players) {
if (p == null)
continue;
if (p.heightLevel == height)
addObject(p, objectId, height, objectX, objectY, 0, type);
}
}
public void addLists(Player p) {
if(p == null || p.stream == null || p.disconnected[0])
return;
p.getByteVector().createFrame(115);
p.getByteVector().writeByte(2);
}
public void addInterfaceItem(Player p, int interfaceid, int child, int itemsize, int itemid) {
if (p == null || p.stream == null)
return;
int inter = ((interfaceid * 65536) + child);
p.getByteVector().createFrame(35);
p.getByteVector().writeDWord_v2(inter);
p.getByteVector().writeDWordBigEndian(itemsize);
p.getByteVector().writeWordBigEndianA(itemid);
}
public void createStaticGraphic(Player p, int graphicId, int absX, int absY) {
if(p == null || p.stream == null || p.disconnected[0])
return;
sendCoords(p, (absX - ((p.mapRegionX - 6) * 8)), (absY - ((p.mapRegionY - 6) * 8)));
p.getByteVector().createFrame(248);
p.getByteVector().writeByte(0);
p.getByteVector().writeWord(graphicId);
p.getByteVector().writeByte(0);
p.getByteVector().writeWord(0);
}
/**
* Set either fullscreen or normal.
* @param p The Player which the frame should be created for.
* @param set The frame set, 548 for the default setup.
*/
public void setWindowPane(Player p, int set) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(239);
p.getByteVector().writeWord(set);
p.getByteVector().writeByteA(0);
}
/**
* Logs a player out.
* @param p The Player which the frame should be created for.
*/
public void logout(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(104);
}
/**
* Display an interface.
* <p>The various ids determines how the interface is displayed, from an overlay, to covering the chatbox, etc.
* @param p The Player which the frame should be created for.
* @param showId Sets the interface such as an overlay, etc.
* @param windowId What type of window you used, default should be 548.
* @param interfaceId Where to display it on the screen.
* @param childId The interface id to display.
*/
public void setInterface(Player p, int showId, int windowId, int interfaceId, int childId) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(93);
p.getByteVector().writeWord(childId);
p.getByteVector().writeByteA(showId);
p.getByteVector().writeWord(windowId);
p.getByteVector().writeWord(interfaceId);
}
/**
* Set a players click option.
* <p>The slot cannot be below 0 and cannot be above 8.
* @param p The Player which the frame should be created for.
* @param option The string to set the option to.
* @param slot The position to set the option on the player.
*/
public void setPlayerOption(Player p, String option, int slot) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSize(252);
p.getByteVector().writeByteC(1);
p.getByteVector().writeString(option);
p.getByteVector().writeByteC(slot);
p.getByteVector().endFrameVarSize();
}
/**
* Setting client configs.
* <p>This is used for setting prayers, running, etc.
* @param p The Player which the frame should be created for.
* @param id The config id to set.
* @param set What to set the config.
*/
public void setConfig(Player p, int id, int set) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(100);
p.getByteVector().writeWordA(id);
p.getByteVector().writeByteA(set);
}
public void setConfig2(Player p, int id, int set) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(161);
p.getByteVector().writeWord(id);
p.getByteVector().writeDWord_v1(set);
}
public void setBankOptions(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(223);
p.getByteVector().writeWord(496);
p.getByteVector().writeWordBigEndianA(0);
p.getByteVector().writeWordBigEndian(73);
p.getByteVector().writeWordBigEndian(762);
p.getByteVector().writeWordBigEndian(1278);
p.getByteVector().writeWordBigEndian(20);
p.getByteVector().createFrame(223);
p.getByteVector().writeWord(27);
p.getByteVector().writeWordBigEndianA(0);
p.getByteVector().writeWordBigEndian(0);
p.getByteVector().writeWordBigEndian(763);
p.getByteVector().writeWordBigEndian(1150);
p.getByteVector().writeWordBigEndian(18);
}
/**
* Creates a projectile. Can be used for magic, range etc.
* @param p The Player which the frame should be created for.
* @param offsetY The distance between caster and enemy Y
* @param offsetX The distance between caster and enemy X
* @param angle The starting place of the projectile
* @param speed The speed minus the distance making it set.
* @param gfxMoving The moving graphic ID
* @param startHeight The starting height
* @param endHeight The destination height
* @param lockon The NPC the missile is locked onto.
* @param npc if this is an npc and not a player set to true
* */
public void addProjectile(Player p, int casterY, int casterX, int offsetY, int offsetX, int angle,
int speed, int gfxMoving, int startHeight, int endHeight, int lockon, boolean npc) {
if (p == null || p.stream == null) {
return;
}
for (Player pl : Server.engine.players) {
if (pl != null) {
if (pl.heightLevel == p.heightLevel) {
sendCoords(pl, (casterX - ((pl.mapRegionX - 6) * 8)) - 3, (casterY - ((pl.mapRegionY - 6) * 8)) - 2);
pl.getByteVector().createFrame(112);
pl.getByteVector().writeByte(angle);
pl.getByteVector().writeByte(offsetX);
pl.getByteVector().writeByte(offsetY);
pl.getByteVector().writeWordBigEndian(lockon);
pl.getByteVector().writeWord(gfxMoving);
pl.getByteVector().writeByte(startHeight);
pl.getByteVector().writeByte(endHeight);
pl.getByteVector().writeWord(51);
pl.getByteVector().writeWord(speed);
pl.getByteVector().writeByte(16);
pl.getByteVector().writeByte(64);
}
}
}
}
public void addProjectile2(Player p, int casterY, int casterX, int offsetY, int offsetX, int angle,
int speed, int gfxMoving, int startHeight, int endHeight, int lockon, boolean npc) {
if (p == null || p.stream == null) {
return;
}
for (Player pl : Server.engine.players) {
if (pl != null) {
if (pl.heightLevel == p.heightLevel) {
sendCoords(pl, (casterX - ((pl.mapRegionX - 6) * 8)) - 3, (casterY - ((pl.mapRegionY - 6) * 8)) - 2);
pl.getByteVector().createFrame(112);
pl.getByteVector().writeByte(angle);
pl.getByteVector().writeByte(offsetX);
pl.getByteVector().writeByte(offsetY);
pl.getByteVector().writeWordBigEndian(lockon);
pl.getByteVector().writeWord(gfxMoving);
pl.getByteVector().writeByte(startHeight);
pl.getByteVector().writeByte(endHeight);
pl.getByteVector().writeWord(51);
pl.getByteVector().writeWord(speed);
pl.getByteVector().writeByte(35);
pl.getByteVector().writeByte(32);
}
}
}
}
public void addProjectile3(Player p, int casterY, int casterX, int offsetY, int offsetX, int angle,
int speed, int gfxMoving, int startHeight, int endHeight, int lockon, boolean npc) {
if (p == null || p.stream == null) {
return;
}
for (Player pl : Server.engine.players) {
if (pl != null) {
if (pl.heightLevel == p.heightLevel) {
sendCoords(pl, (casterX - ((pl.mapRegionX - 6) * 8)) - 3, (casterY - ((pl.mapRegionY - 6) * 8)) - 2);
pl.getByteVector().createFrame(112);
pl.getByteVector().writeByte(angle);
pl.getByteVector().writeByte(offsetX);
pl.getByteVector().writeByte(offsetY);
pl.getByteVector().writeWordBigEndian(lockon);
pl.getByteVector().writeWord(gfxMoving);
pl.getByteVector().writeByte(startHeight);
pl.getByteVector().writeByte(endHeight);
pl.getByteVector().writeWord(33);
pl.getByteVector().writeWord(speed);
pl.getByteVector().writeByte(16);
pl.getByteVector().writeByte(64);
}
}
}
}
public void addProjectile4(Player p, int casterY, int casterX, int offsetY, int offsetX, int angle,
int speed, int gfxMoving, int startHeight, int endHeight, int lockon, boolean npc) {
if (p == null || p.stream == null) {
return;
}
for (Player pl : Server.engine.players) {
if (pl != null) {
if (pl.heightLevel == p.heightLevel) {
sendCoords(pl, (casterX - ((pl.mapRegionX - 6) * 8)) - 3, (casterY - ((pl.mapRegionY - 6) * 8)) - 2);
pl.getByteVector().createFrame(112);
pl.getByteVector().writeByte(angle);
pl.getByteVector().writeByte(offsetX);
pl.getByteVector().writeByte(offsetY);
pl.getByteVector().writeWordBigEndian(lockon);
pl.getByteVector().writeWord(gfxMoving);
pl.getByteVector().writeByte(startHeight);
pl.getByteVector().writeByte(endHeight);
pl.getByteVector().writeWord(51);
pl.getByteVector().writeWord(speed);
pl.getByteVector().writeByte(0);
pl.getByteVector().writeByte(100);
}
}
}
}
public void addProjectile5(Player p, int casterY, int casterX, int offsetY, int offsetX, int angle,
int speed, int gfxMoving, int startHeight, int endHeight, int lockon, boolean npc) {
if (p == null || p.stream == null) {
return;
}
for (Player pl : Server.engine.players) {
if (pl != null) {
if (pl.heightLevel == p.heightLevel) {
sendCoords(pl, (casterX - ((pl.mapRegionX - 6) * 8)) - 3, (casterY - ((pl.mapRegionY - 6) * 8)) - 2);
pl.getByteVector().createFrame(112);
pl.getByteVector().writeByte(angle);
pl.getByteVector().writeByte(offsetX);
pl.getByteVector().writeByte(offsetY);
pl.getByteVector().writeWordBigEndian(lockon);
pl.getByteVector().writeWord(gfxMoving);
pl.getByteVector().writeByte(startHeight);
pl.getByteVector().writeByte(endHeight);
if (p.fightStyle != 3) {
pl.getByteVector().writeWord(21);
} else {
pl.getByteVector().writeWord(41);
}
pl.getByteVector().writeWord(speed);
pl.getByteVector().writeByte(16);
pl.getByteVector().writeByte(64);
}
}
}
}
/**
* Set the run energy on the client.
* @param p The Player which the frame should be created for.
*/
public void setEnergy(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(99);
p.getByteVector().writeByte(p.runEnergy);
}
/**
* Setting a tab.
* @param p The Player which the frame should be created for.
* @param tabId Which tab to display the interface on.
* @param childId The interface to display on the tab.
*/
public void setTab(Player p, int tabId, int childId) {
setInterface(p, 1, childId == 137 ? 752 : 548, tabId, childId);
}
/**
* Set the overlay to be displayed.
* @param p The Player which the frame should be created for.
* @param childId The interface id to display as an overlay.
*/
public void setOverlay(Player p, int childId) {
setInterface(p, 1, 548, 5, childId);
}
/**
* Remove any overlays that might be set.
* @param p The Player which the frame should be created for.
*/
public void removeOverlay(Player p) {
setInterface(p, 1, 548, 5, 56);
}
/**
* Display an interface on the main area in the screen.
* @param p The Player which the frame should be created for.
* @param childId the interface id to display.
*/
public void showInterface(Player p, int childId) {
p.interfaceId = childId;
if(!p.useingHD)
{
setInterface(p, 0, 548, 8, childId);
}
else if(p.useingHD)
{
showInterfacehd(p, childId);
}
}
/**
* Remove an interface on the main screen.
* @param p The Player which the frame should be created for.
*/
public void removeShownInterface(Player p) {
setInterface(p, 1, 548, 8, 56);
p.interfaceId = -1;
}
/**
* Display an interface on the chatbox.
* @param p The Player which the frame should be created for.
* @param childId The interface to display on the chatbox.
*/
public void showChatboxInterface(Player p, int childId) {
setInterface(p, 0, 752, 12, childId);
p.chatboxInterfaceId = childId;
}
/**
* Set the chatbox back removing any interfaces on it.
* @param p The Player which the frame should be created for.
*/
public void removeChatboxInterface(Player p) {
setConfig(p, 334, 1);
p.stream.createFrame(246);
p.stream.writeWord(752);
p.stream.writeWord(12);
p.chatboxInterfaceId = -1;
}
/**
* Set the inventory.
* @param p The Player which the frame should be created for.
* @param childId The interface to display on the inventory.
*/
public void setInventory(Player p, int childId) {
if(!p.useingHD) {
setInterface(p, 0, 548, 71, childId);
} else {
setInterface(p, 1, 746, 90, childId);
}
}
public void sethdtab(int childID) {
if(p.useingHD == true) {
setInterface(p, 1, 746, 87, childID); // Attack tab
} else if(p.useingHD == false) {
setTab(p, 73, childID);
}
}
/**
* Set interface defaults at login.
* @param p The Player which the frame should be created for.
*/
public void setInterfaces(Player p) {
if (p == null || p.disconnected[0]) {
return;
}
setTab(p, 6, 745);
setTab(p, 11, 751); // Chat options
setTab(p, 68, 752); // Chatbox
setTab(p, 64, 748); // HP bar
setTab(p, 65, 749); // Prayer bar
setTab(p, 66, 750); // Energy bar
setTab(p, 67, 747);
setConfig(p, 1160, -1);
setTab(p, 8, 137); // Playername on chat
setTab(p, 73, 92); // Attack tab
setTab(p, 74, 320); // Skill tab
setTab(p, 75, 274); // Quest tab
setTab(p, 76, 149); // Inventory tab
setTab(p, 77, 387); // Equipment tab
setTab(p, 78, 271); // Prayer tab
setTab(p, 79, 192); // Magic tab
setTab(p, 80, 716); // Summoning tab <- Enabled
setTab(p, 81, 550); // Friend tab
setTab(p, 82, 551); // Ignore tab
setTab(p, 83, 589); // Clan tab
setTab(p, 84, 261); // Setting tab
setTab(p, 85, 464); // Emote tab
setTab(p, 86, 187); // Music tab
setTab(p, 87, 182); // Logout tab
setString(p, "If u have finished Playing RanopScape then visit us soon as u can! we Wait for u!", 182, 0);
setString(p, "Log Out :(", 182, 6);
}
/**
* Send coordinates, used with other frames.
* @param p The Player which the frame should be created for.
* @param x The x coordinate.
* @param y The y coordinate.
*/
public void sendCoords(Player p, int x, int y) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(177);
p.getByteVector().writeByte(y);
p.getByteVector().writeByteS(x);
}
/**
* Creates an item on the ground at itemX and itemY.
* @param p The Player which the frame should be created for.
* @param itemId The item id to be displayed.
* @param itemAmt The amount the item stack size is.
* @param itemX The absolute x coordinate to display the item.
* @param itemY The absolute y coordinate to display the item.
* @param itemHeight The height level to set the item.
*/
public void createGroundItem(Player p, int itemId, int itemAmt, int itemX, int itemY, int itemHeight) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
if (Misc.getDistance(itemX, itemY, p.absX, p.absY) <= 60 && p.heightLevel == itemHeight) {
sendCoords(p, (itemX - ((p.mapRegionX - 6) * 8)), (itemY - ((p.mapRegionY - 6) * 8)));
p.getByteVector().createFrame(25);
p.getByteVector().writeWordBigEndianA(itemAmt);
p.getByteVector().writeByte(0);
p.getByteVector().writeWordBigEndianA(itemId);
}
}
/**
* Removes an item on the ground at itemX and itemY.
* @param p The Player which the frame should be created for.
* @param itemId The item id to remove.
* @param itemX The absolute x coordinate to remove the item.
* @param itemY The absolute y coordinate to remove the item.
* @param itemHeight The height level toe remove the item at.
*/
public void removeGroundItem(Player p, int itemId, int itemX, int itemY, int itemHeight) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
if(Misc.getDistance(itemX, itemY, p.absX, p.absY) <= 60 && p.heightLevel == itemHeight) {
sendCoords(p, (itemX - ((p.mapRegionX - 6) * 8)), (itemY - ((p.mapRegionY - 6) * 8)));
p.getByteVector().createFrame(201);
p.getByteVector().writeByte(0);
p.getByteVector().writeWord(itemId);
}
}
/**
* Remove Player Equipment
* @param p The player which the frame should be created for.
* @param index the index of the player
*/
public void removeEquipment(Player p, int itemId, int index) {
if(p == null || itemId <= 0 || index < 0 || index > 13 || p.stream == null)
{
return;
}
PlayerItems pi = new PlayerItems();
if(!pi.addItem(p, p.equipment[index], p.equipmentN[index]))
{
sendMessage(p, "Not enough space in your inventory.");
return;
}
p.equipment[index] = -1;
p.equipmentN[index] = 0;
p.getByteVector().createFrameVarSizeWord(135);
p.getByteVector().writeByte(1);
p.getByteVector().writeByte(131);
p.getByteVector().writeByte(0);
p.getByteVector().writeByte(28);
p.getByteVector().writeWord(28);
p.getByteVector().writeByte(index);
p.getByteVector().writeWord(0);
p.getByteVector().writeByte(0);
p.getByteVector().endFrameVarSizeWord();
p.appearanceUpdateReq = true;
p.updateReq = true;
p.calculateEquipmentBonus();
PlayerWeapon pweapon = new PlayerWeapon(p);
pweapon.setWeapon();
}
/**
* Send players stat.
* @param p The Player which the frame should be created for.
* @param lvlId The stat id to send.
*/
public void setSkillLvl(Player p, int lvlId) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(217);
p.getByteVector().writeByteC(p.skillLvl[lvlId]);
p.getByteVector().writeDWord_v2(p.skillXP[lvlId]);
p.getByteVector().writeByteC(lvlId);
}
/**
* Set item display on an interface.
* @param p The Player which the frame should be created for.
* @param interfaceId The interface to display the items on.
* @param childId The child interface on the main interface.
* @param itemArray The item id array to set on the interface.
* @param itemAmt The item array to go with the itemArray.
*/
public void setItems(Player p, int interfaceId, int childId, int type, int[] itemArray, int[] itemAmt) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSizeWord(255);
p.getByteVector().writeWord(interfaceId);
p.getByteVector().writeWord(childId);
p.getByteVector().writeWord(type);
p.getByteVector().writeWord(itemArray.length);
for (int i = 0; i < itemArray.length; i++) {
if (itemAmt[i] > 254) {
p.getByteVector().writeByteS(255);
p.getByteVector().writeDWord_v2(itemAmt[i]);
} else {
p.getByteVector().writeByteS(itemAmt[i]);
}
p.getByteVector().writeWordBigEndian(itemArray[i] + 1);
}
p.getByteVector().endFrameVarSizeWord();
}
/**
* Set interface configs.
* <p>This is used to do things such as hiding and displaying the special attack bar.
* @param p The Player which the frame should be created for.
* @param interfaceId The interface to the set the config with.
* @param childId The child that belongs to the interface to change.
* @param 1 for true, 0 for false.
*/
public void setInterfaceConfig(Player p, int interfaceId, int childId, boolean set) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrame(59);
p.getByteVector().writeByteC(set ? 1 : 0);
p.getByteVector().writeWord(childId);
p.getByteVector().writeWord(interfaceId);
}
/**
* Display a message in the chatbox.
* @param p The Player which the frame should be created for.
* @param s The message to display in the chatbox.
*/
public void sendMessage(Player p, String s) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSize(218);
p.getByteVector().writeString(s);
p.getByteVector().endFrameVarSize();
}
/**
* Set a string on an interface.
* @param p The Player which the frame should be created for.
* @param str The string to set on the interface.
* @param interfaceId The interface to set the text on.
* @param childId The interface's child to set the text on.
*/
public void setString(Player p, String str, int interfaceId, int childId) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
int sSize = str.length() + 5;
p.getByteVector().createFrame(179);
p.getByteVector().writeByte(sSize / 256);
p.getByteVector().writeByte(sSize % 256);
p.getByteVector().writeString(str);
p.getByteVector().writeWord(childId);
p.getByteVector().writeWord(interfaceId);
}
/**
* Send this player's updated coordinates.
* @param p The Player which the frame should be created for.
*/
public void updateMovement(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSizeWord(216);
p.getByteVector().initBitAccess();
p.getByteVector().writeBits(1, 1);
if (p.runDir == -1) {
p.getByteVector().writeBits(2, 1);
p.getByteVector().writeBits(3, p.walkDir);
p.getByteVector().writeBits(1, p.updateReq ? 1 : 0);
} else {
p.getByteVector().writeBits(2, 2);
p.getByteVector().writeBits(3, p.runDir);
p.getByteVector().writeBits(3, p.walkDir);
p.getByteVector().writeBits(1, p.updateReq ? 1 : 0);
if (p.runEnergy > 0) {
p.runEnergyUpdateReq = true;
p.runEnergy--;
} else {
p.isRunning = false;
}
}
}
/**
* Tell the client this player isn't moving.
* @param p The Player which the frame should be created for.
*/
public void noMovement(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSizeWord(216);
p.getByteVector().initBitAccess();
p.getByteVector().writeBits(1, p.updateReq ? 1 : 0);
if (p.updateReq) {
p.getByteVector().writeBits(2, 0);
}
}
/**
* Changes the coordinates this player is standing at.
* @param p The Player which the frame should be created for.
*/
public void teleport(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSizeWord(216);
p.getByteVector().initBitAccess();
p.getByteVector().writeBits(1, 1);
p.getByteVector().writeBits(2, 3);
p.getByteVector().writeBits(7, p.currentX);
p.getByteVector().writeBits(1, 1);
p.getByteVector().writeBits(2, p.heightLevel);
p.getByteVector().writeBits(1, p.updateReq ? 1 : 0);
p.getByteVector().writeBits(7, p.currentY);
}
/**
* Send the map region and other positioning info to the client.
* @param p The Player which the frame should be created for.
*/
public void setMapRegion(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.getByteVector().createFrameVarSizeWord(142);
p.getByteVector().writeWordA(p.mapRegionX);
p.getByteVector().writeWordBigEndianA(p.currentY);
p.getByteVector().writeWordA(p.currentX);
boolean forceSend = true;
if ((((p.mapRegionX / 8) == 48) || ((p.mapRegionX / 8) == 49)) && ((p.mapRegionY / 8) == 48)) {
forceSend = false;
}
if (((p.mapRegionX / 8) == 48) && ((p.mapRegionY / 8) == 148)) {
forceSend = false;
}
for (int xCalc = (p.mapRegionX - 6) / 8; xCalc <= ((p.mapRegionX + 6) / 8); xCalc++) {
for (int yCalc = (p.mapRegionY - 6) / 8; yCalc <= ((p.mapRegionY + 6) / 8); yCalc++) {
int region = yCalc + (xCalc << 1786653352);
if (forceSend || ((yCalc != 49) && (yCalc != 149) && (yCalc != 147) && (xCalc != 50) && ((xCalc != 49) || (yCalc != 47)))) {
int[] mapData = Engine.mapData.getMapData(region);
if (mapData == null) {
p.setCoords(3254, 3420, 0);
sendMessage(p, "You got teleported to varrock due to Mapdata missing.");
return;
}
p.getByteVector().writeDWord(mapData[0]);
p.getByteVector().writeDWord(mapData[1]);
p.getByteVector().writeDWord(mapData[2]);
p.getByteVector().writeDWord(mapData[3]);
}
}
}
p.getByteVector().writeByteC(p.heightLevel);
p.getByteVector().writeWord(p.mapRegionY);
p.getByteVector().endFrameVarSizeWord();
}
}