1#include "Game/MapObj/KeySwitch.hpp"
2#include "JSystem/JMath/JMath.hpp"
4KeySwitch::~KeySwitch() {
8KeySwitch::KeySwitch(
const char *pName) :
LiveActor(pName) {
14 MR::initDefaultPos(
this, rIter);
15 initModelManagerWithAnm(
"KeySwitch", 0,
false);
16 MR::connectToSceneMapObjDecoration(
this);
22 MR::addHitSensorMapObjSimple(
this,
"body", 8, 105.0f, box);
23 initBinder(105.0f, 105.0f, 0);
24 initEffectKeeper(0, 0,
false);
26 MR::initShadowVolumeCylinder(
this, 90.0f);
28 if (MR::isValidInfo(rIter)) {
29 MR::initActorCamera(
this, rIter, &mCameraInfo);
32 bool usesSwitch =
false;
34 if (MR::isValidInfo(rIter)) {
35 bool uses = MR::useStageSwitchReadAppear(
this, rIter);
38 MR::syncStageSwitchAppear(
this);
41 MR::needStageSwitchWriteA(
this, rIter);
44 if (usesSwitch || !MR::isValidInfo(rIter)) {
45 initNerve(&NrvKeySwitch::KeySwitchNrvDemoStart::sInstance);
49 initNerve(&NrvKeySwitch::KeySwitchNrvWait::sInstance);
52 if (usesSwitch || !MR::isValidInfo(rIter)) {
60void KeySwitch::initKeySwitchByOwner(
const JMapInfoIter &rIter) {
62 MR::needStageSwitchWriteA(
this, rIter);
63 MR::initActorCamera(
this, rIter, &mCameraInfo);
66void KeySwitch::appearKeySwitch(
const TVec3f &rVec) {
67 MR::resetPosition(
this, rVec);
68 MR::onCalcGravity(
this);
69 MR::invalidateClipping(
this);
73void KeySwitch::exeDemoStart() {
75 setNerve(&NrvKeySwitch::KeySwitchNrvAppear::sInstance);
79 if (MR::tryStartDemoWithoutCinemaFrame(
this, cDemoName)) {
80 MR::startActorCameraTargetSelf(
this, mCameraInfo, -1);
82 setNerve(&NrvKeySwitch::KeySwitchNrvAppear::sInstance);
86void KeySwitch::exeAppear() {
87 if (MR::isFirstStep(
this)) {
88 MR::startBck(
this,
"Rotation", 0);
90 MR::invalidateClipping(
this);
91 MR::startSound(
this,
"SE_OJ_KEY_SWITCH_APPEAR", -1, -1);
94 MR::setBckRate(
this, MR::calcNerveValue(
this, 0xB4, 3.0f, 1.5f));
95 MR::addVelocityToGravity(
this, 2.0f);
99 if (MR::isBindedGround(
this)) {
100 if (PSVECMag(
mVelocity.toCVec()) >= 10.0f) {
107 MR::startSound(
this,
"SE_OJ_KEY_SWITCH_BOUND", mag, -1);
110 MR::calcReboundVelocity(&
mVelocity, neg, 0.60000002f, 0.69999999f);
119 MR::validateClipping(
this);
120 setNerve(&NrvKeySwitch::KeySwitchNrvWait::sInstance);
125void KeySwitch::exeWait() {
126 if (MR::isFirstStep(
this)) {
127 MR::tryStartBck(
this,
"Rotation", 0);
128 MR::setBckRate(
this, 1.0f);
132 MR::offCalcGravity(
this);
136void KeySwitch::appear() {
140void KeySwitch::kill() {
142 MR::startSystemSE(
"SE_SY_READ_RIDDLE_S", -1, -1);
143 MR::emitEffect(
this,
"Get");
149 MR::calcFrontVec(&front,
this);
151 MR::calcMtxFromGravityAndZAxis(&mtx,
this,
mGravity, front);
152 MR::setBaseTRMtx(
this, mtx);
155void KeySwitch::control() {
156 if (mCurDemoFrame != -1 && mCameraInfo) {
157 if (mCurDemoFrame >= 0x28) {
158 MR::endActorCamera(
this, mCameraInfo,
false, -1);
159 MR::endDemo(
this, cDemoName);
164 mCurDemoFrame = mCurDemoFrame + 1;
170 return MR::isMsgStarPieceReflect(msg);
174 if (MR::isMsgStarPieceReflect(msg)) {
178 if (isNerve(&NrvKeySwitch::KeySwitchNrvAppear::sInstance) && MR::isLessEqualStep(
this, 0x3C)) {
182 if (MR::isMsgItemGet(msg)) {
183 MR::startSound(
this,
"SE_OJ_KEY_SWITCH_GET", -1, -1);
184 MR::tryRumblePadMiddle(
this, 0);
192bool KeySwitch::tryAvoid() {
196 if (MR::isBindedGround(
this)) {
197 sensor = MR::getGroundSensor(
this);
199 else if (MR::isBindedWall(
this)) {
200 sensor = MR::getWallSensor(
this);
207 if (sensor->mSensorType != 0x58) {
211 sensorActor = sensor->mActor;
213 MR::calcUpVec(&up, sensorActor);
217 JMAVECScaleAdd(up.toCVec(), thing.toCVec(), stack_8.toVec(), -up.dot(thing));
219 if (MR::normalizeOrZero(&stack_8)) {
220 MR::calcFrontVec(&stack_8, sensorActor);
227namespace NrvKeySwitch {
228 INIT_NERVE(KeySwitchNrvDemoStart);
229 INIT_NERVE(KeySwitchNrvAppear);
230 INIT_NERVE(KeySwitchNrvWait);
232 void KeySwitchNrvWait::execute(
Spine *pSpine)
const {
237 void KeySwitchNrvAppear::execute(
Spine *pSpine)
const {
242 void KeySwitchNrvDemoStart::execute(
Spine *pSpine)
const {
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
The basis of a drawable actor that can contain states (see: Nerve)
TVec3f mPosition
3D vector of the actor's position.
TVec3f mVelocity
3D vector of the actor's velocity.
TVec3f mGravity
3D vector of the actor's gravity.
void initWithoutIter()
Initializes a NameObj without a JMapInfoIter instance.