game_end.mcfunction 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. tag @a remove total_rankx
  8. # 1
  9. function ltw:main/get_max_score
  10. execute as @a if score @s total_score = #score_max mem run tag @s add total_rank1
  11. tag @a[tag=total_rank1] add max_uncounted
  12. # 2
  13. function ltw:main/get_max_score
  14. execute as @a[tag=!max_uncounted] if score @s total_score = #score_max mem run tag @s add total_rank2
  15. tag @a[tag=total_rank2] add max_uncounted
  16. # 3
  17. function ltw:main/get_max_score
  18. execute as @a[tag=!max_uncounted] if score @s total_score = #score_max mem run tag @s add total_rank3
  19. tag @a[tag=max_uncounted] remove max_uncounted
  20. # 最低分
  21. scoreboard players set #score_min mem 2147483647
  22. scoreboard players operation #score_min mem < @a[team=playing] total_score
  23. execute as @a if score @s total_score = #score_min mem run tag @s add total_rankl
  24. # 没有名次
  25. tag @a[team=playing,tag=!total_rank1,tag=!total_rank2,tag=!total_rank3] add total_rankx
  26. # 给予进度
  27. scoreboard players add @a[team=playing] stat_total 1
  28. scoreboard players add @a[tag=total_rank1] stat_win 1
  29. advancement grant @a[scores={stat_win=1..}] only ltw:story/win1
  30. advancement grant @a[scores={stat_win=5..}] only ltw:story/win2
  31. advancement grant @a[scores={stat_win=20..}] only ltw:story/win3
  32. # 计算金粒奖励
  33. scoreboard players set #total_gold mem 0
  34. execute as @a[team=playing] run scoreboard players add #total_gold mem 300
  35. # 计算总权重与单份奖励
  36. scoreboard players set #total_weight mem 0
  37. execute as @a[tag=total_rank1] run scoreboard players add #total_weight mem 4
  38. execute as @a[tag=total_rank2] run scoreboard players add #total_weight mem 3
  39. execute as @a[tag=total_rank3] run scoreboard players add #total_weight mem 2
  40. execute as @a[tag=total_rankx] run scoreboard players add #total_weight mem 1
  41. scoreboard players operation #total_gold mem /= #total_weight mem
  42. # 计算名次奖励
  43. scoreboard players set #rank1_gold mem 4
  44. scoreboard players operation #rank1_gold mem *= #total_gold mem
  45. scoreboard players operation #rank1_gold mem /= #100 mem
  46. scoreboard players set #rank2_gold mem 3
  47. scoreboard players operation #rank2_gold mem *= #total_gold mem
  48. scoreboard players operation #rank2_gold mem /= #100 mem
  49. scoreboard players set #rank3_gold mem 2
  50. scoreboard players operation #rank3_gold mem *= #total_gold mem
  51. scoreboard players operation #rank3_gold mem /= #100 mem
  52. scoreboard players set #rankl_gold mem 1
  53. scoreboard players operation #rankl_gold mem *= #total_gold mem
  54. scoreboard players operation #rankl_gold mem /= #100 mem
  55. # 如果因为掉线强制结束则无名次奖励
  56. execute store result score #count mem if entity @a[team=playing]
  57. execute if score #count mem matches ..2 run scoreboard players set #rank1_gold mem 0
  58. execute if score #count mem matches ..2 run scoreboard players set #rank2_gold mem 0
  59. execute if score #count mem matches ..2 run scoreboard players set #rank3_gold mem 0
  60. execute if score #count mem matches ..2 run scoreboard players set #rankl_gold mem 0
  61. # 显示排名
  62. tellraw @a ["",{"text":"\n------ 全场游戏结束! ------\n","color":"light_purple","bold":true}]
  63. 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"}]
  64. 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"}]
  65. 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"}]
  66. tellraw @a ""
  67. # 积分金粒奖励
  68. execute as @a[team=playing] run scoreboard players operation @s gold += @s total_score
  69. execute as @a[team=playing] run scoreboard players operation @s gold_total += @s total_score
  70. 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"},"!"]
  71. # 局中金粒
  72. tellraw @a[team=playing,scores={gold_extra=1..}] [" 在游戏过程中,你拿到了额外的 ",{"score":{"name": "*","objective": "gold_extra"},"color":"gold"},{"text": " 金粒","color":"gold"},"!"]
  73. # 局中绿宝石
  74. tellraw @a[team=playing,scores={green_extra=1..}] [" 由于达成了进度,你得到了 ",{"score":{"name": "*","objective": "green_extra"},"color":"green"},{"text": " 绿宝石","color":"green"}," 完成奖励!"]
  75. # 名次金粒奖励
  76. scoreboard players set @a temp 0
  77. execute as @a[tag=total_rank1] run scoreboard players operation @s temp = #rank1_gold mem
  78. execute as @a[tag=total_rank2] run scoreboard players operation @s temp = #rank2_gold mem
  79. execute as @a[tag=total_rank3] run scoreboard players operation @s temp = #rank3_gold mem
  80. execute as @a[tag=total_rankx] run scoreboard players operation @s temp = #rankl_gold mem
  81. execute as @a run scoreboard players operation @s gold += @s temp
  82. execute as @a run scoreboard players operation @s gold_total += @s temp
  83. tellraw @a[team=playing,tag=!total_rankx,tag=!total_rankl,scores={temp=1..}] [" 最后,由于你的出色名次,还获得了 ",{"score":{"name": "*","objective": "temp"},"color":"gold"},{"text": " 金粒","color":"gold"}," 奖励!"]
  84. tellraw @a[team=playing,tag=!total_rankx,tag=total_rankl,scores={temp=1..}] [" 不要气馁,收下 ",{"score":{"name": "*","objective": "temp"},"color":"gold"},{"text": " 金粒","color":"gold"}," 奖励,继续加油吧!"]
  85. tellraw @a[team=playing,tag=total_rankx,scores={temp=1..}] [" 不要气馁,收下 ",{"score":{"name": "*","objective": "temp"},"color":"gold"},{"text": " 金粒","color":"gold"}," 奖励,继续加油吧!"]
  86. # 奖励结束
  87. tellraw @a[team=playing] ""
  88. # 返回主大厅
  89. schedule function ltw:state/0/state_enter 2t replace
  90. execute as @a at @s run function lib:sounds/theend
  91. forceload remove all
  92. forceload add 0 0
  93. forceload add 0 1900 50 2000
  94. forceload add -32 -17 45 -80