| 1 |
#include "BonusWarp.h" |
| 2 |
#include "../../ILevelHandler.h" |
| 3 |
#include "../../Events/EventMap.h" |
| 4 |
#include "../Player.h" |
| 5 |
|
| 6 |
namespace Jazz2::Actors::Environment |
| 7 |
{ |
| 8 |
BonusWarp::BonusWarp() |
| 9 |
: _warpTarget(UINT8_MAX), _cost(UINT8_MAX), _setLaps(false), _fast(false) |
| 10 |
{ |
| 11 |
} |
| 12 |
|
| 13 |
void BonusWarp::Preload(const ActorActivationDetails& details) |
| 14 |
{ |
| 15 |
PreloadMetadataAsync("Object/BonusWarp"_s); |
| 16 |
} |
| 17 |
|
| 18 |
Task<bool> BonusWarp::OnActivatedAsync(const ActorActivationDetails& details) |
| 19 |
{ |
| 20 |
_warpTarget = details.Params[0]; |
| 21 |
_fast = (details.Params[1] != 0); |
| 22 |
_setLaps = details.Params[2] != 0; |
| 23 |
_cost = details.Params[3]; |
| 24 |
// TODO: Show rabbit for non-listed number of coins (use JJ2+ anim set 8) |
| 25 |
//_showAnim = details.Params[4] != 0; |
| 26 |
|
| 27 |
SetState(ActorState::CanBeFrozen, false); |
| 28 |
_renderer.setLayer(_renderer.layer() - 20); |
| 29 |
|
| 30 |
async_await RequestMetadataAsync("Object/BonusWarp"_s); |
| 31 |
|
| 32 |
switch (_cost) { |
| 33 |
case 10: |
| 34 |
case 20: |
| 35 |
case 50: |
| 36 |
case 100: |
| 37 |
SetAnimation((AnimState)_cost); |
| 38 |
break; |
| 39 |
default: |
| 40 |
// TODO: Show rabbit + coins needed, if (showAnim) |
| 41 |
SetAnimation(AnimState::Default); |
| 42 |
break; |
| 43 |
} |
| 44 |
|
| 45 |
async_return true; |
| 46 |
} |
| 47 |
|
| 48 |
void BonusWarp::OnUpdateHitbox() |
| 49 |
{ |
| 50 |
UpdateHitbox(28, 28); |
| 51 |
} |
| 52 |
|
| 53 |
void BonusWarp::Activate(Player* player) |
| 54 |
{ |
| 55 |
auto events = _levelHandler->EventMap(); |
| 56 |
if (events == nullptr) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
Vector2f targetPos = events->GetWarpTarget(_warpTarget); |
| 61 |
if (targetPos.X < 0.0f || targetPos.Y < 0.0f) { |
| 62 |
// Warp target not found |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
player->WarpToPosition(targetPos, _fast ? WarpFlags::Fast : WarpFlags::Default); |
| 67 |
} |
| 68 |
} |