Skip to content

Commit

Permalink
调整指令结构,优化示例代码
Browse files Browse the repository at this point in the history
  • Loading branch information
oiuv committed May 4, 2022
1 parent 437cff6 commit 6038a30
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 64 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ LPC 开发测试 LIB,配合 fluffos v2019 以上版本使用。
.
├── README.md
├── cmds 游戏指令
│   ├── demo 教程演示指令,请输入 demo/xxx 运行
│   ├── demo 教程演示指令
│   │   └── ...
│   ├── efun 教程 efun 指令
│   │   └── ...
│   ├── test 个人测试目录,你可以把自己的测试指令放在这里
│   │   └── test.c
│   └── ...
│   └── cmd 基础指令
├── config.cfg 运行时配置文件精简版(FluffOS v2019)
├── config.ini 运行时配置文件注释版(FluffOS v2019)
├── data 存档目录
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions cmds/help.c → cmds/cmd/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ int main(object me, string arg)

当你输入$HIY$tutorial user$NOR$会解锁更多功能你慢慢变的能看能动能说能战斗

另外还可以可以直接使用 efun 目录下的指令也可以直接运行 demo 目录下的示例具体有哪些指令和示例
可以输入以下指令查看
$CYN$get_dir cmds/efun$NOR$ $CYN$get_dir cmds/demo$NOR$
另外还可以可以直接使用 efun 目录下的指令具体有哪些指令和示例可以输入以下指令查看
$CYN$get_dir cmds/efun$NOR$

提示如有疑问可以在输入$HIY$tutorial user3$NOR$在线$HIC$chat 问题内容$NOR$寻求QQ群中网友的帮助
HELP;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmds/demo/2.4.1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int main()
int main(object me, string arg)
{
float f = 251;
int w = 19.427;
Expand Down
2 changes: 1 addition & 1 deletion cmds/demo/2.5.1.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 转义字符输出
int main()
int main(object me, string arg)
{
// 字符串
write("\61\11\62\11\63\12");
Expand Down
80 changes: 80 additions & 0 deletions cmds/demo/6.3.2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
int main(object me, string arg)
{
// 声明映射变量
mapping m1, m2, m3, m;
string *keys = ({"a", "b", "c"});
// 初始化
m = (["name":"mudren", "age":18, "gender":"男性"]);
printf("m = %O\n", m);
// 写
m["name"] = "雪风";
// 增
m["title"] = "MUD游戏菜鸟";
// m += (["title":"MUD游戏老鸟"]);
m += (["data":([
"hp":100,
"mp":50,
"str":50,
"def":30,
"dex":20])]);
m += (["ob": me]);
printf("m = %O\n", m);
// 删
map_delete(m, "gender");
map_delete(m["data"], "mp");
// 读
printf("m = %O\n", m);
printf("name = %O\n", m["name"]);
printf("hp = %O\n", m["data"]["hp"]);

// 取所有键值
printf("keys = %O\n", keys(m));
printf("values = %O\n", values(m));

// 判断 undefinedp()
printf("%d\n", undefinedp(m["age"]));
printf("%d\n", nullp(m["gender"]));
printf("%O\n", m["gender"]);

// 映射与json转换(sefun)
printf("%s\n", json_encode(m));

// 初始化空映射
m = allocate_mapping(100);
printf("m = %O\n", m);
m = ([]);
printf("m = %O\n", m);

m1 = allocate_mapping(keys, ({"一", "二", "三"}));
m2 = allocate_mapping(keys, "mud");
m3 = allocate_mapping(keys, (: repeat_string($1, 5) :));
printf("m1 = %O\n", m1);
printf("m2 = %O\n", m2);
printf("m3 = %O\n", m3);

// 运算
m1 = ([]);
m2 = ([]);
m1["driver"] = "mudos";
m2["mudos"] = "fluffos";
m3 = m1 + m2;
printf("m3 = %O\n", m3);
m3 = m1 * m2;
printf("m3 = %O\n", m3);

// copy
m2 = m1;
m3 = copy(m1);
printf("m1 = %O\n", m1);
m2["mudos"] = "fluffos";
printf("m1 = %O\n", m1);
printf("m3 = %O\n", m3);

// 关于映射中的键
m[0] = "test";
m[me] = "test";
m[keys] = "test";
printf("m = %O\n", m);

return 1;
}
2 changes: 1 addition & 1 deletion config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ master file : /system/kernel/master
simulated efun file : /system/kernel/simul_efun
global include file : <globals.h>
debug log file : debug.log
external_port_1 : telnet 4000
external_port_1 : telnet 4004
external_port_2 : websocket 80
; external_port_3 : websocket 443
; external_port_3_tls : cert=cert.crt key=cert.key
Expand Down
48 changes: 48 additions & 0 deletions inherit/living.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
inherit OBJECT;
inherit VERB;

#define CMD_PATH "/cmds/cmd/"
#define DEMO_PATH "/cmds/demo/"
#define EFUN_PATH "/cmds/efun/"
#define TEST_PATH "/cmds/test/"

int is_living() { return 1; }

void set_living(string id)
Expand All @@ -12,6 +17,7 @@ void set_living(string id)
set_living_name(id);
seteuid(id);
}
add_action("command_hook", "", 1);
}

// NPC消息界面 catch_tell()
Expand All @@ -25,3 +31,45 @@ int command(string cmd)
{
return efun::command(cmd);
}

nomask int command_hook(string arg)
{
string verb, cmd, test, efun_cmd, demo;
object me, cmd_ob;

verb = query_verb();
cmd = CMD_PATH + verb;
test = TEST_PATH + verb;
efun_cmd = EFUN_PATH + verb;
demo = DEMO_PATH + verb;
me = this_object();

if ((verb = trim(verb)) == "")
return 0;

if (!arg && (objectp(environment()) && environment()->query("exits/" + verb)))
{
me->command("go " + verb);
}
else if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test) || cmd_ob = load_object(efun_cmd) || cmd_ob = load_object(demo))
{
return (int)cmd_ob->main(me, arg);
}
else
{
mixed err = parse_sentence(arg ? verb + " " + arg : verb, 0);
if (intp(err))
{
switch (err)
{
case 1: // verb 匹配成功
return 1;
default:
return 0;
}
}
return notify_fail(err);
}

return 1;
}
55 changes: 6 additions & 49 deletions inherit/user.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
/*
* @Author: 雪风@mud.ren
* @Date: 2022-03-31 15:04:35
* @LastEditTime: 2022-04-03 17:09:48
* @LastEditTime: 2022-05-04 15:56:29
* @LastEditors: 雪风
* @Description: 自定义 user 对象
* https://bbs.mud.ren
*/
inherit LIVING;

#define CMD_PATH "/cmds/"
#define TEST_PATH "/cmds/test/"
#define EFUN_PATH "/cmds/efun/"
#define DEMO_PATH "/cmds/demo/"

varargs void create(string arg)
{
if (clonep())
Expand All @@ -24,7 +19,6 @@ varargs void create(string arg)
set_living(arg);
set("gender", random(2) ? "男" : "女");
set("name", element_of(name1) + element_of(name2));
add_action("command_hook", "", 1);
move_object(START_ROOM);
}
else
Expand All @@ -36,52 +30,15 @@ varargs void create(string arg)
}
}

nomask int command_hook(string arg)
{
string verb, cmd, test, efun_cmd, demo;
object me, cmd_ob;

verb = query_verb();
cmd = CMD_PATH + verb;
test = TEST_PATH + verb;
efun_cmd = EFUN_PATH + verb;
demo = DEMO_PATH + verb;
me = this_object();

if ((verb = trim(verb)) == "")
return 0;

if (!arg && (objectp(environment()) && environment()->query("exits/" + verb)))
{
me->command("go " + verb);
}
else if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test) || cmd_ob = load_object(efun_cmd) || cmd_ob = load_object(demo))
{
return (int)cmd_ob->main(me, arg);
}
else
{
mixed err = parse_sentence(arg ? verb + " " + arg : verb, 0);
if (intp(err))
{
switch (err)
{
case 1: // verb 匹配成功
return 1;
default:
return 0;
}
}
return notify_fail(err);
}

return 1;
}

int move_or_destruct(object dest)
{
debug("突然一阵时空扭曲,你被传送到虚空。");
move(VOID_OB);

return 1;
}

void net_dead()
{
destruct();
}
6 changes: 6 additions & 0 deletions system/object/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ void logon()
write("请输入你的ID:");
input_to("setup");
}

void net_dead()
{
debug_message(ctime() + " net_dead " + query_ip_number());
destruct();
}
20 changes: 13 additions & 7 deletions system/object/user.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#define CMD_PATH "/cmds/"
#define CMD_PATH "/cmds/cmd/"
#define DEMO_PATH "/cmds/demo/"
#define TEST_PATH "/cmds/test/"

int command_hook(string arg);

varargs void create(string arg)
{
if (clonep())
Expand All @@ -17,13 +16,15 @@ varargs void create(string arg)

int command_hook(string arg)
{
string cmd, test;
string verb, cmd, demo, test;
object cmd_ob;

cmd = CMD_PATH + query_verb();
test = TEST_PATH + query_verb();
verb = query_verb();
cmd = CMD_PATH + verb;
demo = DEMO_PATH + verb;
test = TEST_PATH + verb;

if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test))
if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test) || cmd_ob = load_object(demo))
{
return (int)cmd_ob->main(this_object(), arg);
}
Expand All @@ -32,3 +33,8 @@ int command_hook(string arg)
return notify_fail("指令不存在,你可以输入 tutorial 寻求帮助。\n");
}
}

void net_dead()
{
destruct();
}

0 comments on commit 6038a30

Please sign in to comment.