diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm
index 838670221ad..99f7fa69746 100644
--- a/code/modules/client/client procs.dm
+++ b/code/modules/client/client procs.dm
@@ -109,136 +109,42 @@
if("shop")
if(href_list["KarmaBuy"])
var/karma=verify_karma()
+ if(isnull(karma)) //Doesn't display anything if karma database is down.
+ return
switch(href_list["KarmaBuy"])
if("1")
- if(karma <5)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Barber?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Barber",5)
- return
+ karma_purchase(karma,5,"job","Barber")
if("2")
- if(karma <5)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Brig Physician?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Brig Physician",5)
- return
+ karma_purchase(karma,5,"job","Brig Physician")
if("3")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Nanotrasen Representative?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Nanotrasen Representative",30)
- return
+ karma_purchase(karma,30,"job","Nanotrasen Representative")
if("5")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Blueshield?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Blueshield",30)
- return
+ karma_purchase(karma,30,"job","Blueshield")
if("6")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Mechanic?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Mechanic",30)
- return
+ karma_purchase(karma,30,"job","Mechanic")
if("7")
- if(karma <45)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Magistrate?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Magistrate",45)
- return
+ karma_purchase(karma,45,"job","Magistrate")
if("9")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Security Pod Pilot?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_job_unlock("Security Pod Pilot",30)
- return
+ karma_purchase(karma,30,"job","Security Pod Pilot")
if(href_list["KarmaBuy2"])
var/karma=verify_karma()
+ if(isnull(karma)) //Doesn't display anything if karma database is down.
+ return
switch(href_list["KarmaBuy2"])
if("1")
- if(karma <15)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Machine People?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Machine",15)
- return
+ karma_purchase(karma,15,"species","Machine People","Machine")
if("2")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Kidan?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Kidan",30)
- return
+ karma_purchase(karma,30,"species","Kidan")
if("3")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Grey?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Grey",30)
- return
+ karma_purchase(karma,30,"species","Grey")
if("4")
- if(karma <45)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Vox?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Vox",45)
- return
+ karma_purchase(karma,45,"species","Vox")
if("5")
- if(karma <45)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Slime People?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Slime People",45)
- return
+ karma_purchase(karma,45,"species","Slime People")
if("6")
- if(karma <100)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Plasmaman?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Plasmaman",100)
- return
+ karma_purchase(karma,100,"species","Plasmaman")
if("7")
- if(karma <30)
- to_chat(usr, "You do not have enough karma!")
- return
- else
- if(alert("Are you sure you want to unlock Drask?", "Confirmation", "No", "Yes") != "Yes")
- return
- DB_species_unlock("Drask",30)
- return
+ karma_purchase(karma,30,"species","Drask")
if(href_list["KarmaRefund"])
var/type = href_list["KarmaRefundType"]
var/job = href_list["KarmaRefund"]
diff --git a/code/modules/karma/karma.dm b/code/modules/karma/karma.dm
index 1f18edfae22..cfc44382d64 100644
--- a/code/modules/karma/karma.dm
+++ b/code/modules/karma/karma.dm
@@ -1,3 +1,7 @@
+/* KARMA
+ Everything karma related is here.
+ Part of karma purchase is handled in client_procs.dm */
+
proc/sql_report_karma(var/mob/spender, var/mob/receiver)
var/sqlspendername = sanitizeSQL(spender.name)
var/sqlspenderkey = spender.ckey
@@ -39,49 +43,49 @@ proc/sql_report_karma(var/mob/spender, var/mob/receiver)
var/err = query.ErrorMsg()
log_game("SQL ERROR during karmatotal logging (adding new key). Error : \[[err]\]\n")
else
- karma += 1
+ karma++
query = dbcon.NewQuery("UPDATE [format_table_name("karmatotals")] SET karma=[karma] WHERE id=[id]")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during karmatotal logging (updating existing entry). Error : \[[err]\]\n")
-
var/list/karma_spenders = list()
-// Returns 1 if mob can give karma at all; if not, tells them why
+// Returns TRUE if mob can give karma at all; if not, tells them why
/mob/proc/can_give_karma()
if(!client)
- return 0
+ to_chat(src, "You can't award karma without being connected.")
+ return FALSE
if(config.disable_karma)
to_chat(src, "Karma is disabled.")
- return 0
+ return FALSE
if(!ticker || !player_list.len || (ticker.current_state == GAME_STATE_PREGAME))
to_chat(src, "You can't award karma until the game has started.")
- return 0
+ return FALSE
if(client.karma_spent || (ckey in karma_spenders))
to_chat(src, "You've already spent your karma for the round.")
- return 0
- return 1
+ return FALSE
+ return TRUE
-// Returns 1 if mob can give karma to M; if not, tells them why
+// Returns TRUE if mob can give karma to M; if not, tells them why
/mob/proc/can_give_karma_to_mob(mob/M)
if(!can_give_karma())
- return 0
+ return FALSE
if(!istype(M))
to_chat(src, "That's not a mob.")
- return 0
+ return FALSE
if(!M.client)
to_chat(src, "That mob has no client connected at the moment.")
- return 0
- if(ckey == M.ckey)
+ return FALSE
+ if(M.ckey == ckey)
to_chat(src, "You can't spend karma on yourself!")
- return 0
+ return FALSE
if(client.address == M.client.address)
message_admins("Illegal karma spending attempt detected from [key] to [M.key]. Using the same IP!")
log_game("Illegal karma spending attempt detected from [key] to [M.key]. Using the same IP!")
to_chat(src, "You can't spend karma on someone connected from the same IP.")
- return 0
- return 1
+ return FALSE
+ return TRUE
/mob/verb/spend_karma_list()
@@ -129,9 +133,9 @@ var/list/karma_spenders = list()
if(!can_give_karma_to_mob(M))
return // Check again, just in case things changed while the alert box was up
- M.client.karma += 1
+ M.client.karma++
to_chat(usr, "Good karma spent on [M.name].")
- client.karma_spent = 1
+ client.karma_spent = TRUE
karma_spenders += ckey
var/special_role = "None"
@@ -153,14 +157,14 @@ var/list/karma_spenders = list()
if(config.disable_karma)
to_chat(src, "Karma is disabled.")
- return 0
+ return
- var/currentkarma=verify_karma()
- to_chat(usr, {"
You have [currentkarma] available."})
- return
+ var/currentkarma = verify_karma()
+ if(!isnull(currentkarma))
+ to_chat(usr, {"
You have [currentkarma] available."})
/client/proc/verify_karma()
- var/currentkarma=0
+ var/currentkarma = 0
if(!dbcon.IsConnected())
to_chat(usr, "Unable to connect to karma database. Please try again later.
")
return
@@ -174,24 +178,18 @@ var/list/karma_spenders = list()
totalkarma = query.item[1]
karmaspent = query.item[2]
currentkarma = (text2num(totalkarma) - text2num(karmaspent))
-/* if(totalkarma)
- to_chat(usr, {"
You have [currentkarma] available.
)
-You've gained [totalkarma] total karma in your time here.
"}
- else
- to_chat(usr, "Your total karma is: 0
")*/
+
return currentkarma
/client/verb/karmashop()
set name = "karmashop"
set desc = "Spend your hard-earned karma here"
- set hidden = 1
+ set hidden = TRUE
if(config.disable_karma)
to_chat(src, "Karma is disabled.")
- return 0
-
+ return
karmashopmenu()
- return
/client/proc/karmashopmenu()
var/dat = "