作者laechan (挥泪斩马云)
看板mud_sanc
标题[抠顶] /open/cmds/event.c
时间Mon Jun 19 11:35:00 2023
// event.c
// laechan@sanc add 2023.06.19
// for 节庆/活动 物品资料存放区 兼控制房
inherit DAEMON;
// 历史+现在活动标记与名称对照表
// event_names ([\
// "日期活动标记1":"名称1",\
// "日期活动标记2":"名称2",\
])
#define event_names ([\
])
// 进行中的活动
// now_event ([\
// "日期活动标记1":({"物品11","物品21",...}),\
// "日期活动标记2":({"物品21","物品22",...}),\
// ])
#define now_event ([\
])
/*
过去的活动设定区
*/
static mixed event_obs;
mapping ppl_event_ob;
void create()
{
string tmp1,tmp2;
seteuid(getuid(this_object()));
if(file_exists("/open/cmds/event"))
restore_object("/open/cmds/event");
else
ppl_event_ob=([]);
if(!event_obs)
{
event_obs=({});
foreach(tmp1 in keys(now_event))
foreach(tmp2 in now_event[tmp1])
if(member_array(tmp2,event_obs)==-1)
event_obs+=({tmp2});
}
}
int check_event_ob(string fname)
{
return member_array(fname,event_obs);
}
static int times;
int save_room()
{
int t=time();
if(times && times==t) return 1;
times=t;
save_object("/open/cmds/event");
return 1;
}
// func=set,add,del,query,all
varargs mixed ppl_event_ob(object ppl,string func,string fname,int n)
{
string names;
if(!ppl || !func || !fname)
{
write(HIR+@LONG
ppl_event_ob(玩家物件,"功能","物品名");
ppl_event_ob(玩家物件,"功能","物品名",数量);
LONG
+NOR);
return 0;
}
if(func=="delete") func="del";
if(check_event_ob(fname)==-1 &&
((func=="query" || func=="del") && fname!="all"))
{
write(HIR+fname+" 目前并非活动物品。"NOR"\n");
return 0;
}
if((func=="set" || func=="add") && !n)
{
write(HIR+func+" 必须给数量."NOR"\n");
return 0;
}
names=ppl->query("name");
if(undefinedp(ppl_event_ob[names]))
ppl_event_ob[names]=([]);
else if(undefinedp(ppl_event_ob[names][fname]))
ppl_event_ob[names][fname]=0;
switch(func)
{
case "query":
if(fname=="all")
return (mapping)ppl_event_ob[names];
return (int)ppl_event_ob[names][fname];
break;
case "del":
if(fname=="all")
map_delete(ppl_event_ob,names);
else
map_delete(ppl_event_ob[names],fname);
break;
case "set": ppl_event_ob[names][fname]=n; break;
case "add": ppl_event_ob[names][fname]+=n; break;
}
save_room();
return 1;
}
// 玩家的id
void show_event_info(string names)
{
mixed tmps=({});
string str="";
if(undefinedp(ppl_event_ob[names]))
{
write(HIR"查无 "+names+" 打到的物品资料."NOR"\n");
return ;
}
foreach(t1 in keys(now_event))
{
str+=sprintf("%-s 在 %-s(%-s):\n",names,event_names[t1],t1);
foreach(t2 in now_event[t1])
{
if(undefinedp(ppl_event_ob[names][t2])) continue;
else if(ppl_event_ob[names][t2]<1) continue;
tmps=questing("vobjs","query_array",t2);
str+=sprintf(" %-s(%s) : %d\n",tmps[1],t2,ppl_event_ob[names][t2]);
}
str+="\n";
}
write(str);
return ;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.126.145.135 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/mud_sanc/M.1687145703.A.B4C.html
※ 编辑: laechan (59.126.145.135 台湾), 06/19/2023 15:31:00