| 1 | #include "Item/Coin2DCity.h" |
| 2 | |
| 3 | #include "Library/Controller/PadRumbleFunction.h" |
| 4 | #include "Library/LiveActor/ActorActionFunction.h" |
| 5 | #include "Library/LiveActor/ActorAnimFunction.h" |
| 6 | #include "Library/LiveActor/ActorClippingFunction.h" |
| 7 | #include "Library/LiveActor/ActorInitUtil.h" |
| 8 | #include "Library/LiveActor/ActorModelFunction.h" |
| 9 | #include "Library/Nerve/NerveSetupUtil.h" |
| 10 | #include "Library/Nerve/NerveUtil.h" |
| 11 | #include "Library/Placement/PlacementFunction.h" |
| 12 | #include "Library/Placement/PlacementInfo.h" |
| 13 | #include "Library/Scene/SceneObjUtil.h" |
| 14 | #include "Library/Stage/StageRhythm.h" |
| 15 | |
| 16 | #include "Item/Coin2DCityDirector.h" |
| 17 | #include "System/GameDataFunction.h" |
| 18 | #include "Util/ActorDimensionKeeper.h" |
| 19 | #include "Util/SensorMsgFunction.h" |
| 20 | |
| 21 | namespace { |
| 22 | NERVE_IMPL(Coin2DCity, Wait); |
| 23 | NERVE_IMPL(Coin2DCity, Light); |
| 24 | NERVE_IMPL(Coin2DCity, Got); |
| 25 | NERVE_IMPL(Coin2DCity, GotWait); |
| 26 | |
| 27 | NERVES_MAKE_NOSTRUCT(Coin2DCity, Wait); |
| 28 | NERVES_MAKE_STRUCT(Coin2DCity, Got, Light, GotWait); |
| 29 | } // namespace |
| 30 | |
| 31 | Coin2DCity::Coin2DCity(const char* name, Coin2DCityDirector* director) |
| 32 | : al::LiveActor(name), mCityDirector(director) {} |
| 33 | |
| 34 | void Coin2DCity::init(const al::ActorInitInfo& initInfo) { |
| 35 | al::initActorWithArchiveName(actor: this, initInfo, archiveName: "CoinDot" , suffix: nullptr); |
| 36 | al::tryAddDisplayOffset(actor: this, initInfo); |
| 37 | mDimensionKeeper = rs::createDimensionKeeper(actor: this); |
| 38 | rs::updateDimensionKeeper(keeper: mDimensionKeeper); |
| 39 | |
| 40 | mCityDirector->registerCoin(coin: this); |
| 41 | al::PlacementInfo placementInfo; |
| 42 | if (al::isExistLinkChild(initInfo, linkName: "NextCoin" , index: 0)) { |
| 43 | al::getLinksInfo(linkPlacementInfo: &placementInfo, initInfo, linkName: "NextCoin" ); |
| 44 | mNextCoin = new Coin2DCity("コイン2D都市" , mCityDirector); |
| 45 | al::initCreateActorWithPlacementInfo(actor: mNextCoin, initInfo, placementInfo); |
| 46 | } |
| 47 | |
| 48 | al::initNerve(actor: this, nerve: &Wait, maxStates: 0); |
| 49 | al::invalidateClipping(actor: this); |
| 50 | makeActorAlive(); |
| 51 | } |
| 52 | |
| 53 | void Coin2DCity::control() { |
| 54 | mSyncCounter = al::getSceneObj<al::StageSyncCounter>(user: this)->getCounter(); |
| 55 | if (mLightTime > -1 && mCityDirector->isTriggerBeat()) { |
| 56 | if (mNextCoin != nullptr && mLightTime == 1) |
| 57 | mNextCoin->startLight(); |
| 58 | |
| 59 | if (mLightTime == mCityDirector->getLightTime()) |
| 60 | endLight(); |
| 61 | else |
| 62 | mLightTime++; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | bool Coin2DCity::receiveMsg(const al::SensorMsg* message, al::HitSensor* other, |
| 67 | al::HitSensor* self) { |
| 68 | if (rs::isMsgPlayerItemGet2D(message) && !al::isNerve(user: this, nerve: &NrvCoin2DCity.Got) && |
| 69 | !al::isNerve(user: this, nerve: &NrvCoin2DCity.GotWait)) { |
| 70 | al::startHitReaction(actor: this, name: "取得" ); |
| 71 | al::setNerve(user: this, nerve: &NrvCoin2DCity.Got); |
| 72 | return true; |
| 73 | } |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | void Coin2DCity::startLight() { |
| 78 | mLightTime = 0; |
| 79 | if (!al::isNerve(user: this, nerve: &NrvCoin2DCity.Got) && !al::isNerve(user: this, nerve: &NrvCoin2DCity.GotWait)) { |
| 80 | al::setNerve(user: this, nerve: &NrvCoin2DCity.Light); |
| 81 | al::startVisAnim(this, "LightOn" ); |
| 82 | } |
| 83 | |
| 84 | al::StageSyncCounter* syncCounter = al::getSceneObj<al::StageSyncCounter>(user: this); |
| 85 | if (mSyncCounter == syncCounter->getCounter() && mCityDirector->isTriggerBeat()) { |
| 86 | if (mNextCoin != nullptr && mLightTime == 1) |
| 87 | mNextCoin->startLight(); |
| 88 | |
| 89 | if (mLightTime == mCityDirector->getLightTime()) |
| 90 | endLight(); |
| 91 | else |
| 92 | mLightTime++; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void Coin2DCity::endLight() { |
| 97 | al::startVisAnim(this, "LightOff" ); |
| 98 | mLightTime = -1; |
| 99 | } |
| 100 | |
| 101 | void Coin2DCity::exeWait() { |
| 102 | al::startVisAnim(this, "LightOff" ); |
| 103 | } |
| 104 | |
| 105 | void Coin2DCity::exeLight() {} |
| 106 | |
| 107 | void Coin2DCity::exeGot() { |
| 108 | if (al::isFirstStep(user: this)) { |
| 109 | al::startAction(actor: this, actionName: "Got" ); |
| 110 | alPadRumbleFunction::startPadRumble(actor: this, name: "コッ(微弱)" , near: 1000.0f, far: 3000.0f); |
| 111 | GameDataFunction::addCoin(writer: this, count: 1); |
| 112 | } |
| 113 | if (al::isActionEnd(actor: this)) |
| 114 | al::setNerve(user: this, nerve: &NrvCoin2DCity.GotWait); |
| 115 | } |
| 116 | |
| 117 | void Coin2DCity::exeGotWait() { |
| 118 | if (al::isFirstStep(user: this)) { |
| 119 | al::hideModelIfShow(actor: this); |
| 120 | mCityDirector->getCoin(); |
| 121 | } |
| 122 | } |
| 123 | |