halma.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. rankingtable = "halmaranks";
  2. game_short = "halma";
  3. teams = map.new();
  4. block_click_catcher = set.new();
  5. pointed_loc = loc.new(gamesworld, 0, 0, 0); //Default-Wert, um Error zu verhindern
  6. gamename = "§eHalma";
  7. specific_lobby_handling = true;
  8. no_core_reset = true;
  9. gosub("setstart");
  10. goto("simplelobby");
  11. @specificLobbyHandling
  12. if(event == "player_join") {
  13. entity.cleareffects(player);
  14. living.setHealth(player, 20);
  15. player.setHunger(player, 20);
  16. player.setSaturation(player, 5);
  17. player.clearInventory(player);
  18. display.reset(player);
  19. }
  20. return;
  21. @finalstart
  22. player_list = minigame.getPlayers(script_id);
  23. minigame.speakAll(gamename, "The game has started.");
  24. //Sechseck leeren
  25. iter = list.iterator(center_locs);
  26. while(hasNext(iter)) {
  27. entry = next(iter);
  28. block.set(entry, "minecraft:air");
  29. }
  30. //Start-Felder leeren
  31. map_iter = map.iterator(start_locs);
  32. while(hasNext(map_iter)) {
  33. list = map.getValue(next(map_iter));
  34. iter = list.iterator(list);
  35. while(hasNext(iter)) {
  36. entry = next(iter);
  37. block.set(entry, "minecraft:air");
  38. }
  39. }
  40. //Ziel-Felder leeren
  41. map_iter = map.iterator(aim_locs);
  42. while(hasNext(map_iter)) {
  43. list = map.getValue(next(map_iter));
  44. iter = list.iterator(list);
  45. while(hasNext(iter)) {
  46. entry = next(iter);
  47. block.set(entry, "minecraft:air");
  48. }
  49. }
  50. for(i = 0; i < list.getSize(player_list); i++) {
  51. player = player.get(list.getIndex(player_list, i));
  52. entity.teleport(player, spawn_loc);
  53. player.setGamemode(player, "survival");
  54. player.setFly(player, true);
  55. //Team-Zuweisung
  56. map.add(teams, player, i);
  57. //Start-Feld bestücken
  58. list = map.get(start_locs, i);
  59. banner_type = map.get(tokens_map, i);
  60. rotation = map.get(rotations_map, i);
  61. iter = list.iterator(list);
  62. while(hasNext(iter)) {
  63. entry = next(iter);
  64. block.set(entry, concat(banner_type, "[rotation=", rotation, "]"));
  65. }
  66. }
  67. next_player = player.get(list.getIndex(player_list, math.random(0, list.getSize(player_list) - 1)));
  68. setNextPlayer(next_player);
  69. jump_moves = false;
  70. @wait
  71. wait();
  72. if(player.hasMinigameId(player, script_id)) {
  73. ignoreGoto(event);
  74. }
  75. goto("wait");
  76. @block_click
  77. if(hand == "OFF_HAND") {
  78. goto("wait");
  79. }
  80. if(action == "left" && set.contains(block_click_catcher, player)) {
  81. set.remove(block_click_catcher, player);
  82. goto("wait");
  83. } else {
  84. set.add(block_click_catcher, player);
  85. }
  86. //Korrekter Spieler?
  87. if(player != next_player) {
  88. msg.prefix(player, gamename, "It´s not your turn.");
  89. goto("wait");
  90. }
  91. //Spielfigur ausgewählt?
  92. if(map.contains(tokens_map2, block_type)) {
  93. //Spielfigur der eigenen Farbe ausgewählt?
  94. if(map.get(tokens_map2, block_type) == map.get(teams, player)) {
  95. //Zuletzt ausgewählte Spielfigur der eigenen Farbe speichern, wenn nicht bereits gezogen (gesprungen) wurde
  96. if(jump_moves) {
  97. msg.prefix(player, gamename, "Already moved with another game piece.");
  98. goto("wait");
  99. }
  100. token_loc = block_loc;
  101. block.set(pointed_loc, basic_block);
  102. pointed_loc = loc.mod(block_loc, 0, -1, 0);
  103. block.set(pointed_loc, point_block);
  104. } else {
  105. msg.prefix(player, gamename, "Not your game piece.");
  106. }
  107. goto("wait");
  108. }
  109. //Wurde am Spielbrett ein gültiges Feld angeklickt?
  110. if(block_type == basic_block) {
  111. //Wurde bereits eine Spielfigur der eigenen Farbe ausgewählt?
  112. if(token_loc != null) {
  113. //Ist der Zug gültig? Ziehen / Springen
  114. diff_x = loc.getX(block_loc) - loc.getX(token_loc);
  115. diff_z = loc.getZ(block_loc) - loc.getZ(token_loc);
  116. possible_move = false;
  117. for(i = 0; i < list.getSize(possible_move_differences); i++) {
  118. a = list.getIndex(possible_move_differences, i);
  119. x = a[0];
  120. z = a[1];
  121. //Passt der Vektor des Zuges?
  122. if(math.abs(diff_x) == x && math.abs(diff_z) == z) {
  123. possible_move = true;
  124. move_type = "drag";
  125. if(i >= jumping_index) {
  126. //Sprung. Checken, ob sich eine Spielfigur auf halber Strecke befindet
  127. middle_loc = loc.mod(token_loc, diff_x / 2, 0, diff_z / 2);
  128. if(!map.contains(tokens_map2, block.getType(middle_loc))) {
  129. msg.prefix(player, gamename, "Invalid move.");
  130. goto("wait");
  131. }
  132. move_type = "jump";
  133. }
  134. //Ist der Zielblock belegt?
  135. aim_block = loc.mod(block_loc, 0, 1, 0);
  136. if(block.getType(aim_block) != "minecraft:air") {
  137. goto("wait");
  138. }
  139. //Die Spielfigur kann nicht gezogen werden, wenn bereits gesprungen wurde
  140. if(move_type == "drag" && jump_moves) {
  141. msg.prefix(player, gamename, "Move not possible. Already overjumped a game piece.");
  142. goto("wait");
  143. }
  144. //Zug der Spielfigur
  145. team = map.get(teams, player);
  146. banner_type = map.get(tokens_map, team);
  147. rotation = map.get(rotations_map, team);
  148. block.set(token_loc, "minecraft:air");
  149. block.set(aim_block, concat(banner_type, "[rotation=", rotation, "]"));
  150. token_loc = aim_block;
  151. block.set(pointed_loc, basic_block);
  152. if(move_type == "drag") {
  153. goto("nextplayer");
  154. } else {
  155. jump_moves = true;
  156. pointed_loc = block_loc;
  157. block.set(pointed_loc, point_block);
  158. }
  159. }
  160. }
  161. if(!possible_move) {
  162. msg.prefix(player, gamename, "Invalid move.");
  163. goto("wait");
  164. }
  165. }
  166. }
  167. goto("wait");
  168. @nextplayer
  169. //Gewonnen?
  170. team = map.get(teams, player);
  171. token = map.get(tokens_map, team);
  172. list = map.get(aim_locs, team);
  173. iter = list.iterator(list);
  174. won = true;
  175. while(hasNext(iter)) {
  176. entry = next(iter);
  177. if(block.getType(entry) != token) {
  178. won = false;
  179. }
  180. }
  181. if(won) {
  182. winner = player;
  183. goto("win");
  184. }
  185. token_loc = null;
  186. jump_moves = false;
  187. //Nächsten Spieler setzen
  188. index = list.getIndexOf(player_list, player.getUuid(next_player)) + 1;
  189. if(index >= list.getSize(player_list)) {
  190. index = 0;
  191. }
  192. next_player = player.get(list.getIndex(player_list, index));
  193. setNextPlayer(next_player);
  194. block.set(pointed_loc, basic_block);
  195. goto("wait");
  196. @custom_command
  197. if(command == "nextplayer") {
  198. if(player == next_player) {
  199. goto("nextplayer");
  200. }
  201. }
  202. goto("wait");
  203. @block_break
  204. @block_place
  205. @living_pre_hurt
  206. cancel = true;
  207. goto("wait");
  208. @win
  209. script = script.getFromId(script_id);
  210. minigame.speakAll(gamename, concat("§6", player.getName(winner), " §rhas won."));
  211. for(i = 0; i < list.getSize(player_list); i++) {
  212. p = player.get(list.getIndex(player_list, i));
  213. if(p == winner) {
  214. showstats(p, true);
  215. } else {
  216. showstats(p, false);
  217. }
  218. player.setFly(p, false);
  219. }
  220. minigame.kickAllPlayers(script);
  221. minigame.term(script, gamesignloc);
  222. term();
  223. @player_logout
  224. @player_giveup
  225. minigame.speakAll(gamename, concat("§8", player.getName(player), " §ehas left the game."));
  226. player.setFly(player, false);
  227. showstats(player, false);
  228. script = script.getFromId(script_id);
  229. minigame.kickPlayer(script, player);
  230. size = list.getSize(player_list);
  231. if(size < minplayers) {
  232. block.set(pointed_loc, basic_block);
  233. winner = player.get(list.getIndex(player_list, 0));
  234. goto("win");
  235. } else {
  236. team = map.get(teams, player);
  237. token = map.get(tokens_map, team);
  238. removeSpecificToken(token);
  239. }
  240. goto("wait");
  241. function setNextPlayer(next_player) {
  242. team = map.get($teams, next_player);
  243. color = map.get($colors_map, team);
  244. next_player_name = player.getName(next_player);
  245. if(text.endsWith(next_player_name, "s")) {
  246. minigame.speakAll($gamename, concat("It´s ", color, next_player_name, "' §rturn."));
  247. } else {
  248. minigame.speakAll($gamename, concat("It´s ", color, next_player_name, "'s §rturn."));
  249. }
  250. sound.spawnForPlayer(next_player, $pling_sound, $sound_category_ambient);
  251. msg(next_player, text.click("§r[§eEnd turn§r]", "/nextplayer"));
  252. }
  253. function removeSpecificToken(token) {
  254. //Sechseck nach festgelegter Spielfigur leeren
  255. iter = list.iterator($center_locs);
  256. while(hasNext(iter)) {
  257. entry = next(iter);
  258. if(block.getType(entry) == token) {
  259. block.set(entry, "minecraft:air");
  260. }
  261. }
  262. //Ziel-Felder nach festgelegter Spielfigur leeren
  263. map_iter = map.iterator($aim_locs);
  264. while(hasNext(map_iter)) {
  265. list = map.getValue(next(map_iter));
  266. iter = list.iterator(list);
  267. while(hasNext(iter)) {
  268. entry = next(iter);
  269. if(block.getType(entry) == token) {
  270. block.set(entry, "minecraft:air");
  271. }
  272. }
  273. }
  274. //Start-Felder nach festgelegter Spielfigur leeren
  275. map_iter = map.iterator($start_locs);
  276. while(hasNext(map_iter)) {
  277. list = map.getValue(next(map_iter));
  278. iter = list.iterator(list);
  279. while(hasNext(iter)) {
  280. entry = next(iter);
  281. if(block.getType(entry) == token) {
  282. block.set(entry, "minecraft:air");
  283. }
  284. }
  285. }
  286. }
  287. function showstats(player, won) { //Player player, Boolean won
  288. player_id = player.getId(player);
  289. last_record = ranking.getPoints($rankingtable, player_id);
  290. if(won) {
  291. last_record++;
  292. }
  293. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  294. minigame.setPlayed(player_id, $game_short, playedgames);
  295. ranking.setPoints($rankingtable, player_id, last_record);
  296. minigame.statsHeader(player, $gamename, "§e");
  297. minigame.statsLine(player, "§e", "Won games", text.number(last_record));
  298. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  299. if(playedgames != 0) {
  300. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((last_record / playedgames) * 100, 2)), "%"));
  301. }
  302. }
  303. function getPair(a, b) {
  304. c = array.new(2);
  305. c[0] = a;
  306. c[1] = b;
  307. return c;
  308. }
  309. function createFieldNorth(north_loc, ox, oz) {
  310. list = list.new();
  311. list.add(list, north_loc);
  312. list.add(list, loc.mod(north_loc, -ox, 0, oz));
  313. list.add(list, loc.mod(north_loc, ox, 0, oz));
  314. list.add(list, loc.mod(north_loc, -2*ox, 0, 2*oz));
  315. list.add(list, loc.mod(north_loc, 0, 0, 2*oz));
  316. list.add(list, loc.mod(north_loc, 2*ox, 0, 2*oz));
  317. list.add(list, loc.mod(north_loc, -3*ox, 0, 3*oz));
  318. list.add(list, loc.mod(north_loc, -ox, 0, 3*oz));
  319. list.add(list, loc.mod(north_loc, ox, 0, 3*oz));
  320. list.add(list, loc.mod(north_loc, 3*ox, 0, 3*oz));
  321. list.add(list, loc.mod(north_loc, -4*ox, 0, 4*oz));
  322. list.add(list, loc.mod(north_loc, -2*ox, 0, 4*oz));
  323. list.add(list, loc.mod(north_loc, 0, 0, 4*oz));
  324. list.add(list, loc.mod(north_loc, 2*ox, 0, 4*oz));
  325. list.add(list, loc.mod(north_loc, 4*ox, 0, 4*oz));
  326. return list;
  327. }
  328. function createFieldSouth(south_loc, ox, oz) {
  329. list = list.new();
  330. list.add(list, south_loc);
  331. list.add(list, loc.mod(south_loc, -ox, 0, -oz));
  332. list.add(list, loc.mod(south_loc, ox, 0, -oz));
  333. list.add(list, loc.mod(south_loc, -2*ox, 0, -2*oz));
  334. list.add(list, loc.mod(south_loc, 0, 0, -2*oz));
  335. list.add(list, loc.mod(south_loc, 2*ox, 0, -2*oz));
  336. list.add(list, loc.mod(south_loc, -3*ox, 0, -3*oz));
  337. list.add(list, loc.mod(south_loc, -ox, 0, -3*oz));
  338. list.add(list, loc.mod(south_loc, ox, 0, -3*oz));
  339. list.add(list, loc.mod(south_loc, 3*ox, 0, -3*oz));
  340. list.add(list, loc.mod(south_loc, -4*ox, 0, -4*oz));
  341. list.add(list, loc.mod(south_loc, -2*ox, 0, -4*oz));
  342. list.add(list, loc.mod(south_loc, 0, 0, -4*oz));
  343. list.add(list, loc.mod(south_loc, 2*ox, 0, -4*oz));
  344. list.add(list, loc.mod(south_loc, 4*ox, 0, -4*oz));
  345. return list;
  346. }
  347. function createFieldCenter(loc, ox, oz) {
  348. list = list.new();
  349. list.add(list, loc);
  350. list.add(list, loc.mod(loc, 2*ox, 0, 0));
  351. list.add(list, loc.mod(loc, 4*ox, 0, 0));
  352. list.add(list, loc.mod(loc, 6*ox, 0, 0));
  353. list.add(list, loc.mod(loc, -ox, 0, oz));
  354. list.add(list, loc.mod(loc, ox, 0, oz));
  355. list.add(list, loc.mod(loc, 3*ox, 0, oz));
  356. list.add(list, loc.mod(loc, 5*ox, 0, oz));
  357. list.add(list, loc.mod(loc, 7*ox, 0, oz));
  358. list.add(list, loc.mod(loc, -2*ox, 0, 2*oz));
  359. list.add(list, loc.mod(loc, 0, 0, 2*oz));
  360. list.add(list, loc.mod(loc, 2*ox, 0, 2*oz));
  361. list.add(list, loc.mod(loc, 4*ox, 0, 2*oz));
  362. list.add(list, loc.mod(loc, 6*ox, 0, 2*oz));
  363. list.add(list, loc.mod(loc, 8*ox, 0, 2*oz));
  364. list.add(list, loc.mod(loc, -3*ox, 0, 3*oz));
  365. list.add(list, loc.mod(loc, -ox, 0, 3*oz));
  366. list.add(list, loc.mod(loc, ox, 0, 3*oz));
  367. list.add(list, loc.mod(loc, 3*ox, 0, 3*oz));
  368. list.add(list, loc.mod(loc, 5*ox, 0, 3*oz));
  369. list.add(list, loc.mod(loc, 7*ox, 0, 3*oz));
  370. list.add(list, loc.mod(loc, 9*ox, 0, 3*oz));
  371. list.add(list, loc.mod(loc, -2*ox, 0, 4*oz));
  372. list.add(list, loc.mod(loc, 0, 0, 4*oz));
  373. list.add(list, loc.mod(loc, 2*ox, 0, 4*oz));
  374. list.add(list, loc.mod(loc, 4*ox, 0, 4*oz));
  375. list.add(list, loc.mod(loc, 6*ox, 0, 4*oz));
  376. list.add(list, loc.mod(loc, 8*ox, 0, 4*oz));
  377. list.add(list, loc.mod(loc, -ox, 0, 5*oz));
  378. list.add(list, loc.mod(loc, ox, 0, 5*oz));
  379. list.add(list, loc.mod(loc, 3*ox, 0, 5*oz));
  380. list.add(list, loc.mod(loc, 5*ox, 0, 5*oz));
  381. list.add(list, loc.mod(loc, 7*ox, 0, 5*oz));
  382. list.add(list, loc.mod(loc, 0, 0, 6*oz));
  383. list.add(list, loc.mod(loc, 2*ox, 0, 6*oz));
  384. list.add(list, loc.mod(loc, 4*ox, 0, 6*oz));
  385. list.add(list, loc.mod(loc, 6*ox, 0, 6*oz));
  386. return list;
  387. }