isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
107 lines (106 loc) • 4.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPlayerStat = addPlayerStat;
exports.getDefaultPlayerStat = getDefaultPlayerStat;
exports.getPlayerStat = getPlayerStat;
exports.getPlayerStats = getPlayerStats;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const PlayerStat_1 = require("../enums/PlayerStat");
const defaultPlayerStatMap_1 = require("../maps/defaultPlayerStatMap");
const ReadonlySet_1 = require("../types/ReadonlySet");
const tears_1 = require("./tears");
const STAT_CACHE_FLAGS_SET = new ReadonlySet_1.ReadonlySet([
isaac_typescript_definitions_1.CacheFlag.DAMAGE, // 1 << 0
isaac_typescript_definitions_1.CacheFlag.FIRE_DELAY, // 1 << 1
isaac_typescript_definitions_1.CacheFlag.SHOT_SPEED, // 1 << 2
isaac_typescript_definitions_1.CacheFlag.RANGE, // 1 << 3
isaac_typescript_definitions_1.CacheFlag.SPEED, // 1 << 4
isaac_typescript_definitions_1.CacheFlag.LUCK, // 1 << 10
]);
/**
* Helper function to add a stat to a player based on the `CacheFlag` provided. Call this function
* from the `EVALUATE_CACHE` callback.
*
* Note that for `CacheFlag.FIRE_DELAY`, the "amount" argument will be interpreted as the tear stat
* to add (and not the amount to mutate `EntityPlayer.MaxFireDelay` by).
*
* This function supports the following cache flags:
* - CacheFlag.DAMAGE (1 << 0)
* - CacheFlag.FIRE_DELAY (1 << 1)
* - CacheFlag.SHOT_SPEED (1 << 2)
* - CacheFlag.RANGE (1 << 3)
* - CacheFlag.SPEED (1 << 4)
* - CacheFlag.LUCK (1 << 10)
*/
function addPlayerStat(player, cacheFlag, amount) {
if (!STAT_CACHE_FLAGS_SET.has(cacheFlag)) {
error(`You cannot add a stat to a player with the cache flag of: ${cacheFlag}`);
}
switch (cacheFlag) {
// 1 << 0
case isaac_typescript_definitions_1.CacheFlag.DAMAGE: {
player.Damage += amount;
break;
}
// 1 << 1
case isaac_typescript_definitions_1.CacheFlag.FIRE_DELAY: {
(0, tears_1.addTearsStat)(player, amount);
break;
}
// 1 << 2
case isaac_typescript_definitions_1.CacheFlag.SHOT_SPEED: {
player.ShotSpeed += amount;
break;
}
// 1 << 3
case isaac_typescript_definitions_1.CacheFlag.RANGE: {
player.TearRange += amount;
break;
}
// 1 << 4
case isaac_typescript_definitions_1.CacheFlag.SPEED: {
player.MoveSpeed += amount;
break;
}
// 1 << 10
case isaac_typescript_definitions_1.CacheFlag.LUCK: {
player.Luck += amount;
break;
}
default: {
break;
}
}
}
/**
* Returns the starting stat that Isaac (the default character) starts with. For example, if you
* pass this function `CacheFlag.DAMAGE`, it will return 3.5.
*
* Note that the default fire delay is represented in the tear stat, not the `MaxFireDelay` value.
*/
function getDefaultPlayerStat(cacheFlag) {
return defaultPlayerStatMap_1.DEFAULT_PLAYER_STAT_MAP.get(cacheFlag);
}
/** Helper function to get the stat for a player corresponding to the `StatType`. */
function getPlayerStat(player, playerStat) {
const playerStats = getPlayerStats(player);
return playerStats[playerStat];
}
/** Helper function to get all of the stat for a player. */
function getPlayerStats(player) {
return {
[PlayerStat_1.PlayerStat.DAMAGE]: player.Damage, // 1 << 0
[PlayerStat_1.PlayerStat.FIRE_DELAY]: player.MaxFireDelay, // 1 << 1
[PlayerStat_1.PlayerStat.SHOT_SPEED]: player.ShotSpeed, // 1 << 2
[PlayerStat_1.PlayerStat.TEAR_HEIGHT]: player.TearHeight, // 1 << 3
[PlayerStat_1.PlayerStat.TEAR_RANGE]: player.TearRange, // 1 << 3
[PlayerStat_1.PlayerStat.TEAR_FALLING_ACCELERATION]: player.TearFallingAcceleration, // 1 << 3
[PlayerStat_1.PlayerStat.TEAR_FALLING_SPEED]: player.TearFallingSpeed, // 1 << 3
[PlayerStat_1.PlayerStat.MOVE_SPEED]: player.MoveSpeed, // 1 << 4
[PlayerStat_1.PlayerStat.TEAR_FLAG]: player.TearFlags, // 1 << 5
[PlayerStat_1.PlayerStat.TEAR_COLOR]: player.TearColor, // 1 << 6
[PlayerStat_1.PlayerStat.FLYING]: player.CanFly, // 1 << 7
[PlayerStat_1.PlayerStat.LUCK]: player.Luck, // 1 << 10
[PlayerStat_1.PlayerStat.SIZE]: player.SpriteScale, // 1 << 11
};
}