Skip to content

Commit

Permalink
Log all player antag tokens to a tokens.json log at roundend (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy authored May 20, 2024
1 parent 463a40f commit 112b71a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions code/__HELPERS/roundend.dm
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ GLOBAL_LIST_INIT(round_end_images, world.file2list("data/image_urls.txt")) // MO
//stop collecting feedback during grifftime
SSblackbox.Seal()
var/hour = round((world.time - SSticker.round_start_time) / 36000)

// monkestation start: token backups, monkecoin rewards, challenges, and roundend webhook
rustg_file_write(json_encode(GLOB.saved_token_values), "[GLOB.log_directory]/tokens.json")
var/minute = round(((world.time - SSticker.round_start_time) - (hour * 36000)) / 600)
var/added_xp = round(25 + (minute**0.85))
for(var/client/C in GLOB.clients)
Expand All @@ -305,6 +308,7 @@ GLOBAL_LIST_INIT(round_end_images, world.file2list("data/image_urls.txt")) // MO
ready_for_reboot = TRUE
var/datum/discord_embed/embed = format_roundend_embed("<@&999008528595419278>")
send2roundend_webhook(embed)
// monkestation end
standard_reboot()

/datum/controller/subsystem/ticker/proc/format_roundend_embed(message)
Expand Down
14 changes: 13 additions & 1 deletion monkestation/code/datums/meta_tokens.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
GLOBAL_LIST_INIT(used_monthly_token, list())
GLOBAL_LIST_EMPTY(used_monthly_token)

/// Token for each player in the round, used to backup tokens to logs at roundend.
GLOBAL_LIST_EMPTY(saved_token_values)

///assoc list of how many event tokens each role gets each month
GLOBAL_LIST_INIT(patreon_etoken_values, list(
Expand Down Expand Up @@ -49,6 +52,7 @@ GLOBAL_LIST_INIT(patreon_etoken_values, list(
owner = creator

var/datum/preferences/owners_prefs = creator.prefs
backup_tokens()
convert_list_to_tokens(owners_prefs.saved_tokens)
donator_token = check_for_donator_token()

Expand All @@ -63,6 +67,13 @@ GLOBAL_LIST_INIT(patreon_etoken_values, list(

total_antag_tokens = total_low_threat_tokens + total_medium_threat_tokens + total_high_threat_tokens

/// Backs up the owner's tokens to [GLOB.saved_token_values],
/// with sanity checks to make damn sure we don't write invalid data.
/datum/meta_token_holder/proc/backup_tokens()
if(QDELETED(src) || QDELETED(owner) || !owner.ckey || QDELETED(owner.prefs) || !owner.prefs.saved_tokens)
return
GLOB.saved_token_values[owner.ckey] = owner.prefs.saved_tokens.Copy()

/datum/meta_token_holder/proc/convert_tokens_to_list()
owner.prefs.saved_tokens = list(
"low_threat" = total_low_threat_tokens,
Expand All @@ -71,6 +82,7 @@ GLOBAL_LIST_INIT(patreon_etoken_values, list(
"event_tokens" = event_tokens,
"event_token_month" = event_token_month,
)
backup_tokens()
owner.prefs.save_preferences()

/datum/meta_token_holder/proc/check_for_donator_token()
Expand Down

0 comments on commit 112b71a

Please sign in to comment.