mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-09 01:38:20 +00:00
sanity check on opening packages (#923)
This commit is contained in:
parent
1470af99c3
commit
5cc7d47074
@ -5763,11 +5763,7 @@ void GameMessages::HandleUseNonEquipmentItem(RakNet::BitStream* inStream, Entity
|
|||||||
|
|
||||||
auto* item = inv->FindItemById(itemConsumed);
|
auto* item = inv->FindItemById(itemConsumed);
|
||||||
|
|
||||||
if (item == nullptr) {
|
if (item) item->UseNonEquip(item);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item->UseNonEquip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMessages::HandleMatchRequest(RakNet::BitStream* inStream, Entity* entity) {
|
void GameMessages::HandleMatchRequest(RakNet::BitStream* inStream, Entity* entity) {
|
||||||
|
@ -262,7 +262,7 @@ bool Item::Consume() {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::UseNonEquip() {
|
void Item::UseNonEquip(Item* item) {
|
||||||
LOT thisLot = this->GetLot();
|
LOT thisLot = this->GetLot();
|
||||||
if (!GetInventory()) {
|
if (!GetInventory()) {
|
||||||
Game::logger->LogDebug("Item", "item %i has no inventory??", this->GetLot());
|
Game::logger->LogDebug("Item", "item %i has no inventory??", this->GetLot());
|
||||||
@ -292,45 +292,49 @@ void Item::UseNonEquip() {
|
|||||||
}
|
}
|
||||||
// This precondition response is taken care of in SpawnPet().
|
// This precondition response is taken care of in SpawnPet().
|
||||||
} else {
|
} else {
|
||||||
auto* compRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
|
bool success = false;
|
||||||
const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE);
|
auto inventory = item->GetInventory();
|
||||||
|
if (inventory && inventory->GetType() == eInventoryType::ITEMS) {
|
||||||
|
auto* compRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
|
||||||
|
const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE);
|
||||||
|
|
||||||
if (packageComponentId == 0) return;
|
if (packageComponentId == 0) return;
|
||||||
|
|
||||||
auto* packCompTable = CDClientManager::Instance()->GetTable<CDPackageComponentTable>("PackageComponent");
|
auto* packCompTable = CDClientManager::Instance()->GetTable<CDPackageComponentTable>("PackageComponent");
|
||||||
auto packages = packCompTable->Query([=](const CDPackageComponent entry) {return entry.id == static_cast<uint32_t>(packageComponentId); });
|
auto packages = packCompTable->Query([=](const CDPackageComponent entry) {return entry.id == static_cast<uint32_t>(packageComponentId); });
|
||||||
|
|
||||||
auto success = !packages.empty();
|
auto success = !packages.empty();
|
||||||
if (success) {
|
if (success) {
|
||||||
if (this->GetPreconditionExpression()->Check(playerInventoryComponent->GetParent())) {
|
if (this->GetPreconditionExpression()->Check(playerInventoryComponent->GetParent())) {
|
||||||
auto* entityParent = playerInventoryComponent->GetParent();
|
auto* entityParent = playerInventoryComponent->GetParent();
|
||||||
// Roll the loot for all the packages then see if it all fits. If it fits, give it to the player, otherwise don't.
|
// Roll the loot for all the packages then see if it all fits. If it fits, give it to the player, otherwise don't.
|
||||||
std::unordered_map<LOT, int32_t> rolledLoot{};
|
std::unordered_map<LOT, int32_t> rolledLoot{};
|
||||||
for (auto& pack : packages) {
|
for (auto& pack : packages) {
|
||||||
auto thisPackage = LootGenerator::Instance().RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
auto thisPackage = LootGenerator::Instance().RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
||||||
for (auto& loot : thisPackage) {
|
for (auto& loot : thisPackage) {
|
||||||
// If we already rolled this lot, add it to the existing one, otherwise create a new entry.
|
// If we already rolled this lot, add it to the existing one, otherwise create a new entry.
|
||||||
auto existingLoot = rolledLoot.find(loot.first);
|
auto existingLoot = rolledLoot.find(loot.first);
|
||||||
if (existingLoot == rolledLoot.end()) {
|
if (existingLoot == rolledLoot.end()) {
|
||||||
rolledLoot.insert(loot);
|
rolledLoot.insert(loot);
|
||||||
} else {
|
} else {
|
||||||
existingLoot->second += loot.second;
|
existingLoot->second += loot.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) {
|
||||||
if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) {
|
LootGenerator::Instance().GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::LOOT_SOURCE_CONSUMPTION);
|
||||||
LootGenerator::Instance().GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::LOOT_SOURCE_CONSUMPTION);
|
item->SetCount(item->GetCount() - 1);
|
||||||
playerInventoryComponent->RemoveItem(lot, 1);
|
} else {
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
GameMessages::SendUseItemRequirementsResponse(
|
||||||
|
playerInventoryComponent->GetParent()->GetObjectID(),
|
||||||
|
playerInventoryComponent->GetParent()->GetSystemAddress(),
|
||||||
|
UseItemResponse::FailedPrecondition
|
||||||
|
);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
GameMessages::SendUseItemRequirementsResponse(
|
|
||||||
playerInventoryComponent->GetParent()->GetObjectID(),
|
|
||||||
playerInventoryComponent->GetParent()->GetSystemAddress(),
|
|
||||||
UseItemResponse::FailedPrecondition
|
|
||||||
);
|
|
||||||
success = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Game::logger->LogDebug("Item", "Player %llu %s used item %i", playerEntity->GetObjectID(), success ? "successfully" : "unsuccessfully", thisLot);
|
Game::logger->LogDebug("Item", "Player %llu %s used item %i", playerEntity->GetObjectID(), success ? "successfully" : "unsuccessfully", thisLot);
|
||||||
|
@ -195,7 +195,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Uses this item if its non equip, essentially an interface for the linked GM
|
* Uses this item if its non equip, essentially an interface for the linked GM
|
||||||
*/
|
*/
|
||||||
void UseNonEquip();
|
void UseNonEquip(Item* item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disassembles the part LOTs of this item back into the inventory, if it has any
|
* Disassembles the part LOTs of this item back into the inventory, if it has any
|
||||||
|
Loading…
Reference in New Issue
Block a user