From 52bdd4054a853c93f8701bc530ed518d2fcc3cdd Mon Sep 17 00:00:00 2001 From: jamix77 <> Date: Mon, 23 Mar 2020 22:06:08 +0000 Subject: [PATCH] Auto buy for GE You can now buy stuff from the GE that is auto stocked by the GE for a marked up price. Enjoy! --- Server/data/eco/offer_dispatch_db.emp | Bin 3556031 -> 3556537 bytes Server/itemstostock.txt | 4 ++ Server/src/org/crandor/Server.java | 2 + .../game/content/eco/ge/GEAutoStock.java | 67 ++++++++++++++++++ .../game/content/eco/ge/GEOfferDispatch.java | 5 +- .../net/packet/out/GrandExchangePacket.java | 3 + 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Server/itemstostock.txt diff --git a/Server/data/eco/offer_dispatch_db.emp b/Server/data/eco/offer_dispatch_db.emp index 7a924a3c4965710c20e345520a0541d6bc00495a..8a564cbc2f86286ff413d4baefe487267090b426 100644 GIT binary patch delta 697 zcmZ{hIZFdU7=~wzG4Gma5>33%c*n#$VypikR)UC?f?#7Qg2CbiZN$>X#$MAHAtDIr z{0Y_`@z%mdEOchpV>S4}x6FL|@XoWdCp?qcjWY?MOD3P!KuDs9a1q6XnW;|_=x}!Br1qXB1D9VDx#XGA!>;_qMm3V8i^*NnP?$ei3rg~v=bdfC(%W8 z6Fo$f=p|xAoaiI^i2-7e7$Sy=5h9Vn=)puvCNHhHR-V%jRXJt9WLdk%C1$t2Jo|3u zGI?Qx(rks?G9dQ+1z_HaYv{A3$AG?ULV?ngb0l6_DRcIzP0NT)ZoUekHybFnPFB0N$CzROPx5x@Fjq)BEGaA{^<~k-~MZmtUWM`|F-$%P1n;eQN?p<)g_*I?e+o~=S@XI+l@~Kd=9f5=AB{rv VRfsP4x59iN=n~Pfg&$D85+5DPim?Cy delta 187 zcmWm8IbuO!003dXhYS%yEJ0%5f`lv_zzrNpF@^h3sB(_iI|!!ysyQFx@NXPQ+zY$Q z9to0^NK%rPj6BHAvyziX$;*=zq$tl)lCr!=MXFMhy1Yt5n$nUtd6%|yq$@q?%Rq)Q ilCex=DjzbFxh&*UzGNvY`IaB~l|NaZ*c`XfZT1S}!YZ}^ diff --git a/Server/itemstostock.txt b/Server/itemstostock.txt new file mode 100644 index 000000000..f2e64afb9 --- /dev/null +++ b/Server/itemstostock.txt @@ -0,0 +1,4 @@ +#ooh hash comment system uwu! +#format is: +#itemId:amount:percentage (as decimal) +2349:5000:1.50 \ No newline at end of file diff --git a/Server/src/org/crandor/Server.java b/Server/src/org/crandor/Server.java index 25c31fc7b..9a6a00b0d 100644 --- a/Server/src/org/crandor/Server.java +++ b/Server/src/org/crandor/Server.java @@ -1,5 +1,6 @@ package org.crandor; +import org.crandor.game.content.eco.ge.GEAutoStock; import org.crandor.game.system.SystemLogger; import org.crandor.game.system.SystemShutdownHook; import org.crandor.game.system.mysql.SQLManager; @@ -70,6 +71,7 @@ public final class Server { reactor.start(); SystemLogger.log(GameWorld.getName() + " flags " + GameWorld.getSettings().toString()); SystemLogger.log(GameWorld.getName() + " started in " + t.duration(false, "") + " milliseconds."); + GEAutoStock.stock(); } diff --git a/Server/src/org/crandor/game/content/eco/ge/GEAutoStock.java b/Server/src/org/crandor/game/content/eco/ge/GEAutoStock.java index 454603140..77e8250ef 100644 --- a/Server/src/org/crandor/game/content/eco/ge/GEAutoStock.java +++ b/Server/src/org/crandor/game/content/eco/ge/GEAutoStock.java @@ -1,4 +1,71 @@ package org.crandor.game.content.eco.ge; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +import org.crandor.game.node.entity.player.Player; +import org.crandor.game.node.entity.player.info.PlayerDetails; +import org.crandor.game.node.item.Item; + +/** + * Auto stocking feature for the grand exchange. + * @author jamix77 + * + */ public class GEAutoStock { + + /** + * Should the auto stock feature be enabled in the game? + */ + public static final boolean toStock = true; + + /** + * The items to auto stock in the grand exchange. + */ + public static final ArrayList itemsToStock = new ArrayList(); + + /** + * The values to modify the price by + */ + public static final ArrayList modValues = new ArrayList(); + + /** + * Time to auto stock. + */ + public static void stock() { + if (itemsToStock.isEmpty()) { + try { + File file = new File("itemstostock.txt"); + Scanner myReader = new Scanner(file); + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + if (data.startsWith("#")) { + continue; + } + itemsToStock.add(new Item(Integer.parseInt(data.split(":")[0]), Integer.parseInt(data.split(":")[1]))); + modValues.add(Double.parseDouble(data.split(":")[2])); + } + myReader.close(); + } catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } +; } + + + for (int i = 0; i < itemsToStock.size(); i++) { + Item item = itemsToStock.get(i); + double markup = modValues.get(i); + System.out.println("Stocking " + item.getName() + " id: " + item.getId() + " for " + (int)((item.getValue() * markup)/item.getAmount()) + " x" + item.getAmount() + " at " + markup + "x markup"); + GrandExchangeOffer offer = new GrandExchangeOffer(item.getId(), true); + offer.setOfferedValue((int) ((item.getValue() * markup)/ item.getAmount())); + offer.setAmount(item.getAmount()); + System.out.println(GEOfferDispatch.dispatch(new Player(PlayerDetails.getDetails("2009scape")), offer)); + } + } + + + } diff --git a/Server/src/org/crandor/game/content/eco/ge/GEOfferDispatch.java b/Server/src/org/crandor/game/content/eco/ge/GEOfferDispatch.java index d8ed93488..44b8d68b4 100644 --- a/Server/src/org/crandor/game/content/eco/ge/GEOfferDispatch.java +++ b/Server/src/org/crandor/game/content/eco/ge/GEOfferDispatch.java @@ -174,13 +174,16 @@ public final class GEOfferDispatch extends Pulse implements CallBack { public static boolean dispatch(Player player, GrandExchangeOffer offer) { if (offer.getAmount() < 1) { player.getPacketDispatch().sendMessage("You must choose the quantity you wish to buy!"); + System.out.println("amountthing"); return false; } if (offer.getOfferedValue() < 1) { player.getPacketDispatch().sendMessage("You must choose the price you wish to buy for!"); + System.out.println("pricethng"); return false; } if (offer.getState() != OfferState.PENDING || offer.getUid() != 0) { + System.out.println("pendingthing"); return false; } offer.setPlayerUID(player.getDetails().getUid()); @@ -311,7 +314,7 @@ public final class GEOfferDispatch extends Pulse implements CallBack { * Gets the next UID. * @return The UID. */ - private static long nextUID() { + static long nextUID() { long id = offsetUID++; if (id == 0) { return nextUID(); diff --git a/Server/src/org/crandor/net/packet/out/GrandExchangePacket.java b/Server/src/org/crandor/net/packet/out/GrandExchangePacket.java index ef2b3c6db..43ccffdfc 100644 --- a/Server/src/org/crandor/net/packet/out/GrandExchangePacket.java +++ b/Server/src/org/crandor/net/packet/out/GrandExchangePacket.java @@ -29,7 +29,10 @@ public class GrandExchangePacket implements OutgoingPacket } else { buffer.put(0).putShort(0).putInt(0).putInt(0).putInt(0).putInt(0); } + try { context.getPlayer().getSession().write(buffer); + } catch (Exception e) { + } } }