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 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 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);
- }
- 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;
- }
- }
- }
- }
- 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 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){
- int ShopValue = (int)Math.floor(getItemShopValue(removeId, 0, removeSlot));
- ShopValue *= 1.15;
- String ShopAdd = "";
- if (c.myShopId == 2 || c.myShopId == 3 && c.myShopId == 4 || c.myShopId == 5 || c.myShopId == 6 || c.myShopId == 7) {
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + getSpecialItemValue(removeId) + " points.");
- return;
- }
- if (ShopValue >= 1000 && ShopValue < 1000000) {
- ShopAdd = " (" + (ShopValue / 1000) + "K)";
- } else if (ShopValue >= 1000000) {
- ShopAdd = " (" + (ShopValue / 1000000) + " million)";
- }
- c.sendMessage(c.getItems().getItemName(removeId)+": currently costs "+String.format("%, d",ShopValue)+" coins"+ShopAdd);
- }
- public int getSpecialItemValue(int id) {
- switch (id) {
- case 8839:
- case 8840:
- return 40;
- case 8842:
- return 15;
- case 11663:
- case 11664:
- case 11665:
- return 20;
- case 6570:
- return 15;
- case 6914:
- return 15;
- case 15441:
- case 15442:
- case 15443:
- case 15444:
- case 11718:
- case 10548:
- case 6889:
- return 15;
- case 10551:
- case 15349:
- case 20072:
- case 15013:
- return 20;
- case 13736://Blessed Spirit Shield
- case 15486://Staff of light
- case 18335://Arcane stream neckalace
- return 30;
- case 13744://Spectral Spirit Shield
- return 50;
- case 1038: //phats and masks santa
- case 1040:
- case 1042:
- case 1044:
- case 1046:
- case 1048:
- case 1050:
- case 1053:
- case 1055:
- case 1057:
- return 500;
- case 18349://Chaotic Rapier
- case 18351://Chaotic Longsword
- case 18353://Chaotic Maul
- case 18355://Chaotic Staff
- case 18357://Chaotic crossbow
- case 18359://Chaotic KiteShield
- case 18361://Eagle-eye shield
- case 18363://Farseer kiteshield
- return 200000;
- case 13738://Arcane Spirit Shield
- return 150;
- case 13742://Elysian Spirit Shield
- return 350;
- case 13740://Divine Spirit Shield
- return 450;
- case 6665: //Flippers
- case 6666: //Mudskipper hat
- case 19335:
- case 8950:
- return 5;
- case 13661:
- return 5;
- case 1037: //Bunny ears
- return 10;
- }
- return 100;
- }
- /**
- *Sell item to shop (Shop Price)
- **/
- public void sellToShopPrice(int removeId, int removeSlot) {
- for (int i : Config.ITEM_SELLABLE) {
- if (c.playerRights == 2 && Config.ADMIN_CAN_SELL_ITEMS == false) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(removeId).toLowerCase()+".");
- return;
- }
- if (i == removeId) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(removeId).toLowerCase()+".");
- return;
- }
- }
- if (c.myShopId == 2) {
- c.sendMessage("You can't sell anything to this store.");
- return;
- }
- if (c.myShopId == 3) {
- c.sendMessage("You can't sell anything to this store.");
- return;
- }
- if (c.myShopId == 4) {
- c.sendMessage("You can't sell anything to this store.");
- return;
- }
- if (c.myShopId == 5) {
- c.sendMessage("You can't sell anything to this store.");
- return;
- }
- if (c.myShopId == 6) {
- c.sendMessage("You can't sell anything to this store.");
- return;
- }
- if (c.myShopId == 7) {
- c.sendMessage("You can't sell anything to this store.");
- 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 (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)";
- }
- c.sendMessage(c.getItems().getItemName(removeId)+": shop will buy for "+ShopValue+" coins"+ShopAdd);
- }
- }
- public boolean sellItem(int itemID, int fromSlot, int amount) {
- if (c.playerRights == 2 && Config.ADMIN_CAN_SELL_ITEMS == false) {
- c.sendMessage("You can't sell "+c.getItems().getItemName(itemID).toLowerCase()+".");
- return false;
- }
- if (c.myShopId == 14 || c.myShopId == 3)
- 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.myShopId == 2) {
- c.sendMessage("You can't sell anything to this store.");
- return false;
- }
- if (c.myShopId == 3) {
- c.sendMessage("You can't sell anything to this store.");
- return false;
- }
- if (c.myShopId == 4) {
- c.sendMessage("You can't sell anything to this store.");
- return false;
- }
- if (c.myShopId == 5) {
- c.sendMessage("You can't sell anything to this store.");
- return false;
- }
- if (c.myShopId == 6) {
- c.sendMessage("You can't sell anything to this store.");
- return false;
- }
- if (c.myShopId == 7) {
- c.sendMessage("You can't sell anything to this store.");
- return false;
- }
- if(c.playerRights == 2 && !Config.ADMIN_CAN_SELL_ITEMS) {
- c.sendMessage("Selling items as an admin has been disabled.");
- 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)) {
- if (Item.itemIsNote[itemID] == false) {
- c.getItems().deleteItem(itemID, c.getItems().getItemSlot(itemID), 1);
- } else {
- c.getItems().deleteItem(itemID, fromSlot, 1);
- }
- c.getItems().addItem(995, TotPrice2);
- 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;
- 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;
- Server.shopHandler.ShopItemsDelay[c.myShopId][i] = 0;
- break;
- }
- }
- }
- return true;
- }
- public boolean buyItem(int itemID, int fromSlot, int amount) {
- if (itemID != itemID)
- return false;
- if (Server.shopHandler.ShopItems[c.myShopId][fromSlot]-1 != itemID && c.myShopId != 14) {
- return false;
- }
- if(!shopSellsItem(itemID))
- return false;
- if (c.myShopId == 15) {
- buyVoid(itemID);
- return false;
- }
- if(!shopSellsItem(itemID))
- return false;
- if (amount > 0) {
- if (amount > Server.shopHandler.ShopItemsN[c.myShopId][fromSlot]) {
- amount = Server.shopHandler.ShopItemsN[c.myShopId][fromSlot];
- }
- //double ShopValue;
- //double TotPrice;
- int TotPrice2 = 0;
- //int Overstock;
- int Slot = 0;
- int Slot1 = 0;//Tokkul
- int Slot2 = 0;//Slayer Points
- int Slot3 = 0;//Donator Gold\
- 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);
- if (c.myShopId == 2 || c.myShopId == 3 && c.myShopId == 4 || c.myShopId == 5 || c.myShopId == 6) {
- handleOtherShop(itemID);
- return false;
- }
- if (Slot == -1 && c.myShopId != 14 && c.myShopId != 29 && c.myShopId != 30 && c.myShopId != 31 && c.myShopId != 47) {
- c.sendMessage("You don't have enough coins.");
- break;
- }
- if(Slot1 == -1 && c.myShopId == 29 || c.myShopId == 30 || c.myShopId == 31) {
- c.sendMessage("You don't have enough tokkul.");
- break;
- }
- if(TotPrice2 <= 1) {
- TotPrice2 = (int)Math.floor(getItemShopValue(itemID, 0, fromSlot));
- TotPrice2 *= 1.66;
- }
- if(c.myShopId == 29 || c.myShopId == 30 || c.myShopId == 31) {
- 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;
- 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 != 14 && c.myShopId != 29 || c.myShopId != 30 || c.myShopId != 31 || 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;
- 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;
- if(c.myShopId == 14) {
- 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;
- }
- }
- }
- }
- }
- c.getItems().resetItems(3823);
- resetShop(c.myShopId);
- updatePlayerShop();
- return true;
- }
- return false;
- }
- public void handleOtherShop(int itemID) {
- if (c.myShopId == 6) {
- 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 mage points to buy this item.");
- }
- } else if (c.myShopId == 2) { //Vote points shop
- if (c.votingPoints >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.votingPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough Voting points.");
- }
- } else if (c.myShopId == 3) { // Pk points shop
- if (c.pkp >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.pkp -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough Pk Points.");
- }
- } else if (c.myShopId == 4) { //Pest points shop
- if (c.pcPoints >= getSpecialItemValue(itemID)) {
- if (c.getItems().freeSlots() > 0){
- c.pcPoints -= getSpecialItemValue(itemID);
- c.getItems().addItem(itemID,1);
- c.getItems().resetItems(3823);
- }
- } else {
- c.sendMessage("You do not have enough pest points to buy this item.");
- }
- }
- }
- 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