| 1 | #include "MapObj/VolleyballNet.h" |
| 2 | |
| 3 | #include "Library/LiveActor/ActorActionFunction.h" |
| 4 | #include "Library/LiveActor/ActorInitUtil.h" |
| 5 | #include "Library/LiveActor/ActorSensorUtil.h" |
| 6 | #include "Library/Nerve/NerveSetupUtil.h" |
| 7 | #include "Library/Nerve/NerveUtil.h" |
| 8 | |
| 9 | #include "Util/SensorMsgFunction.h" |
| 10 | |
| 11 | namespace { |
| 12 | NERVE_IMPL(VolleyballNet, Wait); |
| 13 | NERVE_IMPL(VolleyballNet, Reaction); |
| 14 | |
| 15 | NERVES_MAKE_NOSTRUCT(VolleyballNet, Wait, Reaction); |
| 16 | } // namespace |
| 17 | |
| 18 | VolleyballNet::VolleyballNet(const char* name) : al::LiveActor(name) {} |
| 19 | |
| 20 | void VolleyballNet::init(const al::ActorInitInfo& initInfo) { |
| 21 | al::initActor(actor: this, initInfo); |
| 22 | al::initNerve(actor: this, nerve: &Wait, maxStates: 0); |
| 23 | makeActorAlive(); |
| 24 | } |
| 25 | |
| 26 | bool VolleyballNet::receiveMsg(const al::SensorMsg* message, al::HitSensor* other, |
| 27 | al::HitSensor* self) { |
| 28 | if (rs::isMsgCapAttackCollide(message) || al::isMsgPlayerTouch(msg: message) || |
| 29 | rs::isMsgSeedTouch(message)) { |
| 30 | bool isTouchingPlayerOrCap = |
| 31 | (rs::isMsgCapAttackCollide(message) || al::isMsgPlayerTouch(msg: message)); |
| 32 | |
| 33 | if (al::isNerve(user: this, nerve: &Reaction) && mReactionFrames <= 5) { |
| 34 | mReactionFrames = 0; |
| 35 | return isTouchingPlayerOrCap; |
| 36 | } |
| 37 | |
| 38 | mReactionFrames = 0; |
| 39 | al::setNerve(user: this, nerve: &Reaction); |
| 40 | return isTouchingPlayerOrCap; |
| 41 | } |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | void VolleyballNet::exeWait() { |
| 46 | if (al::isFirstStep(user: this)) |
| 47 | al::startAction(actor: this, actionName: "Wait" ); |
| 48 | } |
| 49 | |
| 50 | void VolleyballNet::exeReaction() { |
| 51 | if (al::isFirstStep(user: this)) |
| 52 | al::startAction(actor: this, actionName: "Reaction" ); |
| 53 | |
| 54 | if (al::isActionEnd(actor: this) && mReactionFrames > 5) { |
| 55 | al::setNerve(user: this, nerve: &Wait); |
| 56 | return; |
| 57 | } |
| 58 | mReactionFrames++; |
| 59 | } |
| 60 | |