colony.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. -------------------------------------------------------------------
  3. KONZEPT
  4. -------------------------------------------------------------------
  5. Spieler können eine Kolonie gründen (16x16) und danach beliebig oft in jede Himmelsrichtung um 16 Blöcke erweitern.
  6. Auf dem Koloniegebiet befindet sich ein Nexus. Diesen gilt es zu schützen.
  7. Kolonien können sich gegenseitig angreifen. Wird eine Kolonie besiegt, wird sie entfernt.
  8. Produktionsstätten werden gegen Kosten auf dem Koloniegebiet gesetzt und können geupgradet werden.
  9. Diese Produktionsstätten produzieren Items.
  10. -------------------------------------------------------------------
  11. */
  12. /* TODO
  13. Datenstruktur verändern
  14. colonyplayer
  15. - player_id
  16. - plot_id
  17. - back_loc
  18. - nexus_lox
  19. (chunklocs sind aus plottable auszulesen)
  20. *) Nexus Break canceln
  21. *) Geldeinnahme-Quelle überlegen
  22. *) Funktion für Geldeinnahme, - ausgabe schreiben
  23. *) Kosten für Koloniegründung einbinden
  24. *) Kosten für Kolonieerweiterung einbinden
  25. *) Befehl für Hausaktivierung
  26. *) Befehl für Hausupgrade
  27. */
  28. event.load("portal");
  29. event.load("custom_command");
  30. event.load("block_break");
  31. event.load("block_place");
  32. event.load("block_click");
  33. event.load("player_hurt");
  34. event.load("player_move");
  35. event.load("player_death");
  36. event.load("player_respawn");
  37. command.add("co");
  38. command.add("colony");
  39. set.new(gamemasters);
  40. set.add(gamemasters, "e41b5335-3c74-46e9-a6c5-dafc6334a477"); //marvinius
  41. set.new(safeplotids);
  42. set.add(safeplotids, 144); //Spawn
  43. //set.add(safeplotids, ); //Hausvorlagen
  44. set.new(nexusset);
  45. gdmap.toTable(table, "colony", "nexuslocs");
  46. for(i = 0; i <= table.getSize(table) - 1; i++) {
  47. set.add(nexusset, read.location(table.get(table, i, 1)));
  48. }
  49. gamesworld = world.get("games");
  50. colonyworld = world.get("colony");
  51. nexus = read.item("km:artefact");
  52. airitem = read.item("minecraft:air");
  53. gamename = "§6Colony";
  54. serverspawnloc = read.location(ggv("SERVER", "serverspawn")); //Hauptspawn
  55. colonyspawnloc = loc.new(colonyworld, 1048, 43, 946);
  56. templateloc = loc.new(colonyworld, 1048, 43, 946);
  57. moveidfromworldspawn = event.addMoveData(loc.new(gamesworld, -399, 89, 110), loc.new(gamesworld, -400, 91, 112), 5, -1);
  58. msg("dev", "§bColony §rwurde geladen");
  59. @wait
  60. wait();
  61. if(event == "player_move") {
  62. if(id == moveidfromworldspawn) {
  63. entity.teleport(player, colonyspawnloc);
  64. }
  65. goto("wait");
  66. }
  67. ignoreGoto(event);
  68. goto("wait");
  69. @block_break
  70. if(set.contains(nexusset, block_loc)) {
  71. cancel = true;
  72. }
  73. goto("wait");
  74. @custom_command
  75. if(command == "co" || command == "colony") {
  76. size = list.getSize(args);
  77. if(size == 0) {
  78. player.speak(player, gamename, "§r/colony... (alias /co)");
  79. msg(player, "§6- create §rGründet eine Kolonie");
  80. msg(player, "§6- expand §rKolonie erweitern");
  81. msg(player, "§6- nexus newpos §rNexus umsetzen");
  82. //msg(player, "§6- build ... §rHäuser bauen");
  83. //msg(player, "§6- upgrade ... §rHäuser upgraden");
  84. //msg(player, "§6- attack [spielername] §rFremde Kolonie attackieren");
  85. msg(player, "§6- tp template §rTeleport zu den Hausvorlagen");
  86. msg(player, "§6- tp home §rZum Nexus teleportieren");
  87. msg(player, "§6- tp nexus §rZum Nexus teleportieren");
  88. msg(player, "§6- tp back §rTeleportiert zur letzten gesetzten Back-Position");
  89. if(set.contains(gamemasters, player.getUuid(player))) {
  90. msg(player, "§6- reset §rResettet Colony");
  91. }
  92. goto("wait");
  93. }
  94. arg0 = list.getIndex(args, 0);
  95. if(arg0 == "expand") {
  96. player_loc = entity.getLocation(player);
  97. uuid = player.getUuid(player);
  98. //Check ob eigene Kolonie
  99. if(!isOwnColony(player_loc)) {
  100. player.speak(player, gamename, "Du befindest dich nicht auf deiner eigenen Kolonie");
  101. goto("wait");
  102. }
  103. //Blickrichtung herausfinden
  104. yaw = loc.getYaw(player_loc);
  105. direction = getDirection(yaw);
  106. if(direction == null) {
  107. player.speak(player, gamename, "Blickrichtung zu ungenau");
  108. goto("wait");
  109. }
  110. //Bisherige GS-Ecken aus Datenbank abrufen
  111. edgeloc1 = read.location(gdmap.get("colony", "edgeloc1", uuid));
  112. edgeloc2 = read.location(gdmap.get("colony", "edgeloc2", uuid));
  113. //Ecken des neuen Bereichs definieren
  114. if(direction == "east") {
  115. tempedge2 = loc.mod(edgeloc2, 16, 0, 0);
  116. edgeloc2 = tempedge2;
  117. tempedge1 = loc.new(colonyworld, loc.getX(edgeloc2) + 1, 0, loc.getZ(edgeloc1));
  118. } elseif(direction == "south") {
  119. tempedge2 = loc.mod(edgeloc2, 0, 0, 16);
  120. edgeloc2 = tempedge2;
  121. tempedge1 = loc.new(colonyworld, loc.getX(edgeloc1), 0, loc.getZ(edgeloc2) + 1);
  122. } elseif(direction == "west") {
  123. tempedge1 = loc.mod(edgeloc1, -16, 0, 0);
  124. edgeloc1 = tempedge1;
  125. tempedge2 = loc.new(colonyworld, loc.getX(edgeloc1) - 1, 255, loc.getZ(edgeloc2));
  126. } elseif(direction == "north") {
  127. tempedge1 = loc.mod(edgeloc1, 0, 0, -16);
  128. edgeloc1 = tempedge1;
  129. tempedge2 = loc.new(colonyworld, loc.getX(edgeloc2), 255, loc.getZ(edgeloc1) - 1);
  130. }
  131. //neuen Bereich auf Überschneidungen checken
  132. if(plot.doesIntersect(tempedge1, tempedge2)) {
  133. player.speak(player, gamename, "Deine Kolonie würde sich mit anderen Grundstücken überschneiden");
  134. goto("wait");
  135. }
  136. //Plot- und Datenbank-Handling
  137. oldplotid = gdmap.get("colony", "plotids", uuid);
  138. command("plot remove ", text.number(oldplotid));
  139. plot.add(edgeloc1, edgeloc2, player_name);
  140. plotid = getPlotId(player_loc);
  141. command("plot name ", plotid, " Kolonie von ", player_name);
  142. gdmap.add("colony", "plotids", uuid, plotid);
  143. gdmap.add("colony", "edgeloc1", uuid, text.location(edgeloc1));
  144. gdmap.add("colony", "edgeloc2", uuid, text.location(edgeloc2));
  145. player.speak(player, gamename, "Kolonie erweitert");
  146. goto("wait");
  147. }
  148. if(arg0 == "nexus") {
  149. if(size == 1) {
  150. msg(player, "§6- nexus newpos §rNexus umsetzen");
  151. goto("wait");
  152. }
  153. arg1 = list.getIndex(args, 1);
  154. if(arg1 == "newpos") {
  155. player_loc = entity.getLocation(player);
  156. uuid = player.getUuid(player);
  157. if(!isOwnColony(player_loc)) {
  158. player.speak(player, gamename, "Du befindest dich nicht auf deiner eigenen Kolonie");
  159. goto("wait");
  160. }
  161. yetloc = read.location(gdmap.get("colony", "nexuslocs", uuid));
  162. block.set(yetloc, airitem);
  163. set.remove(nexusset, yetloc);
  164. w = loc.getCoord(player_loc, "w");
  165. x = loc.getCoord(player_loc, "bx");
  166. y = loc.getCoord(player_loc, "by");
  167. z = loc.getCoord(player_loc, "bz");
  168. newpos = concat(w, ":", x, ":", y, ":", z);
  169. gdmap.add("colony", "nexuslocs", uuid, newpos);
  170. newposloc = read.location(newpos);
  171. set.add(nexusset, newposloc);
  172. block.set(newposloc, nexus);
  173. player.speak(player, gamename, "Nexus umgesetzt");
  174. goto("wait");
  175. }
  176. goto("wait");
  177. }
  178. if(arg0 == "tp") {
  179. if(size == 1) {
  180. msg(player, "§6- tp template §rTeleport zu den Hausvorlagen");
  181. msg(player, "§6- tp home §rZum Nexus teleportieren");
  182. msg(player, "§6- tp back §rTeleportiert zur letzten gesetzten Back-Position");
  183. goto("wait");
  184. }
  185. arg1 = list.getIndex(args, 1);
  186. if(arg1 == "template") {
  187. setBackLocation(entity.getLocation(player));
  188. entity.teleport(player, templateloc);
  189. player.speak(player, gamename, "Teleport erfolgreich");
  190. goto("wait");
  191. }
  192. if(arg1 == "home") {
  193. //Keine Back-Position setzen
  194. uuid = player.getUuid(player);
  195. nexusloc = gdmap.get("colony", "nexuslocs", uuid);
  196. if(nexusloc == null) {
  197. player.speak(player, gamename, "Du hast bisher keine Kolonie gegründet");
  198. goto("wait");
  199. }
  200. nexusloc = read.location(nexusloc);
  201. entity.teleport(player, nexusloc);
  202. player.speak(player, gamename, "Teleport erfolgreich");
  203. goto("wait");
  204. }
  205. if(arg1 == "back") {
  206. uuid = player.getUuid(player);
  207. backloc = gdmap.get("colony", "backlocs", uuid);
  208. if(backloc == null) {
  209. player.speak(player, gamename, "Keine Back-Position vorhanden");
  210. goto("wait");
  211. }
  212. backloc = read.location(backloc);
  213. setBackLocation(entity.getLocation(player));
  214. entity.teleport(player, backloc);
  215. player.speak(player, gamename, "Teleport erfolgreich");
  216. goto("wait");
  217. }
  218. goto("wait");
  219. }
  220. if(arg0 == "create") {
  221. player_loc = entity.getLocation(player);
  222. gdmap.toTable(table, "colony", "nexuslocs");
  223. for(i = 0; i <= table.getSize(table) - 1; i++) {
  224. distance = loc.distance(read.location(table.get(gildenblocktable, i, 1)), block_loc);
  225. if(distance < 1100) {
  226. player.speak(player, gamename, "Nexus müssen mindestens 100 Blöcke voneinander entfernt sein (Aktuell: ", text.number(math.roundUp(distance)), ")");
  227. cancel = true;
  228. goto("wait");
  229. }
  230. }
  231. getChunkLocs(player_loc);
  232. if(plot.doesIntersect(chunkloc1, chunkloc2)) {
  233. player.speak(player, gamename, "Deine Kolonie würde sich mit anderen Grundstücken überschneiden");
  234. goto("wait");
  235. }
  236. plot.add(chunkloc1, chunkloc2, player_name);
  237. plotid = getPlotId(player_loc);
  238. command("plot name ", plotid, " Kolonie von ", player_name);
  239. uuid = player.getUuid(player);
  240. w = loc.getCoord(player_loc, "w");
  241. x = loc.getCoord(player_loc, "bx");
  242. y = loc.getCoord(player_loc, "by");
  243. z = loc.getCoord(player_loc, "bz");
  244. newpos = concat(w, ":", x, ":", y, ":", z);
  245. gdmap.add("colony", "nexuslocs", uuid, newpos);
  246. newposloc = read.location(newpos);
  247. set.add(nexusset, newposloc);
  248. gdmap.add("colony", "plotids", uuid, plotid);
  249. gdmap.add("colony", "edgeloc1", uuid, text.location(chunkloc1));
  250. gdmap.add("colony", "edgeloc2", uuid, text.location(chunkloc2));
  251. block.set(newposloc, nexus);
  252. player.speak(player, gamename, "Hauptquartier erstellt, Nexus gesetzt");
  253. goto("wait");
  254. }
  255. if(arg0 == "reset") {
  256. if(!set.contains(gamemasters, player.getUuid(player))) {
  257. player.speak(player, gamename, "Nur DER EINE kann diesen Befehl ausführen");
  258. goto("wait");
  259. }
  260. //Grundstücke und Nexus entfernen
  261. gdmap.toTable(table, "colony", "plotids");
  262. for(i = 0; i <= table.getSize(table) - 1; i++) {
  263. uuid = table.get(table, i, 0);
  264. plotid = table.get(table, i, 1);
  265. nexusloc = read.location(gdmap.get("colony", "nexuslocs", uuid));
  266. block.set(nexusloc, airitem);
  267. command("plot remove ", text.number(plotid));
  268. }
  269. gdmap.removeAll("colony");
  270. //Alle Spieler zum Spawn teleportieren
  271. players.toWorldList(worldlist, colonyworld);
  272. for(i = 0; i <= list.getSize(worldlist) - 1; i++) {
  273. p = list.getIndex(worldlist, i);
  274. display.reset(p);
  275. entity.teleport(p, serverspawnloc);
  276. player.clearInventory(p);
  277. }
  278. players.toWorldList(worldlist, colonyworld);
  279. size = list.getSize(worldlist);
  280. if(size > 0) {
  281. msg("dev", concat("§b§", size, " §cSpieler in der Welt!"));
  282. }
  283. msg("dev", "§cScript neu starten");
  284. term();
  285. }
  286. }
  287. goto("wait");
  288. @portal
  289. goto("wait");
  290. function getChunkLocs(loc) {
  291. player_x = loc.getX(loc);
  292. player_z = loc.getZ(loc);
  293. chunk_x = math.roundDown(player_x / 16) * 16;
  294. chunk_z = math.roundDown(player_z / 16) * 16;
  295. $chunkloc1 = loc.new($colonyworld, chunk_x, 0, chunk_z);
  296. $chunkloc2 = loc.mod($chunkloc1, 15, 265, 15);
  297. return;
  298. }
  299. function isOwnColony(player_loc) {
  300. plotid = gdmap.get("colony", "plotids", $uuid);
  301. plotid2 = getPlotId(player_loc);
  302. if(plotid == plotid2) {
  303. return true;
  304. }
  305. return false;
  306. }
  307. function getDirection(yaw) {
  308. if(yaw > 240 && yaw < 300) {
  309. direction = "east";
  310. } elseif(yaw > 330 || yaw < 30) {
  311. direction = "south";
  312. } elseif(yaw > 60 && yaw < 120) {
  313. direction = "west";
  314. } elseif(yaw > 150 && yaw < 210) {
  315. direction = "north";
  316. } else {
  317. return null;
  318. }
  319. return direction;
  320. }
  321. function setBackLocation(loc) {
  322. gdmap.add("colony", "backlocs", uuid, text.location(loc));
  323. return;
  324. }
  325. /*
  326. DATENSTRUKTURVERZEICHNIS
  327. -------------------------------------------------------------------
  328. Datentyp Name Inhalt Anmerkung
  329. -------------------------------------------------------------------
  330. gdmap colony backlocs, uuid, loc Back-Positionen zu jedem Spieler. Bei Verlassen der Welt/des Servers resettet.
  331. gdmap colony plotids, uuid, plotid Plotids zu den Spielern
  332. gdmap colony nexuslocs, uuid, loc Nexus-Positionen jedes Spielers
  333. gdmap colony edgeloc1, uuid, loc Chunkloc 1 des Plots
  334. gdmap colony edgeloc2, uuid, loc Chunkloc 2 des Plots
  335. gvar colonyjoined Boolean Ob bereits Colony-Spieler
  336. set nexusset nexuslocs Nexus-Positionen (zum effizientem Break-Canceln)
  337. */