123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- /*
- -------------------------------------------------------------------
- KONZEPT
- -------------------------------------------------------------------
- Spieler können eine Kolonie gründen (16x16) und danach beliebig oft in jede Himmelsrichtung um 16 Blöcke erweitern.
- Auf dem Koloniegebiet befindet sich ein Nexus. Diesen gilt es zu schützen.
- Kolonien können sich gegenseitig angreifen. Wird eine Kolonie besiegt, wird sie entfernt.
- Produktionsstätten werden gegen Kosten auf dem Koloniegebiet gesetzt und können geupgradet werden.
- Diese Produktionsstätten produzieren Items.
- -------------------------------------------------------------------
- */
- /* TODO
- Datenstruktur verändern
- colonyplayer
- - player_id
- - plot_id
- - back_loc
- - nexus_lox
- (chunklocs sind aus plottable auszulesen)
- *) Nexus Break canceln
- *) Geldeinnahme-Quelle überlegen
- *) Funktion für Geldeinnahme, - ausgabe schreiben
- *) Kosten für Koloniegründung einbinden
- *) Kosten für Kolonieerweiterung einbinden
- *) Befehl für Hausaktivierung
- *) Befehl für Hausupgrade
- */
- event.load("portal");
- event.load("custom_command");
- event.load("block_break");
- event.load("block_place");
- event.load("block_click");
- event.load("player_hurt");
- event.load("player_move");
- event.load("player_death");
- event.load("player_respawn");
- command.add("co");
- command.add("colony");
- set.new(gamemasters);
- set.add(gamemasters, "e41b5335-3c74-46e9-a6c5-dafc6334a477"); //marvinius
- set.new(safeplotids);
- set.add(safeplotids, 144); //Spawn
- //set.add(safeplotids, ); //Hausvorlagen
- set.new(nexusset);
- gdmap.toTable(table, "colony", "nexuslocs");
- for(i = 0; i <= table.getSize(table) - 1; i++) {
- set.add(nexusset, read.location(table.get(table, i, 1)));
- }
- gamesworld = world.get("games");
- colonyworld = world.get("colony");
- nexus = read.item("km:artefact");
- airitem = read.item("minecraft:air");
- gamename = "§6Colony";
- serverspawnloc = read.location(ggv("SERVER", "serverspawn")); //Hauptspawn
- colonyspawnloc = loc.new(colonyworld, 1048, 43, 946);
- templateloc = loc.new(colonyworld, 1048, 43, 946);
- moveidfromworldspawn = event.addMoveData(loc.new(gamesworld, -399, 89, 110), loc.new(gamesworld, -400, 91, 112), 5, -1);
- msg("dev", "§bColony §rwurde geladen");
- @wait
- wait();
- if(event == "player_move") {
- if(id == moveidfromworldspawn) {
- entity.teleport(player, colonyspawnloc);
- }
- goto("wait");
- }
- ignoreGoto(event);
- goto("wait");
- @block_break
- if(set.contains(nexusset, block_loc)) {
- cancel = true;
- }
- goto("wait");
- @custom_command
- if(command == "co" || command == "colony") {
- size = list.getSize(args);
- if(size == 0) {
- player.speak(player, gamename, "§r/colony... (alias /co)");
- msg(player, "§6- create §rGründet eine Kolonie");
- msg(player, "§6- expand §rKolonie erweitern");
- msg(player, "§6- nexus newpos §rNexus umsetzen");
- //msg(player, "§6- build ... §rHäuser bauen");
- //msg(player, "§6- upgrade ... §rHäuser upgraden");
- //msg(player, "§6- attack [spielername] §rFremde Kolonie attackieren");
- msg(player, "§6- tp template §rTeleport zu den Hausvorlagen");
- msg(player, "§6- tp home §rZum Nexus teleportieren");
- msg(player, "§6- tp nexus §rZum Nexus teleportieren");
- msg(player, "§6- tp back §rTeleportiert zur letzten gesetzten Back-Position");
- if(set.contains(gamemasters, player.getUuid(player))) {
- msg(player, "§6- reset §rResettet Colony");
- }
- goto("wait");
- }
- arg0 = list.getIndex(args, 0);
- if(arg0 == "expand") {
- player_loc = entity.getLocation(player);
- uuid = player.getUuid(player);
- //Check ob eigene Kolonie
- if(!isOwnColony(player_loc)) {
- player.speak(player, gamename, "Du befindest dich nicht auf deiner eigenen Kolonie");
- goto("wait");
- }
- //Blickrichtung herausfinden
- yaw = loc.getYaw(player_loc);
- direction = getDirection(yaw);
- if(direction == null) {
- player.speak(player, gamename, "Blickrichtung zu ungenau");
- goto("wait");
- }
- //Bisherige GS-Ecken aus Datenbank abrufen
- edgeloc1 = read.location(gdmap.get("colony", "edgeloc1", uuid));
- edgeloc2 = read.location(gdmap.get("colony", "edgeloc2", uuid));
- //Ecken des neuen Bereichs definieren
- if(direction == "east") {
- tempedge2 = loc.mod(edgeloc2, 16, 0, 0);
- edgeloc2 = tempedge2;
- tempedge1 = loc.new(colonyworld, loc.getX(edgeloc2) + 1, 0, loc.getZ(edgeloc1));
- } elseif(direction == "south") {
- tempedge2 = loc.mod(edgeloc2, 0, 0, 16);
- edgeloc2 = tempedge2;
- tempedge1 = loc.new(colonyworld, loc.getX(edgeloc1), 0, loc.getZ(edgeloc2) + 1);
- } elseif(direction == "west") {
- tempedge1 = loc.mod(edgeloc1, -16, 0, 0);
- edgeloc1 = tempedge1;
- tempedge2 = loc.new(colonyworld, loc.getX(edgeloc1) - 1, 255, loc.getZ(edgeloc2));
- } elseif(direction == "north") {
- tempedge1 = loc.mod(edgeloc1, 0, 0, -16);
- edgeloc1 = tempedge1;
- tempedge2 = loc.new(colonyworld, loc.getX(edgeloc2), 255, loc.getZ(edgeloc1) - 1);
- }
- //neuen Bereich auf Überschneidungen checken
- if(plot.doesIntersect(tempedge1, tempedge2)) {
- player.speak(player, gamename, "Deine Kolonie würde sich mit anderen Grundstücken überschneiden");
- goto("wait");
- }
- //Plot- und Datenbank-Handling
- oldplotid = gdmap.get("colony", "plotids", uuid);
- command("plot remove ", text.number(oldplotid));
- plot.add(edgeloc1, edgeloc2, player_name);
- plotid = getPlotId(player_loc);
- command("plot name ", plotid, " Kolonie von ", player_name);
- gdmap.add("colony", "plotids", uuid, plotid);
- gdmap.add("colony", "edgeloc1", uuid, text.location(edgeloc1));
- gdmap.add("colony", "edgeloc2", uuid, text.location(edgeloc2));
- player.speak(player, gamename, "Kolonie erweitert");
- goto("wait");
- }
- if(arg0 == "nexus") {
- if(size == 1) {
- msg(player, "§6- nexus newpos §rNexus umsetzen");
- goto("wait");
- }
- arg1 = list.getIndex(args, 1);
- if(arg1 == "newpos") {
- player_loc = entity.getLocation(player);
- uuid = player.getUuid(player);
- if(!isOwnColony(player_loc)) {
- player.speak(player, gamename, "Du befindest dich nicht auf deiner eigenen Kolonie");
- goto("wait");
- }
- yetloc = read.location(gdmap.get("colony", "nexuslocs", uuid));
- block.set(yetloc, airitem);
- set.remove(nexusset, yetloc);
- w = loc.getCoord(player_loc, "w");
- x = loc.getCoord(player_loc, "bx");
- y = loc.getCoord(player_loc, "by");
- z = loc.getCoord(player_loc, "bz");
- newpos = concat(w, ":", x, ":", y, ":", z);
- gdmap.add("colony", "nexuslocs", uuid, newpos);
- newposloc = read.location(newpos);
- set.add(nexusset, newposloc);
- block.set(newposloc, nexus);
- player.speak(player, gamename, "Nexus umgesetzt");
- goto("wait");
- }
- goto("wait");
- }
- if(arg0 == "tp") {
- if(size == 1) {
- msg(player, "§6- tp template §rTeleport zu den Hausvorlagen");
- msg(player, "§6- tp home §rZum Nexus teleportieren");
- msg(player, "§6- tp back §rTeleportiert zur letzten gesetzten Back-Position");
- goto("wait");
- }
- arg1 = list.getIndex(args, 1);
- if(arg1 == "template") {
- setBackLocation(entity.getLocation(player));
- entity.teleport(player, templateloc);
- player.speak(player, gamename, "Teleport erfolgreich");
- goto("wait");
- }
- if(arg1 == "home") {
- //Keine Back-Position setzen
- uuid = player.getUuid(player);
- nexusloc = gdmap.get("colony", "nexuslocs", uuid);
- if(nexusloc == null) {
- player.speak(player, gamename, "Du hast bisher keine Kolonie gegründet");
- goto("wait");
- }
- nexusloc = read.location(nexusloc);
- entity.teleport(player, nexusloc);
- player.speak(player, gamename, "Teleport erfolgreich");
- goto("wait");
- }
- if(arg1 == "back") {
- uuid = player.getUuid(player);
- backloc = gdmap.get("colony", "backlocs", uuid);
- if(backloc == null) {
- player.speak(player, gamename, "Keine Back-Position vorhanden");
- goto("wait");
- }
- backloc = read.location(backloc);
- setBackLocation(entity.getLocation(player));
- entity.teleport(player, backloc);
- player.speak(player, gamename, "Teleport erfolgreich");
- goto("wait");
- }
- goto("wait");
- }
- if(arg0 == "create") {
- player_loc = entity.getLocation(player);
- gdmap.toTable(table, "colony", "nexuslocs");
- for(i = 0; i <= table.getSize(table) - 1; i++) {
- distance = loc.distance(read.location(table.get(gildenblocktable, i, 1)), block_loc);
- if(distance < 1100) {
- player.speak(player, gamename, "Nexus müssen mindestens 100 Blöcke voneinander entfernt sein (Aktuell: ", text.number(math.roundUp(distance)), ")");
- cancel = true;
- goto("wait");
- }
- }
- getChunkLocs(player_loc);
- if(plot.doesIntersect(chunkloc1, chunkloc2)) {
- player.speak(player, gamename, "Deine Kolonie würde sich mit anderen Grundstücken überschneiden");
- goto("wait");
- }
- plot.add(chunkloc1, chunkloc2, player_name);
- plotid = getPlotId(player_loc);
- command("plot name ", plotid, " Kolonie von ", player_name);
- uuid = player.getUuid(player);
- w = loc.getCoord(player_loc, "w");
- x = loc.getCoord(player_loc, "bx");
- y = loc.getCoord(player_loc, "by");
- z = loc.getCoord(player_loc, "bz");
- newpos = concat(w, ":", x, ":", y, ":", z);
- gdmap.add("colony", "nexuslocs", uuid, newpos);
- newposloc = read.location(newpos);
- set.add(nexusset, newposloc);
- gdmap.add("colony", "plotids", uuid, plotid);
- gdmap.add("colony", "edgeloc1", uuid, text.location(chunkloc1));
- gdmap.add("colony", "edgeloc2", uuid, text.location(chunkloc2));
- block.set(newposloc, nexus);
- player.speak(player, gamename, "Hauptquartier erstellt, Nexus gesetzt");
- goto("wait");
- }
- if(arg0 == "reset") {
- if(!set.contains(gamemasters, player.getUuid(player))) {
- player.speak(player, gamename, "Nur DER EINE kann diesen Befehl ausführen");
- goto("wait");
- }
- //Grundstücke und Nexus entfernen
- gdmap.toTable(table, "colony", "plotids");
- for(i = 0; i <= table.getSize(table) - 1; i++) {
- uuid = table.get(table, i, 0);
- plotid = table.get(table, i, 1);
- nexusloc = read.location(gdmap.get("colony", "nexuslocs", uuid));
- block.set(nexusloc, airitem);
- command("plot remove ", text.number(plotid));
- }
- gdmap.removeAll("colony");
- //Alle Spieler zum Spawn teleportieren
- players.toWorldList(worldlist, colonyworld);
- for(i = 0; i <= list.getSize(worldlist) - 1; i++) {
- p = list.getIndex(worldlist, i);
- display.reset(p);
- entity.teleport(p, serverspawnloc);
- player.clearInventory(p);
- }
- players.toWorldList(worldlist, colonyworld);
- size = list.getSize(worldlist);
- if(size > 0) {
- msg("dev", concat("§b§", size, " §cSpieler in der Welt!"));
- }
- msg("dev", "§cScript neu starten");
- term();
- }
- }
- goto("wait");
- @portal
- goto("wait");
- function getChunkLocs(loc) {
- player_x = loc.getX(loc);
- player_z = loc.getZ(loc);
- chunk_x = math.roundDown(player_x / 16) * 16;
- chunk_z = math.roundDown(player_z / 16) * 16;
- $chunkloc1 = loc.new($colonyworld, chunk_x, 0, chunk_z);
- $chunkloc2 = loc.mod($chunkloc1, 15, 265, 15);
- return;
- }
- function isOwnColony(player_loc) {
- plotid = gdmap.get("colony", "plotids", $uuid);
- plotid2 = getPlotId(player_loc);
- if(plotid == plotid2) {
- return true;
- }
- return false;
- }
- function getDirection(yaw) {
- if(yaw > 240 && yaw < 300) {
- direction = "east";
- } elseif(yaw > 330 || yaw < 30) {
- direction = "south";
- } elseif(yaw > 60 && yaw < 120) {
- direction = "west";
- } elseif(yaw > 150 && yaw < 210) {
- direction = "north";
- } else {
- return null;
- }
- return direction;
- }
- function setBackLocation(loc) {
- gdmap.add("colony", "backlocs", uuid, text.location(loc));
- return;
- }
- /*
- DATENSTRUKTURVERZEICHNIS
- -------------------------------------------------------------------
- Datentyp Name Inhalt Anmerkung
- -------------------------------------------------------------------
- gdmap colony backlocs, uuid, loc Back-Positionen zu jedem Spieler. Bei Verlassen der Welt/des Servers resettet.
- gdmap colony plotids, uuid, plotid Plotids zu den Spielern
- gdmap colony nexuslocs, uuid, loc Nexus-Positionen jedes Spielers
- gdmap colony edgeloc1, uuid, loc Chunkloc 1 des Plots
- gdmap colony edgeloc2, uuid, loc Chunkloc 2 des Plots
- gvar colonyjoined Boolean Ob bereits Colony-Spieler
- set nexusset nexuslocs Nexus-Positionen (zum effizientem Break-Canceln)
- */
|