Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.model.shops;
- import server.Config;
- import server.Server;
- import server.model.items.Item;
- import server.model.players.Client;
- public class ShopAssistant {
- private Client c;
- public ShopAssistant(Client client) {
- this.c = client;
- }
- /**
- *Shops
- **/
- public void openPlayerShop(Client o) {
- if (o == null || o.properLogout)
- return;
- c.getItems().resetItems(3823);
- resetShop(o);
- c.myShopClient = o;
- c.myShopId = 7390;
- c.isShopping = true;
- c.getPA().sendFrame248(3824, 3822);
- c.getPA().sendFrame126(o.playerShopTitle, 3901);
- }
- public int[] fixArray(int[] array) {
- int arrayPos = 0;
- int[] newArray = new int[array.length];
- for (int x = 0; x < array.length; x++) {
- if (array[x] != 0) {
- newArray[arrayPos] = array[x];
- arrayPos++;
- }
- }
- return newArray;
- }
- public void fixShop(Client o) {
- o.playerShop = fixArray(o.playerShop);
- o.playerShopN = fixArray(o.playerShopN);
- o.playerShopP = fixArray(o.playerShopP);
- }
- public void resetShop(Client o) {
- synchronized (c) {
- fixShop(o);
- for (int x = 0; x < o.playerShop.length; x++) {
- if (o.playerShopN[x] <= 0) {
- o.playerShop[x] = 0;
- }
- }
- int TotalItems = 0;
- for (int i = 0; i < o.playerShop.length; i++) {
- if (o.playerShop[i] > 0) {
- TotalItems++;
- }
- }
- if (TotalItems > o.playerShop.length) {
- TotalItems = o.playerShop.length;
- }
- c.getOutStream().createFrameVarSizeWord(53);
- c.getOutStream().writeWord(3900);
- c.getOutStream().writeWord(TotalItems);
- int TotalCount = 0;
- for (int i = 0; i < o.playerShop.length; i++) {
- if (o.playerShop[i] > 0) {
- if (o.playerShopN[i] > 254) {
- c.getOutStream().writeByte(255);
- c.getOutStream().writeDWord_v2(o.playerShopN[i]);
- } else {
- c.getOutStream().writeByte(o.playerShopN[i]);
- }
- c.getOutStream().writeWordBigEndianA((o.playerShop[i] + 1));
- TotalCount++;
- }
- if (TotalCount > TotalItems) {
- break;
- }
- }
- c.getOutStream().endFrameVarSizeWord();
- c.flushOutStream();
- }
- }
- public void updatePlayerShop() {
- for (int i = 1; i < Config.MAX_PLAYERS; i++) {
- if (Server.playerHandler.players[i] != null) {
- if (Server.playerHandler.players[i].isShopping == true
- && Server.playerHandler.players[i].myShopId == c.myShopId
- && i != c.playerId) {
- Client sh = (Client) Server.playerHandler.players[i];
- //sh.getShops().openShop(sh.myShopId);
- Server.playerHandler.players[i].updateShop = true;
- }
- }
- }
- }
- public void updatePlayerOwnedShop(Client x) {
- if (x == null)
- return;
- for (int i = 1; i < Config.MAX_PLAYERS; i++) {
- if (Server.playerHandler.players[i] != null) {
- if (Server.playerHandler.players[i].myShopClient != null) {
- if (x.playerName
- .equals(Server.playerHandler.players[i].myShopClient.playerName)) {
- Client sh = (Client) Server.playerHandler.players[i];
- sh.getShops().openPlayerShop(x);
- }
- }
- }
- }
- }
- public void openShop(int ShopID){
- c.getItems().resetItems(3823);
- resetShop(ShopID);
- c.isShopping = true;
- c.myShopId = ShopID;
- c.getPA().sendFrame248(3824, 3822);
- c.getPA().sendFrame126(Server.shopHandler.ShopName[ShopID], 3901);
- if (ShopID == 29 || ShopID == 36)
- {
- c.getPA().sendFrame126("More", 19680);
- }
- else if (ShopID == 34 || ShopID == 37)
- {
- c.getPA().sendFrame126("Less", 19680);
- }
- else if (ShopID == 32)
- {
- c.getPA().sendFrame126("Exchange", 19680);
- c.canExchange = true;
- }
- else
- {
- Server.playerHandler.CantSell = false;
- c.canExchange = false;
- c.getPA().sendFrame126("Player Stock", 19680);
- }
- if (ShopID == 38)
- c.getPA().sendFrame126("Voting Shop - You have " + c.getVotePoints() + " Voting Points", 3901);
- if (ShopID == 29 || ShopID == 34)
- c.getPA().sendFrame126("Pk Points Shop - You have " + c.getZPoints() + " Pk Points", 3901);
- if (ShopID == 7)
- c.getPA().sendFrame126("Dragon Points Shop - You have " + c.getdragonPoints() + " Dragon Points", 3901);
- if (ShopID == 30)
- c.getPA().sendFrame126("Slayer Points Shop - You have " + c.getslayerPoints() + " Slayer Points", 3901);
- }
- public boolean shopSellsItem(int itemID) {
- for (int i = 0; i < Server.shopHandler.ShopItems.length; i++) {
- if(itemID == (Server.shopHandler.ShopItems[c.myShopId][i] - 1)) {
- return true;
- }
- }
- return false;
- }
- /**public void updatePlayerShop() {
- for (int i = 1; i < Config.MAX_PLAYERS; i++) {
- if (Server.playerHandler.players[i] != null) {
- if (Server.playerHandler.players[i].isShopping == true && Server.playerHandler.players[i].myShopId == c.myShopId && i != c.playerId) {
- Server.playerHandler.players[i].updateShop = true;
- Server.playerHandler.players[i].isShopping = false;
- }
- }
- }
- }*/
- public void updateshop(int i){
- resetShop(i);
- }
- public void resetShop(int ShopID) {
- //synchronized(c) {
- int TotalItems = 0;
- for (int i = 0; i < Server.shopHandler.MaxShopItems; i++) {
- if (Server.shopHandler.ShopItems[ShopID][i] > 0) {
- TotalItems++;
- }
- }
- if (TotalItems > Server.shopHandler.MaxShopItems) {
- TotalItems = Server.shopHandler.MaxShopItems;
- }
- c.getOutStream().createFrameVarSizeWord(53);
- c.getOutStream().writeWord(3900);
- c.getOutStream().writeWord(TotalItems);
- int TotalCount = 0;
- for (int i = 0; i < Server.shopHandler.ShopItems.length; i++) {
- if (Server.shopHandler.ShopItems[ShopID][i] > 0 || i <= Server.shopHandler.ShopItemsStandard[ShopID]) {
- if (Server.shopHandler.ShopItemsN[ShopID][i] > 254) {
- c.getOutStream().writeByte(255);
- c.getOutStream().writeDWord_v2(Server.shopHandler.ShopItemsN[ShopID][i]);
- } else {
- c.getOutStream().writeByte(Server.shopHandler.ShopItemsN[ShopID][i]);
- }
- if (Server.shopHandler.ShopItems[ShopID][i] > Config.ITEM_LIMIT || Server.shopHandler.ShopItems[ShopID][i] < 0) {
- Server.shopHandler.ShopItems[ShopID][i] = Config.ITEM_LIMIT;
- }
- c.getOutStream().writeWordBigEndianA(Server.shopHandler.ShopItems[ShopID][i]);
- TotalCount++;
- }
- if (TotalCount > TotalItems)
- break;
- }
- c.getOutStream().endFrameVarSizeWord();
- c.flushOutStream();
- //}
- }
- public String getItemDescription(int ItemID) {
- String stuff = "NULL";
- for (int i = 0; i < Config.ITEM_LIMIT; i++) {
- if (Server.itemHandler.ItemList[i] != null) {
- if (Server.itemHandler.ItemList[i].itemId == ItemID) {
- stuff = Server.itemHandler.ItemList[i].itemDescription;
- }
- }
- }
- return stuff;
- }
- public double getItemWeight(int ItemID) {
- double itmWeight = 0;
- for (int i = 0; i < Config.ITEM_LIMIT; i++) {
- if (Server.itemHandler.ItemList[i] != null) {
- if (Server.itemHandler.ItemList[i].itemId == ItemID) {
- itmWeight = Server.itemHandler.ItemList[i].itemWeight;
- }
- }
- }
- return itmWeight;
- }
- public double getItemWeight2(int ItemID) {
- double itmWeight2 = 0;
- for (int i = 0; i < Config.ITEM_LIMIT; i++) {
- if (Server.itemHandler.ItemList[i] != null) {
- if (Server.itemHandler.ItemList[i].itemId == ItemID) {
- itmWeight2 = Server.itemHandler.ItemList[i].itemWeight2;
- }
- }
- }
- return itmWeight2;
- }
- public double getItemShopValue(int ItemID, int Type, int fromSlot) {
- double ShopValue = 1;
- double Overstock = 0;
- double TotPrice = 0;
- for (int i = 0; i < Config.ITEM_LIMIT; i++) {
- if (Server.itemHandler.ItemList[i] != null) {
- if (Server.itemHandler.ItemList[i].itemId == ItemID) {
- ShopValue = Server.itemHandler.ItemList[i].ShopValue;
- }
- }
- }
- TotPrice = ShopValue;
- if (Server.shopHandler.ShopBModifier[c.myShopId] == 1) {
- TotPrice *= 1;
- TotPrice *= 1;
- if (Type == 1) {
- TotPrice *= 1;
- }
- } else if (Type == 1) {
- TotPrice *= 1;
- }
- return TotPrice;
- }
- public int getItemShopValue(int itemId) {
- for (int i = 0; i < Config.ITEM_LIMIT; i++) {
- if (Server.itemHandler.ItemList[i] != null) {
- if (Server.itemHandler.ItemList[i].itemId == itemId) {
- return (int)Server.itemHandler.ItemList[i].ShopValue;
- }
- }
- }
- return 0;
- }
- /**
- *buy item from shop (Shop Price)
- **/
- public void buyFromShopPrice(int removeId, int removeSlot){
- if (c.myShopId == 7390 && c.myShopClient != null
- && !c.myShopClient.playerName.equals(c.playerName)) {
- int value = c.myShopClient.playerShopP[removeSlot];
- String add = "";
- if (value >= 1000 && value < 1000000) {
- add = " (" + (value / 1000) + "K)";
- } else if (value >= 1000000) {
- add = " (" + (value / 1000000) + " million)";
- }
- c.sendMessage(c.getItems().getItemName(removeId)
- + ": currently costs " + value + " coins." + add);
- return;
- } else if (c.myShopId == 7390 && c.myShopClient != null
- && c.myShopClient.playerName.equals(c.playerName)) {
- c.sendMessage(c.getItems().getItemName(removeId)
- + ": currently costs " + c.playerShopP[removeSlot]
- + " coins.");
- return;
- }
- int ShopValue = (int)Math.floor(getItemShopValue(removeId, 0, removeSlot));
- ShopValue *= 1;
- String ShopAdd = "";
- if (c.myShopId == 18 || c.myShopId == 29 || c.myShopId == 38 || c.myShopId == 34)
- {
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + getSpecialItemValue(removeId) + " Pk Points.");
- return;
- }
- if (c.myShopId == 15) {
- c.sendMessage("This item current costs " + c.getItems().getUntradePrice(removeId) + " coins.");
- return;
- }
- if (c.myShopId == 7) {
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + getSpecialItemValue(removeId) + " Dragon points.");
- return;
- }
- if (c.myShopId == 30) {
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + getSpecialItemValue(removeId) + " Slayer points.");
- return;
- }
- if (c.myShopId == 48) {
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + getSpecialItemValue(removeId) + " Slayer points.");
- return;
- }
- int RVK = (int)(((ShopValue) + (0.5 * 1000)) / 1000);
- int RVM = (int)(((ShopValue) + (0.5 * 1000000)) / 1000000);
- if (ShopValue >= 1000 && ShopValue < 1000000) {
- ShopAdd = " (" + RVK + "K)";
- } else if (ShopValue >= 1000000) {
- ShopAdd = " (" + RVM + "M)";
- }
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs "+ShopValue+" coins"+ShopAdd);
- }
- public int getSpecialItemValue(int id) {
- switch (id) {
- case 15017:
- return 75;
- case 537:
- return 2;
- case 6733:
- return 30;
- case 6737:
- return 30;
- case 6731:
- return 30;
- case 18353:
- return 120;
- case 18349:
- return 120;
- case 18351:
- return 120;
- case 18355:
- return 120;
- case 18357:
- return 120;
- case 15243:
- return 2;
- ///slay helm stuff
- case 4164:
- case 4166:
- case 4168:
- case 4551:
- return 10;
- case 15488:
- case 15490:
- case 8921:
- return 100;
- case 13736:
- case 13738:
- case 13740:
- case 13742:
- case 13744:
- return 100;
- case 10828:
- return 15;
- case 20072:
- return 10;
- case 15441:
- return 15;
- case 15442:
- return 15;
- case 15443:
- return 15;
- case 15444:
- return 15;
- case 11284:
- return 40;
- case 14484:
- case 19780:
- return 200;
- case 6920:
- return 20;
- case 11732:
- return 10;
- case 13890:
- return 100;
- case 13870:
- case 13876:
- return 100;
- case 13873:
- return 100;
- case 13899:
- return 100;
- case 1419:
- return 500;
- case 1961:
- return 200;
- case 15332:
- return 1;
- case 19272:
- case 19275:
- case 19278:
- case 13107:
- case 13109:
- case 13111:
- case 13113:
- case 13115:
- case 13858:
- case 13861:
- case 13864:
- case 13896:
- case 13884:
- case 13887:
- case 13893:
- case 13905:
- case 13867:
- return 100;
- case 13883:
- case 13879:
- return 2;
- case 19281:
- return 1000;
- case 19284:
- return 2000;
- case 19287:
- return 3000;
- case 19290:
- return 4000;
- case 19293:
- return 10000;
- case 19296:
- return 5000;
- case 19299:
- return 6000;
- case 19302:
- return 7000;
- case 19305:
- return 8000;
- case 10499:
- return 20;
- case 8845:
- return 5;
- case 8847:
- return 15;
- case 8848:
- return 20;
- case 8849:
- case 8850:
- return 25;
- case 10531:
- case 10533:
- case 10534:
- case 10537:
- return 50;
- case 11694:
- return 80;
- case 6585:
- return 10;
- case 15051:
- return 300;
- case 11235:
- return 50;
- case 4151:
- return 30;
- case 15039:
- return 1000;
- case 7462:
- return 10;
- case 15241:
- return 200;
- case 15272:
- return 10;
- case 2528:
- return 250;
- //Donator Sets
- //Guthix
- case 11926:
- return 0;
- case 11932:
- return 0;
- //Zammy
- case 11930:
- return 0;
- case 11936:
- return 0;
- //Sara
- case 11928:
- return 0;
- case 11934:
- return 0;
- //Aditional Items
- //Chest key
- case 432:
- return 350;
- case 1044:
- return 175;
- case 1042:
- return 250;
- case 1040:
- return 175;
- case 1038:
- return 200;
- case 1046:
- return 150;
- case 1048:
- return 200;
- case 1050:
- return 225;
- case 1053:
- return 150;
- case 1055:
- return 175;
- case 1057:
- return 200;
- case 10547:
- case 10548:
- case 10549:
- case 10550:
- case 10551:
- case 10555:
- return 10;
- case 11664:
- return 20;
- case 11663:
- return 20;
- case 11665:
- return 20;
- case 8842:
- return 20;
- case 8840:
- case 8839:
- return 40;
- case 6570:
- return 10;
- case 11696:
- return 80;
- case 11698:
- return 80;
- case 11700:
- return 80;
- case 11730:
- return 100;
- case 15001:
- return 160;
- case 11720:
- return 60;
- case 6199:
- return 100;
- case 4671:
- return 250;
- case 3062:
- return 150;
- case 11722:
- return 60;
- case 11718:
- return 60;
- case 12680:
- return 10;
- case 11726:
- return 60;
- case 11724:
- case 11728:
- return 60;
- case 13902:
- return 100;
- case 11283:
- return 120;
- case 15018:
- case 15019:
- case 15020:
- return 10;
- case 6914:
- case 6989:
- case 6924:
- case 6922:
- case 6918:
- case 6916:
- case 6889:
- return 250;
- //torva etc
- case 13362:
- return 200;
- case 13360:
- return 200;
- case 13358:
- return 200;
- case 13355:
- return 150;
- case 13354:
- return 150;
- case 13352:
- return 150;
- case 13350:
- return 150;
- case 13348:
- return 150;
- case 13346:
- return 150;
- case 962:
- return 250;
- case 1959:
- return 45;
- case 981:
- return 150;
- case 1037:
- return 350;
- case 19335:
- return 30;
- case 15220:
- return 10;
- case 12674:
- return 30;
- case 15492:
- return 50;
- //Primal
- case 16293:
- return 30;
- case 16359:
- return 30;
- case 16711:
- return 70;
- case 17259:
- return 80;
- case 16733:
- return 75;
- case 16667:
- return 70;
- case 16689:
- return 70;
- case 17361:
- return 75;
- case 16403:
- return 50;
- case 16425:
- return 70;
- case 15773:
- return 60;
- case 16909:
- return 60;
- case 16955:
- return 60;
- case 20075: //Rainbow phat
- return 350;
- case 18359:
- return 120;
- case 19748:
- return 25;
- case 11846:
- return 35;
- case 11848:
- return 35;
- case 15328:
- return 2;
- case 10925:
- return 1;
- case 18361:
- return 50;
- case 18363:
- return 50;
- }
- return 0;
- }
- /**
- *Sell item to shop (Shop Price)
- **/
- public void sellToShopPrice(int removeId, int removeSlot) {
- if (c.myShopId == 7390) {
- c.sendMessage("You choose your price when using POS.");
- return;
- }
- for (int i : Config.ITEM_SELLABLE) {
- if(c.myShopId == 38) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(removeId).toLowerCase()+" to this store.");
- return;
- }
- if(c.myShopId == 7 || c.myShopId == 29 || c.myShopId == 34 || c.myShopId == 30) {
- c.sendMessage("You can't sell to this store.");
- return;
- }
- if (i == removeId) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(removeId).toLowerCase()+".");
- return;
- }
- }
- /*if(c.isDonator == 0) {
- for (int i : Config.ITEM_DONATOR) {
- if (i == removeId || i+1 == removeId) {
- c.sendMessage("You can't sell a "+c.getItems().getItemName(removeId).toLowerCase()+" unless you are a donator.");
- return;
- }
- }
- }*/
- boolean IsIn = false;
- if (Server.shopHandler.ShopSModifier[c.myShopId] > 1) {
- for (int j = 0; j <= Server.shopHandler.ShopItemsStandard[c.myShopId]; j++) {
- if (removeId == (Server.shopHandler.ShopItems[c.myShopId][j] - 1)) {
- IsIn = true;
- break;
- }
- }
- } else {
- IsIn = true;
- }
- if (Server.playerHandler.getCantSell() == true || IsIn == false) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(removeId).toLowerCase()+" to this store.");
- } else {
- int ShopValue = (int)Math.floor(getItemShopValue(removeId, 1, removeSlot));
- String ShopAdd = "";
- if (ShopValue >= 1000 && ShopValue < 1000000) {
- ShopAdd = " (" + (ShopValue / 1000) + "K)";
- } else if (ShopValue >= 1000000) {
- ShopAdd = " (" + (ShopValue / 1000000) + " million)";
- }
- if (c.myShopId == 2229 || c.myShopId == 3334)
- c.sendMessage(c.getItems().getItemName(removeId)+": shop will buy for "+getSpecialItemValue(removeId)+" Pk Points.");
- else
- c.sendMessage(c.getItems().getItemName(removeId)+": shop will buy for "+ShopValue+" coins"+ShopAdd);
- }
- }
- public boolean sellItem(int itemID, int fromSlot, int amount) {
- if (c.myShopId == 7390) {
- for (int i : Config.ITEM_TRADEABLE) {
- if (i == itemID) {
- c.sendMessage("You can't sell this item.");
- return false;
- }
- }
- if (c.playerName.equals(c.myShopClient.playerName)) {
- c.sellingId = itemID;
- c.sellingN = amount;
- c.sellingS = fromSlot;
- c.xInterfaceId = 7390;
- c.outStream.createFrame(27);
- } else {
- c.sendMessage("You can only sell items on your own store.");
- }
- return true;
- }
- if(c.inTrade) {
- c.sendMessage("You cant sell items to the shop while your in trade!");
- return false;
- }
- if (c.myShopId == 7 || c.myShopId == 29 || c.myShopId == 34 || c.myShopId == 30) {
- return false;
- }
- if (c.myShopId == 38){
- c.sendMessage("You can't sell "+c.getItems().getItemName(itemID).toLowerCase()+" to this store.");
- return false;
- }
- if (c.myShopId == 14)
- return false;
- for (int i : Config.ITEM_SELLABLE) {
- if (i == itemID) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(itemID).toLowerCase()+".");
- return false;
- }
- }
- /*if(c.isDonator == 0) {
- for (int i : Config.ITEM_DONATOR) {
- if (i == itemID || i+1 == itemID) {
- c.sendMessage("You can't sell a "+c.getItems().getItemName(itemID).toLowerCase()+".");
- return false;
- }
- }
- }*/
- if (amount > 0 && itemID == (c.playerItems[fromSlot] - 1)) {
- if (Server.shopHandler.ShopSModifier[c.myShopId] > 1) {
- boolean IsIn = false;
- for (int i = 0; i <= Server.shopHandler.ShopItemsStandard[c.myShopId]; i++) {
- if (itemID == (Server.shopHandler.ShopItems[c.myShopId][i] - 1)) {
- IsIn = true;
- break;
- }
- }
- if (IsIn == false) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(itemID).toLowerCase()+" to this store.");
- return false;
- }
- }
- if (amount > c.playerItemsN[fromSlot] && (Item.itemIsNote[(c.playerItems[fromSlot] - 1)] == true || Item.itemStackable[(c.playerItems[fromSlot] - 1)] == true)) {
- amount = c.playerItemsN[fromSlot];
- } else if (amount > c.getItems().getItemAmount(itemID) && Item.itemIsNote[(c.playerItems[fromSlot] - 1)] == false && Item.itemStackable[(c.playerItems[fromSlot] - 1)] == false) {
- amount = c.getItems().getItemAmount(itemID);
- }
- //double ShopValue;
- //double TotPrice;
- int TotPrice2 = 0;
- //int Overstock;
- for (int i = amount; i > 0; i--) {
- TotPrice2 = (int)Math.floor(getItemShopValue(itemID, 1, fromSlot));
- if (c.getItems().freeSlots() > 0 || c.getItems().playerHasItem(995) || c.myShopId == 29 || c.myShopId == 34 || c.myShopId == 7 || c.myShopId == 30) {
- if (Item.itemIsNote[itemID] == false) {
- c.getItems().deleteItem(itemID, c.getItems().getItemSlot(itemID), 1);
- } else {
- c.getItems().deleteItem(itemID, fromSlot, 1);
- }
- if (c.myShopId == 29 || c.myShopId == 34) {
- c.ZPoints += getSpecialItemValue(itemID);
- c.getPA().sendFrame126("Pk Points Shop - You have " + c.getZPoints() + " Pk Points", 3901);
- c.getPA().sendFrame126("@whi@PK Points: @gre@"+c.getZPoints(), 29168);
- }
- if (c.myShopId == 30) {
- c.slayerPoints += getSpecialItemValue(itemID);
- c.getPA().sendFrame126("Slayer Points Shop - You have " + c.getslayerPoints() + " Slayer Points", 3901);
- c.getPA().sendFrame126("@whi@Slayer Streak: @gre@"+c.getSlayerStreak(), 29166);
- }
- if (c.myShopId == 7) {
- c.dragonPoints += getSpecialItemValue(itemID);
- c.getPA().sendFrame126("Dragon Point Shop - You have " + c.getdragonPoints() + " Dragon Points", 3901);
- c.getPA().sendFrame126("@whi@Dragon Points: @gre@"+c.getdragonPoints(), 29167);
- } else {
- c.getItems().addItem(995, TotPrice2);
- if(c.myShopId != 1)
- addShopItem(itemID, 1);
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- }
- c.getItems().resetItems(3823);
- resetShop(c.myShopId);
- updatePlayerShop();
- return true;
- }
- return true;
- }
- public boolean addShopItem(int itemID, int amount) {
- boolean Added = false;
- if (amount <= 0) {
- return false;
- }
- if (Item.itemIsNote[itemID] == true) {
- itemID = c.getItems().getUnnotedItem(itemID);
- }
- for (int i = 0; i < Server.shopHandler.ShopItems.length; i++) {
- if ((Server.shopHandler.ShopItems[c.myShopId][i] - 1) == itemID) {
- //Server.shopHandler.ShopItemsN[c.myShopId][i] += amount;DISABLED FOR UNLIMITED STOCKS
- Added = true;
- }
- }
- if (Added == false) {
- for (int i = 0; i < Server.shopHandler.ShopItems.length; i++) {
- if (Server.shopHandler.ShopItems[c.myShopId][i] == 0) {
- Server.shopHandler.ShopItems[c.myShopId][i] = (itemID + 1);
- //Server.shopHandler.ShopItemsN[c.myShopId][i] = amount;DISABLED FOR UNLIMITED STOCKS
- Server.shopHandler.ShopItemsDelay[c.myShopId][i] = 0;
- break;
- }
- }
- }
- return true;
- }
- public long buyDelay;
- public boolean buyItem(int itemID, int fromSlot, int amount) {
- if (c.myShopId == 7390 && c.myShopClient != null && !c.myShopClient.properLogout && !c.playerName.equals(c.myShopClient.playerName)) {
- if (c.myShopClient.playerShop[fromSlot] != itemID)
- return false;
- int bought = 0;
- int price = c.myShopClient.playerShopP[fromSlot];
- if (amount > c.myShopClient.playerShopN[fromSlot])
- amount = c.myShopClient.playerShopN[fromSlot];
- for (int x = 0; x < amount; x++) {
- if (c.getItems().playerHasItem(995,
- c.myShopClient.playerShopP[fromSlot])
- && c.getItems().freeSlots() > 0) {
- c.getItems().deleteItem2(995,
- c.myShopClient.playerShopP[fromSlot]);
- c.getItems()
- .addItem(c.myShopClient.playerShop[fromSlot], 1);
- c.myShopClient.playerShopN[fromSlot]--;
- c.myShopClient.playerCollect += c.myShopClient.playerShopP[fromSlot];
- if (c.myShopClient.playerShopN[fromSlot] == 0) {
- c.myShopClient.playerShop[fromSlot] = 0;
- c.myShopClient.playerShopP[fromSlot] = 0;
- }
- bought++;
- } else {
- c.sendMessage("Not enough space or money.");
- break;
- }
- }
- if (bought > 0) {
- resetShop(c.myShopClient);
- c.getItems().resetItems(3823);
- ;
- c.sendMessage("You just bought " + bought + " "
- + c.getItems().getItemName(itemID) + " for "
- + (bought * price));
- c.myShopClient.sendMessage(c.playerName + " has bought "
- + bought + " " + c.getItems().getItemName(itemID)
- + " from you!");
- c.myShopClient.sendMessage("You now have "
- + c.myShopClient.playerCollect
- + " coins to collect (::collect)");
- fixShop(c.myShopClient);
- updatePlayerShop();
- resetShop(c.myShopClient);
- updatePlayerOwnedShop(c.myShopClient);
- // c.myShopClient.complete(5);
- // c.complete(6);
- }
- return false;
- } else if (c.myShopId == 7390 && c.myShopClient != null && !c.myShopClient.properLogout && c.playerName.equals(c.myShopClient.playerName)) {
- if (amount > c.myShopClient.playerShopN[fromSlot])
- amount = c.myShopClient.playerShopN[fromSlot];
- for (int x = 0; x < amount; x++) {
- if (c.getItems().freeSlots() > 0) {
- c.getItems()
- .addItem(c.myShopClient.playerShop[fromSlot], 1);
- c.myShopClient.playerShopN[fromSlot]--;
- if (c.myShopClient.playerShopN[fromSlot] == 0) {
- c.myShopClient.playerShop[fromSlot] = 0;
- c.myShopClient.playerShopP[fromSlot] = 0;
- fixShop(c);
- updatePlayerShop();
- resetShop(c.myShopClient);
- updatePlayerOwnedShop(c.myShopClient);
- }
- } else {
- c.sendMessage("Not enought space.");
- break;
- }
- }
- resetShop(c.myShopClient);
- updatePlayerOwnedShop(c.myShopClient);
- c.getItems().resetItems(3823);
- return false;
- } else if (c.myShopId == 7390) {
- return false;
- }
- if(System.currentTimeMillis() - buyDelay < 1500) {
- return false;
- }
- if (c.myShopId == 14) {
- skillBuy(itemID);
- return false;
- } else if (c.myShopId == 15) {
- buyVoid(itemID);
- return false;
- } /*else if (c.myShopId == 1) {
- buyVoid(itemID);
- return false;
- }*/
- if (!shopSellsItem(itemID))
- return false;
- if(itemID != itemID) {
- c.sendMessage("Don't dupe or you will be IP Banned");
- return false;
- }
- if (amount > 0) {
- /*if (amount > Server.shopHandler.ShopItemsN[c.myShopId][fromSlot]) {
- amount = Server.shopHandler.ShopItemsN[c.myShopId][fromSlot];
- } DISABLED FOR UNLIMITED STOCKS */
- //double ShopValue;
- //double TotPrice;
- int TotPrice2 = 0;
- //int Overstock;
- int Slot = 0;
- int Slot1 = 0;//Tokkul
- int Slot2 = 0;//Pking Points
- int Slot3 = 0;//Donator Gold
- if (c.myShopId == 18) {
- handleOtherShop(itemID);
- return false;
- }
- if (c.myShopId == 73) {
- handleOtherShop(itemID);
- return false;
- }
- if (c.myShopId == 7) {
- handleOtherShop(itemID);
- return true;
- }
- if (c.myShopId == 30) {
- handleOtherShop(itemID);
- return true;
- }
- if (c.myShopId == 29 || c.myShopId == 34 || c.myShopId == 38)
- {
- handleOtherShop(itemID);
- return false;
- }
- for (int i = amount; i > 0; i--) {
- TotPrice2 = (int)Math.floor(getItemShopValue(itemID, 0, fromSlot));
- Slot = c.getItems().getItemSlot(995);
- Slot1 = c.getItems().getItemSlot(6529);
- Slot3 = c.getItems().getItemSlot(5555);
- if (Slot == -1 && c.myShopId != 11 && c.myShopId != 29 && c.myShopId != 34 && c.myShopId != 38 && c.myShopId != 30 && c.myShopId != 47)
- {
- c.sendMessage("You don't have enough coins.");
- break;
- }
- if(c.myShopId == 30) {
- c.sendMessage("You don't have enough slayer Points.");
- break;
- }
- if(Slot3 == -1 && c.myShopId == 11) {
- c.sendMessage("You don't have enough donator gold.");
- break;
- }
- if(TotPrice2 <= 1) {
- TotPrice2 = (int)Math.floor(getItemShopValue(itemID, 0, fromSlot));
- TotPrice2 *= 1.66;
- }
- if (c.myShopId == 29 || c.myShopId == 34 || c.myShopId == 38)
- {
- if (c.playerItemsN[Slot1] >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- buyDelay = System.currentTimeMillis();
- c.getItems().deleteItem(6529, c.getItems().getItemSlot(6529), TotPrice2);
- c.getItems().addItem(itemID, 1);
- //Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;DISABLED FOR UNLIMITED STOCKS
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough tokkul.");
- break;
- }
- }
- else if(c.myShopId == 7) {
- if (c.dragonPoints >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- c.dragonPoints -= TotPrice2;
- c.getItems().addItem(itemID, 1);
- Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough Dragon Points.");
- break;
- }
- }
- else if(c.myShopId == 30) {
- if (c.slayerPoints >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- c.slayerPoints -= TotPrice2;
- c.getItems().addItem(itemID, 1);
- Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough Slayer Points.");
- break;
- }
- }
- else if(c.myShopId == 47) {
- /*
- if (c.pkPoints >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- buyDelay = System.currentTimeMillis();
- c.pkPoints -= TotPrice2;
- c.getItems().addItem(itemID, 1);
- Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough Pk Points.");
- break;
- }
- */
- }
- else if(c.myShopId == 48) {
- if (c.magePoints >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- buyDelay = System.currentTimeMillis();
- c.magePoints -= TotPrice2;
- c.getItems().addItem(itemID, 1);
- //Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;DISABLED FOR UNLIMITED STOCKS
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough slayer points.");
- break;
- }
- }
- else if(c.myShopId == 11) {
- if (c.playerItemsN[Slot3] >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- buyDelay = System.currentTimeMillis();
- c.getItems().deleteItem(5555, c.getItems().getItemSlot(5555), TotPrice2);
- c.getItems().addItem(itemID, 1);
- //Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;DISABLED FOR UNLIMITED STOCKS
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough donator gold.");
- break;
- }
- }
- else if(c.myShopId != 11 && c.myShopId != 29 && c.myShopId != 34 || c.myShopId != 38 || c.myShopId != 30 || c.myShopId != 47) {
- if (c.playerItemsN[Slot] >= TotPrice2) {
- if (c.getItems().freeSlots() > 0) {
- buyDelay = System.currentTimeMillis();
- c.getItems().deleteItem(995, c.getItems().getItemSlot(995), TotPrice2);
- c.getItems().addItem(itemID, 1);
- //Server.shopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;DISABLED FOR UNLIMITED STOCKS
- Server.shopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
- if ((fromSlot + 1) > Server.shopHandler.ShopItemsStandard[c.myShopId]) {
- Server.shopHandler.ShopItems[c.myShopId][fromSlot] = 0;
- }
- } else {
- c.sendMessage("You don't have enough space in your inventory.");
- break;
- }
- } else {
- c.sendMessage("You don't have enough coins.");
- break;
- }
- }
- }
- c.getItems().resetItems(3823);
- resetShop(c.myShopId);
- return true;
- }
- return false;
- }
- public boolean CheckDonor(int item)
- {
- if ((c.isDonator != 4 && c.isDonator != 1) && item == 11926)
- {
- c.sendMessage("You are not a Guthix Donator!");
- }
- else if ((c.isDonator != 4 && c.isDonator != 2) && item == 11930)
- {
- c.sendMessage("You are not a Zamorak Donator!");
- }
- else if ((c.isDonator != 4 && c.isDonator != 3) && item == 11928)
- {
- c.sendMessage("You are not a Saradomin Donator!");
- }
- else
- {
- return true;
- }
- return false;
- }
- public void handleOtherShop(int itemID) {
- if (c.myShopId == 18) {
- if (c.Commendations >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.Commendations -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough PC points to buy this item.");
- }
- } else if (c.myShopId == 7){
- if (c.getdragonPoints() >= getSpecialItemValue(itemID))
- {
- if (c.getItems().freeSlots() > 0){
- c.dragonPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID, 1);
- c.getItems().resetItems(3823);
- c.getPA().sendFrame126("Dragon Point Shop - You have " + c.getdragonPoints() + " Dragon Points", 3901);
- c.getPA().sendFrame126("@whi@Dragon Points: @gre@"+c.getdragonPoints(), 29167);
- }
- } else {
- c.sendMessage("You do not have enough Dragon Points to buy this item.");
- }
- } else if (c.myShopId == 30){
- if (c.getslayerPoints() >= getSpecialItemValue(itemID))
- {
- if (c.getItems().freeSlots() > 0){
- c.slayerPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID, 1);
- c.getItems().resetItems(3823);
- c.getPA().sendFrame126("Slayer Points Shop - You have " + c.getslayerPoints() + " Slayer Points", 3901);
- c.getPA().sendFrame126("@whi@Slayer Points: @gre@"+c.getSlayerPoints(), 29165);
- }
- } else {
- c.sendMessage("You do not have enough Slayer Points to buy this item.");
- }
- } else if (c.myShopId == 38){
- if (c.getVotePoints() >= getSpecialItemValue(itemID))
- {
- if (c.getItems().freeSlots() > 0){
- c.votePoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID, 1);
- c.getItems().resetItems(3823);
- c.getPA().sendFrame126("Voting Shop - You have " + c.getVotePoints() + " Voting Points", 3901);
- c.getPA().sendFrame126("@or2@Voting Points - @yel@" + c.getVotePoints(), 29171); ;
- }
- } else {
- c.sendMessage("You do not have enough Voting points to buy this item.");
- }
- } else if (c.myShopId == 29 || c.myShopId == 34) {
- if (c.isDonator >= 0)
- {
- if (c.getZPoints() >= getSpecialItemValue(itemID))
- {
- if (c.getItems().freeSlots() > 0)
- {
- if (CheckDonor(itemID))
- {
- c.ZPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID, 1);
- c.getItems().resetItems(3823);
- c.getPA().sendFrame126("Pk Points Shop - You have " + c.getZPoints() + " Pk Points", 3901);
- c.getPA().sendFrame126("@whi@PK Points: @gre@"+c.getZPoints(), 29168);
- }
- }
- }
- else
- {
- c.sendMessage("You do not have enough Pk Points to buy this item.");
- }
- }
- else
- {
- c.sendMessage("You must be a donator to buy this item.");
- }
- }
- if (c.myShopId == 73) {
- /*
- if (c.pkPoints >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.pkPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough PK points to buy this item.");
- }
- */
- }
- if (c.myShopId == 74) {
- /*
- if (c.pkPoints >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.pkPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough PK points to buy this item.");
- }
- */
- }
- if (c.myShopId == 48) {
- if (c.magePoints >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.magePoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough Slayer points to buy this item.");
- }
- }
- }
- public void openSkillCape() {
- int capes = get99Count();
- if (capes > 1)
- capes = 1;
- else
- capes = 0;
- c.myShopId = 14;
- setupSkillCapes(capes, get99Count());
- }
- /*public int[][] skillCapes = {{0,9747,4319,2679},{1,2683,4329,2685},{2,2680,4359,2682},{3,2701,4341,2703},{4,2686,4351,2688},{5,2689,4347,2691},{6,2692,4343,2691},
- {7,2737,4325,2733},{8,2734,4353,2736},{9,2716,4337,2718},{10,2728,4335,2730},{11,2695,4321,2697},{12,2713,4327,2715},{13,2725,4357,2727},
- {14,2722,4345,2724},{15,2707,4339,2709},{16,2704,4317,2706},{17,2710,4361,2712},{18,2719,4355,2721},{19,2737,4331,2739},{20,2698,4333,2700}};*/
- public int[] skillCapes = {9747,9753,9750,9768,9756,9759,9762,9801,9807,9783,9798,9804,9780,9795,9792,9774,9771,9777,9786,9810,9765,9948,12169,12524};
- public int get99Count() {
- int count = 0;
- for (int j = 0; j < c.playerLevel.length; j++) {
- if (c.getLevelForXP(c.playerXP[j]) >= 99) {
- count++;
- }
- }
- return count;
- }
- public void setupSkillCapes(int capes, int capes2) {
- c.getItems().resetItems(3823);
- c.isShopping = true;
- c.myShopId = 14;
- c.getPA().sendFrame248(3824, 3822);
- c.getPA().sendFrame126("Skillcape Shop", 3901);
- int TotalItems = 0;
- TotalItems = capes2;
- if (TotalItems > Server.shopHandler.MaxShopItems) {
- TotalItems = Server.shopHandler.MaxShopItems;
- }
- c.getOutStream().createFrameVarSizeWord(53);
- c.getOutStream().writeWord(3900);
- c.getOutStream().writeWord(TotalItems);
- int TotalCount = 0;
- for (int i = 0; i < 24; i++) {
- if (c.getLevelForXP(c.playerXP[i]) < 99)
- continue;
- c.getOutStream().writeByte(1);
- if(i < 23)
- c.getOutStream().writeWordBigEndianA(skillCapes[i] + 2);
- else
- c.getOutStream().writeWordBigEndianA(skillCapes[i] + 1);
- TotalCount++;
- }
- c.getOutStream().endFrameVarSizeWord();
- c.flushOutStream();
- }
- public void skillBuy(int item) {
- int nn = get99Count();
- if (nn > 1)
- nn = 1;
- else
- nn = 0;
- for (int j = 0; j < skillCapes.length; j++) {
- if (skillCapes[j] == item || skillCapes[j]+1 == item) {
- if (c.getItems().freeSlots() > 1) {
- if (c.getItems().playerHasItem(995,99000)) {
- if (c.getLevelForXP(c.playerXP[j]) >= 99) {
- c.getItems().deleteItem(995, c.getItems().getItemSlot(995), 99000);
- c.getItems().addItem(skillCapes[j] + nn,1);
- c.getItems().addItem(skillCapes[j] + 2,1);
- } else {
- c.sendMessage("You must have 99 in the skill of the cape you're trying to buy.");
- }
- } else {
- c.sendMessage("You need 99k to buy this item.");
- }
- } else {
- c.sendMessage("You must have at least 1 inventory spaces to buy this item.");
- }
- }
- /*if (skillCapes[j][1 + nn] == item) {
- if (c.getItems().freeSlots() >= 1) {
- if (c.getItems().playerHasItem(995,99000)) {
- if (c.getLevelForXP(c.playerXP[j]) >= 99) {
- c.getItems().deleteItem(995, c.getItems().getItemSlot(995), 99000);
- c.getItems().addItem(skillCapes[j] + nn,1);
- c.getItems().addItem(skillCapes[j] + 2,1);
- } else {
- c.sendMessage("You must have 99 in the skill of the cape you're trying to buy.");
- }
- } else {
- c.sendMessage("You need 99k to buy this item.");
- }
- } else {
- c.sendMessage("You must have at least 1 inventory spaces to buy this item.");
- }
- break;
- }*/
- }
- c.getItems().resetItems(3823);
- }
- public void openVoid() {
- /*synchronized(c) {
- c.getItems().resetItems(3823);
- c.isShopping = true;
- c.myShopId = 15;
- c.getPA().sendFrame248(3824, 3822);
- c.getPA().sendFrame126("Void Recovery", 3901);
- int TotalItems = 5;
- c.getOutStream().createFrameVarSizeWord(53);
- c.getOutStream().writeWord(3900);
- c.getOutStream().writeWord(TotalItems);
- for (int i = 0; i < c.voidStatus.length; i++) {
- c.getOutStream().writeByte(c.voidStatus[i]);
- c.getOutStream().writeWordBigEndianA(2519 + i * 2);
- }
- c.getOutStream().endFrameVarSizeWord();
- c.flushOutStream();
- }*/
- }
- public void buyVoid(int item) {
- /*if (item > 2527 || item < 2518)
- return;
- //c.sendMessage("" + item);
- if (c.voidStatus[(item-2518)/2] > 0) {
- if (c.getItems().freeSlots() >= 1) {
- if (c.getItems().playerHasItem(995,c.getItems().getUntradePrice(item))) {
- c.voidStatus[(item-2518)/2]--;
- c.getItems().deleteItem(995,c.getItems().getItemSlot(995), c.getItems().getUntradePrice(item));
- c.getItems().addItem(item,1);
- openVoid();
- } else {
- c.sendMessage("This item costs " + c.getItems().getUntradePrice(item) + " coins to rebuy.");
- }
- } else {
- c.sendMessage("I should have a free inventory space.");
- }
- } else {
- c.sendMessage("I don't need to recover this item from the void knights.");
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement