From ead72eee56449f6d606839ee7b6dbb22bdf94449 Mon Sep 17 00:00:00 2001 From: Nerrathiel Date: Sat, 7 Dec 2019 22:48:29 +0100 Subject: [PATCH] Merchant bulk buy function (#7587) Adds additional function to the merchant software - Bulk Buy. Activating this function prompts the user to enter a number. If text is SOMEHOW entered, returns IC error message. If number lesser than 1 is entered, returns IC error message. Expects numbers equal or greater to 1. Function then executes standard money-purchase function using a loop. This loop executes X amount of times where X is the number user entered, ensuring they purchase the amount of items they want to buy up to as much money as they actually have This makes sure they cannot abuse this to buy more things than they can afford. This function greatly reduces lag caused by server spawning excess amount of items and makes merchant much more pleasant to play. Compiled without errors, tested on up-to-date private server, worked as expected. --- code/modules/merchant/merchant_programs.dm | 25 ++++++++++++- html/changelogs/MerchantBulkBuy.yml | 41 ++++++++++++++++++++++ nano/templates/merchant.tmpl | 3 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 html/changelogs/MerchantBulkBuy.yml diff --git a/code/modules/merchant/merchant_programs.dm b/code/modules/merchant/merchant_programs.dm index b0a17e3ead1..1d374a7b4f3 100644 --- a/code/modules/merchant/merchant_programs.dm +++ b/code/modules/merchant/merchant_programs.dm @@ -81,6 +81,26 @@ bank -= response return last_comms = "PAD NOT CONNECTED" + +/datum/computer_file/program/merchant/proc/bulk_offer(var/datum/trader/T, var/num) + var/BulkAmount = input("How many items? (Buy 1-50 items. 0 to cancel.)") as num + if(istext(BulkAmount)) + last_comms = "ERROR: NUMBER EXPECTED" + return + if(BulkAmount < 0 || BulkAmount > 50) + last_comms = "ERROR: POSITIVE NUMBER UP TO 50 EXPECTED" + return + if(pad) + for(var/BulkCounter = 0, BulkCounter < BulkAmount, BulkCounter++) + var/response = T.offer_money_for_trade(num, bank) + if(istext(response)) + last_comms = T.get_response(response, "No thank you.") + else + last_comms = T.get_response("trade_complete", "Thank you!") + T.trade(null,num, get_turf(pad)) + bank -= response + return + last_comms = "PAD NOT CONNECTED" /datum/computer_file/program/merchant/proc/bribe(var/datum/trader/T, var/amt) if(bank < amt) @@ -216,6 +236,9 @@ if(href_list["PRG_offer_money_for_item"]) . = 1 offer_money(T, text2num(href_list["PRG_offer_money_for_item"])+1) + if (href_list["PRG_bulk_money_for_item"]) + . = 1 + bulk_offer(T, text2num(href_list["PRG_bulk_money_for_item"])+1) if(href_list["PRG_what_do_you_want"]) . = 1 last_comms = T.what_do_you_want() @@ -224,4 +247,4 @@ sell_items(T) if(href_list["PRG_bribe"]) . = 1 - bribe(T, text2num(href_list["PRG_bribe"])) \ No newline at end of file + bribe(T, text2num(href_list["PRG_bribe"])) diff --git a/html/changelogs/MerchantBulkBuy.yml b/html/changelogs/MerchantBulkBuy.yml new file mode 100644 index 00000000000..65c14a61390 --- /dev/null +++ b/html/changelogs/MerchantBulkBuy.yml @@ -0,0 +1,41 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: Naelynn + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - rscadd: "Added bulk-buy function to the merchant. Less spamming click to buy things!" diff --git a/nano/templates/merchant.tmpl b/nano/templates/merchant.tmpl index 5b2ef1f0bb8..686883ecaad 100644 --- a/nano/templates/merchant.tmpl +++ b/nano/templates/merchant.tmpl @@ -29,7 +29,8 @@ {{for data.trades}} {{:value}} {{:helper.link('Trade', null, {'PRG_offer_item' : index})}} - {{:helper.link('Offer Money', null, {'PRG_offer_money_for_item' : index})}} + {{:helper.link('Money', null, {'PRG_offer_money_for_item' : index})}} + {{:helper.link('Bulk', null, {'PRG_bulk_money_for_item' : index})}} {{:helper.link('Ask Cost', null, {'PRG_how_much_do_you_want' : index})}} {{/for}}