Files
Bubberstation/code/controllers/subsystem/modular_computers.dm
SkyratBot 49452b3851 [MIRROR] The Coupon Master PDA app [MDB IGNORE] (#25855)
* 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>

* The Coupon Master PDA app

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>
2023-12-25 20:38:54 +00:00

177 lines
6.7 KiB
Plaintext

s///The maximum amount of logs that can be generated before they start overwriting eachother.
#define MAX_LOG_COUNT 300
SUBSYSTEM_DEF(modular_computers)
name = "Modular Computers"
wait = 1 MINUTES
runlevels = RUNLEVEL_GAME
///List of all logs generated by ModPCs through the round.
///Stops at MAX_LOG_COUNT and must be purged to keep logging.
var/list/modpc_logs = list()
///List of all programs available to download from the NTNet store.
var/list/available_station_software = list()
///List of all programs that can be downloaded from an emagged NTNet store.
var/list/available_antag_software = list()
///List of all chat channels created by Chat Client.
var/list/chat_channels = list()
///Boolean on whether the IDS warning system is enabled
var/intrusion_detection_enabled = TRUE
///Boolean to show a message warning if there's an active intrusion for Wirecarp users.
var/intrusion_detection_alarm = FALSE
var/next_picture_id = 0
///Lazylist of coupons used by the Coupon Master PDA app. e.g. "COUPONCODE25" = coupon_code
var/list/discount_coupons
///When will the next coupon drop?
var/next_discount = 0
/datum/controller/subsystem/modular_computers/Initialize()
build_software_lists()
initialized = TRUE
return SS_INIT_SUCCESS
/datum/controller/subsystem/modular_computers/fire(resumed = FALSE)
if(discount_coupons && world.time >= next_discount)
announce_coupon()
///Generate new coupon codes that can be redeemed with the Coupon Master App
/datum/controller/subsystem/modular_computers/proc/announce_coupon()
//If there's no way to announce the coupon, we may as well skip it.
if(!length(GLOB.announcement_systems))
return
var/obj/machinery/announcement_system/announcement_system = pick(GLOB.announcement_systems)
var/static/list/discounts = list("0.10" = 7, "0.15" = 16, "0.20" = 20, "0.25" = 16, "0.50" = 8, "0.66" = 1)
var/static/list/flash_discounts = list("0.30" = 3, "0.40" = 8, "0.50" = 8, "0.66" = 2, "0.75" = 1)
///Eliminates non-alphanumeri characters, as well as the word "Single-Pack" or "Pack" or "Crate" from the coupon code
var/static/regex/strip_pack_name = regex("\[^a-zA-Z0-9]|(Single-)?Pack|Crate", "g")
var/datum/supply_pack/discounted_pack = pick(GLOB.discountable_packs[pick_weight(GLOB.pack_discount_odds)])
var/pack_name = initial(discounted_pack.name)
var/chosen_discount
var/expires_in = 0
if(prob(75))
chosen_discount = text2num(pick_weight(discounts))
if(prob(20))
expires_in = rand(8,10)
else
chosen_discount = text2num(pick_weight(flash_discounts))
expires_in = rand(2, 4)
var/coupon_code = "[uppertext(strip_pack_name.Replace(pack_name, ""))][chosen_discount*100]"
var/list/targets = list()
for (var/messenger_ref in GLOB.pda_messengers)
var/datum/computer_file/program/messenger/messenger = GLOB.pda_messengers[messenger_ref]
if(locate(/datum/computer_file/program/coupon) in messenger?.computer.stored_files)
targets += messenger
///Don't go any further if the same coupon code has been done alrady or if there's no recipient for the 'promo'.
if((coupon_code in discount_coupons) || !length(targets))
return
var/datum/coupon_code/coupon = new(chosen_discount, discounted_pack, expires_in)
discount_coupons[coupon_code] = coupon
///pda message code here
var/static/list/promo_messages = list(
"A new discount has dropped for %GOODY: %DISCOUNT.",
"Check this new offer out: %GOODY, now %DISCOUNT off.",
"Now on sales: %GOODY, at %DISCOUNT discount!",
"This item is now on sale (%DISCOUNT off): %GOODY.",
"Would you look at that! A %DISCOUNT discount on %GOODY!",
"Exclusive offer for %GOODY. Only %DISCOUNT! Get it now:",
"%GOODY is now %DISCOUNT off.",
"*RING* A new discount has dropped: %GOODY, %DISCOUNT off.",
"%GOODY - %DISCOUNT off."
)
var/static/list/code_messages = list(
"Here's the code",
"Use this code to redeem it",
"Open the app to redeem it",
"Code",
"Redeem it now",
"Buy it now",
)
var/chosen_promo_message = replacetext(replacetext(pick(promo_messages), "%GOODY", pack_name), "%DISCOUNT", "[chosen_discount*100]%")
var/datum/signal/subspace/messaging/tablet_message/signal = new(announcement_system, list(
"fakename" = "Coupon Master",
"fakejob" = "Goodies Promotion",
"message" = "[chosen_promo_message] [pick(code_messages)]: [coupon_code][expires_in ? " (EXPIRES IN [expires_in] MINUTES)" : ""].",
"targets" = targets,
"automated" = TRUE,
))
signal.send_to_receivers()
next_discount = world.time + rand(3, 5) MINUTES
///Finds all downloadable programs and adds them to their respective downloadable list.
/datum/controller/subsystem/modular_computers/proc/build_software_lists()
for(var/datum/computer_file/program/prog as anything in subtypesof(/datum/computer_file/program))
// Has no TGUI file so is not meant to be a downloadable thing.
if(!initial(prog.tgui_id) || !initial(prog.filename))
continue
prog = new prog
if(prog.program_flags & PROGRAM_ON_NTNET_STORE)
available_station_software.Add(prog)
if(prog.program_flags & PROGRAM_ON_SYNDINET_STORE)
available_antag_software.Add(prog)
///Attempts to find a new file through searching the available stores with its name.
/datum/controller/subsystem/modular_computers/proc/find_ntnet_file_by_name(filename)
for(var/datum/computer_file/program/programs as anything in available_station_software + available_antag_software)
if(filename == programs.filename)
return programs
return null
///Attempts to find a chatorom using the ID of the channel.
/datum/controller/subsystem/modular_computers/proc/get_chat_channel_by_id(id)
for(var/datum/ntnet_conversation/chan as anything in chat_channels)
if(chan.id == id)
return chan
return null
/**
* Records a message into the station logging system for the network
* Arguments:
* * log_string - The message being logged
*/
/datum/controller/subsystem/modular_computers/proc/add_log(log_string)
var/list/log_text = list()
log_text += "\[[station_time_timestamp()]\]"
log_text += "*SYSTEM* - "
log_text += log_string
log_string = log_text.Join()
modpc_logs.Add(log_string)
// We have too many logs, remove the oldest entries until we get into the limit
if(modpc_logs.len > MAX_LOG_COUNT)
modpc_logs = modpc_logs.Copy(modpc_logs.len - MAX_LOG_COUNT, 0)
/**
* Removes all station logs and leaves it with an alert that it's been wiped.
*/
/datum/controller/subsystem/modular_computers/proc/purge_logs()
modpc_logs = list()
add_log("-!- LOGS DELETED BY SYSTEM OPERATOR -!-")
/**
* Returns a name which a /datum/picture can be assigned to.
* Use this function to get asset names and to avoid cache duplicates/overwriting.
*/
/datum/controller/subsystem/modular_computers/proc/get_next_picture_name()
var/next_uid = next_picture_id
next_picture_id++
return "ntos_picture_[next_uid].png"
#undef MAX_LOG_COUNT