mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-14 12:18:22 +00:00
Packages updates (#864)
Update packages to not open if you dont have enough room. Update packages to no longer allow them selves to be open unless you meet the pre-reqs.
This commit is contained in:
parent
da910309a0
commit
5292f36417
@ -253,7 +253,7 @@ bool Item::Consume() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::logger->Log("Item", "Consumed (%i) / (%llu) with (%d)", lot, id, success);
|
Game::logger->LogDebug("Item", "Consumed LOT (%i) itemID (%llu). Success=(%d)", lot, id, success);
|
||||||
|
|
||||||
GameMessages::SendUseItemResult(inventory->GetComponent()->GetParent(), lot, success);
|
GameMessages::SendUseItemResult(inventory->GetComponent()->GetParent(), lot, success);
|
||||||
|
|
||||||
@ -265,14 +265,34 @@ bool Item::Consume() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Item::UseNonEquip() {
|
void Item::UseNonEquip() {
|
||||||
|
LOT thisLot = this->GetLot();
|
||||||
|
if (!GetInventory()) {
|
||||||
|
Game::logger->LogDebug("Item", "item %i has no inventory??", this->GetLot());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* playerInventoryComponent = GetInventory()->GetComponent();
|
||||||
|
if (!playerInventoryComponent) {
|
||||||
|
Game::logger->LogDebug("Item", "no inventory component attached to item id %llu lot %i", this->GetId(), this->GetLot());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* playerEntity = playerInventoryComponent->GetParent();
|
||||||
|
if (!playerEntity) {
|
||||||
|
Game::logger->LogDebug("Item", "no player entity attached to inventory? item id is %llu", this->GetId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto type = static_cast<eItemType>(info->itemType);
|
const auto type = static_cast<eItemType>(info->itemType);
|
||||||
if (type == eItemType::ITEM_TYPE_MOUNT) {
|
if (type == eItemType::ITEM_TYPE_MOUNT) {
|
||||||
GetInventory()->GetComponent()->HandlePossession(this);
|
playerInventoryComponent->HandlePossession(this);
|
||||||
|
// TODO Check if mounts are allowed to be spawned
|
||||||
} else if (type == eItemType::ITEM_TYPE_PET_INVENTORY_ITEM && subKey != LWOOBJID_EMPTY) {
|
} else if (type == eItemType::ITEM_TYPE_PET_INVENTORY_ITEM && subKey != LWOOBJID_EMPTY) {
|
||||||
const auto& databasePet = GetInventory()->GetComponent()->GetDatabasePet(subKey);
|
const auto& databasePet = playerInventoryComponent->GetDatabasePet(subKey);
|
||||||
if (databasePet.lot != LOT_NULL) {
|
if (databasePet.lot != LOT_NULL) {
|
||||||
GetInventory()->GetComponent()->SpawnPet(this);
|
playerInventoryComponent->SpawnPet(this);
|
||||||
}
|
}
|
||||||
|
// This precondition response is taken care of in SpawnPet().
|
||||||
} else {
|
} else {
|
||||||
auto* compRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
|
auto* compRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
|
||||||
const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE);
|
const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE);
|
||||||
@ -282,18 +302,41 @@ void Item::UseNonEquip() {
|
|||||||
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); });
|
||||||
|
|
||||||
const auto success = !packages.empty();
|
auto success = !packages.empty();
|
||||||
if (success) {
|
if (success) {
|
||||||
auto* entityParent = inventory->GetComponent()->GetParent();
|
if (this->GetPreconditionExpression()->Check(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.
|
||||||
|
std::unordered_map<LOT, int32_t> rolledLoot{};
|
||||||
for (auto& pack : packages) {
|
for (auto& pack : packages) {
|
||||||
std::unordered_map<LOT, int32_t> result{};
|
auto thisPackage = LootGenerator::Instance().RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
||||||
result = LootGenerator::Instance().RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
for (auto& loot : thisPackage) {
|
||||||
if (!inventory->GetComponent()->HasSpaceForLoot(result)) {
|
// If we already rolled this lot, add it to the existing one, otherwise create a new entry.
|
||||||
|
auto existingLoot = rolledLoot.find(loot.first);
|
||||||
|
if (existingLoot == rolledLoot.end()) {
|
||||||
|
rolledLoot.insert(loot);
|
||||||
|
} else {
|
||||||
|
existingLoot->second += loot.second;
|
||||||
}
|
}
|
||||||
LootGenerator::Instance().GiveLoot(inventory->GetComponent()->GetParent(), result, eLootSourceType::LOOT_SOURCE_CONSUMPTION);
|
|
||||||
}
|
}
|
||||||
inventory->GetComponent()->RemoveItem(lot, 1);
|
|
||||||
}
|
}
|
||||||
|
if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) {
|
||||||
|
LootGenerator::Instance().GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::LOOT_SOURCE_CONSUMPTION);
|
||||||
|
playerInventoryComponent->RemoveItem(lot, 1);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
GameMessages::SendUseItemResult(playerInventoryComponent->GetParent(), thisLot, success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ bool Precondition::CheckValue(Entity* player, const uint32_t value, bool evaluat
|
|||||||
case PreconditionType::MissionComplete:
|
case PreconditionType::MissionComplete:
|
||||||
mission = missionComponent->GetMission(value);
|
mission = missionComponent->GetMission(value);
|
||||||
|
|
||||||
return mission == nullptr || mission->GetMissionState() >= MissionState::MISSION_STATE_COMPLETE;
|
return mission == nullptr ? false : mission->GetMissionState() >= MissionState::MISSION_STATE_COMPLETE;
|
||||||
case PreconditionType::PetDeployed:
|
case PreconditionType::PetDeployed:
|
||||||
return false; // TODO
|
return false; // TODO
|
||||||
case PreconditionType::HasFlag:
|
case PreconditionType::HasFlag:
|
||||||
@ -277,11 +277,6 @@ bool PreconditionExpression::Check(Entity* player, bool evaluateCosts) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->GetGMLevel() >= 9) // Developers can skip this for testing
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto a = Preconditions::Check(player, condition, evaluateCosts);
|
const auto a = Preconditions::Check(player, condition, evaluateCosts);
|
||||||
|
|
||||||
if (!a) {
|
if (!a) {
|
||||||
|
Loading…
Reference in New Issue
Block a user