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!
This commit is contained in:
jamix77 2020-03-23 22:06:08 +00:00 committed by RedSparr0w
parent b9c764f105
commit 52bdd4054a
6 changed files with 80 additions and 1 deletions

4
Server/itemstostock.txt Normal file
View file

@ -0,0 +1,4 @@
#ooh hash comment system uwu!
#format is:
#itemId:amount:percentage (as decimal)
2349:5000:1.50

View file

@ -1,5 +1,6 @@
package org.crandor; package org.crandor;
import org.crandor.game.content.eco.ge.GEAutoStock;
import org.crandor.game.system.SystemLogger; import org.crandor.game.system.SystemLogger;
import org.crandor.game.system.SystemShutdownHook; import org.crandor.game.system.SystemShutdownHook;
import org.crandor.game.system.mysql.SQLManager; import org.crandor.game.system.mysql.SQLManager;
@ -70,6 +71,7 @@ public final class Server {
reactor.start(); reactor.start();
SystemLogger.log(GameWorld.getName() + " flags " + GameWorld.getSettings().toString()); SystemLogger.log(GameWorld.getName() + " flags " + GameWorld.getSettings().toString());
SystemLogger.log(GameWorld.getName() + " started in " + t.duration(false, "") + " milliseconds."); SystemLogger.log(GameWorld.getName() + " started in " + t.duration(false, "") + " milliseconds.");
GEAutoStock.stock();
} }

View file

@ -1,4 +1,71 @@
package org.crandor.game.content.eco.ge; 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 { 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<Item> itemsToStock = new ArrayList<Item>();
/**
* The values to modify the price by
*/
public static final ArrayList<Double> modValues = new ArrayList<Double>();
/**
* 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));
}
}
} }

View file

@ -174,13 +174,16 @@ public final class GEOfferDispatch extends Pulse implements CallBack {
public static boolean dispatch(Player player, GrandExchangeOffer offer) { public static boolean dispatch(Player player, GrandExchangeOffer offer) {
if (offer.getAmount() < 1) { if (offer.getAmount() < 1) {
player.getPacketDispatch().sendMessage("You must choose the quantity you wish to buy!"); player.getPacketDispatch().sendMessage("You must choose the quantity you wish to buy!");
System.out.println("amountthing");
return false; return false;
} }
if (offer.getOfferedValue() < 1) { if (offer.getOfferedValue() < 1) {
player.getPacketDispatch().sendMessage("You must choose the price you wish to buy for!"); player.getPacketDispatch().sendMessage("You must choose the price you wish to buy for!");
System.out.println("pricethng");
return false; return false;
} }
if (offer.getState() != OfferState.PENDING || offer.getUid() != 0) { if (offer.getState() != OfferState.PENDING || offer.getUid() != 0) {
System.out.println("pendingthing");
return false; return false;
} }
offer.setPlayerUID(player.getDetails().getUid()); offer.setPlayerUID(player.getDetails().getUid());
@ -311,7 +314,7 @@ public final class GEOfferDispatch extends Pulse implements CallBack {
* Gets the next UID. * Gets the next UID.
* @return The UID. * @return The UID.
*/ */
private static long nextUID() { static long nextUID() {
long id = offsetUID++; long id = offsetUID++;
if (id == 0) { if (id == 0) {
return nextUID(); return nextUID();

View file

@ -29,7 +29,10 @@ public class GrandExchangePacket implements OutgoingPacket<GrandExchangeContext>
} else { } else {
buffer.put(0).putShort(0).putInt(0).putInt(0).putInt(0).putInt(0); buffer.put(0).putShort(0).putInt(0).putInt(0).putInt(0).putInt(0);
} }
try {
context.getPlayer().getSession().write(buffer); context.getPlayer().getSession().write(buffer);
} catch (Exception e) {
}
} }
} }