Files
Bubberstation/code/modules/modular_computers/file_system/programs/ntdownloader.dm
Ghom fec7ccc6fd The Coupon Master PDA app (#80240)
## About The Pull Request
This PR adds a new PDA program to the supply category, which allows
users to redeems coupons for various cargo packs (mostly goodies), like
the ones also found at the bottom of cig packs.

How it works is fairly simple: 

- Once installed, the modular computer subsystem will periodically, at a
3-5 minutes interval, generate a coupon code datum associated to a plain
text code, which is sent out to everyone with the program installed.
- The user can then open the program and insert the text into an input
box to redeem the coupon code, which is then associated with their bank
account.
- He will then have to find a photocopier, and tap it with the PDA to
print the coupon. Only one coupon can be printed. Photocopier fees
apply, so it'd cost 5 creds to the average assistant to print the
coupon.
- He can then insert the coupon in a cargo console and order/reuest the
associated pack (same deal as cig coupons).
- Some coupon codes however, especially those with juicer discounts,
will expire after a while if not printed.

Albeit mostly innocuous, the program provides negative Detomatix
resistance, slowly fills the computer file storage with trash files with
each redeemed coupon, and halves the download speed of new apps. Not
really the cleanest ware out there.

This PR also extends coupons to several non-goody packs, since they have
been privately buyable for over the last couple years now. Some packs
get discounts less frequently however, with those in the uncommon
category being roughly 1 in a 12 chance and the rare being 1 in 50.

Here's a screenshot of the UI (outdated, I've reduced the height from
500 to 400 and the notice box tip to specify the right click):
![Coupon
Master](https://github.com/tgstation/tgstation/assets/42542238/1d242d09-0f62-4e2e-8a6e-014daa3f6a55)

Fun fact: Right now, the odds of a 75% discount coming from the Coupon
Master for the 1.000.000 credits bycycle pack are roughly 0.0012%, while
that of a 50% for the same pack, from a cig pack coupon are 0.0042%.

## Why It's Good For The Game
These last couple days I've been wanting to test myself at making simple
UIs, as well as contributing to the modular computers feature, which has
started to become pretty neat ever since PDAs were reworked into a
subtype of it.

Beside, coupons are a very small feature limited to the bottom of
cigarette packs (also possibly cursed) in the current state of affairs.
Cargo is filled with packs that are niche or fluff. Modular computers
also has those little things that, while interesting, do not contribute
a whole lot. Maybe this is one of them, but I guess free* coupons are
always a big W.

## Changelog

🆑
add: Added the 'Coupon Master' program for the PDA. Install it to
receive periodical, redeemable coupons for several cargo packs. Requires
NTnet connection and the messenger enabled to work.
add: Coupons are no longer only limited to goodies, but may also apply
discount to some other packs as well.
/🆑

<sup>*minus the photocopier fee</sup>

---------

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
2023-12-25 11:19:56 -08:00

164 lines
6.1 KiB
Plaintext

/datum/computer_file/program/ntnetdownload
filename = "ntsoftwarehub"
filedesc = "NT Software Hub"
program_open_overlay = "generic"
extended_desc = "This program allows downloads of software from official NT repositories"
undeletable = TRUE
size = 4
program_flags = PROGRAM_REQUIRES_NTNET
tgui_id = "NtosNetDownloader"
program_icon = "download"
///The program currently being downloaded.
var/datum/computer_file/program/downloaded_file
///Boolean on whether the `downloaded_file` is being downloaded from the Syndicate store,
///in which case it will appear as 'ENCRYPTED' in logs, rather than display file name.
var/hacked_download = FALSE
///How much of the data has been downloaded.
var/download_completion
///The error message being displayed to the user, if necessary. Null if there isn't one.
var/downloaderror
///The list of categories to display in the UI, in order of which they appear.
var/static/list/show_categories = list(
PROGRAM_CATEGORY_DEVICE,
PROGRAM_CATEGORY_EQUIPMENT,
PROGRAM_CATEGORY_GAMES,
PROGRAM_CATEGORY_SECURITY,
PROGRAM_CATEGORY_ENGINEERING,
PROGRAM_CATEGORY_SUPPLY,
PROGRAM_CATEGORY_SCIENCE,
)
/datum/computer_file/program/ntnetdownload/kill_program(mob/user)
abort_file_download()
ui_header = null
. = ..()
/datum/computer_file/program/ntnetdownload/proc/begin_file_download(filename)
if(downloaded_file)
return FALSE
var/datum/computer_file/program/PRG = SSmodular_computers.find_ntnet_file_by_name(filename)
if(!PRG || !istype(PRG))
return FALSE
// Attempting to download antag only program, but without having emagged/syndicate computer. No.
if((PRG.program_flags & PROGRAM_ON_SYNDINET_STORE) && !(computer.obj_flags & EMAGGED))
return FALSE
if(!computer || !computer.can_store_file(PRG))
return FALSE
ui_header = "downloader_running.gif"
if(PRG in SSmodular_computers.available_station_software)
generate_network_log("Began downloading file [PRG.filename].[PRG.filetype] from NTNet Software Repository.")
hacked_download = FALSE
else if(PRG in SSmodular_computers.available_antag_software)
generate_network_log("Began downloading file **ENCRYPTED**.[PRG.filetype] from unspecified server.")
hacked_download = TRUE
else
generate_network_log("Began downloading file [PRG.filename].[PRG.filetype] from unspecified server.")
hacked_download = FALSE
downloaded_file = PRG.clone()
/datum/computer_file/program/ntnetdownload/proc/abort_file_download()
if(!downloaded_file)
return
generate_network_log("Aborted download of file [hacked_download ? "**ENCRYPTED**" : "[downloaded_file.filename].[downloaded_file.filetype]"].")
downloaded_file = null
download_completion = FALSE
ui_header = null
/datum/computer_file/program/ntnetdownload/proc/complete_file_download()
if(!downloaded_file)
return
generate_network_log("Completed download of file [hacked_download ? "**ENCRYPTED**" : "[downloaded_file.filename].[downloaded_file.filetype]"].")
if(!computer || !computer.store_file(downloaded_file))
// The download failed
downloaderror = "I/O ERROR - Unable to save file. Check whether you have enough free space on your hard drive and whether your hard drive is properly connected. If the issue persists contact your system administrator for assistance."
downloaded_file = null
download_completion = FALSE
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/process_tick(seconds_per_tick)
if(!downloaded_file)
return
if(download_completion >= downloaded_file.size)
complete_file_download()
// Download speed according to connectivity state. NTNet server is assumed to be on unlimited speed so we're limited by our local connectivity
var/download_netspeed
// Speed defines are found in misc.dm
switch(ntnet_status)
if(NTNET_LOW_SIGNAL)
download_netspeed = NTNETSPEED_LOWSIGNAL
if(NTNET_GOOD_SIGNAL)
download_netspeed = NTNETSPEED_HIGHSIGNAL
if(NTNET_ETHERNET_SIGNAL)
download_netspeed = NTNETSPEED_ETHERNET
if(download_netspeed)
if(HAS_TRAIT(computer, TRAIT_MODPC_HALVED_DOWNLOAD_SPEED))
download_netspeed *= 0.5
download_completion += download_netspeed
/datum/computer_file/program/ntnetdownload/ui_act(action, params, datum/tgui/ui, datum/ui_state/state)
switch(action)
if("PRG_downloadfile")
if(!downloaded_file)
begin_file_download(params["filename"])
return TRUE
if("PRG_reseterror")
if(downloaderror)
download_completion = FALSE
downloaded_file = null
downloaderror = ""
return TRUE
return FALSE
/datum/computer_file/program/ntnetdownload/ui_data(mob/user)
var/list/data = list()
var/list/access = computer.GetAccess()
data["downloading"] = !!downloaded_file
data["error"] = downloaderror || FALSE
// Download running. Wait please..
if(downloaded_file)
data["downloadname"] = downloaded_file.filename
data["downloaddesc"] = downloaded_file.filedesc
data["downloadsize"] = downloaded_file.size
data["downloadcompletion"] = round(download_completion, 0.1)
data["disk_size"] = computer.max_capacity
data["disk_used"] = computer.used_capacity
data["emagged"] = (computer.obj_flags & EMAGGED)
var/list/repo = SSmodular_computers.available_antag_software | SSmodular_computers.available_station_software
for(var/datum/computer_file/program/programs as anything in repo)
data["programs"] += list(list(
"icon" = programs.program_icon,
"filename" = programs.filename,
"filedesc" = programs.filedesc,
"fileinfo" = programs.extended_desc,
"category" = programs.downloader_category,
"installed" = !!computer.find_file_by_name(programs.filename),
"compatible" = check_compatibility(programs),
"size" = programs.size,
"access" = programs.can_run(user, downloading = TRUE, access = access),
"verifiedsource" = !!(programs.program_flags & PROGRAM_ON_NTNET_STORE),
))
data["categories"] = show_categories
return data
///Checks if a provided `program_to_check` is compatible to be downloaded on our computer.
/datum/computer_file/program/ntnetdownload/proc/check_compatibility(datum/computer_file/program/program_to_check)
if(!program_to_check || !program_to_check.is_supported_by_hardware(hardware_flag = computer.hardware_flag, loud = FALSE))
return FALSE
return TRUE