From 7dd807082d65fc0632ce76e47e0413e33f9462b2 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Thu, 28 Jul 2022 14:28:08 +0000 Subject: [PATCH] Added cheat option for singleplayer - in Server/worldprops/default.conf set i_want_to_cheat to true for GE autobuy/autosell --- .../src/main/kotlin/rs09/ServerConstants.kt | 3 ++ .../main/kotlin/rs09/game/ge/GrandExchange.kt | 50 +++++++++++++------ .../game/system/config/ServerConfigParser.kt | 1 + Server/worldprops/default.conf | 2 + 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/Server/src/main/kotlin/rs09/ServerConstants.kt b/Server/src/main/kotlin/rs09/ServerConstants.kt index b0ab26f70..8578389e5 100644 --- a/Server/src/main/kotlin/rs09/ServerConstants.kt +++ b/Server/src/main/kotlin/rs09/ServerConstants.kt @@ -137,6 +137,9 @@ class ServerConstants { @JvmField var WATCHDOG_ENABLED = true + @JvmField + var I_AM_A_CHEATER = false + //location names for the ::to command. val TELEPORT_DESTINATIONS = arrayOf( arrayOf(Location.create(2974, 4383, 2), "corp", "corporal", "corporeal"), diff --git a/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt b/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt index 991ed1de8..072395b80 100644 --- a/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt +++ b/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt @@ -5,10 +5,12 @@ import core.game.ge.OfferState import core.game.node.entity.player.Player import core.game.node.entity.player.info.PlayerDetails import core.game.node.entity.player.link.audio.Audio +import core.game.system.task.Pulse import rs09.ServerConstants import rs09.game.system.SystemLogger import rs09.game.system.command.Privilege import rs09.game.system.config.ItemConfigParser +import rs09.game.world.GameWorld import rs09.game.world.repository.Repository import rs09.tools.stringtools.colorize import java.lang.Integer.max @@ -20,9 +22,6 @@ import java.util.concurrent.LinkedBlockingDeque * @author Ceikry */ class GrandExchange : StartupListener, Commands { - private val GET_SPECIFIC_OFFER_BY_UID = "SELECT * FROM player_offers WHERE uid = ?;" - private val GET_MATCHES_FROM_PLAYER_OFFERS = "SELECT * FROM player_offers WHERE item_id = ? AND is_sale = ? AND offer_state < 4 AND NOT offer_state = 2;" - private val GET_MATCH_FROM_BOT_OFFERS = "SELECT * FROM bot_offers WHERE item_id = ?;" /** * Fallback safety check to make sure we don't start the GE twice under any circumstance @@ -56,18 +55,6 @@ class GrandExchange : StartupListener, Commands { isRunning = true } - private fun getOfferByUid(uid: Long): GrandExchangeOffer? { - var offer: GrandExchangeOffer? = null - GEDB.run { conn -> - val query = conn.prepareStatement(GET_SPECIFIC_OFFER_BY_UID) - query.setLong(1, uid) - val res = query.executeQuery() - - if (res.next()) - offer = GrandExchangeOffer.fromQuery(res) - } - return offer - } private fun tryExchangeWithBots(offer: GrandExchangeOffer) { GEDB.run { conn -> @@ -125,6 +112,22 @@ class GrandExchange : StartupListener, Commands { companion object { val pendingOffers = LinkedBlockingDeque() + private val GET_SPECIFIC_OFFER_BY_UID = "SELECT * FROM player_offers WHERE uid = ?;" + private val GET_MATCHES_FROM_PLAYER_OFFERS = "SELECT * FROM player_offers WHERE item_id = ? AND is_sale = ? AND offer_state < 4 AND NOT offer_state = 2;" + private val GET_MATCH_FROM_BOT_OFFERS = "SELECT * FROM bot_offers WHERE item_id = ?;" + + private fun getOfferByUid(uid: Long): GrandExchangeOffer? { + var offer: GrandExchangeOffer? = null + GEDB.run { conn -> + val query = conn.prepareStatement(GET_SPECIFIC_OFFER_BY_UID) + query.setLong(1, uid) + val res = query.executeQuery() + + if (res.next()) + offer = GrandExchangeOffer.fromQuery(res) + } + return offer + } @JvmStatic fun getRecommendedPrice(itemID: Int, from_bot: Boolean = false): Int { @@ -240,6 +243,23 @@ class GrandExchange : StartupListener, Commands { Repository.sendNews(username + " just offered " + offer.amount + " " + getItemName(offer.itemID) + " on the GE.") } + if (ServerConstants.I_AM_A_CHEATER) { + val otherO = GrandExchangeOffer() + otherO.itemID = offer.itemID + otherO.amount = offer.amount + otherO.sell = !offer.sell + otherO.offeredValue = offer.offeredValue + offer.writeNew() + GameWorld.Pulser.submit(object : Pulse(5) { + override fun pulse(): Boolean { + val offer2 = getOfferByUid(offer.uid) ?: return false + exchange(offer2, otherO) + return true + } + }) + return true + } + pendingOffers.add(offer) return true } diff --git a/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt b/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt index ab551a544..a336beac1 100644 --- a/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt +++ b/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt @@ -120,6 +120,7 @@ object ServerConfigParser { ServerConstants.BANK_BOOTH_NOTE_UIM = data.getBoolean("world.bank_booth_note_uim", true) ServerConstants.DISCORD_GE_WEBHOOK = data.getString("server.discord_webhook", "") ServerConstants.WATCHDOG_ENABLED = data.getBoolean("server.watchdog_enabled", true) + ServerConstants.I_AM_A_CHEATER = data.getBoolean("world.i_want_to_cheat", false) } diff --git a/Server/worldprops/default.conf b/Server/worldprops/default.conf index 467a96e60..cfdc8cd90 100644 --- a/Server/worldprops/default.conf +++ b/Server/worldprops/default.conf @@ -60,6 +60,8 @@ verbose_cutscene = false show_rules = true #the number of revenants active at a time revenant_population = 30 +#enable auto-buy/auto-sell on the GE. +i_want_to_cheat = false [paths] #path to the data folder, which contains the cache subfolder and such