Skip to content

Commit

Permalink
Merge pull request #18 from kcalbCube/corecode-rewrite
Browse files Browse the repository at this point in the history
Psionics fixes
  • Loading branch information
VoiceInYourHead authored Jun 8, 2024
2 parents 82ceb6e + e2c2c94 commit 7952a8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions code/game/jobs/job/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@

var/list/psi_abilities_by_name = H.client.prefs.psi_abilities

if(!H.client.prefs.psi_threat_level)
return

LAZYINITLIST(psi_faculties)
for(var/faculty_name in psi_abilities_by_name)
var/singleton/psionic_faculty/faculty = SSpsi.faculties_by_name[faculty_name]
Expand Down
1 change: 1 addition & 0 deletions code/modules/client/preference_setup/psionics/01_basic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GLOBAL_LIST_INIT(text2psi_status, list("C" = 1, "B" = 2, "A" = 3, "S" = 4))
if(href_list["select_psi_threat_level"])
pref.psi_threat_level = text2num(input("Select threat level", CHARACTER_PREFERENCE_INPUT_TITLE, pref.psi_threat_level) in list("0", "1", "2", "3", "4"))
pref.psi_threat_level = clamp(pref.psi_threat_level, 0, 4)
pref.sanitize_psi_abilities()
return TOPIC_REFRESH

else if(href_list["select_psi_status"])
Expand Down
40 changes: 28 additions & 12 deletions code/modules/client/preference_setup/psionics/02_abilities.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ GLOBAL_LIST_INIT(psi_threat_level2free_points, list(3, 4, 9, 14))
/datum/preferences
var/list/psi_abilities

/datum/preferences/proc/sanitize_psi_abilities()
if(!psi_threat_level)
return

while(TRUE)
for(var/faculty in psi_abilities)
if(calculate_free_points() >= 0)
return

if(psi_abilities[faculty] > 1)
--psi_abilities[faculty]


/datum/preferences/proc/calculate_free_points()
. = GLOB.psi_threat_level2free_points[psi_threat_level]

for(var/faculty in psi_abilities)
for(var/level in 1 to GLOB.psi_level2cost.len)
var/level_name = GLOB.psi_level2cost[level]
var/level_cost = GLOB.psi_level2cost[level_name]

if(psi_abilities[faculty] == level)
. -= level_cost

/datum/category_item/player_setup_item/psionics/abilities
name = "Abilities"
Expand All @@ -43,19 +66,12 @@ GLOBAL_LIST_INIT(psi_threat_level2free_points, list(3, 4, 9, 14))

return ..()

/datum/category_item/player_setup_item/psionics/abilities/proc/calculate_free_points()
. = GLOB.psi_threat_level2free_points[pref.psi_threat_level]

for(var/faculty in pref.psi_abilities)
for(var/level in 1 to GLOB.psi_level2cost.len)
var/level_name = GLOB.psi_level2cost[level]
var/level_cost = GLOB.psi_level2cost[level_name]

if(pref.psi_abilities[faculty] == level)
. -= level_cost

/datum/category_item/player_setup_item/psionics/abilities/proc/can_select_level(faculty, level)
return (calculate_free_points() + GLOB.psi_level2cost[GLOB.psi_level2cost[pref.psi_abilities[faculty]]]) >= GLOB.psi_level2cost[GLOB.psi_level2cost[level]]
if(level <= 1)
return TRUE // safe measure

return (pref.calculate_free_points() + GLOB.psi_level2cost[GLOB.psi_level2cost[pref.psi_abilities[faculty]]]) >= GLOB.psi_level2cost[GLOB.psi_level2cost[level]]

/datum/category_item/player_setup_item/psionics/abilities/content()
if(!pref.psi_threat_level)
Expand All @@ -75,7 +91,7 @@ GLOBAL_LIST_INIT(psi_threat_level2free_points, list(3, 4, 9, 14))

. += "<tt><center>"

. += FONT_LARGE("<b>Points remaining: [calculate_free_points()]</b>")
. += FONT_LARGE("<b>Points remaining: [pref.calculate_free_points()]</b>")

. += "<table style='width: 100%' style='font-size: 15px; text-align: center' class='table'>"

Expand Down

0 comments on commit 7952a8f

Please sign in to comment.