isaacscript-common 30.4.5 → 30.4.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "30.4.5",
3
+ "version": "30.4.6",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -1,3 +1,10 @@
1
+ import {
2
+ CardType,
3
+ CollectibleType,
4
+ ModCallback,
5
+ PillEffect,
6
+ } from "isaac-typescript-definitions";
7
+ import { game } from "../../core/cachedClasses";
1
8
  import { ModCallbackCustom } from "../../enums/ModCallbackCustom";
2
9
  import { getPickups } from "../../functions/entitiesSpecific";
3
10
  import {
@@ -19,6 +26,7 @@ const v = {
19
26
  playersHoldingItemOnLastFrameMap: new DefaultMap<PlayerIndex, boolean>(
20
27
  false,
21
28
  ),
29
+ playersUsedItemOnFrame: new DefaultMap<PlayerIndex, int>(0),
22
30
  },
23
31
  };
24
32
 
@@ -28,6 +36,17 @@ export class PostPurchase extends CustomCallback<T> {
28
36
  constructor() {
29
37
  super();
30
38
 
39
+ this.callbacksUsed = [
40
+ // 3
41
+ [ModCallback.POST_USE_ITEM, this.postUseItem],
42
+
43
+ // 5
44
+ [ModCallback.POST_USE_CARD, this.postUseCard],
45
+
46
+ // 10
47
+ [ModCallback.POST_USE_PILL, this.postUsePill],
48
+ ];
49
+
31
50
  this.customCallbacksUsed = [
32
51
  [
33
52
  ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
@@ -51,6 +70,28 @@ export class PostPurchase extends CustomCallback<T> {
51
70
  );
52
71
  };
53
72
 
73
+ // ModCallback.POST_USE_ITEM (3)
74
+ private postUseItem = (
75
+ _collectibleType: CollectibleType,
76
+ _rng: RNG,
77
+ player: EntityPlayer,
78
+ ): boolean | undefined => {
79
+ markUsedItemOnThisFrame(player);
80
+ return undefined;
81
+ };
82
+
83
+ // ModCallback.POST_USE_CARD (5)
84
+ private postUseCard = (_cardType: CardType, player: EntityPlayer) => {
85
+ markUsedItemOnThisFrame(player);
86
+ return undefined;
87
+ };
88
+
89
+ // ModCallback.POST_USE_PILL (10)
90
+ private postUsePill = (_pillEffect: PillEffect, player: EntityPlayer) => {
91
+ markUsedItemOnThisFrame(player);
92
+ return undefined;
93
+ };
94
+
54
95
  // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
55
96
  private postPEffectUpdateReordered = (player: EntityPlayer) => {
56
97
  const isHoldingItem = player.IsHoldingItem();
@@ -64,11 +105,29 @@ export class PostPurchase extends CustomCallback<T> {
64
105
  isHoldingItem,
65
106
  );
66
107
 
67
- if (!wasHoldingItemOnLastFrame && isHoldingItem) {
108
+ // Assume that if the player did not use an active item, card, or pill recently, then they
109
+ // purchased an item.
110
+ if (
111
+ !wasHoldingItemOnLastFrame &&
112
+ isHoldingItem &&
113
+ !this.playerUsedItemRecently(player)
114
+ ) {
68
115
  this.playerPickedUpNewItem(player);
69
116
  }
70
117
  };
71
118
 
119
+ private playerUsedItemRecently(player: EntityPlayer): boolean {
120
+ const gameFrameCount = game.GetFrameCount();
121
+ const usedCollectibleOnFrame = defaultMapGetPlayer(
122
+ v.room.playersUsedItemOnFrame,
123
+ player,
124
+ );
125
+ return (
126
+ gameFrameCount === usedCollectibleOnFrame ||
127
+ gameFrameCount === usedCollectibleOnFrame + 1
128
+ );
129
+ }
130
+
72
131
  private playerPickedUpNewItem(player: EntityPlayer) {
73
132
  const pickups = getPickups();
74
133
  const disappearingPickup = pickups.find(
@@ -79,3 +138,8 @@ export class PostPurchase extends CustomCallback<T> {
79
138
  }
80
139
  }
81
140
  }
141
+
142
+ function markUsedItemOnThisFrame(player: EntityPlayer) {
143
+ const gameFrameCount = game.GetFrameCount();
144
+ mapSetPlayer(v.room.playersUsedItemOnFrame, player, gameFrameCount);
145
+ }