Curation round 13: grid entities, more enemies, Caves, boss helpers and five bosses, chests and costumes, curses and alt stages, the Lua API
This commit is contained in:
1 parent
f8ce24fc6c
commit
8ae02a8422
160 files changed
+16231
-1689
No files matched your search
@@ -0,0 +1,574 @@
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "item_pool.h"
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "npc_ai.h"
|
||||
#include "room.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
// The shift index of the RNG every outcome draw seeds (5, 9, 7), and the one a loot's spot angle comes from.
|
||||
constexpr int OUTCOME_SHIFT_INDEX = 35;
|
||||
constexpr int LOOT_ANGLE_SHIFT_INDEX = 18;
|
||||
constexpr int LOOT_DROP_SHIFT_INDEX = 12;
|
||||
constexpr float LOOT_ANGLE_SCALE = 3.14f;
|
||||
|
||||
// The chests a player opens by touch, a key for the locked ones, and their pedestals for the items they give.
|
||||
constexpr std::array<int, 3> LOCKED_CHESTS = {PICKUP_LOCKEDCHEST, PICKUP_ETERNALCHEST, PICKUP_OLDCHEST};
|
||||
constexpr std::array<int, 4> GOLDEN_CHESTS = {PICKUP_LOCKEDCHEST, PICKUP_BOMBCHEST, PICKUP_ETERNALCHEST,
|
||||
PICKUP_MEGACHEST};
|
||||
constexpr std::array<int, 4> UNWRITTEN_LOOT = {PICKUP_REDCHEST, PICKUP_MOMSCHEST, PICKUP_OLDCHEST, PICKUP_GRAB_BAG};
|
||||
constexpr int EVENT_LOCKED_CHESTS_OPENED = 198;
|
||||
constexpr float CHEST_VANISH_VOLUME = 0.7f;
|
||||
constexpr float SPIKED_CHEST_DAMAGE = 1;
|
||||
constexpr int SPIKED_CHEST_DAMAGE_COOLDOWN = 30;
|
||||
constexpr int CHEST_WAIT = 20;
|
||||
constexpr int ETERNAL_CHEST_RECLOSE = 60;
|
||||
constexpr float CHEST_PUSH_RADIUS = 40;
|
||||
constexpr float CHEST_PUSH_STRENGTH = 0.4f;
|
||||
constexpr float ENEMY_LOOT_DISTANCE = 20;
|
||||
constexpr float CHEST_POOF_HEIGHT = -10;
|
||||
constexpr float CHEST_POOF_SCALE = 0.8f;
|
||||
constexpr float CHEST_POOF_ALPHA = 0.3f;
|
||||
constexpr float CHEST_POOF_DEPTH = 4;
|
||||
constexpr float MEGA_CHEST_SPEED_BASE = 0.4f;
|
||||
constexpr float MEGA_CHEST_SPEED_STEP = 0.05f;
|
||||
constexpr int PICKUP_COUNT_MIN = 2;
|
||||
constexpr int PICKUP_COUNT_ROLL = 4;
|
||||
constexpr int GOLDEN_PICKUP_COUNT_ROLL = 7;
|
||||
constexpr int CHEST_COINS_ROLL = 3;
|
||||
constexpr int MEGA_CHEST_DRAWS = 5;
|
||||
constexpr size_t WOODEN_CHEST_TRINKETS = 2;
|
||||
constexpr int CHEST_TRINKET_ODDS = 100;
|
||||
constexpr int LUCKY_TOE_ODDS = 3;
|
||||
|
||||
// The pickups a chest's own draw gives (the outcome ids of GetChestLoot's first draw).
|
||||
enum ChestOutcome
|
||||
{
|
||||
CHEST_OUTCOME_TRINKET,
|
||||
CHEST_OUTCOME_CHEST,
|
||||
CHEST_OUTCOME_LOCKED_CHEST,
|
||||
CHEST_OUTCOME_PICKUPS,
|
||||
CHEST_OUTCOME_PILL,
|
||||
CHEST_OUTCOME_CARD,
|
||||
CHEST_OUTCOME_ITEM,
|
||||
CHEST_OUTCOME_GILDED_PICKUPS
|
||||
};
|
||||
|
||||
// The pickups a chest's pickups draw gives (the outcome ids of its second draw). Gilded Key adds the rarer ones.
|
||||
enum ChestPickup
|
||||
{
|
||||
CHEST_PICKUP_COINS,
|
||||
CHEST_PICKUP_HEART,
|
||||
CHEST_PICKUP_KEY,
|
||||
CHEST_PICKUP_BOMB,
|
||||
CHEST_PICKUP_PILL,
|
||||
CHEST_PICKUP_CARD,
|
||||
CHEST_PICKUP_RUNE,
|
||||
CHEST_PICKUP_TRINKET,
|
||||
CHEST_PICKUP_BATTERY
|
||||
};
|
||||
|
||||
// What a wooden chest gives: an item, cards or pills.
|
||||
enum WoodenChestOutcome
|
||||
{
|
||||
WOODEN_OUTCOME_ITEM,
|
||||
WOODEN_OUTCOME_CARDS,
|
||||
WOODEN_OUTCOME_PILLS
|
||||
};
|
||||
|
||||
// A trinket that may add a pickup to a chest: the pickup, and the shift index of the RNG it draws from.
|
||||
struct ChestTrinket
|
||||
{
|
||||
int trinket = 0;
|
||||
int variant = 0;
|
||||
int shiftIndex = 0;
|
||||
};
|
||||
|
||||
// The bonus trinkets in the order they roll, then the order their pickups take precedence in.
|
||||
constexpr std::array<ChestTrinket, 5> CHEST_TRINKETS = {{{TRINKET_ACE_OF_SPADES, PICKUP_TAROTCARD, 2},
|
||||
{TRINKET_SAFETY_CAP, PICKUP_PILL, 3},
|
||||
{TRINKET_CHILDS_HEART, PICKUP_HEART, 5},
|
||||
{TRINKET_MATCH_STICK, PICKUP_BOMB, 4},
|
||||
{TRINKET_RUSTED_KEY, PICKUP_KEY, 6}}};
|
||||
constexpr std::array<int, 5> CHEST_TRINKET_PRECEDENCE = {0, 1, 3, 2, 4};
|
||||
|
||||
// The odds out of a hundred that one, two or three copies of a bonus trinket add their pickup.
|
||||
constexpr std::array<int, 3> CHEST_TRINKET_CHANCES = {33, 66, 100};
|
||||
|
||||
// The pedestal an item from each chest stands on, with its pay to play look, by chest variant.
|
||||
struct ChestPedestal
|
||||
{
|
||||
int variant = 0;
|
||||
int pedestal = 0;
|
||||
int payPedestal = 0;
|
||||
};
|
||||
constexpr std::array<ChestPedestal, 11> CHEST_PEDESTALS = {{{PICKUP_CHEST, 10, 10},
|
||||
{PICKUP_BOMBCHEST, 6, 6},
|
||||
{PICKUP_SPIKEDCHEST, 7, 7},
|
||||
{PICKUP_ETERNALCHEST, 8, 17},
|
||||
{PICKUP_MIMICCHEST, 7, 7},
|
||||
{PICKUP_OLDCHEST, 12, 18},
|
||||
{PICKUP_WOODENCHEST, 13, 13},
|
||||
{PICKUP_MEGACHEST, 14, 19},
|
||||
{PICKUP_LOCKEDCHEST, 4, 16},
|
||||
{PICKUP_REDCHEST, 5, 5},
|
||||
{PICKUP_MOMSCHEST, 11, 11}}};
|
||||
|
||||
// The draws GetChestLoot makes: the chest's RNG (or a copy that leaves it be), how items leave their pool, and the
|
||||
// bonus trinkets' RNGs and whether each added its pickup.
|
||||
struct ChestDraw
|
||||
{
|
||||
std::array<RNG, CHEST_TRINKETS.size()> trinketRngs{};
|
||||
std::array<bool, CHEST_TRINKETS.size()> isTrinketProc{};
|
||||
LootList loot;
|
||||
RNG* rng = nullptr;
|
||||
uint32_t poolFlags = 0;
|
||||
bool isDaemonsTail = false;
|
||||
};
|
||||
|
||||
// Adds weight to an outcome, never below zero, or adds the outcome (inlined in the original).
|
||||
void WeightedOutcomePicker::AddOutcomeWeight(int id, int weight)
|
||||
{
|
||||
for (Outcome& outcome : outcomes)
|
||||
if (outcome.id == id)
|
||||
{
|
||||
outcome.weight = std::max(0, outcome.weight + weight);
|
||||
return;
|
||||
}
|
||||
outcomes.push_back({id, weight});
|
||||
}
|
||||
|
||||
// 0049cbf0 Draws an outcome: a roll below the total weight lands in one outcome's share, the first with no weight.
|
||||
int WeightedOutcomePicker::PickOutcome(RNG rng)
|
||||
{
|
||||
uint32_t total = 0;
|
||||
int sum = 0;
|
||||
|
||||
for (Outcome& outcome : outcomes) total += outcome.weight;
|
||||
uint32_t roll = rng.Next();
|
||||
roll = total ? roll % total : 0;
|
||||
for (Outcome& outcome : outcomes)
|
||||
if ((int)roll < (sum += outcome.weight)) return outcome.id;
|
||||
if (sum <= 0) log_printf(LOG_ASSERT, "No weights were added. At least one outcome needs weight.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Draws an outcome from a picker, seeded by the next draw of an RNG.
|
||||
static int outcome_draw(WeightedOutcomePicker& picker, RNG& rng)
|
||||
{
|
||||
RNG draw;
|
||||
draw.SetSeed(rng.Next(), OUTCOME_SHIFT_INDEX);
|
||||
return picker.PickOutcome(draw);
|
||||
}
|
||||
|
||||
// Adds a pickup to the loot, seeded by the next draw.
|
||||
static void loot_add(ChestDraw& draw, int variant, int subType = 0)
|
||||
{
|
||||
uint32_t seed = draw.rng->Next();
|
||||
draw.loot.entries.push_back({.subType = subType, .type = ENTITY_PICKUP, .variant = variant, .seed = seed});
|
||||
}
|
||||
|
||||
// Adds an item from a pool to the loot: its seed first, then the pool's draw.
|
||||
static void loot_item_add(ChestDraw& draw, int pool)
|
||||
{
|
||||
uint32_t seed = draw.rng->Next();
|
||||
int item = g_game->itemPool.GetCollectible((ItemPoolType)pool, draw.rng->Next(), draw.poolFlags, 0, 0);
|
||||
draw.loot.entries.push_back({.subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, .seed = seed});
|
||||
}
|
||||
|
||||
// Rolls each bonus trinket for the first player holding it (a Lazarus twin's own copy counts for globally shared
|
||||
// ones): one in five passes Child's Heart under Daemon's Tail, then one, two or three copies add their pickup a
|
||||
// third, two thirds or every time.
|
||||
static void chest_trinkets_roll(ChestDraw& draw)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
for (size_t index = 0; index < CHEST_TRINKETS.size(); index++)
|
||||
{
|
||||
int trinket = CHEST_TRINKETS[index].trinket;
|
||||
ItemConfig_Item* config = g_manager->itemConfig.GetTrinket(trinket);
|
||||
bool isShared = config && config->HasTags(TAG_LAZ_SHARED_GLOBAL);
|
||||
auto isHolder = [&](Entity_Player* player)
|
||||
{
|
||||
return player->variant == PLAYER_VARIANT_PLAYER &&
|
||||
(player->HasTrinket(trinket) ||
|
||||
(isShared && player->backupPlayer && player->backupPlayer->HasTrinket(trinket)));
|
||||
};
|
||||
if (std::ranges::none_of(players.playerList, isHolder)) continue;
|
||||
|
||||
if (trinket == TRINKET_CHILDS_HEART && draw.isDaemonsTail && draw.rng->Next() % DAEMONS_TAIL_ODDS != 0)
|
||||
continue;
|
||||
int copies = std::clamp(players.GetTrinketMultiplier(trinket), 1, (int)CHEST_TRINKET_CHANCES.size());
|
||||
draw.isTrinketProc[index] = (int)(draw.rng->Next() % CHEST_TRINKET_ODDS) < CHEST_TRINKET_CHANCES[copies - 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Adds the pickup of the bonus trinket that takes precedence, from its own RNG. Wooden chests only know the first
|
||||
// two.
|
||||
static void chest_trinket_pickup_add(ChestDraw& draw, size_t precedenceCount)
|
||||
{
|
||||
for (size_t rank = 0; rank < precedenceCount; rank++)
|
||||
{
|
||||
int index = CHEST_TRINKET_PRECEDENCE[rank];
|
||||
if (!draw.isTrinketProc[index]) continue;
|
||||
uint32_t seed = draw.trinketRngs[index].Next();
|
||||
draw.loot.entries.push_back({.type = ENTITY_PICKUP, .variant = CHEST_TRINKETS[index].variant, .seed = seed});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// A chest's count of pickups grown by Lucky Toe two times in three and doubled by Mom's Key.
|
||||
static int chest_pickup_count_grow(ChestDraw& draw, int count)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
if (draw.rng->RandomInt(LUCKY_TOE_ODDS) != 0 && players.AnyoneHasTrinket(TRINKET_LUCKY_TOE)) count++;
|
||||
if (players.FirstCollectibleOwner(COLLECTIBLE_MOMS_KEY, LAZARUS_SHARE_CHECK)) count *= 2;
|
||||
return count;
|
||||
}
|
||||
|
||||
// The pickups a chest's pickups outcome gives: coins (one to three), hearts, keys and bombs, or with Gilded Key also
|
||||
// pills, cards, runes, trinkets and batteries.
|
||||
static void chest_pickups_add(ChestDraw& draw, int count, bool isGilded)
|
||||
{
|
||||
WeightedOutcomePicker picker;
|
||||
int heartWeight = draw.isDaemonsTail ? 4 : 20;
|
||||
if (isGilded)
|
||||
picker.outcomes = {{CHEST_PICKUP_COINS, 25}, {CHEST_PICKUP_HEART, heartWeight}, {CHEST_PICKUP_KEY, 10},
|
||||
{CHEST_PICKUP_BOMB, 20}, {CHEST_PICKUP_PILL, 5}, {CHEST_PICKUP_CARD, 5},
|
||||
{CHEST_PICKUP_RUNE, 5}, {CHEST_PICKUP_TRINKET, 5}, {CHEST_PICKUP_BATTERY, 5}};
|
||||
else
|
||||
picker.outcomes = {{CHEST_PICKUP_COINS, 35}, {CHEST_PICKUP_HEART, heartWeight}, {CHEST_PICKUP_KEY, 15},
|
||||
{CHEST_PICKUP_BOMB, 30}};
|
||||
|
||||
constexpr std::array<int, 9> PICKUP_VARIANTS = {PICKUP_COIN, PICKUP_HEART, PICKUP_KEY,
|
||||
PICKUP_BOMB, PICKUP_PILL, PICKUP_TAROTCARD,
|
||||
PICKUP_TAROTCARD, PICKUP_TRINKET, PICKUP_LIL_BATTERY};
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
if (outcome == CHEST_PICKUP_COINS)
|
||||
{
|
||||
for (int coins = draw.rng->RandomInt(CHEST_COINS_ROLL) + 1; coins > 0; coins--) loot_add(draw, PICKUP_COIN);
|
||||
continue;
|
||||
}
|
||||
if (outcome != CHEST_PICKUP_RUNE)
|
||||
{
|
||||
loot_add(draw, PICKUP_VARIANTS[outcome]);
|
||||
continue;
|
||||
}
|
||||
uint32_t seed = draw.rng->Next();
|
||||
uint32_t cardSeed = draw.rng->Next();
|
||||
int card = ItemPool::GetCardEx((int)cardSeed, 0, 1, 0, true);
|
||||
RNG cardRng;
|
||||
cardRng.SetSeed(cardSeed, OUTCOME_SHIFT_INDEX);
|
||||
card = lua_engine_get().GetCard({.rng = &cardRng, .card = card, .isOnlyRunes = true, .isRunes = true});
|
||||
draw.loot.entries.push_back(
|
||||
{.subType = card, .type = ENTITY_PICKUP, .variant = PICKUP_TAROTCARD, .seed = seed});
|
||||
}
|
||||
}
|
||||
|
||||
// An ordinary or golden chest's loot: one draw (five for a Mega Chest) among a trinket, a chest, a locked chest, a
|
||||
// pill or a card, an item from the golden chest pool and the pickups (two to four, or two to six from golden chests),
|
||||
// Gilded Key turning a golden chest's pickups richer. A Mega Chest gives two treasure items half the time.
|
||||
static void chest_loot_draw(ChestDraw& draw, int variant)
|
||||
{
|
||||
bool isMega = variant == PICKUP_MEGACHEST;
|
||||
bool isGolden = std::ranges::count(GOLDEN_CHESTS, variant) > 0;
|
||||
if (isMega && draw.rng->RandomInt(2) == 0)
|
||||
{
|
||||
loot_item_add(draw, POOL_TREASURE);
|
||||
loot_item_add(draw, POOL_TREASURE);
|
||||
return;
|
||||
}
|
||||
|
||||
WeightedOutcomePicker picker;
|
||||
if (isGolden && g_game->playerManager.AnyoneHasTrinket(TRINKET_GILDED_KEY))
|
||||
{
|
||||
picker.AddOutcomeWeight(CHEST_OUTCOME_GILDED_PICKUPS, 80);
|
||||
if (!isMega) picker.AddOutcomeWeight(CHEST_OUTCOME_ITEM, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
picker.AddOutcomeWeight(CHEST_OUTCOME_TRINKET, 10);
|
||||
if (!isMega) picker.AddOutcomeWeight(CHEST_OUTCOME_CHEST, 1);
|
||||
if (!isMega) picker.AddOutcomeWeight(CHEST_OUTCOME_LOCKED_CHEST, 1);
|
||||
picker.AddOutcomeWeight(isGolden ? CHEST_OUTCOME_CARD : CHEST_OUTCOME_PILL, 10);
|
||||
if (isGolden && !isMega) picker.AddOutcomeWeight(CHEST_OUTCOME_ITEM, 20);
|
||||
picker.AddOutcomeWeight(CHEST_OUTCOME_PICKUPS, isGolden ? 58 : 78);
|
||||
}
|
||||
|
||||
for (int draws = isMega ? MEGA_CHEST_DRAWS : 1; draws > 0; draws--)
|
||||
{
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
switch (outcome)
|
||||
{
|
||||
case CHEST_OUTCOME_TRINKET:
|
||||
loot_add(draw, PICKUP_TRINKET);
|
||||
break;
|
||||
case CHEST_OUTCOME_CHEST:
|
||||
loot_add(draw, PICKUP_CHEST);
|
||||
break;
|
||||
case CHEST_OUTCOME_LOCKED_CHEST:
|
||||
loot_add(draw, PICKUP_LOCKEDCHEST);
|
||||
break;
|
||||
case CHEST_OUTCOME_PILL:
|
||||
loot_add(draw, PICKUP_PILL);
|
||||
break;
|
||||
case CHEST_OUTCOME_CARD:
|
||||
loot_add(draw, PICKUP_TAROTCARD);
|
||||
break;
|
||||
case CHEST_OUTCOME_ITEM:
|
||||
loot_item_add(draw, POOL_GOLDEN_CHEST);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
int roll = isGolden ? GOLDEN_PICKUP_COUNT_ROLL : PICKUP_COUNT_ROLL;
|
||||
int count = std::max(PICKUP_COUNT_MIN, (int)draw.rng->RandomInt(roll));
|
||||
chest_trinket_pickup_add(draw, CHEST_TRINKET_PRECEDENCE.size());
|
||||
chest_pickups_add(draw, chest_pickup_count_grow(draw, count), outcome == CHEST_OUTCOME_GILDED_PICKUPS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A wooden chest's loot: an item from the wooden chest pool, or two or three cards or pills. A first draw only
|
||||
// decides whether Lucky Toe may add one, and Ace of Spades or Safety Cap add their pickup.
|
||||
static void wooden_chest_loot_draw(ChestDraw& draw)
|
||||
{
|
||||
WeightedOutcomePicker picker;
|
||||
picker.outcomes = {{WOODEN_OUTCOME_ITEM, 2}, {WOODEN_OUTCOME_CARDS, 10}, {WOODEN_OUTCOME_PILLS, 10}};
|
||||
int first = outcome_draw(picker, *draw.rng);
|
||||
int count = (draw.rng->Next() & 1) + PICKUP_COUNT_MIN;
|
||||
if (first != WOODEN_OUTCOME_ITEM && draw.rng->Next() % LUCKY_TOE_ODDS != 0 &&
|
||||
g_game->playerManager.AnyoneHasTrinket(TRINKET_LUCKY_TOE))
|
||||
count++;
|
||||
chest_trinket_pickup_add(draw, WOODEN_CHEST_TRINKETS);
|
||||
if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_MOMS_KEY, LAZARUS_SHARE_CHECK)) count *= 2;
|
||||
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
if (outcome == WOODEN_OUTCOME_ITEM) return loot_item_add(draw, POOL_WOODEN_CHEST);
|
||||
for (; count > 0; count--) loot_add(draw, outcome == WOODEN_OUTCOME_CARDS ? PICKUP_TAROTCARD : PICKUP_PILL);
|
||||
}
|
||||
|
||||
// 006dae40 What the chest gives, drawn from its RNG, or from a copy with POOL_DRAW_PEEK, which also leaves the items
|
||||
// in their pools. An eternal chest gives nothing a quarter of the time (and stays). Ace of Spades, Safety Cap,
|
||||
// Match Stick, Child's Heart and Rusted Key may add their pickups, and in the Chest every chest gives a treasure item.
|
||||
// Red, old and Mom's chests, sacks and Poker Chip stop the game until reached.
|
||||
LootList Entity_Pickup::GetChestLoot(PoolDraw draw, Entity_Player* player)
|
||||
{
|
||||
ChestDraw chest;
|
||||
RNG peek = dropRNG;
|
||||
chest.rng = draw == POOL_DRAW_TAKE ? &dropRNG : &peek;
|
||||
chest.poolFlags = draw == POOL_DRAW_TAKE ? 0 : POOL_FLAG_NO_DECREASE;
|
||||
chest.isDaemonsTail = g_game->playerManager.AnyoneHasTrinket(TRINKET_DAEMONS_TAIL);
|
||||
for (size_t index = 0; index < CHEST_TRINKETS.size(); index++)
|
||||
chest.trinketRngs[index].SetSeed(dropRNG._seed, CHEST_TRINKETS[index].shiftIndex);
|
||||
|
||||
Game& game = *g_game;
|
||||
if (variant == PICKUP_ETERNALCHEST && game.stage != STAGE_DARK_ROOM && subtype < 2 && (chest.rng->Next() & 3) == 0)
|
||||
return chest.loot;
|
||||
chest_trinkets_roll(chest);
|
||||
|
||||
bool isDeathmatch = game.deathmatchManager.is_active();
|
||||
bool isChestFloor = !game.IsGreedMode() && game.stage == STAGE_DARK_ROOM && !isDeathmatch;
|
||||
bool isPokerChip = isDeathmatch ? player && player->HasTrinket(TRINKET_POKER_CHIP)
|
||||
: game.playerManager.AnyoneHasTrinket(TRINKET_POKER_CHIP);
|
||||
if (isPokerChip) reconstruction_missing("Entity_Pickup::GetChestLoot 006dae40 (Poker Chip)");
|
||||
if (std::ranges::count(UNWRITTEN_LOOT, variant) > 0)
|
||||
reconstruction_missing("Entity_Pickup::GetChestLoot 006dae40 (red, old and Mom's chests and sacks)");
|
||||
|
||||
if (variant == PICKUP_WOODENCHEST) wooden_chest_loot_draw(chest);
|
||||
else if (!isChestFloor) chest_loot_draw(chest, variant);
|
||||
else
|
||||
{
|
||||
loot_item_add(chest, POOL_TREASURE);
|
||||
if (variant == PICKUP_MEGACHEST) loot_item_add(chest, POOL_TREASURE);
|
||||
}
|
||||
return chest.loot;
|
||||
}
|
||||
|
||||
// The poof a chest opens in, small and faint over its lid.
|
||||
static void chest_poof_spawn(Entity_Pickup& chest)
|
||||
{
|
||||
Entity* poof = g_game->Spawn(
|
||||
{.position = chest.pos, .subType = 2, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()});
|
||||
poof->posOffset = vector_make(chest.sprite.scale.x * 0, chest.sprite.scale.x * CHEST_POOF_HEIGHT);
|
||||
poof->sprite.scale = vector_make(chest.sprite.scale.x * CHEST_POOF_SCALE, chest.sprite.scale.y * CHEST_POOF_SCALE);
|
||||
poof->sprite.color = {{1, 1, 1, CHEST_POOF_ALPHA}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
poof->renderDepthOffset = CHEST_POOF_DEPTH;
|
||||
}
|
||||
|
||||
// The deathmatch's chests vanish once open, in a poof.
|
||||
static void chest_vanish(Entity_Pickup& chest)
|
||||
{
|
||||
g_game->Spawn({.position = chest.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()});
|
||||
int sound = SOUND_SUMMONSOUND;
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, {.volume = CHEST_VANISH_VOLUME});
|
||||
chest.Remove();
|
||||
}
|
||||
|
||||
// 006e6e40 Opens the chest for a player (the nearest when none): it plays Open with its sounds and a faint poof,
|
||||
// gives its loot and stays open. An eternal chest that gives nothing closes again. An item turns the chest into its
|
||||
// pedestal, and a pickup or enemy coming out pushes a close player away. Whether a closed chest opened.
|
||||
bool Entity_Pickup::TryOpenChest(Entity_Player* player)
|
||||
{
|
||||
if (!player) player = game_nearest_player(pos);
|
||||
if (subtype == 0) return false;
|
||||
|
||||
sprite.Play("Open", PLAY_FORCED);
|
||||
sound_play(SOUND_CHEST_OPEN);
|
||||
if (std::ranges::count(LOCKED_CHESTS, variant) > 0)
|
||||
{
|
||||
sound_play(SOUND_UNLOCK);
|
||||
g_manager->persistentGameData.IncreaseEventCounter(EVENT_LOCKED_CHESTS_OPENED, 1);
|
||||
}
|
||||
chest_poof_spawn(*this);
|
||||
|
||||
int chestVariant = variant;
|
||||
LootList loot = GetChestLoot(POOL_DRAW_TAKE, player);
|
||||
subtype = 0;
|
||||
Game& game = *g_game;
|
||||
if (chestVariant == PICKUP_ETERNALCHEST && loot.entries.empty())
|
||||
{
|
||||
chestReCloseTimer = 0;
|
||||
game.room->isPickupVisionInvalid = true;
|
||||
if (game.deathmatchManager.is_active()) chest_vanish(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
chest_loot_spawn(loot, *player, chestVariant);
|
||||
if (variant == PICKUP_ETERNALCHEST) chestReCloseTimer = ETERNAL_CHEST_RECLOSE;
|
||||
if (game.deathmatchManager.is_active() && IsChest(variant) && variant != PICKUP_ETERNALCHEST) chest_vanish(*this);
|
||||
game.room->isPickupVisionInvalid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Spawns what a chest gives: the first item turns the chest into its pedestal (a pay to play look for those) and
|
||||
// more stand beside it, pickups and enemies fly out from a spot beside the chest (a Mega Chest's slower at first),
|
||||
// enemies placed towards the player, and chests come out smaller. Red chests' spiders, flies and teleports stop the
|
||||
// game until reached.
|
||||
void Entity_Pickup::chest_loot_spawn(const LootList& loot, Entity_Player& player, int chestVariant)
|
||||
{
|
||||
RNG dropRng;
|
||||
dropRng.SetSeed(dropRNG._seed, LOOT_DROP_SHIFT_INDEX);
|
||||
bool isPushing = false;
|
||||
int spawned = 0;
|
||||
|
||||
for (const LootEntry& entry : loot.entries)
|
||||
{
|
||||
if (entry.type == ENTITY_PICKUP && entry.variant == PICKUP_COLLECTIBLE)
|
||||
{
|
||||
Entity_Pickup* item = this;
|
||||
if (variant == PICKUP_COLLECTIBLE)
|
||||
item = static_cast<Entity_Pickup*>(g_game->Spawn({.position = pos, .subType = entry.subType,
|
||||
.type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE,
|
||||
.seed = entry.seed}));
|
||||
else Morph(ENTITY_PICKUP, PICKUP_COLLECTIBLE, entry.subType, false, false, false);
|
||||
if (item->variant == PICKUP_COLLECTIBLE)
|
||||
{
|
||||
item->targetPosition = pos;
|
||||
for (const ChestPedestal& pedestal : CHEST_PEDESTALS)
|
||||
if (pedestal.variant == chestVariant)
|
||||
item->SetAlternatePedestal(isPayToPlay ? pedestal.payPedestal : pedestal.pedestal);
|
||||
}
|
||||
isPushing = true;
|
||||
continue;
|
||||
}
|
||||
if (entry.type != ENTITY_PICKUP)
|
||||
reconstruction_missing("Entity_Pickup::TryOpenChest 006e6e40 (a red chest's spiders, flies or teleport)");
|
||||
|
||||
float speed = variant == PICKUP_MEGACHEST
|
||||
? std::min(1.0f, (float)spawned * MEGA_CHEST_SPEED_STEP + MEGA_CHEST_SPEED_BASE)
|
||||
: 1;
|
||||
Vector velocity = GetRandomPickupVelocity(pos, &dropRng, 0);
|
||||
RNG angleRng;
|
||||
angleRng.SetSeed(dropRng.Next(), LOOT_ANGLE_SHIFT_INDEX);
|
||||
float angle = angleRng.RandomFloat() * LOOT_ANGLE_SCALE * 2;
|
||||
Entity* out = g_game->Spawn({.position = vector_make(std::cos(angle) + pos.x, std::sin(angle) + pos.y),
|
||||
.velocity = vector_make(velocity.x * speed, velocity.y * speed),
|
||||
.subType = entry.subType,
|
||||
.type = entry.type,
|
||||
.variant = entry.variant,
|
||||
.seed = entry.seed});
|
||||
if (out->type == ENTITY_PICKUP && variant == PICKUP_MEGACHEST)
|
||||
static_cast<Entity_Pickup*>(out)->dropDelay = spawned / 2;
|
||||
out->Update();
|
||||
spawned++;
|
||||
if (Entity::is_enemy_type(out->type))
|
||||
{
|
||||
Vector toward = vector_sub(pos, player.pos);
|
||||
float length = std::sqrt(toward.x * toward.x + toward.y * toward.y);
|
||||
float step = length > 0 ? ENEMY_LOOT_DISTANCE / length : 1;
|
||||
out->pos = vector_make(pos.x + toward.x * step, pos.y + toward.y * step);
|
||||
isPushing = true;
|
||||
}
|
||||
else if (out->type == ENTITY_PICKUP && IsChest(out->variant))
|
||||
out->sprite.scale = vector_make(sprite.scale.x * CHEST_POOF_SCALE, sprite.scale.y * CHEST_POOF_SCALE);
|
||||
}
|
||||
if (!isPushing) return;
|
||||
|
||||
Vector away = vector_sub(pos, player.pos);
|
||||
float distance = std::sqrt(away.x * away.x + away.y * away.y);
|
||||
if (distance * distance < CHEST_PUSH_RADIUS * CHEST_PUSH_RADIUS)
|
||||
{
|
||||
if (distance > 0) away = vector_make(away.x / distance, away.y / distance);
|
||||
float push = (CHEST_PUSH_RADIUS - distance) * CHEST_PUSH_STRENGTH;
|
||||
player.velocity =
|
||||
vector_make((player.velocity.x - push * away.x) * 0.5f, (player.velocity.y - push * away.y) * 0.5f);
|
||||
}
|
||||
wait = CHEST_WAIT;
|
||||
}
|
||||
|
||||
// The chest part of 006e8ae0: a locked, eternal or old chest takes a key (a coin to pay to play) unless the player
|
||||
// holds Paper Clip, or two Strange Keys in the Blue Womb, then the chest opens. A spiked chest hurts a player still
|
||||
// touching it. Whether the touch counts as opening, which every unlocked touch does.
|
||||
bool Entity_Pickup::chest_touch(Entity_Player& player)
|
||||
{
|
||||
bool isLocked = !player.HasTrinket(TRINKET_PAPER_CLIP) && std::ranges::count(LOCKED_CHESTS, variant) > 0;
|
||||
if (isLocked && subtype == 0) return false;
|
||||
bool isStrangeKeyed = g_game->stage == STAGE_BLUE_WOMB && player.GetTrinketMultiplier(TRINKET_STRANGE_KEY) >= 2;
|
||||
if (isLocked && !isStrangeKeyed && !chest_lock_pay(player)) return false;
|
||||
|
||||
int chestVariant = variant;
|
||||
if (!TryOpenChest(&player) || chestVariant != PICKUP_SPIKEDCHEST) return true;
|
||||
Vector apart = vector_sub(pos, player.pos);
|
||||
if (std::sqrt(apart.x * apart.x + apart.y * apart.y) <= size + player.size)
|
||||
player.TakeDamage(SPIKED_CHEST_DAMAGE, DAMAGE_CHEST | DAMAGE_NO_PENALTIES, EntityRef(this),
|
||||
SPIKED_CHEST_DAMAGE_COOLDOWN);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pays a chest's lock: a key, or a coin for a pay to play chest. Whether it was paid.
|
||||
bool Entity_Pickup::chest_lock_pay(Entity_Player& player)
|
||||
{
|
||||
if (!isPayToPlay) return player.TryUseKey();
|
||||
if (player.numCoins <= 0) return false;
|
||||
player.AddCoins(-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// The Mega Chest part of 006e8ae0: a closed Mega Chest not already animating takes a key (or a coin) and plays its
|
||||
// unlock towards the player, opening when the animation ends.
|
||||
void Entity_Pickup::mega_chest_touch(Entity_Player& player)
|
||||
{
|
||||
bool isAnimating = sprite.animState.animData && sprite.animState.isPlaying;
|
||||
if (subtype == 0 || isAnimating || !chest_lock_pay(player)) return;
|
||||
|
||||
target = &player;
|
||||
if (isPayToPlay)
|
||||
{
|
||||
sound_play(SOUND_COIN_INSERT);
|
||||
sprite.Play("UseCoin", PLAY_FORCED);
|
||||
return;
|
||||
}
|
||||
sound_play(SOUND_UNLOCK);
|
||||
sprite.Play(player.hasGoldenKey ? "UseGoldenKey" : "UseKey", PLAY_FORCED);
|
||||
}
|
||||
Reference in new issue
Block a user