diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e292a..84638fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ >所有可查阅的更改记录皆可在此处找到 +### v2.1.3 pre1 + +- 添加`census`地毯脚本 +- `census`脚本**不稳定**,请谨慎使用,本版本无release + ### v2.1.2 & 2.0.10 - 添加鞘翅滑翔距离榜单 [#I40PFS](https://gitee.com/harvey-husky/FZ-sDatapack/issues/I40PFS) diff --git a/census.sc b/census.sc new file mode 100644 index 0000000..0c8efd8 --- /dev/null +++ b/census.sc @@ -0,0 +1,193 @@ +// by shenjack +// write at carpet 1.16.5 1.4.31 v210407 +// with carpet-extra-1.16.5-1.4.30 +// with carpet-tis-addition-mc1.16.4-1.15.0+build.492 +// with fabric-api-0.26.0+1.16 (because on server Api Version > 0.26 will cause bug) + +global_version = '1.2.0'; +global_carpet_version = split('\\+v',system_info('scarpet_version')); +global_require_carpet_version = ['1.4.30', 210407]; +global_filename = system_info('app_name'); +global_score_path = 'census/'; + +// debug级别 +global_debug_level = 2; +// 0 -> show all message +// 1 -> show most debug +// 2 -> show all info +// 3 -> show all warn +// 4 -> show all error + +global_score = {}; +global_player_name = []; +// 分数相关初始化 + +__config() -> { + 'stay_loaded' -> true, + 'scope' -> 'global', + // 'allow_command_conflicts' -> true, + 'legacy_command_type_support' -> true, + 'requires' -> { + 'minecraft' -> '>=1.16', // best at 1.16+ haven't test in 1.15.2 and 1.14.4 + 'fabric-api' -> '>=0.26.0', // for some reason api left in 0.26.0 + 'carpet' -> '>=1.4.31' // best at 1.4.31 because fix issue of read_file() + }, + 'commands' -> { + '' -> 'help', + 'help' -> 'help', + 'reload' -> 'reload_script', + 'score load' -> 'load_scores', + 'score save' -> 'save_scores', + 'score print' -> 'print_scores', + 'debug level' -> ['debug_level', null], + 'debug level ' -> 'debug_level', + 'debug add_mine ' -> 'add_mine', + }, + 'arguments' -> { + 'player' -> { + 'type' -> 'players' + }, + 'block' -> { + 'type' -> 'string', + }, + 'debug_level' -> { + 'type' -> 'int', + 'min' -> 0, + 'max' -> 4, + 'suggest' -> [0, 1, 2, 3, 4] + } + }; +}; + +__on_close() -> ( + // 保存一些debug信息 + debug_info = {'debug_level' -> global_debug_level}; + write_file('main', 'json', debug_info); + // 保存分数 + save_scores(); +); + +printl(message, level = 2, say = false, reply = true) -> ( + if(global_debug_level <= level, + if(reply, print(message)); + if(say, run('say' + message))); +); + +debug_level(level) -> ( + if(level == null, + print('目前DEBUG等级为: ' + global_debug_level); + return(0)); + global_debug_level = level; + print('DEBUG等级已经设置为: ' + global_debug_level); + logger(type = 'info', 'DEBUG等级已经设置为: ' + global_debug_level); +); + +help() -> ( + print(format('y ' + '-'*10 + '帮助信息' + '-'*10)); + print(format('m 提醒:大部分信息都可以点击来执行相对应的命令,所以请小心点击', '^g 包括我! 点我来执行 /' + global_filename, '! /' + global_filename)); + print(format('e /' + global_filename + ' -> ', 'c 同 /' + global_filename + ' help')); + print(format('e /' + global_filename + ' help -> ', 'c 显示这条帮助信息', '^g 你就在看着我呢!', '! /' + global_filename + ' help')); + print(format('e /' + global_filename + ' reload -> ', 'c 重新加载script', '^g 获得成就:我重载我自己', '! /' + global_filename + ' reload')); + print(format('e /' + global_filename + ' score load -> ', 'c 加载各项榜单', '^rub 警告:这会覆盖游戏内的现有数据(所以请自行输入命令)')); + print(format('e /' + global_filename + ' score save -> ', 'c 保存各项榜单', '^ub 提醒:这会覆盖文件数据', '! /' + global_filename + ' score save')); + print(format('e /' + global_filename + ' score print -> ', 'c 输出各项榜单数据', '^gs 吐槽一下,scarpet的字符串处理真的麻烦死了', '! /' + global_filename + ' score print')); + print(format('e /' + global_filename + ' debug level -> ', 'c 显示DEBUG信息等级', '^g (没啥可吐槽的)', '! /' + global_filename + ' debug level')); + print(format('e /' + global_filename + ' debug level -> ', 'c 设置DEBUG信息等级为 ', '^g 为 0-4的正整数,默认为2', '?/' + global_filename + ' debug level ')); +// print(format('e /' + global_filename + ' xxx -> ', 'c xxx', '^g xxx', '! /' + global_filename + ' xxx')); + print(format('y [系统信息]' + global_filename + ' 版本: ' + global_version)); + print(format('y [系统信息]' + global_filename + ' 文件名: ' + global_filename)); + print(format('y [插件信息]' + global_filename + ' 数据存储路径: ' + global_score_path)); + print(format('e 感谢 @Harvey_Husky 延皓 的支持! script中一部分源码就来自哈姥姥!', '^g 哈姥姥真好用(', '?https://gitee.com/harvey-husky/FZ-sDatapack')); +); + +reload_script() -> ( + print('script ' + global_filename + ' 重载中···'); + run(str('script load ' + global_filename)); +); + +load_scores() -> ( + print('重新加载计分数据中···'); + global_score = {}; // 重置分数 + files = list_files(global_score_path, 'shared_json'); // 列出所有文件 + printl(files, 1, true, true); // DEBUG 输出 + for(files, + data = read_file(_, 'shared_json'); // 获取文件内json + name = split('/', _):1; // 获取文件名(玩家名称 + global_score:name = data; // 存储进计分表 + printl(data + '\n\n' + _, 1, false, true)); // DEBUG 输出 +); + +print_scores() -> ( + // 目前只会输出挖掘榜 + printl(global_score, 0, false, true); + print('§7' + '-'*10 + '挖掘榜' + '-'*10); // 输出标题 + mine = []; + max_len = 1; + // 初始化两个数据 + for(global_score, + max_len = max(max_len, length(_)); + // 如果这个名字的长度大于之前的,就把最大长度换成这个名字的 + put(mine, 0, [_, global_score:_:'mine':'total'], 'insert')); + // 把所有的数据加到mine里备用,等待排序 + mine = sort_key(mine, -_:1); // 根据每个挖掘数据的挖掘量进行排序(排序用的分数是挖掘量的倒数,这样可以倒序排列) + printl(mine, 1, false, true); + for(mine, + print(format(' ' + _:0 + ': ' + ' '*(max_len-length(_:0))+ _:1 + ' block'))); + // 依次输出数据 + +); + +save_scores() -> ( + print('计分数据保存中'); + for(global_score, + write_file(global_score_path + _, 'shared_json', global_score:_); + printl(_ + '\n' + global_score_path + _, 1, false, true)); + print('计分数据保存完毕'); +); + +make_player_score(player) -> ( + score = {'mine'-> {'total'-> 0}, + 'kill'-> {}}; // 基本信息 + put(global_score, player, score); // 加到列表里 +); + +__on_player_dies(player) -> ( + pos = query(player, 'pos'); + dim = query(player, 'dimension'); + die_pos = str('[x: %d, y:%d, z:%d]', pos); + if(dim == 'the_nether', dim = '地狱'); + if(dim == 'overworld', dim = '主世界'); + run(str('say ' + str(player) + '在' + dim + ' ' + die_pos + '死亡')); +); + +__on_player_breaks_block(player, block) -> ( + add_mine(player, block); +); + +add_mine(player, block) -> ( + block = str(block); + splayer = player ~ 'name'; + if(!player(splayer), + return()); + // 如果玩家列表里没有输入的玩家就返回 + if(!has(global_score:splayer), + make_player_score(splayer)); + // 如果榜单里没有玩家就加入玩家的榜单 + if(!has(global_score:splayer:'mine', block), + put(global_score:splayer:'mine':block, 1), + // 如果玩家的记录里没有这个方块就把这个方块加到挖掘列表里 + score = get(global_score:splayer:'mine':block); + put(global_score:splayer:'mine':block, score + 1)); + // 如果记录里有就 += 1 + full_score = get(global_score:splayer:'mine':'total'); + put(global_score:splayer:'mine':'total', full_score + 1); + // print(global_score); +); + +// 加载debug信息 +debug_info = read_file('main', 'json'); +if(debug_info, + global_debug_level = debug_info:'debug_level'); +// 基本信息初始化 +// 加载分数 +load_scores(); diff --git a/here.sc b/here.sc index 015f6f0..4876e96 100644 --- a/here.sc +++ b/here.sc @@ -1,5 +1,14 @@ __config() -> { - 'stay_loaded' -> true + 'stay_loaded' -> true, + 'commands' -> { + '' -> 'my_pos', + '' -> 'print_pos' + }, + 'arguments' -> { + 'player' -> { + 'type' -> 'players' + }, + } }; __command() -> ( s_player = player(); @@ -34,4 +43,18 @@ __command() -> ( )) ); exit() -) \ No newline at end of file +); + + +print_pos(request_player) -> ( + name = request_player ~ 'name'; + pos = query(request_player, 'pos'); + dim = query(request_player, 'dimension'); + if(dim == 'overworld', + o_dim = '主世界'; + run('say ' + name + ' 在主世界的 [x:' + pos:0 + ',y:' + pos:1 + ',z:' + pos:2 + ']向你说话')) +); + +my_pos() -> ( + print_pos(player()) +); \ No newline at end of file