1#include "Player/PlayerStateAutoDash.h"
2
3#include "Library/LiveActor/ActorActionFunction.h"
4#include "Library/LiveActor/ActorAnimFunction.h"
5#include "Library/LiveActor/ActorMovementFunction.h"
6#include "Library/Nerve/NerveSetupUtil.h"
7#include "Library/Nerve/NerveStateBase.h"
8#include "Library/Nerve/NerveUtil.h"
9#include "Library/Player/PlayerFunction.h"
10
11#include "Player/PlayerFunction.h"
12
13namespace {
14NERVE_IMPL(PlayerStateAutoDash, Run)
15NERVE_IMPL(PlayerStateAutoDash, Dash)
16NERVES_MAKE_NOSTRUCT(PlayerStateAutoDash, Run, Dash)
17} // namespace
18
19PlayerStateAutoDash::PlayerStateAutoDash(al::LiveActor* player)
20 : al::ActorStateBase("自動ダッシュ", player) {
21 initNerve(nerve: &Run, stateCount: 0);
22}
23
24void PlayerStateAutoDash::appear() {
25 al::LiveActor* player = mActor;
26 al::NerveStateBase::appear();
27
28 if (al::calcSpeed(actor: player) < 12.0f)
29 al::setNerve(user: this, nerve: &Run);
30 else
31 al::setNerve(user: this, nerve: &Dash);
32}
33
34void PlayerStateAutoDash::exeDash() {
35 if (al::isFirstStep(user: this)) {
36 al::startAction(actor: mActor, actionName: "Dash");
37 mRunTimer = 0;
38 }
39
40 al::addVelocityToGravity(actor: mActor, force: 6.0f);
41 al::scaleVelocity(actor: mActor, factor: 0.7f);
42
43 al::LiveActor* player = mActor;
44 al::setSklAnimFrameRate(player, al::calcSpeed(actor: player) * 0.08f, 0);
45
46 sead::Vector3f accelDir = {0.0f, 0.0f, 0.0f};
47 al::addPlayerAccelStickGravity(mActor, &accelDir, 6.0f, {0.0f, 1.0f, 0.0f},
48 PlayerFunction::getPlayerInputPort(mActor),
49 &PlayerFunction::getPlayerViewMtx(mActor));
50 al::faceToDirection(actor: mActor, dir: accelDir);
51
52 if (al::isVelocitySlow(actor: mActor, threshold: 6.0f)) {
53 kill();
54 return;
55 }
56
57 al::reboundVelocityFromCollision(actor: mActor, reboundStrength: 0.0f, reboundMin: 0.0f, friction: 1.0f);
58}
59
60void PlayerStateAutoDash::exeRun() {
61 if (al::isFirstStep(user: this)) {
62 al::startAction(actor: mActor, actionName: "Dash");
63 mRunTimer = 0;
64 }
65
66 al::addVelocityToGravity(actor: mActor, force: 3.0f);
67 al::scaleVelocity(actor: mActor, factor: 0.7f);
68
69 sead::Vector3f accelDir = {0.0f, 0.0f, 0.0f};
70 al::addPlayerAccelStickGravity(mActor, &accelDir, 3.0f, {0.0f, 1.0f, 0.0f},
71 PlayerFunction::getPlayerInputPort(mActor),
72 &PlayerFunction::getPlayerViewMtx(mActor));
73 al::faceToDirection(actor: mActor, dir: accelDir);
74
75 al::LiveActor* player = mActor;
76 al::setSklAnimFrameRate(player, al::calcSpeed(actor: player) * 0.27f, 0);
77
78 if (al::isVelocitySlow(actor: mActor, threshold: 3.0f)) {
79 kill();
80 return;
81 }
82
83 al::reboundVelocityFromCollision(actor: mActor, reboundStrength: 0.0f, reboundMin: 0.0f, friction: 1.0f);
84 mRunTimer++;
85 if (mRunTimer >= 60)
86 al::setNerve(user: this, nerve: &Dash);
87}
88