| 1 |
#include "DevanRemote.h" |
| 2 |
#include "../../../ILevelHandler.h" |
| 3 |
#include "../../Player.h" |
| 4 |
#include "../../Explosion.h" |
| 5 |
|
| 6 |
#include "../../../../nCine/Base/Random.h" |
| 7 |
|
| 8 |
#include <float.h> |
| 9 |
|
| 10 |
namespace Jazz2::Actors::Bosses |
| 11 |
{ |
| 12 |
DevanRemote::DevanRemote() |
| 13 |
: _introText(0), _endText(0) |
| 14 |
{ |
| 15 |
} |
| 16 |
|
| 17 |
DevanRemote::~DevanRemote() |
| 18 |
{ |
| 19 |
if (_robot != nullptr) { |
| 20 |
_robot->Deactivate(); |
| 21 |
_robot = nullptr; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
void DevanRemote::Preload(const ActorActivationDetails& details) |
| 26 |
{ |
| 27 |
PreloadMetadataAsync("Boss/DevanRemote"_s); |
| 28 |
} |
| 29 |
|
| 30 |
Task<bool> DevanRemote::OnActivatedAsync(const ActorActivationDetails& details) |
| 31 |
{ |
| 32 |
_introText = details.Params[1]; |
| 33 |
_endText = details.Params[2]; |
| 34 |
|
| 35 |
SetState(ActorState::CollideWithOtherActors | ActorState::CanBeFrozen, false); |
| 36 |
|
| 37 |
async_await RequestMetadataAsync("Boss/DevanRemote"_s); |
| 38 |
SetAnimation(AnimState::Idle); |
| 39 |
|
| 40 |
SetFacingLeft(true); |
| 41 |
|
| 42 |
async_return true; |
| 43 |
} |
| 44 |
|
| 45 |
bool DevanRemote::OnActivatedBoss() |
| 46 |
{ |
| 47 |
StringView text = _levelHandler->GetLevelText(_introText); |
| 48 |
_levelHandler->ShowLevelText(text); |
| 49 |
|
| 50 |
auto actors = _levelHandler->GetActors(); |
| 51 |
for (auto& actor : actors) { |
| 52 |
if (auto robot = runtime_cast<Robot>(actor)) { |
| 53 |
_robot = std::move(robot); |
| 54 |
_robot->Activate(); |
| 55 |
|
| 56 |
// Copy health to Devan to enable HealthBar |
| 57 |
_health = _robot->GetHealth(); |
| 58 |
_maxHealth = _robot->GetMaxHealth(); |
| 59 |
break; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
bool DevanRemote::OnPlayerDied() |
| 67 |
{ |
| 68 |
if (_robot != nullptr) { |
| 69 |
_robot->Deactivate(); |
| 70 |
_robot = nullptr; |
| 71 |
} |
| 72 |
|
| 73 |
return BossBase::OnPlayerDied(); |
| 74 |
} |
| 75 |
|
| 76 |
void DevanRemote::OnUpdate(float timeMult) |
| 77 |
{ |
| 78 |
BossBase::OnUpdate(timeMult); |
| 79 |
|
| 80 |
if (_robot != nullptr) { |
| 81 |
int robotHealth = _robot->GetHealth(); |
| 82 |
if (robotHealth <= 0) { |
| 83 |
_robot = nullptr; |
| 84 |
|
| 85 |
_health = 1; |
| 86 |
|
| 87 |
StringView text = _levelHandler->GetLevelText(_endText, -1, '|'); |
| 88 |
_levelHandler->ShowLevelText(text); |
| 89 |
|
| 90 |
PlaySfx("WarpOut"_s); |
| 91 |
SetTransition(AnimState::TransitionWarpOut, false, [this]() { |
| 92 |
_renderer.setDrawEnabled(false); |
| 93 |
DecreaseHealth(INT32_MAX); |
| 94 |
}); |
| 95 |
} else { |
| 96 |
_health = robotHealth; |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
} |