[摳頂] /open/cmds/event.c

作者: laechan (揮淚斬馬雲)   2023-06-19 11:35:00
// event.c
// [email protected] 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([email protected]
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 ;
}

Links booklink

Contact Us: admin [ a t ] ucptt.com