isaacscript-common 11.2.3 → 11.2.4

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/index.d.ts CHANGED
@@ -2627,6 +2627,16 @@ export declare function getCharacterName(character: PlayerType): string;
2627
2627
  /** Helper function to get an array containing the characters of all of the current players. */
2628
2628
  export declare function getCharacters(): PlayerType[];
2629
2629
 
2630
+ /**
2631
+ * Helper function to get the amount of charges away from the maximum charge that a particular
2632
+ * player is.
2633
+ *
2634
+ * This function accounts for The Battery. For example, if the player has 2/6 charges on a D6, this
2635
+ * function will return 10 (because there are 4 charges remaining on the base charge and 6 charges
2636
+ * remaining on The Battery charge).
2637
+ */
2638
+ export declare function getChargesAwayFromMax(player: EntityPlayer, activeSlot: ActiveSlot): int;
2639
+
2630
2640
  /**
2631
2641
  * Helper function to get an array of equidistant points on the circumference around a circle.
2632
2642
  * Useful for equally distributing things in a circle pattern.
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 11.2.3
3
+ isaacscript-common 11.2.4
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -27608,7 +27608,7 @@ return ____exports
27608
27608
  end,
27609
27609
  ["src.functions.charge"] = function(...)
27610
27610
  local ____exports = {}
27611
- local getClampedChargesToAdd, getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
27611
+ local getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
27612
27612
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
27613
27613
  local ActiveSlot = ____isaac_2Dtypescript_2Ddefinitions.ActiveSlot
27614
27614
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
@@ -27650,7 +27650,8 @@ function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEf
27650
27650
  playSoundEffect = true
27651
27651
  end
27652
27652
  local hud = game:GetHUD()
27653
- local chargesToAdd = getClampedChargesToAdd(nil, player, activeSlot, numCharges)
27653
+ local chargesAwayFromMax = ____exports.getChargesAwayFromMax(nil, player, activeSlot)
27654
+ local chargesToAdd = numCharges > chargesAwayFromMax and chargesAwayFromMax or numCharges
27654
27655
  local modifiedChargesToAdd = getChargesToAddWithAAAModifier(nil, player, activeSlot, chargesToAdd)
27655
27656
  local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
27656
27657
  local newCharge = totalCharge + modifiedChargesToAdd
@@ -27697,6 +27698,9 @@ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomD
27697
27698
  local room = game:GetRoom()
27698
27699
  local roomShape = room:GetRoomShape()
27699
27700
  local numCharges = bigRoomDoubleCharge and getRoomShapeCharges(nil, roomShape) or 1
27701
+ if chargeType == ItemConfigChargeType.TIMED then
27702
+ numCharges = getCollectibleMaxCharges(nil, activeItem)
27703
+ end
27700
27704
  ____exports.addCharge(
27701
27705
  nil,
27702
27706
  player,
@@ -27705,43 +27709,28 @@ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomD
27705
27709
  playSoundEffect
27706
27710
  )
27707
27711
  end
27708
- function getClampedChargesToAdd(self, player, activeSlot, numCharges)
27709
- local activeItem = player:GetActiveItem(activeSlot)
27710
- local activeCharge = player:GetActiveCharge(activeSlot)
27711
- local batteryCharge = player:GetBatteryCharge(activeSlot)
27712
- local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
27713
- local maxCharges = getCollectibleMaxCharges(nil, activeItem)
27714
- if not hasBattery and activeCharge == maxCharges then
27715
- return 0
27716
- end
27717
- if hasBattery and batteryCharge == maxCharges then
27718
- return 0
27719
- end
27720
- if not hasBattery and activeCharge + 1 == maxCharges then
27721
- return 1
27722
- end
27723
- if hasBattery and batteryCharge + 1 == maxCharges then
27724
- return 1
27725
- end
27726
- return numCharges
27727
- end
27728
27712
  function getChargesToAddWithAAAModifier(self, player, activeSlot, chargesToAdd)
27729
- local activeItem = player:GetActiveItem(activeSlot)
27730
- local activeCharge = player:GetActiveCharge(activeSlot)
27731
- local batteryCharge = player:GetBatteryCharge(activeSlot)
27732
- local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
27733
27713
  local hasAAABattery = player:HasTrinket(TrinketType.AAA_BATTERY)
27734
- local maxCharges = getCollectibleMaxCharges(nil, activeItem)
27735
27714
  if not hasAAABattery then
27736
27715
  return chargesToAdd
27737
27716
  end
27738
- if not hasBattery and activeCharge + chargesToAdd == maxCharges - 1 then
27739
- return chargesToAdd + 1
27740
- end
27741
- if hasBattery and batteryCharge + chargesToAdd == maxCharges - 1 then
27742
- return chargesToAdd + 1
27743
- end
27744
- return chargesToAdd
27717
+ local chargesAwayFromMax = ____exports.getChargesAwayFromMax(nil, player, activeSlot)
27718
+ local AAABatteryShouldApply = chargesToAdd == chargesAwayFromMax - 1
27719
+ return AAABatteryShouldApply and chargesToAdd + 1 or chargesToAdd
27720
+ end
27721
+ --- Helper function to get the amount of charges away from the maximum charge that a particular
27722
+ -- player is.
27723
+ --
27724
+ -- This function accounts for The Battery. For example, if the player has 2/6 charges on a D6, this
27725
+ -- function will return 10 (because there are 4 charges remaining on the base charge and 6 charges
27726
+ -- remaining on The Battery charge).
27727
+ function ____exports.getChargesAwayFromMax(self, player, activeSlot)
27728
+ local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
27729
+ local activeItem = player:GetActiveItem(activeSlot)
27730
+ local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
27731
+ local maxCharges = getCollectibleMaxCharges(nil, activeItem)
27732
+ local effectiveMaxCharges = hasBattery and maxCharges * 2 or maxCharges
27733
+ return effectiveMaxCharges - totalCharge
27745
27734
  end
27746
27735
  --- Helper function to get the combined normal charge and the battery charge for the player's active
27747
27736
  -- item. This is useful because you have to add these two values together when setting the active
@@ -46970,7 +46959,7 @@ return ____exports
46970
46959
  ["package"] = function(...)
46971
46960
  return {
46972
46961
  name = "isaacscript-common",
46973
- version = "11.2.3",
46962
+ version = "11.2.4",
46974
46963
  description = "Helper functions and features for IsaacScript mods.",
46975
46964
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
46976
46965
  homepage = "https://isaacscript.github.io/",
package/dist/package.lua CHANGED
@@ -1,6 +1,6 @@
1
1
  return {
2
2
  name = "isaacscript-common",
3
- version = "11.2.3",
3
+ version = "11.2.4",
4
4
  description = "Helper functions and features for IsaacScript mods.",
5
5
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
6
6
  homepage = "https://isaacscript.github.io/",
@@ -68,6 +68,15 @@ export declare function addRoomClearChargeToSlot(player: EntityPlayer, activeSlo
68
68
  * is true.
69
69
  */
70
70
  export declare function addRoomClearCharges(bigRoomDoubleCharge?: boolean): void;
71
+ /**
72
+ * Helper function to get the amount of charges away from the maximum charge that a particular
73
+ * player is.
74
+ *
75
+ * This function accounts for The Battery. For example, if the player has 2/6 charges on a D6, this
76
+ * function will return 10 (because there are 4 charges remaining on the base charge and 6 charges
77
+ * remaining on The Battery charge).
78
+ */
79
+ export declare function getChargesAwayFromMax(player: EntityPlayer, activeSlot: ActiveSlot): int;
71
80
  /**
72
81
  * Helper function to get the combined normal charge and the battery charge for the player's active
73
82
  * item. This is useful because you have to add these two values together when setting the active
@@ -1 +1 @@
1
- {"version":3,"file":"charge.d.ts","sourceRoot":"","sources":["../../../src/functions/charge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAKX,MAAM,8BAA8B,CAAC;AAStC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,EACtB,UAAU,SAAI,EACd,eAAe,UAAO,GACrB,GAAG,CA2BL;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CAaN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,EACtB,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CAkBN;AAuED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,mBAAmB,UAAO,GAAG,IAAI,CAIpE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,GAAG,CAKL;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,OAAO,CAMT;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,IAAI,CAYN"}
1
+ {"version":3,"file":"charge.d.ts","sourceRoot":"","sources":["../../../src/functions/charge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAKX,MAAM,8BAA8B,CAAC;AAStC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,EACtB,UAAU,SAAI,EACd,eAAe,UAAO,GACrB,GAAG,CA+BL;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CAaN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,EACtB,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CA4BN;AAqBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,mBAAmB,UAAO,GAAG,IAAI,CAIpE;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,GAAG,CAQL;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,GAAG,CAKL;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,OAAO,CAMT;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,IAAI,CAYN"}
@@ -1,5 +1,5 @@
1
1
  local ____exports = {}
2
- local getClampedChargesToAdd, getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
2
+ local getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
3
3
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
4
4
  local ActiveSlot = ____isaac_2Dtypescript_2Ddefinitions.ActiveSlot
5
5
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
@@ -41,7 +41,8 @@ function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEf
41
41
  playSoundEffect = true
42
42
  end
43
43
  local hud = game:GetHUD()
44
- local chargesToAdd = getClampedChargesToAdd(nil, player, activeSlot, numCharges)
44
+ local chargesAwayFromMax = ____exports.getChargesAwayFromMax(nil, player, activeSlot)
45
+ local chargesToAdd = numCharges > chargesAwayFromMax and chargesAwayFromMax or numCharges
45
46
  local modifiedChargesToAdd = getChargesToAddWithAAAModifier(nil, player, activeSlot, chargesToAdd)
46
47
  local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
47
48
  local newCharge = totalCharge + modifiedChargesToAdd
@@ -88,6 +89,9 @@ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomD
88
89
  local room = game:GetRoom()
89
90
  local roomShape = room:GetRoomShape()
90
91
  local numCharges = bigRoomDoubleCharge and getRoomShapeCharges(nil, roomShape) or 1
92
+ if chargeType == ItemConfigChargeType.TIMED then
93
+ numCharges = getCollectibleMaxCharges(nil, activeItem)
94
+ end
91
95
  ____exports.addCharge(
92
96
  nil,
93
97
  player,
@@ -96,43 +100,28 @@ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomD
96
100
  playSoundEffect
97
101
  )
98
102
  end
99
- function getClampedChargesToAdd(self, player, activeSlot, numCharges)
100
- local activeItem = player:GetActiveItem(activeSlot)
101
- local activeCharge = player:GetActiveCharge(activeSlot)
102
- local batteryCharge = player:GetBatteryCharge(activeSlot)
103
- local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
104
- local maxCharges = getCollectibleMaxCharges(nil, activeItem)
105
- if not hasBattery and activeCharge == maxCharges then
106
- return 0
107
- end
108
- if hasBattery and batteryCharge == maxCharges then
109
- return 0
110
- end
111
- if not hasBattery and activeCharge + 1 == maxCharges then
112
- return 1
113
- end
114
- if hasBattery and batteryCharge + 1 == maxCharges then
115
- return 1
116
- end
117
- return numCharges
118
- end
119
103
  function getChargesToAddWithAAAModifier(self, player, activeSlot, chargesToAdd)
120
- local activeItem = player:GetActiveItem(activeSlot)
121
- local activeCharge = player:GetActiveCharge(activeSlot)
122
- local batteryCharge = player:GetBatteryCharge(activeSlot)
123
- local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
124
104
  local hasAAABattery = player:HasTrinket(TrinketType.AAA_BATTERY)
125
- local maxCharges = getCollectibleMaxCharges(nil, activeItem)
126
105
  if not hasAAABattery then
127
106
  return chargesToAdd
128
107
  end
129
- if not hasBattery and activeCharge + chargesToAdd == maxCharges - 1 then
130
- return chargesToAdd + 1
131
- end
132
- if hasBattery and batteryCharge + chargesToAdd == maxCharges - 1 then
133
- return chargesToAdd + 1
134
- end
135
- return chargesToAdd
108
+ local chargesAwayFromMax = ____exports.getChargesAwayFromMax(nil, player, activeSlot)
109
+ local AAABatteryShouldApply = chargesToAdd == chargesAwayFromMax - 1
110
+ return AAABatteryShouldApply and chargesToAdd + 1 or chargesToAdd
111
+ end
112
+ --- Helper function to get the amount of charges away from the maximum charge that a particular
113
+ -- player is.
114
+ --
115
+ -- This function accounts for The Battery. For example, if the player has 2/6 charges on a D6, this
116
+ -- function will return 10 (because there are 4 charges remaining on the base charge and 6 charges
117
+ -- remaining on The Battery charge).
118
+ function ____exports.getChargesAwayFromMax(self, player, activeSlot)
119
+ local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
120
+ local activeItem = player:GetActiveItem(activeSlot)
121
+ local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
122
+ local maxCharges = getCollectibleMaxCharges(nil, activeItem)
123
+ local effectiveMaxCharges = hasBattery and maxCharges * 2 or maxCharges
124
+ return effectiveMaxCharges - totalCharge
136
125
  end
137
126
  --- Helper function to get the combined normal charge and the battery charge for the player's active
138
127
  -- item. This is useful because you have to add these two values together when setting the active
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "11.2.3",
3
+ "version": "11.2.4",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -40,8 +40,12 @@ export function addCharge(
40
40
  ): int {
41
41
  const hud = game.GetHUD();
42
42
 
43
- // Ensure that there is enough space on the active item to store these amount of charges.
44
- const chargesToAdd = getClampedChargesToAdd(player, activeSlot, numCharges);
43
+ // Ensure that there is enough space on the active item to store these amount of charges. (If we
44
+ // add too many charges, it will grant orange "battery" charges, even if the player does not have
45
+ // The Battery.)
46
+ const chargesAwayFromMax = getChargesAwayFromMax(player, activeSlot);
47
+ const chargesToAdd =
48
+ numCharges > chargesAwayFromMax ? chargesAwayFromMax : numCharges;
45
49
 
46
50
  // The AAA Battery trinket might grant an additional charge.
47
51
  const modifiedChargesToAdd = getChargesToAddWithAAAModifier(
@@ -139,46 +143,18 @@ export function addRoomClearChargeToSlot(
139
143
  const room = game.GetRoom();
140
144
  const roomShape = room.GetRoomShape();
141
145
 
142
- const numCharges = bigRoomDoubleCharge ? getRoomShapeCharges(roomShape) : 1;
143
- addCharge(player, activeSlot, numCharges, playSoundEffect);
144
- }
146
+ // Big rooms grant two charges and normal rooms grant one charge.
147
+ let numCharges = bigRoomDoubleCharge ? getRoomShapeCharges(roomShape) : 1;
145
148
 
146
- /**
147
- * We don't want to add more charges than is normally possible, so we must check to see if the
148
- * player can hold the specified amount of charges in the given slot.
149
- */
150
- function getClampedChargesToAdd(
151
- player: EntityPlayer,
152
- activeSlot: ActiveSlot,
153
- numCharges: int,
154
- ) {
155
- const activeItem = player.GetActiveItem(activeSlot);
156
- const activeCharge = player.GetActiveCharge(activeSlot);
157
- const batteryCharge = player.GetBatteryCharge(activeSlot);
158
- const hasBattery = player.HasCollectible(CollectibleType.BATTERY);
159
- const maxCharges = getCollectibleMaxCharges(activeItem);
160
-
161
- if (!hasBattery && activeCharge === maxCharges) {
162
- return 0;
163
- }
164
-
165
- if (hasBattery && batteryCharge === maxCharges) {
166
- return 0;
149
+ // Handle the special case of a timed item. When clearing a room with a timed item, it should
150
+ // become fully charged.
151
+ if (chargeType === ItemConfigChargeType.TIMED) {
152
+ // The charges will become clamped to the proper amount in the `addCharge` function. (If the
153
+ // item is at 50% charge and the player has The Battery, it should go to 150% charged.)
154
+ numCharges = getCollectibleMaxCharges(activeItem);
167
155
  }
168
156
 
169
- if (!hasBattery && activeCharge + 1 === maxCharges) {
170
- // We are only 1 charge away from a full charge, so only add one charge to avoid an overcharge.
171
- // (It is possible to set orange charges without the player actually having The Battery.)
172
- return 1;
173
- }
174
-
175
- if (hasBattery && batteryCharge + 1 === maxCharges) {
176
- // We are only 1 charge away from a full double-charge, so only add one charge to avoid an
177
- // overcharge.
178
- return 1;
179
- }
180
-
181
- return numCharges;
157
+ addCharge(player, activeSlot, numCharges, playSoundEffect);
182
158
  }
183
159
 
184
160
  /**
@@ -190,26 +166,14 @@ function getChargesToAddWithAAAModifier(
190
166
  activeSlot: ActiveSlot,
191
167
  chargesToAdd: int,
192
168
  ) {
193
- const activeItem = player.GetActiveItem(activeSlot);
194
- const activeCharge = player.GetActiveCharge(activeSlot);
195
- const batteryCharge = player.GetBatteryCharge(activeSlot);
196
- const hasBattery = player.HasCollectible(CollectibleType.BATTERY);
197
169
  const hasAAABattery = player.HasTrinket(TrinketType.AAA_BATTERY);
198
- const maxCharges = getCollectibleMaxCharges(activeItem);
199
-
200
170
  if (!hasAAABattery) {
201
171
  return chargesToAdd;
202
172
  }
203
173
 
204
- if (!hasBattery && activeCharge + chargesToAdd === maxCharges - 1) {
205
- return chargesToAdd + 1;
206
- }
207
-
208
- if (hasBattery && batteryCharge + chargesToAdd === maxCharges - 1) {
209
- return chargesToAdd + 1;
210
- }
211
-
212
- return chargesToAdd;
174
+ const chargesAwayFromMax = getChargesAwayFromMax(player, activeSlot);
175
+ const AAABatteryShouldApply = chargesToAdd === chargesAwayFromMax - 1;
176
+ return AAABatteryShouldApply ? chargesToAdd + 1 : chargesToAdd;
213
177
  }
214
178
 
215
179
  /**
@@ -231,6 +195,27 @@ export function addRoomClearCharges(bigRoomDoubleCharge = true): void {
231
195
  }
232
196
  }
233
197
 
198
+ /**
199
+ * Helper function to get the amount of charges away from the maximum charge that a particular
200
+ * player is.
201
+ *
202
+ * This function accounts for The Battery. For example, if the player has 2/6 charges on a D6, this
203
+ * function will return 10 (because there are 4 charges remaining on the base charge and 6 charges
204
+ * remaining on The Battery charge).
205
+ */
206
+ export function getChargesAwayFromMax(
207
+ player: EntityPlayer,
208
+ activeSlot: ActiveSlot,
209
+ ): int {
210
+ const totalCharge = getTotalCharge(player, activeSlot);
211
+ const activeItem = player.GetActiveItem(activeSlot);
212
+ const hasBattery = player.HasCollectible(CollectibleType.BATTERY);
213
+ const maxCharges = getCollectibleMaxCharges(activeItem);
214
+ const effectiveMaxCharges = hasBattery ? maxCharges * 2 : maxCharges;
215
+
216
+ return effectiveMaxCharges - totalCharge;
217
+ }
218
+
234
219
  /**
235
220
  * Helper function to get the combined normal charge and the battery charge for the player's active
236
221
  * item. This is useful because you have to add these two values together when setting the active