From 749cf40f209422c66aef6fa2ac3877a6313f6a2f Mon Sep 17 00:00:00 2001 From: FernandoJ8 Date: Mon, 22 Jan 2024 20:36:37 +0100 Subject: [PATCH 1/4] Various type mismatch fixes --- .../code/modules/job_xp/milestones/_milestones.dm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/monkestation/code/modules/job_xp/milestones/_milestones.dm b/monkestation/code/modules/job_xp/milestones/_milestones.dm index af22742064ee..403f836e6433 100644 --- a/monkestation/code/modules/job_xp/milestones/_milestones.dm +++ b/monkestation/code/modules/job_xp/milestones/_milestones.dm @@ -11,16 +11,17 @@ return if(milestones[num2text(level)]) - var/datum/milestone_type = milestones[level] + var/datum/milestone_type = milestones[num2text(level)] //handles adding loadout items - if(istype(milestone_type, /datum/loadout_item)) + if(ispath(milestone_type, /datum/loadout_item)) var/datum/loadout_item/listed_loadout = milestone_type for(var/path in user.prefs.job_rewards_claimed[key_id]) if(path == initial(milestone_type)) return - - user.prefs.job_rewards_claimed[key_id] |= initial(milestone_type) + if(!user.prefs.job_rewards_claimed[key_id]) + user.prefs.job_rewards_claimed[key_id] = list() + user.prefs.job_rewards_claimed[key_id] |= milestone_type if(!user.prefs.inventory[initial(listed_loadout.item_path)]) user.prefs.inventory += initial(listed_loadout.item_path) var/datum/db_query/query_add_gear_purchase = SSdbcore.NewQuery({" @@ -48,7 +49,7 @@ var/obj/item/milestone_item = new temp if(!islist(user.prefs.job_rewards_per_round[key_id])) user.prefs.job_rewards_per_round[key_id] = list() - user.prefs.job_rewards_per_round[key_id] += milestone_item.type + user.prefs.job_rewards_per_round[key_id] += "[milestone_item.type]" //Path2String user.prefs.save_preferences() qdel(milestone_item) From c63cbcd522d4dccbf16867a7137ca7013b28ab84 Mon Sep 17 00:00:00 2001 From: FernandoJ8 Date: Mon, 22 Jan 2024 22:39:20 +0100 Subject: [PATCH 2/4] Additional touches. --- .../modules/job_xp/milestones/_milestones.dm | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/monkestation/code/modules/job_xp/milestones/_milestones.dm b/monkestation/code/modules/job_xp/milestones/_milestones.dm index 403f836e6433..558e420128dd 100644 --- a/monkestation/code/modules/job_xp/milestones/_milestones.dm +++ b/monkestation/code/modules/job_xp/milestones/_milestones.dm @@ -4,7 +4,7 @@ var/list/in_round_milestones -/datum/job_milestone/proc/check_milestones(level, client/user) +/datum/job_milestone/proc/check_milestones(level, client/user, force) if(!length(milestones) && !length(in_round_milestones)) return if(!milestones[num2text(level)] && !in_round_milestones[num2text(level)]) @@ -16,19 +16,17 @@ //handles adding loadout items if(ispath(milestone_type, /datum/loadout_item)) var/datum/loadout_item/listed_loadout = milestone_type - for(var/path in user.prefs.job_rewards_claimed[key_id]) - if(path == initial(milestone_type)) - return - if(!user.prefs.job_rewards_claimed[key_id]) - user.prefs.job_rewards_claimed[key_id] = list() - user.prefs.job_rewards_claimed[key_id] |= milestone_type + if(!force) + for(var/path in user.prefs.job_rewards_claimed[key_id]) + if(path == initial(milestone_type)) + return if(!user.prefs.inventory[initial(listed_loadout.item_path)]) user.prefs.inventory += initial(listed_loadout.item_path) var/datum/db_query/query_add_gear_purchase = SSdbcore.NewQuery({" INSERT INTO [format_table_name("metacoin_item_purchases")] (`ckey`, `item_id`, `amount`) VALUES (:ckey, :item_id, :amount)"}, list("ckey" = user.ckey, "item_id" = initial(listed_loadout.item_path), "amount" = 1)) if(!query_add_gear_purchase.Execute()) - to_chat(user, "Failed to add level up reward contact coders") + to_chat(user, "Failed to add level up reward to the database, contact coders.") qdel(query_add_gear_purchase) return FALSE qdel(query_add_gear_purchase) @@ -38,10 +36,14 @@ UPDATE [format_table_name("metacoin_item_purchases")] SET amount = :amount WHERE ckey = :ckey AND item_id = :item_id"}, list("ckey" = user.ckey, "item_id" = initial(listed_loadout.item_path), "amount" = 1)) if(!query_add_gear_purchase.Execute()) - to_chat(user, "Failed to add level up reward contact coders") + to_chat(user, "Failed to add level up reward to the database, contact coders.") qdel(query_add_gear_purchase) return FALSE qdel(query_add_gear_purchase) + + if(!user.prefs.job_rewards_claimed[key_id]) + user.prefs.job_rewards_claimed[key_id] = list() + user.prefs.job_rewards_claimed[key_id] |= milestone_type user.prefs.save_preferences() if(in_round_milestones[num2text(level)]) @@ -95,3 +97,22 @@ if(ishuman(mob)) var/mob/living/carbon/human/human_mob = mob human_mob.put_in_hands(new_item) + +/client/verb/reload_job_rewards() + set category = "IC" + set name = "Reload Job Rewards" + set desc = "Refresh job rewards you have for the current job (Use this if you suspect something is missing or broken)." + + if(!isliving(mob)) + to_chat(src, "For this to work you need to be living.") + return + + var/datum/mind/listed_mob = mob.mind + var/job_string = listed_mob.assigned_role.title + + for(var/datum/job_milestone/subtype as anything in subtypesof(/datum/job_milestone)) + if(!initial(subtype.key_id) == job_string) + continue + var/datum/job_milestone/subtype_created = new subtype + for(var/level in 1 to mob.client.prefs.job_level_list[job_string]) + subtype_created.check_milestones(level, mob.client, force = TRUE) From bbf20ddd6ceee086a51c73d85b0273285197f4e2 Mon Sep 17 00:00:00 2001 From: FernandoJ8 Date: Mon, 22 Jan 2024 23:00:46 +0100 Subject: [PATCH 3/4] Forgot that bit. --- monkestation/code/modules/job_xp/milestones/_milestones.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkestation/code/modules/job_xp/milestones/_milestones.dm b/monkestation/code/modules/job_xp/milestones/_milestones.dm index 558e420128dd..0f0173bd3323 100644 --- a/monkestation/code/modules/job_xp/milestones/_milestones.dm +++ b/monkestation/code/modules/job_xp/milestones/_milestones.dm @@ -4,7 +4,7 @@ var/list/in_round_milestones -/datum/job_milestone/proc/check_milestones(level, client/user, force) +/datum/job_milestone/proc/check_milestones(level, client/user, force = FALSE) if(!length(milestones) && !length(in_round_milestones)) return if(!milestones[num2text(level)] && !in_round_milestones[num2text(level)]) From 190ee6c1c9da096d60e14b65146e6e78df5edfc0 Mon Sep 17 00:00:00 2001 From: FernandoJ8 Date: Wed, 24 Jan 2024 10:13:44 +0100 Subject: [PATCH 4/4] Redundant things and safety checks --- monkestation/code/modules/job_xp/milestones/_milestones.dm | 4 ++-- .../code/modules/job_xp/preferences/base_preferences.dm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monkestation/code/modules/job_xp/milestones/_milestones.dm b/monkestation/code/modules/job_xp/milestones/_milestones.dm index 0f0173bd3323..2d6f74bc98c6 100644 --- a/monkestation/code/modules/job_xp/milestones/_milestones.dm +++ b/monkestation/code/modules/job_xp/milestones/_milestones.dm @@ -111,8 +111,8 @@ var/job_string = listed_mob.assigned_role.title for(var/datum/job_milestone/subtype as anything in subtypesof(/datum/job_milestone)) - if(!initial(subtype.key_id) == job_string) + if(!(initial(subtype.key_id) == job_string) || !isnum(prefs.job_level_list[job_string])) continue var/datum/job_milestone/subtype_created = new subtype - for(var/level in 1 to mob.client.prefs.job_level_list[job_string]) + for(var/level in 1 to prefs.job_level_list[job_string]) subtype_created.check_milestones(level, mob.client, force = TRUE) diff --git a/monkestation/code/modules/job_xp/preferences/base_preferences.dm b/monkestation/code/modules/job_xp/preferences/base_preferences.dm index 8abecd53b510..4af2348b8fdc 100644 --- a/monkestation/code/modules/job_xp/preferences/base_preferences.dm +++ b/monkestation/code/modules/job_xp/preferences/base_preferences.dm @@ -90,7 +90,7 @@ job_level_list[job]++ level_up_reward(job) for(var/datum/job_milestone/subtype as anything in subtypesof(/datum/job_milestone)) - if(!initial(subtype.key_id) == job) + if(!(initial(subtype.key_id) == job)) continue var/datum/job_milestone/subtype_created = new subtype subtype_created.check_milestones(job_level_list[job], parent)