game_end.mcfunction 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # 游戏结束,根据 total_score 判断排名,并返回主大厅
  2. # 计算排名
  3. tag @a remove total_rank1
  4. tag @a remove total_rank2
  5. tag @a remove total_rank3
  6. tag @a remove total_rankl
  7. # 1
  8. function ltw:main/get_max_score
  9. execute as @a if score @s total_score = #score_max mem run tag @s add total_rank1
  10. tag @a[tag=total_rank1] add max_uncounted
  11. # 2
  12. function ltw:main/get_max_score
  13. execute as @a[tag=!max_uncounted] if score @s total_score = #score_max mem run tag @s add total_rank2
  14. tag @a[tag=total_rank2] add max_uncounted
  15. # 3
  16. function ltw:main/get_max_score
  17. execute as @a[tag=!max_uncounted] if score @s total_score = #score_max mem run tag @s add total_rank3
  18. tag @a[tag=max_uncounted] remove max_uncounted
  19. # 最低分
  20. scoreboard players set #score_min mem 2147483647
  21. scoreboard players operation #score_min mem < @a[team=playing] total_score
  22. execute as @a if score @s total_score = #score_min mem run tag @s add total_rankl
  23. # 没有名次
  24. tag @a[team=playing,tag=!total_rank1,tag=!total_rank2,tag=!total_rank3] add total_rankl
  25. # 给予进度
  26. scoreboard players add @a[team=playing] stat_total 1
  27. scoreboard players add @a[tag=total_rank1] stat_win 1
  28. # 显示排名
  29. tellraw @a ["",{"text":"\n------ 全场游戏结束! ------\n","color":"light_purple","bold":true}]
  30. tellraw @a [" ",{"text": "第一名 > ","color":"red"},{"selector": "@a[tag=total_rank1]","color":"red"},{"text":" (","color":"gray"},{"score":{"name": "@p[tag=total_rank1]","objective": "total_score"},"color":"gray"},{"text":")","color":"gray"}]
  31. execute if entity @a[tag=total_rank2] run tellraw @a [" ",{"text": "第二名 > ","color":"gold"},{"selector": "@a[tag=total_rank2]","color":"gold"},{"text":" (","color":"gray"},{"score":{"name": "@p[tag=total_rank2]","objective": "total_score"},"color":"gray"},{"text":")","color":"gray"}]
  32. execute if entity @a[tag=total_rank3] run tellraw @a [" ",{"text": "第三名 > ","color":"yellow"},{"selector": "@a[tag=total_rank3]","color":"yellow"},{"text":" (","color":"gray"},{"score":{"name": "@p[tag=total_rank3]","objective": "total_score"},"color":"gray"},{"text":")","color":"gray"}]
  33. tellraw @a ""
  34. # 积分金粒奖励
  35. execute as @a[team=playing] run scoreboard players operation @s gold += @s total_score
  36. execute as @a[team=playing] run scoreboard players operation @s gold_total += @s total_score
  37. tellraw @a[team=playing,scores={total_score=1..}] [" 你得到的 ",{"score":{"name": "*","objective": "total_score"},"color":"gold"},{"text": " 积分","color":"gold"}," 已转换为 ",{"score":{"name": "*","objective": "total_score"},"color":"gold"},{"text": " 金粒","color":"gold"},"!"]
  38. # 局中金粒
  39. tellraw @a[team=playing,scores={gold_extra=1..}] [" 在游戏过程中,你拿到了额外的 ",{"score":{"name": "*","objective": "gold_extra"},"color":"gold"},{"text": " 金粒","color":"gold"},"!"]
  40. # 局中绿宝石
  41. tellraw @a[team=playing,scores={green_extra=1..}] [" 由于达成了进度,你得到了 ",{"score":{"name": "*","objective": "green_extra"},"color":"green"},{"text": " 绿宝石","color":"green"}," 完成奖励!"]
  42. # 如果因为掉线强制结束则无安慰奖
  43. execute store result score #count mem if entity @a[team=playing]
  44. execute if score #count mem matches ..2 run tag @a remove total_rankl
  45. # 安慰奖
  46. execute as @a[tag=total_rankl] run scoreboard players add @s gold 5
  47. execute as @a[tag=total_rankl] run scoreboard players add @s gold_total 5
  48. tellraw @a[tag=total_rankl] [" 不要气馁,收下 ",{"text": "5 金粒","color":"gold"}," 奖励,继续加油吧!"]
  49. # 奖励结束
  50. tellraw @a[team=playing] ""
  51. # 返回主大厅
  52. schedule function ltw:state/0/state_enter 2t replace
  53. execute as @a at @s run function lib:sounds/theend
  54. forceload remove all
  55. forceload add 0 0
  56. forceload add 0 1900 50 2000
  57. forceload add -32 -17 45 -80