336 lines
12 KiB
Python
336 lines
12 KiB
Python
// 计分板模块扩展插件
|
||
// 忽略假人分数
|
||
// **请勿修改文件名!!**
|
||
global_app_version = '1.0-beta.8';
|
||
|
||
__config() -> {
|
||
'scope' -> 'global',
|
||
'requires' -> {
|
||
'carpet' -> '>=1.4.45',
|
||
'minecraft' -> '>=1.17'
|
||
},
|
||
'command_permission' -> 4,
|
||
'commands' -> {
|
||
'' -> 'help',
|
||
'help' -> 'help',
|
||
'delete_old <delete_old>' -> 'delete_old',
|
||
'update_from <update_from>' -> 'update_from',
|
||
'restore_from_stats' -> 'restore_from_stats',
|
||
'recalculate_total' -> 'recalculate_total_scores',
|
||
'commandPlayer <boolean>' -> 'command_player'
|
||
},
|
||
'arguments' -> {
|
||
'boolean' -> {
|
||
'type' -> 'bool'
|
||
},
|
||
'update_from' -> {
|
||
'type' -> 'term',
|
||
'suggest' -> [
|
||
'2.x',
|
||
'3.0-beta.4',
|
||
'3.0-beta.9',
|
||
'3.0-beta.10'
|
||
]
|
||
},
|
||
'delete_old' -> {
|
||
'type' -> 'term',
|
||
'suggest' -> [
|
||
'2.x',
|
||
'3.0-beta.4',
|
||
'3.0-beta.9',
|
||
'3.0-beta.10'
|
||
]
|
||
}
|
||
}
|
||
};
|
||
|
||
__on_start() -> (
|
||
global_team_cache = read_file('team_cache', 'json');
|
||
if(global_team_cache == null, // carpet 1.4.69 兼容
|
||
global_team_cache = {};
|
||
);
|
||
print(player('all'), 'fzsd_score.sc已加载!');
|
||
);
|
||
|
||
__on_close() -> (
|
||
delete_file('team_cache', 'json');
|
||
write_file('team_cache', 'json', global_team_cache);
|
||
);
|
||
|
||
__on_player_connects(player) -> (
|
||
player_type = player ~ 'player_type';
|
||
player_team = player ~ 'team';
|
||
player_name = player ~ 'name';
|
||
if(player_type == 'fake' && player_team != 'fzsd.module.scoreboard.fake',
|
||
(
|
||
global_team_cache:player_name = player_team;
|
||
team_add('fzsd.module.scoreboard.fake', player);
|
||
),
|
||
player_type == 'shadow' && player_team != 'fzsd.module.scoreboard.shadow',
|
||
(
|
||
global_team_cache:player_name = player_team;
|
||
team_add('fzsd.module.scoreboard.shadow', player);
|
||
),
|
||
try_restore_team_from_cache(player);
|
||
);
|
||
);
|
||
|
||
__on_player_disconnects(player, reason) -> (
|
||
try_restore_team_from_cache(player);
|
||
);
|
||
|
||
try_restore_team_from_cache(player) -> (
|
||
player_team = player ~ 'team';
|
||
player_name = player ~ 'name';
|
||
debug('restore_team_from_cache');
|
||
if(player_team == 'fzsd.module.scoreboard.fake'
|
||
|| player_team == 'fzsd.module.scoreboard.shadow',
|
||
if(global_team_cache:player_name == null,
|
||
(
|
||
team_leave(player);
|
||
),
|
||
team_add(global_team_cache:player_name , player);
|
||
delete(global_team_cache:player_name);
|
||
);
|
||
);
|
||
);
|
||
|
||
help() -> (
|
||
print('暂未开发');
|
||
return();
|
||
);
|
||
|
||
delete_old(fzsd_version) -> (
|
||
if(fzsd_version == '3.0-beta.10',
|
||
(
|
||
scoreboard_remove('fzsd.module.scoreboard.display.bedrock_broke_count');
|
||
team_remove('fzsd.module.scoreboard.display.bedrock_broke_count');
|
||
),
|
||
fzsd_version == '3.0-beta.9',
|
||
(
|
||
scoreboard_remove('fzsd.extra.bbl.display');
|
||
),
|
||
fzsd_version == '2.x',
|
||
(
|
||
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'];
|
||
team_remove('carpetBot');
|
||
team_remove('shadowedPlayer');
|
||
for(old_scoreboards, scoreboard_remove(_));
|
||
),
|
||
fzsd_version == '3.0-beta.4',
|
||
(
|
||
old_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', 'fz.module.scoreboard.display.placement_count', 'fz.module.scoreboard.assign.general', 'fz.module.scoreboard.display.general', 'fz.module.scoreboard.interactor'];
|
||
team_remove('fz.module.scoreboard.fake');
|
||
team_remove('fz.module.scoreboard.shadow');
|
||
for(old_scoreboards, scoreboard_remove(_));
|
||
),
|
||
print('参数错误!');
|
||
return();
|
||
);
|
||
print('已清除旧版计分板!');
|
||
return();
|
||
);
|
||
|
||
update_from(fzsd_version) -> (
|
||
if(fzsd_version == '3.0-beta.10',
|
||
(
|
||
merge_score('fzsd.module.scoreboard.display.bedrock_broke_count', 'fzsd.module.scoreboard.display.bedrock_broken_count', fzsd_version);
|
||
delete_old(fzsd_version);
|
||
scoreboard_remove('fzsd.module.scoreboard.display.placement_count', '总放置方块数');
|
||
team_add('fzsd.module.scoreboard.display.bedrock_broken_count');
|
||
),
|
||
fzsd_version == '3.0-beta.9',
|
||
(
|
||
merge_score('fzsd.extra.bbl.display', 'fzsd.module.scoreboard.display.bedrock_broken_count', fzsd_version);
|
||
delete_old(fzsd_version);
|
||
),
|
||
fzsd_version == '2.x',
|
||
(
|
||
params = [
|
||
['activation', 'fzsd.module.scoreboard.display.activation'],
|
||
['damageTaken', 'fzsd.module.scoreboard.display.damage_taken'],
|
||
['deathCounter', 'fzsd.module.scoreboard.display.death_count'],
|
||
['digCounter', 'fzsd.module.scoreboard.display.dig_count'],
|
||
['fishingCounter', 'fzsd.module.scoreboard.display.fishing_count'],
|
||
['killCounter', 'fzsd.module.scoreboard.display.kill_count'],
|
||
['tradingCounter', 'fzsd.module.scoreboard.display.trade_count'],
|
||
['bedrockBreaked', 'fzsd.module.scoreboard.display.bedrock_broken_count'],
|
||
['fz.aviate1m', 'fzsd.module.scoreboard.display.aviating_distance']
|
||
];
|
||
for(params, merge_score(..._, fzsd_version));
|
||
delete_old(fzsd_version);
|
||
),
|
||
fzsd_version == '3.0-beta.4',
|
||
(
|
||
params = [
|
||
['fz.module.scoreboard.display.activation', 'fzsd.module.scoreboard.display.activation'],
|
||
['fz.module.scoreboard.display.damage_taken', 'fzsd.module.scoreboard.display.damage_taken'],
|
||
['fz.module.scoreboard.display.death_count', 'fzsd.module.scoreboard.display.death_count'],
|
||
['fz.module.scoreboard.display.dig_count', 'fzsd.module.scoreboard.display.dig_count'],
|
||
['fz.module.scoreboard.display.fishing_count', 'fzsd.module.scoreboard.display.fishing_count'],
|
||
['fz.module.scoreboard.display.kill_count', 'fzsd.module.scoreboard.display.kill_count'],
|
||
['fz.module.scoreboard.display.trade_count', 'fzsd.module.scoreboard.display.trade_count'],
|
||
['fz.module.scoreboard.display.bedrock_broke_count', 'fzsd.module.scoreboard.display.bedrock_broken_count'],
|
||
['fz.module.scoreboard.display.aviating_distance', 'fzsd.module.scoreboard.display.aviating_distance'],
|
||
['fz.module.scoreboard.display.placement_count', 'fzsd.module.scoreboard.display.placement_count']
|
||
];
|
||
for(params, merge_score(..._, fzsd_version));
|
||
delete_old(fzsd_version);
|
||
),
|
||
print('参数错误!');
|
||
return();
|
||
);
|
||
recalculate_total_scores();
|
||
print('已从' + fzsd_version + '升级!');
|
||
return();
|
||
);
|
||
|
||
merge_score(from, to, fzsd_version) -> (
|
||
// 如果目标计分板不存在则创建
|
||
if(scoreboard() ~ to == null, scoreboard_add(to));
|
||
|
||
// new_players = [];
|
||
|
||
if(fzsd_version == '2.x',
|
||
(
|
||
// 2.x数据包的假人列表
|
||
fake_players = team_list('carpetBot');
|
||
|
||
// 新数据包的计分板中存储的玩家列表
|
||
new_players = scoreboard('fzsd.module.interactor.trigger');
|
||
|
||
for(fake_players, delete(new_players, _));
|
||
),
|
||
fzsd_version == '3.0-beta.4',
|
||
(
|
||
new_players = scoreboard('fz.module.interactor.trigger');
|
||
)
|
||
);
|
||
|
||
for(scoreboard(from),
|
||
if(!(_ ~ '\\W'),
|
||
scoreboard(to, _, scoreboard(to, _) + scoreboard(from, _));
|
||
);
|
||
);
|
||
|
||
print('已合并:' + to);
|
||
return();
|
||
);
|
||
|
||
// 因为新计分板允许玩家自定义显示的总榜名称,故续做复杂判断才能使脚本确定之
|
||
get_total_score_name_new(scoreboard) -> (
|
||
INT_MIN = -2147483648;
|
||
// 获取系统总榜id
|
||
system_total_name = replace(scoreboard, 'display', 'total');
|
||
|
||
|
||
// 将系统总榜分数加上最小int值,使其成为最低分
|
||
scoreboard(
|
||
'fzsd.module.scoreboard.assign.general',
|
||
system_total_name,
|
||
scoreboard(
|
||
'fzsd.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 = _;
|
||
)
|
||
);
|
||
);
|
||
|
||
// 恢复总榜分数
|
||
scoreboard(
|
||
'fzsd.module.scoreboard.assign.general',
|
||
system_total_name,
|
||
scoreboard(
|
||
'fzsd.module.scoreboard.assign.general',
|
||
system_total_name
|
||
) - INT_MIN
|
||
);
|
||
display_total_score(scoreboard);
|
||
|
||
// 返回榜内最低分的名称
|
||
return(last_min_player);
|
||
);
|
||
|
||
recalculate_total_scores() -> (
|
||
scoreboards = [
|
||
'fzsd.module.scoreboard.display.activation',
|
||
'fzsd.module.scoreboard.display.damage_taken',
|
||
'fzsd.module.scoreboard.display.death_count',
|
||
'fzsd.module.scoreboard.display.dig_count',
|
||
'fzsd.module.scoreboard.display.fishing_count',
|
||
'fzsd.module.scoreboard.display.kill_count',
|
||
'fzsd.module.scoreboard.display.trade_count',
|
||
'fzsd.module.scoreboard.display.bedrock_broken_count',
|
||
'fzsd.module.scoreboard.display.placement_count',
|
||
'fzsd.module.scoreboard.display.aviating_distance'
|
||
];
|
||
for(scoreboards,recalculate_total_score(_, get_total_score_name_new(_)));
|
||
print('已重新计算总分!');
|
||
return();
|
||
);
|
||
|
||
recalculate_total_score(scoreboard, total_score_name_new) -> (
|
||
// 计算总分
|
||
total_score = 0;
|
||
for(scoreboard(scoreboard),
|
||
if(_ != total_score_name_new,
|
||
total_score += scoreboard(scoreboard, _);
|
||
);
|
||
);
|
||
// 赋值总分到系统总分计分板
|
||
scoreboard(
|
||
'fzsd.module.scoreboard.assign.general',
|
||
replace(scoreboard, 'display', 'total'),
|
||
total_score
|
||
);
|
||
display_total_score(scoreboard);
|
||
return();
|
||
);
|
||
|
||
display_total_score(scoreboard) -> (
|
||
// 获取计算总榜的函数标签名
|
||
str_1 = split('\\.', scoreboard);
|
||
function_name = str_1:(length(str_1) - 1);
|
||
// 运行函数,将分数赋值到显示计分板上
|
||
run('function #fzsd:module/scoreboard/assign/scoreboard/general/' + function_name);
|
||
return();
|
||
);
|
||
|
||
restore_from_stats() -> (
|
||
print('暂未开发');
|
||
return();
|
||
);
|
||
|
||
merge_stat(scoreboard, ...stats) -> (
|
||
print('暂未开发');
|
||
return();
|
||
);
|
||
|
||
command_player(boolean) -> (
|
||
print(run('carpet setDefault commandPlayer ' + str(boolean)):1:0);
|
||
);
|
||
|
||
// 工具函数
|
||
|
||
contains(list, value) -> (
|
||
return(list ~ value != null);
|
||
);
|
||
|
||
debug(msg) -> (
|
||
logger('debug', msg);
|
||
return();
|
||
); |