halma.txt 13 KB

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