Proper Rocket Holding

Sanity checks on Prop and LUP launchpads to not open if no valid rocket
Add serialization for sending item configs
so that rockets show for other players
This commit is contained in:
Aaron Kimbre
2022-05-08 19:57:36 -05:00
parent 24745c2e7a
commit ec207838d4
10 changed files with 156 additions and 132 deletions

View File

@@ -13,6 +13,7 @@
#include "PossessorComponent.h"
#include "VehiclePhysicsComponent.h"
#include "GameMessages.h"
#include "Item.h"
CharacterComponent::CharacterComponent(Entity* parent, Character* character) : Component(parent) {
m_Character = character;
@@ -448,6 +449,56 @@ void CharacterComponent::SetLastRocketConfig(std::u16string config) {
m_LastRocketConfig = config;
}
Item* CharacterComponent::GetRocket(Entity* player) {
Item* rocket = nullptr;
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
if (!inventoryComponent) return rocket;
// Select the rocket
if (!rocket){
rocket = inventoryComponent->FindItemById(GetLastRocketItemID());
}
if (!rocket) {
rocket = inventoryComponent->FindItemByLot(6416);
}
if (!rocket) {
Game::logger->Log("CharacterComponent", "Unable to find rocket to equip!\n");
return rocket;
}
return rocket;
}
Item* CharacterComponent::RocketEquip(Entity* player) {
Item* rocket = GetRocket(player);
if (!rocket) return rocket;
// build and define the rocket config
for (LDFBaseData* data : rocket->GetConfig()) {
if (data->GetKey() == u"assemblyPartLOTs") {
std::string newRocketStr = data->GetValueAsString() + ";";
GeneralUtils::ReplaceInString(newRocketStr, "+", ";");
SetLastRocketConfig(GeneralUtils::ASCIIToUTF16(newRocketStr));
}
}
// Store the last used rocket item's ID
SetLastRocketItemID(rocket->GetId());
// carry the rocket
rocket->Equip(true);
return rocket;
}
void CharacterComponent::RocketUnEquip(Entity* player) {
Item* rocket = GetRocket(player);
if (!rocket) return;
// We don't want to carry it anymore
rocket->UnEquip();
}
void CharacterComponent::TrackMissionCompletion(bool isAchievement) {
UpdatePlayerStatistic(MissionsCompleted);