| 1 | #include "Item/CoinCollectEmpty2D.h" |
| 2 | |
| 3 | #include <math/seadMatrix.h> |
| 4 | #include <math/seadVector.h> |
| 5 | |
| 6 | #include "Library/Collision/PartsConnector.h" |
| 7 | #include "Library/LiveActor/ActorActionFunction.h" |
| 8 | #include "Library/LiveActor/ActorClippingFunction.h" |
| 9 | #include "Library/LiveActor/ActorInitFunction.h" |
| 10 | #include "Library/LiveActor/ActorInitUtil.h" |
| 11 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 12 | #include "Library/LiveActor/ActorSensorUtil.h" |
| 13 | #include "Library/Matrix/MatrixUtil.h" |
| 14 | #include "Library/Model/ModelShapeUtil.h" |
| 15 | #include "Library/Nerve/NerveSetupUtil.h" |
| 16 | #include "Library/Nerve/NerveUtil.h" |
| 17 | |
| 18 | #include "System/GameDataFunction.h" |
| 19 | #include "Util/ActorDimensionKeeper.h" |
| 20 | #include "Util/ActorDimensionUtil.h" |
| 21 | #include "Util/ItemUtil.h" |
| 22 | #include "Util/SensorMsgFunction.h" |
| 23 | |
| 24 | namespace { |
| 25 | NERVE_IMPL(CoinCollectEmpty2D, Wait); |
| 26 | NERVE_IMPL(CoinCollectEmpty2D, Got); |
| 27 | |
| 28 | NERVES_MAKE_STRUCT(CoinCollectEmpty2D, Wait, Got); |
| 29 | } // namespace |
| 30 | |
| 31 | CoinCollectEmpty2D::CoinCollectEmpty2D(const char* name, const char* archiveName) |
| 32 | : al::LiveActor(name), mArchiveName(archiveName) {} |
| 33 | |
| 34 | void CoinCollectEmpty2D::init(const al::ActorInitInfo& initInfo) { |
| 35 | al::initActorSceneInfo(actor: this, info: initInfo); |
| 36 | al::initActorWithArchiveName(actor: this, initInfo, archiveName: mArchiveName, suffix: nullptr); |
| 37 | al::tryAddDisplayOffset(actor: this, initInfo); |
| 38 | mMtxConnector = al::tryCreateMtxConnector(actor: this, info: initInfo); |
| 39 | mDimensionKeeper = rs::createDimensionKeeper(actor: this); |
| 40 | rs::updateDimensionKeeper(keeper: mDimensionKeeper); |
| 41 | rs::snap2DParallelizeFront(this, this, 500.0f); |
| 42 | al::initNerve(actor: this, nerve: &NrvCoinCollectEmpty2D.Wait, maxStates: 0); |
| 43 | al::startAction(actor: this, actionName: "Wait" ); |
| 44 | makeActorAlive(); |
| 45 | } |
| 46 | |
| 47 | void CoinCollectEmpty2D::initAfterPlacement() { |
| 48 | if (mMtxConnector != nullptr) |
| 49 | al::attachMtxConnectorToCollision(mtxConnector: mMtxConnector, actor: this, false); |
| 50 | |
| 51 | sead::Matrix44f matrix = sead::Matrix44f::ident; |
| 52 | sead::Vector3f frontDir = sead::Vector3f::zero; |
| 53 | sead::Vector3f upDir = sead::Vector3f::zero; |
| 54 | al::calcFrontDir(front: &frontDir, actor: this); |
| 55 | al::calcUpDir(up: &upDir, actor: this); |
| 56 | const sead::Vector2f aDir(100.0f, 100.0f); |
| 57 | al::makeMtxProj(&matrix, aDir, frontDir, upDir); |
| 58 | const sead::Vector3f& objTrans = al::getTrans(actor: this); |
| 59 | matrix.setCol(axis: 3, v: sead::Vector4f(objTrans.x, objTrans.y, objTrans.z, 1.0f)); |
| 60 | al::setModelProjMtx0(getModelKeeper(), matrix); |
| 61 | } |
| 62 | |
| 63 | bool CoinCollectEmpty2D::receiveMsg(const al::SensorMsg* message, al::HitSensor* other, |
| 64 | al::HitSensor* self) { |
| 65 | if (rs::isMsgItemGet2D(message) && al::isNerve(user: this, nerve: &NrvCoinCollectEmpty2D.Wait)) { |
| 66 | al::invalidateClipping(actor: this); |
| 67 | al::setNerve(user: this, nerve: &NrvCoinCollectEmpty2D.Got); |
| 68 | return true; |
| 69 | } |
| 70 | if (al::isMsgPlayerDisregard(msg: message)) |
| 71 | return true; |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | void CoinCollectEmpty2D::endClipped() { |
| 76 | rs::syncCoin2DAnimFrame(actor: this, name: "Wait" ); |
| 77 | al::LiveActor::endClipped(); |
| 78 | } |
| 79 | |
| 80 | void CoinCollectEmpty2D::exeWait() { |
| 81 | if (mMtxConnector != nullptr) |
| 82 | al::connectPoseQT(actor: this, mtxConnector: mMtxConnector); |
| 83 | } |
| 84 | |
| 85 | void CoinCollectEmpty2D::exeGot() { |
| 86 | if (al::isFirstStep(user: this)) |
| 87 | al::startAction(actor: this, actionName: "Got" ); |
| 88 | |
| 89 | if (al::isActionEnd(actor: this)) { |
| 90 | GameDataFunction::addCoin(writer: this, count: 1); |
| 91 | GameDataFunction::addCoin(writer: this, count: 1); |
| 92 | kill(); |
| 93 | } |
| 94 | } |
| 95 | |