/
job_exp.dm
225 lines (198 loc) · 6.67 KB
/
job_exp.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
GLOBAL_LIST_EMPTY(exp_to_update)
GLOBAL_PROTECT(exp_to_update)
// Procs
/datum/job/proc/required_playtime_remaining(client/C)
if(!C)
return 0
if(!CONFIG_GET(flag/use_exp_tracking))
return 0
if(!SSdbcore.Connect())
return 0
if(!exp_requirements || !exp_type)
return 0
if(!job_is_xp_locked(src.title))
return 0
if(CONFIG_GET(flag/use_exp_restrictions_admin_bypass) && check_rights_for(C,R_ADMIN))
return 0
var/isexempt = C.prefs.db_flags & DB_FLAG_EXEMPT
if(isexempt)
return 0
var/my_exp = C.calc_exp_type(get_exp_req_type())
var/job_requirement = get_exp_req_amount()
if(my_exp >= job_requirement)
return 0
else
return (job_requirement - my_exp)
/datum/job/proc/get_exp_req_amount()
if(title in (GLOB.command_positions | list("AI")))
var/uerhh = CONFIG_GET(number/use_exp_restrictions_heads_hours)
if(uerhh)
return uerhh * 60
return exp_requirements
/datum/job/proc/get_exp_req_type()
if(title in (GLOB.command_positions | list("AI")))
if(CONFIG_GET(flag/use_exp_restrictions_heads_department) && exp_type_department)
return exp_type_department
return exp_type
/proc/job_is_xp_locked(jobtitle)
if(!CONFIG_GET(flag/use_exp_restrictions_heads) && (jobtitle in (GLOB.command_positions | list("AI"))))
return FALSE
if(!CONFIG_GET(flag/use_exp_restrictions_other) && !(jobtitle in (GLOB.command_positions | list("AI"))))
return FALSE
return TRUE
/client/proc/calc_exp_type(exptype)
var/list/explist = prefs.exp.Copy()
var/amount = 0
var/list/typelist = GLOB.exp_jobsmap[exptype]
if(!typelist)
return -1
for(var/job in typelist["titles"])
if(job in explist)
amount += explist[job]
return amount
/client/proc/get_exp_living(pure_numeric = FALSE)
if(!prefs.exp || !prefs.exp[EXP_TYPE_LIVING])
return pure_numeric ? 0 : "No data"
var/exp_living = text2num(prefs.exp[EXP_TYPE_LIVING])
return pure_numeric ? exp_living : get_exp_format(exp_living)
/proc/get_exp_format(expnum)
if(expnum > 60)
return num2text(round(expnum / 60)) + "h"
else if(expnum > 0)
return num2text(expnum) + "m"
else
return "0h"
/datum/controller/subsystem/blackbox/proc/update_exp(mins, ann = FALSE)
if(!SSdbcore.Connect())
return -1
for(var/client/L in GLOB.clients)
if(L.is_afk())
continue
L.update_exp_list(mins,ann)
/datum/controller/subsystem/blackbox/proc/update_exp_db()
set waitfor = FALSE
var/list/old_minutes = GLOB.exp_to_update
GLOB.exp_to_update = null
SSdbcore.MassInsert(format_table_name("role_time"), old_minutes, duplicate_key = "ON DUPLICATE KEY UPDATE minutes = minutes + VALUES(minutes)")
//resets a client's exp to what was in the db.
/client/proc/set_exp_from_db()
if(!CONFIG_GET(flag/use_exp_tracking))
return -1
if(!SSdbcore.Connect())
return -1
var/datum/db_query/exp_read = SSdbcore.NewQuery(
"SELECT job, minutes FROM [format_table_name("role_time")] WHERE ckey = :ckey",
list("ckey" = ckey)
)
if(!exp_read.Execute(async = TRUE))
qdel(exp_read)
return -1
var/list/play_records = list()
while(exp_read.NextRow())
play_records[exp_read.item[1]] = text2num(exp_read.item[2])
qdel(exp_read)
for(var/rtype in SSjob.name_occupations)
if(!play_records[rtype])
play_records[rtype] = 0
for(var/rtype in GLOB.exp_specialmap)
if(!play_records[rtype])
play_records[rtype] = 0
prefs.exp = play_records
//updates player db flags
/client/proc/update_flag_db(newflag, state = FALSE)
if(!SSdbcore.Connect())
return -1
if(!set_db_player_flags())
return -1
if((prefs.db_flags & newflag) && !state)
prefs.db_flags &= ~newflag
else
prefs.db_flags |= newflag
var/datum/db_query/flag_update = SSdbcore.NewQuery(
"UPDATE [format_table_name("player")] SET flags=:flags WHERE ckey=:ckey",
list("flags" = "[prefs.db_flags]", "ckey" = ckey)
)
if(!flag_update.Execute())
qdel(flag_update)
return -1
qdel(flag_update)
/client/proc/update_exp_list(minutes, announce_changes = FALSE)
if(!CONFIG_GET(flag/use_exp_tracking))
return -1
if(!SSdbcore.Connect())
return -1
if (!isnum(minutes))
return -1
var/list/play_records = list()
if(isliving(mob))
if(mob.stat != DEAD)
var/rolefound = FALSE
play_records[EXP_TYPE_LIVING] += minutes
if(announce_changes)
to_chat(src,"<span class='notice'>You got: [minutes] Living EXP!</span>")
if(mob.mind.assigned_role)
for(var/job in SSjob.name_occupations)
if(mob.mind.assigned_role == job)
rolefound = TRUE
play_records[job] += minutes
if(announce_changes)
to_chat(src,"<span class='notice'>You got: [minutes] [job] EXP!</span>")
if(!rolefound)
for(var/role in GLOB.exp_specialmap[EXP_TYPE_SPECIAL])
if(mob.mind.assigned_role == role)
rolefound = TRUE
play_records[role] += minutes
if(announce_changes)
to_chat(mob,"<span class='notice'>You got: [minutes] [role] EXP!</span>")
if(mob.mind.special_role && !(mob.mind.datum_flags & DF_VAR_EDITED))
var/trackedrole = mob.mind.special_role
play_records[trackedrole] += minutes
if(announce_changes)
to_chat(src,"<span class='notice'>You got: [minutes] [trackedrole] EXP!</span>")
if(!rolefound)
play_records["Unknown"] += minutes
else
if(holder && !holder.deadmined)
play_records[EXP_TYPE_ADMIN] += minutes
if(announce_changes)
to_chat(src,"<span class='notice'>You got: [minutes] Admin EXP!</span>")
else
play_records[EXP_TYPE_GHOST] += minutes
if(announce_changes)
to_chat(src,"<span class='notice'>You got: [minutes] Ghost EXP!</span>")
else if(isobserver(mob))
play_records[EXP_TYPE_GHOST] += minutes
if(announce_changes)
to_chat(src,"<span class='notice'>You got: [minutes] Ghost EXP!</span>")
else if(minutes) //Let "refresh" checks go through
return
for(var/jtype in play_records)
var/jvalue = play_records[jtype]
if (!jvalue)
continue
if (!isnum(jvalue))
CRASH("invalid job value [jtype]:[jvalue]")
LAZYINITLIST(GLOB.exp_to_update)
GLOB.exp_to_update.Add(list(list(
"job" = jtype,
"ckey" = ckey,
"minutes" = jvalue)))
prefs.exp[jtype] += jvalue
addtimer(CALLBACK(SSblackbox,/datum/controller/subsystem/blackbox/proc/update_exp_db),20,TIMER_OVERRIDE|TIMER_UNIQUE)
//ALWAYS call this at beginning to any proc touching player flags, or your database admin will probably be mad
/client/proc/set_db_player_flags()
if(!SSdbcore.Connect())
return FALSE
var/datum/db_query/flags_read = SSdbcore.NewQuery(
"SELECT flags FROM [format_table_name("player")] WHERE ckey=:ckey",
list("ckey" = ckey)
)
if(!flags_read.Execute(async = TRUE))
qdel(flags_read)
return FALSE
if(flags_read.NextRow())
prefs.db_flags = text2num(flags_read.item[1])
else if(isnull(prefs.db_flags))
prefs.db_flags = 0 //This PROBABLY won't happen, but better safe than sorry.
qdel(flags_read)
return TRUE