game_end.mcfunction 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # 游戏结束,根据 total_score 判断排名,并返回主大厅
  2. # 计算排名
  3. tag @a remove total_rank1
  4. tag @a remove total_rank2
  5. tag @a remove total_rank3
  6. # 1
  7. function ltw:main/get_max_score
  8. execute as @a if score @s total_score = #score_max mem run tag @s add total_rank1
  9. tag @a[tag=total_rank1] add max_uncounted
  10. # 2
  11. function ltw:main/get_max_score
  12. execute as @a[tag=!max_uncounted] if score @s total_score = #score_max mem run tag @s add total_rank2
  13. tag @a[tag=total_rank2] add max_uncounted
  14. # 3
  15. function ltw:main/get_max_score
  16. execute as @a[tag=!max_uncounted] if score @s total_score = #score_max mem run tag @s add total_rank3
  17. tag @a[tag=max_uncounted] remove max_uncounted
  18. # 计算金粒奖励
  19. scoreboard players set #total_gold mem 0
  20. execute as @a[tag=!watcher] run scoreboard players add #total_gold mem 400
  21. # 无名次
  22. execute as @a[tag=!total_rank1,tag=!total_rank2,tag=!total_rank3,tag=!watcher] run scoreboard players remove #total_gold mem 100
  23. # 计算总权重与单份奖励
  24. scoreboard players set #total_weight mem 0
  25. execute as @a[tag=total_rank1] run scoreboard players add #total_weight mem 3
  26. execute as @a[tag=total_rank2] run scoreboard players add #total_weight mem 2
  27. execute as @a[tag=total_rank3] run scoreboard players add #total_weight mem 1
  28. scoreboard players operation #total_gold mem /= #total_weight mem
  29. # 计算名次奖励
  30. scoreboard players set #rank1_gold mem 3
  31. scoreboard players operation #rank1_gold mem *= #total_gold mem
  32. scoreboard players operation #rank1_gold mem /= #const_100 mem
  33. scoreboard players set #rank2_gold mem 2
  34. scoreboard players operation #rank2_gold mem *= #total_gold mem
  35. scoreboard players operation #rank2_gold mem /= #const_100 mem
  36. scoreboard players set #rank3_gold mem 1
  37. scoreboard players operation #rank3_gold mem *= #total_gold mem
  38. scoreboard players operation #rank3_gold mem /= #const_100 mem
  39. # 如果因为掉线强制结束则无名次奖励
  40. execute store result score #count mem if entity @a[tag=!watcher]
  41. execute if score #count mem matches ..2 run scoreboard players set #rank1_gold mem 0
  42. execute if score #count mem matches ..2 run scoreboard players set #rank2_gold mem 0
  43. execute if score #count mem matches ..2 run scoreboard players set #rank3_gold mem 0
  44. # 显示排名
  45. tellraw @a [" ",{"text":"\n\n\n\n----- 游戏结束 -----\n","color":"green","bold":true}]
  46. tellraw @a [" ",{"text": "第一名 - ","color":"green"},{"selector": "@a[tag=total_rank1]","color":"white"},{"text":" (","color":"gray"},{"score":{"name": "@p[tag=total_rank1]","objective": "total_score"},"color":"gray"},{"text":")","color":"gray"}]
  47. execute if entity @a[tag=total_rank2] run tellraw @a [" ",{"text": "第二名 - ","color":"green"},{"selector": "@a[tag=total_rank2]","color":"white"},{"text":" (","color":"gray"},{"score":{"name": "@p[tag=total_rank2]","objective": "total_score"},"color":"gray"},{"text":")","color":"gray"}]
  48. execute if entity @a[tag=total_rank3] run tellraw @a [" ",{"text": "第三名 - ","color":"green"},{"selector": "@a[tag=total_rank3]","color":"white"},{"text":" (","color":"gray"},{"score":{"name": "@p[tag=total_rank3]","objective": "total_score"},"color":"gray"},{"text":")","color":"gray"}]
  49. tellraw @a ""
  50. # 得分金粒奖励
  51. execute as @a[tag=!watcher] run scoreboard players operation @s gold += @s total_score
  52. execute as @a[tag=!watcher] run scoreboard players operation @s gold_total += @s total_score
  53. tellraw @a[tag=!watcher] [" ",{"text": "得分奖励: ","color":"gold"},{"score":{"name": "*","objective": "total_score"}}," 金粒"]
  54. # 名次金粒奖励
  55. scoreboard players set @a temp 0
  56. execute as @a[tag=total_rank1] run scoreboard players operation @s temp = #rank1_gold mem
  57. execute as @a[tag=total_rank2] run scoreboard players operation @s temp = #rank2_gold mem
  58. execute as @a[tag=total_rank3] run scoreboard players operation @s temp = #rank3_gold mem
  59. scoreboard players set @a[tag=!total_rank1,tag=!total_rank2,tag=!total_rank3,tag=!watcher] temp 1
  60. execute as @a run scoreboard players operation @s gold += @s temp
  61. execute as @a run scoreboard players operation @s gold_total += @s temp
  62. tellraw @a[tag=!watcher] [" ",{"text": "名次奖励: ","color":"gold"},{"score":{"name": "*","objective": "temp"}}," 金粒"]
  63. # 奖励结束
  64. tellraw @a[tag=!watcher] ""
  65. # 返回主大厅
  66. schedule function ltw:state/0/state_enter 2t replace
  67. execute as @a at @s run function lib:sounds/theend
  68. forceload remove all
  69. # TODO: 主要的需求见 https://shimo.im/docs/8dQtWhYp8rJhRRWG