Files
isaac-port/src/entity_knife.h
T

151 lines
5.0 KiB
C++

#pragma once
#include "entity.h"
#include "homing_laser.h"
#include <vector>
// The distances a knife has no use for yet: where it splits off its parent and where it shows up.
constexpr float KNIFE_DISTANCE_NONE = -1;
// A swung sword marked to throw its beam this swing.
constexpr uint64_t FLAG_SWORD_BEAM = FLAG_SPAWN_STICKY_SPIDERS;
// The knives (Lua's KnifeVariant): Mom's Knife, the Forgotten's swung weapons, Bloody Babylon's and the swords.
enum KnifeVariant : int
{
KNIFE_MOMS_KNIFE,
KNIFE_BONE_CLUB,
KNIFE_BONE_SCYTHE,
KNIFE_DONKEY_JAWBONE,
KNIFE_BAG_OF_CRAFTING,
KNIFE_SUMPTORIUM,
KNIFE_BERSERK_CLUB = 8,
KNIFE_NOTCHED_AXE = 9,
KNIFE_SPIRIT_SWORD = 10,
KNIFE_TECH_SWORD = 11
};
// What a knife is by subtype: held or thrown, following a homing path, chained to its parent, or swung as an item.
enum KnifeSubType : int
{
KNIFE_SUBTYPE_HELD,
KNIFE_SUBTYPE_PATH,
KNIFE_SUBTYPE_CHAINED = 3,
KNIFE_SUBTYPE_HELD_ITEM = 4
};
// Where apply_hit_effects lands its effects: the knife's point, the target and its size, the damage and its flags, and
// whether the knife hit while thrown.
struct KnifeHit
{
Vector position{};
Vector targetPosition{};
Entity* target = nullptr;
uint64_t damageFlags = 0;
float damage = 0;
float targetSize = 0;
bool isFlying = false;
};
// Construction and destruction (00960b50, 00960a70) are the defaults.
// Field accessors (004d7790, 004d77a0, 0060cf10, 0060cfb0, 0085de90, 0085deb0, 0085dec0) are the public fields.
// A knife (Lua's EntityKnife): Mom's Knife and the swung weapons (bones, clubs, swords), with the tear effects they
// carry, their charge and flight, and the path a homing knife follows. A knife split off its parent (Cricket's Body,
// Angelic Prism) follows it out to splitDistance, then turns off by splitAngle and splitOffset.
struct Entity_Knife : Entity
{
HomingLaser homingLaser;
std::vector<uint32_t> hitList;
TearFlags tearFlags;
TearFlags usedTearFlags;
EntityPtr brimstoneLaser;
EntityPtr linkedKnife;
EntityPtr spinEffect;
EntityPtr techLaser;
Vector anchorPosition{};
Vector initPosition{};
Vector splitOffset{};
float basePosOffsetY = 0;
float charge = 0;
float displayRotation = 0;
float fallingSpeed = 0;
float flightAngle = 0;
float height = 0;
float knifeDepthOffset = 0;
float knifeDistance = 0;
float knifeVelocity = 0;
float maxDistance = 0;
float pathFollowSpeed = 0;
float pathOffset = 0;
float pathProgress = 0;
float rotation = 0;
float rotationOffset = 0;
float scale = 0;
float showDistance = KNIFE_DISTANCE_NONE;
float splitAngle = 0;
float splitDistance = KNIFE_DISTANCE_NONE;
int pathSegment = 0;
short spinsLeft = 0;
short swingEffects = 0;
short swingTick = 0;
bool isAttacking = false;
bool isDeadEyeHit = false;
bool isFlying = false;
bool isMultidimensionalApplied = false;
bool isPrimaryClub = false;
bool isPrismApplied = false;
bool isRecoiled = false;
bool isSpinAttack = false;
bool isSwingCharged = false;
bool isSwinging = false;
bool isUsingParentHitList = false;
void Init(int type, int variant, int subType, uint32_t initSeed) override;
void Update() override;
void Interpolate() override;
void Render(const Vector& offset) override;
int GetRenderZ() override;
void ClearReferences() override;
bool HandleCollision(Entity* collider, bool isLow) override;
int GetBaseVariant();
std::vector<uint32_t>& GetHitEntities();
void InitHomingPath(Vector direction, Entity* source, float offset);
void copy_parent_state(Entity_Knife& source);
bool spawn_child_knife();
Entity_Player* GetPlayer();
Entity_Knife* GetRootParent();
void Shoot(float charge, float range);
void UpdateHomingPath();
void update_target(float& angle);
void apply_wiggle(float& angle);
void screen_wrap();
void Reset();
void SetAttackAnimation();
void SpinAttack(short remainingSpins, int startFrame);
bool drain_notched_axe(int charge);
void UpdateSwingHits();
void apply_hit_effects(const KnifeHit& hit);
private:
bool held_update(Entity_Player* player);
void ludovico_update();
void path_update();
void chained_update();
void held_item_update();
void hydrobounce_land();
void hydrobounce_update();
void lasers_update(Entity_Player* player);
void grid_hit_update(Entity_Player* player);
void sword_beam_fire(Entity_Player* player);
void brimstone_knife_spawn(Entity_Player* player);
void render_orbit_trail(const Vector& offset);
};
bool is_swung_knife_variant(int variant);
float bezier_closest_point(const Vector& point, const BezierPoint& start, const BezierPoint& end, float& outT);
Vector room_screen_wrap(const Vector& position, float margin);
void tear_flags_area_apply(const Vector& position, Entity* source, float radius, float damage,
const TearFlags& flags);
extern Entity_Player* g_notchedAxePlayer;