Added negative checks

This commit is contained in:
EmosewaMC 2022-03-30 21:58:59 -07:00
parent e66421d34f
commit 0561f60031
3 changed files with 28 additions and 17 deletions

View File

@ -192,28 +192,32 @@ void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::s
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
}
void PropertyManagementComponent::Claim(const LWOOBJID playerId)
bool PropertyManagementComponent::Claim(const LWOOBJID playerId)
{
if (owner != LWOOBJID_EMPTY)
{
return;
return false;
}
SetOwnerId(playerId);
auto* zone = dZoneManager::Instance()->GetZone();
const auto& worldId = zone->GetZoneID();
const auto zoneId = worldId.GetMapID();
auto* entity = EntityManager::Instance()->GetEntity(playerId);
auto* user = entity->GetParentUser();
auto character = entity->GetCharacter();
if (!character) return;
if (!character) return false;
const auto cloneId = character->GetPropertyCloneID();
auto* zone = dZoneManager::Instance()->GetZone();
const auto& worldId = zone->GetZoneID();
const auto propertyZoneId = worldId.GetMapID();
const auto propertyCloneId = worldId.GetCloneID();
const auto playerCloneId = character->GetPropertyCloneID();
// If we are not on our clone do not allow us to claim the property
if (propertyCloneId != playerCloneId) return false;
SetOwnerId(playerId);
propertyId = ObjectIDManager::GenerateRandomObjectID();
@ -225,9 +229,9 @@ void PropertyManagementComponent::Claim(const LWOOBJID playerId)
insertion->setUInt64(1, propertyId);
insertion->setUInt64(2, (uint32_t) playerId);
insertion->setUInt(3, templateId);
insertion->setUInt64(4, cloneId);
insertion->setUInt64(4, playerCloneId);
insertion->setString(5, zone->GetZoneName().c_str());
insertion->setInt(6, zoneId);
insertion->setInt(6, propertyZoneId);
// Try and execute the query, print an error if it fails.
try
@ -239,12 +243,14 @@ void PropertyManagementComponent::Claim(const LWOOBJID playerId)
Game::logger->Log("PropertyManagementComponent", "Failed to execute query: (%s)!\n", exception.what());
throw exception;
return false;
}
auto* zoneControlObject = dZoneManager::Instance()->GetZoneControlObject();
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControlObject)) {
script->OnZonePropertyRented(zoneControlObject, entity);
}
return true;
}
void PropertyManagementComponent::OnStartBuilding()

View File

@ -101,8 +101,10 @@ public:
/**
* Makes this property owned by the passed player ID, storing it in the database
* @param playerId the ID of the entity that claimed the property
*
* @return If the claim is successful return true.
*/
void Claim(LWOOBJID playerId);
bool Claim(LWOOBJID playerId);
/**
* Event triggered when the owner of the property starts building, will kick other entities out

View File

@ -41,14 +41,17 @@ void PropertyVendorComponent::OnBuyFromVendor(Entity* originator, const bool con
{
if (PropertyManagementComponent::Instance() == nullptr) return;
if (PropertyManagementComponent::Instance()->Claim(originator->GetObjectID()) == false) {
Game::logger->Log("PropertyVendorComponent", "FAILED TO CLAIM PROPERTY. PLAYER ID IS %llu\n", originator->GetObjectID());
return;
}
GameMessages::SendPropertyRentalResponse(m_Parent->GetObjectID(), 0, 0, 0, 0, originator->GetSystemAddress());
auto* controller = dZoneManager::Instance()->GetZoneControlObject();
controller->OnFireEventServerSide(m_Parent, "propertyRented");
PropertyManagementComponent::Instance()->Claim(originator->GetObjectID());
PropertyManagementComponent::Instance()->SetOwner(originator);
PropertyManagementComponent::Instance()->OnQueryPropertyData(originator, originator->GetSystemAddress());