Files
isaac-port/src/entity_player_weapons.cpp
T

623 lines
31 KiB
C++

#include "entity_effect.h"
#include "entity_familiar.h"
#include "entity_knife.h"
#include "weapon_knives.h"
#include "entity_laser.h"
#include "entity_player.h"
#include "entity_tear.h"
#include "game.h"
#include "log.h"
#include "lua_engine.h"
#include "manager.h"
#include "menu_manager.h"
#include "room.h"
#include <algorithm>
#include <cmath>
constexpr int TECH5_FLAG_CHANCE = 5;
constexpr int TECH5_FLAG_ROLL = 100;
constexpr int TECH5_FLAG_COUNT = 84;
constexpr float HEAD_PIVOT_LIFT = -5;
constexpr int PLAYER_HEAD_LAYER = 4;
constexpr const char* NULL_OFFSET_NAMES[] = {"LeftEye", "RightEye", "Forehead", "Mouth", "Mouth", "MomsEye", "Tractor"};
constexpr float CROSS_EYED_ANGLE = 0.7853982f;
constexpr float DEAD_EYE_STEP = 0.125f;
constexpr float DEGREES_TO_RADIANS = 0.017453292f;
constexpr float DEGREES_PER_RADIAN = 57.295776f;
constexpr float DUNGEON_TEAR_HEIGHT_MAX = -5.1f;
constexpr float DUNGEON_TEAR_OFFSET_Y = -18;
constexpr float INHERIT_SCALE = 0.6f;
constexpr float LANE_HALF_ARC = 90;
constexpr float LANE_SPREAD_X = 1.15f;
constexpr float LANE_SPREAD_Y = 0.8f;
constexpr float RANDOM_UNIT = 2.3283064e-10f;
constexpr float SPREAD_CLAMP = 90;
constexpr float TEAR_FALL_SPREAD = 0.2f;
constexpr float TEAR_SCALE_MIN = 0.01f;
constexpr float WIZ_EYE_ANGLE = 45;
// How much each extra tear widens a volley's tears and lasers, by what adds it, and how the other weapons follow.
constexpr float SPREAD_ITEM_LASER = 2.333f;
constexpr float SPREAD_ITEM_TEARS = 2.167f;
constexpr float SPREAD_LUNG_LASER = 2.7f;
constexpr float SPREAD_LUNG_TEARS = 2.4f;
constexpr float SPREAD_MULTIPLIER_LASER = 2.33f;
constexpr float SPREAD_MULTIPLIER_TEARS = 2.17f;
constexpr float SPREAD_TWINS_TEARS = 0.4f;
constexpr float SPREAD_WIZ_LASER = 3;
constexpr float SPREAD_KNIFE_SCALE = 2.14f;
constexpr float SPREAD_TECH_X_SCALE = 2.4f;
constexpr float SPREAD_BONE_SCALE = 3;
constexpr float MOMS_EYE_CHANCE = 0.5f;
constexpr float MOMS_EYE_LUCK = 0.1f;
constexpr float LOKIS_HORNS_CHANCE = 0.25f;
constexpr float LOKIS_HORNS_LUCK = 0.05f;
constexpr int LUNG_TEARS_PER_COPY = 5;
constexpr int LUNG_RANDOM_ROCKETS = 2;
constexpr int LUNG_RANDOM_LASERS = 3;
constexpr int LUNG_RANDOM_RANGE = 3;
constexpr int EYE_SORE_ROLL_MASK = 3;
constexpr int BOOKWORM_ROLL_MASK = 3;
constexpr int CONJOINED_EXTRA_TEARS = 2;
constexpr float WIZ_EYE_ANGLE_MAX = 55;
constexpr int DEAD_EYE_STEPS = 8;
constexpr int DARK_ARTS_STEPS = 16;
constexpr float DARK_ARTS_STEP = 0.0625f;
constexpr int MAX_TEARS = 16;
constexpr int MAX_EYES = 8;
constexpr int BABY_TECHNOLOGY = 16;
constexpr int BABY_TWENTY_TWENTY = 65;
constexpr int PLAYERFORM_CONJOINED = 7;
constexpr int PLAYERFORM_BOOKWORM = 10;
constexpr int TRANSFORMATION_COUNT = 3;
constexpr int TEAR_COLOR_PRIORITY = 255;
constexpr float TECH_X_THICKER_SCALE = 1.5f;
constexpr float TECH_X_RING_LIFT = -20;
constexpr int COLLECTIBLE_BRIMSTONE_WEAPON = 118;
constexpr int COLLECTIBLE_CURSED_EYE_WEAPON = 316;
constexpr int COLLECTIBLE_DEAD_TOOTH = 446;
constexpr int COLLECTIBLE_EYE_SORE = 558;
constexpr int COLLECTIBLE_INNER_EYE = 2;
constexpr int COLLECTIBLE_LARGE_ZIT = 502;
constexpr int COLLECTIBLE_NEPTUNUS = 597;
constexpr int COLLECTIBLE_THE_WIZ = 358;
constexpr int NULLITEM_DARK_ARTS = 111;
// The items GetWeaponModifiers turns into modifier bits, in the order it asks.
constexpr std::pair<int, uint32_t> MODIFIER_ITEMS[] = {
{COLLECTIBLE_CHOCOLATE_MILK, WEAPON_MOD_CHOCOLATE_MILK}, {COLLECTIBLE_CURSED_EYE_WEAPON, WEAPON_MOD_CURSED_EYE},
{COLLECTIBLE_BRIMSTONE_WEAPON, WEAPON_MOD_BRIMSTONE}, {COLLECTIBLE_MONSTROS_LUNG, WEAPON_MOD_MONSTROS_LUNG},
{COLLECTIBLE_LUDOVICO, WEAPON_MOD_LUDOVICO_TECHNIQUE}, {COLLECTIBLE_ANTI_GRAVITY, WEAPON_MOD_ANTI_GRAVITY},
{COLLECTIBLE_TRACTOR_BEAM, WEAPON_MOD_TRACTOR_BEAM}, {COLLECTIBLE_NEPTUNUS, WEAPON_MOD_NEPTUNUS}};
// The items whose copies past the first each add a tear to the volley.
constexpr int SPREAD_ITEMS[] = {COLLECTIBLE_TECHNOLOGY, COLLECTIBLE_MOMS_KNIFE, COLLECTIBLE_DR_FETUS,
COLLECTIBLE_EPIC_FETUS, COLLECTIBLE_LUDOVICO, COLLECTIBLE_TECH_X};
// A vector turned by an angle in radians.
static Vector vector_rotate(Vector v, float radians)
{
float cosine = std::cos(radians);
float sine = std::sin(radians);
return vector_make(v.x * cosine - v.y * sine, v.y * cosine + v.x * sine);
}
static Vector vector_scale(Vector v, float scale) { return vector_make(v.x * scale, v.y * scale); }
// The weapon in charge: the one overriding the rest, or the main one.
static Weapon* weapon_main(std::array<WeaponPtr, WEAPON_SLOT_COUNT>& weapons)
{
return weapons[0] ? weapons[0].get() : weapons[1].get();
}
// 005b1780 Whether the player has a weapon type.
bool Entity_Player::HasWeaponType(int weaponType)
{
return weaponType >= 0 && weaponType < WEAPON_TYPE_COUNT && weaponTypes[weaponType];
}
// 00753980 Gives or takes a weapon type, which EvaluateItems makes weapons of. Out of range types write past the array
// in the original: here they are ignored.
void Entity_Player::EnableWeaponType(int weaponType, bool isSet)
{
if (weaponType >= 0 && weaponType < WEAPON_TYPE_COUNT) weaponTypes[weaponType] = isSet;
}
// 00779320 What the camera and the head follow: the Marked target, or what a weapon (past the overriding slot) aims.
Entity* Entity_Player::GetFocusEntity()
{
if (markedTarget) return markedTarget;
for (int slot = 1; slot < WEAPON_SLOT_COUNT; slot++)
if (Entity* focus = weapons[slot] ? weapons[slot]->GetFocusEntity() : nullptr) return focus;
return nullptr;
}
// 00779a20 The modifier bits the player's items, Tainted Azazel's sneeze and C Section give its weapons.
int Entity_Player::GetWeaponModifiers()
{
uint32_t modifiers = 0;
for (auto [item, modifier] : MODIFIER_ITEMS)
if (HasCollectible(item)) modifiers |= modifier;
if (HasCollectible(COLLECTIBLE_SOY_MILK) || HasCollectible(COLLECTIBLE_ALMOND_MILK))
modifiers |= WEAPON_MOD_SOY_MILK;
if (playerType == PLAYER_AZAZEL_B) modifiers |= WEAPON_MOD_AZAZELS_SNEEZE;
if (HasCollectible(COLLECTIBLE_C_SECTION)) modifiers |= WEAPON_MOD_C_SECTION;
return (int)modifiers;
}
// 00782a40 The entity the weapon in charge fires as, if any.
Entity* Entity_Player::GetActiveWeaponEntity()
{
Weapon* weapon = weapon_main(weapons);
return weapon ? weapon->GetMainEntity() : nullptr;
}
// 00782a70 The fire delay of the weapon in charge.
float Entity_Player::FireDelay()
{
Weapon* weapon = weapon_main(weapons);
return weapon ? weapon->fireDelay : 0;
}
// 00753940 The shot direction of a few frames ago, as weapons aim with it: the oldest kept, or the last one.
Vector Entity_Player::delayed_shoot_direction()
{
return shootDirectionHistory.empty() ? lastDirection : shootDirectionHistory.front();
}
// 007ad4e0 Stops the item animations of the costumes the player wears, unless it is a co-op ghost.
void Entity_Player::stop_costume_item_anims()
{
if (isCoopGhost) return;
for (PlayerCostumeMap& map : playerCostumeMap)
if (map.index >= 0) costumeSpriteDescs[map.index].isItemAnimPlay = false;
}
// 007826d0 What firing does each frame: the items that react to shots (not written yet), then the weapon in charge
// fires, or every weapon does. Offline every player is local, so the deathmatch's check is not written yet.
void Entity_Player::trigger_fire_item_effects(Vector direction, bool isShotFired)
{
if (g_game->deathmatchManager.is_active())
reconstruction_missing("Entity_Player::trigger_fire_item_effects 007826d0 (deathmatch)");
if (HasCollectible(COLLECTIBLE_DEAD_TOOTH) || HasCollectible(COLLECTIBLE_LARGE_ZIT))
reconstruction_missing("Entity_Player::trigger_fire_item_effects 007826d0 (Dead Tooth and Large Zit)");
bool isInterpolated = HasEntityFlags(FLAG_INTERPOLATION_UPDATE);
if (weapons[0])
{
weapons[0]->Fire(direction, isShotFired, isInterpolated);
return;
}
for (int slot = 1; slot < WEAPON_SLOT_COUNT; slot++)
if (weapons[slot]) weapons[slot]->Fire(direction, isShotFired, isInterpolated);
}
// 007aaea0 The share of the player's movement its shots carry: twice six tenths of its last velocity, without the part
// against the shot. None while Marked aims or tears leave from a shifted head, unless always asked.
Vector Entity_Player::GetTearMovementInheritance(const Vector& shotDirection, InheritMode mode)
{
bool isShifted =
(tearsOffset.x != 0 || tearsOffset.y != 0) && (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_SCISSORS) ||
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_DECAP_ATTACK));
if (mode == INHERIT_CHECKED && ((HasCollectible(COLLECTIBLE_MARKED) && markedTarget) || isShifted)) return {};
Vector inherited = vector_make(lastVelocity.x * INHERIT_SCALE, lastVelocity.y * INHERIT_SCALE);
inherited = vector_make(inherited.x + inherited.x, inherited.y + inherited.y);
if (shotDirection.x == 0 && shotDirection.y == 0) return inherited;
float length = std::sqrt(shotDirection.x * shotDirection.x + shotDirection.y * shotDirection.y);
Vector normal = length > 0 ? vector_scale(shotDirection, 1 / length) : shotDirection;
float along = inherited.x * normal.x + inherited.y * normal.y;
Vector projection = vector_scale(normal, along);
if (projection.y * shotDirection.y + projection.x * shotDirection.x < 0)
inherited = vector_make(inherited.x - projection.x, inherited.y - projection.y);
return inherited;
}
// 00781b90 How the player's volleys spread: extra tears for each copy of the weapon items past the first, Monstro's
// Lung, Mutant Spider, Inner Eye, 20/20 and Bookworm's chance, The Wiz's eyes, Conjoined's cross-eyed pair, Mom's Eye
// and Loki's Horns' backward and sideways shots, and Eye Sore's and the Lung's random ones.
Weapon_MultiShotParams Entity_Player::GetMultiShotParams(WeaponType weaponType)
{
Weapon_MultiShotParams params;
int extraTears = 0;
for (int item : SPREAD_ITEMS) extraTears += std::max(0, GetCollectibleNum(item) - 1);
if (extraTears != 0)
{
params.numTears = (short)(params.numTears + extraTears);
params.spreadAngleLaser += (float)extraTears * SPREAD_ITEM_LASER;
params.spreadAngleTears += (float)extraTears * SPREAD_ITEM_TEARS;
}
int lungTears = std::max(0, GetCollectibleNum(COLLECTIBLE_MONSTROS_LUNG) - 1);
if (lungTears != 0)
{
params.numTears = (short)(params.numTears + lungTears * LUNG_TEARS_PER_COPY);
params.spreadAngleLaser += (float)lungTears * SPREAD_LUNG_LASER;
params.spreadAngleTears += (float)lungTears * SPREAD_LUNG_TEARS;
}
int spiders = GetCollectibleNum(COLLECTIBLE_MUTANT_SPIDER) + (playerType == PLAYER_KEEPER_B);
int innerEyes = temporaryEffects.HasNullEffect(NULLITEM_REVERSE_HANGED_MAN) + (playerType == PLAYER_KEEPER) +
GetCollectibleNum(COLLECTIBLE_INNER_EYE) +
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_INNER_EYE);
int twins = temporaryEffects.HasCollectibleEffect(COLLECTIBLE_20_20) + GetCollectibleNum(COLLECTIBLE_20_20) +
(babySkin == BABY_TWENTY_TWENTY);
bool isMultiplied = spiders != 0 || innerEyes != 0;
if (isMultiplied)
{
int extra = spiders * 2 + 1 + innerEyes;
params.numTears = (short)(params.numTears + extra);
params.spreadAngleLaser += (float)extra * SPREAD_MULTIPLIER_LASER;
params.spreadAngleTears += (float)extra * SPREAD_MULTIPLIER_TEARS;
}
if (twins != 0) params.numTears = (short)(params.numTears + twins - (isMultiplied ? 1 : 0));
bool isBookwormShot = weaponType != WEAPON_LUDOVICO_TECHNIQUE && !hasCurseMistEffect && !isCoopGhost &&
playerForms[PLAYERFORM_BOOKWORM] >= TRANSFORMATION_COUNT &&
(Random() & BOOKWORM_ROLL_MASK) == 0;
if (isBookwormShot) params.numTears++;
if (isBookwormShot || twins != 0)
{
params.spreadAngleTears *= SPREAD_TWINS_TEARS;
params.spreadAngleLaser += (float)twins + (float)twins;
}
int wizards = temporaryEffects.HasCollectibleEffect(COLLECTIBLE_THE_WIZ) + GetCollectibleNum(COLLECTIBLE_THE_WIZ);
int tears = params.numTears;
if (wizards != 0)
{
params.numEyesActive = std::min(params.numEyesActive + wizards, MAX_EYES);
params.spreadAngleLaser += (float)wizards * SPREAD_WIZ_LASER;
tears = (short)(params.numTears + wizards);
if (tears % params.numEyesActive != 0)
tears = (short)(tears + params.numEyesActive - tears % params.numEyesActive);
params.multiEyeAngle = std::min((float)wizards * WIZ_EYE_ANGLE, WIZ_EYE_ANGLE_MAX);
}
if (!hasCurseMistEffect && !isCoopGhost && playerForms[PLAYERFORM_CONJOINED] >= TRANSFORMATION_COUNT)
{
params.isCrossEyed = wizards == 0;
tears = (short)(tears + CONJOINED_EXTRA_TEARS);
}
tears = std::min(tears, MAX_TEARS);
params.numLanesPerEye = (short)(tears / params.numEyesActive);
params.spreadAngleKnife = params.spreadAngleLaser * SPREAD_KNIFE_SCALE;
params.numTears = (short)(params.numLanesPerEye * params.numEyesActive);
params.spreadAngleTechX = std::min(params.spreadAngleTears * SPREAD_TECH_X_SCALE, SPREAD_CLAMP);
params.spreadAngleTears = std::min(params.spreadAngleTears, SPREAD_CLAMP);
params.spreadAngleLaser = std::min(params.spreadAngleLaser, SPREAD_CLAMP);
bool isMomsEye = HasCollectible(COLLECTIBLE_MOMS_EYE);
bool isLokisHorns = HasCollectible(COLLECTIBLE_LOKIS_HORNS);
bool isLung = HasCollectible(COLLECTIBLE_MONSTROS_LUNG);
if (weaponType == WEAPON_LUDOVICO_TECHNIQUE)
{
params.isShootingBackwards = isMomsEye || isLokisHorns;
params.isShootingSideways = isLokisHorns;
}
else if ((isMomsEye && (float)Random() * RANDOM_UNIT < luck * MOMS_EYE_LUCK + MOMS_EYE_CHANCE) ||
(isLokisHorns && (float)Random() * RANDOM_UNIT < luck * LOKIS_HORNS_LUCK + LOKIS_HORNS_CHANCE))
{
params.isShootingBackwards = true;
params.isShootingSideways = isLokisHorns;
}
if (HasCollectible(COLLECTIBLE_EYE_SORE))
{
uint32_t first = Random();
uint32_t second = Random();
params.numRandomDirTears = (short)std::max(0, (int)(first & EYE_SORE_ROLL_MASK) - EYE_SORE_ROLL_MASK +
(int)(second & EYE_SORE_ROLL_MASK));
}
else if (isLung && weaponType == WEAPON_ROCKETS)
params.numRandomDirTears = (short)(Random() % LUNG_RANDOM_RANGE + LUNG_RANDOM_ROCKETS);
else if (isLung && (weaponType == WEAPON_BRIMSTONE || weaponType == WEAPON_TECH_X))
params.numRandomDirTears = (short)(Random() % LUNG_RANDOM_RANGE + LUNG_RANDOM_LASERS);
return params;
}
// 00782160 Where shot loopIndex of a volley starts and how fast it goes: the eyes fan out over The Wiz's angle, the
// lanes of an eye spread over the weapon's angle (tears, Tech X and bombs also start along an arc), and Conjoined's
// last two shots go off at 45 degrees.
PosVel Entity_Player::GetMultiShotPositionVelocity(int loopIndex, WeaponType weaponType, const Vector& shotDirection,
float shotSpeed, const Weapon_MultiShotParams& params)
{
float spreadAngle = params.spreadAngleTears;
if (weaponType == WEAPON_LASER || weaponType == WEAPON_BRIMSTONE) spreadAngle = params.spreadAngleLaser;
else if (weaponType == WEAPON_TECH_X) spreadAngle = params.spreadAngleTechX;
else if (weaponType == WEAPON_KNIFE) spreadAngle = params.spreadAngleKnife;
else if (weaponType == WEAPON_BONE) spreadAngle = params.spreadAngleKnife * SPREAD_BONE_SCALE;
PosVel shot;
if (params.isCrossEyed && loopIndex >= params.numTears - 2)
{
float angle = loopIndex == params.numTears - 1 ? CROSS_EYED_ANGLE : -CROSS_EYED_ANGLE;
shot.velocity = vector_scale(vector_rotate(shotDirection, angle), shotSpeed);
return shot;
}
float eyeAngle = 0;
if (params.numEyesActive > 1)
{
float t = std::clamp((float)(loopIndex % params.numEyesActive) / ((float)params.numEyesActive - 1), 0.0f, 1.0f);
eyeAngle = (params.multiEyeAngle + params.multiEyeAngle) * t - params.multiEyeAngle;
}
Vector aimed = vector_rotate(shotDirection, eyeAngle * DEGREES_TO_RADIANS);
shot.velocity = vector_scale(aimed, shotSpeed);
if (params.numLanesPerEye <= 1) return shot;
float lane = std::clamp((float)(loopIndex / params.numEyesActive) / ((float)params.numLanesPerEye - 1), 0.0f, 1.0f);
if (weaponType == WEAPON_TEARS || weaponType == WEAPON_TECH_X || weaponType == WEAPON_BOMBS)
{
float arc = (lane * (LANE_HALF_ARC + LANE_HALF_ARC) - LANE_HALF_ARC) * DEGREES_TO_RADIANS;
float length = std::sqrt(aimed.y * aimed.y + aimed.x * aimed.x);
Vector offset = vector_make(std::cos(arc) * LANE_SPREAD_X * length, std::sin(arc) * LANE_SPREAD_Y * length);
shot.position = vector_rotate(offset, std::atan2(aimed.y, aimed.x) * DEGREES_PER_RADIAN * DEGREES_TO_RADIANS);
}
shot.velocity =
vector_rotate(shot.velocity, ((spreadAngle + spreadAngle) * lane - spreadAngle) * DEGREES_TO_RADIANS);
return shot;
}
// 00790af0 Fires a tear with the player's hit params from a shot (from the player's tear offset when it shoots it
// itself): its height, fall, scale, color, range, Dead Eye's (or Dark Arts') glow and an index, updated once and moved
// back a frame.
// The Marked target holds no tear back, and extra shots drop the Tractor Beam and end no streak. The co-op baby's
// lasers, Stye, Evil Eye and the Lua callback are not written yet.
Entity_Tear* Entity_Player::FireTear(const PosVel& shot, uint32_t fireFlags, Entity* source, float damageMultiplier)
{
if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_TECHNOLOGY)
reconstruction_missing("Entity_Player::FireTear 00790af0 (the laser baby)");
Vector position = shot.position;
if (source && source == this) position = vector_add(position, tearsOffset);
TearParams params = GetTearHitParams(WEAPON_TEARS, damageMultiplier, tearDisplacement, source);
if (HasCollectible(COLLECTIBLE_MARKED)) params.tearFlags.reset(TEAR_WAIT);
if (fireFlags & TEAR_FIRE_NO_TRACTOR_BEAM) params.tearFlags.reset(TEAR_TRACTOR_BEAM);
EntitySpawn spawn{.position = vector_add(shot.velocity, position),
.velocity = shot.velocity,
.spawner = this,
.type = ENTITY_TEAR,
.variant = params.tearVariant};
spawn.seed = Random();
Entity_Tear* tear = g_game->Spawn(spawn)->ToTear();
tear->velocity = vector_scale(tear->velocity, params.speedMultiplier);
tear->height = params.tearHeight;
tear->posOffset.y = tear->get_height_offset_y(params.tearHeight);
if (g_game->room->roomType == ROOM_DUNGEON)
{
tear->posOffset.y = DUNGEON_TEAR_OFFSET_Y;
if (params.tearHeight > DUNGEON_TEAR_HEIGHT_MAX) tear->height = DUNGEON_TEAR_HEIGHT_MAX;
}
float fallSpread = params.tearFlags.test(TEAR_POP) ? 0 : (float)Random() * RANDOM_UNIT * TEAR_FALL_SPREAD;
tear->fallingSpeed = fallSpread - tearFallingSpeed;
tear->SetCollisionDamage(params.tearDamage);
tear->SetTearFlags(params.tearFlags);
tear->baseScale = std::max(params.tearScale, TEAR_SCALE_MIN);
tear->fScale = tear->baseScale;
tear->ResetSpriteScale();
tear->fallingAccel = tearFallingAcceleration;
tear->SetColor(params.tearColor, -1, TEAR_COLOR_PRIORITY, false, true);
tear->tearRange = tearRange;
tear->parent = this;
if (fireFlags & TEAR_FIRE_NO_STREAK_END) tear->isCanTriggerStreakEnd = false;
float deadEye = deadEyeCharges > 0 ? (float)std::min((int)deadEyeCharges, DEAD_EYE_STEPS) * DEAD_EYE_STEP : 0;
float intensity = deadEye;
if (int darkArts = temporaryEffects.GetNullEffectNum(NULLITEM_DARK_ARTS); darkArts > 0)
intensity = std::max((float)std::min(darkArts, DARK_ARTS_STEPS) * DARK_ARTS_STEP, deadEye);
if (HasCollectible(COLLECTIBLE_STYE)) reconstruction_missing("Entity_Player::FireTear 00790af0 (Stye)");
if (intensity > 0) tear->SetDeadEyeIntensity(intensity);
tear->mass *= params.massMultiplier;
tear->knockbackMultiplier = params.knockbackMultiplier;
tear->tearIdx = firedTearCount++;
tear->Update();
tear->pos = vector_make(tear->pos.x - tear->velocity.x, tear->pos.y - tear->velocity.y);
lua_engine_get().PostFireTear(tear);
if (HasCollectible(COLLECTIBLE_EVIL_EYE) && !(fireFlags & TEAR_FIRE_NO_EVIL_EYE))
reconstruction_missing("Entity_Player::FireTear 00790af0 (Evil Eye)");
return tear;
}
// 0075af10 Where a null sits on the player, under its head's facing for a direction (its costumes' null overriding
// the body's), else on its current animations: scaled by the sprite, and by the head's size about the head's pivot.
Vector Entity_Player::GetCostumeNullPos(std::string_view nullName, bool isHeadScale, const Vector& direction)
{
const NullFrame* frame = nullptr;
bool isCostumed = variant == PLAYER_VARIANT_PLAYER && !isCoopGhost;
if (direction.x != 0 || direction.y != 0)
{
std::string headAnimation = std::abs(direction.x) <= std::abs(direction.y) ? (direction.y >= 0 ? "HeadDown" : "HeadUp")
: (direction.x >= 0 ? "HeadRight" : "HeadLeft");
frame = sprite.GetNullFrame(headAnimation, nullName, 1);
if (!frame && sprite.overlayAnimState.animData) frame = sprite.GetNullFrame(headAnimation + "_Overlay", nullName, 1);
if (isCostumed)
for (PlayerCostumeMap& costume : playerCostumeMap)
if (costume.index >= 0)
if (const NullFrame* worn = costumeSpriteDescs[(size_t)costume.index].sprite.GetNullFrame(headAnimation, nullName, 1))
frame = worn;
}
if (!frame)
{
frame = sprite.animState.animData ? sprite.animState.GetNullFrame(nullName) : nullptr;
if (!frame && sprite.overlayAnimState.animData) frame = sprite.overlayAnimState.GetNullFrame(nullName);
if (isCostumed)
for (PlayerCostumeMap& costume : playerCostumeMap)
{
if (costume.index < 0) continue;
AnimationState& worn = costumeSpriteDescs[(size_t)costume.index].sprite.animState;
if (const NullFrame* found = worn.animData ? worn.GetNullFrame(nullName) : nullptr) frame = found;
}
if (!frame) return {};
}
Vector position = vector_make(sprite.scale.x * frame->pos.x, sprite.scale.y * frame->pos.y);
if (!isHeadScale) return position;
Vector pivot = vector_make(0, sprite.scale.y * HEAD_PIVOT_LIFT);
position = vector_make(position.x - pivot.x, position.y - pivot.y);
if (isCostumed)
{
LayerState* head = sprite.GetLayer(PLAYER_HEAD_LAYER);
position = vector_make(position.x * head->size.x, position.y * head->size.y);
}
return vector_add(position, pivot);
}
// 007aa850 Where a laser of an offset leaves the player: the null of its eye, forehead, mouth, Mom's Eye (facing back)
// or Tractor Beam, in world units, lifted while it flies. C Section's lasers leave above it instead.
Vector Entity_Player::GetLaserOffset(int laserOffsetId, const Vector& shootDirection)
{
if (laserOffsetId == LASER_OFFSET_NONE) return {};
if (laserOffsetId == LASER_OFFSET_BRIMSTONE && HasCollectible(COLLECTIBLE_C_SECTION))
return vector_make(0, sprite.scale.y * C_SECTION_LASER_LIFT);
Vector offset{};
if (laserOffsetId >= LASER_OFFSET_TECH1 && laserOffsetId <= LASER_OFFSET_TRACTOR_BEAM)
{
Vector facing = shootDirection;
if (laserOffsetId == LASER_OFFSET_MOMS_EYE) facing = vector_make(-shootDirection.x, -shootDirection.y);
if (laserOffsetId == LASER_OFFSET_SHOOP || laserOffsetId == LASER_OFFSET_BRIMSTONE ||
laserOffsetId == LASER_OFFSET_TRACTOR_BEAM)
facing = Vector{};
offset = vector_scale(GetCostumeNullPos(NULL_OFFSET_NAMES[laserOffsetId], true, facing), 1 / LASER_SCREEN_SCALE);
}
if (canFly) offset = vector_add(offset, vector_scale(GetFlyingOffset(), 1 / LASER_SCREEN_SCALE));
return offset;
}
// 007aab70 Fires a Technology laser from the player: from an eye's offset along a direction, lasting three frames,
// in the player's laser color with its laser hit params (Technology 2's with the player's damage, one of Tech.5's in
// twenty with a random flag of its own), drawn behind the head when it fires up or away from the eye.
Entity_Laser* Entity_Player::FireTechLaser(const TechLaserShot& shot)
{
Vector offset = GetLaserOffset(shot.offsetId, shot.direction);
Entity_Laser* laser = Entity_Laser::ShootAngle({.position = vector_make(shot.position.x + offset.x, shot.position.y),
.posOffset = vector_make(0, offset.y),
.source = shot.source ? shot.source : this,
.angleDegrees = std::atan2(shot.direction.y, shot.direction.x) * DEGREES_PER_RADIAN,
.timeout = TECH_LASER_TIMEOUT,
.variant = LASER_THIN_RED});
laser->parentOffset = vector_make(offset.x, 0);
laser->isOneHit = shot.isOneHit;
laser->isDisableFollowParent = true;
laser->pos = vector_add(vector_add(tearsOffset, shot.position), vector_make(offset.x, 0));
TearFlags flags = tearFlags;
if (shot.offsetId == LASER_OFFSET_TECH5 && Random() % TECH5_FLAG_ROLL < TECH5_FLAG_CHANCE)
{
flags.reset();
flags.set(Random() % TECH5_FLAG_COUNT);
}
laser->tearFlags = flags;
laser->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
if (shot.offsetId == LASER_OFFSET_TECH2) laser->SetCollisionDamage(damage);
else
{
int displacement = (int)(Random() & 1) * 2 - 1;
TearParams params = GetTearHitParams(WEAPON_LASER, shot.damageScale, displacement, nullptr);
laser->SetCollisionDamage(params.tearDamage);
laser->tearFlags |= params.tearFlags;
laser->damageMultiplier = shot.damageScale;
laser->set_scale(params.tearScale);
laser->mass *= params.massMultiplier;
}
laser->entityGridCollisionClass = GRIDCOLL_NOPITS;
const Vector& aim = shot.direction;
bool isBehind = shot.isLeftEye ? (aim.y < -TECH_LASER_FACING || aim.x > TECH_LASER_FACING)
: (aim.y <= -TECH_LASER_FACING || aim.x <= -TECH_LASER_FACING);
laser->renderDepthOffset = isBehind ? TECH_LASER_BACK_DEPTH : TECH_LASER_FRONT_DEPTH;
laser->isPlayerParams = true;
return laser;
}
// 007cb230 Fires a Tech X ring from the player (Lua's FireTechXLaser): thick red with Brimstone or as Azazel (half
// as thick for Tainted Azazel without Brimstone), doubled by a second Brimstone and thicker past one and a half, red
// and blue with Technology. It takes the player's laser color and hit params.
Entity_Laser* Entity_Player::FireTechXLaser(const TechXShot& shot)
{
Entity* spawner = shot.source ? shot.source : this;
float scale = std::sqrt(shot.damageMultiplier);
if (spawner->type == ENTITY_FAMILIAR) scale *= 0.5f;
int variant = LASER_THIN_RED;
bool isBrimstone = HasCollectible(COLLECTIBLE_BRIMSTONE);
if (isBrimstone || playerType == PLAYER_AZAZEL) variant = LASER_THICK_RED;
if (playerType == PLAYER_AZAZEL_B && !isBrimstone)
{
scale *= 0.5f;
variant = LASER_THICK_RED;
}
if (GetCollectibleNum(COLLECTIBLE_BRIMSTONE) > 1) scale += scale;
if (scale > TECH_X_THICKER_SCALE && variant == LASER_THICK_RED)
{
scale *= 0.5f;
variant = LASER_THICKER_RED;
}
if (HasCollectible(COLLECTIBLE_TECHNOLOGY))
variant = variant == LASER_THICKER_RED ? LASER_THICKER_BRIM_TECH : LASER_BRIM_TECH;
Entity_Laser* laser = static_cast<Entity_Laser*>(g_game->Spawn({.position = shot.position,
.velocity = shot.velocity,
.spawner = spawner,
.subType = LASER_SUBTYPE_RING_PROJECTILE,
.type = ENTITY_LASER,
.variant = variant,
.seed = Random()}));
int displacement = (int)(Random() & 1) * 2 - 1;
TearParams params = GetTearHitParams(WEAPON_LASER, 1, displacement, spawner);
laser->posOffset = vector_make(0, TECH_X_RING_LIFT);
laser->parent = spawner;
laser->renderDepthOffset = TECH_LASER_FRONT_DEPTH;
laser->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
laser->tearFlags = params.tearFlags;
laser->SetCollisionDamage(params.tearDamage);
laser->scale = scale;
laser->ResetSpriteScale();
laser->radius = shot.radius;
laser->spawnerEntity = spawner;
laser->isPlayerParams = true;
laser->mass *= params.massMultiplier;
laser->damageMultiplier = shot.damageMultiplier;
return laser;
}
// 007aded0 Fires a knife from the player (Lua's FireKnife): it hangs from its parent at its angle, with the player's
// tear color, tear flags and damage.
Entity_Knife* Entity_Player::FireKnife(const KnifeShot& shot)
{
Entity* knife = g_game->Spawn({.position = pos,
.spawner = this,
.subType = shot.subType,
.type = ENTITY_KNIFE,
.variant = shot.variant,
.seed = Random()});
knife->parent = shot.parent;
knife->posOffset = vector_make(0, KNIFE_LIFT);
knife->SetColor(tearColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
static_cast<Entity_Knife*>(knife)->tearFlags = tearFlags;
knife->SetCollisionDamage(damage);
static_cast<Entity_Knife*>(knife)->rotationOffset = angle_wrap(shot.rotationOffset);
if (shot.isCantOverwrite) knife->AddEntityFlags(FLAG_DONT_OVERWRITE);
return static_cast<Entity_Knife*>(knife);
}
// 007a0f50 Fires a Brimstone beam from the player in its laser color (Lua's FireBrimstone).
Entity_Laser* Entity_Player::FireBrimstone(const Vector& direction, Entity*, float damageMultiplier)
{
Entity_Laser* laser = Weapon::FireBrimstone({.direction = direction, .position = pos, .entity = this,
.damageMultiplier = damageMultiplier});
laser->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
return laser;
}
// 00665c20 The player's laser color.
ColorMod Entity_Player::get_laser_color_copy()
{
return laserColor;
}