diff --git a/dGame/dComponents/Property/PropertyEntranceComponent.cpp b/dGame/dComponents/Property/PropertyEntranceComponent.cpp index 8ad08c15b..50b2da67c 100644 --- a/dGame/dComponents/Property/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/Property/PropertyEntranceComponent.cpp @@ -58,6 +58,11 @@ bool PropertyEntranceComponent::OnRequestUse(GameMessages::RequestUseEvent& even return true; } +void PropertyEntranceComponent::CancelLaunch(Entity& player) { + auto* const characterComponent = player.GetComponent(); + if (characterComponent) characterComponent->RocketUnEquip(&player); +} + bool PropertyEntranceComponent::IsFriendsSort(const int32_t sortMethod) { return sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS; } diff --git a/dGame/dComponents/Property/PropertyEntranceComponent.h b/dGame/dComponents/Property/PropertyEntranceComponent.h index 2be448041..5e112cfc8 100644 --- a/dGame/dComponents/Property/PropertyEntranceComponent.h +++ b/dGame/dComponents/Property/PropertyEntranceComponent.h @@ -34,6 +34,10 @@ public: */ void OnEnterProperty(Entity* entity, uint32_t index, bool returnToZone, const SystemAddress& sysAddr); + // The player left the property browser without launching (FireEventServerSide "CancelLaunch"): the rocket that + // OnRequestUse put in their hands is taken off again + static void CancelLaunch(Entity& player); + // True when the property browser asked for the friends list (the reply's wasFriends says so) static bool IsFriendsSort(int32_t sortMethod); diff --git a/dGame/dGameMessages/ObjectMessages.cpp b/dGame/dGameMessages/ObjectMessages.cpp index e4afc7def..fc6f75a0e 100644 --- a/dGame/dGameMessages/ObjectMessages.cpp +++ b/dGame/dGameMessages/ObjectMessages.cpp @@ -13,6 +13,7 @@ #include "MissionComponent.h" #include "MissionOfferComponent.h" #include "PlayerManager.h" +#include "PropertyEntranceComponent.h" #include "RocketLaunchpadControlComponent.h" #include "ZoneMessages.h" #include "ZoneInstanceManager.h" @@ -127,6 +128,12 @@ namespace GameMessages { }); } + // The property browser was closed without a launch, or the player died with it open + // (LWOPropertyEntranceComponent::onPropertyEntranceSelected) + if (args == u"CancelLaunch" && entity.HasComponent(eReplicaComponentType::PROPERTY_ENTRANCE)) { + PropertyEntranceComponent::CancelLaunch(*player); + } + entity.OnFireEventServerSide(sender, GeneralUtils::UTF16ToWTF8(args), param1, param2, param3); } diff --git a/tests/dGameTests/dComponentsTests/EquipMessagesTests.cpp b/tests/dGameTests/dComponentsTests/EquipMessagesTests.cpp index f129a79a8..1448261a4 100644 --- a/tests/dGameTests/dComponentsTests/EquipMessagesTests.cpp +++ b/tests/dGameTests/dComponentsTests/EquipMessagesTests.cpp @@ -17,6 +17,7 @@ #include "InventoryComponent.h" #include "InventoryMessages.h" #include "Item.h" +#include "PropertyEntranceComponent.h" #include "SkillMessages.h" #include "ZoneMessages.h" #include "eReplicaComponentType.h" @@ -217,6 +218,27 @@ TEST_F(EquipMessagesTests, UnequippingAndSlotsWithoutAnEffect) { // A worn jetpack is found again after a world load, so jetpack mode can be sent again: live sent SetJetPackMode (use, // bypass checks, effect 167) about 100 packets after the player's own construction in 12 of 28 world loads of a player // with a jetpack, and constructed the player in jetpack mode in the other 16. +// Opening a property launch pad puts the rocket in the player's hands; leaving the browser without launching (the +// client's "CancelLaunch" event) takes it off again +TEST_F(EquipMessagesTests, CancellingAPropertyLaunchTakesTheRocketOff) { + auto* const rocket = Give(ROCKET); + auto* const sword = Give(SWORD); + sword->Equip(true); + auto* const characterComponent = entity->GetComponent(); + characterComponent->SetLastRocketItemID(rocket->GetId()); + ASSERT_EQ(characterComponent->RocketEquip(entity.get()), rocket); + ASSERT_TRUE(rocket->IsEquipped()); + + PropertyEntranceComponent::CancelLaunch(*entity); + EXPECT_FALSE(rocket->IsEquipped()); + EXPECT_TRUE(sword->IsEquipped()); + + // Cancelling with nothing in hand changes nothing + PropertyEntranceComponent::CancelLaunch(*entity); + EXPECT_FALSE(rocket->IsEquipped()); + EXPECT_TRUE(sword->IsEquipped()); +} + TEST_F(EquipMessagesTests, AWornJetPackIsFoundAfterAWorldLoad) { constexpr LOT JETPACK = 1727; // skill 306, behavior 3569 on equip RegisterLot(JETPACK, "back");