dame.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //Schwarz muss IMMER nach Süden schauen!!!
  2. //Weiß muss IMMER nach Norden schauen!!!
  3. rankingtable = "dameranks";
  4. teams = map.new();
  5. block_click_catcher = set.new();
  6. pointed_loc = loc.new(gamesworld, 0, 0, 0); //Default-Wert, um Error zu verhindern
  7. gamename = "§eDame";
  8. gosub("setstart");
  9. goto("simplelobby");
  10. @finalstart
  11. player_list = minigame.getPlayers(script_id);
  12. minigame.speakAll(gamename, "The game has started.");
  13. black_token = concat("minecraft:wither_skeleton_skull[rotation=8]");
  14. white_token = concat("minecraft:wither_skeleton_skull[rotation=0]");
  15. black_token_plus = concat("minecraft:black_banner[rotation=0]");
  16. white_token_plus = concat("minecraft:white_banner[rotation=8]");
  17. for(i = 0; i < list.getSize(player_list); i++) {
  18. player_uuid = list.getIndex(player_list, i);
  19. player = player.get(player_uuid);
  20. entity.teleport(player, map.get(spawn_locs, i));
  21. player.setGamemode(player, "survival");
  22. player.setFly(player, true);
  23. map.add(teams, player_uuid, i); //Team-Zuweisung
  24. }
  25. next_player_uuid = list.getIndex(player_list, math.random(0, list.getSize(player_list) - 1));
  26. setNextPlayer(next_player_uuid);
  27. jump_moves = false;
  28. @wait
  29. wait();
  30. if(player.hasMinigameId(player, script_id)) {
  31. ignoreGoto(event);
  32. }
  33. goto("wait");
  34. @block_click
  35. if(hand == "OFF_HAND") {
  36. goto("wait");
  37. }
  38. if(action == "left" && set.contains(block_click_catcher, player)) {
  39. set.remove(block_click_catcher, player);
  40. goto("wait");
  41. } else {
  42. set.add(block_click_catcher, player);
  43. }
  44. //Korrekter Spieler?
  45. if(player.getUUid(player) != next_player_uuid) {
  46. speakPrefix(player, gamename, "It´s not your turn.");
  47. goto("wait");
  48. }
  49. //Spielfigur ausgewählt?
  50. if(map.contains(tokens_map2, block_type)) {
  51. //Spielfigur der eigenen Farbe ausgewählt?
  52. if(map.get(tokens_map2, block_type) == map.get(teams, player.getUuid(player))) {
  53. //Zuletzt ausgewählte Spielfigur der eigenen Farbe speichern, wenn nicht bereits gezogen (gesprungen) wurde
  54. if(jump_moves) {
  55. speakPrefix(player, gamename, "Already moved with another game piece.");
  56. goto("wait");
  57. }
  58. token_loc = block_loc;
  59. block.set(pointed_loc, basic_block);
  60. pointed_loc = loc.mod(block_loc, 0, -1, 0);
  61. block.set(pointed_loc, point_block);
  62. } else {
  63. speakPrefix(player, gamename, "Not your game piece.");
  64. }
  65. goto("wait");
  66. }
  67. //Wurde am Spielbrett ein gültiges Feld angeklickt?
  68. if(block_type == basic_block) {
  69. //Wurde bereits eine Spielfigur der eigenen Farbe ausgewählt?
  70. if(token_loc != null) {
  71. //Ist der Zug gültig? Ziehen / Springen
  72. diff_x = loc.getX(block_loc) - loc.getX(token_loc);
  73. diff_z = loc.getZ(block_loc) - loc.getZ(token_loc);
  74. possible_move = false;
  75. for(i = 0; i < list.getSize(possible_move_differences); i++) {
  76. a = list.getIndex(possible_move_differences, i);
  77. x = a[0];
  78. z = a[1];
  79. //Passt der Vektor des Zuges?
  80. if(math.abs(diff_x) == x && math.abs(diff_z) == z) {
  81. possible_move = true;
  82. move_type = "drag";
  83. if(i >= jumping_index) {
  84. //Sprung. Checken, ob sich eine Spielfigur auf halber Strecke befindet
  85. middle_loc = loc.mod(token_loc, diff_x / 2, 0, diff_z / 2);
  86. if(!map.contains(tokens_map2, block.getType(middle_loc))) {
  87. speakPrefix(player, gamename, "Invalid move.");
  88. goto("wait");
  89. }
  90. move_type = "jump";
  91. }
  92. //Ist der Zielblock belegt?
  93. aim_block = loc.mod(block_loc, 0, 1, 0);
  94. if(block.getType(aim_block) != "minecraft:air") {
  95. goto("wait");
  96. }
  97. //Die Spielfigur kann nicht gezogen werden, wenn bereits gesprungen wurde
  98. if(move_type == "drag" && jump_moves) {
  99. speakPrefix(player, gamename, "Move not possible. Already overjumped a game piece.");
  100. goto("wait");
  101. }
  102. //Zug der Spielfigur
  103. team = map.get(teams, player.getUuid(player));
  104. banner_type = map.get(tokens_map, team);
  105. rotation = map.get(rotations_map, team);
  106. block.set(token_loc, "minecraft:air");
  107. block.set(aim_block, concat(banner_type, "[rotation=", rotation, "]"));
  108. token_loc = aim_block;
  109. block.set(pointed_loc, basic_block);
  110. if(move_type == "drag") {
  111. goto("nextplayer");
  112. } else {
  113. jump_moves = true;
  114. pointed_loc = block_loc;
  115. block.set(pointed_loc, point_block);
  116. }
  117. }
  118. }
  119. if(!possible_move) {
  120. speakPrefix(player, gamename, "Invalid move.");
  121. goto("wait");
  122. }
  123. }
  124. }
  125. goto("wait");
  126. @nextplayer
  127. //Gewonnen?
  128. team = map.get(teams, player.getUuid(player));
  129. token = map.get(tokens_map, team);
  130. list = map.get(aim_locs, team);
  131. iter = list.iterator(list);
  132. won = true;
  133. while(hasNext(iter)) {
  134. entry = next(iter);
  135. if(block.getType(entry) != token) {
  136. won = false;
  137. }
  138. }
  139. if(won) {
  140. winner = player;
  141. goto("win");
  142. }
  143. token_loc = null;
  144. jump_moves = false;
  145. //Nächsten Spieler setzen
  146. index = list.getIndexOf(player_list, next_player_uuid) + 1;
  147. if(index >= list.getSize(player_list)) {
  148. index = 0;
  149. }
  150. next_player_uuid = list.getIndex(player_list, index);
  151. setNextPlayer(next_player_uuid);
  152. block.set(pointed_loc, basic_block);
  153. goto("wait");
  154. @custom_command
  155. if(command == "nextplayer") {
  156. if(player.getUuid(player) == next_player_uuid) {
  157. goto("nextplayer");
  158. }
  159. }
  160. goto("wait");
  161. @block_break
  162. @block_place
  163. @living_pre_hurt
  164. cancel = true;
  165. goto("wait");
  166. @win
  167. resetField();
  168. script = script.getFromId(script_id);
  169. minigame.speakAll(gamename, concat("§6", player.getName(winner), " §rhas won."));
  170. for(i = 0; i < list.getSize(player_list); i++) {
  171. p = player.get(list.getIndex(player_list, i));
  172. if(p == winner) {
  173. showstats(p, true);
  174. } else {
  175. showstats(p, false);
  176. }
  177. player.setFly(p, false);
  178. }
  179. minigame.kickAllPlayers(script);
  180. minigame.term(script, gamesignloc);
  181. term();
  182. @player_logout
  183. @player_giveup
  184. minigame.speakAll(gamename, concat("§8", player.getName(player), " §ehas left the game."));
  185. player.setFly(player, false);
  186. showstats(player, false);
  187. script = script.getFromId(script_id);
  188. minigame.kickPlayer(script, player);
  189. size = list.getSize(player_list);
  190. if(size < minplayers) {
  191. block.set(pointed_loc, basic_block);
  192. winner = player.get(list.getIndex(player_list, 0));
  193. goto("win");
  194. } else {
  195. team = map.get(teams, player.getUuid(player));
  196. token = map.get(tokens_map, team);
  197. removeSpecificToken(token);
  198. }
  199. goto("wait");
  200. function setNextPlayer(next_player_uuid) {
  201. team = map.get($teams, next_player_uuid);
  202. color = map.get($colors_map, team);
  203. next_player_name = player.getName(next_player_uuid);
  204. if(text.endsWith(next_player_name, "s")) {
  205. minigame.speakAll($gamename, concat("It´s ", color, next_player_name, "' §rturn."));
  206. } else {
  207. minigame.speakAll($gamename, concat("It´s ", color, next_player_name, "'s §rturn."));
  208. }
  209. next_player = player.get(next_player_uuid);
  210. sound.spawnForPlayer(next_player, $pling_sound, $sound_category_ambient);
  211. msg(next_player, text.click("§r[§eEnd turn§r]", "/nextplayer"));
  212. }
  213. function removeSpecificToken(token) {
  214. //Sechseck nach festgelegter Spielfigur leeren
  215. iter = list.iterator($center_locs);
  216. while(hasNext(iter)) {
  217. entry = next(iter);
  218. if(block.getType(entry) == token) {
  219. block.set(entry, "minecraft:air");
  220. }
  221. }
  222. //Ziel-Felder nach festgelegter Spielfigur leeren
  223. map_iter = map.iterator($aim_locs);
  224. while(hasNext(map_iter)) {
  225. list = map.getValue(next(map_iter));
  226. iter = list.iterator(list);
  227. while(hasNext(iter)) {
  228. entry = next(iter);
  229. if(block.getType(entry) == token) {
  230. block.set(entry, "minecraft:air");
  231. }
  232. }
  233. }
  234. //Start-Felder nach festgelegter Spielfigur leeren
  235. map_iter = map.iterator($start_locs);
  236. while(hasNext(map_iter)) {
  237. list = map.getValue(next(map_iter));
  238. iter = list.iterator(list);
  239. while(hasNext(iter)) {
  240. entry = next(iter);
  241. if(block.getType(entry) == token) {
  242. block.set(entry, "minecraft:air");
  243. }
  244. }
  245. }
  246. }
  247. function showstats(player, won) { //Player player, Boolean won
  248. player_id = player.getId(player);
  249. last_record = getPoints($rankingtable, player_id);
  250. if(won) {
  251. last_record++;
  252. }
  253. playedgames = getPlayedGames($rankingtable, player_id) + 1;
  254. setRanking($rankingtable, player_id, last_record, playedgames);
  255. minigame.statsHeader(player, $gamename, "§e");
  256. minigame.statsLine(player, "§e", "Won games", text.hover(text.number(last_record), "Relevant for ranking"));
  257. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  258. if(playedgames != 0) {
  259. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((last_record / playedgames) * 100, 2)), "%"));
  260. }
  261. }
  262. function resetField() {
  263. loc = $black_left_front_corner_loc;
  264. resetFieldRow(loc, $black_token);
  265. loc.add(loc, -1, 0, 1);
  266. resetFieldRow(loc, $black_token);
  267. loc.add(loc, 1, 0, 1);
  268. resetFieldRow(loc, $black_token);
  269. loc.add(loc, -1, 0, 3);
  270. resetFieldRow(loc, $white_token);
  271. loc.add(loc, 1, 0, 1);
  272. resetFieldRow(loc, $white_token);
  273. loc.add(loc, -1, 0, 1);
  274. resetFieldRow(loc, $white_token);
  275. }
  276. function resetFieldRow(loc, token) {
  277. x = 0;
  278. for(i = 0; i < 4; i++) {
  279. block.set(loc, token);
  280. loc.add(loc, -2, 0, 0);
  281. }
  282. loc.add(loc, 8, 0, 0);
  283. }