311 lines
11 KiB
C++
311 lines
11 KiB
C++
#include "entity_effect.h"
|
|
#include "entity_effect_ambient.h"
|
|
#include "entity_effect_combat.h"
|
|
#include "entity_list.h"
|
|
#include "game.h"
|
|
#include "log.h"
|
|
#include "lua_engine.h"
|
|
#include "manager.h"
|
|
#include "room.h"
|
|
#include "sfx_manager.h"
|
|
#include <algorithm>
|
|
#include <array>
|
|
|
|
// The creep variants the players leave (holy water trail, black, red, white, holy water, green, Lemon Mishap, Lemon
|
|
// Party, 204, Black Powder, milk, Black Powder's pentagram).
|
|
constexpr std::array<int, 12> PLAYER_CREEPS = {54, 45, 46, 44, 37, 53, 32, 78, 204, 92, 90, 93};
|
|
|
|
// The floor stains a crawlspace never shows: blood, craters, creep of every kind, footprints and puddles.
|
|
constexpr std::array<int, 26> CRAWLSPACE_HIDDEN_EFFECTS = {7, 18, 22, 23, 24, 25, 26, 32, 37, 44, 45, 46, 53,
|
|
54, 56, 77, 78, 89, 90, 92, 93, 94, 100, 169, 195, 204};
|
|
|
|
// The creep a familiar's wave of creep (familiar variant 125) leaves, which keeps its chain going.
|
|
constexpr std::array<int, 6> WAVE_CHAIN_CREEPS = {53, 44, 46, 45, 32, 204};
|
|
constexpr int FAMILIAR_CREEP_WAVE = 125;
|
|
|
|
constexpr int EFFECT_BLOOD_PARTICLE = 5;
|
|
constexpr int EFFECT_HUSH_LASER = 96;
|
|
constexpr int EFFECT_HUSH_LASER_UP = 101;
|
|
constexpr int EFFECT_BLACK_POWDER = 92;
|
|
constexpr int EFFECT_BOOMERANG = 60;
|
|
constexpr int EFFECT_PORTAL_TELEPORT = 161;
|
|
constexpr int EFFECT_TIMER = 119;
|
|
constexpr int EFFECT_ENEMY_SOUL = 179;
|
|
constexpr int EFFECT_ANIMA_CHAIN = 193;
|
|
constexpr int EFFECT_REDEMPTION = 185;
|
|
constexpr int EFFECT_LIGHT = 121;
|
|
|
|
// The Hourglass slows Hush's lasers from full speed to half as its effect's cooldown runs from 0 to 30.
|
|
constexpr int COLLECTIBLE_HOURGLASS = 66;
|
|
constexpr float HOURGLASS_COOLDOWN_SPAN = 30;
|
|
constexpr float HOURGLASS_SLOWEST = 0.5f;
|
|
|
|
constexpr float PAUSE_VELOCITY_DECAY = 0.6f;
|
|
constexpr int SOUND_BOOMERANG_LOOP = 837;
|
|
constexpr int SOUND_PORTAL_ENTITY_LOOP = 846;
|
|
constexpr int SOUND_CHAIN_LOOP = 503;
|
|
|
|
template <size_t N>
|
|
static bool is_listed(const std::array<int, N>& list, int value)
|
|
{
|
|
return std::find(list.begin(), list.end(), value) != list.end();
|
|
}
|
|
|
|
// 0060c400 Only a boss spawn pentagram holds the doors shut.
|
|
bool Entity_Effect::CanShutDoors()
|
|
{
|
|
return variant == EFFECT_SPAWN_PENTAGRAM;
|
|
}
|
|
|
|
// 005ccc20 Collides with nothing it reacts to, letting the collision through.
|
|
bool Entity_Effect::HandleCollision(Entity*, bool)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// 00435e90 Sets how long it lasts, from now.
|
|
void Entity_Effect::SetTimeout(int frames)
|
|
{
|
|
timeout = frames;
|
|
lifespan = frames;
|
|
}
|
|
|
|
// 00435ef0 Sets the radius it grows between.
|
|
void Entity_Effect::SetRadii(float newMinRadius, float newMaxRadius)
|
|
{
|
|
minRadius = newMinRadius;
|
|
maxRadius = newMaxRadius;
|
|
}
|
|
|
|
// 005cd950 Whether two indices differ, the filter of the rift's pull.
|
|
bool Entity_Effect::rift_attract_filter(int first, int second)
|
|
{
|
|
return first != second;
|
|
}
|
|
|
|
// 0060ac20 Whether the variant is creep or fire the players leave, which hurts only enemies.
|
|
bool Entity_Effect::IsPlayerCreep(int effectVariant)
|
|
{
|
|
return std::find(PLAYER_CREEPS.begin(), PLAYER_CREEPS.end(), effectVariant) != PLAYER_CREEPS.end();
|
|
}
|
|
|
|
// 005cdb20 Starts the effect from its config's sprite with no timeout, rotation or extra data, then hands it to its
|
|
// variant. A crawlspace removes its floor stains at once, and a variant that removes itself skips its graphics and
|
|
// Lua's callback.
|
|
void Entity_Effect::Init(int entityType, int entityVariant, int entitySubType, uint32_t seed)
|
|
{
|
|
extraData.reset();
|
|
Entity::Init(entityType, entityVariant, entitySubType, seed);
|
|
hitList.clear();
|
|
maxHitPoints = 0;
|
|
if (config)
|
|
{
|
|
sprite.Load(config->anm2Path, GRAPHICS_DEFER);
|
|
sprite.Play(sprite.GetDefaultAnimationName());
|
|
}
|
|
|
|
state = 0;
|
|
timeout = -1;
|
|
lifespan = 1;
|
|
parentOffset = {};
|
|
rotation = 0;
|
|
isFollowing = false;
|
|
scale = 1;
|
|
minRadius = 0;
|
|
maxRadius = 0;
|
|
damageSource = 0;
|
|
varData = {};
|
|
if (g_game->room->roomType == ROOM_DUNGEON && is_listed(CRAWLSPACE_HIDDEN_EFFECTS, variant))
|
|
{
|
|
isVisible = false;
|
|
return Remove();
|
|
}
|
|
|
|
entityGridCollisionClass = variant == EFFECT_BLOOD_PARTICLE ? GRIDCOLL_WALLS : GRIDCOLL_NONE;
|
|
entityCollisionClass = ENTCOLL_NONE;
|
|
if (is_ambient_effect(variant)) ambient_effect_init(*this);
|
|
else if (is_combat_effect(variant)) combat_effect_init(*this);
|
|
else reconstruction_missing("Entity_Effect::Init 005cdb20: this effect variant");
|
|
if (!isExists) return;
|
|
|
|
sprite.LoadGraphics();
|
|
if (g_game->deathmatchManager.is_active())
|
|
reconstruction_missing("Entity_Effect::Init 005cdb20: the versus mode's entity registration");
|
|
lua_engine_get().PostEffectInit(this);
|
|
}
|
|
|
|
// 005d4380 Runs the effect for a frame at the room's time scale, held in place while paused and kept on its parent
|
|
// while following it, then runs its variant and counts its timeout down to its death.
|
|
void Entity_Effect::Update()
|
|
{
|
|
speedMultiplier = g_game->room->GetTimeScale(this);
|
|
if (variant == EFFECT_HUSH_LASER || variant == EFFECT_HUSH_LASER_UP)
|
|
{
|
|
if (TemporaryEffect* hourglass = g_game->room->temporaryEffects.GetCollectibleEffect(COLLECTIBLE_HOURGLASS))
|
|
{
|
|
float t = std::clamp((float)hourglass->cooldown / HOURGLASS_COOLDOWN_SPAN, 0.0f, 1.0f);
|
|
speedMultiplier *= (HOURGLASS_SLOWEST - 1) * t + 1;
|
|
}
|
|
}
|
|
if (variant == EFFECT_BLACK_POWDER) pauseTimer = 0;
|
|
if (pauseTimer != 0)
|
|
{
|
|
uint64_t savedFlags = flags;
|
|
bool wasDead = isDead;
|
|
|
|
if (pausePosition.x == 0 && pausePosition.y == 0) pausePosition = pos;
|
|
if (pauseTimer > 0) pauseTimer--;
|
|
pos = pausePosition;
|
|
velocity = vector_make(velocity.x * PAUSE_VELOCITY_DECAY, velocity.y * PAUSE_VELOCITY_DECAY);
|
|
AddEntityFlags(FLAG_NO_SPRITE_UPDATE);
|
|
Entity::Update();
|
|
flags = savedFlags;
|
|
if (wasDead == isDead) return;
|
|
}
|
|
|
|
Entity::Update();
|
|
if (isFollowing && parent)
|
|
{
|
|
pos = vector_make(parent->pos.x + parentOffset.x, parent->pos.y + parentOffset.y);
|
|
velocity = parent->velocity;
|
|
posOffset = parent->posOffset;
|
|
}
|
|
else if (isFollowing)
|
|
{
|
|
velocity = {};
|
|
isFollowing = false;
|
|
if (variant == EFFECT_LIGHT && timeout < 0) SetTimeout(state);
|
|
}
|
|
|
|
EffectUpdateEnd end = EFFECT_UPDATE_FINISH;
|
|
if (is_ambient_effect(variant)) end = ambient_effect_update(*this);
|
|
else if (is_combat_effect(variant)) end = combat_effect_update(*this);
|
|
else reconstruction_missing("Entity_Effect::Update 005d4380: this effect variant");
|
|
if (end == EFFECT_UPDATE_RETURN) return;
|
|
|
|
if (timeout > 0 && --timeout < 1) isDead = true;
|
|
pausePosition = pos;
|
|
if (spawnerType == ENTITY_FAMILIAR && spawnerVariant == FAMILIAR_CREEP_WAVE && is_listed(WAVE_CHAIN_CREEPS, variant))
|
|
update_wave_chain();
|
|
lua_engine_get().PostEffectUpdate(this);
|
|
}
|
|
|
|
// 005d2520 Moves the effect half a step between updates, keeping a following effect on its parent.
|
|
void Entity_Effect::Interpolate()
|
|
{
|
|
if (pauseTimer != 0) return;
|
|
|
|
Entity::Interpolate();
|
|
if (!isFollowing || !parent) return;
|
|
pos = vector_make(parent->pos.x + parentOffset.x, parent->pos.y + parentOffset.y);
|
|
posOffset = parent->posOffset;
|
|
}
|
|
|
|
// 00607620 Draws the effect at its place on screen through its variant, or its sprite. A light only lights the room.
|
|
void Entity_Effect::Render(const Vector& offset)
|
|
{
|
|
if (variant == EFFECT_LIGHT || !isVisible) return;
|
|
|
|
Vector screen = render_position_get(vector_make(pos.x + posOffset.x, pos.y + posOffset.y), RENDER_SNAPPED);
|
|
renderPosition = vector_make(screen.x + offset.x, screen.y + offset.y);
|
|
if (is_ambient_effect(variant)) ambient_effect_render(*this, offset);
|
|
else sprite.Render(SpriteDraw{renderPosition, {}, {}});
|
|
lua_engine_get().PostEffectRender(this, offset);
|
|
}
|
|
|
|
// 005d2420 Stops the boomerang and portal loops unless another such effect still plays them, then removes it.
|
|
void Entity_Effect::Remove()
|
|
{
|
|
bool isBoomerangShared = false;
|
|
bool isPortalShared = false;
|
|
|
|
for (Entity* entity : g_game->room->entityList.updateEL)
|
|
{
|
|
if (entity->type != ENTITY_EFFECT || entity == this) continue;
|
|
if (entity->variant == EFFECT_BOOMERANG) isBoomerangShared = true;
|
|
else if (entity->variant == EFFECT_PORTAL_TELEPORT) isPortalShared = true;
|
|
}
|
|
if (!isBoomerangShared) g_manager->sfxManager.Stop(SOUND_BOOMERANG_LOOP);
|
|
if (!isPortalShared) g_manager->sfxManager.Stop(SOUND_PORTAL_ENTITY_LOOP);
|
|
Entity::Remove();
|
|
}
|
|
|
|
// 0060c370 Glowing Hourglass removes a timer, and sets Redemption back to idle.
|
|
void Entity_Effect::TriggerGlowingHourglass()
|
|
{
|
|
if (variant == EFFECT_REDEMPTION)
|
|
reconstruction_missing("Entity_Effect::TriggerGlowingHourglass 0060c370: Redemption's idle restart");
|
|
if (variant == EFFECT_TIMER) Remove();
|
|
}
|
|
|
|
// 0060abb0 Gives an enemy soul to the player it flew to and stops a hidden Anima chain's sound, then lets go of its
|
|
// links and extra data.
|
|
void Entity_Effect::ClearReferences()
|
|
{
|
|
if (variant == EFFECT_ENEMY_SOUL && target && target->type == ENTITY_PLAYER)
|
|
reconstruction_missing("Entity_Effect::ClearReferences 0060abb0: the Urn of Souls' soul");
|
|
if (variant == EFFECT_ANIMA_CHAIN && subtype == 0 && !isVisible) g_manager->sfxManager.Stop(SOUND_CHAIN_LOOP);
|
|
Entity::ClearReferences();
|
|
extraData.reset();
|
|
}
|
|
|
|
// 004564b0 Follows an entity, keeping the offset it has from it now.
|
|
// The original reads a null entity's position and crashes. This only lets go of the parent.
|
|
void Entity_Effect::FollowParent(Entity* newParent)
|
|
{
|
|
parent = newParent;
|
|
if (!newParent) return;
|
|
isFollowing = true;
|
|
parentOffset = vector_make(pos.x - newParent->pos.x, pos.y - newParent->pos.y);
|
|
}
|
|
|
|
// The rest of Entity_Effect is not reconstructed yet.
|
|
|
|
// 00435290
|
|
void Entity_Effect::render_player_target(const Vector&, int)
|
|
{
|
|
reconstruction_missing("Entity_Effect::render_player_target 00435290");
|
|
}
|
|
|
|
// 005d2a70
|
|
void Entity_Effect::update_mr_me()
|
|
{
|
|
reconstruction_missing("Entity_Effect::update_mr_me 005d2a70");
|
|
}
|
|
|
|
// 005d4010
|
|
void Entity_Effect::update_wave_chain()
|
|
{
|
|
reconstruction_missing("Entity_Effect::update_wave_chain 005d4010");
|
|
}
|
|
|
|
// 006073f0
|
|
void Entity_Effect::moonlight_timer_callback(int)
|
|
{
|
|
reconstruction_missing("Entity_Effect::moonlight_timer_callback 006073f0");
|
|
}
|
|
|
|
// 0060af00
|
|
Entity_Effect* Entity_Effect::CreateTimer(void*, uint32_t, uint32_t, bool)
|
|
{
|
|
reconstruction_missing("Entity_Effect::CreateTimer 0060af00");
|
|
}
|
|
|
|
// 0060b0d0
|
|
void Entity_Effect::update_variant178_shooter(bool)
|
|
{
|
|
reconstruction_missing("Entity_Effect::update_variant178_shooter 0060b0d0");
|
|
}
|
|
|
|
// 0060b7a0
|
|
Entity_Effect* Entity_Effect::CreateLootPreview(void*, const Vector&, Entity*, Entity_Effect*)
|
|
{
|
|
reconstruction_missing("Entity_Effect::CreateLootPreview 0060b7a0");
|
|
}
|
|
|
|
// 0060bae0
|
|
void Entity_Effect::setup_loot_preview(void*)
|
|
{
|
|
reconstruction_missing("Entity_Effect::setup_loot_preview 0060bae0");
|
|
}
|