/** * Updates a Slot1 and Slot2 of any GEItem in the database instantly. * @param GEItem */ public void updateGEItemSlotsDatabase(GEItem geItem) { try { SQLiteDatabase db = new SQLiteDatabase(Constants.databaseName); /** * Each time you do in GESession.cs [checkOffer or abortOffer] * A Slot1 and Slot2 is generated but those Slot's themselves are never saved, less data like this. * Only thing thats saved is how much to generate of those Slots next time you call [checkOffer]. * Even generated Slots check against how much they can truly take out. */ if (geItem is BuyOffer) { db.ExecuteNonQuery("UPDATE grandExchangeBuying SET collectedItem = " + geItem.getAmountCollectedItem() + ", collectedGold = " + geItem.getAmountCollectedGold() + " WHERE slot = " + geItem.getSlot() + " AND playerHash = " + geItem.getPlayerHash()); } else if (geItem is SellOffer) { db.ExecuteNonQuery("UPDATE grandExchangeSelling SET collectedItem = " + geItem.getAmountCollectedItem() + ", collectedGold = " + geItem.getAmountCollectedGold() + " WHERE slot = " + geItem.getSlot() + " AND playerHash = " + geItem.getPlayerHash()); } db.CloseDatabase(); } catch (Exception e) { misc.WriteError("GrandExchange Error]: " + e.Message); } }
/** * Add a GEItem to be removed from database. * @param GEItem */ public void removeOffer(GEItem geItem) { lock (removeOffersLocker) { offersToRemove.Add(geItem); } }
/** * Add a GEItem to be update in database. * @param GEItem */ public void abortOffer(GEItem geItem) { lock (abortOffersLocker) { offersToAbort.Add(geItem); } }
/** * Add a GEItem to be added to database. * @param GEItem */ public void addOffer(GEItem offer) { lock (addOffersLocker) { offersToAdd.Add(offer); } }
public void checkOffer(byte slot) { this.currentOffer = myGEItems[slot]; /* * The line below always gets the GEItem by player and GE slot from database. * It's alot slower to keep retrieving it from database. * Line above this comment uses the preloaded GEItems * That should be the same thing, But faster. */ //this.currentOffer = Server.getGrandExchange().getOfferByPlayerSlot(p, slot); if (currentOffer == null) { p.getPackets().sendMessage("[checkOffer]: Nice try cheater!, If this is bug please report it."); return; } ItemData.ItemPrice price = currentOffer.getItemPrice(); ItemData.Item def = ItemData.forId(currentOffer.getItem()); if (def == null) { p.getPackets().sendMessage("Item: " + currentOffer.getItem() + " cannot be found in item definitions, please report it."); return; } p.getPackets().sendConfig(1109, currentOffer.getItem()); p.getPackets().sendConfig(1110, currentOffer.getTotalAmount()); p.getPackets().sendConfig(1111, currentOffer.getPriceEach()); p.getPackets().sendConfig(1112, currentOffer.getSlot()); p.getPackets().sendConfig(1113, 0); p.getPackets().sendConfig(1114, price.getNormalPrice()); p.getPackets().sendConfig(1116, price.getMaximumPrice()); p.getPackets().sendConfig(1115, price.getMinimumPrice()); p.getPackets().modifyText(def.getExamine(), 105, 142); //item examine text. if (currentOffer is BuyOffer) { //A Buyer can have how much of the item's he bought shown even if they aborted the currentOffer. currentOffer.setSlot1((currentOffer.getAmountItemsLeftToCollect() > 0) ? new Item(currentOffer.getItem(), currentOffer.getAmountItemsLeftToCollect()) : null); /**If Buyer Aborted the item buying, it shows UnBought item gold + Overpay gold * If Buyer doesn't abort the item it shows just Overpay gold. */ if (currentOffer.isAborted()) currentOffer.setSlot2((currentOffer.getTotalAmountGoldLeftToCollect() > 0) ? new Item(995, currentOffer.getTotalAmountGoldLeftToCollect()) : null); else currentOffer.setSlot2((currentOffer.getAmountCollectedGold() < currentOffer.getAmountOverpaid()) ? new Item(995, currentOffer.getAmountOverpaid()) : null); } else if(currentOffer is SellOffer) { //If Seller Aborted the item selling, it shows UnSold items currentOffer.setSlot1((currentOffer.isAborted() && currentOffer.getTotalAmountItemsLeftToCollect() > 0) ? new Item(currentOffer.getItem(), currentOffer.getTotalAmountItemsLeftToCollect()) : null); //Always shows Seller Item Sold Gold + Overpay gold (shows how much money you made from sales + overpays.) currentOffer.setSlot2((currentOffer.getAmountGoldLeftToCollect() > 0) ? new Item(995, currentOffer.getAmountGoldLeftToCollect()) : null); } Item[] items = {currentOffer.getSlot1(), currentOffer.getSlot2()}; p.getPackets().sendItems(-1, -1757, 523 + currentOffer.getSlot(), items); }
public void updateSlotStates() { Item[] items = { currentOffer.getSlot1(), currentOffer.getSlot2() }; p.getPackets().sendItems(-1, -1757, 523 + currentOffer.getSlot(), items); /* * Deletes the offer from database completely. * Only if amount you were willing to sell/(buy?) was completed * Or you clicked abort item * And taken both items out of Slot1 and Slot2. * Otherwise it just saves how much you taken out of both slots (if anything). */ if (((currentOffer.getAmountTraded() == currentOffer.getTotalAmount()) || currentOffer.isAborted()) && currentOffer.getSlot1() == null && currentOffer.getSlot2() == null) { Server.getGrandExchange().removeOffer(currentOffer); resetInterface(); currentOffer = null; } else { Server.getGrandExchange().updateGEItemSlotsDatabase(currentOffer); } }
public void newSellOffer(byte slot) { this.currentOffer = new SellOffer(slot, p.getLoginDetails().getLongName()); myGEItems[slot] = this.currentOffer; p.getPackets().sendConfig(1109, -1); p.getPackets().sendConfig(1110, 0); p.getPackets().sendConfig(1111, 0); p.getPackets().sendConfig(1112, slot); p.getPackets().sendConfig(1113, 1); p.getPackets().sendConfig(1114, 0); p.getPackets().sendConfig(1115, 0); p.getPackets().sendConfig(1116, 0); p.getPackets().displayInventoryInterface(107); p.getPackets().setRightClickOptions(1026, 107 * 65536 + 18, 0, 27); object[] opts = new object[]{"", "", "", "", "Offer", -1, 0, 7, 4, 93, 7012370}; p.getPackets().sendClientScript(149, opts, "IviiiIsssss"); p.getPackets().sendItems(-1, 65535, 93, p.getInventory().getItems()); }
public void newBuyOffer(byte slot) { this.currentOffer = new BuyOffer(slot, p.getLoginDetails().getLongName()); myGEItems[slot] = this.currentOffer; p.getPackets().sendConfig(1109, -1); p.getPackets().sendConfig(1110, 0); p.getPackets().sendConfig(1111, 0); p.getPackets().sendConfig(1112, slot); p.getPackets().sendConfig(1113, 0); p.getPackets().sendConfig(1114, 0); p.getPackets().sendConfig(1115, 0); p.getPackets().sendConfig(1116, 0); openItemSearch(); }
public void confirmOffer() { /* * Confirm a Buyer or Seller listing. */ if (currentOffer == null) { p.getPackets().sendMessage("[confirmOffer]: Nice try cheater!, If this is bug please report it."); return; } long gpAmountCalculated = Math.BigMul(currentOffer.getTotalAmount(), currentOffer.getPriceEach()); if (gpAmountCalculated > Inventory.MAX_ITEM_AMOUNT) { if (currentOffer is BuyOffer) { p.getPackets().sendMessage("You won't be able to cover the offer, it exceeds maximum gold."); return; } else if (currentOffer is SellOffer) { p.getPackets().sendMessage("You can't sell that many, it would create too much gold to be able to take out."); return; } } if (currentOffer is BuyOffer) { int gpAmount = (int)gpAmountCalculated; if (currentOffer.getTotalAmount() <= 0) { p.getPackets().sendMessage("You must choose the quantity you wish to buy!"); return; } else if (!p.getInventory().hasItemAmount(995, gpAmount)) { p.getPackets().sendMessage("You don't have enough coins in your inventory to cover the offer."); return; } else if (!p.getInventory().deleteItem(995, gpAmount)) { return; } } else if (currentOffer is SellOffer) { if (currentOffer.getTotalAmount() <= 0) { p.getPackets().sendMessage("You must choose the quantity you wish to sell!"); return; } else if (!p.getInventory().hasItemAmount(currentOffer.getItem(), currentOffer.getTotalAmount())) { p.getPackets().sendMessage("You do not have enough of this item in your inventory to cover the offer."); return; } if (ItemData.forId(currentOffer.getItem()).isNoted() || ItemData.forId(currentOffer.getItem()).isStackable()) { if (!p.getInventory().deleteItem(currentOffer.getItem(), currentOffer.getTotalAmount())) { p.getPackets().sendMessage("[confirmOffer]: Nice try cheater!, you don't have this item!."); return; } } else { //UnNoted variant of this item, so remove multiple items from inventory. int amountTotalDeleted = p.getInventory().deleteItemAndShowAmountDeleted(currentOffer.getUnNotedId(), currentOffer.getTotalAmount()); currentOffer.setTotalAmount(amountTotalDeleted); p.getPackets().sendConfig(1110, currentOffer.getTotalAmount()); } } p.getPackets().sendConfig(1113, -1); p.getPackets().sendConfig(1112, -1); currentOffer.setSubmitting(true); p.getPackets().updateGEProgress(currentOffer); Server.getGrandExchange().addOffer(currentOffer); GEItem offer = currentOffer; currentOffer = null; Event updateGEProgressEvent = new Event(500); updateGEProgressEvent.setAction(() => { updateGEProgressEvent.stop(); offer.setSubmitting(false); //done submitting = orangebar p.getPackets().updateGEProgress(offer); }); Server.registerEvent(updateGEProgressEvent); }
public void updateGEProgress(GEItem offer) { connection.SendPacket(new PacketBuilder().setId(116) .addByte((byte)offer.getSlot()) .addByte((byte)offer.getProgress()) .addUShort(offer.getDisplayItem()) .addInt(offer.getPriceEach()) .addInt(offer.getTotalAmount()) .addInt(offer.getAmountTraded()) .addInt(offer.getTotalAmount() * offer.getPriceEach()).toPacket()); }
public GEItem[] getOffersByPlayer(Player p) { /* * Gives the player their GrandExchange Items both Buying and Selling are here. * Returns a GEItem[] of all Item's array based on slot id, null array index = space */ long playerHash = p.getLoginDetails().getLongName(); try { int itemId; int amount; int price; bool isSoldNull; bool isBoughtNull; int sold; int bought; int collectedItem; int collectedGold; int overpaid; byte slot; //0-5 bool aborted; GEItem[] myGEItems = new GEItem[6]; SQLiteDatabase db = new SQLiteDatabase(Constants.databaseName); SQLiteVdbe preparedStatement = new SQLiteVdbe(db, "SELECT itemId, amount, price, bought, NULL sold, collectedItem, collectedGold, overpaid, slot, aborted FROM grandExchangeBuying WHERE playerHash = ? UNION SELECT itemId, amount, price, NULL bought, sold, collectedItem, collectedGold, overpaid, slot, aborted FROM grandExchangeSelling WHERE playerHash = ?"); preparedStatement.Reset(); preparedStatement.BindLong(1, playerHash); preparedStatement.BindLong(2, playerHash); while (preparedStatement.ExecuteStep() != Sqlite3.SQLITE_DONE) { if (preparedStatement.GetLastError() != "") { misc.WriteError("[GrandExchange SQL Error]: " + preparedStatement.GetLastError()); return null; } itemId = preparedStatement.Result_Int(0); amount = preparedStatement.Result_Int(1); price = preparedStatement.Result_Int(2); isBoughtNull = string.IsNullOrEmpty(preparedStatement.Result_Text(3)); isSoldNull = string.IsNullOrEmpty(preparedStatement.Result_Text(4)); collectedItem = preparedStatement.Result_Int(5); collectedGold = preparedStatement.Result_Int(6); overpaid = preparedStatement.Result_Int(7); slot = Convert.ToByte(preparedStatement.Result_Int(8)); aborted = Convert.ToBoolean(preparedStatement.Result_Int(9)); if (isSoldNull && !isBoughtNull) { bought = Convert.ToInt32(preparedStatement.Result_Text(3)); myGEItems[slot] = new BuyOffer(itemId, amount, price, bought, collectedItem, collectedGold, overpaid, slot, aborted, playerHash); } else if (isBoughtNull && !isSoldNull) { sold = Convert.ToInt32(preparedStatement.Result_Text(4)); myGEItems[slot] = new SellOffer(itemId, amount, price, sold, collectedItem, collectedGold, overpaid, slot, aborted, playerHash); } else { misc.WriteError("[GrandExchange Error]: sold or bought both are NULL? how this happen?"); } } db.CloseDatabase(); return myGEItems; } catch (Exception e) { misc.WriteError("GrandExchange Error]: " + e.Message); } return null; }
/** * Updates a Slot1 and Slot2 of any GEItem in the database instantly. * @param GEItem */ public void updateGEItemSlotsDatabase(GEItem geItem) { try { SQLiteDatabase db = new SQLiteDatabase(Constants.databaseName); /** * Each time you do in GESession.cs [checkOffer or abortOffer] * A Slot1 and Slot2 is generated but those Slot's themselves are never saved, less data like this. * Only thing thats saved is how much to generate of those Slots next time you call [checkOffer]. * Even generated Slots check against how much they can truly take out. */ if(geItem is BuyOffer) db.ExecuteNonQuery("UPDATE grandExchangeBuying SET collectedItem = " + geItem.getAmountCollectedItem() + ", collectedGold = " + geItem.getAmountCollectedGold() + " WHERE slot = " + geItem.getSlot() + " AND playerHash = " + geItem.getPlayerHash()); else if(geItem is SellOffer) db.ExecuteNonQuery("UPDATE grandExchangeSelling SET collectedItem = " + geItem.getAmountCollectedItem() + ", collectedGold = " + geItem.getAmountCollectedGold() + " WHERE slot = " + geItem.getSlot() + " AND playerHash = " + geItem.getPlayerHash()); db.CloseDatabase(); } catch (Exception e) { misc.WriteError("GrandExchange Error]: " + e.Message); } }
public GEItem getOfferByPlayerSlot(Player p, byte slot) { /* * Gives the player their GrandExchange Items both Buying and Selling are here. * Returns a GEItem[] of all Item's array based on slot id, null array index = space */ long playerHash = p.getLoginDetails().getLongName(); try { int itemId; int amount; int price; bool isSoldNull; bool isBoughtNull; int sold; int bought; int collectedItem; int collectedGold; int overpaid; bool aborted; GEItem geItem = null; SQLiteDatabase db = new SQLiteDatabase(Constants.databaseName); SQLiteVdbe preparedStatement = new SQLiteVdbe(db, "SELECT itemId, amount, price, bought, NULL sold, collectedItem, collectedGold, overpaid, aborted FROM grandExchangeBuying WHERE playerHash = ? AND slot = ? UNION SELECT itemId, amount, price, NULL bought, sold, collectedItem, collectedGold, overpaid, aborted FROM grandExchangeSelling WHERE playerHash = ? AND slot = ?"); preparedStatement.Reset(); preparedStatement.BindLong(1, playerHash); preparedStatement.BindInteger(2, slot); preparedStatement.BindLong(3, playerHash); preparedStatement.BindInteger(4, slot); while (preparedStatement.ExecuteStep() != Sqlite3.SQLITE_DONE) { if (preparedStatement.GetLastError() != "") { misc.WriteError("[GrandExchange SQL Error]: " + preparedStatement.GetLastError()); return(null); } itemId = preparedStatement.Result_Int(0); amount = preparedStatement.Result_Int(1); price = preparedStatement.Result_Int(2); isBoughtNull = string.IsNullOrEmpty(preparedStatement.Result_Text(3)); isSoldNull = string.IsNullOrEmpty(preparedStatement.Result_Text(4)); collectedItem = preparedStatement.Result_Int(5); collectedGold = preparedStatement.Result_Int(6); overpaid = preparedStatement.Result_Int(7); aborted = Convert.ToBoolean(preparedStatement.Result_Int(8)); if (isSoldNull && !isBoughtNull) { bought = Convert.ToInt32(preparedStatement.Result_Text(3)); geItem = new BuyOffer(itemId, amount, price, bought, collectedItem, collectedGold, overpaid, slot, aborted, playerHash); } else if (isBoughtNull && !isSoldNull) { sold = Convert.ToInt32(preparedStatement.Result_Text(4)); geItem = new SellOffer(itemId, amount, price, sold, collectedItem, collectedGold, overpaid, slot, aborted, playerHash); } else { misc.WriteError("[GrandExchange Error]: sold or bought both are NULL? how this happen?"); } } db.CloseDatabase(); return(geItem); } catch (Exception e) { misc.WriteError("[GrandExchange Error]: " + e.Message); } return(null); }