mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-17 19:14:15 +01:00
Reworks pAIs (#68241)
A pretty heavy refactor for pAIs that just spilled into a rework. Attempts to fully document and organize backend code. Fixes a large number of bugs left untouched for a decade. Breaks down the frontend into subcomponents. Rebalances their software modules. (should) fix pAI faces get removed if you activate them during alert #68242
This commit is contained in:
@@ -1,231 +0,0 @@
|
||||
/obj/item/paicard
|
||||
name = "personal AI device"
|
||||
icon = 'icons/obj/aicards.dmi'
|
||||
icon_state = "pai"
|
||||
inhand_icon_state = "electronic"
|
||||
worn_icon_state = "electronic"
|
||||
lefthand_file = 'icons/mob/inhands/misc/devices_lefthand.dmi'
|
||||
righthand_file = 'icons/mob/inhands/misc/devices_righthand.dmi'
|
||||
w_class = WEIGHT_CLASS_SMALL
|
||||
slot_flags = ITEM_SLOT_BELT
|
||||
custom_premium_price = PAYCHECK_COMMAND * 1.25
|
||||
resistance_flags = FIRE_PROOF | ACID_PROOF | INDESTRUCTIBLE
|
||||
|
||||
/// Spam alert prevention
|
||||
var/alert_cooldown
|
||||
/// If the pAIcard is slotted in a PDA
|
||||
var/slotted = FALSE
|
||||
/// Any pAI personalities inserted
|
||||
var/mob/living/silicon/pai/pai
|
||||
///what emotion icon we have. handled in /mob/living/silicon/pai/Topic()
|
||||
var/emotion_icon = "off"
|
||||
|
||||
/obj/item/paicard/suicide_act(mob/living/user)
|
||||
user.visible_message(span_suicide("[user] is staring sadly at [src]! [user.p_they()] can't keep living without real human intimacy!"))
|
||||
return OXYLOSS
|
||||
|
||||
/obj/item/paicard/Initialize(mapload)
|
||||
SSpai.pai_card_list += src
|
||||
. = ..()
|
||||
update_appearance()
|
||||
|
||||
/obj/item/paicard/vv_edit_var(vname, vval)
|
||||
. = ..()
|
||||
if(vname == NAMEOF(src, emotion_icon))
|
||||
update_appearance()
|
||||
|
||||
/obj/item/paicard/handle_atom_del(atom/A)
|
||||
if(A == pai) //double check /mob/living/silicon/pai/Destroy() if you change these.
|
||||
pai = null
|
||||
emotion_icon = initial(emotion_icon)
|
||||
update_appearance()
|
||||
return ..()
|
||||
|
||||
/obj/item/paicard/update_overlays()
|
||||
. = ..()
|
||||
. += "pai-[emotion_icon]"
|
||||
if(pai?.hacking_cable)
|
||||
. += "[initial(icon_state)]-connector"
|
||||
|
||||
/obj/item/paicard/Destroy()
|
||||
//Will stop people throwing friend pAIs into the singularity so they can respawn
|
||||
SSpai.pai_card_list -= src
|
||||
if(!QDELETED(pai))
|
||||
QDEL_NULL(pai)
|
||||
return ..()
|
||||
|
||||
/obj/item/paicard/attack_self(mob/user)
|
||||
if (!in_range(src, user))
|
||||
return
|
||||
user.set_machine(src)
|
||||
ui_interact(user)
|
||||
|
||||
/obj/item/paicard/ui_interact(mob/user, datum/tgui/ui)
|
||||
. = ..()
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
if(!ui)
|
||||
ui = new(user, src, "PaiCard")
|
||||
ui.open()
|
||||
|
||||
/obj/item/paicard/ui_state(mob/user)
|
||||
return GLOB.paicard_state
|
||||
|
||||
/obj/item/paicard/ui_data(mob/user)
|
||||
. = ..()
|
||||
var/list/data = list()
|
||||
data["candidates"] = list()
|
||||
if(!pai)
|
||||
data["candidates"] = pool_candidates()
|
||||
data["pai"] = null
|
||||
return data
|
||||
data["pai"] = list()
|
||||
data["pai"]["can_holo"] = pai.canholo
|
||||
data["pai"]["dna"] = pai.master_dna
|
||||
data["pai"]["emagged"] = pai.emagged
|
||||
data["pai"]["laws"] = pai.laws.supplied
|
||||
data["pai"]["master"] = pai.master
|
||||
data["pai"]["name"] = pai.name
|
||||
data["pai"]["transmit"] = pai.can_transmit
|
||||
data["pai"]["receive"] = pai.can_receive
|
||||
return data
|
||||
|
||||
/obj/item/paicard/ui_act(action, list/params)
|
||||
. = ..()
|
||||
if(.)
|
||||
return FALSE
|
||||
switch(action)
|
||||
if("download")
|
||||
/// The individual candidate to download
|
||||
var/datum/pai_candidate/candidate
|
||||
for(var/datum/pai_candidate/checked_candidate as anything in SSpai.candidates)
|
||||
if(params["key"] == checked_candidate.key)
|
||||
candidate = checked_candidate
|
||||
break
|
||||
if(isnull(candidate))
|
||||
return FALSE
|
||||
if(pai)
|
||||
return FALSE
|
||||
if(SSpai.check_ready(candidate) != candidate)
|
||||
return FALSE
|
||||
/// The newly downloaded pAI personality
|
||||
var/mob/living/silicon/pai/new_pai = new(src)
|
||||
new_pai.name = candidate.name || pick(GLOB.ninja_names)
|
||||
new_pai.real_name = new_pai.name
|
||||
new_pai.key = candidate.key
|
||||
setPersonality(new_pai)
|
||||
SSpai.candidates -= candidate
|
||||
if("fix_speech")
|
||||
to_chat(pai, span_notice("Your owner has corrected your speech modulation!"))
|
||||
to_chat(usr, span_notice("You fix the pAI's speech modulator."))
|
||||
for(var/effect in typesof(/datum/status_effect/speech))
|
||||
pai.remove_status_effect(effect)
|
||||
|
||||
if("request")
|
||||
if(!pai)
|
||||
SSpai.findPAI(src, usr)
|
||||
if("set_dna")
|
||||
if(pai.master_dna)
|
||||
return
|
||||
if(!iscarbon(usr))
|
||||
to_chat(usr, span_warning("You don't have any DNA, or your DNA is incompatible with this device!"))
|
||||
else
|
||||
var/mob/living/carbon/master = usr
|
||||
pai.master = master.real_name
|
||||
pai.master_dna = master.dna.unique_enzymes
|
||||
to_chat(pai, span_notice("You have been bound to a new master."))
|
||||
pai.emittersemicd = FALSE
|
||||
if("set_laws")
|
||||
var/newlaws = tgui_input_text(usr, "Enter any additional directives you would like your pAI personality to follow. Note that these directives will not override the personality's allegiance to its imprinted master. Conflicting directives will be ignored.", "pAI Directive Configuration", pai.laws.supplied[1], MAX_MESSAGE_LEN, TRUE)
|
||||
if(newlaws && pai)
|
||||
pai.add_supplied_law(0,newlaws)
|
||||
if("toggle_holo")
|
||||
if(pai.canholo)
|
||||
to_chat(pai, span_warning("Your owner has disabled your holomatrix projectors!"))
|
||||
pai.canholo = FALSE
|
||||
to_chat(usr, span_notice("You disable your pAI's holomatrix!"))
|
||||
else
|
||||
to_chat(pai, span_notice("Your owner has enabled your holomatrix projectors!"))
|
||||
pai.canholo = TRUE
|
||||
to_chat(usr, span_notice("You enable your pAI's holomatrix!"))
|
||||
if("toggle_radio")
|
||||
var/transmitting = params["option"] == "transmit" //it can't be both so if we know it's not transmitting it must be receiving.
|
||||
var/transmit_holder = (transmitting ? WIRE_TX : WIRE_RX)
|
||||
if(transmitting)
|
||||
pai.can_transmit = !pai.can_transmit
|
||||
else //receiving
|
||||
pai.can_receive = !pai.can_receive
|
||||
pai.radio.wires.cut(transmit_holder)//wires.cut toggles cut and uncut states
|
||||
transmit_holder = (transmitting ? pai.can_transmit : pai.can_receive) //recycling can be fun!
|
||||
to_chat(usr, span_notice("You [transmit_holder ? "enable" : "disable"] your pAI's [transmitting ? "outgoing" : "incoming"] radio transmissions!"))
|
||||
to_chat(pai, span_notice("Your owner has [transmit_holder ? "enabled" : "disabled"] your [transmitting ? "outgoing" : "incoming"] radio transmissions!"))
|
||||
if("wipe_pai")
|
||||
var/confirm = tgui_alert(usr, "Are you certain you wish to delete the current personality? This action cannot be undone.", "Personality Wipe", list("Yes", "No"))
|
||||
if(confirm != "Yes")
|
||||
return
|
||||
if(!pai)
|
||||
return
|
||||
to_chat(pai, span_warning("You feel yourself slipping away from reality."))
|
||||
to_chat(pai, span_danger("Byte by byte you lose your sense of self."))
|
||||
to_chat(pai, span_userdanger("Your mental faculties leave you."))
|
||||
to_chat(pai, span_rose("oblivion... "))
|
||||
qdel(pai)
|
||||
return
|
||||
|
||||
// WIRE_SIGNAL = 1
|
||||
// WIRE_RECEIVE = 2
|
||||
// WIRE_TRANSMIT = 4
|
||||
|
||||
/obj/item/paicard/proc/setPersonality(mob/living/silicon/pai/personality)
|
||||
pai = personality
|
||||
emotion_icon = "null"
|
||||
update_appearance()
|
||||
|
||||
playsound(loc, 'sound/effects/pai_boot.ogg', 50, TRUE, -1)
|
||||
audible_message("\The [src] plays a cheerful startup noise!")
|
||||
|
||||
/obj/item/paicard/proc/alertUpdate()
|
||||
if(!COOLDOWN_FINISHED(src, alert_cooldown))
|
||||
return
|
||||
COOLDOWN_START(src, alert_cooldown, 5 SECONDS)
|
||||
add_alert()
|
||||
addtimer(CALLBACK(src, .proc/remove_alert), 5 SECONDS)
|
||||
playsound(src, 'sound/machines/ping.ogg', 30, TRUE)
|
||||
loc.visible_message(span_info("[src] flashes a message across its screen, \"Additional personalities available for download.\""), blind_message = span_notice("[src] vibrates with an alert."))
|
||||
|
||||
/obj/item/paicard/proc/add_alert()
|
||||
add_overlay(
|
||||
list(mutable_appearance(icon, "[initial(icon_state)]-alert"),
|
||||
emissive_appearance(icon, "[initial(icon_state)]-alert", alpha = src.alpha)))
|
||||
|
||||
/obj/item/paicard/proc/remove_alert()
|
||||
cut_overlays()
|
||||
|
||||
/obj/item/paicard/emp_act(severity)
|
||||
. = ..()
|
||||
if (. & EMP_PROTECT_SELF)
|
||||
return
|
||||
if(pai && !pai.holoform)
|
||||
pai.emp_act(severity)
|
||||
|
||||
/**
|
||||
* Gathers a list of candidates to display in the download candidate
|
||||
* window. If the candidate isn't marked ready, ie they have not
|
||||
* pressed submit, they will be skipped over.
|
||||
*
|
||||
* @return - An array of candidate objects.
|
||||
*/
|
||||
/obj/item/paicard/proc/pool_candidates()
|
||||
/// Array of pAI candidates
|
||||
var/list/candidates = list()
|
||||
if(length(SSpai.candidates))
|
||||
for(var/datum/pai_candidate/checked_candidate as anything in SSpai.candidates)
|
||||
if(!checked_candidate.ready)
|
||||
continue
|
||||
/// The object containing the candidate data.
|
||||
var/list/candidate = list()
|
||||
candidate["comments"] = checked_candidate.comments
|
||||
candidate["description"] = checked_candidate.description
|
||||
candidate["key"] = checked_candidate.key
|
||||
candidate["name"] = checked_candidate.name
|
||||
candidates += list(candidate)
|
||||
return candidates
|
||||
@@ -77,7 +77,7 @@ GLOBAL_LIST_EMPTY(possible_gifts)
|
||||
/obj/item/banhammer,
|
||||
/obj/item/food/grown/ambrosia/deus,
|
||||
/obj/item/food/grown/ambrosia/vulgaris,
|
||||
/obj/item/paicard,
|
||||
/obj/item/pai_card,
|
||||
/obj/item/instrument/violin,
|
||||
/obj/item/instrument/guitar,
|
||||
/obj/item/storage/belt/utility/full,
|
||||
|
||||
Reference in New Issue
Block a user