isaacscript-common 6.13.0 → 6.16.0
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/callbacks/postGridEntityCustomCollision.d.ts +2 -0
- package/dist/callbacks/postGridEntityCustomCollision.d.ts.map +1 -0
- package/dist/callbacks/postGridEntityCustomCollision.lua +71 -0
- package/dist/callbacks/postGridEntityCustomRender.lua +0 -7
- package/dist/callbacks/postGridEntityCustomUpdate.lua +0 -7
- package/dist/callbacks/subscriptions/postGridEntityCustomBroken.d.ts +6 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomBroken.d.ts.map +1 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomBroken.lua +29 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomCollision.d.ts +6 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomCollision.d.ts.map +1 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomCollision.lua +29 -0
- package/dist/enums/ModCallbackCustom.d.ts +96 -62
- package/dist/enums/ModCallbackCustom.d.ts.map +1 -1
- package/dist/enums/ModCallbackCustom.lua +64 -60
- package/dist/enums/private/SerializationBrand.d.ts +1 -1
- package/dist/enums/private/SerializationBrand.lua +1 -1
- package/dist/features/customGridEntity.d.ts +7 -3
- package/dist/features/customGridEntity.d.ts.map +1 -1
- package/dist/features/customGridEntity.lua +67 -7
- package/dist/features/extraConsoleCommands/exports.d.ts +4 -3
- package/dist/features/extraConsoleCommands/exports.d.ts.map +1 -1
- package/dist/features/extraConsoleCommands/exports.lua +4 -3
- package/dist/features/extraConsoleCommands/init.lua +1 -0
- package/dist/functions/collectibles.d.ts +6 -2
- package/dist/functions/collectibles.d.ts.map +1 -1
- package/dist/functions/collectibles.lua +4 -2
- package/dist/functions/color.d.ts +20 -14
- package/dist/functions/color.d.ts.map +1 -1
- package/dist/functions/color.lua +78 -73
- package/dist/functions/deepCopy.d.ts.map +1 -1
- package/dist/functions/deepCopy.lua +22 -1
- package/dist/functions/gridEntities.d.ts +2 -36
- package/dist/functions/gridEntities.d.ts.map +1 -1
- package/dist/functions/gridEntities.lua +2 -78
- package/dist/functions/isaacAPIClass.d.ts +1 -1
- package/dist/functions/isaacAPIClass.d.ts.map +1 -1
- package/dist/functions/itemPool.d.ts +10 -0
- package/dist/functions/itemPool.d.ts.map +1 -0
- package/dist/functions/itemPool.lua +116 -0
- package/dist/functions/kColor.d.ts +20 -14
- package/dist/functions/kColor.d.ts.map +1 -1
- package/dist/functions/kColor.lua +65 -60
- package/dist/functions/mergeTests.lua +2 -2
- package/dist/functions/npcs.d.ts +1 -29
- package/dist/functions/npcs.d.ts.map +1 -1
- package/dist/functions/npcs.lua +0 -45
- package/dist/functions/projectiles.d.ts +32 -0
- package/dist/functions/projectiles.d.ts.map +1 -0
- package/dist/functions/projectiles.lua +73 -0
- package/dist/functions/random.d.ts +1 -1
- package/dist/functions/random.lua +1 -1
- package/dist/functions/rng.d.ts +11 -15
- package/dist/functions/rng.d.ts.map +1 -1
- package/dist/functions/rng.lua +32 -52
- package/dist/functions/rockAlt.d.ts +48 -0
- package/dist/functions/rockAlt.d.ts.map +1 -0
- package/dist/functions/rockAlt.lua +365 -0
- package/dist/functions/saveFile.d.ts +8 -7
- package/dist/functions/saveFile.d.ts.map +1 -1
- package/dist/functions/saveFile.lua +10 -96
- package/dist/functions/serialization.d.ts +26 -7
- package/dist/functions/serialization.d.ts.map +1 -1
- package/dist/functions/serialization.lua +51 -19
- package/dist/functions/table.d.ts +2 -2
- package/dist/functions/table.lua +2 -2
- package/dist/functions/trinketGive.d.ts +13 -0
- package/dist/functions/trinketGive.d.ts.map +1 -1
- package/dist/functions/trinketGive.lua +16 -0
- package/dist/functions/tstlClass.d.ts +1 -1
- package/dist/functions/tstlClass.d.ts.map +1 -1
- package/dist/functions/vector.d.ts +21 -14
- package/dist/functions/vector.d.ts.map +1 -1
- package/dist/functions/vector.lua +58 -54
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.lua +16 -0
- package/dist/initCustomCallbacks.d.ts.map +1 -1
- package/dist/initCustomCallbacks.lua +3 -0
- package/dist/interfaces/AddCallbackParameterCustom.d.ts +4 -0
- package/dist/interfaces/AddCallbackParameterCustom.d.ts.map +1 -1
- package/dist/objects/callbackRegisterFunctions.d.ts.map +1 -1
- package/dist/objects/callbackRegisterFunctions.lua +6 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.d.ts +12 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.d.ts.map +1 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.lua +25 -0
- package/dist/types/{private/IsaacAPIClass.d.ts → IsaacAPIClass.d.ts} +0 -0
- package/dist/types/IsaacAPIClass.d.ts.map +1 -0
- package/dist/types/{private/IsaacAPIClass.lua → IsaacAPIClass.lua} +0 -0
- package/dist/types/{private/SerializedIsaacAPIClass.d.ts → SerializedIsaacAPIClass.d.ts} +0 -0
- package/dist/types/SerializedIsaacAPIClass.d.ts.map +1 -0
- package/dist/types/{private/SerializedIsaacAPIClass.lua → SerializedIsaacAPIClass.lua} +0 -0
- package/dist/types/{private/TSTLClass.d.ts → TSTLClass.d.ts} +0 -0
- package/dist/types/TSTLClass.d.ts.map +1 -0
- package/dist/types/{private/TSTLClass.lua → TSTLClass.lua} +0 -0
- package/package.json +2 -2
- package/src/callbacks/postGridEntityCustomCollision.ts +74 -0
- package/src/callbacks/postGridEntityCustomRender.ts +1 -17
- package/src/callbacks/postGridEntityCustomUpdate.ts +1 -17
- package/src/callbacks/subscriptions/postGridEntityCustomBroken.ts +41 -0
- package/src/callbacks/subscriptions/postGridEntityCustomCollision.ts +43 -0
- package/src/enums/ModCallbackCustom.ts +38 -2
- package/src/enums/private/SerializationBrand.ts +1 -1
- package/src/features/customGridEntity.ts +78 -2
- package/src/features/extraConsoleCommands/exports.ts +4 -3
- package/src/features/extraConsoleCommands/init.ts +1 -0
- package/src/features/extraConsoleCommands/listCommands.ts +2 -2
- package/src/functions/collectibles.ts +6 -2
- package/src/functions/color.ts +89 -87
- package/src/functions/deepCopy.ts +15 -2
- package/src/functions/gridEntities.ts +2 -77
- package/src/functions/isaacAPIClass.ts +1 -1
- package/src/functions/itemPool.ts +153 -0
- package/src/functions/kColor.ts +87 -84
- package/src/functions/mergeTests.ts +2 -2
- package/src/functions/npcs.ts +1 -58
- package/src/functions/projectiles.ts +78 -0
- package/src/functions/random.ts +1 -1
- package/src/functions/rng.ts +45 -65
- package/src/functions/rockAlt.ts +396 -0
- package/src/functions/saveFile.ts +13 -119
- package/src/functions/serialization.ts +81 -25
- package/src/functions/table.ts +2 -2
- package/src/functions/trinketGive.ts +21 -0
- package/src/functions/tstlClass.ts +1 -1
- package/src/functions/vector.ts +78 -74
- package/src/index.ts +2 -0
- package/src/initCustomCallbacks.ts +2 -0
- package/src/interfaces/AddCallbackParameterCustom.ts +4 -0
- package/src/objects/callbackRegisterFunctions.ts +6 -0
- package/src/objects/isaacAPIClassTypeToFunctions.ts +63 -0
- package/src/types/{private/IsaacAPIClass.ts → IsaacAPIClass.ts} +0 -0
- package/src/types/{private/SerializedIsaacAPIClass.ts → SerializedIsaacAPIClass.ts} +0 -0
- package/src/types/{private/TSTLClass.ts → TSTLClass.ts} +0 -0
- package/dist/objects/isaacAPIClassTypeToCopyFunction.d.ts +0 -6
- package/dist/objects/isaacAPIClassTypeToCopyFunction.d.ts.map +0 -1
- package/dist/objects/isaacAPIClassTypeToCopyFunction.lua +0 -13
- package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.d.ts +0 -5
- package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.d.ts.map +0 -1
- package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.lua +0 -13
- package/dist/types/private/IsaacAPIClass.d.ts.map +0 -1
- package/dist/types/private/SerializedIsaacAPIClass.d.ts.map +0 -1
- package/dist/types/private/TSTLClass.d.ts.map +0 -1
- package/src/objects/isaacAPIClassTypeToCopyFunction.ts +0 -18
- package/src/objects/serializedIsaacAPIClassTypeToIdentityFunction.ts +0 -14
package/src/functions/kColor.ts
CHANGED
|
@@ -1,101 +1,87 @@
|
|
|
1
1
|
import { SerializationBrand } from "../enums/private/SerializationBrand";
|
|
2
|
-
import { SerializationType } from "../enums/SerializationType";
|
|
3
2
|
import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
3
|
+
import { getRandom } from "./random";
|
|
4
|
+
import { getRandomSeed, isRNG, newRNG } from "./rng";
|
|
4
5
|
import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
|
|
5
6
|
import { isTable } from "./types";
|
|
6
7
|
|
|
7
|
-
type SerializedKColor = LuaMap<string, unknown> & {
|
|
8
|
+
export type SerializedKColor = LuaMap<string, unknown> & {
|
|
8
9
|
readonly __serializedKColorBrand: symbol;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
interface CopyKColorReturn {
|
|
12
|
-
[SerializationType.NONE]: KColor;
|
|
13
|
-
[SerializationType.SERIALIZE]: SerializedKColor;
|
|
14
|
-
[SerializationType.DESERIALIZE]: KColor;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
12
|
const KEYS = ["Red", "Green", "Blue", "Alpha"];
|
|
18
13
|
const OBJECT_NAME = "KColor";
|
|
19
14
|
|
|
15
|
+
/** Helper function to copy a `KColor` Isaac API class. */
|
|
16
|
+
export function copyKColor(kColor: KColor): KColor {
|
|
17
|
+
if (!isKColor(kColor)) {
|
|
18
|
+
error(
|
|
19
|
+
`Failed to copy a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return KColor(kColor.Red, kColor.Green, kColor.Blue, kColor.Alpha);
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
/**
|
|
21
|
-
* Helper function to
|
|
22
|
-
*
|
|
23
|
-
* @param kColor The KColor object to copy. In the case of deserialization, this will actually be a
|
|
24
|
-
* Lua table instead of an instantiated KColor class.
|
|
25
|
-
* @param serializationType Default is `SerializationType.NONE`.
|
|
27
|
+
* Helper function to convert a `SerializedKColor` object to a normal `KColor` object. (This is used
|
|
28
|
+
* by the save data manager when reading data from the "save#.dat" file.)
|
|
26
29
|
*/
|
|
27
|
-
export function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return kColorTable as SerializedKColor;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
case SerializationType.DESERIALIZE: {
|
|
63
|
-
if (!isTable(kColor)) {
|
|
64
|
-
error(
|
|
65
|
-
`Failed to deserialize a ${OBJECT_NAME} object since the provided object was not a Lua table.`,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const [r, g, b, a] = getNumbersFromTable(
|
|
70
|
-
kColor as LuaMap<string, unknown>,
|
|
71
|
-
OBJECT_NAME,
|
|
72
|
-
...KEYS,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
if (r === undefined) {
|
|
76
|
-
error(
|
|
77
|
-
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: r`,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
if (g === undefined) {
|
|
81
|
-
error(
|
|
82
|
-
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: g`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
if (b === undefined) {
|
|
86
|
-
error(
|
|
87
|
-
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: b`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
if (a === undefined) {
|
|
91
|
-
error(
|
|
92
|
-
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: a`,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return KColor(r, g, b, a);
|
|
97
|
-
}
|
|
30
|
+
export function deserializeKColor(kColor: SerializedKColor): KColor {
|
|
31
|
+
if (!isTable(kColor)) {
|
|
32
|
+
error(
|
|
33
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object was not a Lua table.`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const [r, g, b, a] = getNumbersFromTable(
|
|
38
|
+
kColor as LuaMap<string, unknown>,
|
|
39
|
+
OBJECT_NAME,
|
|
40
|
+
...KEYS,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (r === undefined) {
|
|
44
|
+
error(
|
|
45
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: Red`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (g === undefined) {
|
|
49
|
+
error(
|
|
50
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: Green`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (b === undefined) {
|
|
54
|
+
error(
|
|
55
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: Blue`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (a === undefined) {
|
|
59
|
+
error(
|
|
60
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: Alpha`,
|
|
61
|
+
);
|
|
98
62
|
}
|
|
63
|
+
|
|
64
|
+
return KColor(r, g, b, a);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Helper function to get a random color.
|
|
69
|
+
*
|
|
70
|
+
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
71
|
+
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
72
|
+
* @param alpha Optional. The alpha value to use. Default is 1.
|
|
73
|
+
*/
|
|
74
|
+
export function getRandomKColor(
|
|
75
|
+
seedOrRNG: Seed | RNG = getRandomSeed(),
|
|
76
|
+
alpha = 1,
|
|
77
|
+
): KColor {
|
|
78
|
+
const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
|
|
79
|
+
|
|
80
|
+
const r = getRandom(rng);
|
|
81
|
+
const g = getRandom(rng);
|
|
82
|
+
const b = getRandom(rng);
|
|
83
|
+
|
|
84
|
+
return KColor(r, g, b, alpha);
|
|
99
85
|
}
|
|
100
86
|
|
|
101
87
|
/** Helper function to check if something is an instantiated KColor object. */
|
|
@@ -122,3 +108,20 @@ export function isSerializedKColor(
|
|
|
122
108
|
export function kColorEquals(kColor1: KColor, kColor2: KColor): boolean {
|
|
123
109
|
return isaacAPIClassEquals(kColor1, kColor2, KEYS);
|
|
124
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Helper function to convert a `KColor` object to a `SerializedKColor` object. (This is used by the
|
|
114
|
+
* save data manager when writing data from the "save#.dat" file.)
|
|
115
|
+
*/
|
|
116
|
+
export function serializeKColor(kColor: KColor): SerializedKColor {
|
|
117
|
+
if (!isKColor(kColor)) {
|
|
118
|
+
error(
|
|
119
|
+
`Failed to serialize a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const kColorTable = new LuaMap<string, unknown>();
|
|
124
|
+
copyValuesToTable(kColor, KEYS, kColorTable);
|
|
125
|
+
kColorTable.set(SerializationBrand.K_COLOR, "");
|
|
126
|
+
return kColorTable as SerializedKColor;
|
|
127
|
+
}
|
|
@@ -5,7 +5,7 @@ import { deepCopy } from "./deepCopy";
|
|
|
5
5
|
import { log } from "./log";
|
|
6
6
|
import { isRNG, newRNG } from "./rng";
|
|
7
7
|
import { isSerializedIsaacAPIClass } from "./serialization";
|
|
8
|
-
import {
|
|
8
|
+
import { isVector, serializeVector } from "./vector";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Run the suite of tests that prove that the "merge" function works properly. (This function is not
|
|
@@ -92,7 +92,7 @@ function oldTableHasSerializedIsaacAPIClass() {
|
|
|
92
92
|
const y = 60;
|
|
93
93
|
const vector = Vector(x, y);
|
|
94
94
|
|
|
95
|
-
const vectorSerialized =
|
|
95
|
+
const vectorSerialized = serializeVector(vector);
|
|
96
96
|
if (!isSerializedIsaacAPIClass(vectorSerialized)) {
|
|
97
97
|
error(
|
|
98
98
|
'The "isSerializedIsaacAPIClass" function says that a serialized vector is not serialized.',
|
package/src/functions/npcs.ts
CHANGED
|
@@ -11,13 +11,11 @@ import {
|
|
|
11
11
|
MotherVariant,
|
|
12
12
|
NpcState,
|
|
13
13
|
PeepVariant,
|
|
14
|
-
ProjectilesMode,
|
|
15
14
|
RaglingVariant,
|
|
16
15
|
VisVariant,
|
|
17
16
|
} from "isaac-typescript-definitions";
|
|
18
17
|
import { EGGY_STATE_FRAME_OF_FINAL_SPIDER } from "../constants";
|
|
19
|
-
import {
|
|
20
|
-
import { getNPCs, getProjectiles } from "./entitiesSpecific";
|
|
18
|
+
import { getNPCs } from "./entitiesSpecific";
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
21
|
* Used to filter out certain NPCs when determining of an NPC is "alive" and/or should keep the
|
|
@@ -46,33 +44,6 @@ const NON_ALIVE_NPCS_TYPE_VARIANT_SUBTYPE: ReadonlySet<string> = new Set([
|
|
|
46
44
|
`${EntityType.MOTHER}.${MotherVariant.MOTHER_1}.${MotherSubType.PHASE_2}`, // 912
|
|
47
45
|
]);
|
|
48
46
|
|
|
49
|
-
/**
|
|
50
|
-
* Helper function to make an NPC fire a projectile. Returns the fired projectile. Use this function
|
|
51
|
-
* instead of the `EntityNPC.FireProjectiles` method, since that returns void.
|
|
52
|
-
*
|
|
53
|
-
* @param npc The NPC to fire the projectile from.
|
|
54
|
-
* @param position The staring position of the projectile.
|
|
55
|
-
* @param velocity The starting velocity of the projectile.
|
|
56
|
-
* @param projectilesMode The mode of the projectile. Optional. Default is
|
|
57
|
-
* `ProjectilesMode.ONE_PROJECTILE`.
|
|
58
|
-
* @param projectileParams The parameters of the projectile. Optional. Default is
|
|
59
|
-
* `ProjectileParams()`.
|
|
60
|
-
* @returns The fired projectile.
|
|
61
|
-
*/
|
|
62
|
-
export function fireProjectiles(
|
|
63
|
-
npc: EntityNPC,
|
|
64
|
-
position: Vector,
|
|
65
|
-
velocity: Vector,
|
|
66
|
-
projectilesMode: ProjectilesMode = ProjectilesMode.ONE_PROJECTILE,
|
|
67
|
-
projectileParams: ProjectileParams = ProjectileParams(),
|
|
68
|
-
): EntityProjectile[] {
|
|
69
|
-
const oldProjectiles = getProjectiles(projectileParams.Variant);
|
|
70
|
-
npc.FireProjectiles(position, velocity, projectilesMode, projectileParams);
|
|
71
|
-
const newProjectiles = getProjectiles(projectileParams.Variant);
|
|
72
|
-
|
|
73
|
-
return getFilteredNewEntities(oldProjectiles, newProjectiles);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
47
|
/**
|
|
77
48
|
* Helper function to get all of the non-dead NPCs in the room.
|
|
78
49
|
*
|
|
@@ -149,31 +120,3 @@ export function isRaglingDeathPatch(npc: EntityNPC): boolean {
|
|
|
149
120
|
npc.State === NpcState.SPECIAL
|
|
150
121
|
);
|
|
151
122
|
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* The base game `EntityNPC.FireProjectiles` method does not return anything, which is a problem in
|
|
155
|
-
* situations where you need to work with the fired projectiles. This function invokes that method,
|
|
156
|
-
* and then returns the projectiles that were spawned.
|
|
157
|
-
*
|
|
158
|
-
* @param npc The EntityNPC firing projectiles.
|
|
159
|
-
* @param position The starting position of the projectiles.
|
|
160
|
-
* @param velocity The starting velocity of the projectiles.
|
|
161
|
-
* @param projectilesMode A ProjectilesMode enum value defining how to fire the projectiles.
|
|
162
|
-
* @param projectileParams A ProjectileParams object containing various parameters for the
|
|
163
|
-
* projectiles.
|
|
164
|
-
* @returns An array of EntityProjectiles containing all fired projectiles.
|
|
165
|
-
*/
|
|
166
|
-
export function npcFireProjectiles(
|
|
167
|
-
npc: EntityNPC,
|
|
168
|
-
position: Vector,
|
|
169
|
-
velocity: Vector,
|
|
170
|
-
projectilesMode: ProjectilesMode,
|
|
171
|
-
projectileParams: ProjectileParams,
|
|
172
|
-
): EntityProjectile[] {
|
|
173
|
-
const oldEntities = getProjectiles();
|
|
174
|
-
npc.FireProjectiles(position, velocity, projectilesMode, projectileParams);
|
|
175
|
-
const newEntities = getProjectiles();
|
|
176
|
-
const filteredNewEntities = getFilteredNewEntities(oldEntities, newEntities);
|
|
177
|
-
|
|
178
|
-
return filteredNewEntities;
|
|
179
|
-
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EntityFlag,
|
|
3
|
+
EntityType,
|
|
4
|
+
ProjectilesMode,
|
|
5
|
+
} from "isaac-typescript-definitions";
|
|
6
|
+
import { getFilteredNewEntities } from "./entities";
|
|
7
|
+
import { getProjectiles, spawnNPC } from "./entitiesSpecific";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to make an NPC fire one or more projectiles. Returns the fired projectile(s).
|
|
11
|
+
*
|
|
12
|
+
* Use this function instead of the `EntityNPC.FireProjectiles` method if you need to modify or
|
|
13
|
+
* access the `EntityProjectile` objects after they are fired, since this function returns the
|
|
14
|
+
* objects in an array.
|
|
15
|
+
*
|
|
16
|
+
* @param npc The NPC to fire the projectile(s) from. You can also pass undefined if you do not want
|
|
17
|
+
* the projectile(s) to come from anything in particular.
|
|
18
|
+
* @param position The staring position of the projectile(s).
|
|
19
|
+
* @param velocity The starting velocity of the projectile(s).
|
|
20
|
+
* @param projectilesMode Optional. The mode of the projectile(s). Default is
|
|
21
|
+
* `ProjectilesMode.ONE_PROJECTILE`.
|
|
22
|
+
* @param projectileParams Optional. The parameters of the projectile(s). Default is
|
|
23
|
+
* `ProjectileParams()`.
|
|
24
|
+
* @returns The fired projectile(s).
|
|
25
|
+
*/
|
|
26
|
+
export function fireProjectiles(
|
|
27
|
+
npc: EntityNPC | undefined,
|
|
28
|
+
position: Vector,
|
|
29
|
+
velocity: Vector,
|
|
30
|
+
projectilesMode: ProjectilesMode = ProjectilesMode.ONE_PROJECTILE,
|
|
31
|
+
projectileParams: ProjectileParams = ProjectileParams(),
|
|
32
|
+
): EntityProjectile[] {
|
|
33
|
+
const oldProjectiles = getProjectiles(projectileParams.Variant);
|
|
34
|
+
|
|
35
|
+
let spawnedFly = false;
|
|
36
|
+
if (npc === undefined) {
|
|
37
|
+
// Since the `EntityNPC.FireProjectiles` method is not static, we arbitrarily spawn a fly.
|
|
38
|
+
spawnedFly = true;
|
|
39
|
+
npc = spawnNPC(EntityType.FLY, 0, 0, position);
|
|
40
|
+
npc.Visible = false;
|
|
41
|
+
npc.ClearEntityFlags(EntityFlag.APPEAR);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
npc.FireProjectiles(position, velocity, projectilesMode, projectileParams);
|
|
45
|
+
const newProjectiles = getProjectiles(projectileParams.Variant);
|
|
46
|
+
|
|
47
|
+
if (spawnedFly) {
|
|
48
|
+
npc.Remove();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return getFilteredNewEntities(oldProjectiles, newProjectiles);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Helper function to spawn projectiles in a circle around a position. Under the hood, this
|
|
56
|
+
* leverages `ProjectileMode.N_PROJECTILES_IN_CIRCLE`.
|
|
57
|
+
*
|
|
58
|
+
* @param npc The NPC to fire the projectile(s) from. You can also pass undefined if you do not want
|
|
59
|
+
* the projectile(s) to come from anything in particular.
|
|
60
|
+
* @param position The staring position of the projectile(s).
|
|
61
|
+
* @param speed The speed of the projectile(s).
|
|
62
|
+
* @param numProjectiles The amount of projectiles to spawn.
|
|
63
|
+
* @returns The fired projectile(s).
|
|
64
|
+
*/
|
|
65
|
+
export function fireProjectilesInCircle(
|
|
66
|
+
npc: EntityNPC | undefined,
|
|
67
|
+
position: Vector,
|
|
68
|
+
speed: float,
|
|
69
|
+
numProjectiles: int,
|
|
70
|
+
): EntityProjectile[] {
|
|
71
|
+
const velocity = Vector(speed, numProjectiles);
|
|
72
|
+
return fireProjectiles(
|
|
73
|
+
npc,
|
|
74
|
+
position,
|
|
75
|
+
velocity,
|
|
76
|
+
ProjectilesMode.N_PROJECTILES_IN_CIRCLE,
|
|
77
|
+
);
|
|
78
|
+
}
|
package/src/functions/random.ts
CHANGED
|
@@ -45,7 +45,7 @@ export function getRandomFloat(
|
|
|
45
45
|
/**
|
|
46
46
|
* This returns a random integer between min and max. It is inclusive on both ends.
|
|
47
47
|
*
|
|
48
|
-
* Note that this function will
|
|
48
|
+
* Note that this function will run the `Next` method on the `RNG` object before returning the
|
|
49
49
|
* random number.
|
|
50
50
|
*
|
|
51
51
|
* For example:
|
package/src/functions/rng.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { game } from "../cachedClasses";
|
|
2
2
|
import { SerializationBrand } from "../enums/private/SerializationBrand";
|
|
3
|
-
import { SerializationType } from "../enums/SerializationType";
|
|
4
3
|
import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
5
4
|
import { getNumbersFromTable, tableHasKeys } from "./table";
|
|
6
5
|
import { isTable } from "./types";
|
|
7
6
|
|
|
8
|
-
type SerializedRNG = LuaMap<string, unknown> & {
|
|
7
|
+
export type SerializedRNG = LuaMap<string, unknown> & {
|
|
9
8
|
readonly __serializedRNGBrand: symbol;
|
|
10
9
|
};
|
|
11
10
|
|
|
12
|
-
interface CopyRNGReturn {
|
|
13
|
-
[SerializationType.NONE]: RNG;
|
|
14
|
-
[SerializationType.SERIALIZE]: SerializedRNG;
|
|
15
|
-
[SerializationType.DESERIALIZE]: RNG;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
11
|
/**
|
|
19
12
|
* This is the ShiftIdx that Blade recommended after having reviewing the game's internal functions.
|
|
20
13
|
* Any value between 0 and 80 should work equally well.
|
|
@@ -25,66 +18,35 @@ const RECOMMENDED_SHIFT_IDX = 35;
|
|
|
25
18
|
const KEYS = ["seed"];
|
|
26
19
|
const OBJECT_NAME = "RNG";
|
|
27
20
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export function copyRNG<
|
|
36
|
-
R extends RNG | SerializedRNG,
|
|
37
|
-
S extends SerializationType,
|
|
38
|
-
>(rng: R, serializationType: S): CopyRNGReturn[S];
|
|
39
|
-
export function copyRNG<R extends RNG | SerializedRNG>(
|
|
40
|
-
rng: R,
|
|
41
|
-
): CopyRNGReturn[SerializationType.NONE];
|
|
42
|
-
export function copyRNG(
|
|
43
|
-
rng: RNG | SerializedRNG,
|
|
44
|
-
serializationType = SerializationType.NONE,
|
|
45
|
-
): CopyRNGReturn[keyof CopyRNGReturn] {
|
|
46
|
-
switch (serializationType) {
|
|
47
|
-
case SerializationType.NONE: {
|
|
48
|
-
if (!isRNG(rng)) {
|
|
49
|
-
error(
|
|
50
|
-
`Failed to copy a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const seed = rng.GetSeed();
|
|
55
|
-
return newRNG(seed);
|
|
56
|
-
}
|
|
21
|
+
/** Helper function to copy an `RNG` Isaac API class. */
|
|
22
|
+
export function copyRNG(rng: RNG): RNG {
|
|
23
|
+
if (!isRNG(rng)) {
|
|
24
|
+
error(
|
|
25
|
+
`Failed to copy a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
57
28
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`Failed to serialize a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const seed = rng.GetSeed();
|
|
66
|
-
const rngTable = new LuaMap<string, unknown>();
|
|
67
|
-
rngTable.set("seed", seed);
|
|
68
|
-
rngTable.set(SerializationBrand.RNG, "");
|
|
69
|
-
return rngTable as SerializedRNG;
|
|
70
|
-
}
|
|
29
|
+
const seed = rng.GetSeed();
|
|
30
|
+
return newRNG(seed);
|
|
31
|
+
}
|
|
71
32
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
OBJECT_NAME,
|
|
82
|
-
...KEYS,
|
|
83
|
-
);
|
|
84
|
-
const seed = seedNumber as Seed;
|
|
85
|
-
return newRNG(seed);
|
|
86
|
-
}
|
|
33
|
+
/**
|
|
34
|
+
* Helper function to convert a `SerializedRNG` object to a normal `RNG` object. (This is used by
|
|
35
|
+
* the save data manager when reading data from the "save#.dat" file.)
|
|
36
|
+
*/
|
|
37
|
+
export function deserializeRNG(rng: SerializedRNG): RNG {
|
|
38
|
+
if (!isTable(rng)) {
|
|
39
|
+
error(
|
|
40
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object was not a Lua table.`,
|
|
41
|
+
);
|
|
87
42
|
}
|
|
43
|
+
|
|
44
|
+
const [seed] = getNumbersFromTable(
|
|
45
|
+
rng as LuaMap<string, unknown>,
|
|
46
|
+
OBJECT_NAME,
|
|
47
|
+
...KEYS,
|
|
48
|
+
);
|
|
49
|
+
return newRNG(seed as Seed);
|
|
88
50
|
}
|
|
89
51
|
|
|
90
52
|
/**
|
|
@@ -130,6 +92,24 @@ export function rngEquals(rng1: RNG, rng2: RNG): boolean {
|
|
|
130
92
|
return isaacAPIClassEquals(rng1, rng2, KEYS);
|
|
131
93
|
}
|
|
132
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Helper function to convert a `RNG` object to a `SerializedRNG` object. (This is used by the save
|
|
97
|
+
* data manager when writing data from the "save#.dat" file.)
|
|
98
|
+
*/
|
|
99
|
+
export function serializeRNG(rng: RNG): SerializedRNG {
|
|
100
|
+
if (!isRNG(rng)) {
|
|
101
|
+
error(
|
|
102
|
+
`Failed to serialize a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const seed = rng.GetSeed();
|
|
107
|
+
const rngTable = new LuaMap<string, unknown>();
|
|
108
|
+
rngTable.set("seed", seed);
|
|
109
|
+
rngTable.set(SerializationBrand.RNG, "");
|
|
110
|
+
return rngTable as SerializedRNG;
|
|
111
|
+
}
|
|
112
|
+
|
|
133
113
|
/**
|
|
134
114
|
* Helper function to iterate over the provided object and set the seed for all of the values that
|
|
135
115
|
* are RNG objects equal to a particular seed.
|