game_end.mcfunction 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 add @a[team=playing] stat_total 1
  20. advancement grant @a[scores={stat_total=5..}] only ltw:story/total1
  21. advancement grant @a[scores={stat_total=20..}] only ltw:story/total2
  22. advancement grant @a[scores={stat_total=50..}] only ltw:story/total3
  23. scoreboard players add @a[tag=total_rank1] stat_win 1
  24. advancement grant @a[scores={stat_win=1..}] only ltw:story/win1
  25. advancement grant @a[scores={stat_win=5..}] only ltw:story/win2
  26. advancement grant @a[scores={stat_win=20..}] only ltw:story/win3
  27. # 计算金粒奖励
  28. scoreboard players set #total_gold mem 0
  29. execute as @a[team=playing] run scoreboard players add #total_gold mem 400
  30. # 无名次
  31. execute as @a[tag=!total_rank1,tag=!total_rank2,tag=!total_rank3,team=playing] run scoreboard players remove #total_gold mem 100
  32. # 计算总权重与单份奖励
  33. scoreboard players set #total_weight mem 0
  34. execute as @a[tag=total_rank1] run scoreboard players add #total_weight mem 3
  35. execute as @a[tag=total_rank2] run scoreboard players add #total_weight mem 2
  36. execute as @a[tag=total_rank3] run scoreboard players add #total_weight mem 1
  37. scoreboard players operation #total_gold mem /= #total_weight mem
  38. # 计算名次奖励
  39. scoreboard players set #rank1_gold mem 3
  40. scoreboard players operation #rank1_gold mem *= #total_gold mem
  41. scoreboard players operation #rank1_gold mem /= #const_100 mem
  42. scoreboard players set #rank2_gold mem 2
  43. scoreboard players operation #rank2_gold mem *= #total_gold mem
  44. scoreboard players operation #rank2_gold mem /= #const_100 mem
  45. scoreboard players set #rank3_gold mem 1
  46. scoreboard players operation #rank3_gold mem *= #total_gold mem
  47. scoreboard players operation #rank3_gold mem /= #const_100 mem
  48. # 如果因为掉线强制结束则无名次奖励
  49. execute store result score #count mem if entity @a[team=playing]
  50. execute if score #count mem matches ..2 run scoreboard players set #rank1_gold mem 0
  51. execute if score #count mem matches ..2 run scoreboard players set #rank2_gold mem 0
  52. execute if score #count mem matches ..2 run scoreboard players set #rank3_gold mem 0
  53. # 显示排名
  54. tellraw @a [" ",{"text":"\n----- 游戏结束 -----\n","color":"green","bold":true}]
  55. 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"}]
  56. 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"}]
  57. 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"}]
  58. tellraw @a ""
  59. # 得分金粒奖励
  60. execute as @a[team=playing] run scoreboard players operation @s gold += @s total_score
  61. execute as @a[team=playing] run scoreboard players operation @s gold_total += @s total_score
  62. tellraw @a[team=playing] [" ",{"text": "得分奖励: ","color":"gold"},{"score":{"name": "*","objective": "total_score"}}," 金粒"]
  63. # 名次金粒奖励
  64. scoreboard players set @a temp 0
  65. execute as @a[tag=total_rank1] run scoreboard players operation @s temp = #rank1_gold mem
  66. execute as @a[tag=total_rank2] run scoreboard players operation @s temp = #rank2_gold mem
  67. execute as @a[tag=total_rank3] run scoreboard players operation @s temp = #rank3_gold mem
  68. scoreboard players set @a[tag=!total_rank1,tag=!total_rank2,tag=!total_rank3,team=playing] temp 1
  69. execute as @a run scoreboard players operation @s gold += @s temp
  70. execute as @a run scoreboard players operation @s gold_total += @s temp
  71. tellraw @a[team=playing] [" ",{"text": "名次奖励: ","color":"gold"},{"score":{"name": "*","objective": "temp"}}," 金粒"]
  72. # 奖励结束
  73. tellraw @a[team=playing] ""
  74. # 返回主大厅
  75. schedule function ltw:state/0/state_enter 2t replace
  76. execute as @a at @s run function lib:sounds/theend
  77. forceload remove all