2022-07-26 07:57:04 +08:00
|
|
|
|
// 计分板模块扩展插件
|
|
|
|
|
// 忽略假人分数
|
|
|
|
|
// **请勿修改文件名!!**
|
2022-07-30 16:34:38 +08:00
|
|
|
|
global_app_version = '1.0-beta.4';
|
2022-07-26 07:57:04 +08:00
|
|
|
|
|
|
|
|
|
__config() -> {
|
|
|
|
|
'scope' -> 'global',
|
|
|
|
|
'requires' -> {
|
|
|
|
|
'carpet' -> '>=1.4.45',
|
|
|
|
|
'minecraft' -> '>=1.17'
|
|
|
|
|
},
|
|
|
|
|
'command_permission' -> 4,
|
|
|
|
|
'commands' -> {
|
|
|
|
|
'' -> 'help',
|
|
|
|
|
'help' -> 'help',
|
|
|
|
|
'delete_old' -> 'delete_old',
|
|
|
|
|
'merge_old' -> 'restore_merge_old',
|
|
|
|
|
'restore_from_stats' -> 'restore_from_stats',
|
|
|
|
|
'recalculate_total' -> 'recalculate_total_scores'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
__on_start() -> (
|
|
|
|
|
global_team_cache = read_file('team_cache', 'json');
|
|
|
|
|
debug(global_team_cache);
|
2022-07-30 16:34:38 +08:00
|
|
|
|
print(player('all'), 'fzsd_score.sc已加载!');
|
2022-07-26 07:57:04 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
__on_close() -> (
|
|
|
|
|
debug(global_team_cache);
|
|
|
|
|
delete_file('team_cache', 'json');
|
|
|
|
|
write_file('team_cache', 'json', global_team_cache);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
__on_player_connects(player) -> (
|
|
|
|
|
debug(player ~ 'name');
|
|
|
|
|
debug(player ~ 'player_type');
|
|
|
|
|
debug(player ~ 'team');
|
|
|
|
|
debug(global_team_cache);
|
|
|
|
|
if(player ~ 'player_type' == 'fake' && player ~ 'team' != 'fz.module.scoreboard.fake',
|
|
|
|
|
(
|
|
|
|
|
debug('1~');
|
|
|
|
|
global_team_cache:(player ~ 'name') = player ~ 'team';
|
|
|
|
|
debug(global_team_cache);
|
|
|
|
|
team_add('fz.module.scoreboard.fake', player);
|
|
|
|
|
),
|
|
|
|
|
player ~ 'player_type' == 'shadow' && player ~ 'team' != 'fz.module.scoreboard.shadow',
|
|
|
|
|
(
|
|
|
|
|
debug('2~');
|
|
|
|
|
global_team_cache:(player ~ 'name') = player ~ 'team';
|
|
|
|
|
team_add('fz.module.scoreboard.shadow', player);
|
|
|
|
|
),
|
|
|
|
|
try_restore_team_from_cache(player);
|
|
|
|
|
);
|
|
|
|
|
debug(global_team_cache);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
__on_player_disconnects(player, reason) -> (
|
|
|
|
|
debug(player ~ 'name');
|
|
|
|
|
debug(player ~ 'player_type');
|
|
|
|
|
debug(player ~ 'team');
|
|
|
|
|
debug(global_team_cache);
|
|
|
|
|
try_restore_team_from_cache(player);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
try_restore_team_from_cache(player) -> (
|
|
|
|
|
debug('restore_team_from_cache');
|
|
|
|
|
if(player ~ 'team' == 'fz.module.scoreboard.fake'
|
|
|
|
|
|| player ~ 'team' == 'fz.module.scoreboard.shadow',
|
|
|
|
|
debug(global_team_cache);
|
|
|
|
|
if(global_team_cache:(player ~ 'name') == null,
|
|
|
|
|
(
|
|
|
|
|
debug('global_team_cache:(player ~ \'name\') == null');
|
|
|
|
|
team_leave(player);
|
|
|
|
|
),
|
|
|
|
|
debug('global_team_cache:(player ~ \'name\') != null');
|
|
|
|
|
team_add(global_team_cache:(player ~ 'name') , player);
|
|
|
|
|
delete(global_team_cache:(player ~ 'name'));
|
|
|
|
|
);
|
|
|
|
|
);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
help() -> (
|
|
|
|
|
print('这是一条帮助');
|
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
delete_old() -> (
|
|
|
|
|
old_scoreboards = [
|
|
|
|
|
'usedDiaAxe', 'usedDiaPickaxe', 'usedDiaShovel', 'usedDiaHoe', 'usedIroAxe', 'usedIroPickaxe',
|
|
|
|
|
'usedIroShovel', 'usedIroHoe', 'usedStoAxe', 'usedStoPickaxe', 'usedStoShovel', 'usedStoHoe',
|
|
|
|
|
'usedWooAxe', 'usedWooPickaxe', 'usedWooShovel', 'usedWooHoe', 'usedGolAxe', 'usedGolPickaxe',
|
|
|
|
|
'usedGolShovel', 'usedGolHoe', 'usedNetAxe', 'usedNetPickaxe', 'usedNetShovel', 'usedNetHoe',
|
|
|
|
|
'usedShears', 'damageTaken', '10xDamageTaken', 'deathCounter', 'deathTester', 'digCounter',
|
|
|
|
|
'fishingCounter', 'fishingTester', 'killCounter', 'tradingCounter', 'totalList',
|
|
|
|
|
'bedrockBreaked', 'fz.bbl', 'fz.aviate1m', 'fz.aviateCounter', 'fz.aviateOneTime', 'Health',
|
|
|
|
|
'carpetBot', 'parameter'
|
|
|
|
|
];
|
|
|
|
|
for(old_scoreboards, scoreboard_remove(_));
|
|
|
|
|
team_remove('carpetBot');
|
|
|
|
|
team_remove('shadowedPlayer');
|
|
|
|
|
print('已清除旧版计分板!');
|
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
restore_merge_old() -> (
|
2022-07-26 08:15:36 +08:00
|
|
|
|
|
2022-07-26 07:57:04 +08:00
|
|
|
|
merge_score('activation', 'fz.module.scoreboard.display.activation');
|
|
|
|
|
merge_score('damageTaken', 'fz.module.scoreboard.display.damage_taken');
|
|
|
|
|
merge_score('deathCounter', 'fz.module.scoreboard.display.death_count');
|
|
|
|
|
merge_score('digCounter', 'fz.module.scoreboard.display.dig_count');
|
|
|
|
|
merge_score('fishingCounter', 'fz.module.scoreboard.display.fishing_count');
|
|
|
|
|
merge_score('killCounter', 'fz.module.scoreboard.display.kill_count');
|
|
|
|
|
merge_score('tradingCounter', 'fz.module.scoreboard.display.trade_count');
|
|
|
|
|
merge_score('bedrockBreaked', 'fz.module.scoreboard.display.bedrock_broke_count');
|
|
|
|
|
merge_score('fz.aviate1m', 'fz.module.scoreboard.display.aviating_distance');
|
|
|
|
|
// restore_score('fz.module.scoreboard.display.placement_count', );
|
|
|
|
|
|
|
|
|
|
// 清除旧计分板
|
|
|
|
|
delete_old();
|
|
|
|
|
|
|
|
|
|
print('完成!');
|
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
merge_score(from, to) -> (
|
|
|
|
|
// 如果目标计分板不存在则创建
|
|
|
|
|
if(scoreboard() ~ to == null, scoreboard_add(to));
|
|
|
|
|
|
|
|
|
|
// 旧版数据包的假人列表
|
|
|
|
|
fake_players = team_list('carpetBot');
|
|
|
|
|
|
|
|
|
|
// 新数据包的计分板中存储的玩家列表
|
|
|
|
|
new_players = scoreboard('fz.module.interactor.trigger');
|
|
|
|
|
debug('2' + new_players);
|
|
|
|
|
for(scoreboard(from),
|
|
|
|
|
debug('3' + _);
|
|
|
|
|
debug('3.1' + contains(fake_players, _));
|
|
|
|
|
debug('3.2' + contains(new_players, _));
|
|
|
|
|
debug('3.3' + str(_ != total_name_old));
|
|
|
|
|
debug('3.4' + str((!contains(fake_players, _)
|
|
|
|
|
|| contains(new_players, _)
|
2022-07-30 16:34:38 +08:00
|
|
|
|
) && !(_ ~ '\\W')));
|
2022-07-26 07:57:04 +08:00
|
|
|
|
if((!contains(fake_players, _)
|
|
|
|
|
|| contains(new_players, _)
|
2022-07-30 16:34:38 +08:00
|
|
|
|
) && !(_ ~ '\\W'),
|
2022-07-26 07:57:04 +08:00
|
|
|
|
debug('4' + _);
|
|
|
|
|
debug('from' + scoreboard(from, _));
|
|
|
|
|
debug('to' + scoreboard(to, _));
|
|
|
|
|
scoreboard(to, _, scoreboard(to, _) + scoreboard(from, _));
|
|
|
|
|
);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 重新计算总分
|
|
|
|
|
recalculate_total_score(to, get_total_score_name_new(to));
|
|
|
|
|
|
|
|
|
|
print('已合并:' + to);
|
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 因为新计分板允许玩家自定义显示的总榜名称,故续做复杂判断才能使脚本确定之
|
|
|
|
|
get_total_score_name_new(scoreboard) -> (
|
|
|
|
|
INT_MIN = -2147483648;
|
|
|
|
|
// 获取系统总榜id
|
|
|
|
|
system_total_name = replace(scoreboard, 'display', 'total');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将系统总榜分数加上最小int值,使其成为最低分
|
|
|
|
|
scoreboard(
|
|
|
|
|
'fz.module.scoreboard.assign.general',
|
|
|
|
|
system_total_name,
|
|
|
|
|
scoreboard(
|
|
|
|
|
'fz.module.scoreboard.assign.general',
|
|
|
|
|
system_total_name
|
|
|
|
|
) + INT_MIN
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 将总分赋值到显示计分板上
|
|
|
|
|
display_total_score(scoreboard);
|
|
|
|
|
|
|
|
|
|
// 查找榜内最低分
|
|
|
|
|
last_min_player = null;
|
|
|
|
|
for(scoreboard(scoreboard),
|
|
|
|
|
if(last_min_player == null,
|
|
|
|
|
(
|
|
|
|
|
last_min_player = _;
|
|
|
|
|
),
|
|
|
|
|
if(scoreboard(scoreboard, _) < scoreboard(scoreboard, last_min_player),
|
|
|
|
|
last_min_player = _;
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
debug(_);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 恢复总榜分数
|
|
|
|
|
scoreboard(
|
|
|
|
|
'fz.module.scoreboard.assign.general',
|
|
|
|
|
system_total_name,
|
|
|
|
|
scoreboard(
|
|
|
|
|
'fz.module.scoreboard.assign.general',
|
|
|
|
|
system_total_name
|
|
|
|
|
) - INT_MIN
|
|
|
|
|
);
|
|
|
|
|
display_total_score(scoreboard);
|
|
|
|
|
|
|
|
|
|
// 返回榜内最低分的名称
|
|
|
|
|
return(last_min_player);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
recalculate_total_scores() -> (
|
2022-07-26 08:15:36 +08:00
|
|
|
|
scoreboards = [
|
|
|
|
|
'fz.module.scoreboard.display.activation',
|
|
|
|
|
'fz.module.scoreboard.display.damage_taken',
|
|
|
|
|
'fz.module.scoreboard.display.death_count',
|
|
|
|
|
'fz.module.scoreboard.display.dig_count',
|
|
|
|
|
'fz.module.scoreboard.display.fishing_count',
|
|
|
|
|
'fz.module.scoreboard.display.kill_count',
|
|
|
|
|
'fz.module.scoreboard.display.trade_count',
|
|
|
|
|
'fz.module.scoreboard.display.bedrock_broke_count',
|
|
|
|
|
'fz.module.scoreboard.display.aviating_distance'
|
|
|
|
|
];
|
|
|
|
|
for(scoreboards,recalculate_total_score(_, get_total_score_name_new(_)));
|
|
|
|
|
print('完成!');
|
2022-07-26 07:57:04 +08:00
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
recalculate_total_score(scoreboard, total_score_name_new) -> (
|
|
|
|
|
// 计算总分
|
|
|
|
|
total_score = 0;
|
|
|
|
|
for(scoreboard(scoreboard),
|
|
|
|
|
if(_ != total_score_name_new,
|
|
|
|
|
total_score += scoreboard(scoreboard, _);
|
|
|
|
|
);
|
|
|
|
|
);
|
|
|
|
|
// 赋值总分到系统总分计分板
|
|
|
|
|
scoreboard(
|
|
|
|
|
'fz.module.scoreboard.assign.general',
|
|
|
|
|
replace(scoreboard, 'display', 'total'),
|
|
|
|
|
total_score
|
|
|
|
|
);
|
|
|
|
|
display_total_score(scoreboard);
|
2022-07-26 08:15:36 +08:00
|
|
|
|
print('已重新计算总分:' + scoreboard);
|
2022-07-26 07:57:04 +08:00
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
display_total_score(scoreboard) -> (
|
|
|
|
|
// 获取计算总榜的函数标签名
|
|
|
|
|
str_1 = split('\\.', scoreboard);
|
|
|
|
|
function_name = str_1:(length(str_1) - 1);
|
|
|
|
|
// 运行函数,将分数赋值到显示计分板上
|
|
|
|
|
run('function #fz:module/scoreboard/assign/scoreboard/general/' + function_name);
|
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
restore_from_stats() -> (
|
2022-07-30 16:34:38 +08:00
|
|
|
|
|
2022-07-26 08:15:36 +08:00
|
|
|
|
print('暂未开发');
|
2022-07-26 07:57:04 +08:00
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
merge_stat(scoreboard, ...stats) -> (
|
2022-07-26 08:15:36 +08:00
|
|
|
|
print('暂未开发');
|
2022-07-26 07:57:04 +08:00
|
|
|
|
return(0);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
contains(list, value) -> (
|
|
|
|
|
return(list ~ value != null);
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
debug(msg) -> (
|
|
|
|
|
logger('debug', msg);
|
|
|
|
|
return(0);
|
|
|
|
|
);
|