1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include "GemCrate.h"
#include "../../ILevelHandler.h"
#include "../../Tiles/TileMap.h"
#include "../Player.h"
#include "../Weapons/ShotBase.h"
#include "../Weapons/TNT.h"
namespace Jazz2::Actors::Solid
{
GemCrate::GemCrate()
{
}
void GemCrate::Preload(const ActorActivationDetails& details)
{
PreloadMetadataAsync("Object/Crate/Generic"_s);
PreloadMetadataAsync("Collectible/Gems"_s);
}
Task<bool> GemCrate::OnActivatedAsync(const ActorActivationDetails& details)
{
Movable = true;
std::uint8_t eventParam = 0;
AddContent(EventType::Gem, details.Params[0], &eventParam, sizeof(eventParam));
eventParam = 1;
AddContent(EventType::Gem, details.Params[1], &eventParam, sizeof(eventParam));
eventParam = 2;
AddContent(EventType::Gem, details.Params[2], &eventParam, sizeof(eventParam));
eventParam = 3;
AddContent(EventType::Gem, details.Params[3], &eventParam, sizeof(eventParam));
async_await RequestMetadataAsync("Object/Crate/Generic"_s);
SetAnimation(AnimState::Idle);
async_return true;
}
bool GemCrate::OnHandleCollision(std::shared_ptr<ActorBase> other)
{
if (_health == 0) {
return GenericContainer::OnHandleCollision(other);
}
if (auto* shotBase = runtime_cast<Weapons::ShotBase>(other.get())) {
if (shotBase->GetStrength() > 0) {
DecreaseHealth(shotBase->GetStrength(), shotBase);
shotBase->DecreaseHealth(1);
return true;
}
} else if (auto* tnt = runtime_cast<Weapons::TNT>(other.get())) {
DecreaseHealth(INT32_MAX, tnt);
return true;
} else if (auto* player = runtime_cast<Player>(other.get())) {
if (player->CanBreakSolidObjects()) {
DecreaseHealth(INT32_MAX, player);
return true;
}
}
return GenericContainer::OnHandleCollision(std::move(other));
}
bool GemCrate::OnPerish(ActorBase* collider)
{
SetState(ActorState::CollideWithTileset | ActorState::CollideWithOtherActors | ActorState::ApplyGravitation, false);
CreateParticleDebrisOnPerish(ParticleDebrisEffect::Standard, Vector2f::Zero);
PlaySfx("Break"_s);
CreateSpriteDebris((AnimState)1, 3);
CreateSpriteDebris((AnimState)2, 2);
_frozenTimeLeft = std::min(1.0f, _frozenTimeLeft);
SetTransition(AnimState::TransitionDeath, false, [this, collider]() {
GenericContainer::OnPerish(collider);
});
SpawnContent();
return true;
}
}
|