add career config & fix

Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
方而静 2023-08-25 12:34:41 +08:00
parent 7871ba9f98
commit 8acd57c49b
Signed by: szTom
GPG Key ID: 072D999D60C6473C
5 changed files with 142 additions and 26 deletions

View File

@ -10,6 +10,17 @@ __config() -> {
},
};
import('ica-libs', 'shuffleList', 'countCareer');
__on_start() -> (
if(nbt_storage('ica:data'):'Goals' == null, (
nbt_storage('ica:data', '{Goals: [], Started: 0b, Preparing: 0b}')
));
if(nbt_storage('ica:careers'):'Config' == null, (
nbt_storage('ica:careers', '{Config: [], Participants: []}')
))
);
clearBossbars() -> (
run('bossbar remove ica:prepare_counter');
run('bossbar remove ica:time_counter');
@ -26,11 +37,18 @@ createBossbar(nid, name, val, sty) -> (
if(sty != null, bossbar(nid, 'style', sty));
);
__on_player_dies(p) -> (
if(nbt_storage('ica:data'):'Started'
&& !nbt_storage('ica:data'):'Preparing', (
modify(p, 'gamemode', 'spectator');
modify(p, 'tag', 'ica.deceased');
));
);
__on_player_connects(p) -> (
if(nbt_storage('ica:data'):'Started'
&& query(p, 'has_scoreboard_tag', 'ica.deceased'), (
modify(p, 'gamemode', 'spectator');
));
);
@ -65,7 +83,7 @@ endTimeout(iv) -> (
endGameTitle(getPigPlayers(), 'Timeout!'
, str('You didn\'t complete %d goals in time.', iv));
endGameTitle(getWolfPlayers(), 'You won!'
, str('Those fools have failed, haha.', iv));
, str('Those fools have failed, good job.', iv));
);
endFinish() -> (
@ -153,12 +171,6 @@ playerInit(p) -> (
inventory_set(p, 2, 1, 'minecraft:spyglass');
);
__on_start() -> (
if(nbt_storage('ica:data'):'Goals' == null, (
nbt_storage('ica:data', '{Goals: [], Started: 0b, Preparing: 0b}')
))
);
cmdResetClear() -> (
clearBossbars();
put(nbt_storage('ica:data'):'Started', '0b');
@ -196,6 +208,16 @@ cmdStart() -> (
print('Already started, use /ica-admin reset clear to cancel.');
return(false)
));
participants_list = player('all');
participants_list = shuffleList(participants_list);
wolf_n = countCareer('wolf');
hunter_n = countCareer('hunter') + wolf_n;
if(hunter_n > length(participants_list), (
print('Not enough players online.');
return(false);
));
put(nbt_storage('ica:data'):'Started', '1b');
put(nbt_storage('ica:data'):'Preparing', '1b');
put(nbt_storage('ica:data'):'Goals[].Completed', '0b');
@ -206,17 +228,20 @@ cmdStart() -> (
for(player('all'), modify(_, 'clear_tag', ['ica.piggy'
, 'ica.wolf', 'ica.hunter', 'ica.spyglasser', 'ica.spyglass_fireball'
, 'ica.voter', 'ica.flyer']));
, 'ica.voter', 'ica.flyer', 'ica.spyglasser_cooldown'
, 'ica.coordinator', 'ica.deceased']));
player_n = length(player('all'));
wolf_id = floor(rand(player_n));
for(player('all'), (
for(participants_list, (
modify(_, 'tag', ['ica.voter', 'ica.flyer']);
modify(_, 'tag', if(_i == wolf_id, ['ica.wolf', 'ica.spyglasser'], 'ica.piggy'));
career_tag = 'ica.piggy';
if(_i < hunter_n, career_tag = ['ica.hunter', 'ica.spyglasser', 'ica.spyglasser_cooldown']);
if(_i < wolf_n, career_tag = ['ica.wolf', 'ica.spyglasser', 'ica.coordinator']);
modify(_, 'tag', career_tag);
));
run('execute as @a run clear');
for(player('all'), playerInit(_));
for(participants_list, playerInit(_));
run('ica-effect-applier enable');
run('time set day');

View File

@ -1,4 +1,6 @@
shoot_fireball(myself, rm) -> (
global_lastUseSpyglass = -1000;
shootFireball(myself, rm) -> (
playerPos = query(myself, 'pos') + l(0, query(myself, 'eye_height'), 0); // Set the position where the fireball will spawn
playerM = query(myself, 'motion');
@ -16,15 +18,28 @@ shoot_fireball(myself, rm) -> (
__on_player_uses_item(myself, item_tuple, hand) -> (
if(item_tuple:0 == 'fire_charge',
shoot_fireball(myself, true);
shootFireball(myself, true);
);
);
__on_player_releases_item(myself, item_tuple, hand) -> (
shootFireballSpyglass(myself) -> (
if(!query(myself, 'has_scoreboard_tag', 'ica.spyglass_fireball'), (
return();
return(null);
));
nowTT = tick_time();
dt = nowTT - global_lastUseSpyglass;
if(query(myself, 'has_scoreboard_tag', 'ica.spyglasser_cooldown')
&& dt < 200, (
print(str('spyglass too hot, please wait another %.2f seconds to shoot again.'
, (200 - dt) / 20.0));
return(null);
));
shootFireball(myself, false);
global_lastUseSpyglass = nowTT;
);
__on_player_releases_item(myself, item_tuple, hand) -> (
if(item_tuple:0 == 'spyglass',
shoot_fireball(myself, false);
shootFireballSpyglass(myself);
);
);

26
src/ica-libs.sc Normal file
View File

@ -0,0 +1,26 @@
__config() -> {
'scope' -> 'global',
'exports' -> ['shuffleList', 'countCareer']
};
shuffleList(list) -> (
if (length(list) <= 1, list,
c_for(i = length(list) - 1, i >= 1, i = i - 1,
random_index = floor(rand(i + 1));
// swap elements
temp = list:i;
list:i = list:random_index;
list:random_index = temp;
);
list
)
);
countCareer(cartype) -> (
if(nbt_storage('ica:careers'):str('Config[{Type: "%s"}]', cartype) == null, (
0
),
nbt_storage('ica:careers'):str('Config[{Type: "%s"}].Count', cartype)
)
);

View File

@ -6,14 +6,20 @@ __config() -> {
'list' -> 'cmdList',
'set <slot> <item>' -> 'cmdSet',
'add <item>' -> 'cmdSetAppend',
'career' -> 'cmdListCareers',
'career <career_type> <amount>' -> 'cmdConfigCareer',
},
'arguments' -> {
'slot' -> { 'type' -> 'int', 'min' -> 0, 'max' -> 5
, 'suggest' -> [0, 1, 2, 3, 4, 5] },
'item' -> { 'type' -> 'item' }
}
'item' -> { 'type' -> 'item' },
'career_type' -> { 'type' -> 'string', 'options' -> [ 'wolf', 'hunter' ] },
'amount' -> { 'type' -> 'int', 'min' -> 0, 'suggest' -> [1] },
},
};
import('ica-libs', 'countCareer');
getFirstUnsetGoal() -> (
c_for(i = 0, i <= 5, i = i + 1, (
p = nbt_storage('ica:data'):str('Goals[{Slot: %db}]', i);
@ -47,6 +53,26 @@ cmdSetAppend(goal_item_tuple) -> (
if(missing_goal <= 5, (
cmdSet(missing_goal, goal_item_tuple)
), (
print('All are goals set, please specify slot.')
print('All are goals set, please use /ica-settings set <slot> <item>.')
));
);
cmdListCareers() -> (
print('Career configs are:');
print(str(' - Wolf: %d participants.', countCareer('wolf')));
print(str(' - Hunter: %d participants.', countCareer('hunter')));
print(' - Piggy: Whatever the rest.');
);
cmdConfigCareer(cartype, ccount) -> (
if(nbt_storage('ica:data'):'Started', (
print('Already started, use /ica-admin reset clear to cancel.');
return(false)
));
pkey = str('Config[{Type: "%s"}].Count', cartype);
etag = nbt(str('{Type: "%s", Count: %db}', cartype, ccount));
if(nbt_storage('ica:careers'):pkey != null, delete(nbt_storage('ica:careers'):pkey));
put(nbt_storage('ica:careers'), 'Config', etag, -1);
print(str('Career %s set to %d participants.', cartype, ccount))
);

View File

@ -1,5 +1,4 @@
__config() -> {
'command_permission' -> 'ops',
'commands' -> {
'' -> 'cmdList',
'list' -> 'cmdList',
@ -7,11 +6,12 @@ __config() -> {
'refill' -> 'cmdRefill',
'seed' -> 'cmdSeed',
'me' -> 'cmdMe',
'locate <participant>' -> 'cmdLocate',
},
'arguments' -> {
'slot' -> { 'type' -> 'int', 'min' -> 0, 'max' -> 5
, 'suggest' -> [0, 1, 2, 3, 4, 5] },
'item' -> { 'type' -> 'item' }
'participant' -> { 'type' -> 'players' },
}
};
@ -23,6 +23,27 @@ tm_per_goal() -> (
12000
);
cmdLocate(pname) -> (
if(!nbt_storage('ica:data'):'Started', (
print('Not started. use /ica-admin confirm to start.');
return(false)
));
if(!query(player(), 'has_scoreboard_tag', 'ica.coordinator'), (
print('You don\'t have this ability.');
return(false)
));
p = player(pname:0);
ppos = query(p, 'pos');
pdim = query(p, 'dimension');
mydim = query(player(), 'dimension');
if(pdim == mydim, (
print(str('%s: %.1f %.1f %.1f.', pdim, ppos:0, ppos:1, ppos:2));
), (
print(str('%s: ? ? ?', pdim));
));
);
cmdSeed() -> (
print(str('%s: %d', system_info('world_name'), system_info('world_seed')));
);
@ -32,7 +53,7 @@ cmdRefill() -> (
print('Not started. use /ica-admin confirm to start.');
return(false)
));
if(!query(p, 'has_scoreboard_tag', 'ica.flyer'), (
if(!query(player(), 'has_scoreboard_tag', 'ica.flyer'), (
print('You cannot fly.');
return(false)
));
@ -93,7 +114,7 @@ cmdMe() -> (
print('[ability] voter: you can vote.');
));
if(query(myself, 'has_scoreboard_tag', 'ica.flyer'), (
print('[ability] flyer: you can fly with an elt.');
print('[ability] flyer: you can fly with an elytra.');
));
if(query(myself, 'has_scoreboard_tag', 'ica.spyglasser'), (
print('[ability] spyglasser: You can shoot fireballs with a spyglass(except in prepare stage).');
@ -101,6 +122,9 @@ cmdMe() -> (
// if(query(myself, 'has_scoreboard_tag', 'ica.kungfu_master'), (
// print('[ability] kungfu master: You can get a temporary slow-falling effect by using a feather.');
// ));
if(query(myself, 'has_scoreboard_tag', 'ica.coordinator'), (
print('[ability] coordinator: you can locate other participants.');
));
);
cmdSubmit(slot_id) -> (