Ver Fonte

多轮小游戏

LTCatt há 6 anos atrás
pai
commit
d336e6b3e2

+ 24 - 0
data/ltw/functions/main/game_end.mcfunction

@@ -0,0 +1,24 @@
+# 游戏结束,根据 total_score 判断排名,并返回主大厅
+
+# 计算排名
+tag @a remove total_rank1
+tag @a remove total_rank2
+tag @a remove total_rank3
+# 1
+scoreboard players set $t_score_max total_score -2147483648
+execute as @a run function total:main/get_max_score
+execute as @a unless entity @a[tag=total_rank1] if score @s total_score = $t_score_max total_score run tag @s add total_rank1
+# 2
+scoreboard players set $t_score_max total_score -2147483648
+execute as @a[tag=!total_rank1] run function total:main/get_max_score
+execute as @a[tag=!total_rank1] unless entity @a[tag=total_rank2] if score @s total_score = $t_score_max total_score run tag @s add total_rank2
+# 3
+scoreboard players set $t_score_max total_score -2147483648
+execute as @a[tag=!total_rank1,tag=!total_rank2] run function total:main/get_max_score
+execute as @a[tag=!total_rank1,tag=!total_rank2] unless entity @a[tag=total_rank3] if score @s total_score = $t_score_max total_score run tag @s add total_rank3
+
+# 显示排名
+tellraw @s [{"text":"\n>> 游戏结束 >>\n\n","color":"gold","bold":true},{"text": "第一名 - ","color":"green","bold": false},{"selector": "@a[tag=total_rank1]","color":"white","bold": false},{"text": "\n第二名 - ","color":"green","bold": false},{"selector": "@a[tag=total_rank2]","color":"white","bold": false},{"text": "\n第三名 - ","color":"green","bold": false},{"selector": "@a[tag=total_rank3]","color":"white","bold": false},"\n"]
+
+# 返回主大厅
+schedule function ltw:state/0/state_enter 2t replace

+ 1 - 0
data/ltw/functions/main/get_max_score.mcfunction

@@ -0,0 +1 @@
+execute if score @s total_score > $t_score_max total_score run scoreboard players operation $t_score_max total_score = @s total_score

+ 8 - 4
data/ltw/functions/state/0/start_gameparty.mcfunction

@@ -7,11 +7,15 @@ execute store result score $count mem if entity @a[tag=hub_gameparty]
 execute if score $count mem matches ..2 run tellraw @a [{"text": "需要至少 3 人以开始小游戏模式, 当前仅有 ","color":"red"},{"score": { "name": "$count","objective": "mem"}}, " 人!"]
 execute if score $count mem matches 9.. run tellraw @a [{"text": "小游戏模式最多支持 8 人, 当前已有 ","color":"red"},{"score": { "name": "$count","objective": "mem"}}, " 人!"]
 
-# 开始小游戏
+# 判断旁观
 execute if score $count mem matches 3..8 run tag @a remove watcher
 execute if score $count mem matches 3..8 run tag @a[tag=!hub_gameparty] add watcher
-execute if score $count mem matches 3..8 run function ltw:state/3/state_enter
 
-# 重置积分
-scoreboard players reset total_score
+# 重置数据
+scoreboard players reset * total_score
 scoreboard players set @a[tag=!watcher] total_score 0
+scoreboard players set $round mem 1
+scoreboard players set $game_type mem 1
+
+# 开始小游戏
+execute if score $count mem matches 3..8 run function ltw:state/3/state_enter

+ 4 - 0
data/ltw/functions/state/7/continue_gameparty.mcfunction

@@ -0,0 +1,4 @@
+# 继续下一轮小游戏
+
+scoreboard players add $round mem 1
+schedule function ltw:state/3/state_enter 2t replace

+ 3 - 1
data/ltw/functions/state/7/state_enter.mcfunction

@@ -5,4 +5,6 @@ execute as @a run function ltw:state/7/player_enter
 # HUD
 scoreboard objectives setdisplay sidebar total_score
 
-schedule function ltw:state/0/state_enter 5t replace
+# 判断进入下一轮小游戏或结束
+execute if score $game_type mem matches 1 if score $round mem matches ..2 run function ltw:state/7/continue_gameparty
+execute if score $game_type mem matches 1 if score $round mem matches 3.. run function ltw:main/game_end

+ 2 - 0
data/test/functions/start_hotpm.mcfunction

@@ -1,6 +1,8 @@
 # 测试用:快速开始 Hot Potato
 
 tag @a remove watcher
+scoreboard players set $game_type mem 1
+scoreboard players set $round mem 3
 scoreboard players set $mini_type mem 3
 function mini:main/game_init
 function ltw:state/4/state_enter

+ 2 - 0
data/test/functions/start_parkour.mcfunction

@@ -1,6 +1,8 @@
 # 测试用:快速开始跑酷
 
 tag @a remove watcher
+scoreboard players set $game_type mem 1
+scoreboard players set $round mem 3
 scoreboard players set $mini_type mem 1
 function mini:main/game_init
 function ltw:state/4/state_enter

+ 2 - 0
data/test/functions/start_tntrun.mcfunction

@@ -1,6 +1,8 @@
 # 测试用:快速开始 TNT Run
 
 tag @a remove watcher
+scoreboard players set $game_type mem 1
+scoreboard players set $round mem 3
 scoreboard players set $mini_type mem 2
 function mini:main/game_init
 function ltw:state/4/state_enter