diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 45073f9d878..87070d95594 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1685,6 +1685,12 @@ void Player::onCreatureAppear(std::shared_ptr creature, bool isLogin) } sendBlessStatus(); } + + if (getCurrentMount() != 0) { + toggleMount(true); + } + + g_game().changePlayerSpeed(static_self_cast(), 0); } } @@ -1717,6 +1723,12 @@ void Player::onChangeZone(ZoneType_t zone) { wasMounted = true; } } else { + int32_t ticks = g_configManager().getNumber(STAIRHOP_DELAY, __FUNCTION__); + if (ticks > 0) { + if (const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_PACIFIED, ticks, 0)) { + addCondition(condition); + } + } if (wasMounted) { toggleMount(true); wasMounted = false; @@ -4393,6 +4405,7 @@ void Player::onAddCondition(ConditionType_t type) { if (type == CONDITION_OUTFIT && isMounted()) { dismount(); + wasMounted = true; } sendIcons(); @@ -4466,6 +4479,10 @@ void Player::onEndCondition(ConditionType_t type) { } } + if (type == CONDITION_OUTFIT && wasMounted) { + toggleMount(true); + } + sendIcons(); } @@ -5610,6 +5627,14 @@ void Player::sendUnjustifiedPoints() { } } +uint8_t Player::getLastMount() const { + int32_t value = getStorageValue(PSTRG_MOUNTS_CURRENTMOUNT); + if (value > 0) { + return value; + } + return static_cast(kv()->get("last-mount")->get()); +} + uint8_t Player::getCurrentMount() const { int32_t value = getStorageValue(PSTRG_MOUNTS_CURRENTMOUNT); if (value > 0) { @@ -5668,7 +5693,7 @@ bool Player::toggleMount(bool mount) { return false; } - uint8_t currentMountId = getCurrentMount(); + uint8_t currentMountId = getLastMount(); if (currentMountId == 0) { sendOutfitWindow(); return false; @@ -5685,6 +5710,7 @@ bool Player::toggleMount(bool mount) { if (!hasMount(currentMount)) { setCurrentMount(0); + kv()->set("last-mount", 0); sendOutfitWindow(); return false; } @@ -5701,6 +5727,7 @@ bool Player::toggleMount(bool mount) { defaultOutfit.lookMount = currentMount->clientId; setCurrentMount(currentMount->id); + kv()->set("last-mount", currentMount->id); if (currentMount->speed != 0) { g_game().changeSpeed(static_self_cast(), currentMount->speed); @@ -5760,6 +5787,7 @@ bool Player::untameMount(uint8_t mountId) { } setCurrentMount(0); + kv()->set("last-mount", 0); } return true; @@ -5791,6 +5819,7 @@ void Player::dismount() { } defaultOutfit.lookMount = 0; + setCurrentMount(0); } bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) { diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 9f6c01252b2..a33c538c814 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -159,6 +159,7 @@ class Player final : public Creature, public Cylinder, public Bankable { return CREATURETYPE_PLAYER; } + uint8_t getLastMount() const; uint8_t getCurrentMount() const; void setCurrentMount(uint8_t mountId); bool isMounted() const { diff --git a/src/game/game.cpp b/src/game/game.cpp index bc758180bf6..a0028c1aa18 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -5479,7 +5479,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun auto deltaSpeedChange = mount->speed; if (player->isMounted()) { - const auto prevMount = mounts.getMountByID(player->getCurrentMount()); + const auto prevMount = mounts.getMountByID(player->getLastMount()); if (prevMount) { deltaSpeedChange -= prevMount->speed; } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index ad8b728ed05..b0f3c39e573 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -6411,7 +6411,7 @@ void ProtocolGame::sendOutfitWindow() { if (oldProtocol) { Outfit_t currentOutfit = player->getDefaultOutfit(); - const auto currentMount = g_game().mounts.getMountByID(player->getCurrentMount()); + const auto currentMount = g_game().mounts.getMountByID(player->getLastMount()); if (currentMount) { currentOutfit.lookMount = currentMount->clientId; } @@ -6471,7 +6471,7 @@ void ProtocolGame::sendOutfitWindow() { bool mounted = false; Outfit_t currentOutfit = player->getDefaultOutfit(); - const auto currentMount = g_game().mounts.getMountByID(player->getCurrentMount()); + const auto currentMount = g_game().mounts.getMountByID(player->getLastMount()); if (currentMount) { mounted = (currentOutfit.lookMount == currentMount->clientId); currentOutfit.lookMount = currentMount->clientId;