| 1 | #include "Player/PlayerActorBase.h" |
| 2 | |
| 3 | #include "Library/LiveActor/ActorAreaFunction.h" |
| 4 | #include "Library/LiveActor/ActorCollisionFunction.h" |
| 5 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 6 | #include "Library/LiveActor/ActorSensorUtil.h" |
| 7 | #include "Library/Math/MathUtil.h" |
| 8 | #include "Library/Se/SeFunction.h" |
| 9 | |
| 10 | #include "Util/ObjUtil.h" |
| 11 | #include "Util/SensorMsgFunction.h" |
| 12 | |
| 13 | PlayerActorBase::PlayerActorBase(const char* name) : LiveActor(name) {} |
| 14 | |
| 15 | u32 PlayerActorBase::getPortNo() const { |
| 16 | return mPortNo; |
| 17 | } |
| 18 | |
| 19 | sead::Matrix34f* PlayerActorBase::getViewMtx() const { |
| 20 | return mViewMtx; |
| 21 | } |
| 22 | |
| 23 | void PlayerActorBase::movement() { |
| 24 | al::LiveActor::movement(); |
| 25 | if (!checkDeathArea()) |
| 26 | sendCollisionMsg(); |
| 27 | } |
| 28 | |
| 29 | bool PlayerActorBase::checkDeathArea() { |
| 30 | if (!al::isInDeathArea(actor: this)) |
| 31 | return false; |
| 32 | |
| 33 | al::tryStartSe(this, "FallDown" ); |
| 34 | al::tryStartSe(this, "vDeadFallDown" ); |
| 35 | kill(); |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | void PlayerActorBase::sendCollisionMsg() { |
| 40 | if (!al::isExistActorCollider(this)) |
| 41 | return; |
| 42 | |
| 43 | al::HitSensor* body = al::getHitSensor(this, "Body" ); |
| 44 | if (!body) |
| 45 | return; |
| 46 | |
| 47 | rs::sendPlayerCollisionTouchMsg(this, body, getPlayerCollision()); |
| 48 | } |
| 49 | |
| 50 | bool PlayerActorBase::receivePushMsg(const al::SensorMsg* msg, al::HitSensor* other, |
| 51 | al::HitSensor* self, f32 maxPush) { |
| 52 | if (al::isMsgPush(msg) || al::isMsgPushStrong(msg) || al::isMsgPushVeryStrong(msg) || |
| 53 | rs::isMsgPushToPlayer(msg)) { |
| 54 | f32 combinedRadius = al::getSensorRadius(self) + al::getSensorRadius(other); |
| 55 | sead::Vector3f diff = al::getSensorPos(self) - al::getSensorPos(other); |
| 56 | if (diff.squaredLength() > sead::Mathf::square(t: combinedRadius)) |
| 57 | return true; |
| 58 | |
| 59 | al::verticalizeVec(out: &diff, vertical: al::getGravity(actor: this), vec: diff); |
| 60 | f32 push = sead::Mathf::clampMax(val: combinedRadius - diff.length(), max_: maxPush); |
| 61 | |
| 62 | if (!al::tryNormalizeOrZero(out: &diff)) { |
| 63 | al::calcFrontDir(front: &diff, actor: this); |
| 64 | diff = -diff; |
| 65 | } |
| 66 | diff = push * diff; |
| 67 | al::setTrans(actor: this, trans: al::getTrans(actor: this) + diff); |
| 68 | return true; |
| 69 | } |
| 70 | return false; |
| 71 | } |
| 72 | |