2
0

game_end.mcfunction 4.8 KB

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