summaryrefslogtreecommitdiff
path: root/utils/tele.js
diff options
context:
space:
mode:
Diffstat (limited to 'utils/tele.js')
-rw-r--r--utils/tele.js59
1 files changed, 55 insertions, 4 deletions
diff --git a/utils/tele.js b/utils/tele.js
index 6794af2..89c62c7 100644
--- a/utils/tele.js
+++ b/utils/tele.js
@@ -16,13 +16,14 @@ place
[x] set tile 0x9b
[x] remove from inventory
inventory UI
-[ ]
-0x9b onstep
-[ ]
-go through first time
+[x]
+[x] unexpected inventory UI overhaul
+0x9b onstep (first time)
[ ] get new coord
[ ] generate new chunk
[ ] generate new tele
+0x9b onstep (routine)
+[ ]
*/
const doorPath = "doors.txt";
@@ -71,6 +72,56 @@ doorUtils.findDoorIdWithPos = function(pos) {
}
return null;
};
+doorUtils.findDoorWithPos = function(pos) {
+ let doorid = doorUtils.findDoorIdWithPos(pos);
+ if (doorid === null) return null;
+ return doors[doorid];
+};
+
+doorUtils.getDestCoord = function(doorid) {
+ // needs to handle chunk generation
+ if (doorid === null) console.log("ladkfjajsf");
+ let door = doors[doorid];
+ if (door.destId === null) { // generate new chunk
+ for (let r = 4000; r <= 64000; r *= 2) {
+ let th = Math.random() * 2 * Math.PI;
+ let xoff = Math.cos(th) * r;
+ let yoff = Math.sin(th) * r;
+ let chunkSize = 128;
+ let cx = Math.floor((door.pos.x + xoff) / chunkSize) * chunkSize;
+ let cy = Math.floor((door.pos.y + yoff) / chunkSize) * chunkSize;
+ let pos = new Pos(cx, cy);
+ let chunkExist = chunkUtils.checkChunkExist(pos);
+ if (chunkExist) continue;
+ let chunk = chunkUtils.getChunk(pos);
+ pos = new Pos(pos.x,pos.y);
+ pos.add(new Pos(
+ Math.floor(Math.random() * chunkSize),
+ Math.floor(Math.random() * chunkSize),
+ ));
+ chunk.generateAllTiles();
+ chunk.setTile(pos, 0x9b);
+ let destid = doorUtils.registerDoor(pos);
+ doors[destid].destId = doorid;
+ door.destId = destid;
+ return pos;
+ }
+ console.warn("lkadsfald");
+ return null;
+ } else {
+ let destdoor = doors[door.destId];
+ if (destdoor.postype == "player") {
+ // handle later...
+ // if the player is online, teleport to player
+ // otherwise null
+ } else if (destdoor.postype == "coordinate") {
+ return new Pos(destdoor.pos.x, destdoor.pos.y);
+ } else {
+ console.error("laksflsdf");
+ return null;
+ }
+ }
+};
doorUtils.removeDoorFromInventory = function(inv, doorid) {
let m = inv.tileCountMap[0x9b];