Ports a psionic system from Bay. (#7717)

* Ports a psionic system from Bay.

* Rip out this shitcode.

* shitcoden't

* fixes

* it should work fully now

* Admin fixes

* Remove todos

* remove todos part 2

* Removes psi-armour. We don't need this for now.

* Skrell are now operants. Tweaks coercion.

* Adds thralls.

* Temp removal of psiarmour. Fixes psigrabs.

* Thrall assay.

* fixes

* More fixes

* unused define cleanup

* Log and powers

* Skrell powers are done.

* Update code/modules/psionics/events/mini_spasm.dm

Co-Authored-By: Geeves <ggrobler447@gmail.com>

* Update code/modules/psionics/events/mini_spasm.dm

Co-Authored-By: Geeves <ggrobler447@gmail.com>

* Update code/modules/psionics/equipment/cerebro_enhancers.dm

* did this work???

* jargon

* arrow's fixes

Co-authored-by: Geeves <ggrobler447@gmail.com>
This commit is contained in:
Matt Atlas
2019-12-24 11:32:05 +01:00
committed by Werner
co-authored by Geeves
parent 6fe1c9c3b4
commit c087a0a0bf
94 changed files with 2284 additions and 413 deletions
@@ -0,0 +1,92 @@
/datum/psi_complexus
var/announced = FALSE // Whether or not we have been announced to our holder yet.
var/suppressed = TRUE // Whether or not we are suppressing our psi powers.
var/use_psi_armour = TRUE // Whether or not we should automatically deflect/block incoming damage.
var/rebuild_power_cache = TRUE // Whether or not we need to rebuild our cache of psi powers.
var/rating = 0 // Overall psi rating.
var/cost_modifier = 1 // Multiplier for power use stamina costs.
var/stun = 0 // Number of process ticks we are stunned for.
var/next_power_use = 0 // world.time minimum before next power use.
var/stamina = 50 // Current psi pool.
var/max_stamina = 50 // Max psi pool.
var/list/latencies // List of all currently latent faculties.
var/list/ranks // Assoc list of psi faculties to current rank.
var/list/base_ranks // Assoc list of psi faculties to base rank, in case reset is needed
var/list/manifested_items // List of atoms manifested/maintained by psychic power.
var/next_latency_trigger = 0 // world.time minimum before a trigger can be attempted again.
var/last_armor_check // world.time of last armour check.
var/last_aura_size
var/last_aura_alpha
var/last_aura_color
var/aura_color = "#ff0022"
// Cached powers.
var/list/melee_powers // Powers used in melee range.
var/list/grab_powers // Powers use by using a grab.
var/list/ranged_powers // Powers used at range.
var/list/manifestation_powers // Powers that create an item.
var/list/powers_by_faculty // All powers within a given faculty.
var/obj/screen/psi/hub/ui // Reference to the master psi UI object.
var/mob/living/owner // Reference to our owner.
var/image/_aura_image // Client image
/datum/psi_complexus/proc/get_aura_image()
if(_aura_image && !istype(_aura_image))
var/atom/A = _aura_image
log_debug("Non-image found in psi complexus: \ref[A] - \the [A] - [istype(A) ? A.type : "non-atom"]")
destroy_aura_image(_aura_image)
_aura_image = null
if(!_aura_image)
_aura_image = create_aura_image(owner)
return _aura_image
/proc/create_aura_image(var/newloc)
var/image/aura_image = image(loc = newloc, icon = 'icons/effects/psi_aura_small.dmi', icon_state = "aura")
aura_image.blend_mode = BLEND_MULTIPLY
aura_image.appearance_flags = NO_CLIENT_COLOR | RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM
aura_image.layer = TURF_LAYER + 0.5
aura_image.alpha = 0
aura_image.pixel_x = -64
aura_image.pixel_y = -64
aura_image.mouse_opacity = 0
aura_image.appearance_flags = 0
for(var/thing in SSpsi.processing)
var/datum/psi_complexus/psychic = thing
if(psychic.owner.client && !psychic.suppressed)
psychic.owner.client.images += aura_image
SSpsi.all_aura_images[aura_image] = TRUE
return aura_image
/proc/destroy_aura_image(var/image/aura_image)
for(var/thing in SSpsi.processing)
var/datum/psi_complexus/psychic = thing
if(psychic.owner.client)
psychic.owner.client.images -= aura_image
SSpsi.all_aura_images -= aura_image
/datum/psi_complexus/New(var/mob/_owner)
owner = _owner
START_PROCESSING(SSpsi, src)
/datum/psi_complexus/Destroy()
destroy_aura_image(_aura_image)
STOP_PROCESSING(SSpsi, src)
if(owner)
cancel()
if(owner.client)
owner.client.screen -= ui
for(var/thing in SSpsi.all_aura_images)
owner.client.images -= thing
QDEL_NULL(ui)
owner.psi = null
owner = null
if(manifested_items)
for(var/thing in manifested_items)
qdel(thing)
manifested_items.Cut()
. = ..()
@@ -0,0 +1,104 @@
/datum/psi_complexus/proc/cancel()
sound_to(owner, sound('sound/effects/psi/power_fail.ogg'))
if(LAZYLEN(manifested_items))
for(var/thing in manifested_items)
owner.drop_from_inventory(thing)
qdel(thing)
manifested_items = null
/datum/psi_complexus/proc/stunned(var/amount)
var/old_stun = stun
stun = max(stun, amount)
if(amount && !old_stun)
to_chat(owner, "<span class='danger'>Your concentration has been shattered! You cannot focus your psi power!</span>")
ui.update_icon()
cancel()
/datum/psi_complexus/proc/get_armour(var/armourtype)
if(can_use_passive())
last_armor_check = world.time
return round(Clamp(Clamp(4 * rating, 0, 20) * get_rank(SSpsi.armour_faculty_by_type[armourtype]), 0, 100) * (stamina/max_stamina))
else
last_armor_check = 0
return 0
/datum/psi_complexus/proc/get_rank(var/faculty)
return LAZYACCESS(ranks, faculty)
/datum/psi_complexus/proc/set_rank(var/faculty, var/rank, var/defer_update, var/temporary)
if(get_rank(faculty) != rank)
LAZYSET(ranks, faculty, rank)
if(!temporary)
LAZYSET(base_ranks, faculty, rank)
if(!defer_update)
update()
/datum/psi_complexus/proc/set_cooldown(var/value)
next_power_use = world.time + value
ui.update_icon()
/datum/psi_complexus/proc/can_use_passive()
return (owner.stat == CONSCIOUS && !suppressed && !stun)
/datum/psi_complexus/proc/can_use(var/incapacitation_flags)
return (owner.stat == CONSCIOUS && (!incapacitation_flags || !owner.incapacitated(incapacitation_flags)) && !suppressed && !stun && world.time >= next_power_use)
/datum/psi_complexus/proc/spend_power(var/value = 0, var/check_incapacitated)
. = FALSE
if(isnull(check_incapacitated))
check_incapacitated = (INCAPACITATION_STUNNED|INCAPACITATION_KNOCKOUT)
if(can_use(check_incapacitated))
value = max(1, Ceiling(value * cost_modifier))
if(value <= stamina)
stamina -= value
ui.update_icon()
. = TRUE
else
backblast(abs(stamina - value))
stamina = 0
. = FALSE
ui.update_icon()
/datum/psi_complexus/proc/hide_auras()
if(owner.client)
for(var/thing in SSpsi.all_aura_images)
owner.client.images -= thing
/datum/psi_complexus/proc/show_auras()
if(owner.client)
for(var/image/I in SSpsi.all_aura_images)
owner.client.images |= I
/datum/psi_complexus/proc/backblast(var/value)
// Can't backblast if you're controlling your power.
if(!owner || suppressed)
return FALSE
sound_to(owner, sound('sound/effects/psi/power_feedback.ogg'))
to_chat(owner, "<span class='danger'><font size=3>Wild energistic feedback blasts across your psyche!</font></span>")
stunned(value * 2)
set_cooldown(value * 100)
if(prob(value*10)) owner.emote("scream")
// Your head asplode.
owner.adjustBrainLoss(value)
owner.adjustHalLoss(value * 25) //Ouch.
if(ishuman(owner))
var/mob/living/carbon/human/pop = owner
if(pop.should_have_organ(BP_BRAIN))
var/obj/item/organ/internal/brain/sponge = pop.internal_organs_by_name[BP_BRAIN]
if(sponge && sponge.damage >= sponge.max_damage)
var/obj/item/organ/external/affecting = pop.get_organ(sponge.parent_organ)
if(affecting && !affecting.is_stump())
affecting.droplimb(0, DROPLIMB_BLUNT)
if(sponge) qdel(sponge)
/datum/psi_complexus/proc/reset()
aura_color = initial(aura_color)
ranks = base_ranks ? base_ranks.Copy() : null
max_stamina = initial(max_stamina)
stamina = min(stamina, max_stamina)
cancel()
update()
@@ -0,0 +1,17 @@
/datum/psi_complexus/proc/check_latency_trigger(var/trigger_strength = 0, var/source, var/redactive = FALSE)
if(!LAZYLEN(latencies) || world.time < next_latency_trigger)
return FALSE
if(!prob(trigger_strength))
next_latency_trigger = world.time + rand(100, 300)
return FALSE
var/faculty = pick(latencies)
var/new_rank = rand(2,5)
owner.set_psi_rank(faculty, new_rank)
var/datum/psionic_faculty/faculty_decl = SSpsi.get_faculty(faculty)
to_chat(owner, span("danger", "You scream internally as your [faculty_decl.name] faculty is forced into operancy by [source]!"))
next_latency_trigger = world.time + rand(600, 1800) * new_rank
if(!redactive) owner.adjustBrainLoss(rand(trigger_strength * 2, trigger_strength * 4))
return TRUE
@@ -0,0 +1,49 @@
/datum/psi_complexus/proc/rebuild_power_cache()
if(rebuild_power_cache)
melee_powers = list()
grab_powers = list()
ranged_powers = list()
manifestation_powers = list()
powers_by_faculty = list()
for(var/faculty in ranks)
var/relevant_rank = get_rank(faculty)
var/datum/psionic_faculty/faculty_decl = SSpsi.get_faculty(faculty)
for(var/thing in faculty_decl.powers)
var/datum/psionic_power/power = thing
if(relevant_rank >= power.min_rank)
if(!powers_by_faculty[power.faculty]) powers_by_faculty[power.faculty] = list()
powers_by_faculty[power.faculty] += power
if(power.use_ranged)
if(!ranged_powers[faculty]) ranged_powers[faculty] = list()
ranged_powers[faculty] += power
if(power.use_melee)
if(!melee_powers[faculty]) melee_powers[faculty] = list()
melee_powers[faculty] += power
if(power.use_manifest)
manifestation_powers += power
if(power.use_grab)
if(!grab_powers[faculty]) grab_powers[faculty] = list()
grab_powers[faculty] += power
rebuild_power_cache = FALSE
/datum/psi_complexus/proc/get_powers_by_faculty(var/faculty)
rebuild_power_cache()
return powers_by_faculty[faculty]
/datum/psi_complexus/proc/get_melee_powers(var/faculty)
rebuild_power_cache()
return melee_powers[faculty]
/datum/psi_complexus/proc/get_ranged_powers(var/faculty)
rebuild_power_cache()
return ranged_powers[faculty]
/datum/psi_complexus/proc/get_grab_powers(var/faculty)
rebuild_power_cache()
return grab_powers[faculty]
/datum/psi_complexus/proc/get_manifestations()
rebuild_power_cache()
return manifestation_powers
@@ -0,0 +1,228 @@
/datum/psi_complexus/proc/update(var/force)
set waitfor = FALSE
var/last_rating = rating
var/highest_faculty
var/highest_rank = 0
var/combined_rank = 0
for(var/faculty in ranks)
var/check_rank = get_rank(faculty)
if(check_rank == 1)
LAZYADD(latencies, faculty)
else
if(check_rank <= 0)
ranks -= faculty
LAZYREMOVE(latencies, faculty)
combined_rank += check_rank
if(!highest_faculty || highest_rank < check_rank)
highest_faculty = faculty
highest_rank = check_rank
UNSETEMPTY(latencies)
var/rank_count = max(1, LAZYLEN(ranks))
if(force || last_rating != Ceiling(combined_rank/rank_count))
if(highest_rank <= 1)
if(highest_rank == 0)
qdel(src)
return
else
rebuild_power_cache = TRUE
sound_to(owner, 'sound/effects/psi/power_unlock.ogg')
rating = Ceiling(combined_rank/rank_count)
cost_modifier = 1
if(rating > 1)
cost_modifier -= min(1, max(0.1, (rating-1) / 10))
if(!ui)
ui = new(owner)
if(owner.client)
owner.client.screen += ui
else
if(owner.client)
owner.client.screen |= ui
if(!suppressed && owner.client)
for(var/thing in SSpsi.all_aura_images)
owner.client.images |= thing
var/image/aura_image = get_aura_image()
if(rating >= PSI_RANK_PARAMOUNT) // spooky boosters
aura_color = "#aaffaa"
aura_image.blend_mode = BLEND_SUBTRACT
else
aura_image.blend_mode = BLEND_ADD
if(highest_faculty == PSI_COERCION)
aura_color = "#cc3333"
else if(highest_faculty == PSI_PSYCHOKINESIS)
aura_color = "#3333cc"
else if(highest_faculty == PSI_REDACTION)
aura_color = "#33cc33"
else if(highest_faculty == PSI_ENERGISTICS)
aura_color = "#cccc33"
if(!announced && owner && owner.client && !QDELETED(src))
announced = TRUE
to_chat(owner, "<hr>")
to_chat(owner, span("notice", "<font size = 3>You are <b>psionic</b>, touched by powers beyond understanding.</font>"))
to_chat(owner, span("notice", "<b>Shift-left-click your Psi icon</b> on the bottom right to <b>view a summary of how to use them</b>, or <b>left click</b> it to <b>suppress or unsuppress</b> your psionics. Beware: overusing your gifts can have <b>deadly consequences</b>."))
to_chat(owner, "<hr>")
/datum/psi_complexus/process()
var/update_hud
if(stun)
stun--
if(stun)
if(!suppressed)
suppressed = TRUE
update_hud = TRUE
else
to_chat(owner, span("notice", "You have recovered your mental composure."))
update_hud = TRUE
return
else if(stamina < max_stamina)
if(owner?.stat == CONSCIOUS)
stamina = min(max_stamina, stamina + rand(1,3))
else if(owner?.stat == UNCONSCIOUS)
stamina = min(max_stamina, stamina + rand(3,5))
if(!owner.nervous_system_failure() && owner.stat == CONSCIOUS && stamina && !suppressed && get_rank(PSI_REDACTION) >= PSI_RANK_OPERANT)
attempt_regeneration()
var/next_aura_size = max(0.1,((stamina/max_stamina)*min(3,rating))/5)
var/next_aura_alpha = round(((suppressed ? max(0,rating - 2) : rating)/5)*255)
if(next_aura_alpha != last_aura_alpha || next_aura_size != last_aura_size || aura_color != last_aura_color)
last_aura_size = next_aura_size
last_aura_alpha = next_aura_alpha
last_aura_color = aura_color
var/matrix/M = matrix()
if(next_aura_size != 1)
M.Scale(next_aura_size)
animate(get_aura_image(), alpha = next_aura_alpha, transform = M, color = aura_color, time = 3)
if(update_hud)
ui.update_icon()
/datum/psi_complexus/proc/attempt_regeneration()
var/heal_general = FALSE
var/heal_poison = FALSE
var/heal_internal = FALSE
var/heal_bleeding = FALSE
var/heal_rate = 0
var/mend_prob = 0
var/use_rank = get_rank(PSI_REDACTION)
if(use_rank >= PSI_RANK_PARAMOUNT)
heal_general = TRUE
heal_poison = TRUE
heal_internal = TRUE
heal_bleeding = TRUE
mend_prob = 50
heal_rate = 7
else if(use_rank == PSI_RANK_GRANDMASTER)
heal_poison = TRUE
heal_internal = TRUE
heal_bleeding = TRUE
mend_prob = 20
heal_rate = 5
else if(use_rank == PSI_RANK_MASTER)
heal_internal = TRUE
heal_bleeding = TRUE
mend_prob = 10
heal_rate = 3
else if(use_rank == PSI_RANK_OPERANT)
heal_bleeding = TRUE
mend_prob = 5
heal_rate = 1
else
return
if(!heal_rate || stamina < heal_rate)
return // Don't backblast from trying to heal ourselves thanks.
if(ishuman(owner))
var/mob/living/carbon/human/H = owner
// Fix some pain.
if(heal_rate > 0)
H.shock_stage = max(0, H.shock_stage - max(1, round(heal_rate/2)))
// Mend internal damage.
if(prob(mend_prob))
// Fix our heart if we're paramount.
if(heal_general && H.is_asystole() && H.should_have_organ(BP_HEART) && spend_power(heal_rate))
H.resuscitate()
// Heal organ damage.
if(heal_internal)
for(var/obj/item/organ/I in H.internal_organs)
if(BP_IS_ROBOTIC(I))
continue
if(I.damage > 0 && spend_power(heal_rate))
I.damage = max(I.damage - heal_rate, 0)
if(prob(25))
to_chat(H, span("notice", "Your innards itch as your autoredactive faculty mends your [I.name]."))
return
// Heal broken bones.
if(H.bad_external_organs.len)
for(var/obj/item/organ/external/E in H.bad_external_organs)
if(BP_IS_ROBOTIC(E))
continue
if(heal_internal && (E.status & ORGAN_BROKEN) && E.damage < (E.min_broken_damage * config.organ_health_multiplier)) // So we don't mend and autobreak.
if(spend_power(heal_rate))
if(E.mend_fracture())
to_chat(H, span("notice", "Your autoredactive faculty coaxes together the shattered bones in your [E.name]."))
return
if(heal_bleeding)
if((E.status & ORGAN_ARTERY_CUT) && spend_power(heal_rate))
to_chat(H, span("notice", "Your autoredactive faculty mends the torn artery in your [E.name], stemming the worst of the bleeding."))
E.status &= ~ORGAN_ARTERY_CUT
return
if(E.status & ORGAN_TENDON_CUT)
to_chat(H, span("notice", "Your autoredactive faculty repairs the severed tendon in your [E.name]."))
E.status &= ~ORGAN_TENDON_CUT
return TRUE
for(var/datum/wound/W in E.wounds)
if(W.bleeding() && spend_power(heal_rate))
to_chat(H, span("notice", "Your autoredactive faculty knits together severed veins, stemming the bleeding from \a [W.desc] on your [E.name]."))
W.bleed_timer = 0
W.clamped = TRUE
E.status &= ~ORGAN_BLEEDING
return
// Heal radiation, cloneloss and poisoning.
if(heal_poison)
if(owner.total_radiation && spend_power(heal_rate))
if(prob(25))
to_chat(owner, span("notice", "Your autoredactive faculty repairs some of the radiation damage to your body."))
owner.total_radiation = max(0, owner.total_radiation - heal_rate)
return
if(owner.getCloneLoss() && spend_power(heal_rate))
if(prob(25))
to_chat(owner, span("notice", "Your autoredactive faculty stitches together some of your mangled DNA."))
owner.adjustCloneLoss(-heal_rate)
return
// Heal everything left.
if(heal_general && prob(mend_prob) && (owner.getBruteLoss() || owner.getFireLoss() || owner.getOxyLoss()) && spend_power(heal_rate))
owner.adjustBruteLoss(-(heal_rate))
owner.adjustFireLoss(-(heal_rate))
owner.adjustOxyLoss(-(heal_rate))
if(prob(25))
to_chat(owner, span("notice", "Your skin crawls as your autoredactive faculty heals your body."))