isaacscript-common 11.2.2 → 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.2
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
 
@@ -4861,7 +4861,7 @@ return ____exports
4861
4861
  ["lua_modules.isaac-typescript-definitions.dist.package"] = function(...)
4862
4862
  return {
4863
4863
  name = "isaac-typescript-definitions",
4864
- version = "7.2.3",
4864
+ version = "7.2.4",
4865
4865
  description = "TypeScript definitions for The Binding of Isaac: Repentance.",
4866
4866
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
4867
4867
  homepage = "https://isaacscript.github.io/",
@@ -8785,9 +8785,10 @@ ____exports.PlayerVariant[____exports.PlayerVariant.COOP_BABY] = "COOP_BABY"
8785
8785
  -- explode. `TearVariant.NEEDLE` makes the tear look like a needle, and the exploding effect comes
8786
8786
  -- from `TearFlag.NEEDLE`.
8787
8787
  --
8788
- -- However, there are some exceptions. For example, Sharp Key makes Isaac shoot key tears that deal
8789
- -- extra damage. Both the graphical effect and the extra damage are granted by
8790
- -- `TearVariant.KEY_BLOOD`.
8788
+ -- However, there are some exceptions:
8789
+ -- - `TearVariant.CHAOS_CARD` (9) - The variant grants the instant-kill property of the tear.
8790
+ -- - `TearVariant.KEY_BLOOD` (44) - Sharp Key makes Isaac shoot key tears that deal extra damage.
8791
+ -- Both the graphical effect and the extra damage are granted by this variant.
8791
8792
  ____exports.TearVariant = {}
8792
8793
  ____exports.TearVariant.BLUE = 0
8793
8794
  ____exports.TearVariant[____exports.TearVariant.BLUE] = "BLUE"
@@ -27607,7 +27608,7 @@ return ____exports
27607
27608
  end,
27608
27609
  ["src.functions.charge"] = function(...)
27609
27610
  local ____exports = {}
27610
- local getClampedChargesToAdd, getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
27611
+ local getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
27611
27612
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
27612
27613
  local ActiveSlot = ____isaac_2Dtypescript_2Ddefinitions.ActiveSlot
27613
27614
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
@@ -27649,7 +27650,8 @@ function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEf
27649
27650
  playSoundEffect = true
27650
27651
  end
27651
27652
  local hud = game:GetHUD()
27652
- local chargesToAdd = getClampedChargesToAdd(nil, player, activeSlot, numCharges)
27653
+ local chargesAwayFromMax = ____exports.getChargesAwayFromMax(nil, player, activeSlot)
27654
+ local chargesToAdd = numCharges > chargesAwayFromMax and chargesAwayFromMax or numCharges
27653
27655
  local modifiedChargesToAdd = getChargesToAddWithAAAModifier(nil, player, activeSlot, chargesToAdd)
27654
27656
  local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
27655
27657
  local newCharge = totalCharge + modifiedChargesToAdd
@@ -27696,6 +27698,9 @@ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomD
27696
27698
  local room = game:GetRoom()
27697
27699
  local roomShape = room:GetRoomShape()
27698
27700
  local numCharges = bigRoomDoubleCharge and getRoomShapeCharges(nil, roomShape) or 1
27701
+ if chargeType == ItemConfigChargeType.TIMED then
27702
+ numCharges = getCollectibleMaxCharges(nil, activeItem)
27703
+ end
27699
27704
  ____exports.addCharge(
27700
27705
  nil,
27701
27706
  player,
@@ -27704,43 +27709,28 @@ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomD
27704
27709
  playSoundEffect
27705
27710
  )
27706
27711
  end
27707
- function getClampedChargesToAdd(self, player, activeSlot, numCharges)
27708
- local activeItem = player:GetActiveItem(activeSlot)
27709
- local activeCharge = player:GetActiveCharge(activeSlot)
27710
- local batteryCharge = player:GetBatteryCharge(activeSlot)
27711
- local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
27712
- local maxCharges = getCollectibleMaxCharges(nil, activeItem)
27713
- if not hasBattery and activeCharge == maxCharges then
27714
- return 0
27715
- end
27716
- if hasBattery and batteryCharge == maxCharges then
27717
- return 0
27718
- end
27719
- if not hasBattery and activeCharge + 1 == maxCharges then
27720
- return 1
27721
- end
27722
- if hasBattery and batteryCharge + 1 == maxCharges then
27723
- return 1
27724
- end
27725
- return numCharges
27726
- end
27727
27712
  function getChargesToAddWithAAAModifier(self, player, activeSlot, chargesToAdd)
27728
- local activeItem = player:GetActiveItem(activeSlot)
27729
- local activeCharge = player:GetActiveCharge(activeSlot)
27730
- local batteryCharge = player:GetBatteryCharge(activeSlot)
27731
- local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
27732
27713
  local hasAAABattery = player:HasTrinket(TrinketType.AAA_BATTERY)
27733
- local maxCharges = getCollectibleMaxCharges(nil, activeItem)
27734
27714
  if not hasAAABattery then
27735
27715
  return chargesToAdd
27736
27716
  end
27737
- if not hasBattery and activeCharge + chargesToAdd == maxCharges - 1 then
27738
- return chargesToAdd + 1
27739
- end
27740
- if hasBattery and batteryCharge + chargesToAdd == maxCharges - 1 then
27741
- return chargesToAdd + 1
27742
- end
27743
- 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
27744
27734
  end
27745
27735
  --- Helper function to get the combined normal charge and the battery charge for the player's active
27746
27736
  -- item. This is useful because you have to add these two values together when setting the active
@@ -46969,7 +46959,7 @@ return ____exports
46969
46959
  ["package"] = function(...)
46970
46960
  return {
46971
46961
  name = "isaacscript-common",
46972
- version = "11.2.2",
46962
+ version = "11.2.4",
46973
46963
  description = "Helper functions and features for IsaacScript mods.",
46974
46964
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
46975
46965
  homepage = "https://isaacscript.github.io/",
@@ -46980,7 +46970,7 @@ return {
46980
46970
  type = "commonjs",
46981
46971
  main = "dist/src/index",
46982
46972
  types = "dist/src/index.d.ts",
46983
- dependencies = {["isaac-typescript-definitions"] = "^7.2.3"}
46973
+ dependencies = {["isaac-typescript-definitions"] = "^7.2.4"}
46984
46974
  }
46985
46975
  end,
46986
46976
  ["src.functions.map"] = function(...)
@@ -52316,13 +52306,14 @@ local ____lualib = require("lualib_bundle")
52316
52306
  local Map = ____lualib.Map
52317
52307
  local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
52318
52308
  local ____exports = {}
52319
- local initCommandMap, initCallbacks, postUpdate, evaluateCacheDamage, evaluateCacheFireDelay, evaluateCacheSpeed, evaluateCacheFlying, entityTakeDmgPlayer, postCurseEval, executeCmd
52309
+ local initCommandMap, initCallbacks, postUpdate, evaluateCacheDamage, evaluateCacheFireDelay, evaluateCacheSpeed, evaluateCacheFlying, entityTakeDmgPlayer, postCurseEval, executeCmd, postFireTear
52320
52310
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
52321
52311
  local CacheFlag = ____isaac_2Dtypescript_2Ddefinitions.CacheFlag
52322
52312
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
52323
52313
  local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
52324
52314
  local LevelCurse = ____isaac_2Dtypescript_2Ddefinitions.LevelCurse
52325
52315
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
52316
+ local TearVariant = ____isaac_2Dtypescript_2Ddefinitions.TearVariant
52326
52317
  local ____flag = require("src.functions.flag")
52327
52318
  local addFlag = ____flag.addFlag
52328
52319
  local bitFlags = ____flag.bitFlags
@@ -52360,6 +52351,7 @@ function initCallbacks(self, mod)
52360
52351
  mod:AddCallback(ModCallback.ENTITY_TAKE_DMG, entityTakeDmgPlayer, EntityType.PLAYER)
52361
52352
  mod:AddCallback(ModCallback.POST_CURSE_EVAL, postCurseEval)
52362
52353
  mod:AddCallback(ModCallback.EXECUTE_CMD, executeCmd)
52354
+ mod:AddCallback(ModCallback.POST_FIRE_TEAR, postFireTear)
52363
52355
  end
52364
52356
  function postUpdate(self)
52365
52357
  if v.persistent.spamBloodRights then
@@ -52440,6 +52432,11 @@ function executeCmd(self, command, params)
52440
52432
  printConsole(nil, "Command: " .. commandName)
52441
52433
  commandFunction(nil, params)
52442
52434
  end
52435
+ function postFireTear(self, tear)
52436
+ if v.persistent.chaosCardTears then
52437
+ tear:ChangeVariant(TearVariant.CHAOS_CARD)
52438
+ end
52439
+ end
52443
52440
  function ____exports.extraConsoleCommandsInit(self, mod)
52444
52441
  saveDataManager(nil, "extraConsoleCommands", v, false)
52445
52442
  initCommandMap(nil)
package/dist/package.lua CHANGED
@@ -1,6 +1,6 @@
1
1
  return {
2
2
  name = "isaacscript-common",
3
- version = "11.2.2",
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/",
@@ -11,5 +11,5 @@ return {
11
11
  type = "commonjs",
12
12
  main = "dist/src/index",
13
13
  types = "dist/src/index.d.ts",
14
- dependencies = {["isaac-typescript-definitions"] = "^7.2.3"}
14
+ dependencies = {["isaac-typescript-definitions"] = "^7.2.4"}
15
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/features/extraConsoleCommands/init.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAUxD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAK/D"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/features/extraConsoleCommands/init.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAUxD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAK/D"}
@@ -2,13 +2,14 @@ local ____lualib = require("lualib_bundle")
2
2
  local Map = ____lualib.Map
3
3
  local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
4
4
  local ____exports = {}
5
- local initCommandMap, initCallbacks, postUpdate, evaluateCacheDamage, evaluateCacheFireDelay, evaluateCacheSpeed, evaluateCacheFlying, entityTakeDmgPlayer, postCurseEval, executeCmd
5
+ local initCommandMap, initCallbacks, postUpdate, evaluateCacheDamage, evaluateCacheFireDelay, evaluateCacheSpeed, evaluateCacheFlying, entityTakeDmgPlayer, postCurseEval, executeCmd, postFireTear
6
6
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
7
7
  local CacheFlag = ____isaac_2Dtypescript_2Ddefinitions.CacheFlag
8
8
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
9
9
  local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
10
10
  local LevelCurse = ____isaac_2Dtypescript_2Ddefinitions.LevelCurse
11
11
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
12
+ local TearVariant = ____isaac_2Dtypescript_2Ddefinitions.TearVariant
12
13
  local ____flag = require("src.functions.flag")
13
14
  local addFlag = ____flag.addFlag
14
15
  local bitFlags = ____flag.bitFlags
@@ -46,6 +47,7 @@ function initCallbacks(self, mod)
46
47
  mod:AddCallback(ModCallback.ENTITY_TAKE_DMG, entityTakeDmgPlayer, EntityType.PLAYER)
47
48
  mod:AddCallback(ModCallback.POST_CURSE_EVAL, postCurseEval)
48
49
  mod:AddCallback(ModCallback.EXECUTE_CMD, executeCmd)
50
+ mod:AddCallback(ModCallback.POST_FIRE_TEAR, postFireTear)
49
51
  end
50
52
  function postUpdate(self)
51
53
  if v.persistent.spamBloodRights then
@@ -126,6 +128,11 @@ function executeCmd(self, command, params)
126
128
  printConsole(nil, "Command: " .. commandName)
127
129
  commandFunction(nil, params)
128
130
  end
131
+ function postFireTear(self, tear)
132
+ if v.persistent.chaosCardTears then
133
+ tear:ChangeVariant(TearVariant.CHAOS_CARD)
134
+ end
135
+ end
129
136
  function ____exports.extraConsoleCommandsInit(self, mod)
130
137
  saveDataManager(nil, "extraConsoleCommands", v, false)
131
138
  initCommandMap(nil)
@@ -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.2",
3
+ "version": "11.2.4",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -22,6 +22,6 @@
22
22
  "main": "dist/src/index",
23
23
  "types": "dist/src/index.d.ts",
24
24
  "dependencies": {
25
- "isaac-typescript-definitions": "^7.2.3"
25
+ "isaac-typescript-definitions": "^7.2.4"
26
26
  }
27
27
  }
@@ -5,6 +5,7 @@ import {
5
5
  EntityType,
6
6
  LevelCurse,
7
7
  ModCallback,
8
+ TearVariant,
8
9
  } from "isaac-typescript-definitions";
9
10
  import { ModUpgraded } from "../../classes/ModUpgraded";
10
11
  import { addFlag, bitFlags } from "../../functions/flag";
@@ -62,6 +63,7 @@ function initCallbacks(mod: ModUpgraded) {
62
63
  ); // 11
63
64
  mod.AddCallback(ModCallback.POST_CURSE_EVAL, postCurseEval); // 12
64
65
  mod.AddCallback(ModCallback.EXECUTE_CMD, executeCmd); // 22
66
+ mod.AddCallback(ModCallback.POST_FIRE_TEAR, postFireTear); // 61
65
67
  }
66
68
 
67
69
  // ModCallback.POST_UPDATE (1)
@@ -188,3 +190,10 @@ function executeCmd(command: string, params: string) {
188
190
  printConsole(`Command: ${commandName}`);
189
191
  commandFunction(params);
190
192
  }
193
+
194
+ // ModCallback.POST_FIRE_TEAR (61)
195
+ function postFireTear(tear: EntityTear) {
196
+ if (v.persistent.chaosCardTears) {
197
+ tear.ChangeVariant(TearVariant.CHAOS_CARD);
198
+ }
199
+ }
@@ -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