UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

63 lines (62 loc) 3.1 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StartAmbush = void 0; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const decorators_1 = require("../../../decorators"); const ISCFeature_1 = require("../../../enums/ISCFeature"); const entities_1 = require("../../../functions/entities"); const pickupsSpecific_1 = require("../../../functions/pickupsSpecific"); const Feature_1 = require("../../private/Feature"); /** Hard-coding this makes it easier to clean up the pickups afterwards. */ const SACK_SEED_THAT_SPAWNS_TWO_COINS = 6; class StartAmbush extends Feature_1.Feature { runInNFrames; /** @internal */ constructor(runInNFrames) { super(); this.featuresUsed = [ISCFeature_1.ISCFeature.RUN_IN_N_FRAMES]; this.runInNFrames = runInNFrames; } /** * Helper function to start a Challenge Room or the Boss Rush. * * Specifically, this is performed by spawning a sack on top of the player, waiting a game frame, * and then removing the sack and the pickups that the sack dropped. * * In order to use this function, you must upgrade your mod with `ISCFeature.START_AMBUSH`. * * @public */ startAmbush() { const player = Isaac.GetPlayer(); const sack = (0, pickupsSpecific_1.spawnSackWithSeed)(isaac_typescript_definitions_1.SackSubType.NULL, player.Position, SACK_SEED_THAT_SPAWNS_TWO_COINS); // The sack will play the "Appear" animation and the player will not be able to interact with it // while this is occurring. By stopping the animation, it will transition to the "Idle" // animation and be interactable on the next game frame. const sprite = sack.GetSprite(); sprite.Stop(); const sackPtr = EntityPtr(sack); this.runInNFrames.runNextGameFrame(() => { const futureSack = sackPtr.Ref; if (futureSack === undefined) { return; } futureSack.Remove(); const sackPtrHash = GetPtrHash(futureSack); const coins = (0, pickupsSpecific_1.getCoins)(); const coinsFromSack = coins.filter((pickup) => pickup.SpawnerEntity !== undefined && GetPtrHash(pickup.SpawnerEntity) === sackPtrHash); (0, entities_1.removeEntities)(coinsFromSack); }); } } exports.StartAmbush = StartAmbush; __decorate([ decorators_1.Exported ], StartAmbush.prototype, "startAmbush", null);