Skip to content

Commit 736ba9f

Browse files
KOSMOGORZamiell
andauthored
feat: custom CustomPickups return value (#135)
* update: changed signature of functions in CustomPickups for more functionality fix: getAdjustedPrice() now uses Math.ceil() instead of Math.floor() fix: changed version using "npm audit fix" * fix: linting revert: package-lock.json * fix: comment linting * revert: added this to function signatures * update: simplified CustomPickups Co-authored-by: James <5511220+Zamiell@users.noreply.github.com> --------- Co-authored-by: James <5511220+Zamiell@users.noreply.github.com>
1 parent 4d2559e commit 736ba9f

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

packages/isaacscript-common/src/classes/features/other/CustomPickups.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import { spawnEffect } from "../../../functions/entitiesSpecific";
1414
import { Feature } from "../../private/Feature";
1515

1616
interface CustomPickupFunctions {
17-
collectFunc: (this: void, player: EntityPlayer) => void;
18-
collisionFunc: (this: void, player: EntityPlayer) => boolean;
17+
collectFunc: (this: void, pickup: EntityPickup, player: EntityPlayer) => void;
18+
collisionFunc: (
19+
this: void,
20+
pickup: EntityPickup,
21+
player: EntityPlayer,
22+
) => boolean | undefined;
1923
}
2024

2125
/**
@@ -69,9 +73,9 @@ export class CustomPickups extends Feature {
6973
return undefined;
7074
}
7175

72-
const shouldPickup = customPickupFunctions.collisionFunc(player);
73-
if (!shouldPickup) {
74-
return undefined;
76+
const shouldPickup = customPickupFunctions.collisionFunc(pickup, player);
77+
if (shouldPickup !== undefined) {
78+
return shouldPickup;
7579
}
7680

7781
pickup.Remove();
@@ -88,7 +92,7 @@ export class CustomPickups extends Feature {
8892
effectSprite.Load(fileName, true);
8993
effectSprite.Play("Collect", true);
9094

91-
customPickupFunctions.collectFunc(player);
95+
customPickupFunctions.collectFunc(pickup, player);
9296

9397
return undefined;
9498
};
@@ -128,18 +132,27 @@ export class CustomPickups extends Feature {
128132
* @param subType The sub-type for the corresponding custom pickup.
129133
* @param collectFunc The function to run when the player collects this pickup.
130134
* @param collisionFunc Optional. The function to run when a player collides with the pickup.
131-
* Default is a function that always returns true, meaning that the player
132-
* will always immediately collect the pickup when they collide with it.
133-
* Specify this function if your pickup should only be able to be collected
134-
* under certain conditions.
135+
* Default is a function that always returns undefined, meaning that the
136+
* player will always immediately collect the pickup when they collide with
137+
* it. Specify this function if your pickup should only be able to be
138+
* collected under certain conditions. Return value acts similar to
139+
* `ModCallback.PRE_PICKUP_COLLISION`.
135140
* @public
136141
*/
137142
@Exported
138143
public registerCustomPickup(
139144
pickupVariantCustom: PickupVariant,
140145
subType: int,
141-
collectFunc: (this: void, player: EntityPlayer) => void,
142-
collisionFunc: (this: void, player: EntityPlayer) => boolean = () => true,
146+
collectFunc: (
147+
this: void,
148+
pickup: EntityPickup,
149+
player: EntityPlayer,
150+
) => void,
151+
collisionFunc: (
152+
this: void,
153+
pickup: EntityPickup,
154+
player: EntityPlayer,
155+
) => boolean | undefined = () => undefined,
143156
): void {
144157
const entityID = getEntityIDFromConstituents(
145158
EntityType.PICKUP,

packages/isaacscript-common/src/functions/playerCollectibles.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export function getActiveItemSlots(
7878
*/
7979
export function getAdjustedPrice(basePrice: int): int {
8080
const numSteamSales = getTotalPlayerCollectibles(CollectibleType.STEAM_SALE);
81-
return numSteamSales > 0
82-
? Math.floor(basePrice / (numSteamSales + 1))
83-
: basePrice;
81+
return Math.ceil(basePrice / (numSteamSales + 1));
8482
}
8583

8684
/**

0 commit comments

Comments
 (0)