isaacscript-common 9.0.0 → 9.0.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"postPlayerCollectible.d.ts","sourceRoot":"","sources":["../../src/callbacks/postPlayerCollectible.ts"],"names":[],"mappings":";AAkCA,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAIjE"}
1
+ {"version":3,"file":"postPlayerCollectible.d.ts","sourceRoot":"","sources":["../../src/callbacks/postPlayerCollectible.ts"],"names":[],"mappings":";AA4CA,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAIjE"}
@@ -1,19 +1,27 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local Map = ____lualib.Map
3
3
  local __TS__New = ____lualib.__TS__New
4
+ local Set = ____lualib.Set
4
5
  local __TS__Spread = ____lualib.__TS__Spread
5
6
  local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
6
7
  local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
7
8
  local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
9
+ local __TS__Iterator = ____lualib.__TS__Iterator
8
10
  local __TS__ArraySort = ____lualib.__TS__ArraySort
9
11
  local ____exports = {}
10
- local hasSubscriptions, postPEffectUpdate, collectibleCountChanged, v
12
+ local hasSubscriptions, postPEffectUpdate, collectibleCountChanged, checkActiveItemsChanged, activeItemsChanged, v
11
13
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
14
+ local ActiveSlot = ____isaac_2Dtypescript_2Ddefinitions.ActiveSlot
15
+ local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
12
16
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
13
17
  local ____DefaultMap = require("classes.DefaultMap")
14
18
  local DefaultMap = ____DefaultMap.DefaultMap
15
19
  local ____exports = require("features.saveDataManager.exports")
16
20
  local saveDataManager = ____exports.saveDataManager
21
+ local ____array = require("functions.array")
22
+ local arrayEquals = ____array.arrayEquals
23
+ local ____enums = require("functions.enums")
24
+ local getEnumValues = ____enums.getEnumValues
17
25
  local ____playerDataStructures = require("functions.playerDataStructures")
18
26
  local defaultMapGetPlayer = ____playerDataStructures.defaultMapGetPlayer
19
27
  local mapGetPlayer = ____playerDataStructures.mapGetPlayer
@@ -43,30 +51,37 @@ function postPEffectUpdate(self, player)
43
51
  end
44
52
  local difference = newCollectibleCount - oldCollectibleCount
45
53
  if difference > 0 then
46
- collectibleCountChanged(nil, player, difference, true)
54
+ collectibleCountChanged(nil, player, difference)
47
55
  elseif difference < 0 then
48
- collectibleCountChanged(nil, player, difference * -1, false)
56
+ collectibleCountChanged(nil, player, difference * -1)
57
+ elseif difference == 0 then
58
+ checkActiveItemsChanged(nil, player)
49
59
  end
50
60
  end
51
- function collectibleCountChanged(self, player, numCollectiblesChanged, increased)
61
+ function collectibleCountChanged(self, player, numCollectiblesChanged)
52
62
  local oldCollectibleMap = defaultMapGetPlayer(nil, v.run.playersCollectibleMap, player)
53
63
  local newCollectibleMap = getPlayerCollectibleMap(nil, player)
54
64
  mapSetPlayer(nil, v.run.playersCollectibleMap, player, newCollectibleMap)
65
+ local ____Set_1 = Set
55
66
  local ____array_0 = __TS__SparseArrayNew(__TS__Spread(oldCollectibleMap:keys()))
56
67
  __TS__SparseArrayPush(
57
68
  ____array_0,
58
69
  __TS__Spread(newCollectibleMap:keys())
59
70
  )
60
- local collectibleTypes = {__TS__SparseArraySpread(____array_0)}
61
- __TS__ArraySort(collectibleTypes)
71
+ local collectibleTypeSet = __TS__New(
72
+ ____Set_1,
73
+ {__TS__SparseArraySpread(____array_0)}
74
+ )
62
75
  local numFired = 0
63
- for ____, collectibleType in ipairs(collectibleTypes) do
76
+ for ____, collectibleType in __TS__Iterator(collectibleTypeSet:values()) do
64
77
  local oldNum = oldCollectibleMap:get(collectibleType) or 0
65
78
  local newNum = newCollectibleMap:get(collectibleType) or 0
66
- local difference = math.abs(newNum - oldNum)
79
+ local difference = newNum - oldNum
80
+ local increased = difference > 0
81
+ local absoluteDifference = math.abs(difference)
67
82
  ____repeat(
68
83
  nil,
69
- difference,
84
+ absoluteDifference,
70
85
  function()
71
86
  if increased then
72
87
  postPlayerCollectibleAddedFire(nil, player, collectibleType)
@@ -81,11 +96,65 @@ function collectibleCountChanged(self, player, numCollectiblesChanged, increased
81
96
  end
82
97
  end
83
98
  end
99
+ function checkActiveItemsChanged(self, player)
100
+ local activeItemMap = defaultMapGetPlayer(nil, v.run.playersActiveItemMap, player)
101
+ local oldCollectibleTypes = {}
102
+ local newCollectibleTypes = {}
103
+ for ____, activeSlot in ipairs(getEnumValues(nil, ActiveSlot)) do
104
+ local oldCollectibleType = activeItemMap:get(activeSlot) or CollectibleType.NULL
105
+ local newCollectibleType = player:GetActiveItem(activeSlot)
106
+ activeItemMap:set(activeSlot, newCollectibleType)
107
+ oldCollectibleTypes[#oldCollectibleTypes + 1] = oldCollectibleType
108
+ newCollectibleTypes[#newCollectibleTypes + 1] = newCollectibleType
109
+ end
110
+ __TS__ArraySort(oldCollectibleTypes)
111
+ __TS__ArraySort(newCollectibleTypes)
112
+ if not arrayEquals(nil, oldCollectibleTypes, newCollectibleTypes) then
113
+ local ____Set_3 = Set
114
+ local ____array_2 = __TS__SparseArrayNew(table.unpack(oldCollectibleTypes))
115
+ __TS__SparseArrayPush(
116
+ ____array_2,
117
+ table.unpack(newCollectibleTypes)
118
+ )
119
+ local collectibleTypeSet = __TS__New(
120
+ ____Set_3,
121
+ {__TS__SparseArraySpread(____array_2)}
122
+ )
123
+ activeItemsChanged(nil, player, collectibleTypeSet)
124
+ end
125
+ end
126
+ function activeItemsChanged(self, player, collectibleTypesSet)
127
+ local oldCollectibleMap = defaultMapGetPlayer(nil, v.run.playersCollectibleMap, player)
128
+ local newCollectibleMap = getPlayerCollectibleMap(nil, player)
129
+ mapSetPlayer(nil, v.run.playersCollectibleMap, player, newCollectibleMap)
130
+ for ____, collectibleType in __TS__Iterator(collectibleTypesSet:values()) do
131
+ local oldNum = oldCollectibleMap:get(collectibleType) or 0
132
+ local newNum = newCollectibleMap:get(collectibleType) or 0
133
+ local difference = newNum - oldNum
134
+ local increased = difference > 0
135
+ local absoluteDifference = math.abs(difference)
136
+ ____repeat(
137
+ nil,
138
+ absoluteDifference,
139
+ function()
140
+ if increased then
141
+ postPlayerCollectibleAddedFire(nil, player, collectibleType)
142
+ else
143
+ postPlayerCollectibleRemovedFire(nil, player, collectibleType)
144
+ end
145
+ end
146
+ )
147
+ end
148
+ end
84
149
  v = {run = {
85
150
  playersCollectibleCount = __TS__New(Map),
86
151
  playersCollectibleMap = __TS__New(
87
152
  DefaultMap,
88
153
  function() return __TS__New(Map) end
154
+ ),
155
+ playersActiveItemMap = __TS__New(
156
+ DefaultMap,
157
+ function() return __TS__New(Map) end
89
158
  )
90
159
  }}
91
160
  function ____exports.postPlayerCollectibleCallbacksInit(self, mod)
@@ -1 +1 @@
1
- {"version":3,"file":"playerInventory.d.ts","sourceRoot":"","sources":["../../src/features/playerInventory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAe,MAAM,8BAA8B,CAAC;AAsH5E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,yBAAyB,UAAO,GAC/B,eAAe,EAAE,CAanB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,YAAY,GACnB,eAAe,GAAG,SAAS,CAK7B"}
1
+ {"version":3,"file":"playerInventory.d.ts","sourceRoot":"","sources":["../../src/features/playerInventory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAe,MAAM,8BAA8B,CAAC;AAkH5E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,yBAAyB,UAAO,GAC/B,eAAe,EAAE,CAanB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,YAAY,GACnB,eAAe,GAAG,SAAS,CAK7B"}
@@ -33,16 +33,14 @@ local saveDataManager = ____exports.saveDataManager
33
33
  function newPlayerInventory(self, player)
34
34
  local inventory = {}
35
35
  for ____, collectibleType in ipairs(getCollectibleArray(nil)) do
36
- if player:HasCollectible(collectibleType) then
37
- local numCollectibles = player:GetCollectibleNum(collectibleType, true)
38
- ____repeat(
39
- nil,
40
- numCollectibles,
41
- function()
42
- inventory[#inventory + 1] = collectibleType
43
- end
44
- )
45
- end
36
+ local numCollectibles = player:GetCollectibleNum(collectibleType, true)
37
+ ____repeat(
38
+ nil,
39
+ numCollectibles,
40
+ function()
41
+ inventory[#inventory + 1] = collectibleType
42
+ end
43
+ )
46
44
  end
47
45
  return inventory
48
46
  end
@@ -1 +1 @@
1
- {"version":3,"file":"cards.d.ts","sourceRoot":"","sources":["../../src/functions/cards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAkE5E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAe7D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAetD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,mBAAmB,EAAE,kBAAkB,EAAE,GAC3C,GAAG,CAAC,QAAQ,CAAC,CAqBf;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,kBAAkB,CAQ5E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,UAAU,GAAE,QAAQ,EAAO,GAC1B,QAAQ,CAEV;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,kBA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;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE9D;AAED,wDAAwD;AACxD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAElD;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAEzD;AAED,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAEtD;AAED,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAEvD;AAED,iDAAiD;AACjD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE7D"}
@@ -11,7 +11,7 @@ export declare function collectibleHasCacheFlag(collectibleType: CollectibleType
11
11
  export declare function getCollectiblesForCacheFlag(cacheFlag: CacheFlag): ReadonlySet<CollectibleType>;
12
12
  /**
13
13
  * Returns an array containing every collectible type that the player has that matches the provided
14
- * CacheFlag.
14
+ * `CacheFlag`.
15
15
  *
16
16
  * For example, if the cache flag is `CacheFlag.FLYING`, and the player has one Lord of the Pit and
17
17
  * two Dead Doves, then this function would return:
@@ -24,6 +24,9 @@ export declare function getCollectiblesForCacheFlag(cacheFlag: CacheFlag): Reado
24
24
  * ]
25
25
  * ```
26
26
  *
27
+ * Note that this array will not include collectibles that the player does not really have, like
28
+ * Lilith's Incubus.
29
+ *
27
30
  * This function can only be called if at least one callback has been executed. This is because not
28
31
  * all collectibles will necessarily be present when a mod first loads (due to mod load order).
29
32
  */
@@ -1 +1 @@
1
- {"version":3,"file":"collectibleCacheFlag.d.ts","sourceRoot":"","sources":["../../src/functions/collectibleCacheFlag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AA+B1E,iGAAiG;AACjG,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,SAAS,GACnB,OAAO,CAOT;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,SAAS,GACnB,WAAW,CAAC,eAAe,CAAC,CAS9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,GACnB,eAAe,EAAE,CAYnB"}
1
+ {"version":3,"file":"collectibleCacheFlag.d.ts","sourceRoot":"","sources":["../../src/functions/collectibleCacheFlag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AA+B1E,iGAAiG;AACjG,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,SAAS,GACnB,OAAO,CAOT;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,SAAS,GACnB,WAAW,CAAC,eAAe,CAAC,CAS9B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,GACnB,eAAe,EAAE,CAanB"}
@@ -54,7 +54,7 @@ function ____exports.getCollectiblesForCacheFlag(self, cacheFlag)
54
54
  return collectiblesSet
55
55
  end
56
56
  --- Returns an array containing every collectible type that the player has that matches the provided
57
- -- CacheFlag.
57
+ -- `CacheFlag`.
58
58
  --
59
59
  -- For example, if the cache flag is `CacheFlag.FLYING`, and the player has one Lord of the Pit and
60
60
  -- two Dead Doves, then this function would return:
@@ -67,13 +67,16 @@ end
67
67
  -- ]
68
68
  -- ```
69
69
  --
70
+ -- Note that this array will not include collectibles that the player does not really have, like
71
+ -- Lilith's Incubus.
72
+ --
70
73
  -- This function can only be called if at least one callback has been executed. This is because not
71
74
  -- all collectibles will necessarily be present when a mod first loads (due to mod load order).
72
75
  function ____exports.getPlayerCollectiblesForCacheFlag(self, player, cacheFlag)
73
76
  local collectiblesForCacheFlag = ____exports.getCollectiblesForCacheFlag(nil, cacheFlag)
74
77
  local playerCollectibles = {}
75
78
  for ____, collectibleType in ipairs(getSortedSetValues(nil, collectiblesForCacheFlag)) do
76
- local numCollectibles = player:GetCollectibleNum(collectibleType)
79
+ local numCollectibles = player:GetCollectibleNum(collectibleType, true)
77
80
  ____repeat(
78
81
  nil,
79
82
  numCollectibles,
@@ -1 +1 @@
1
- {"version":3,"file":"familiars.d.ts","sourceRoot":"","sources":["../../src/functions/familiars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAKhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,GAAG,EAChB,eAAe,EAAE,eAAe,EAChC,eAAe,CAAC,EAAE,GAAG,GACpB,IAAI,CASN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,eAAe,EAChC,eAAe,CAAC,EAAE,GAAG,GACpB,IAAI,CAiBN;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,EAAE,CAOzE;AAED,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,cAAc,GACvB,OAAO,CAET"}
1
+ {"version":3,"file":"familiars.d.ts","sourceRoot":"","sources":["../../src/functions/familiars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAKhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,GAAG,EAChB,eAAe,EAAE,eAAe,EAChC,eAAe,CAAC,EAAE,GAAG,GACpB,IAAI,CASN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,eAAe,EAChC,eAAe,CAAC,EAAE,GAAG,GACpB,IAAI,CAkBN;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,EAAE,CAOzE;AAED,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,cAAc,GACvB,OAAO,CAET"}
@@ -71,17 +71,15 @@ function removeItemsAndTrinketsThatAffectItemPools(self)
71
71
  for ____, player in ipairs(getPlayers(nil)) do
72
72
  local removedItems = {}
73
73
  for ____, itemToRemove in ipairs(COLLECTIBLES_THAT_AFFECT_ITEM_POOLS) do
74
- if player:HasCollectible(itemToRemove) then
75
- local numCollectibles = player:GetCollectibleNum(itemToRemove)
76
- ____repeat(
77
- nil,
78
- numCollectibles,
79
- function()
80
- player:RemoveCollectible(itemToRemove)
81
- removedItems[#removedItems + 1] = itemToRemove
82
- end
83
- )
84
- end
74
+ local numCollectibles = player:GetCollectibleNum(itemToRemove)
75
+ ____repeat(
76
+ nil,
77
+ numCollectibles,
78
+ function()
79
+ player:RemoveCollectible(itemToRemove)
80
+ removedItems[#removedItems + 1] = itemToRemove
81
+ end
82
+ )
85
83
  end
86
84
  mapSetPlayer(nil, removedItemsMap, player, removedItems)
87
85
  local removedTrinkets = {}
@@ -62,11 +62,15 @@ export declare function getPlayerCloserThan(position: Vector, distance: float):
62
62
  * collectible type(s) provided.
63
63
  *
64
64
  * This function is variadic, meaning that you can specify N collectible types.
65
+ *
66
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
65
67
  */
66
68
  export declare function getPlayerCollectibleCount(player: EntityPlayer, ...collectibleTypes: CollectibleType[]): int;
67
69
  /**
68
70
  * Iterates over every item in the game and returns a map containing the number of each item that
69
71
  * the player has.
72
+ *
73
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
70
74
  */
71
75
  export declare function getPlayerCollectibleMap(player: EntityPlayer): Map<CollectibleType, int>;
72
76
  /** Helper function to get the player from a tear, laser, bomb, etc. */
@@ -111,6 +115,8 @@ export declare function getPlayersWithTrinket(...trinketTypes: TrinketType[]): E
111
115
  /**
112
116
  * Returns the total number of collectibles amongst all players. For example, if player 1 has 1 Sad
113
117
  * Onion and player 2 has 2 Sad Onions, then this function would return 3.
118
+ *
119
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
114
120
  */
115
121
  export declare function getTotalPlayerCollectibles(collectibleType: CollectibleType): int;
116
122
  /** After touching a white fire, a player will turn into The Lost until they clear a room. */
@@ -1 +1 @@
1
- {"version":3,"file":"players.d.ts","sourceRoot":"","sources":["../../src/functions/players.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,eAAe,EAIf,UAAU,EAEV,WAAW,EACZ,MAAM,8BAA8B,CAAC;AAetC,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,GAC/B,IAAI,CAON;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,WAAW,GACvB,IAAI,CAON;AAED,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAGT;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAGrE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,kBAAkB,EAAE,UAAU,EAAE,GAAG,OAAO,CAIxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CASjE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,e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AI,CAalE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,GAC/B,IAAI,CAON;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAIlE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,WAAW,GACvB,IAAI,CAON;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU,EACtB,MAAM,CAAC,EAAE,GAAG,EACZ,WAAW,UAAQ,GAClB,IAAI,CA6DN;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,aAAa,UAAO,GACnB,IAAI,CAsBN;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,GAC/B,IAAI,CAEN"}
@@ -219,6 +219,8 @@ end
219
219
  -- collectible type(s) provided.
220
220
  --
221
221
  -- This function is variadic, meaning that you can specify N collectible types.
222
+ --
223
+ -- Note that this will filter out non-real collectibles like Lilith's Incubus.
222
224
  function ____exports.getPlayerCollectibleCount(self, player, ...)
223
225
  local collectibleTypes = {...}
224
226
  local numCollectibles = 0
@@ -229,6 +231,8 @@ function ____exports.getPlayerCollectibleCount(self, player, ...)
229
231
  end
230
232
  --- Iterates over every item in the game and returns a map containing the number of each item that
231
233
  -- the player has.
234
+ --
235
+ -- Note that this will filter out non-real collectibles like Lilith's Incubus.
232
236
  function ____exports.getPlayerCollectibleMap(self, player)
233
237
  local collectibleArray = getCollectibleArray(nil)
234
238
  local collectibleMap = __TS__New(Map)
@@ -334,11 +338,13 @@ function ____exports.getPlayersWithTrinket(self, ...)
334
338
  end
335
339
  --- Returns the total number of collectibles amongst all players. For example, if player 1 has 1 Sad
336
340
  -- Onion and player 2 has 2 Sad Onions, then this function would return 3.
341
+ --
342
+ -- Note that this will filter out non-real collectibles like Lilith's Incubus.
337
343
  function ____exports.getTotalPlayerCollectibles(self, collectibleType)
338
344
  local players = getPlayers(nil)
339
345
  local numCollectiblesArray = __TS__ArrayMap(
340
346
  players,
341
- function(____, player) return player:GetCollectibleNum(collectibleType) end
347
+ function(____, player) return player:GetCollectibleNum(collectibleType, true) end
342
348
  )
343
349
  return sumArray(nil, numCollectiblesArray)
344
350
  end
package/dist/index.d.ts CHANGED
@@ -3926,18 +3926,22 @@ export declare function getPlayerCloserThan(position: Vector, distance: float):
3926
3926
  * collectible type(s) provided.
3927
3927
  *
3928
3928
  * This function is variadic, meaning that you can specify N collectible types.
3929
+ *
3930
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
3929
3931
  */
3930
3932
  export declare function getPlayerCollectibleCount(player: EntityPlayer, ...collectibleTypes: CollectibleType[]): int;
3931
3933
 
3932
3934
  /**
3933
3935
  * Iterates over every item in the game and returns a map containing the number of each item that
3934
3936
  * the player has.
3937
+ *
3938
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
3935
3939
  */
3936
3940
  export declare function getPlayerCollectibleMap(player: EntityPlayer): Map<CollectibleType, int>;
3937
3941
 
3938
3942
  /**
3939
3943
  * Returns an array containing every collectible type that the player has that matches the provided
3940
- * CacheFlag.
3944
+ * `CacheFlag`.
3941
3945
  *
3942
3946
  * For example, if the cache flag is `CacheFlag.FLYING`, and the player has one Lord of the Pit and
3943
3947
  * two Dead Doves, then this function would return:
@@ -3950,6 +3954,9 @@ export declare function getPlayerCollectibleMap(player: EntityPlayer): Map<Colle
3950
3954
  * ]
3951
3955
  * ```
3952
3956
  *
3957
+ * Note that this array will not include collectibles that the player does not really have, like
3958
+ * Lilith's Incubus.
3959
+ *
3953
3960
  * This function can only be called if at least one callback has been executed. This is because not
3954
3961
  * all collectibles will necessarily be present when a mod first loads (due to mod load order).
3955
3962
  */
@@ -4983,6 +4990,8 @@ export declare function getTotalCharge(player: EntityPlayer, activeSlot: ActiveS
4983
4990
  /**
4984
4991
  * Returns the total number of collectibles amongst all players. For example, if player 1 has 1 Sad
4985
4992
  * Onion and player 2 has 2 Sad Onions, then this function would return 3.
4993
+ *
4994
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
4986
4995
  */
4987
4996
  export declare function getTotalPlayerCollectibles(collectibleType: CollectibleType): int;
4988
4997
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "9.0.0",
3
+ "version": "9.0.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -2,9 +2,15 @@
2
2
  // - `POST_PLAYER_COLLECTIBLE_ADDED`
3
3
  // - `POST_PLAYER_COLLECTIBLE_REMOVED`
4
4
 
5
- import { CollectibleType, ModCallback } from "isaac-typescript-definitions";
5
+ import {
6
+ ActiveSlot,
7
+ CollectibleType,
8
+ ModCallback,
9
+ } from "isaac-typescript-definitions";
6
10
  import { DefaultMap } from "../classes/DefaultMap";
7
11
  import { saveDataManager } from "../features/saveDataManager/exports";
12
+ import { arrayEquals } from "../functions/array";
13
+ import { getEnumValues } from "../functions/enums";
8
14
  import {
9
15
  defaultMapGetPlayer,
10
16
  mapGetPlayer,
@@ -29,6 +35,10 @@ const v = {
29
35
  PlayerIndex,
30
36
  Map<CollectibleType, int>
31
37
  >(() => new Map()),
38
+ playersActiveItemMap: new DefaultMap<
39
+ PlayerIndex,
40
+ Map<ActiveSlot, CollectibleType>
41
+ >(() => new Map()),
32
42
  },
33
43
  };
34
44
 
@@ -65,16 +75,17 @@ function postPEffectUpdate(player: EntityPlayer) {
65
75
  const difference = newCollectibleCount - oldCollectibleCount;
66
76
 
67
77
  if (difference > 0) {
68
- collectibleCountChanged(player, difference, true);
78
+ collectibleCountChanged(player, difference);
69
79
  } else if (difference < 0) {
70
- collectibleCountChanged(player, difference * -1, false);
80
+ collectibleCountChanged(player, difference * -1);
81
+ } else if (difference === 0) {
82
+ checkActiveItemsChanged(player);
71
83
  }
72
84
  }
73
85
 
74
86
  function collectibleCountChanged(
75
87
  player: EntityPlayer,
76
88
  numCollectiblesChanged: int,
77
- increased: boolean,
78
89
  ) {
79
90
  const oldCollectibleMap = defaultMapGetPlayer(
80
91
  v.run.playersCollectibleMap,
@@ -83,19 +94,20 @@ function collectibleCountChanged(
83
94
  const newCollectibleMap = getPlayerCollectibleMap(player);
84
95
  mapSetPlayer(v.run.playersCollectibleMap, player, newCollectibleMap);
85
96
 
86
- const collectibleTypes = [
97
+ const collectibleTypeSet = new Set<CollectibleType>([
87
98
  ...oldCollectibleMap.keys(),
88
99
  ...newCollectibleMap.keys(),
89
- ];
90
- collectibleTypes.sort();
100
+ ]);
91
101
 
92
102
  let numFired = 0;
93
- for (const collectibleType of collectibleTypes) {
103
+ for (const collectibleType of collectibleTypeSet.values()) {
94
104
  const oldNum = oldCollectibleMap.get(collectibleType) ?? 0;
95
105
  const newNum = newCollectibleMap.get(collectibleType) ?? 0;
96
- const difference = Math.abs(newNum - oldNum);
106
+ const difference = newNum - oldNum;
107
+ const increased = difference > 0;
108
+ const absoluteDifference = Math.abs(difference);
97
109
 
98
- repeat(difference, () => {
110
+ repeat(absoluteDifference, () => {
99
111
  if (increased) {
100
112
  postPlayerCollectibleAddedFire(player, collectibleType);
101
113
  } else {
@@ -109,3 +121,70 @@ function collectibleCountChanged(
109
121
  }
110
122
  }
111
123
  }
124
+
125
+ /**
126
+ * The special case is when a player swaps their active item for another active item. In this
127
+ * situation, their overall collectible count will not change. Thus, we explicitly check for this.
128
+ */
129
+ function checkActiveItemsChanged(player: EntityPlayer) {
130
+ const activeItemMap = defaultMapGetPlayer(v.run.playersActiveItemMap, player);
131
+
132
+ const oldCollectibleTypes: CollectibleType[] = [];
133
+ const newCollectibleTypes: CollectibleType[] = [];
134
+
135
+ for (const activeSlot of getEnumValues(ActiveSlot)) {
136
+ const oldCollectibleType =
137
+ activeItemMap.get(activeSlot) ?? CollectibleType.NULL;
138
+ const newCollectibleType = player.GetActiveItem(activeSlot);
139
+ activeItemMap.set(activeSlot, newCollectibleType);
140
+
141
+ oldCollectibleTypes.push(oldCollectibleType);
142
+ newCollectibleTypes.push(newCollectibleType);
143
+ }
144
+
145
+ // For example, it is possible for the player to switch Schoolbag items, which will cause the
146
+ // collectibles in the array to be the same, but in a different order. Thus, sort both arrays
147
+ // before comparing them.
148
+ oldCollectibleTypes.sort();
149
+ newCollectibleTypes.sort();
150
+
151
+ if (!arrayEquals(oldCollectibleTypes, newCollectibleTypes)) {
152
+ const collectibleTypeSet = new Set<CollectibleType>([
153
+ ...oldCollectibleTypes,
154
+ ...newCollectibleTypes,
155
+ ]);
156
+ activeItemsChanged(player, collectibleTypeSet);
157
+ }
158
+ }
159
+
160
+ /**
161
+ * One or more active items have changed (with the player's total collectible count remaining the
162
+ * same).
163
+ */
164
+ function activeItemsChanged(
165
+ player: EntityPlayer,
166
+ collectibleTypesSet: Set<CollectibleType>,
167
+ ) {
168
+ const oldCollectibleMap = defaultMapGetPlayer(
169
+ v.run.playersCollectibleMap,
170
+ player,
171
+ );
172
+ const newCollectibleMap = getPlayerCollectibleMap(player);
173
+ mapSetPlayer(v.run.playersCollectibleMap, player, newCollectibleMap);
174
+
175
+ for (const collectibleType of collectibleTypesSet.values()) {
176
+ const oldNum = oldCollectibleMap.get(collectibleType) ?? 0;
177
+ const newNum = newCollectibleMap.get(collectibleType) ?? 0;
178
+ const difference = newNum - oldNum;
179
+ const increased = difference > 0;
180
+ const absoluteDifference = Math.abs(difference);
181
+
182
+ repeat(absoluteDifference, () => {
183
+ if (increased) {
184
+ postPlayerCollectibleAddedFire(player, collectibleType);
185
+ } else {
186
+ postPlayerCollectibleRemovedFire(player, collectibleType);
187
+ }
188
+ });
189
+ }
190
+ }
@@ -35,16 +35,12 @@ function newPlayerInventory(player: EntityPlayer) {
35
35
  const inventory: CollectibleType[] = [];
36
36
 
37
37
  for (const collectibleType of getCollectibleArray()) {
38
- // We have to use the `EntityPlayer.HasCollectible` method in addition to the
39
- // `EntityPlayer.GetCollectibleNum` method in order to mitigate situations like Lilith's Incubus
40
- // counting as a collectible. (The former method will return false for her innate Incubus, but
41
- // the latter method will return 1.)
42
- if (player.HasCollectible(collectibleType)) {
43
- const numCollectibles = player.GetCollectibleNum(collectibleType, true);
44
- repeat(numCollectibles, () => {
45
- inventory.push(collectibleType);
46
- });
47
- }
38
+ // We need to specify "true" as the second argument here to filter out things like Lilith's
39
+ // Incubus.
40
+ const numCollectibles = player.GetCollectibleNum(collectibleType, true);
41
+ repeat(numCollectibles, () => {
42
+ inventory.push(collectibleType);
43
+ });
48
44
  }
49
45
 
50
46
  return inventory;
@@ -73,7 +73,8 @@ export function getCardDescription(cardType: CardType): string {
73
73
  // "ItemConfigCard.Description" is bugged with vanilla cards on patch v1.7.6, so we use a
74
74
  // hard-coded map as a workaround.
75
75
  const cardDescription = CARD_DESCRIPTIONS[cardType];
76
-
76
+ // Handle modded cards.
77
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
77
78
  if (cardDescription !== undefined) {
78
79
  return cardDescription;
79
80
  }
@@ -95,7 +96,8 @@ export function getCardName(cardType: CardType): string {
95
96
  // "ItemConfigCard.Name" is bugged with vanilla cards on patch v1.7.6, so we use a hard-coded map
96
97
  // as a workaround.
97
98
  const cardName = CARD_NAMES[cardType];
98
-
99
+ // Handle modded cards.
100
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
99
101
  if (cardName !== undefined) {
100
102
  return cardName;
101
103
  }
@@ -64,7 +64,7 @@ export function getCollectiblesForCacheFlag(
64
64
 
65
65
  /**
66
66
  * Returns an array containing every collectible type that the player has that matches the provided
67
- * CacheFlag.
67
+ * `CacheFlag`.
68
68
  *
69
69
  * For example, if the cache flag is `CacheFlag.FLYING`, and the player has one Lord of the Pit and
70
70
  * two Dead Doves, then this function would return:
@@ -77,6 +77,9 @@ export function getCollectiblesForCacheFlag(
77
77
  * ]
78
78
  * ```
79
79
  *
80
+ * Note that this array will not include collectibles that the player does not really have, like
81
+ * Lilith's Incubus.
82
+ *
80
83
  * This function can only be called if at least one callback has been executed. This is because not
81
84
  * all collectibles will necessarily be present when a mod first loads (due to mod load order).
82
85
  */
@@ -88,7 +91,8 @@ export function getPlayerCollectiblesForCacheFlag(
88
91
 
89
92
  const playerCollectibles: CollectibleType[] = [];
90
93
  for (const collectibleType of getSortedSetValues(collectiblesForCacheFlag)) {
91
- const numCollectibles = player.GetCollectibleNum(collectibleType);
94
+ // We specify "true" as the second argument to filter out things like Lilith's Incubus.
95
+ const numCollectibles = player.GetCollectibleNum(collectibleType, true);
92
96
  repeat(numCollectibles, () => {
93
97
  playerCollectibles.push(collectibleType);
94
98
  });
@@ -82,6 +82,7 @@ export function checkFamiliarFromCollectibles(
82
82
  familiarVariant: FamiliarVariant,
83
83
  familiarSubType?: int,
84
84
  ): void {
85
+ // We need to include non-real collectibles, like Lilith's Incubus.
85
86
  const numCollectibles = player.GetCollectibleNum(collectibleType);
86
87
  const effects = player.GetEffects();
87
88
 
@@ -128,13 +128,12 @@ function removeItemsAndTrinketsThatAffectItemPools(): [
128
128
  for (const player of getPlayers()) {
129
129
  const removedItems: CollectibleType[] = [];
130
130
  for (const itemToRemove of COLLECTIBLES_THAT_AFFECT_ITEM_POOLS) {
131
- if (player.HasCollectible(itemToRemove)) {
132
- const numCollectibles = player.GetCollectibleNum(itemToRemove);
133
- repeat(numCollectibles, () => {
134
- player.RemoveCollectible(itemToRemove);
135
- removedItems.push(itemToRemove);
136
- });
137
- }
131
+ // We need to include non-real collectibles, like Lilith's Incubus.
132
+ const numCollectibles = player.GetCollectibleNum(itemToRemove);
133
+ repeat(numCollectibles, () => {
134
+ player.RemoveCollectible(itemToRemove);
135
+ removedItems.push(itemToRemove);
136
+ });
138
137
  }
139
138
 
140
139
  mapSetPlayer(removedItemsMap, player, removedItems);
@@ -223,6 +223,8 @@ export function getPlayerCloserThan(
223
223
  * collectible type(s) provided.
224
224
  *
225
225
  * This function is variadic, meaning that you can specify N collectible types.
226
+ *
227
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
226
228
  */
227
229
  export function getPlayerCollectibleCount(
228
230
  player: EntityPlayer,
@@ -230,6 +232,8 @@ export function getPlayerCollectibleCount(
230
232
  ): int {
231
233
  let numCollectibles = 0;
232
234
  for (const collectibleType of collectibleTypes) {
235
+ // We need to specify "true" as the second argument here to filter out things like Lilith's
236
+ // Incubus.
233
237
  numCollectibles += player.GetCollectibleNum(collectibleType, true);
234
238
  }
235
239
 
@@ -239,6 +243,8 @@ export function getPlayerCollectibleCount(
239
243
  /**
240
244
  * Iterates over every item in the game and returns a map containing the number of each item that
241
245
  * the player has.
246
+ *
247
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
242
248
  */
243
249
  export function getPlayerCollectibleMap(
244
250
  player: EntityPlayer,
@@ -247,6 +253,8 @@ export function getPlayerCollectibleMap(
247
253
 
248
254
  const collectibleMap = new Map<CollectibleType, int>();
249
255
  for (const collectibleType of collectibleArray) {
256
+ // We need to specify "true" as the second argument here to filter out things like Lilith's
257
+ // Incubus.
250
258
  const collectibleNum = player.GetCollectibleNum(collectibleType, true);
251
259
  if (collectibleNum > 0) {
252
260
  collectibleMap.set(collectibleType, collectibleNum);
@@ -374,14 +382,19 @@ export function getPlayersWithTrinket(
374
382
  /**
375
383
  * Returns the total number of collectibles amongst all players. For example, if player 1 has 1 Sad
376
384
  * Onion and player 2 has 2 Sad Onions, then this function would return 3.
385
+ *
386
+ * Note that this will filter out non-real collectibles like Lilith's Incubus.
377
387
  */
378
388
  export function getTotalPlayerCollectibles(
379
389
  collectibleType: CollectibleType,
380
390
  ): int {
381
391
  const players = getPlayers();
382
392
  const numCollectiblesArray = players.map((player) =>
383
- player.GetCollectibleNum(collectibleType),
393
+ // We need to specify "true" as the second argument here to filter out things like Lilith's
394
+ // Incubus.
395
+ player.GetCollectibleNum(collectibleType, true),
384
396
  );
397
+
385
398
  return sumArray(numCollectiblesArray);
386
399
  }
387
400