Переглянути джерело

For some reason still not triggering on 100% chance all the time, no idea why

Reddo 5 роки тому
батько
коміт
5617ba8f8c

+ 23 - 3
app/World/Classes/RandomDungeons/RegionRandom.ts

@@ -111,17 +111,37 @@ class RegionRandom extends Region {
             placedRooms.forEach((room : RoomRandom) => {
                 let myCoordinates = region.map.getCoordinates(room);
                 let directionShuffler = new Shuffler<number>(room.connectableOn.slice(0), RegionRandom.rng);
-                for (let direction = directionShuffler.getOne(); direction != undefined && (RegionRandom.rng() * 100) <= room.extraConnectionChance; direction = directionShuffler.getOne()) {
+                // use greater connection chance
+                for (let direction = directionShuffler.getOne(); direction != undefined; direction = directionShuffler.getOne()) {
+                    let chance1 = room.extraConnectionChance;
                     if (room.connections[direction] == undefined) {
                         let otherCoordinates = Room.shift(myCoordinates, direction);
                         let otherRoom = region.map.getRoom(otherCoordinates[0], otherCoordinates[1]);
                         if (otherRoom != undefined && otherRoom.randomizable
                             && otherRoom.isConnectableOn(OppositeDirection[Direction[direction]])
-                            && (RegionRandom.rng() * 100) <= otherRoom.extraConnectionChance) {
-                            room.mapRoom(otherRoom, direction);
+                        ) {
+                            let chance2 = otherRoom.extraConnectionChance;
+                            let chance = (chance1 == 0 || chance2 == 0) ? 0 : Math.max(chance1, chance2);
+                            console.log(chance);
+                            if ((RegionRandom.rng() * 100) <= chance) {
+                                room.mapRoom(otherRoom, direction);
+                            }
                         }
                     }
                 }
+
+
+                // for (let direction = directionShuffler.getOne(); direction != undefined && (RegionRandom.rng() * 100) <= room.extraConnectionChance; direction = directionShuffler.getOne()) {
+                //     if (room.connections[direction] == undefined) {
+                //         let otherCoordinates = Room.shift(myCoordinates, direction);
+                //         let otherRoom = region.map.getRoom(otherCoordinates[0], otherCoordinates[1]);
+                //         if (otherRoom != undefined && otherRoom.randomizable
+                //             && otherRoom.isConnectableOn(OppositeDirection[Direction[direction]])
+                //             && (RegionRandom.rng() * 100) <= otherRoom.extraConnectionChance) {
+                //             room.mapRoom(otherRoom, direction);
+                //         }
+                //     }
+                // }
             });
         }
     });

+ 6 - 2
app/World/Classes/RandomDungeons/RoomRandom.ts

@@ -23,7 +23,7 @@ class RoomRandom extends Room {
     public randomizable = true; // non-randomizable rooms don't get placed automatically
     public placed = false;
     public appearChance = 75;
-    public extraConnectionChance = 75; // Requires two successes
+    public extraConnectionChance = 75;
     public backgroundImage = "tomato";
 
     public lastMap : RoomRandomMap;
@@ -108,8 +108,12 @@ class RoomRandom extends Room {
     }
 
     public getDistanceTo (room : RoomRandom) {
-        let myCoordinates = this.lastMap.getCoordinates(this);
         let otherCoordinates = this.lastMap.getCoordinates(room);
+        return this.getDistanceToCoordinates(otherCoordinates);
+    }
+
+    public getDistanceToCoordinates (otherCoordinates) {
+        let myCoordinates = this.lastMap.getCoordinates(this);
         if (myCoordinates != undefined && otherCoordinates != undefined) {
             let c1 = myCoordinates;
             let c2 = otherCoordinates;