isaacscript-common 1.2.200 → 1.2.201

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.
@@ -15,6 +15,7 @@ local ____familiars = require("functions.familiars")
15
15
  local removeAllFamiliars = ____familiars.removeAllFamiliars
16
16
  local ____log = require("functions.log")
17
17
  local log = ____log.log
18
+ local logError = ____log.logError
18
19
  local ____playerIndex = require("functions.playerIndex")
19
20
  local getPlayerFromIndex = ____playerIndex.getPlayerFromIndex
20
21
  local getPlayerIndex = ____playerIndex.getPlayerIndex
@@ -97,25 +98,19 @@ function playerIsAboutToDie(self, player)
97
98
  player:AddCollectible(CollectibleType.COLLECTIBLE_1UP, 0, false)
98
99
  removeAllFamiliars(nil, FamiliarVariant.ONE_UP)
99
100
  removeCollectibleFromItemTracker(nil, CollectibleType.COLLECTIBLE_1UP)
100
- local character = player:GetPlayerType()
101
- if character ~= PlayerType.PLAYER_SAMSON_B then
102
- return
103
- end
104
101
  local playerIndex = getPlayerIndex(nil, player)
105
102
  runNextGameFrame(
106
103
  nil,
107
104
  function()
108
- local taintedSamson = getPlayerFromIndex(nil, playerIndex)
109
- if taintedSamson == nil then
105
+ local futurePlayer = getPlayerFromIndex(nil, playerIndex)
106
+ if futurePlayer == nil then
110
107
  return
111
108
  end
112
- local effects = player:GetEffects()
113
- local isBerserk = effects:HasCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK)
114
- if not isBerserk then
109
+ if futurePlayer:IsDead() then
115
110
  return
116
111
  end
117
- effects:RemoveCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK, -1)
118
- removeAllFamiliars(nil, FamiliarVariant.ONE_UP)
112
+ logError("The player is still alive after initializing a custom revive. Explicitly killing the player.")
113
+ futurePlayer:Kill()
119
114
  end
120
115
  )
121
116
  end
@@ -7,7 +7,7 @@ local ____gridEntity = require("functions.gridEntity")
7
7
  local getTopLeftWallGridIndex = ____gridEntity.getTopLeftWallGridIndex
8
8
  local spawnGridEntity = ____gridEntity.spawnGridEntity
9
9
  local ____log = require("functions.log")
10
- local log = ____log.log
10
+ local logError = ____log.logError
11
11
  local ____postNewRoomEarly = require("callbacks.subscriptions.postNewRoomEarly")
12
12
  local postNewRoomEarlyFire = ____postNewRoomEarly.postNewRoomEarlyFire
13
13
  local postNewRoomEarlyHasSubscriptions = ____postNewRoomEarly.postNewRoomEarlyHasSubscriptions
@@ -35,18 +35,16 @@ function checkRoomChanged(self)
35
35
  if topLeftWall == nil then
36
36
  topLeftWall = spawnGridEntity(nil, GridEntityType.GRID_WALL, topLeftWallGridIndex)
37
37
  if topLeftWall == nil then
38
- log("Error: Failed to spawn a new wall (1) for the PostNewRoomEarly callback.")
38
+ logError("Failed to spawn a new wall (1) for the PostNewRoomEarly callback.")
39
39
  return
40
40
  end
41
- log("Spawned a new wall (1) for the PostNewRoomEarly callback.")
42
41
  end
43
42
  if topLeftWall2 == nil then
44
43
  topLeftWall2 = spawnGridEntity(nil, GridEntityType.GRID_WALL, rightOfTopWallGridIndex)
45
44
  if topLeftWall2 == nil then
46
- log("Error: Failed to spawn a new wall (2) for the PostNewRoomEarly callback.")
45
+ logError("Failed to spawn a new wall (2) for the PostNewRoomEarly callback.")
47
46
  return
48
47
  end
49
- log("Spawned a new wall (2) for the PostNewRoomEarly callback.")
50
48
  end
51
49
  local topLeftWallPtrHash = GetPtrHash(topLeftWall)
52
50
  local topLeftWallPtrHash2 = GetPtrHash(topLeftWall2)
@@ -69,6 +69,8 @@ export declare const MAX_ROOM_INDEX = 168;
69
69
  * effect.
70
70
  */
71
71
  export declare const MAX_SPEED_STAT = 2;
72
+ /** Corresponds to the maximum value for `EntityPlayer.SamsonBerserkCharge`. */
73
+ export declare const MAX_TAINTED_SAMSON_BERSERK_CHARGE = 100000;
72
74
  export declare const MAX_VANILLA_CHARACTER: number;
73
75
  export declare const MAX_VANILLA_COLLECTIBLE_TYPE: number;
74
76
  export declare const NUM_DIMENSIONS = 3;
@@ -89,6 +91,8 @@ export declare const PILL_COLOR_MASK = 2047;
89
91
  * 1 << 11
90
92
  */
91
93
  export declare const PILL_GIANT_FLAG = 2048;
94
+ /** After taking damage, `EntityPlayer.SamsonBerserkCharge` is incremented by this amount. */
95
+ export declare const TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE = 10000;
92
96
  /**
93
97
  * Add this to a `TrinketType` to get the corresponding golden trinket type.
94
98
  *
@@ -22,6 +22,7 @@ ____exports.MAX_PLAYER_SPEED_IN_UNITS = 9.8
22
22
  ____exports.MAX_PLAYER_TRINKET_SLOTS = 2
23
23
  ____exports.MAX_ROOM_INDEX = 168
24
24
  ____exports.MAX_SPEED_STAT = 2
25
+ ____exports.MAX_TAINTED_SAMSON_BERSERK_CHARGE = 100000
25
26
  ____exports.MAX_VANILLA_CHARACTER = PlayerType.NUM_PLAYER_TYPES - 1
26
27
  ____exports.MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.NUM_COLLECTIBLES - 1
27
28
  ____exports.NUM_DIMENSIONS = 3
@@ -30,6 +31,7 @@ ____exports.MINUTE_IN_MILLISECONDS = 60 * ____exports.SECOND_IN_MILLISECONDS
30
31
  ____exports.ONE_BY_ONE_ROOM_GRID_SIZE = 135
31
32
  ____exports.PILL_COLOR_MASK = 2047
32
33
  ____exports.PILL_GIANT_FLAG = 2048
34
+ ____exports.TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE = 10000
33
35
  ____exports.TRINKET_GOLDEN_FLAG = 32768
34
36
  ____exports.TRINKET_ID_MASK = 32767
35
37
  ____exports.UI_HEART_WIDTH = 12
@@ -15,7 +15,7 @@ import { JSONRoom } from "../types/JSONRoom";
15
15
  * deployJSONRoom(firstJSONRoom);
16
16
  * ```
17
17
  * @param seed Optional. Specifies the seed that will be used for spawning every entity in the room.
18
- * Default is `Random()`.
18
+ * 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
  * @returns Before using the seed for spawning each entity, it is iterated with `nextSeed`. The
@@ -43,7 +43,7 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: Seed, verbose?
43
43
  * deployRandomJSONRoom(jsonRooms);
44
44
  * ```
45
45
  * @param seed Optional. Specifies the seed that will be used for determining the random room. After
46
- * that, it is also used for spawning every entity in the room. Default is `Random()`.
46
+ * that, it is also used for spawning every entity in the room. Default is `getRandomSeed()`.
47
47
  * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
48
48
  * what the function is doing. Default is false.
49
49
  * @returns Before using the seed for spawning each entity, it is iterated with `nextSeed`. The
@@ -33,6 +33,7 @@ local getNPCs = ____npc.getNPCs
33
33
  local ____pickups = require("functions.pickups")
34
34
  local removeAllPickups = ____pickups.removeAllPickups
35
35
  local ____random = require("functions.random")
36
+ local getRandomSeed = ____random.getRandomSeed
36
37
  local nextSeed = ____random.nextSeed
37
38
  local ____roomData = require("functions.roomData")
38
39
  local getRoomListIndex = ____roomData.getRoomListIndex
@@ -405,7 +406,7 @@ function ____exports.deployJSONRoomInit(self, mod)
405
406
  end
406
407
  function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
407
408
  if seed == nil then
408
- seed = Random()
409
+ seed = getRandomSeed(nil)
409
410
  end
410
411
  if verbose == nil then
411
412
  verbose = false
@@ -431,7 +432,7 @@ function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
431
432
  end
432
433
  function ____exports.deployRandomJSONRoom(self, jsonRooms, seed, verbose)
433
434
  if seed == nil then
434
- seed = Random()
435
+ seed = getRandomSeed(nil)
435
436
  end
436
437
  if verbose == nil then
437
438
  verbose = false
@@ -6,6 +6,7 @@ local ____jsonHelpers = require("functions.jsonHelpers")
6
6
  local jsonDecode = ____jsonHelpers.jsonDecode
7
7
  local ____log = require("functions.log")
8
8
  local log = ____log.log
9
+ local logError = ____log.logError
9
10
  local ____constants = require("features.saveDataManager.constants")
10
11
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
11
12
  local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
@@ -15,7 +16,7 @@ function readSaveDatFile(self, mod)
15
16
  local renderFrameCount = Isaac.GetFrameCount()
16
17
  local ok, jsonStringOrErrMsg = pcall(tryLoadModData, mod)
17
18
  if not ok then
18
- log((("Error: Failed to read from the \"save#.dat\" file on render frame " .. tostring(renderFrameCount)) .. ": ") .. jsonStringOrErrMsg)
19
+ logError((("Failed to read from the \"save#.dat\" file on render frame " .. tostring(renderFrameCount)) .. ": ") .. jsonStringOrErrMsg)
19
20
  return DEFAULT_MOD_DATA
20
21
  end
21
22
  if jsonStringOrErrMsg == nil then
@@ -13,7 +13,7 @@ local SerializationType = ____SerializationType.SerializationType
13
13
  local ____deepCopy = require("functions.deepCopy")
14
14
  local deepCopy = ____deepCopy.deepCopy
15
15
  local ____log = require("functions.log")
16
- local log = ____log.log
16
+ local logError = ____log.logError
17
17
  local ____table = require("functions.table")
18
18
  local clearTable = ____table.clearTable
19
19
  local ____constants = require("features.saveDataManager.constants")
@@ -72,12 +72,12 @@ function restoreDefaults(self, childTableName)
72
72
  end
73
73
  local saveDataDefaults = saveDataDefaultsMap[subscriberName]
74
74
  if saveDataDefaults == nil then
75
- log("Error: Failed to find the default copy of the save data for subscriber: " .. subscriberName)
75
+ logError("Failed to find the default copy of the save data for subscriber: " .. subscriberName)
76
76
  goto __continue14
77
77
  end
78
78
  local childTableDefaults = saveDataDefaults[childTableName]
79
79
  if childTableDefaults == nil then
80
- log((("Error: Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber: ") .. subscriberName)
80
+ logError((("Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber: ") .. subscriberName)
81
81
  goto __continue14
82
82
  end
83
83
  local childTableDefaultsTable = childTableDefaults
@@ -43,7 +43,7 @@ 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 seed Optional. The seed used to select the random element. Default is `Random()`.
46
+ * @param seed Optional. The seed used to select the random element. Default is `getRandomSeed()`.
47
47
  * @param exceptions Optional. An array of elements to skip over if selected.
48
48
  */
49
49
  export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
@@ -52,7 +52,7 @@ export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed
52
52
  * decided, it is then removed from the array (in-place).
53
53
  *
54
54
  * @param array The array to get an element from.
55
- * @param seed Optional. The seed used to select the random element. Default is `Random()`.
55
+ * @param seed Optional. The seed used to select the random element. Default is `getRandomSeed()`.
56
56
  * @param exceptions Optional. An array of elements to skip over if selected.
57
57
  */
58
58
  export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
@@ -11,12 +11,13 @@ local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
11
11
  local ____exports = {}
12
12
  local ____random = require("functions.random")
13
13
  local getRandomInt = ____random.getRandomInt
14
+ local getRandomSeed = ____random.getRandomSeed
14
15
  local nextSeed = ____random.nextSeed
15
16
  local ____utils = require("functions.utils")
16
17
  local ____repeat = ____utils["repeat"]
17
18
  function ____exports.getRandomArrayIndex(self, array, seed)
18
19
  if seed == nil then
19
- seed = Random()
20
+ seed = getRandomSeed(nil)
20
21
  end
21
22
  if #array == 0 then
22
23
  error("Failed to get a random array index since the provided array is empty.")
@@ -25,7 +26,7 @@ function ____exports.getRandomArrayIndex(self, array, seed)
25
26
  end
26
27
  function ____exports.shuffleArrayInPlace(self, array, seed)
27
28
  if seed == nil then
28
- seed = Random()
29
+ seed = getRandomSeed(nil)
29
30
  end
30
31
  local currentIndex = #array
31
32
  local randomIndex
@@ -117,7 +118,7 @@ function ____exports.getLastElement(self, array)
117
118
  end
118
119
  function ____exports.getRandomArrayElement(self, array, seed, exceptions)
119
120
  if seed == nil then
120
- seed = Random()
121
+ seed = getRandomSeed(nil)
121
122
  end
122
123
  if exceptions == nil then
123
124
  exceptions = {}
@@ -135,7 +136,7 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
135
136
  end
136
137
  function ____exports.getRandomArrayElementAndRemove(self, array, seed, exceptions)
137
138
  if seed == nil then
138
- seed = Random()
139
+ seed = getRandomSeed(nil)
139
140
  end
140
141
  if exceptions == nil then
141
142
  exceptions = {}
@@ -194,7 +195,7 @@ function ____exports.isArrayInArray(self, arrayToMatch, parentArray)
194
195
  end
195
196
  function ____exports.shuffleArray(self, originalArray, seed)
196
197
  if seed == nil then
197
- seed = Random()
198
+ seed = getRandomSeed(nil)
198
199
  end
199
200
  local array = ____exports.copyArray(nil, originalArray)
200
201
  ____exports.shuffleArrayInPlace(nil, array, seed)
@@ -43,13 +43,13 @@ export declare function getMaxCards(): int;
43
43
  * - any objects like Dice Shard
44
44
  * - any modded cards.
45
45
  *
46
- * @param seed Optional. The seed with which to select the random card. Default is `Random()`.
46
+ * @param seed Optional. The seed with which to select the random card. Default is `getRandomSeed()`.
47
47
  * @param exceptions Optional. An array of cards to not select.
48
48
  */
49
49
  export declare function getRandomCard(seed?: Seed, exceptions?: Card[]): Card;
50
50
  /**
51
51
  * @param cardType The card type that represents the pool of cards to select from.
52
- * @param seed Optional. The seed with which to select the random card. Default is `Random()`.
52
+ * @param seed Optional. The seed with which to select the random card. Default is `getRandomSeed()`.
53
53
  * @param exceptions Optional. An array of cards to not select.
54
54
  */
55
55
  export declare function getRandomCardOfType(cardType: CardType, seed?: Seed, exceptions?: Card[]): Card;
@@ -57,7 +57,8 @@ export declare function getRandomCardOfType(cardType: CardType, seed?: Seed, exc
57
57
  * Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul of
58
58
  * Isaac, etc.). This will never return a Rune Shard.
59
59
  *
60
- * @param seed Optional. The seed with which to select the random rune. Default is `Random()`.
60
+ * @param seed Optional. The seed with which to select the random rune. Default is
61
+ * `getRandomSeed()`.
61
62
  * @param exceptions Optional. An array of runes to not select.
62
63
  */
63
64
  export declare function getRandomRune(seed?: Seed, exceptions?: Card[]): Card;
@@ -20,6 +20,8 @@ local CARD_TYPES = ____cardTypes.CARD_TYPES
20
20
  local DEFAULT_CARD_TYPE = ____cardTypes.DEFAULT_CARD_TYPE
21
21
  local ____math = require("functions.math")
22
22
  local range = ____math.range
23
+ local ____random = require("functions.random")
24
+ local getRandomSeed = ____random.getRandomSeed
23
25
  local ____set = require("functions.set")
24
26
  local addSetsToSet = ____set.addSetsToSet
25
27
  local getRandomSetElement = ____set.getRandomSetElement
@@ -100,7 +102,7 @@ function ____exports.getCardName(self, card)
100
102
  end
101
103
  function ____exports.getRandomCard(self, seed, exceptions)
102
104
  if seed == nil then
103
- seed = Random()
105
+ seed = getRandomSeed(nil)
104
106
  end
105
107
  if exceptions == nil then
106
108
  exceptions = {}
@@ -109,7 +111,7 @@ function ____exports.getRandomCard(self, seed, exceptions)
109
111
  end
110
112
  function ____exports.getRandomCardOfType(self, cardType, seed, exceptions)
111
113
  if seed == nil then
112
- seed = Random()
114
+ seed = getRandomSeed(nil)
113
115
  end
114
116
  if exceptions == nil then
115
117
  exceptions = {}
@@ -119,7 +121,7 @@ function ____exports.getRandomCardOfType(self, cardType, seed, exceptions)
119
121
  end
120
122
  function ____exports.getRandomRune(self, seed, exceptions)
121
123
  if seed == nil then
122
- seed = Random()
124
+ seed = getRandomSeed(nil)
123
125
  end
124
126
  if exceptions == nil then
125
127
  exceptions = {}
@@ -2,7 +2,7 @@
2
2
  local ____exports = {}
3
3
  local json = require("@NoResolution:json")
4
4
  local ____log = require("functions.log")
5
- local log = ____log.log
5
+ local logError = ____log.logError
6
6
  local function tryDecode(jsonString)
7
7
  return json.decode(jsonString)
8
8
  end
@@ -12,7 +12,7 @@ end
12
12
  function ____exports.jsonDecode(self, jsonString)
13
13
  local ok, luaTableOrErrMsg = pcall(tryDecode, jsonString)
14
14
  if not ok then
15
- log("Error: Failed to convert the JSON string to a Lua table: " .. jsonString)
15
+ logError("Failed to convert the JSON string to a Lua table: " .. jsonString)
16
16
  return {}
17
17
  end
18
18
  return luaTableOrErrMsg
@@ -9,6 +9,7 @@ local ____log = require("functions.log")
9
9
  local log = ____log.log
10
10
  local ____random = require("functions.random")
11
11
  local getRandomFloat = ____random.getRandomFloat
12
+ local getRandomSeed = ____random.getRandomSeed
12
13
  function getTotalWeightOfJSONRooms(self, jsonRooms)
13
14
  local weights = __TS__ArrayMap(
14
15
  jsonRooms,
@@ -66,7 +67,7 @@ function ____exports.getJSONRoomsOfSubType(self, jsonRooms, subType)
66
67
  end
67
68
  function ____exports.getRandomJSONRoom(self, jsonRooms, seed, verbose)
68
69
  if seed == nil then
69
- seed = Random()
70
+ seed = getRandomSeed(nil)
70
71
  end
71
72
  if verbose == nil then
72
73
  verbose = false
@@ -14,16 +14,27 @@ export declare function logArray<T>(this: void, array: T[]): void;
14
14
  export declare function logColor(this: void, color: Color): void;
15
15
  /** Helper function for printing out every damage flag that is turned on. Useful when debugging. */
16
16
  export declare function logDamageFlags(this: void, flags: int): void;
17
+ /** Helper function for printing out every entity (or filtered entity) in the current room. */
17
18
  export declare function logEntities(this: void, includeBackgroundEffects: boolean, entityTypeFilter?: EntityType | int): void;
18
19
  export declare function logEntity(this: void, entity: Entity): void;
19
20
  /** Helper function for printing out every entity flag that is turned on. Useful when debugging. */
20
21
  export declare function logEntityFlags(this: void, flags: int): void;
22
+ /**
23
+ * Helper function to log an error message and also print it to the console for better visibility.
24
+ * This is useful in combination with an early return when invoking the `error` function would be
25
+ * dangerous (since it prevents all of the subsequent code in the callback from running).
26
+ */
27
+ export declare function logError(this: void, msg: string): void;
21
28
  /** Helper function for printing out every flag that is turned on. Useful when debugging. */
22
29
  export declare function logFlags(this: void, flags: int, flagEnum?: LuaTable, description?: string): void;
23
30
  /**
24
31
  * Helper function for printing out every game state flag that is turned on. Useful when debugging.
25
32
  */
26
33
  export declare function logGameStateFlags(this: void): void;
34
+ /**
35
+ * Helper function for printing out every grid entity (or filtered grid entity) in the current
36
+ * room.
37
+ */
27
38
  export declare function logGridEntities(this: void, includeWalls: boolean, gridEntityTypeFilter?: GridEntityType | int): void;
28
39
  export declare function logKColor(this: void, kColor: KColor): void;
29
40
  export declare function logMap(this: void, map: Map<AnyNotNil, unknown>): void;
@@ -47,7 +58,7 @@ export declare function logTable(this: void, table: unknown, parentTables?: numb
47
58
  export declare function logTearFlags(this: void, flags: int): void;
48
59
  export declare function logTemporaryEffects(this: void, player: EntityPlayer): void;
49
60
  /** Helper function for printing out every use flag that is turned on. Useful when debugging. */
50
- export declare function logUseFlags(this: void, _flags: int): void;
61
+ export declare function logUseFlags(this: void, flags: int): void;
51
62
  export declare function logVector(this: void, vector: Vector): void;
52
63
  /**
53
64
  * Converts every `isaacscript-common` function that begins with "log" to a global function.
@@ -35,6 +35,8 @@ local ____set = require("functions.set")
35
35
  local getSortedSetValues = ____set.getSortedSetValues
36
36
  local ____trinkets = require("functions.trinkets")
37
37
  local getTrinketName = ____trinkets.getTrinketName
38
+ local ____utils = require("functions.utils")
39
+ local printConsole = ____utils.printConsole
38
40
  function ____exports.getDebugPrependString(self, msg, numParentFunctions)
39
41
  if numParentFunctions == nil then
40
42
  numParentFunctions = 3
@@ -76,14 +78,14 @@ function ____exports.logFlags(flags, flagEnum, description)
76
78
  for key, value in pairs(flagEnum) do
77
79
  do
78
80
  if type(value) ~= "number" then
79
- goto __continue34
81
+ goto __continue35
80
82
  end
81
83
  if hasFlag(nil, flags, value) then
82
84
  ____exports.log((((" Has flag: " .. tostring(key)) .. " (") .. tostring(value)) .. ")")
83
85
  hasNoFlags = false
84
86
  end
85
87
  end
86
- ::__continue34::
88
+ ::__continue35::
87
89
  end
88
90
  if hasNoFlags then
89
91
  ____exports.log(" n/a (no flags)")
@@ -194,6 +196,11 @@ end
194
196
  function ____exports.logEntityFlags(flags)
195
197
  ____exports.logFlags(flags, EntityFlag, "entity")
196
198
  end
199
+ function ____exports.logError(msg)
200
+ local errorMsg = "Error: " .. msg
201
+ ____exports.log(errorMsg)
202
+ printConsole(nil, errorMsg)
203
+ end
197
204
  function ____exports.logGameStateFlags()
198
205
  ____exports.log("Logging game state flags:")
199
206
  local hasNoFlags = true
@@ -405,8 +412,8 @@ function ____exports.logTemporaryEffects(player)
405
412
  end
406
413
  )
407
414
  end
408
- function ____exports.logUseFlags(_flags)
409
- ____exports.log("The \"logUseFlags\" helper function is temporarily disabled while the UseFlag enum remains unpatched in vanilla.")
415
+ function ____exports.logUseFlags(flags)
416
+ ____exports.logFlags(flags, UseFlag, "use")
410
417
  end
411
418
  function ____exports.logVector(vector)
412
419
  ____exports.log(((("Vector: (" .. tostring(vector.X)) .. ", ") .. tostring(vector.Y)) .. ")")
@@ -420,6 +427,7 @@ function ____exports.setLogFunctionsGlobal(self)
420
427
  globals.logEntities = ____exports.logEntities
421
428
  globals.logEntity = ____exports.logEntity
422
429
  globals.logEntityFlags = ____exports.logEntityFlags
430
+ globals.logError = ____exports.logError
423
431
  globals.logFlags = ____exports.logFlags
424
432
  globals.logGameStateFlags = ____exports.logGameStateFlags
425
433
  globals.logGridEntities = ____exports.logGridEntities
@@ -25,6 +25,12 @@ export declare function getRandomFloat(min: int, max: int, seed?: Seed): float;
25
25
  * ```
26
26
  */
27
27
  export declare function getRandomInt(min: int, max: int, seed?: Seed): int;
28
+ /**
29
+ * Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
30
+ * instead of calling the `Random` function directly since that can return a value of 0 and crash
31
+ * the game.
32
+ */
33
+ export declare function getRandomSeed(): Seed;
28
34
  /**
29
35
  * Helper function to initialize an RNG object.
30
36
  *
@@ -38,7 +44,7 @@ export declare function getRandomInt(min: int, max: int, seed?: Seed): int;
38
44
  * It is recommended to not deal with RNG objects directly and instead use seeds. Also see the
39
45
  * `getRandom`, `getRandomInt`, and `getRandomFloat` helper functions.
40
46
  *
41
- * @param seed The seed to initialize it with. Default is `Random()`.
47
+ * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
42
48
  */
43
49
  export declare function initRNG(seed?: Seed): RNG;
44
50
  /**
@@ -1,9 +1,14 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
3
  local RECOMMENDED_SHIFT_IDX
4
+ function ____exports.getRandomSeed(self)
5
+ local random = Random()
6
+ local safeRandomValue = random == 0 and 1 or random
7
+ return safeRandomValue
8
+ end
4
9
  function ____exports.initRNG(self, seed)
5
10
  if seed == nil then
6
- seed = Random()
11
+ seed = ____exports.getRandomSeed(nil)
7
12
  end
8
13
  if seed == 0 then
9
14
  error("You cannot initialize an RNG object with a seed of 0, or the game will crash.")
@@ -15,20 +20,20 @@ end
15
20
  RECOMMENDED_SHIFT_IDX = 35
16
21
  function ____exports.getRandom(self, seed)
17
22
  if seed == nil then
18
- seed = Random()
23
+ seed = ____exports.getRandomSeed(nil)
19
24
  end
20
25
  local rng = ____exports.initRNG(nil, seed)
21
26
  return rng:RandomFloat()
22
27
  end
23
28
  function ____exports.getRandomFloat(self, min, max, seed)
24
29
  if seed == nil then
25
- seed = Random()
30
+ seed = ____exports.getRandomSeed(nil)
26
31
  end
27
32
  return min + ____exports.getRandom(nil, seed) * (max - min)
28
33
  end
29
34
  function ____exports.getRandomInt(self, min, max, seed)
30
35
  if seed == nil then
31
- seed = Random()
36
+ seed = ____exports.getRandomSeed(nil)
32
37
  end
33
38
  local rng = ____exports.initRNG(nil, seed)
34
39
  return rng:RandomInt(max - min + 1) + min
@@ -2,6 +2,9 @@
2
2
  local ____exports = {}
3
3
  local ____cachedClasses = require("cachedClasses")
4
4
  local game = ____cachedClasses.game
5
+ local ____constants = require("constants")
6
+ local MAX_TAINTED_SAMSON_BERSERK_CHARGE = ____constants.MAX_TAINTED_SAMSON_BERSERK_CHARGE
7
+ local TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE = ____constants.TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE
5
8
  local ____character = require("functions.character")
6
9
  local getCharacterDeathAnimationName = ____character.getCharacterDeathAnimationName
7
10
  local ____player = require("functions.player")
@@ -44,6 +47,10 @@ function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSou
44
47
  if isBerserk then
45
48
  return false
46
49
  end
50
+ local berserkChargeAfterHit = player.SamsonBerserkCharge + TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE
51
+ if character == PlayerType.PLAYER_SAMSON_B and berserkChargeAfterHit >= MAX_TAINTED_SAMSON_BERSERK_CHARGE then
52
+ return false
53
+ end
47
54
  if ____exports.willReviveFromSpiritShackles(nil, player) then
48
55
  return false
49
56
  end
@@ -25,7 +25,7 @@ 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 seed Optional. The seed used to select the random element. Default is `Random()`.
28
+ * @param seed Optional. The seed used to select the random element. Default is `getRandomSeed()`.
29
29
  * @param exceptions Optional. An array of elements to skip over if selected.
30
30
  */
31
31
  export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, seed?: Seed, exceptions?: T[] | readonly T[]): T;
@@ -7,6 +7,8 @@ local __TS__ArraySort = ____lualib.__TS__ArraySort
7
7
  local ____exports = {}
8
8
  local ____array = require("functions.array")
9
9
  local getRandomArrayElement = ____array.getRandomArrayElement
10
+ local ____random = require("functions.random")
11
+ local getRandomSeed = ____random.getRandomSeed
10
12
  function ____exports.getSortedSetValues(self, set)
11
13
  local values = set:values()
12
14
  local array = {__TS__Spread(values)}
@@ -48,7 +50,7 @@ function ____exports.deleteSetsFromSet(self, mainSet, ...)
48
50
  end
49
51
  function ____exports.getRandomSetElement(self, set, seed, exceptions)
50
52
  if seed == nil then
51
- seed = Random()
53
+ seed = getRandomSeed(nil)
52
54
  end
53
55
  if exceptions == nil then
54
56
  exceptions = {}
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @param collectibleType The collectible type to spawn.
9
9
  * @param position The position to spawn the collectible at.
10
- * @param seed Optional. Default is `Random()`.
10
+ * @param seed Optional. Default is `getRandomSeed()`.
11
11
  * @param options Optional. Set to true to make the collectible a "There's Options" style
12
12
  * collectible. Default is false.
13
13
  * @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
@@ -11,9 +11,11 @@ local isQuestCollectible = ____collectibles.isQuestCollectible
11
11
  local setCollectibleEmpty = ____collectibles.setCollectibleEmpty
12
12
  local ____player = require("functions.player")
13
13
  local anyPlayerIs = ____player.anyPlayerIs
14
+ local ____random = require("functions.random")
15
+ local getRandomSeed = ____random.getRandomSeed
14
16
  function ____exports.spawnCollectible(self, collectibleType, position, seed, options, forceFreeItem)
15
17
  if seed == nil then
16
- seed = Random()
18
+ seed = getRandomSeed(nil)
17
19
  end
18
20
  if options == nil then
19
21
  options = false
@@ -50,7 +52,7 @@ function ____exports.spawnCollectible(self, collectibleType, position, seed, opt
50
52
  end
51
53
  function ____exports.spawnEmptyCollectible(self, position, seed)
52
54
  if seed == nil then
53
- seed = Random()
55
+ seed = getRandomSeed(nil)
54
56
  end
55
57
  local collectible = ____exports.spawnCollectible(
56
58
  nil,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.200",
3
+ "version": "1.2.201",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,7 +25,7 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.377",
28
+ "isaac-typescript-definitions": "^1.0.379",
29
29
  "isaacscript-lint": "^1.0.95",
30
30
  "isaacscript-tsconfig": "^1.1.8",
31
31
  "typedoc": "^0.22.13",