cores.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /* --- Game instruction ---
  2. Each team has cores.
  3. The game is won, when all cores of the opponent team are broken.
  4. A killed player respawns at his team spawn. At respawn the inventory is reset to default.
  5. Friendly Fire is canceled.
  6. The spawns are protected within a 3D-radius.
  7. The iron blocks under a beacon are protected.
  8. If a beacon is left clicked, the player gets mining fatigued.
  9. Cores cannot be broken by the own team.
  10. On the rest of the game field blocks can be placed and broken.
  11. Beacons cannot be used.
  12. */
  13. default_inv = array.new(9, 2); // slot | item
  14. default_inv[0, 0] = 0;
  15. default_inv[0, 1] = item.new(material.get("IRON_SWORD"));
  16. default_inv[1, 0] = 1;
  17. default_inv[1, 1] = item.new(material.get("IRON_PICKAXE"));
  18. default_inv[2, 0] = 2;
  19. default_inv[2, 1] = item.new(material.get("IRON_AXE"));
  20. default_inv[3, 0] = 3;
  21. default_inv[3, 1] = item.new(material.get("OAK_LOG"), 64);
  22. default_inv[4, 0] = 4;
  23. default_inv[4, 1] = item.new(material.get("BREAD"), 32);
  24. default_inv[5, 0] = 5;
  25. default_inv[5, 1] = item.new(material.get("ARROW"), 64);
  26. default_inv[6, 0] = 6;
  27. default_inv[6, 1] = item.new(material.get("GOLDEN_APPLE"), 16);
  28. default_inv[7, 0] = 7;
  29. default_inv[7, 1] = item.new(material.get("BOW"));
  30. default_inv[8, 0] = 8;
  31. default_inv[8, 1] = item.new(material.get("OAK_PLANKS"), 64);
  32. rankingtable = "coresranks";
  33. gamename = "§bCores";
  34. game_short = "cores";
  35. game_tab = "§bCores";
  36. minigame.setIndivStartCheck(true);
  37. minigame.setSpecificLobbyHandling(true);
  38. bed_sound = sound.get("ENTITY_WITHER_DEATH");
  39. air_mat = material.getAir();
  40. beacon_mat = material.get("BEACON");
  41. colorcodes = map.new();
  42. map.add(colorcodes, 0, "§9");
  43. map.add(colorcodes, 1, "§c");
  44. teamcolortext = map.new();
  45. map.add(teamcolortext, 0, "§9blue");
  46. map.add(teamcolortext, 1, "§cred");
  47. teamcolortext2 = map.new();
  48. map.add(teamcolortext2, 0, "§9Blue");
  49. map.add(teamcolortext2, 1, "§cRed");
  50. clothescode = map.new(); //lift of data values for colored clothes
  51. map.add(clothescode, 0, 5592575);
  52. map.add(clothescode, 1, 16733525);
  53. team_lists = map.new(); //Map mit Spielerlisten für jedes Team
  54. map.add(team_lists, 0, list.new());
  55. map.add(team_lists, 1, list.new());
  56. players = map.new(); //Alle Spieler (key) des Spiels und deren Teamzugehörigkeit (value)
  57. allteams = list.new(); //Alle Teams, die noch im Spiel sind
  58. waiters = list.new(); //Spieler in der Lobby ohne Teamzugehörigkeit
  59. broken_cores = map.new(); //Broken cores per player
  60. placedblocks = list.new();
  61. brokenblocks = map.new();
  62. active_cores = list.new();
  63. for(i = 0; i < list.getSize(cores); i++) {
  64. l = list.getIndex(cores, i);
  65. list.add(active_cores, list.copy(l));
  66. }
  67. protected_locs = set.new();
  68. for(i = 0; i < list.getSize(cores); i++) {
  69. l = list.getIndex(cores, i);
  70. for(h = 0; h < list.getSize(l); h++) {
  71. loc = list.getIndex(l, h);
  72. //4 blocks (+ pattern) around the core are protected
  73. set.add(protected_locs, loc.mod(loc, 0, 0, 1));
  74. set.add(protected_locs, loc.mod(loc, 0, 0, -1));
  75. set.add(protected_locs, loc.mod(loc, 1, 0, 0));
  76. set.add(protected_locs, loc.mod(loc, -1, 0, 0));
  77. //2 blocks above the core are protected
  78. set.add(protected_locs, loc.mod(loc, 0, 2, 0));
  79. set.add(protected_locs, loc.mod(loc, 0, 1, 0));
  80. //iron blocks under cores are protected
  81. set.add(protected_locs, loc.mod(loc, 0, -1, 0));
  82. set.add(protected_locs, loc.mod(loc, 0, -1, 1));
  83. set.add(protected_locs, loc.mod(loc, 0, -1, -1));
  84. set.add(protected_locs, loc.mod(loc, 1, -1, 0));
  85. set.add(protected_locs, loc.mod(loc, -1, -1, 0));
  86. set.add(protected_locs, loc.mod(loc, 1, -1, 1));
  87. set.add(protected_locs, loc.mod(loc, -1, -1, -1));
  88. set.add(protected_locs, loc.mod(loc, -1, -1, 1));
  89. set.add(protected_locs, loc.mod(loc, 1, -1, -1));
  90. }
  91. }
  92. minigame.initStart();
  93. goto("simplelobby");
  94. @specificLobbyHandling
  95. player_name = player.getName(player);
  96. if(event == "minigame_join") {
  97. list.add(waiters, player_name);
  98. living.setHealth(player, 20);
  99. player.setHunger(player, 20);
  100. player.setSaturation(player, 5);
  101. player.clearInventory(player);
  102. sb.add(player, 99, gamename);
  103. sb.add(player, 98, string.concat("Map: ", mapname));
  104. sb.add(player, 97, string.concat(string.number(numberofteams), "x", string.number(teamsize)));
  105. sb.add(player, 96, sb.getSpacer());
  106. return;
  107. }
  108. if(event == "player_quit" || event == "player_giveup") {
  109. list.remove(waiters, player_name);
  110. team = map.get(players, player_name);
  111. if(team != null) {
  112. teamlist = getTeamList(team);
  113. list.remove(teamlist, player_name);
  114. }
  115. map.remove(players, player_name);
  116. return;
  117. }
  118. if(event == "block_click") {
  119. if(slot.isOffHand(hand)) {
  120. return;
  121. }
  122. if(action != "RIGHT_CLICK_BLOCK") {
  123. return;
  124. }
  125. block_loc = block.getLocation(block);
  126. if(list.contains(joinblocks, block_loc)) {
  127. newteam = list.getIndexOf(joinblocks, block_loc);
  128. newteamlist = getTeamList(newteam);
  129. if(list.contains(newteamlist, player_name)) {
  130. msg.prefix(player, gamename, "§eYou are already in this team.");
  131. return;
  132. }
  133. if(list.getSize(newteamlist) >= teamsize) {
  134. msg.prefix(player, gamename, "§eNo space for you in this team.");
  135. return;
  136. }
  137. list.remove(waiters, player_name);
  138. yetteam = map.get(players, player_name);
  139. if(yetteam != null) {
  140. yetteamlist = getTeamList(yetteam);
  141. list.remove(yetteamlist, player_name);
  142. }
  143. list.add(newteamlist, player_name);
  144. map.add(players, player_name, newteam);
  145. msg.prefix(player, gamename, string.concat("§eYou joined the ", map.get(teamcolortext, newteam), " §eteam."));;
  146. entity.setName(player, text.new(string.concat(getColorCode(newteam), player_name)));
  147. if(!minigame.isStarting()) {
  148. goto("startcountdown");
  149. }
  150. }
  151. }
  152. return;
  153. function minigame.canStartIndiv() {
  154. player_list = minigame.getPlayers($script_id);
  155. p_amount = list.getSize(player_list);
  156. if(p_amount < minigame.getMinPlayers()) {
  157. return false;
  158. }
  159. if(p_amount > 0 && list.getSize($waiters) > 0) {
  160. return true;
  161. }
  162. for(i = 0; i < $numberofteams; i++) {
  163. teamlist = getTeamList(i);
  164. team_size = list.getSize(teamlist);
  165. if(team_size == p_amount) {
  166. return false;
  167. }
  168. }
  169. return true;
  170. }
  171. @finalstart
  172. player_list = minigame.getPlayers(script_id);
  173. minigame.speakAll(gamename, "The game has started.");
  174. if(voidedge1 != null) {
  175. voidid = event.addMoveData(voidedge1, voidedge2, 3, -1);
  176. }
  177. while(list.getSize(waiters) != 0) {
  178. team = getTeamWithLowestPeople(team_lists, numberofteams);
  179. teamlist = getTeamList(team);
  180. p_name = list.getIndex(waiters, 0);
  181. map.add(players, p_name, team);
  182. list.add(teamlist, p_name);
  183. list.remove(waiters, p_name);
  184. entity.setName(read.player(p_name), text.new(string.concat(getColorCode(team), p_name)));
  185. }
  186. for(i = 0; i < numberofteams; i++) {
  187. teamlist = getTeamList(i);
  188. size = list.getSize(teamlist);
  189. if(size > 0) {
  190. list.add(allteams, i);
  191. }
  192. }
  193. updateDisplay();
  194. for(i = 0; i < list.getSize(player_list); i++) {
  195. p = player.get(list.getIndex(player_list, i));
  196. team = getTeamFromPlayer(p);
  197. player.setHunger(p, 20);
  198. player.setSaturation(p, 5);
  199. player.setGamemode(p, "SURVIVAL");
  200. player.setFly(p, false);
  201. entity.teleport(p, list.getIndex(spawnlocs, team));
  202. color = getColorCode(team);
  203. player.action(p, text.new(string.concat(color, "Team ", map.get(teamcolortext2, team))));
  204. equipPlayer(p);
  205. minigame.setTabName(p, game_tab, color);
  206. }
  207. sgoto(30, "loop");
  208. event.load("player_post_respawn");
  209. event.load("player_move");
  210. @checkgame
  211. wait();
  212. if(event == "entity_damage") {
  213. if(!isPlayer(entity)) {
  214. goto("checkgame");
  215. }
  216. player = entity;
  217. }
  218. if(player.hasMinigameId(player, script_id)) {
  219. player_name = player.getName(player);
  220. ignoreGoto(event);
  221. }
  222. goto("checkgame");
  223. @loop
  224. for(i = 0; i < list.getSize(player_list); i++) {
  225. p = player.get(list.getIndex(player_list, i));
  226. team = getTeamFromPlayer(p);
  227. player.action(p, text.new(string.concat(getColorCode(team), "Team ", map.get(teamcolortext2, team))));
  228. }
  229. sgoto(30, "loop");
  230. goto("checkgame");
  231. @player_post_respawn
  232. team = getTeamFromPlayer(player);
  233. entity.setName(player, text.new(string.concat(getColorCode(team), player.getName(player))));
  234. loc = list.getIndex(spawnlocs, team);
  235. entity.teleport(player, loc);
  236. equipPlayer(player);
  237. goto("checkgame");
  238. @player_move
  239. if(id == voidid) {
  240. damage_source = damage.get("outOfWorld");
  241. living.damage(player, 300, damage_source);
  242. }
  243. goto("checkgame");
  244. @entity_damage
  245. attacker = player.getFromDamageSource(damage_source);
  246. if(attacker == null) {
  247. goto("checkgame");
  248. }
  249. if(isSameTeam(attacker, player)) {
  250. cancel = true;
  251. }
  252. goto("checkgame");
  253. @player_giveup
  254. @player_quit
  255. player_name = player.getName(player);
  256. team = getTeamFromPlayer(player);
  257. color = getColorCode(team);
  258. minigame.speakAll(gamename, string.concat(color, player_name, " §ehas left the game."));
  259. teamlist = getTeamList(team);
  260. list.remove(teamlist, player_name);
  261. map.remove(players, player_name);
  262. showstats(player, false);
  263. script = script.getFromId(script_id);
  264. minigame.kickplayer(script, player);
  265. if(list.getSize(teamlist) == 0) {
  266. teamGameover(team);
  267. }
  268. goto("checkgame");
  269. @block_click
  270. if(action == "RIGHT_CLICK_BLOCK") {
  271. if(material.equals(block.getType(block), beacon_mat)) {
  272. cancel = true;
  273. }
  274. goto("checkgame");
  275. }
  276. if(action == "LEFT_CLICK_BLOCK") {
  277. if(material.equals(block.getType(block), beacon_mat)) {
  278. living.addEffect(player, "SLOW_DIGGING", 1200, 0.5, false);
  279. goto("checkgame");
  280. }
  281. }
  282. living.clearEffects(player);
  283. goto("checkgame");
  284. @block_break
  285. cancel = true;
  286. block_loc = block.getLocation(block);
  287. if(set.contains(protected_locs, block_loc)) {
  288. goto("checkgame");
  289. }
  290. //spawns are 3D radius protected
  291. for(i = 0; i < list.getSize(spawnlocs); i++) {
  292. spawn_loc = list.getIndex(spawnlocs, i);
  293. mod_block_loc = loc.mod(block_loc, 0.5, 0, 0.5);
  294. if(loc.distance(mod_block_loc, spawn_loc) <= spawn_protection_radius) {
  295. goto("checkgame");
  296. }
  297. }
  298. if(material.equals(block.getType(block), beacon_mat)) {
  299. team = getTeamFromPlayer(player);
  300. //Cores cannot be broken by the own team.
  301. l = list.getIndex(cores, team);
  302. if(list.contains(l, block_loc)) {
  303. goto("checkgame");
  304. }
  305. block.setMaterial(block, air_mat);
  306. block_type = block.getType(block);
  307. map.add(brokenblocks, block, beacon_mat);
  308. player_uuid = player.getUuid(player);
  309. map.add(broken_cores, player_uuid, map.getOrDefault(broken_cores, player_uuid, 0) + 1);
  310. removeCore(block_loc);
  311. goto("checkgame");
  312. }
  313. if(list.contains(placedblocks, block)) {
  314. cancel = false;
  315. list.remove(placedblocks, block);
  316. goto("checkgame");
  317. }
  318. block_type = block.getType(block);
  319. cancel = false;
  320. map.add(brokenblocks, block, block_type);
  321. goto("checkgame");
  322. @block_place
  323. cancel = true;
  324. block_loc = block.getLocation(block);
  325. if(set.contains(protected_locs, block_loc)) {
  326. goto("checkgame");
  327. }
  328. //spawns are 3D radius protected
  329. for(i = 0; i < list.getSize(spawnlocs); i++) {
  330. spawn_loc = list.getIndex(spawnlocs, i);
  331. mod_block_loc = loc.mod(block_loc, 0.5, 0, 0.5);
  332. if(loc.distance(mod_block_loc, spawn_loc) <= spawn_protection_radius) {
  333. goto("checkgame");
  334. }
  335. }
  336. cancel = false;
  337. list.add(placedblocks, block);
  338. goto("checkgame");
  339. function isSameTeam(player1, player2) {
  340. return getTeamFromPlayer(player1) == getTeamFromPlayer(player2);
  341. }
  342. function getTeamFromPlayer(player) {
  343. return map.get($players, player.getName(player));
  344. }
  345. function teamGameover(team) {
  346. tempcolortext = map.get($teamcolortext, team);
  347. minigame.speakAll($gamename, string.concat("§cTeam ", tempcolortext, "§c has been eliminated."));
  348. list.remove($allteams, team);
  349. updateDisplay();
  350. if(list.getSize($allteams) == 1) {
  351. $endtime = time.getMillis();
  352. kickteam(team, false);
  353. win_team = list.getIndex($allteams, 0);
  354. tempcolortext = map.get($teamcolortext, win_team);
  355. minigame.speakAll($gamename, string.concat("§cTeam ", tempcolortext, "§c won."));
  356. resetGameField();
  357. kickteam(win_team, true);
  358. minigame.clearItems($middleloc, $radius);
  359. script = script.getFromId($script_id);
  360. minigame.term(script, $gamesignloc);
  361. term();
  362. }
  363. kickteam(team, false);
  364. }
  365. function kickteam(team, won) {
  366. teamlist = getTeamList(team);
  367. for(i = 0; i < list.getSize(teamlist); i++) {
  368. p_name = list.getIndex(teamlist, i);
  369. p = read.player(p_name);
  370. showstats(p, won);
  371. script = script.getFromId($script_id);
  372. minigame.kickplayer(script, p);
  373. }
  374. }
  375. function getTeamList(team) {
  376. return map.get($team_lists, team);
  377. }
  378. function showstats(player, won) { //Player player, Boolean won
  379. player_id = player.getId(player);
  380. last_record = ranking.getPoints($rankingtable, player_id) + map.getOrDefault($broken_cores, player.getUuid(player), 0);
  381. ranking.setPoints($rankingtable, player_id, last_record);
  382. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  383. minigame.setPlayed(player_id, $game_short, playedgames);
  384. wongames = minigame.getWon(player, $game_short);
  385. if(won) {
  386. wongames++;
  387. minigame.setWon(player, $game_short, wongames);
  388. }
  389. minigame.statsHeader(player, $gamename, "§e");
  390. minigame.statsLine(player, "§e", "Broken cores", string.number(last_record));
  391. minigame.statsLine(player, "§e", "Played games", string.number(playedgames));
  392. minigame.statsLine(player, "§e", "Won games", string.number(wongames));
  393. if(playedgames != 0) {
  394. minigame.statsLine(player, "§e", "Win ratio", string.concat(string.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
  395. }
  396. }
  397. function equipPlayer(player) {
  398. player.clearInventory(player);
  399. inv = player.getInv(player);
  400. s = array.getSize($default_inv);
  401. for(i = 0; i < s; i++) {
  402. inv.setItem(inv, $default_inv[i, 0], $default_inv[i, 1]);
  403. }
  404. team = getTeamFromPlayer(player);
  405. clothescolor = map.get($clothescode, team);
  406. living.setEquip(player, slot.getChest(), read.item(string.concat("{Count:1b,id:'minecraft:leather_chestplate',tag:{Damage:0,display:{color:", clothescolor, "}}}")));
  407. }
  408. function resetGameField() {
  409. iter = iterator($placedblocks);
  410. while(hasNext(iter)) {
  411. block.setMaterial(next(iter), $air_mat);
  412. }
  413. iter = map.iterator($brokenblocks);
  414. while(hasNext(iter)) {
  415. element = next(iter);
  416. block = map.getKey(element);
  417. type = map.getValue(element);
  418. block.setMaterial(block, type);
  419. }
  420. }
  421. function updateDisplay() {
  422. sb.clearGameAll();
  423. minigame.displayAll(99, $gamename);
  424. index = 98;
  425. for(i = 0; i < list.getSize($allteams); i++) {
  426. team = list.getIndex($allteams, i);
  427. color = getColorCode(team);
  428. teamText = map.get($teamcolortext2, team);
  429. active_cores_list = list.getIndex($active_cores, i);
  430. cores_list = list.getIndex($cores, i);
  431. for(h = 0; h < list.getSize(cores_list); h++) {
  432. core = list.getIndex(cores_list, h);
  433. if(list.contains(active_cores_list, core)) {
  434. foo = "§2✔";
  435. } else {
  436. foo = "§4✘";
  437. }
  438. minigame.displayAll(index--, string.concat(color, teamText, " Core ", foo));
  439. }
  440. }
  441. minigame.displayAll(index, sb.getSpacer());
  442. }
  443. function getColorCode(team) {
  444. return map.get($colorcodes, team);
  445. }
  446. function removeCore(block_loc) {
  447. for(i = 0; i < list.getSize($player_list); i++) {
  448. p = player.get(list.getIndex($player_list, i));
  449. sound.spawnForPlayer(p, $bed_sound, $sound_category_ambient);
  450. }
  451. for(i = 0; i < list.getSize($active_cores); i++) {
  452. cores_list = list.getIndex($active_cores, i);
  453. if(list.contains(cores_list, block_loc)) {
  454. list.remove(cores_list, block_loc);
  455. color = getColorCode(i);
  456. tempcolortext = map.get($teamcolortext2, i);
  457. minigame.speakAll($gamename, string.concat("A ", color, tempcolortext, " Core §rhas been destroyed."));
  458. }
  459. if(list.getSize(cores_list) == 0) {
  460. teamGameover(i);
  461. }
  462. }
  463. updateDisplay();
  464. }