Finishes timeclock duty switching functionality

This commit is contained in:
Heroman3003
2019-04-19 10:28:38 +10:00
parent 5f494a8470
commit 1a9cdecb32
4 changed files with 80 additions and 22 deletions

View File

@@ -5,6 +5,7 @@
/datum/configuration
var/list/engine_map // Comma separated list of engines to choose from. Blank means fully random.
var/time_off = FALSE
var/pto_job_change = FALSE
var/limit_interns = -1 //Unlimited by default
var/limit_visitors = -1 //Unlimited by default
var/pto_cap = 100 //Hours
@@ -52,5 +53,7 @@
config.pto_cap = text2num(value)
if ("time_off")
config.time_off = TRUE
if ("pto_job_change")
config.pto_job_change = TRUE
return 1

View File

@@ -90,7 +90,8 @@
"head_position" = job.head_position,
"timeoff_factor" = job.timeoff_factor
)
// TODO - Once job changing is implemented, we will want to list jobs to change into.
if(config.time_off && config.pto_job_change)
data["allow_change_job"] = TRUE
if(job && job.timeoff_factor < 0) // Currently are Off Duty, so gotta lookup what on-duty jobs are open
data["job_choices"] = getOpenOnDutyJobs(user, job.department)
@@ -116,18 +117,29 @@
I.forceMove(src)
card = I
update_icon()
return
return 1
if(href_list["switch-to-onduty"])
if(card)
if(checkCardCooldown())
makeOnDuty(href_list["switch-to-onduty"])
usr.put_in_hands(card)
card = null
update_icon()
return 1
if(href_list["switch-to-offduty"])
if(card)
if(checkCardCooldown())
makeOffDuty()
usr.put_in_hands(card)
card = null
update_icon()
return 1
return 1 // Return 1 to update UI
/obj/machinery/computer/timeclock/proc/getOpenOnDutyJobs(var/mob/user, var/department)
var/list/available_jobs = list()
for(var/datum/job/job in job_master.occupations)
if(job && job.is_position_available() && !job.whitelist_only) // && job.player_old_enough(user.client) && !jobban_isbanned(user,job.title)
if(job && job.is_position_available() && !job.whitelist_only && !jobban_isbanned(user,job.title) && job.player_old_enough(user.client))
if(job.department == department && !job.head_position && job.timeoff_factor > 0 && !(job.title == "Internal Affairs Agent"))
available_jobs += job.title
if(job.alt_titles)
@@ -138,19 +150,68 @@
/obj/machinery/computer/timeclock/proc/makeOnDuty(var/newjob)
var/datum/job/foundjob = null
for(var/datum/job/job in job_master.occupations)
if(job.title == newjob || newjob in job.alt_titles)
if(newjob == job.title)
foundjob = job
break
if(foundjob)
if(newjob in job.alt_titles)
foundjob = job
break
if(foundjob && card)
card.access = foundjob.get_access()
card.rank = foundjob.title
card.assignment = newjob
card.name = text("[card.registered_name]'s ID Card ([card.assignment])")
data_core.manifest_modify(card.registered_name, card.assignment)
card.last_job_switch = world.time
callHook("reassign_employee", list(card))
announce.autosay("[card.registered_name] has moved On-Duty as [card.assignment]", "Employee Oversight")
foundjob.current_positions++
announce.autosay("[card.registered_name] has moved On-Duty as [card.assignment].", "Employee Oversight")
return
/obj/machinery/computer/timeclock/proc/makeOffDuty()
var/datum/job/foundjob = null
for(var/datum/job/job in job_master.occupations)
if(card.rank == job.title)
foundjob = job
break
if(!foundjob)
return
var/real_dept = foundjob.department
if(real_dept && real_dept == "Command")
real_dept = "Civilian"
var/datum/job/ptojob = null
for(var/datum/job/job in job_master.occupations)
if(job.department == real_dept && job.timeoff_factor < 0)
ptojob = job
break
if(ptojob && card)
var/oldtitle = card.assignment
card.access = ptojob.get_access()
card.rank = ptojob.title
card.assignment = ptojob.title
card.name = text("[card.registered_name]'s ID Card ([card.assignment])")
data_core.manifest_modify(card.registered_name, card.assignment)
card.last_job_switch = world.time
callHook("reassign_employee", list(card))
foundjob.current_positions--
announce.autosay("[card.registered_name], [oldtitle], has moved Off-Duty.", "Employee Oversight")
return
/obj/machinery/computer/timeclock/proc/checkCardCooldown()
if(!card)
return FALSE
if((world.time - card.last_job_switch) < 15 MINUTES)
to_chat(usr, "You need to wait at least 15 minutes after last duty switch.")
return FALSE
return TRUE
/obj/item/weapon/card/id
var/last_job_switch
/obj/item/weapon/card/id/New()
.=..()
last_job_switch = world.time
//
// Frame type for construction
//
@@ -184,12 +245,3 @@
/obj/machinery/computer/timeclock/premade/west
dir = 4
pixel_x = -26
/mob/verb/gain_pto()
set name = "Gain PTO"
set category = "Debug"
if(!client)
return FALSE
else
client.department_hours += list("Security" = 30)

View File

@@ -407,6 +407,9 @@ ENGINE_MAP Supermatter Engine,Edison's Bane
# Controls if the 'time off' system is used for determining if players can play 'Off-Duty' jobs (requires SQL)
# TIME_OFF
# If 'time off' system is on, controls whether or not players can switch on/off duty midround using timeclocks
# PTO_JOB_CHANGE
# Applies a limit to the number of assistants and visitors respectively
# LIMIT_INTERNS 6
# LIMIT_VISITORS 6

View File

@@ -56,12 +56,12 @@
{{/if}}
</div>
{{if data.job_datum && data.job_datum.timeoff_factor != 0 && !(data.assignment == "Terminated")}}
{{if data.allow_change_job && data.job_datum && data.job_datum.timeoff_factor != 0 && !(data.assignment == "Terminated")}}
<h3>Employment Actions</h3>
<div class='itemGroup'>
<div class='item'>
{{if (data.job_datum.timeoff_factor > 0) }}
{{if helper.round(data.department_hours[data.job_datum.department]) > 0 }}
{{if helper.round(data.department_hours[data.job_datum.department]) > 0 || (data.job_datum.department == "Command" && helper.round(data.department_hours["Civilian"]) > 0)}}
{{:helper.link('Go Off-Duty', 'alert', {'switch-to-offduty': 1})}}
{{else}}
<i class='uiIcon16 icon-alert-red'></i>