UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

48 lines (47 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostPlayerChangeHealth = void 0; const cachedEnumValues_1 = require("../../cachedEnumValues"); const ModCallbackCustom_1 = require("../../enums/ModCallbackCustom"); const playerHealth_1 = require("../../functions/playerHealth"); const playerIndex_1 = require("../../functions/playerIndex"); const shouldFire_1 = require("../../shouldFire"); const DefaultMap_1 = require("../DefaultMap"); const CustomCallback_1 = require("../private/CustomCallback"); const v = { run: { playersHealthMap: new DefaultMap_1.DefaultMap(() => new Map()), }, }; class PostPlayerChangeHealth extends CustomCallback_1.CustomCallback { v = v; constructor() { super(); this.customCallbacksUsed = [ [ ModCallbackCustom_1.ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED, this.postPEffectReordered, ], ]; } shouldFire = shouldFire_1.shouldFirePlayer; // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED postPEffectReordered = (player) => { // We call the "getPlayerIndex" function with the "differentiateForgottenAndSoul" argument. If // we don't differentiate between The Forgotten and The Soul, the callback will fire every time // the player switches between the two. const playerIndex = (0, playerIndex_1.getPlayerIndex)(player, true); const playerHealthMap = v.run.playersHealthMap.getAndSetDefault(playerIndex); for (const healthType of cachedEnumValues_1.HEALTH_TYPE_VALUES) { const storedHealthValue = playerHealthMap.get(healthType); const currentHealthValue = (0, playerHealth_1.getPlayerHealthType)(player, healthType); playerHealthMap.set(healthType, currentHealthValue); if (storedHealthValue !== undefined && storedHealthValue !== currentHealthValue) { const difference = currentHealthValue - storedHealthValue; this.fire(player, healthType, difference, storedHealthValue, currentHealthValue); } } }; } exports.PostPlayerChangeHealth = PostPlayerChangeHealth;