isaacscript-common 1.2.209 → 1.2.212
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/deployJSONRoom.d.ts +6 -6
- package/dist/features/deployJSONRoom.lua +12 -9
- package/dist/functions/array.d.ts +25 -7
- package/dist/functions/array.lua +21 -21
- package/dist/functions/cards.d.ts +9 -6
- package/dist/functions/cards.lua +13 -13
- package/dist/functions/familiars.lua +2 -2
- package/dist/functions/jsonRoom.d.ts +1 -1
- package/dist/functions/jsonRoom.lua +5 -5
- package/dist/functions/random.d.ts +18 -27
- package/dist/functions/random.lua +14 -22
- package/dist/functions/set.d.ts +3 -2
- package/dist/functions/set.lua +5 -5
- package/dist/functions/spawnCollectible.d.ts +8 -3
- package/dist/functions/spawnCollectible.lua +10 -10
- package/package.json +1 -1
|
@@ -14,12 +14,12 @@ import { JSONRoom } from "../types/JSONRoom";
|
|
|
14
14
|
* const firstJSONRoom = customRooms.rooms.room[0];
|
|
15
15
|
* deployJSONRoom(firstJSONRoom);
|
|
16
16
|
* ```
|
|
17
|
-
* @param
|
|
18
|
-
*
|
|
17
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
18
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
19
19
|
* @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
|
|
20
20
|
* what the function is doing. Default is false.
|
|
21
21
|
*/
|
|
22
|
-
export declare function deployJSONRoom(jsonRoom: JSONRoom,
|
|
22
|
+
export declare function deployJSONRoom(jsonRoom: JSONRoom, seedOrRNG?: Seed | RNG, verbose?: boolean): void;
|
|
23
23
|
/**
|
|
24
24
|
* Helper function to deconstruct a vanilla room and set up a custom room in its place.
|
|
25
25
|
* Specifically, this will clear the current room of all entities and grid entities, and then spawn
|
|
@@ -39,12 +39,12 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, rng?: RNG, verbose?:
|
|
|
39
39
|
* const jsonRooms = customRooms.rooms.room;
|
|
40
40
|
* deployRandomJSONRoom(jsonRooms);
|
|
41
41
|
* ```
|
|
42
|
-
* @param
|
|
43
|
-
*
|
|
42
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
43
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
44
44
|
* @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
|
|
45
45
|
* what the function is doing. Default is false.
|
|
46
46
|
*/
|
|
47
|
-
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[],
|
|
47
|
+
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seedOrRNG?: Seed | RNG, verbose?: boolean): void;
|
|
48
48
|
/**
|
|
49
49
|
* Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
|
|
50
50
|
* this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
|
|
@@ -33,6 +33,8 @@ local getNPCs = ____npc.getNPCs
|
|
|
33
33
|
local ____pickups = require("functions.pickups")
|
|
34
34
|
local removeAllPickups = ____pickups.removeAllPickups
|
|
35
35
|
local ____rng = require("functions.rng")
|
|
36
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
37
|
+
local isRNG = ____rng.isRNG
|
|
36
38
|
local newRNG = ____rng.newRNG
|
|
37
39
|
local ____roomData = require("functions.roomData")
|
|
38
40
|
local getRoomListIndex = ____roomData.getRoomListIndex
|
|
@@ -234,6 +236,7 @@ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
|
|
|
234
236
|
local room = game:GetRoom()
|
|
235
237
|
local roomType = room:GetType()
|
|
236
238
|
local position = gridToPos(nil, x, y)
|
|
239
|
+
local seed = rng:Next()
|
|
237
240
|
local entity
|
|
238
241
|
if entityType == EntityType.ENTITY_PICKUP and variant == 100 then
|
|
239
242
|
local options = roomType == RoomType.ROOM_ANGEL
|
|
@@ -241,12 +244,10 @@ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
|
|
|
241
244
|
nil,
|
|
242
245
|
subType,
|
|
243
246
|
position,
|
|
244
|
-
|
|
247
|
+
seed,
|
|
245
248
|
options
|
|
246
249
|
)
|
|
247
250
|
else
|
|
248
|
-
rng:Next()
|
|
249
|
-
local seed = rng:GetSeed()
|
|
250
251
|
entity = game:Spawn(
|
|
251
252
|
entityType,
|
|
252
253
|
variant,
|
|
@@ -403,14 +404,15 @@ function ____exports.deployJSONRoomInit(self, mod)
|
|
|
403
404
|
saveDataManager(nil, "deployJSONRoom", v)
|
|
404
405
|
mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, postNewRoom)
|
|
405
406
|
end
|
|
406
|
-
function ____exports.deployJSONRoom(self, jsonRoom,
|
|
407
|
-
if
|
|
408
|
-
|
|
407
|
+
function ____exports.deployJSONRoom(self, jsonRoom, seedOrRNG, verbose)
|
|
408
|
+
if seedOrRNG == nil then
|
|
409
|
+
seedOrRNG = getRandomSeed(nil)
|
|
409
410
|
end
|
|
410
411
|
if verbose == nil then
|
|
411
412
|
verbose = false
|
|
412
413
|
end
|
|
413
414
|
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
415
|
+
local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
|
|
414
416
|
if verbose then
|
|
415
417
|
log("Starting to empty the room of entities and grid entities.")
|
|
416
418
|
end
|
|
@@ -428,14 +430,15 @@ function ____exports.deployJSONRoom(self, jsonRoom, rng, verbose)
|
|
|
428
430
|
fixPitGraphics(nil)
|
|
429
431
|
fillRoomWithDecorations(nil)
|
|
430
432
|
end
|
|
431
|
-
function ____exports.deployRandomJSONRoom(self, jsonRooms,
|
|
432
|
-
if
|
|
433
|
-
|
|
433
|
+
function ____exports.deployRandomJSONRoom(self, jsonRooms, seedOrRNG, verbose)
|
|
434
|
+
if seedOrRNG == nil then
|
|
435
|
+
seedOrRNG = getRandomSeed(nil)
|
|
434
436
|
end
|
|
435
437
|
if verbose == nil then
|
|
436
438
|
verbose = false
|
|
437
439
|
end
|
|
438
440
|
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
441
|
+
local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
|
|
439
442
|
local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, rng, verbose)
|
|
440
443
|
if verbose then
|
|
441
444
|
log((((((("Randomly chose JSON room " .. randomJSONRoom["$"].type) .. ".") .. randomJSONRoom["$"].variant) .. ".") .. randomJSONRoom["$"].subtype) .. " with name: ") .. randomJSONRoom["$"].name)
|
|
@@ -43,20 +43,29 @@ export declare function getLastElement<T>(array: T[]): T;
|
|
|
43
43
|
* Helper function to get a random element from the provided array.
|
|
44
44
|
*
|
|
45
45
|
* @param array The array to get an element from.
|
|
46
|
-
* @param
|
|
46
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
47
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
47
48
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
48
49
|
*/
|
|
49
|
-
export declare function getRandomArrayElement<T>(array: T[] | readonly T[],
|
|
50
|
+
export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG, exceptions?: T[] | readonly T[]): T;
|
|
50
51
|
/**
|
|
51
52
|
* Helper function to get a random element from the provided array. Once the random element is
|
|
52
53
|
* decided, it is then removed from the array (in-place).
|
|
53
54
|
*
|
|
54
55
|
* @param array The array to get an element from.
|
|
55
|
-
* @param
|
|
56
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
57
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
56
58
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
57
59
|
*/
|
|
58
|
-
export declare function getRandomArrayElementAndRemove<T>(array: T[],
|
|
59
|
-
|
|
60
|
+
export declare function getRandomArrayElementAndRemove<T>(array: T[], seedOrRNG?: Seed | RNG, exceptions?: T[] | readonly T[]): T;
|
|
61
|
+
/**
|
|
62
|
+
* Helper function to get a random index from the provided array.
|
|
63
|
+
*
|
|
64
|
+
* @param array The array to get the index from.
|
|
65
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
66
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG): int;
|
|
60
69
|
/**
|
|
61
70
|
* Initializes an array with all elements containing the specified default value.
|
|
62
71
|
*
|
|
@@ -74,17 +83,26 @@ export declare function initArray<T>(defaultValue: T, size: int): T[];
|
|
|
74
83
|
* - the table has no keys (i.e. an "empty" table)
|
|
75
84
|
*/
|
|
76
85
|
export declare function isArray(thing: unknown): boolean;
|
|
86
|
+
/** Checks if an array is in the provided 2-dimensional array. */
|
|
77
87
|
export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], parentArray: Array<T[] | readonly T[]>): boolean;
|
|
78
88
|
/**
|
|
79
89
|
* Shallow copies and shuffles the array using the Fisher-Yates algorithm. Returns the copied array.
|
|
80
90
|
*
|
|
81
91
|
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
92
|
+
*
|
|
93
|
+
* @param originalArray The array to shuffle.
|
|
94
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
95
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
82
96
|
*/
|
|
83
|
-
export declare function shuffleArray<T>(originalArray: T[] | readonly T[],
|
|
97
|
+
export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seedOrRNG?: Seed | RNG): T[];
|
|
84
98
|
/**
|
|
85
99
|
* Shuffles the provided array in-place using the Fisher-Yates algorithm.
|
|
86
100
|
*
|
|
87
101
|
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
102
|
+
*
|
|
103
|
+
* @param array The array to shuffle.
|
|
104
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
105
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
88
106
|
*/
|
|
89
|
-
export declare function shuffleArrayInPlace<T>(array: T[],
|
|
107
|
+
export declare function shuffleArrayInPlace<T>(array: T[], seedOrRNG?: Seed | RNG): void;
|
|
90
108
|
export declare function sumArray(array: number[] | readonly number[]): number;
|
package/dist/functions/array.lua
CHANGED
|
@@ -12,27 +12,27 @@ local ____exports = {}
|
|
|
12
12
|
local ____random = require("functions.random")
|
|
13
13
|
local getRandomInt = ____random.getRandomInt
|
|
14
14
|
local ____rng = require("functions.rng")
|
|
15
|
-
local
|
|
15
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
16
16
|
local ____utils = require("functions.utils")
|
|
17
17
|
local ____repeat = ____utils["repeat"]
|
|
18
|
-
function ____exports.getRandomArrayIndex(self, array,
|
|
19
|
-
if
|
|
20
|
-
|
|
18
|
+
function ____exports.getRandomArrayIndex(self, array, seedOrRNG)
|
|
19
|
+
if seedOrRNG == nil then
|
|
20
|
+
seedOrRNG = getRandomSeed(nil)
|
|
21
21
|
end
|
|
22
22
|
if #array == 0 then
|
|
23
23
|
error("Failed to get a random array index since the provided array is empty.")
|
|
24
24
|
end
|
|
25
|
-
return getRandomInt(nil, 0, #array - 1,
|
|
25
|
+
return getRandomInt(nil, 0, #array - 1, seedOrRNG)
|
|
26
26
|
end
|
|
27
|
-
function ____exports.shuffleArrayInPlace(self, array,
|
|
28
|
-
if
|
|
29
|
-
|
|
27
|
+
function ____exports.shuffleArrayInPlace(self, array, seedOrRNG)
|
|
28
|
+
if seedOrRNG == nil then
|
|
29
|
+
seedOrRNG = getRandomSeed(nil)
|
|
30
30
|
end
|
|
31
31
|
local currentIndex = #array
|
|
32
32
|
local randomIndex
|
|
33
33
|
while currentIndex > 0 do
|
|
34
34
|
currentIndex = currentIndex - 1
|
|
35
|
-
randomIndex = ____exports.getRandomArrayIndex(nil, array,
|
|
35
|
+
randomIndex = ____exports.getRandomArrayIndex(nil, array, seedOrRNG)
|
|
36
36
|
local ____temp_0 = {array[randomIndex + 1], array[currentIndex + 1]}
|
|
37
37
|
array[currentIndex + 1] = ____temp_0[1]
|
|
38
38
|
array[randomIndex + 1] = ____temp_0[2]
|
|
@@ -115,9 +115,9 @@ end
|
|
|
115
115
|
function ____exports.getLastElement(self, array)
|
|
116
116
|
return array[#array]
|
|
117
117
|
end
|
|
118
|
-
function ____exports.getRandomArrayElement(self, array,
|
|
119
|
-
if
|
|
120
|
-
|
|
118
|
+
function ____exports.getRandomArrayElement(self, array, seedOrRNG, exceptions)
|
|
119
|
+
if seedOrRNG == nil then
|
|
120
|
+
seedOrRNG = getRandomSeed(nil)
|
|
121
121
|
end
|
|
122
122
|
if exceptions == nil then
|
|
123
123
|
exceptions = {}
|
|
@@ -130,17 +130,17 @@ function ____exports.getRandomArrayElement(self, array, rng, exceptions)
|
|
|
130
130
|
array,
|
|
131
131
|
table.unpack(exceptions)
|
|
132
132
|
)
|
|
133
|
-
local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions,
|
|
133
|
+
local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, seedOrRNG)
|
|
134
134
|
return arrayWithoutExceptions[randomIndex + 1]
|
|
135
135
|
end
|
|
136
|
-
function ____exports.getRandomArrayElementAndRemove(self, array,
|
|
137
|
-
if
|
|
138
|
-
|
|
136
|
+
function ____exports.getRandomArrayElementAndRemove(self, array, seedOrRNG, exceptions)
|
|
137
|
+
if seedOrRNG == nil then
|
|
138
|
+
seedOrRNG = getRandomSeed(nil)
|
|
139
139
|
end
|
|
140
140
|
if exceptions == nil then
|
|
141
141
|
exceptions = {}
|
|
142
142
|
end
|
|
143
|
-
local randomArrayElement = ____exports.getRandomArrayElement(nil, array,
|
|
143
|
+
local randomArrayElement = ____exports.getRandomArrayElement(nil, array, seedOrRNG, exceptions)
|
|
144
144
|
____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
|
|
145
145
|
return randomArrayElement
|
|
146
146
|
end
|
|
@@ -192,12 +192,12 @@ function ____exports.isArrayInArray(self, arrayToMatch, parentArray)
|
|
|
192
192
|
function(____, element) return ____exports.arrayEquals(nil, element, arrayToMatch) end
|
|
193
193
|
)
|
|
194
194
|
end
|
|
195
|
-
function ____exports.shuffleArray(self, originalArray,
|
|
196
|
-
if
|
|
197
|
-
|
|
195
|
+
function ____exports.shuffleArray(self, originalArray, seedOrRNG)
|
|
196
|
+
if seedOrRNG == nil then
|
|
197
|
+
seedOrRNG = getRandomSeed(nil)
|
|
198
198
|
end
|
|
199
199
|
local array = ____exports.copyArray(nil, originalArray)
|
|
200
|
-
____exports.shuffleArrayInPlace(nil, array,
|
|
200
|
+
____exports.shuffleArrayInPlace(nil, array, seedOrRNG)
|
|
201
201
|
return array
|
|
202
202
|
end
|
|
203
203
|
function ____exports.sumArray(self, array)
|
|
@@ -43,24 +43,27 @@ export declare function getMaxCards(): int;
|
|
|
43
43
|
* - any objects like Dice Shard
|
|
44
44
|
* - any modded cards.
|
|
45
45
|
*
|
|
46
|
-
* @param
|
|
46
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
47
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
47
48
|
* @param exceptions Optional. An array of cards to not select.
|
|
48
49
|
*/
|
|
49
|
-
export declare function getRandomCard(
|
|
50
|
+
export declare function getRandomCard(seedOrRNG?: Seed | RNG, exceptions?: Card[]): Card;
|
|
50
51
|
/**
|
|
51
52
|
* @param cardType The card type that represents the pool of cards to select from.
|
|
52
|
-
* @param
|
|
53
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
54
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
53
55
|
* @param exceptions Optional. An array of cards to not select.
|
|
54
56
|
*/
|
|
55
|
-
export declare function getRandomCardOfType(cardType: CardType,
|
|
57
|
+
export declare function getRandomCardOfType(cardType: CardType, seedOrRNG?: Seed | RNG, exceptions?: Card[]): Card;
|
|
56
58
|
/**
|
|
57
59
|
* Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul of
|
|
58
60
|
* Isaac, etc.). This will never return a Rune Shard.
|
|
59
61
|
*
|
|
60
|
-
* @param
|
|
62
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
63
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
61
64
|
* @param exceptions Optional. An array of runes to not select.
|
|
62
65
|
*/
|
|
63
|
-
export declare function getRandomRune(
|
|
66
|
+
export declare function getRandomRune(seedOrRNG?: Seed | RNG, exceptions?: Card[]): Card;
|
|
64
67
|
/**
|
|
65
68
|
* Returns true for cards that have the following card type:
|
|
66
69
|
* - CardType.TAROT
|
package/dist/functions/cards.lua
CHANGED
|
@@ -21,7 +21,7 @@ local DEFAULT_CARD_TYPE = ____cardTypes.DEFAULT_CARD_TYPE
|
|
|
21
21
|
local ____math = require("functions.math")
|
|
22
22
|
local range = ____math.range
|
|
23
23
|
local ____rng = require("functions.rng")
|
|
24
|
-
local
|
|
24
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
25
25
|
local ____set = require("functions.set")
|
|
26
26
|
local addSetsToSet = ____set.addSetsToSet
|
|
27
27
|
local getRandomSetElement = ____set.getRandomSetElement
|
|
@@ -100,35 +100,35 @@ function ____exports.getCardName(self, card)
|
|
|
100
100
|
end
|
|
101
101
|
return DEFAULT_CARD_NAME
|
|
102
102
|
end
|
|
103
|
-
function ____exports.getRandomCard(self,
|
|
104
|
-
if
|
|
105
|
-
|
|
103
|
+
function ____exports.getRandomCard(self, seedOrRNG, exceptions)
|
|
104
|
+
if seedOrRNG == nil then
|
|
105
|
+
seedOrRNG = getRandomSeed(nil)
|
|
106
106
|
end
|
|
107
107
|
if exceptions == nil then
|
|
108
108
|
exceptions = {}
|
|
109
109
|
end
|
|
110
|
-
return getRandomSetElement(nil, CARD_SET,
|
|
110
|
+
return getRandomSetElement(nil, CARD_SET, seedOrRNG, exceptions)
|
|
111
111
|
end
|
|
112
|
-
function ____exports.getRandomCardOfType(self, cardType,
|
|
113
|
-
if
|
|
114
|
-
|
|
112
|
+
function ____exports.getRandomCardOfType(self, cardType, seedOrRNG, exceptions)
|
|
113
|
+
if seedOrRNG == nil then
|
|
114
|
+
seedOrRNG = getRandomSeed(nil)
|
|
115
115
|
end
|
|
116
116
|
if exceptions == nil then
|
|
117
117
|
exceptions = {}
|
|
118
118
|
end
|
|
119
119
|
local cardSet = ____exports.getCardsOfType(nil, cardType)
|
|
120
|
-
return getRandomSetElement(nil, cardSet,
|
|
120
|
+
return getRandomSetElement(nil, cardSet, seedOrRNG, exceptions)
|
|
121
121
|
end
|
|
122
|
-
function ____exports.getRandomRune(self,
|
|
123
|
-
if
|
|
124
|
-
|
|
122
|
+
function ____exports.getRandomRune(self, seedOrRNG, exceptions)
|
|
123
|
+
if seedOrRNG == nil then
|
|
124
|
+
seedOrRNG = getRandomSeed(nil)
|
|
125
125
|
end
|
|
126
126
|
if exceptions == nil then
|
|
127
127
|
exceptions = {}
|
|
128
128
|
end
|
|
129
129
|
local runesSet = ____exports.getCardsOfType(nil, CardType.RUNE)
|
|
130
130
|
runesSet:delete(Card.RUNE_SHARD)
|
|
131
|
-
return getRandomSetElement(nil, runesSet,
|
|
131
|
+
return getRandomSetElement(nil, runesSet, seedOrRNG, exceptions)
|
|
132
132
|
end
|
|
133
133
|
function ____exports.isCard(self, card)
|
|
134
134
|
return CARD_SET:has(card)
|
|
@@ -54,7 +54,7 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamil
|
|
|
54
54
|
nil,
|
|
55
55
|
numFamiliarsToSpawn,
|
|
56
56
|
function()
|
|
57
|
-
collectibleRNG:Next()
|
|
57
|
+
local seed = collectibleRNG:Next()
|
|
58
58
|
local familiar = game:Spawn(
|
|
59
59
|
EntityType.ENTITY_FAMILIAR,
|
|
60
60
|
familiarVariant,
|
|
@@ -62,7 +62,7 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamil
|
|
|
62
62
|
Vector.Zero,
|
|
63
63
|
player,
|
|
64
64
|
familiarSubTypeToUse,
|
|
65
|
-
|
|
65
|
+
seed
|
|
66
66
|
):ToFamiliar()
|
|
67
67
|
if familiar ~= nil then
|
|
68
68
|
familiar.Player = player
|
|
@@ -9,4 +9,4 @@ export declare function getJSONRoomsOfSubType(jsonRooms: JSONRoom[], subType: in
|
|
|
9
9
|
* properly account for each room weight using the algorithm from:
|
|
10
10
|
* https://stackoverflow.com/questions/1761626/weighted-random-numbers
|
|
11
11
|
*/
|
|
12
|
-
export declare function getRandomJSONRoom(jsonRooms: JSONRoom[],
|
|
12
|
+
export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seedOrRNG?: Seed | RNG, verbose?: boolean): JSONRoom;
|
|
@@ -10,7 +10,7 @@ local log = ____log.log
|
|
|
10
10
|
local ____random = require("functions.random")
|
|
11
11
|
local getRandomFloat = ____random.getRandomFloat
|
|
12
12
|
local ____rng = require("functions.rng")
|
|
13
|
-
local
|
|
13
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
14
14
|
function getTotalWeightOfJSONRooms(self, jsonRooms)
|
|
15
15
|
local weights = __TS__ArrayMap(
|
|
16
16
|
jsonRooms,
|
|
@@ -66,9 +66,9 @@ function ____exports.getJSONRoomsOfSubType(self, jsonRooms, subType)
|
|
|
66
66
|
end
|
|
67
67
|
)
|
|
68
68
|
end
|
|
69
|
-
function ____exports.getRandomJSONRoom(self, jsonRooms,
|
|
70
|
-
if
|
|
71
|
-
|
|
69
|
+
function ____exports.getRandomJSONRoom(self, jsonRooms, seedOrRNG, verbose)
|
|
70
|
+
if seedOrRNG == nil then
|
|
71
|
+
seedOrRNG = getRandomSeed(nil)
|
|
72
72
|
end
|
|
73
73
|
if verbose == nil then
|
|
74
74
|
verbose = false
|
|
@@ -77,7 +77,7 @@ function ____exports.getRandomJSONRoom(self, jsonRooms, rng, verbose)
|
|
|
77
77
|
if verbose then
|
|
78
78
|
log("Total weight of the JSON rooms provided: " .. tostring(totalWeight))
|
|
79
79
|
end
|
|
80
|
-
local chosenWeight = getRandomFloat(nil, 0, totalWeight,
|
|
80
|
+
local chosenWeight = getRandomFloat(nil, 0, totalWeight, seedOrRNG)
|
|
81
81
|
if verbose then
|
|
82
82
|
log("Randomly chose weight for JSON room: " .. tostring(chosenWeight))
|
|
83
83
|
end
|
|
@@ -1,39 +1,27 @@
|
|
|
1
1
|
/// <reference types="isaac-typescript-definitions" />
|
|
2
2
|
/**
|
|
3
3
|
* This returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on
|
|
4
|
-
* the high end. (This is because the `RNG.RandomFloat` method
|
|
5
|
-
*
|
|
4
|
+
* the high end. (This is because the `RNG.RandomFloat` method will never return a value of exactly
|
|
5
|
+
* 1.)
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
8
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getRandom(
|
|
10
|
+
export declare function getRandom(seedOrRNG?: Seed | RNG): float;
|
|
11
11
|
/**
|
|
12
|
-
* This returns a random float between min and max.
|
|
13
|
-
* the high end. (This is because the `RNG.RandomFloat` method can return a value of 0.999, but it
|
|
14
|
-
* will never return a value of exactly 1.)
|
|
15
|
-
*
|
|
16
|
-
* Note that this function will invoke the `Next` method on the `RNG` object before returning the
|
|
17
|
-
* random number.
|
|
12
|
+
* This returns a random float between min and max.
|
|
18
13
|
*
|
|
19
14
|
* Example:
|
|
20
15
|
* ```ts
|
|
21
16
|
* const realNumberBetweenOneAndThree = getRandomFloat(1, 3);
|
|
22
17
|
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param min The lower bound for the random number (inclusive).
|
|
20
|
+
* @param max The upper bound for the random number (exclusive).
|
|
21
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
22
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
23
23
|
*/
|
|
24
|
-
export declare function getRandomFloat(min: int, max: int,
|
|
25
|
-
/**
|
|
26
|
-
* This returns a random float between min and max. It is inclusive on the low end, but exclusive on
|
|
27
|
-
* the high end. (This is because the `RNG.RandomFloat` method can return a value of 0.999, but it
|
|
28
|
-
* will never return a value of exactly 1.)
|
|
29
|
-
*/
|
|
30
|
-
export declare function getRandomFloatFromSeed(min: int, max: int, seed: Seed): float;
|
|
31
|
-
/**
|
|
32
|
-
* This returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on
|
|
33
|
-
* the high end. (This is because the `RNG.RandomFloat` method can return a value of 0.999, but it
|
|
34
|
-
* will never return a value of exactly 1.)
|
|
35
|
-
*/
|
|
36
|
-
export declare function getRandomFromSeed(seed: Seed): float;
|
|
24
|
+
export declare function getRandomFloat(min: int, max: int, seedOrRNG?: Seed | RNG): float;
|
|
37
25
|
/**
|
|
38
26
|
* This returns a random integer between min and max. It is inclusive on both ends.
|
|
39
27
|
*
|
|
@@ -44,7 +32,10 @@ export declare function getRandomFromSeed(seed: Seed): float;
|
|
|
44
32
|
* ```ts
|
|
45
33
|
* const oneTwoOrThree = getRandomInt(1, 3);
|
|
46
34
|
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param min The lower bound for the random number (inclusive).
|
|
37
|
+
* @param max The upper bound for the random number (inclusive).
|
|
38
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
39
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
47
40
|
*/
|
|
48
|
-
export declare function getRandomInt(min: int, max: int,
|
|
49
|
-
/** This returns a random integer between min and max. It is inclusive on both ends. */
|
|
50
|
-
export declare function getRandomIntFromSeed(min: int, max: int, seed: Seed): int;
|
|
41
|
+
export declare function getRandomInt(min: int, max: int, seedOrRNG?: Seed | RNG): int;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
2
2
|
local ____exports = {}
|
|
3
3
|
local ____rng = require("functions.rng")
|
|
4
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
5
|
+
local isRNG = ____rng.isRNG
|
|
4
6
|
local newRNG = ____rng.newRNG
|
|
5
|
-
function ____exports.getRandom(self,
|
|
6
|
-
if
|
|
7
|
-
|
|
7
|
+
function ____exports.getRandom(self, seedOrRNG)
|
|
8
|
+
if seedOrRNG == nil then
|
|
9
|
+
seedOrRNG = getRandomSeed(nil)
|
|
8
10
|
end
|
|
11
|
+
local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
|
|
9
12
|
return rng:RandomFloat()
|
|
10
13
|
end
|
|
11
|
-
function ____exports.getRandomFloat(self, min, max,
|
|
12
|
-
if
|
|
13
|
-
|
|
14
|
+
function ____exports.getRandomFloat(self, min, max, seedOrRNG)
|
|
15
|
+
if seedOrRNG == nil then
|
|
16
|
+
seedOrRNG = getRandomSeed(nil)
|
|
14
17
|
end
|
|
15
18
|
if min > max then
|
|
16
19
|
local oldMin = min
|
|
@@ -18,20 +21,13 @@ function ____exports.getRandomFloat(self, min, max, rng)
|
|
|
18
21
|
min = oldMax
|
|
19
22
|
max = oldMin
|
|
20
23
|
end
|
|
21
|
-
return min + ____exports.getRandom(nil,
|
|
24
|
+
return min + ____exports.getRandom(nil, seedOrRNG) * (max - min)
|
|
22
25
|
end
|
|
23
|
-
function ____exports.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
function ____exports.getRandomFromSeed(self, seed)
|
|
28
|
-
local rng = newRNG(nil, seed)
|
|
29
|
-
return ____exports.getRandom(nil, rng)
|
|
30
|
-
end
|
|
31
|
-
function ____exports.getRandomInt(self, min, max, rng)
|
|
32
|
-
if rng == nil then
|
|
33
|
-
rng = newRNG(nil)
|
|
26
|
+
function ____exports.getRandomInt(self, min, max, seedOrRNG)
|
|
27
|
+
if seedOrRNG == nil then
|
|
28
|
+
seedOrRNG = getRandomSeed(nil)
|
|
34
29
|
end
|
|
30
|
+
local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
|
|
35
31
|
if min > max then
|
|
36
32
|
local oldMin = min
|
|
37
33
|
local oldMax = max
|
|
@@ -40,8 +36,4 @@ function ____exports.getRandomInt(self, min, max, rng)
|
|
|
40
36
|
end
|
|
41
37
|
return rng:RandomInt(max - min + 1) + min
|
|
42
38
|
end
|
|
43
|
-
function ____exports.getRandomIntFromSeed(self, min, max, seed)
|
|
44
|
-
local rng = newRNG(nil, seed)
|
|
45
|
-
return ____exports.getRandomInt(nil, min, max, rng)
|
|
46
|
-
end
|
|
47
39
|
return ____exports
|
package/dist/functions/set.d.ts
CHANGED
|
@@ -25,10 +25,11 @@ export declare function deleteSetsFromSet<T>(mainSet: Set<T>, ...setsToRemove: A
|
|
|
25
25
|
* Helper function to get a random element from the provided set.
|
|
26
26
|
*
|
|
27
27
|
* @param set The set to get an element from.
|
|
28
|
-
* @param
|
|
28
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
29
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
29
30
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
30
31
|
*/
|
|
31
|
-
export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>,
|
|
32
|
+
export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, seedOrRNG?: Seed | RNG, exceptions?: T[] | readonly T[]): T;
|
|
32
33
|
/**
|
|
33
34
|
* Helper function to get a sorted array based on the contents of a set.
|
|
34
35
|
*
|
package/dist/functions/set.lua
CHANGED
|
@@ -8,7 +8,7 @@ local ____exports = {}
|
|
|
8
8
|
local ____array = require("functions.array")
|
|
9
9
|
local getRandomArrayElement = ____array.getRandomArrayElement
|
|
10
10
|
local ____rng = require("functions.rng")
|
|
11
|
-
local
|
|
11
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
12
12
|
function ____exports.getSortedSetValues(self, set)
|
|
13
13
|
local values = set:values()
|
|
14
14
|
local array = {__TS__Spread(values)}
|
|
@@ -48,14 +48,14 @@ function ____exports.deleteSetsFromSet(self, mainSet, ...)
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
|
-
function ____exports.getRandomSetElement(self, set,
|
|
52
|
-
if
|
|
53
|
-
|
|
51
|
+
function ____exports.getRandomSetElement(self, set, seedOrRNG, exceptions)
|
|
52
|
+
if seedOrRNG == nil then
|
|
53
|
+
seedOrRNG = getRandomSeed(nil)
|
|
54
54
|
end
|
|
55
55
|
if exceptions == nil then
|
|
56
56
|
exceptions = {}
|
|
57
57
|
end
|
|
58
58
|
local array = ____exports.getSortedSetValues(nil, set)
|
|
59
|
-
return getRandomArrayElement(nil, array,
|
|
59
|
+
return getRandomArrayElement(nil, array, seedOrRNG, exceptions)
|
|
60
60
|
end
|
|
61
61
|
return ____exports
|
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @param collectibleType The collectible type to spawn.
|
|
9
9
|
* @param position The position to spawn the collectible at.
|
|
10
|
-
* @param
|
|
10
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
11
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
11
12
|
* @param options Optional. Set to true to make the collectible a "There's Options" style
|
|
12
13
|
* collectible. Default is false.
|
|
13
14
|
* @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
|
|
14
15
|
* Tainted Keeper. Default is false.
|
|
15
16
|
*/
|
|
16
|
-
export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector,
|
|
17
|
+
export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, seedOrRNG?: Seed | RNG, options?: boolean, forceFreeItem?: boolean): EntityPickup;
|
|
17
18
|
/**
|
|
18
19
|
* Helper function to spawn an empty collectible. Doing this is tricky since spawning a collectible
|
|
19
20
|
* with `CollectibleType.COLLECTIBLE_NULL` will result in spawning a collectible with a random type
|
|
@@ -21,5 +22,9 @@ export declare function spawnCollectible(collectibleType: CollectibleType | int,
|
|
|
21
22
|
*
|
|
22
23
|
* Instead, this function arbitrarily spawns a collectible with
|
|
23
24
|
* `CollectibleType.COLLECTIBLE_SAD_ONION`, and then converts it to an empty pedestal afterward.
|
|
25
|
+
*
|
|
26
|
+
* @param position The position to spawn the empty collectible at.
|
|
27
|
+
* @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
28
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
24
29
|
*/
|
|
25
|
-
export declare function spawnEmptyCollectible(position: Vector,
|
|
30
|
+
export declare function spawnEmptyCollectible(position: Vector, seedOrRNG?: Seed | RNG): EntityPickup;
|
|
@@ -12,10 +12,11 @@ local setCollectibleEmpty = ____collectibles.setCollectibleEmpty
|
|
|
12
12
|
local ____player = require("functions.player")
|
|
13
13
|
local anyPlayerIs = ____player.anyPlayerIs
|
|
14
14
|
local ____rng = require("functions.rng")
|
|
15
|
-
local
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
local getRandomSeed = ____rng.getRandomSeed
|
|
16
|
+
local isRNG = ____rng.isRNG
|
|
17
|
+
function ____exports.spawnCollectible(self, collectibleType, position, seedOrRNG, options, forceFreeItem)
|
|
18
|
+
if seedOrRNG == nil then
|
|
19
|
+
seedOrRNG = getRandomSeed(nil)
|
|
19
20
|
end
|
|
20
21
|
if options == nil then
|
|
21
22
|
options = false
|
|
@@ -23,8 +24,7 @@ function ____exports.spawnCollectible(self, collectibleType, position, rng, opti
|
|
|
23
24
|
if forceFreeItem == nil then
|
|
24
25
|
forceFreeItem = false
|
|
25
26
|
end
|
|
26
|
-
|
|
27
|
-
local seed = rng:GetSeed()
|
|
27
|
+
local seed = isRNG(nil, seedOrRNG) and seedOrRNG:Next() or seedOrRNG
|
|
28
28
|
local collectible = game:Spawn(
|
|
29
29
|
EntityType.ENTITY_PICKUP,
|
|
30
30
|
100,
|
|
@@ -49,15 +49,15 @@ function ____exports.spawnCollectible(self, collectibleType, position, rng, opti
|
|
|
49
49
|
end
|
|
50
50
|
return collectible
|
|
51
51
|
end
|
|
52
|
-
function ____exports.spawnEmptyCollectible(self, position,
|
|
53
|
-
if
|
|
54
|
-
|
|
52
|
+
function ____exports.spawnEmptyCollectible(self, position, seedOrRNG)
|
|
53
|
+
if seedOrRNG == nil then
|
|
54
|
+
seedOrRNG = getRandomSeed(nil)
|
|
55
55
|
end
|
|
56
56
|
local collectible = ____exports.spawnCollectible(
|
|
57
57
|
nil,
|
|
58
58
|
CollectibleType.COLLECTIBLE_SAD_ONION,
|
|
59
59
|
position,
|
|
60
|
-
|
|
60
|
+
seedOrRNG,
|
|
61
61
|
false,
|
|
62
62
|
true
|
|
63
63
|
)
|