Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/__HELPERS/roundend.dm
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
parts += "<span class='greentext'>You managed to survive the events on [station_name()] as [M.real_name].</span>"
if(M.mind.assigned_role in GLOB.engineering_positions) // We don't actually need to even really do a check to see if assigned_role is set to anything.
SSachievements.unlock_achievement(/datum/achievement/engineering, C)
else if(M.mind.assigned_role in GLOB.supply_positions) // We don't actually need to even really do a check to see if assigned_role is set to anything.
SSachievements.unlock_achievement(/datum/achievement/cargo, C)


else
parts += "<div class='panel redborder'>"
Expand Down
26 changes: 14 additions & 12 deletions code/controllers/subsystem/achievements.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ SUBSYSTEM_DEF(achievements)
var/datum/achievement/A = new i
achievements[A] = A.id

var/datum/DBQuery/medalQuery = SSdbcore.NewQuery("SELECT name, descr FROM [format_table_name("achievements")] WHERE id = '[sanitizeSQL(A.id)]'")
var/datum/DBQuery/medalQuery = SSdbcore.NewQuery("SELECT name, descr FROM [format_table_name("achievements")] WHERE id = '[A.id]'") // No sanitation of A is needed for these calls because we instantiated A right here in this proc.
medalQuery.Execute()
if(!medalQuery.NextRow())
var/datum/DBQuery/medalQuery2 = SSdbcore.NewQuery("INSERT INTO [format_table_name("achievements")] (name, id, descr) VALUES ('[sanitizeSQL(A.name)]', '[sanitizeSQL(A.id)]', '[sanitizeSQL(A.desc)]')")
var/datum/DBQuery/medalQuery2 = SSdbcore.NewQuery("INSERT INTO [format_table_name("achievements")] (name, id, descr) VALUES ('[A.name]', '[A.id]', '[A.desc]')")
medalQuery2.Execute()
qdel(medalQuery2)
else if(medalQuery.item[1] != A.name || medalQuery.item[2] != A.desc)
var/datum/DBQuery/medalQuery2 = SSdbcore.NewQuery("UPDATE [format_table_name("achievements")] SET name = '[sanitizeSQL(A.name)]', descr = '[sanitizeSQL(A.desc)]' WHERE id = '[sanitizeSQL(A.id)]'")
var/datum/DBQuery/medalQuery2 = SSdbcore.NewQuery("UPDATE [format_table_name("achievements")] SET name = '[A.name]', descr = '[A.desc]' WHERE id = '[A.id]'")
medalQuery2.Execute()
qdel(medalQuery2)

Expand All @@ -29,18 +29,18 @@ SUBSYSTEM_DEF(achievements)
var/datum/DBQuery/ridOldChieves = SSdbcore.NewQuery("SELECT id FROM [format_table_name("achievements")]")
ridOldChieves.Execute()
while(ridOldChieves.NextRow())
var/id = text2num(ridOldChieves.item[1])
var/id = text2num(ridOldChieves.item[1]) // This id var also doesn't need to be sanitized because it's from the actual database
var/found_achievement = FALSE
for(var/I in achievements)
var/datum/achievement/A = I
if(A.id != id)
continue
found_achievement = TRUE
if(A.id == id)
found_achievement = TRUE
break
if(!found_achievement)
log_sql("Old achievement [id] found in database, removing")
var/datum/DBQuery/getRidOfOldStuff = SSdbcore.NewQuery("DELETE FROM [format_table_name("achievements")] WHERE id = '[sanitizeSQL(id)]'")
var/datum/DBQuery/getRidOfOldStuff = SSdbcore.NewQuery("DELETE FROM [format_table_name("achievements")] WHERE id = '[id]'")
getRidOfOldStuff.Execute()
var/datum/DBQuery/ridTheOtherTableAsWell = SSdbcore.NewQuery("DELETE FROM [format_table_name("earned_achievements")] WHERE id = '[sanitizeSQL(id)]'")
var/datum/DBQuery/ridTheOtherTableAsWell = SSdbcore.NewQuery("DELETE FROM [format_table_name("earned_achievements")] WHERE id = '[id]'")
ridTheOtherTableAsWell.Execute()
qdel(ridTheOtherTableAsWell)
qdel(getRidOfOldStuff)
Expand All @@ -66,14 +66,16 @@ SUBSYSTEM_DEF(achievements)

//Ad-hoc procs
/datum/controller/subsystem/achievements/proc/unlock_achievement(achievementPath, client/C)
if(!C)
return FALSE
var/datum/achievement/achievement = get_achievement(achievementPath)
if(!achievement)
log_sql("Achievement [achievementPath] not found in list of achievements when trying to unlock for [C.ckey]")
log_sql("Achievement [achievementPath] not found in list of achievements when trying to unlock for [ckey(C.ckey)]")
return FALSE
if(istype(achievement,/datum/achievement/greentext) && achievementPath != /datum/achievement/greentext)
unlock_achievement(/datum/achievement/greentext,C) // Oooh, a little bit recursive!
if(!has_achievement(achievementPath, C))
var/datum/DBQuery/medalQuery = SSdbcore.NewQuery("INSERT INTO [format_table_name("earned_achievements")] (ckey, id) VALUES ('[sanitizeSQL(C.ckey)]', '[sanitizeSQL(achievement.id)]')")
var/datum/DBQuery/medalQuery = SSdbcore.NewQuery("INSERT INTO [format_table_name("earned_achievements")] (ckey, id) VALUES ('[ckey(C.ckey)]', '[initial(achievement.id)]')")
medalQuery.Execute()
qdel(medalQuery)
cached_achievements[C.ckey] += achievement
Expand All @@ -94,7 +96,7 @@ SUBSYSTEM_DEF(achievements)
return (achievement in cached_achievements[C.ckey])

/datum/controller/subsystem/achievements/proc/cache_achievements(client/C)
var/datum/DBQuery/cacheQuery = SSdbcore.NewQuery("SELECT id FROM [format_table_name("earned_achievements")] WHERE ckey = '[sanitizeSQL(C.ckey)]'")
var/datum/DBQuery/cacheQuery = SSdbcore.NewQuery("SELECT id FROM [format_table_name("earned_achievements")] WHERE ckey = '[ckey(C.ckey)]'")
cacheQuery.Execute()
cached_achievements[C.ckey] = list()
while(cacheQuery.NextRow())
Expand Down
22 changes: 22 additions & 0 deletions code/datums/achievements/achievements.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define GREENTEXT 256 // An offset for new greentext-related achievements, to keep the incremental pattern.
#define REDTEXT 512 // Offset for redtexts.
#define ENGIEDEPT 768 // Offset for engineering-related achievements.
#define CARGODEPT 1028 // Offset for Cargo-related achievements

/datum/achievement
var/name = "achievement"
Expand Down Expand Up @@ -271,6 +272,27 @@
id = ENGIEDEPT + 4
//end-engineering

//start-cargo
/datum/achievement/cargo
name = "Glory to Cargonia"
desc = "Survive a full round as part of the Supply department."
id = CARGODEPT + 1
/datum/achievement/cargo/bourgeois
name = "Top 1%"
desc = "Have one million credits on your ID."
id = CARGODEPT + 2
/datum/achievement/cargo/bounties
name = "Five Year Plan"
desc = "As a member of the Supply department, complete ten bounties."
id = CARGODEPT + 3
/datum/achievement/cargo/bsa
name = "\"Glass them.\""
desc = "Fire the Bluespace artillery."
id = CARGODEPT + 4

//end-cargo

#undef GREENTEXT
#undef REDTEXT
#undef ENGIEDEPT
#undef CARGODEPT
5 changes: 4 additions & 1 deletion code/modules/cargo/bounty.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ GLOBAL_LIST_EMPTY(bounties_list)
return !claimed

// Called when the claim button is clicked. Override to provide fancy rewards.
/datum/bounty/proc/claim()
/datum/bounty/proc/claim(mob/user)
if(can_claim())
var/datum/bank_account/D = SSeconomy.get_dep_account(ACCOUNT_CAR)
if(D)
D.adjust_money(reward)
D.bounties_claimed += 1
if(D.bounties_claimed == 10)
SSachievements.unlock_achievement(/datum/achievement/cargo/bounties, user.client)
claimed = TRUE

// If an item sent in the cargo shuttle can satisfy the bounty.
Expand Down
2 changes: 1 addition & 1 deletion code/modules/cargo/bounty_console.dm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
if("Claim")
var/datum/bounty/B = locate(href_list["d_rec"]) in GLOB.bounties_list
if(B)
B.claim()
B.claim(usr)

if(href_list["refresh"])
playsound(src, "terminal_type", 25, 0)
Expand Down
10 changes: 10 additions & 0 deletions code/modules/economy/account.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
var/account_id
var/being_dumped = FALSE //pink levels are rising
var/withdrawDelay = 0
var/is_bourgeois = FALSE // Marks whether we've tried giving them the achievement already, this round.
var/bounties_claimed = 0 // Marks how many bounties this person has successfully claimed

/datum/bank_account/New(newname, job)
if(add_to_accounts)
Expand All @@ -30,6 +32,14 @@
account_balance += amt
if(account_balance < 0)
account_balance = 0
else if(account_balance > 1000000 && !is_bourgeois) // if we are now a millionaire, give the achievement
//So we currently only know what is *supposed* to be the real_name of the client's mob. If we can find them, we can get them this achievement.
for(var/x in GLOB.player_list)
var/mob/M = x
if(M.real_name == account_holder)
SSachievements.unlock_achievement(/datum/achievement/cargo/bourgeois, M.client)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a check within the unlock_achievement proc to check if the client exists, its too easy to forget a if(whatever.client)

is_bourgeois = TRUE
//break would result in the possibility of this being given to changeling who has duplicated the millionaire, and not to the actual millionaire.

/datum/bank_account/proc/has_money(amt)
return account_balance >= amt
Expand Down
3 changes: 2 additions & 1 deletion code/modules/station_goals/bsa.dm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
T.ex_act(EXPLODE_DEVASTATE)
point.Beam(get_target_turf(),icon_state="bsa_beam",time=50,maxdistance = world.maxx) //ZZZAP
new /obj/effect/temp_visual/bsa_splash(point, dir)

if(user.client)
SSachievements.unlock_achievement(/datum/achievement/cargo/bsa, user.client)
message_admins("[ADMIN_LOOKUPFLW(user)] has launched an artillery strike.")
explosion(bullseye,ex_power,ex_power*2,ex_power*4)

Expand Down