From 88fbe41208a5d8736337bbbdb657101cdeddebe5 Mon Sep 17 00:00:00 2001 From: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com> Date: Sun, 4 Aug 2024 04:01:35 -0400 Subject: [PATCH] Allows Job and Species specific items to roll discounts (#25915) * Job and Species Discounts * Condensed procs * No His Grace discounts * Better crates, no discounts for 10 TC or lower * Removes extraneous bits * Removed excess null, fixed out-of-scope discount floor change * Documentation, null check, and a lot of snakes * Reworked logic of where it does job/species checks * Curly brackets begone Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com> Signed-off-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com> * Curly brackets begone pt2 Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com> Signed-off-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com> * Removed for loops in job-species checks * No freebies * Early continues --------- Signed-off-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com> Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com> --- code/datums/uplink_items/uplink_general.dm | 28 +++++++++++++++------- code/datums/uplink_items/uplink_traitor.dm | 3 +-- code/game/objects/items/devices/uplinks.dm | 8 ++++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/code/datums/uplink_items/uplink_general.dm b/code/datums/uplink_items/uplink_general.dm index 074048268ca..3db7889d818 100644 --- a/code/datums/uplink_items/uplink_general.dm +++ b/code/datums/uplink_items/uplink_general.dm @@ -2,14 +2,12 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) // This define is used when we have to spawn in an uplink item in a weird way, like a Surplus crate spawning an actual crate. // Use this define by setting `uses_special_spawn` to TRUE on the item, and then checking if the parent proc of `spawn_item` returns this define. If it does, implement your special spawn after that. -/proc/get_uplink_items(obj/item/uplink/U) +/proc/get_uplink_items(obj/item/uplink/U, mob/user) var/list/uplink_items = list() var/list/sales_items = list() var/newreference = 1 if(!length(uplink_items)) - for(var/path in GLOB.uplink_items) - var/datum/uplink_item/I = new path if(!I.item) continue @@ -17,30 +15,42 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) continue if(length(I.excludefrom) && (U.uplink_type in I.excludefrom)) continue + //Add items to discount pool, checking job, species, and hijacker status + if(I.job && !(user.mind.assigned_role in I.job)) //If your job does not match, no discount + continue + if(I.species && !(user.dna?.species.name in I.species)) //If your species does not match, no discount + continue + if(I.hijack_only && !(locate(/datum/objective/hijack) in user.mind.get_all_objectives())) //If you aren't a hijacker, no hijack only items + continue if(!uplink_items[I.category]) uplink_items[I.category] = list() uplink_items[I.category] += I + + if(I.limited_stock < 0 && I.can_discount && I.item && I.cost > 5) sales_items += I + if(isnull(user)) //Handles surplus + return uplink_items + for(var/i in 1 to 3) - var/datum/uplink_item/I = pick_n_take(sales_items) - var/datum/uplink_item/A = new I.type + var/datum/uplink_item/sale_item = pick_n_take(sales_items) + var/datum/uplink_item/A = new sale_item.type var/discount = 0.5 A.limited_stock = 1 + sale_item.refundable = FALSE + A.refundable = FALSE if(A.cost >= 100) discount *= 0.5 // If the item costs 100TC or more, it's only 25% off. A.cost = max(round(A.cost * (1 - discount)), 1) A.category = "Discounted Gear" A.name += " ([round(((initial(A.cost) - A.cost) / initial(A.cost)) * 100)]% off!)" - A.job = null // If you get a job specific item selected, actually lets you buy it in the discount section - A.species = null //same as above for species speific items A.reference = "DIS[newreference]" A.desc += " Limit of [A.limited_stock] per uplink. Normally costs [initial(A.cost)] TC." - A.surplus = 0 // stops the surplus crate potentially giving out a bit too much - A.item = I.item + A.surplus = 0 //No freebies + A.item = sale_item.item newreference++ if(!uplink_items[A.category]) uplink_items[A.category] = list() diff --git a/code/datums/uplink_items/uplink_traitor.dm b/code/datums/uplink_items/uplink_traitor.dm index e949266ce2e..e117b493a09 100644 --- a/code/datums/uplink_items/uplink_traitor.dm +++ b/code/datums/uplink_items/uplink_traitor.dm @@ -4,7 +4,6 @@ /datum/uplink_item/jobspecific category = "Job Specific Tools" - can_discount = FALSE excludefrom = list(UPLINK_TYPE_NUCLEAR, UPLINK_TYPE_SST) // Stops the job specific category appearing for nukies //Clown @@ -145,6 +144,7 @@ job = list("Chaplain") surplus = 0 //No lucky chances from the crate; if you get this, this is ALL you're getting hijack_only = TRUE //This is a murderbone weapon, as such, it should only be available in those scenarios. + can_discount = FALSE //Janitor @@ -333,7 +333,6 @@ /datum/uplink_item/species_restricted category = "Species Specific Gear" - can_discount = FALSE excludefrom = list(UPLINK_TYPE_NUCLEAR, UPLINK_TYPE_SST) // Stops the job specific category appearing for nukies //skrell diff --git a/code/game/objects/items/devices/uplinks.dm b/code/game/objects/items/devices/uplinks.dm index 15cc43d49da..ffaa3372ff8 100644 --- a/code/game/objects/items/devices/uplinks.dm +++ b/code/game/objects/items/devices/uplinks.dm @@ -26,19 +26,18 @@ GLOBAL_LIST_EMPTY(world_uplinks) var/uplink_type = UPLINK_TYPE_TRAITOR /// Whether the uplink is jammed and cannot be used to order items. var/is_jammed = FALSE + /// Whether or not the uplink has generated its stock and discounts + var/items_generated = FALSE /obj/item/uplink/ui_host() return loc /obj/item/uplink/proc/update_uplink_type(new_uplink_type) uplink_type = new_uplink_type - uplink_items = get_uplink_items(src) /obj/item/uplink/New() ..() uses = 100 - uplink_items = get_uplink_items(src) - GLOB.world_uplinks += src /obj/item/uplink/Destroy() @@ -58,6 +57,9 @@ GLOBAL_LIST_EMPTY(world_uplinks) job = user.mind.assigned_role if(!species) species = user.dna.species.name + if(!items_generated) + uplink_items = get_uplink_items(src, user) + items_generated = TRUE var/list/cats = list()