Skip to content

Commit

Permalink
feat(uplink): TGUI and uplink component
Browse files Browse the repository at this point in the history
  • Loading branch information
Filatelele authored Apr 24, 2024
1 parent fa22d01 commit 4ce1704
Show file tree
Hide file tree
Showing 51 changed files with 1,050 additions and 1,117 deletions.
15 changes: 3 additions & 12 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
#include "code\_global_vars\lists\pipe_dispenser.dm"
#include "code\_global_vars\lists\rcd.dm"
#include "code\_global_vars\lists\russian.dm"
#include "code\_global_vars\lists\traitor_uplink.dm"
#include "code\_global_vars\lists\wheelcannon.dm"
#include "code\_global_vars\monikers\_animal_moniker.dm"
#include "code\_global_vars\monikers\moniker.dm"
Expand Down Expand Up @@ -346,6 +347,7 @@
#include "code\datums\components\movable_physics.dm"
#include "code\datums\components\movement_detector.dm"
#include "code\datums\components\orbiter.dm"
#include "code\datums\components\uplink.dm"
#include "code\datums\configuration\__defines.dm"
#include "code\datums\configuration\admin_section.dm"
#include "code\datums\configuration\ban_section.dm"
Expand Down Expand Up @@ -544,17 +546,6 @@
#include "code\datums\uplink\categories\stealth_and_camouflage_items.dm"
#include "code\datums\uplink\categories\stealthy_and_inconspicuous_weapons.dm"
#include "code\datums\uplink\categories\telecrystals.dm"
#include "code\datums\uplink\deity\_defines.dm"
#include "code\datums\uplink\deity\deity_categories.dm"
#include "code\datums\uplink\deity\deity_items.dm"
#include "code\datums\uplink\deity\general.dm"
#include "code\datums\uplink\deity\unlockable_categories.dm"
#include "code\datums\uplink\deity\form_specific\narsie\basic.dm"
#include "code\datums\uplink\deity\form_specific\narsie\minions.dm"
#include "code\datums\uplink\deity\form_specific\narsie\sacrificing.dm"
#include "code\datums\uplink\deity\form_specific\wizard\single_charge.dm"
#include "code\datums\uplink\deity\form_specific\wizard\wizard_conjuration.dm"
#include "code\datums\uplink\deity\form_specific\wizard\wizard_transmutation.dm"
#include "code\datums\vending\stored_item.dm"
#include "code\datums\vending\vending.dm"
#include "code\datums\vote\custom.dm"
Expand Down Expand Up @@ -1161,7 +1152,6 @@
#include "code\game\objects\items\devices\traitordevices.dm"
#include "code\game\objects\items\devices\transfer_valve.dm"
#include "code\game\objects\items\devices\tvcamera.dm"
#include "code\game\objects\items\devices\uplink.dm"
#include "code\game\objects\items\devices\uplink_random_lists.dm"
#include "code\game\objects\items\devices\whistle.dm"
#include "code\game\objects\items\devices\PDA\cart.dm"
Expand Down Expand Up @@ -2988,6 +2978,7 @@
#include "code\modules\tgui_panel\external.dm"
#include "code\modules\tgui_panel\telemetry.dm"
#include "code\modules\tgui_panel\tgui_panel.dm"
#include "code\modules\uplink\uplink_presets.dm"
#include "code\modules\vehicles\bike.dm"
#include "code\modules\vehicles\cargo_train.dm"
#include "code\modules\vehicles\engine.dm"
Expand Down
6 changes: 6 additions & 0 deletions code/__defines/contracts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
#define CONTRACT_STEAL_OPERATION 2
#define CONTRACT_STEAL_SCIENCE 3
#define CONTRACT_STEAL_UNDERPANTS 4

#define CONTRACT_CATEGORY_STEAL "Steal"
#define CONTRACT_CATEGORY_IMPLANT "Implant"
#define CONTRACT_CATEGORY_ASSASINATE "Assasinate"
#define CONTRACT_CATEGORY_DUMP "Dump"
#define CONTRACT_CATEGORY_RECON "Recon"
8 changes: 8 additions & 0 deletions code/_global_vars/lists/traitor_uplink.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
GLOBAL_LIST_INIT(contract_categories, list(CONTRACT_CATEGORY_STEAL,
CONTRACT_CATEGORY_IMPLANT,
CONTRACT_CATEGORY_ASSASINATE,
CONTRACT_CATEGORY_DUMP,
CONTRACT_CATEGORY_RECON
))

GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item))
5 changes: 0 additions & 5 deletions code/_helpers/global_access.dm
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,6 @@
return global.wireColours;
if("world_topic_spam_protect_time")
return global.world_topic_spam_protect_time;
if("world_uplinks")
return global.world_uplinks;
if("worths")
return global.worths;
if("wrapped_species_by_ref")
Expand Down Expand Up @@ -1596,8 +1594,6 @@
global.wireColours=newval;
if("world_topic_spam_protect_time")
global.world_topic_spam_protect_time=newval;
if("world_uplinks")
global.world_uplinks=newval;
if("worths")
global.worths=newval;
if("wrapped_species_by_ref")
Expand Down Expand Up @@ -2065,7 +2061,6 @@
"whitelisted_species",
"wireColours",
"world_topic_spam_protect_time",
"world_uplinks",
"worths",
"wrapped_species_by_ref",
"z_levels",
Expand Down
2 changes: 1 addition & 1 deletion code/_helpers/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var/global/list/all_grabstates[0]
var/global/list/all_grabobjects[0]

// Uplinks
var/list/obj/item/device/uplink/world_uplinks = list()
GLOBAL_LIST_EMPTY(uplinks)

// Surgery steps
GLOBAL_LIST_EMPTY(surgery_steps)
Expand Down
214 changes: 214 additions & 0 deletions code/datums/components/uplink.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/datum/component/uplink
dupe_mode = COMPONENT_DUPE_UNIQUE
var/name = "syndicate uplink"
var/ui_style = "Uplink"
var/active = FALSE
var/lockable = TRUE
var/locked = TRUE
var/allow_restricted = TRUE
var/telecrystals
var/list/uplink_items
var/datum/mind/owner = null
var/datum/game_mode/gamemode
var/datum/uplink_purchase_log/purchase_log
var/unlock_code
var/unlock_emote
var/traitor_frequency
var/debug = FALSE
var/exploit_uid = null
// Can STD be purchased for free
var/complimentary_std = TRUE

/datum/component/uplink/Initialize(owner, lockable = TRUE, active = FALSE, datum/game_mode/gamemode, starting_tc = DEFAULT_TELECRYSTAL_AMOUNT)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE

GLOB.uplinks += src

src.owner = owner
src.lockable = lockable
src.active = active
src.gamemode = gamemode
telecrystals = starting_tc
if(!lockable)
active = TRUE
locked = FALSE

/datum/component/uplink/inherit_component(datum/component/uplink/U)
lockable |= U.lockable
active |= U.active
if(!gamemode)
gamemode = U.gamemode
telecrystals += U.telecrystals

/datum/component/uplink/Destroy()
GLOB.uplinks -= src
gamemode = null
return ..()

/datum/component/uplink/proc/LoadTC(mob/user, obj/item/stack/TC, silent = FALSE)
if(!silent)
to_chat(user, SPAN_NOTICE("You slot [TC] into [parent] and charge its internal uplink."))
var/amt = TC.amount
telecrystals += amt
TC.use(amt)

/datum/component/uplink/proc/set_gamemode(_gamemode)
gamemode = _gamemode

/datum/component/uplink/proc/interact(mob/user)
if(locked)
return

active = TRUE
if(user)
tgui_interact(user)

/datum/component/uplink/tgui_state(mob/user)
return GLOB.tgui_inventory_state

/datum/component/uplink/tgui_interact(mob/user, datum/tgui/ui)
active = TRUE
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, ui_style, name)
ui.set_autoupdate(FALSE)
ui.open()

/datum/component/uplink/tgui_data(mob/user)
if(!user.mind)
return

var/list/data = list(
"telecrystals" = telecrystals,
"lockable" = lockable,
"selectedExploitUID" = exploit_uid,
)

data["exploitData"] = list()
if(!isnull(exploit_uid))
for(var/datum/computer_file/crew_record/L in GLOB.all_crew_records)
if(L.uid != exploit_uid)
continue

var/list/fields = list(
REC_FIELD(name),
REC_FIELD(sex),
REC_FIELD(age),
REC_FIELD(species),
REC_FIELD(homeSystem),
REC_FIELD(background),
REC_FIELD(religion),
REC_FIELD(fingerprint),
REC_FIELD(antagRecord))
var/list/rec_fields = list()
for(var/field in fields)
var/record_field/F = locate(field) in L.fields
if(!F)
continue

rec_fields[html_encode(F.name)] += list(F.get_display_value())

data["exploitData"] += rec_fields
break

return data

/datum/component/uplink/tgui_static_data(mob/user)
var/list/data = list()

var/list/all_contracts = list()
for(var/datum/antag_contract/AC in GLOB.traitors.fixer.return_contracts(user?.mind))
all_contracts[AC.category] += list(list(
"name" = AC.name,
"category" = AC.category,
"desc" = AC.desc,
"reward" = AC.reward,
))

data["contractCategories"] = list()
for(var/category in GLOB.contract_categories)
data["contractCategories"] += list(list(
"name" = category,
"contracts" = LAZYCOPY(all_contracts[category]),
))

uplink_items = get_uplink_items(src, allow_sales = TRUE)

data["itemCategories"] = list()
for(var/category in uplink_items)
var/list/cat = list(
"name" = capitalize(replacetext(replacetext("[category]", "/datum/uplink_category/", ""), "_", " "))
)

for(var/item in uplink_items[category])
var/datum/uplink_item/I = uplink_items[category][item]
if(LAZYLEN(I.job_specific))
var/is_inaccessible = TRUE
for(var/R in I.job_specific)
if(R == user.mind.assigned_role || debug)
is_inaccessible = FALSE
if(is_inaccessible)
continue

cat["items"] += list(list(
"name" = I.name,
"cost" = I.cost(telecrystals, src),
"desc" = I.desc,
"path" = replacetext(replacetext("[I.path]", "/obj/item/", ""), "/", "-"),
))

data["itemCategories"] += list(cat)

data["crewRecords"] = list()
for(var/datum/computer_file/crew_record/L in GLOB.all_crew_records)
data["crewRecords"] += list(list(
"name" = L.get_name(),
"uid" = L.uid,
))

return data

/datum/component/uplink/tgui_act(action, params)
. = ..()
if(.)
return

if(!active)
return

switch(action)
if("buy")
var/item_name = params["name"]
var/list/buyable_items = list()
for(var/category in uplink_items)
buyable_items += uplink_items[category]
if(item_name in buyable_items)
var/datum/uplink_item/I = buyable_items[item_name]
MakePurchase(usr, I)
return TRUE

if("lock")
active = FALSE
locked = TRUE
SStgui.close_uis(src)
return TRUE

if("select_exploit")
var/old_exploit_uid = exploit_uid
exploit_uid = text2num(params["uid"])
if(exploit_uid == old_exploit_uid)
exploit_uid = null
return TRUE

/datum/component/uplink/proc/MakePurchase(mob/user, datum/uplink_item/U)
if(!istype(U))
return

if(!user || user.incapacitated())
return

if(telecrystals < U.item_cost)
return

U.buy(src, user)
27 changes: 13 additions & 14 deletions code/datums/mind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,15 @@
memory = null//Remove any memory they may have had.
if("crystals")
if (usr.client.holder.rights & R_FUN)
var/obj/item/device/uplink/suplink = find_syndicate_uplink()
var/datum/component/uplink/suplink = find_syndicate_uplink()
if(!suplink)
to_chat(usr, "<span class='warning'>Failed to find an uplink.</span>")
to_chat(usr, SPAN_WARNING("Failed to find an uplink."))
return
var/crystals = suplink.uses
crystals = input("Amount of telecrystals for [key]","Operative uplink", crystals) as null|num
if (!isnull(crystals) && !QDELETED(suplink))
suplink.uses = crystals

var/crystals = suplink.telecrystals
crystals = tgui_input_number(usr, "Amount of telecrystals for [key]", "Operative uplink", crystals, min_value = 0)
if(!isnull(crystals) && !QDELETED(suplink))
suplink.telecrystals = crystals
log_and_message_admins("set the telecrystals for [key] to [crystals]")

else if (href_list["obj_announce"])
Expand All @@ -456,17 +457,15 @@
edit_memory()

/datum/mind/proc/find_syndicate_uplink()
var/datum/component/uplink/uplink
var/list/L = current.get_contents()
for (var/obj/item/I in L)
if (I.hidden_uplink)
return I.hidden_uplink
return null
for(var/atom/movable/I in L)
uplink = I.get_component(/datum/component/uplink)
if(istype(uplink))
return uplink

/datum/mind/proc/take_uplink()
var/obj/item/device/uplink/H = find_syndicate_uplink()
if(H)
qdel(H)

qdel(find_syndicate_uplink())

// check whether this mind's mob has been brigged for the given duration
// have to call this periodically for the duration to work properly
Expand Down
5 changes: 2 additions & 3 deletions code/datums/trading/ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ They sell generic supplies and ask for generic supplies.
/obj/item/device/encryptionkey/syndicate = TRADER_BLACKLIST,
/obj/item/tank/plasma/onetankbomb = TRADER_BLACKLIST,
/obj/item/device/radio = TRADER_BLACKLIST_ALL,
/obj/item/device/pda = TRADER_BLACKLIST_SUB,
/obj/item/device/uplink = TRADER_BLACKLIST
/obj/item/device/pda = TRADER_BLACKLIST_SUB
)

possible_trading_items = list(/obj/item/storage/bag = TRADER_SUBTYPES_ONLY,
Expand Down Expand Up @@ -125,4 +124,4 @@ They sell generic supplies and ask for generic supplies.
// /obj/structure/sign/double = TRADER_BLACKLIST_ALL,
// /obj/structure/sign/goldenplaque = TRADER_BLACKLIST_ALL,
// /obj/structure/sign/poster = TRADER_BLACKLIST
// )
// )
Loading

0 comments on commit 4ce1704

Please sign in to comment.