-
Notifications
You must be signed in to change notification settings - Fork 0
/
CORE 02 - Global Functions.txt
220 lines (129 loc) · 12.1 KB
/
CORE 02 - Global Functions.txt
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
@@ CORE
@cmdquota me=99999
@skip isdbref(tag(setr(1,gfun)))={@assert/inline isdbref(tag(stor))=@pemit %#=ERROR: No storage object installed!;@assert/inline isdbref(setr(0,create(Global Functions,,t)))=@pemit %#=ERROR: Could not create code object: %q0;@set %q0=INDESTRUCTIBLE NO_COMMAND;@tag/add %q1=%q0;@tel %q1=#stor}
&GFN.GTBITTYPE #gfun=gt(bittype(%0),%1)
&GFN.GTEBITTYPE #gfun=gte(bittype(%0),%1)
&GFN.GET_SWITCHES #gfun=setunion(iter(lnum(7),if(gtebittype(%1,%i0),u(%0/SWITCHES.[if(strlen(%2),%2.)]%i0)),%b,|),u(%0/SWITCHES[if(strlen(%2),%2.)],%1),|,|)
&GFN.SET_KV #gfun=setunion(del_kv(%0,%1),%1~%2,|,|)
&GFN.DEL_KV #gfun=setdiff(%0,grab(%0,%1~*,|),|,|)
&GFN.GET_KV #gfun=strfirstof(rest(grab(%0,%1~*,|),~),%2)
&GFN.UCRC32 #gfun=crc32(ucstr(%0))
&GFN.ATTRIB_GET #gfun=if(visiblemux(%@,%0/%1),xget(%0,%1),#-1 READ PERMISSION DENIED FOR %0/%1)
&GFN.SET_AKV #gfun=attrib_set(%0,%1,set_kv(attrib_get(%0,%1),%2,%3))
&GFN.SORTNAME #gfun=sortby(#lambda/[lit([comp(lcstr(name(%0)),lcstr(name(%1)))])],%0,if(strlen(%1),%1,%B),if(strlen(%2),%2,%B))
&GFN.GETALIAS #gfun=switch(type(%0),EXIT,if(strfirstof(%1,1),elementsmux(fullname(%0),2,;),after(fullalias(%0),chr(59))),get(%0/ALIAS))
@@ %0 - dbref, %1 - full alias if exit.
&GFN.RANDWORD #gfun=first(shuffle(%0,strfirstof(%1,%b),strfirstof(%1,%b)),strfirstof(%1,%b))
&GFN.NAMEMATCH #gfun=t(match([name(%0)]|[num(%0)]|[objid(%0)][if(%2,|[getalias(%0)])][if(%3,|[u(%0/%3)])],%1,|))
&GFN.NAMEFIND #gfun=trim(localize(iter(sortname(%0),if(namematch(%i0,%1,%2,%3),%i0[ibreak()]))))
@@ %0 - dbrefs. %1 - name. %2 - check aliases. %3 - match against results of this function call
&GFN.OBJIDS #gfun=squish(iter(%0,if(isdbref(%i0),objid(%i0))))
@@ %0 dbref list.
&GFN.NUMTH #gfun=%0[switch(%0,11,th,12,th,13,th,switch(right(%0,1),1,st,2,nd,3,rd,th))]
&GPFN.ISAPPROVED #gfun=cor(gtebittype(%0,2),if(globalconf(REQAPPROVAL),default(%0/GAME.APPROVED,0),1))
&FIL.INHERITABLE_ATTR #gfun=!hasflag(%1/%0,NO_INHERIT)
&FN.INHERITABLE #gfun=filter(#gfun/FIL.INHERITABLE_ATTR,lattrp(%0/%1,%2,%3,%4,%5,%6),%b,%b,%0)
&FN.LATTR_ANCESTOR #gfun=if(isdbref(#[config(%0)]),u(#gfun/FN.INHERITABLE,#[config(%0)],%1,%2,%3,%4,%5,%6))
&GPFN.LATTRP_FULL #gfun=setunion(lattrp(%0/%1,%@,%2,%3,%4,%5),if(!hasflag(%0,NO_GOBJ),u(#gfun/FN.LATTR_ANCESTOR,global_parent_[type(%0)],%1,%@,%2,%3,%4,%5)))
&GFN.AWHO #gfun=sortname(setunion(iter(account_who(),objid(#[account_owner(%i0)])),))
®_CAPNAMES #gfun=(?:^|(?<=[_\/\-\|\s()\+]))([a-z]+)
®_CAPNAMES2 #gfun=(^|(?<=[(]))(of|the|a|and)
®_CAPNAMES3 #gfun=\b(of|the|a|and)\b
&GPFN.CAPNAMES #gfun=regeditalli(lcstr(%0),v(REG_CAPNAMES),capstr($1),v(REG_CAPNAMES3),lcstr($0),v(REG_CAPNAMES2),$1[capstr($2)])
&GFN.COMMAFY #gfun=trim(flip(foreach(#lambda/if(mod([lit(%1)],3),[lit(%0)],\\,[lit(%0)]),flip(%0))),b,chr(44))
&GFN.RYG #gfun=<[if(gt(%0,50),255,round(mul(255,fdiv(mul(%0,2),100)),0))] [if(gte(%0,50),sub(mul(255,2),round(mul(255,fdiv(mul(%0,2),100)),0)),255)] 0>
&GFN.AGO #gfun=singletime(%0)
&GFN.SMALLTIME #gfun=singletime(%0)
&GFN.NCHILDREN #gfun=last(children(%0,l))
&GFN.CSECS #gfun=runintz(UTC,convtime(createtime(%0)))
&GFN.CTIME #gfun=createtime(%0)
&GFN.GETTZ #gfun=strfirstof(accoption(%0,TIMEZONE),get(%0/TIMEZONE),UTC)
&GFN.LWHOID #gfun=setunion(lwho(,,1),)
&GFN.BITWHO #gfun=filter(#lambda/[lit(gte(bittype(%0),%1))],lwhoid(),%b,%b,%0)
&GFN.FILTEROBJID #gfun=filter(#lambda/[lit(isobjid(%0))],%0)
&GFN.FANCYTIME #gfun=if(cor(!strlen(%0),isint(%0)),runintz(if(strlen(%2),if(isdbref(%2),gettz(%2),%2),gettz(%#)),timefmt(switch(%1,2,$a $b $02D $02I:$02M$p $Z,3,$b $02D $02I:$02M$p $Y $Z,day,$b $02D $Y,date,$m/$d/$Y,strfirstof(%3,$b $02D $02H:$02T$P $i)),strfirstof(%0,secs()))),<invalid date>)
&GFN.DECOMPOSE #gfun=translate(%0,p)
&GFN.HAS_MARKUP #gfun=!eq(strlen(%0),strlenraw(%0))
&GFN.CENTER #gfun=printf($^[strfirstof(%1,78)]:%2:s,%0)
&GFN.HASATTRVAL #gfun=!!$get(%0)
&GFN.CONTAINS_CHARACTER #gfun=lmax(iter(%1,strmatch(%0,*%i0*)))
&GFN.PMATCHID #gfun=localize(if(setr(!,pmatch(%0),res),objid(%q<res>),%q<res>))
&GFN.PMATCHREG #gfun=setr(!,pmatch(%0),%1)
&GFN.PARTIAL #gfun=localize(if(setr(0,match(%0,%1,%2)),elementsmux(%0,%q0,%2),grab(%0,%1*,%2)))
&GPFN.UPZONE #gfun=if(hastype(%0,ROOM),if(isdbref(lzone(%0)),objid(lzone(%0))),if(isdbref(loc(%0)),if(hasflag(loc(%0),ZONEMASTER),objid(loc(%0)),upzone(loc(%0)))))
@@ %0 - an object to find the next zone 'up' for. This strives to deal with searching up through locations and zone relationships. For example a ZONEMASTER could be in another ZONEMASTER's inventory, or it could be in a ROOM that belongs to the zone.
&GPFN.UPZONES #gfun=privatize(1,if(cand(isdbref(setr(!,upzone(%0),newzone)),!match(%1,%q<newzone>)),upzones(%q<newzone>,%1 %q<newzone>),trim(%1)))
@@ %0 - start location object for upzone(). %1 - current chain.
&GFN.SECS_REMAIN #gfun=max(0,sub(%0,secs()))
&GFN.UMAIL #gfun=elementsmux(mailquick(%0,,1),2)
&GPFN.GETCONF #gfun=default(%0/CONFIG.%1.VALUE,get(%0/CONFIG.%1.DEFAULT))
&GPFN.GLOBALCONF #gfun=getconf(#conf,%0)
&GFN.ACCOUNT #gfun=privatize(1,if(hastotem(%0,ACCOUNT),objid(%0),if(isdbref(setr(!,get(%0/_ACCOUNT),acc)),account(%q<acc>))))
@@ %0 - dbref of player or account.
&GPFN.ACCOPTION #gfun=privatize(1,if(isdbref(setr(!,account(%0),acc)),default(%q<acc>/CONFIG.%1.VALUE,get(#acc_parent/CONFIG.%1.DEFAULT)),get(#acc_parent/CONFIG.%1.DEFAULT)))
@@ %0 - Dbref of player or account. %1 - Option.
&GPFN.LASTIDLE #gfun=switch(objeval(%#,conn(%0)),-1,ansi(hx,elementsmux(get(%0/last),2 3)),hideidle(%0))
&GPFN.HIDECONN #gfun=switch(objeval(%#,conn(%0)),-1,ansi(hx,Off),ansi(if(ishidden(%0),hx,hg),smalltime(conn(%0),3)))
&GPFN.HIDEIDLE #gfun=switch(objeval(%#,idle(%0)),-1,ansi(hx,Off),ansi(if(ishidden(%0),hx,ryg(round(mul(fdiv(bound(idle(%0),0,3600),3600),100),0))),smalltime(idle(%0),3)))
&GPFN.LASTCONN #gfun=switch(objeval(%#,conn(%0)),-1,ansi(hx,elementsmux(get(%0/last),2 3)),hideconn(%0))
@@ Header stuff
&GPFN.HEADER #gfun=localize(u(HEADER_PREP,%1,HEADER,%2,=,%3)[setq(!,if(strlen(%0),[ansi(%q<bordercolor>,<<)]%B[if(has_markup(%0),%0,ansi(%q<htextcolor>,%0))]%B[ansi(%q<bordercolor>,>>)]),headertext)][u(HEADER_RENDER,HEADER,%0)])
&GPFN.SUBHEADER #gfun=localize(u(HEADER_PREP,%1,SUBHEADER,%2,=,%3)[setq(!,if(strlen(%0),[ansi(%q<bordercolor>,<)]%B[if(has_markup(%0),%0,ansi(%q<htextcolor>,%0))]%B[ansi(%q<bordercolor>,>)]),headertext)][u(HEADER_RENDER,SUBHEADER,%0)])
&GPFN.SEPARATOR #gfun=localize(u(HEADER_PREP,%1,SEPARATOR,%2,-,%3)[setq(!,if(strlen(%0),[ansi(%q<bordercolor>,<)]%B[if(has_markup(%0),%0,ansi(%q<htextcolor>,%0))]%B[ansi(%q<bordercolor>,>)]),headertext)][u(HEADER_RENDER,SEPARATOR,%0)])
&GPFN.FOOTER #gfun=localize(u(HEADER_PREP,%1,FOOTER,%2,=,%3)[setq(!,if(strlen(%0),[ansi(%q<bordercolor>,<)]%B[if(has_markup(%0),%0,ansi(%q<htextcolor>,%0))]%B[ansi(%q<bordercolor>,>)]),headertext)][u(HEADER_RENDER,FOOTER,%0)])
&GPFN.CONFOVERRIDE #gfun=strfirstof(accoption(%0,%1),globalconf(%1),%2)
&HEADER_PREP #gfun=setq(!,owner(strfirstof(%0,%#)),target)[setq(!,confoverride(%q<target>,BORDER),bordercolor)][setq(!,%4,bordermode)][setq(!,confoverride(%q<target>,HDRTEXT),htextcolor)][setq(!,sub(width(%q<target>),2),width)][setq(!,%2,lwidth)][setq(!,%3,fill)][switch(%q<bordermode>,2,switch(%2,HEADER,setq(!,ansi(%q<bordercolor>,/),start)[setq(!,ansi(%q<bordercolor>,chr(92)),end)],FOOTER,setq(!,ansi(%q<bordercolor>,chr(92)),start)[setq(!,ansi(%q<bordercolor>,/),end)]),1,setq(!,setr(!,ansi(%q<bordercolor>,+),end),start),setq(!,setr(!,ansi(%q<bordercolor>,%q<fill>),end),start))]
&HEADER_RENDER #gfun=if(%q<screenreader>,if(strlen(%1),%1),%q<start>[if(%q<lwidth>,[repeat(ansi(%q<bordercolor>,%q<fill>),%q<lwidth>,1)]%q<headertext>[repeat(ansi(%q<bordercolor>,%q<fill>),sub(%q<width>,%q<lwidth>,strlen(%q<headertext>)),1)],center(%q<headertext>,%q<width>,ansi(%q<bordercolor>,%q<fill>)))]%q<end>)
@@ HEADER family args: %0 - Title. %1 - Viewer dbref. %2 - left side manual size, %3 - bordermode.
&GMFN.GET_UPZONES #gfun=filterobjid(get(%0/GAME.UPZONES))
&GFN.GETPARTIAL #gfun=if(!strlen(%0),#-1 MUST ENTER A [strfirstof(%4,%3)],if(setr(!,match(%1,%0,%2),%3),1[setq(!,elementsmux(%1,r(%3),%2),%3)],if(eq(words(setr(!,graball(%1,%0*,%2,%2),%3),%2),1),1,if(gt(words(r(%3),%2),1),#-2 AMBIGUOUS MATCH FOR A [strfirstof(%4,%3)]: [elist(r(%3),,%2)],#-1 NO MATCHED [strfirstof(%4,%3)]. CHOICES ARE: [elist(%1,,%2)]))))
@@ %0 - input, %1 - choices, %2 - delimiter, %3 register to load, %4 name of thing to display
@@ Function returns 0 or 1 for if partial match successful, else returns helpful formatted error.
&GFN.MYSQL #gfun=if(hasattrp(%!/Q.%0),sql(setr(!,sqlformat(%0,%1,%2,%3,%4,%5,%6,%7,%8,%9),sqlformat)),#-1 SQL QUERY DATA NOT FOUND)
&GFN.MYSQL2 #gfun=if(hasattrp(%!/Q.%0),sql(setr(!,sqlformat(%0,%1,%2,%3,%4,%5,%6,%7,%8,%9),sqlformat),|,^),#-1 SQL QUERY DATA NOT FOUND)
®.SQLFORMAT #gfun=(!|\?)
&GFN.SQLFORMAT_RAW #gfun=privatize(1,edit(edit(edit(regeditalli(%0,get(#gfun/REG.SQLFORMAT),[setq(!,$0,reg)][if(isint(setr(!,v(setr(!,inc(%q<sqlnum>),sqlnum)),arg)),%q<arg>,switch(%q<reg>,!,%q<arg>,switch(%q<arg>,NULL,NULL,SET_NULL,SET_NULL,'[sqlescape(%q<arg>)]')))]),=NULL,%BIS NULL),=SET_NULL,=NULL),='SET_NULL',=NULL))
&GFN.SQLFORMAT #gfun=sqlformat_raw(v(Q.%0),%1,%2,%3,%4,%5,%6,%7,%8,%9)
&GMFN.CAN_ACT #gfun=ofparse(3,1)
&GMFN.CAN_SEE #gfun=ofparse(3,1)
&GMFN.CAN_MOVE #gfun=ofparse(3,u(GMFN.CAN_ACT,%0),1)
&FN.ONAME.PC #gfun=cname(%0)
&FN.ONAME.ITEM #gfun=cname(%0)
&FN.ONAME.NPC #gfun=cname(%0)
&FN.ONAME.STRUCTURE #gfun=cname(%0)
&FN.ONAME.REGION #gfun=cname(%0)
&GMFN.ONAME_FOR #gfun=privatize(1,if(cor(strmatch(num(%0),num(%1)),gtebittype(%1,2),!hastype(%1,PLAYER)),cname(%0),if(strlen(setr(!,trim(squish(iter(PC NPC ITEM STRUCTURE REGION,if(cand(hastotem(%0,%i0),strlen(setr(!,u(FN.ONAME.%i0,%0,%1)))),%q<res>[ibreak()]),|,|),|),b,|),res)),%q<res>,cname(%0))))
@@ %0 target, %1 - viewer
&GPFN.ONAME #gfun=oname_for(%0,%#)
&FN.KEYWORDS.PC #gfun=name(%0)
&FN.KEYWORDS.ITEM #gfun=name(%0)
&FN.KEYWORDS.NPC #gfun=name(%0)
&FN.KEYWORDS.STRUCTURE #gfun=name(%0)
&FN.KEYWORDS.REGION #gfun=name(%0)
&GMFN.KEYWORDS_FOR #gfun=privatize(1,if(cor(strmatch(num(%0),num(%1)),gtebittype(%1,2),!hastype(%1,PLAYER)),name(%0),if(strlen(setr(!,trim(squish(iter(PC NPC ITEM STRUCTURE REGION,if(cand(hastotem(%0,%i0),strlen(setr(!,u(FN.KEYWORDS.%i0,%0,%1)))),%q<res>[ibreak()]),|,|),|),b,|),res)),%q<res>,name(%0))))
@@ %0 target, %1 - viewer
@@ Can items, vehicles, and locations have a sex/gender? Sure why not.
&FN.SEX.PC #gfun=get(%0/SEX)
&FN.SEX.ITEM #gfun=get(%0/SEX)
&FN.SEX.NPC #gfun=get(%0/SEX)
&FN.SEX.STRUCTURE #gfun=get(%0/SEX)
&FN.SEX.REGION #gfun=get(%0/SEX)
&GMFN.SEX_FOR #gfun=privatize(1,if(cor(strmatch(num(%0),num(%1)),gtebittype(%1,2),!hastype(%1,PLAYER)),get(%0/SEX),if(strlen(setr(!,trim(squish(iter(PC NPC ITEM STRUCTURE REGION,if(cand(hastotem(%0,%i0),strlen(setr(!,u(FN.SEX.%i0,%0,%1)))),%q<res>[ibreak()]),|,|),|),b,|),res)),%q<res>,get(%0/SEX))))
&GPFN.MYONAMEFORENACTOR #gfun=u(FN.ONAME_FOR,%@,%#)
&FMT._UPPER #gfun=privatize(1,if(isupper(setr(!,left(%2,1),first)),if(eq(0,comp(%0,%1)),ucstr(%2),creplace(%2,0,ucstr(%q<first>))),%2))
&FMT.YOU #gfun=u(FMT._UPPER,%0,YOU,if(strmatch(setr(!,num(strfirstof(%1,%3)),target),num(%2)),you,gm_oname_for(%q<target>,%2)))
&FMT.YOUR #gfun=u(FMT._UPPER,%0,YOUR,if(strmatch(setr(!,num(strfirstof(%1,%3)),target),num(%2)),your,gm_oname_for(%q<target>,%2)'s))
@@ %0 function name, %1 argument, %2 recipient, %3 source
&FMT.FANCYTIME #gfun=fancytime(elements(%1,1,|),elements(%1,2,|),%2)
&FMT.ART #gfun=u(FMT._UPPER,%0,ART,art(%1))
&FMT.AN #gfun=u(FMT._UPPER,%0,AN,art(%1,1))
&FMT._GENDER #gfun=u(FMT._UPPER,%0,%1,if(strmatch(setr(!,num(strfirstof(%1,%3)),target),num(%2)),%4,[set(%!,SEX:[gm_sex_for(%q<target>,%2)])][strfunc(%5,%!)]))
&FMT.POSS #gfun=u(FMT._GENDER,%0,POSS,%2,%3,your,poss)
&FMT.APOSS #gfun=u(FMT._GENDER,%0,APOSS,%2,%3,yours,aposs)
&FMT.SUBJ #gfun=u(FMT._GENDER,%0,SUBJ,%2,%3,you,subj)
&FMT.OBJ #gfun=u(FMT._GENDER,%0,OBJ,%2,%3,you,obj)
&FMT.ALT #gfun=u(FMT._UPPER,%0,ALT,elements(%1,if(strmatch(num(%2),num(%3)),1,2),|))
®.FORMAT #gfun=(\$(\w+)(?:\((.*?)\))?)
&GMFN.FORMAT #gfun=regeditalli(%0,get(#gfun/REG.FORMAT),[setq(!,$0,all)][setq(!,$2,fn)][setq(!,$3,arg)][uldefault(#gfun/FMT.%q<fn>,%q<all>,%q<fn>,%q<arg>,%1,%2,%3,%4,%5,%6,%7,%8,%9)])
@@ %0 - message, %1 - recipient, %2 - source, %3+, extra arguments?
@startup #gfun=@attach #inc/REGISTER_FUNCTIONS