format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -14,40 +14,33 @@ std::vector<LOT> Inventory::m_GameMasterRestrictedItems = {
14442 // The jamesster jetpack
};
Inventory::Inventory(const eInventoryType type, const uint32_t size, const std::vector<Item*>& items, InventoryComponent* component)
{
Inventory::Inventory(const eInventoryType type, const uint32_t size, const std::vector<Item*>& items, InventoryComponent* component) {
this->type = type;
this->size = size;
this->free = size;
this->component = component;
for (auto* item : items)
{
for (auto* item : items) {
AddManagedItem(item);
}
}
eInventoryType Inventory::GetType() const
{
eInventoryType Inventory::GetType() const {
return type;
}
uint32_t Inventory::GetSize() const
{
uint32_t Inventory::GetSize() const {
return size;
}
std::map<LWOOBJID, Item*>& Inventory::GetItems()
{
std::map<LWOOBJID, Item*>& Inventory::GetItems() {
return items;
}
std::map<uint32_t, Item*> Inventory::GetSlots() const
{
std::map<uint32_t, Item*> Inventory::GetSlots() const {
std::map<uint32_t, Item*> slots;
for (const auto& pair : items)
{
for (const auto& pair : items) {
auto* item = pair.second;
slots.insert_or_assign(item->GetSlot(), item);
@@ -56,21 +49,17 @@ std::map<uint32_t, Item*> Inventory::GetSlots() const
return slots;
}
InventoryComponent* Inventory::GetComponent() const
{
InventoryComponent* Inventory::GetComponent() const {
return component;
}
uint32_t Inventory::GetLotCount(const LOT lot) const
{
uint32_t Inventory::GetLotCount(const LOT lot) const {
uint32_t count = 0;
for (const auto& pair : items)
{
for (const auto& pair : items) {
const auto* item = pair.second;
if (item->GetLot() == lot)
{
if (item->GetLot() == lot) {
count += item->GetCount();
}
}
@@ -78,8 +67,7 @@ uint32_t Inventory::GetLotCount(const LOT lot) const
return count;
}
void Inventory::SetSize(const uint32_t value)
{
void Inventory::SetSize(const uint32_t value) {
free += static_cast<int32_t>(value) - static_cast<int32_t>(size);
size = value;
@@ -87,45 +75,34 @@ void Inventory::SetSize(const uint32_t value)
GameMessages::SendSetInventorySize(component->GetParent(), type, static_cast<int>(size));
}
int32_t Inventory::FindEmptySlot()
{
int32_t Inventory::FindEmptySlot() {
if (free <= 6) // Up from 1
{
if (type != ITEMS && type != VAULT_ITEMS && type != eInventoryType::VAULT_MODELS)
{
if (type != ITEMS && type != VAULT_ITEMS && type != eInventoryType::VAULT_MODELS) {
uint32_t newSize = size;
if (type == MODELS)
{
if (type == MODELS) {
newSize = 240;
}
else if (type == eInventoryType::VENDOR_BUYBACK)
{
} else if (type == eInventoryType::VENDOR_BUYBACK) {
newSize += 9u;
}
else
{
} else {
newSize += 10u;
}
if (newSize > GetSize())
{
if (newSize > GetSize()) {
SetSize(newSize);
}
}
}
if (free == 0)
{
if (free == 0) {
return -1;
}
const auto slots = GetSlots();
for (auto i = 0u; i < size; ++i)
{
if (slots.find(i) == slots.end())
{
for (auto i = 0u; i < size; ++i) {
if (slots.find(i) == slots.end()) {
return i;
}
}
@@ -133,13 +110,11 @@ int32_t Inventory::FindEmptySlot()
return -1;
}
int32_t Inventory::GetEmptySlots()
{
int32_t Inventory::GetEmptySlots() {
return free;
}
bool Inventory::IsSlotEmpty(int32_t slot)
{
bool Inventory::IsSlotEmpty(int32_t slot) {
const auto slots = GetSlots();
const auto& index = slots.find(slot);
@@ -147,50 +122,41 @@ bool Inventory::IsSlotEmpty(int32_t slot)
return index == slots.end();
}
Item* Inventory::FindItemById(const LWOOBJID id) const
{
Item* Inventory::FindItemById(const LWOOBJID id) const {
const auto& index = items.find(id);
if (index == items.end())
{
if (index == items.end()) {
return nullptr;
}
return index->second;
}
Item* Inventory::FindItemByLot(const LOT lot, const bool ignoreEquipped, const bool ignoreBound) const
{
Item* Inventory::FindItemByLot(const LOT lot, const bool ignoreEquipped, const bool ignoreBound) const {
Item* smallest = nullptr;
for (const auto& pair : items)
{
for (const auto& pair : items) {
auto* item = pair.second;
if (item->GetLot() != lot)
{
if (item->GetLot() != lot) {
continue;
}
if (ignoreEquipped && item->IsEquipped())
{
if (ignoreEquipped && item->IsEquipped()) {
continue;
}
if (ignoreBound && item->GetBound())
{
if (ignoreBound && item->GetBound()) {
continue;
}
if (smallest == nullptr)
{
if (smallest == nullptr) {
smallest = item;
continue;
}
if (smallest->GetCount() > item->GetCount())
{
if (smallest->GetCount() > item->GetCount()) {
smallest = item;
}
}
@@ -198,26 +164,21 @@ Item* Inventory::FindItemByLot(const LOT lot, const bool ignoreEquipped, const b
return smallest;
}
Item* Inventory::FindItemBySlot(const uint32_t slot) const
{
Item* Inventory::FindItemBySlot(const uint32_t slot) const {
const auto slots = GetSlots();
const auto index = slots.find(slot);
if (index == slots.end())
{
if (index == slots.end()) {
return nullptr;
}
return index->second;
}
Item* Inventory::FindItemBySubKey(LWOOBJID id) const
{
for (const auto& item : items)
{
if (item.second->GetSubKey() == id)
{
Item* Inventory::FindItemBySubKey(LWOOBJID id) const {
for (const auto& item : items) {
if (item.second->GetSubKey() == id) {
return item.second;
}
}
@@ -225,12 +186,10 @@ Item* Inventory::FindItemBySubKey(LWOOBJID id) const
return nullptr;
}
void Inventory::AddManagedItem(Item* item)
{
void Inventory::AddManagedItem(Item* item) {
const auto id = item->GetId();
if (items.find(id) != items.end())
{
if (items.find(id) != items.end()) {
Game::logger->Log("Inventory", "Attempting to add an item with an already present id (%llu)!", id);
return;
@@ -240,8 +199,7 @@ void Inventory::AddManagedItem(Item* item)
const auto slot = item->GetSlot();
if (slots.find(slot) != slots.end())
{
if (slots.find(slot) != slots.end()) {
Game::logger->Log("Inventory", "Attempting to add an item with an already present slot (%i)!", slot);
return;
@@ -252,12 +210,10 @@ void Inventory::AddManagedItem(Item* item)
free--;
}
void Inventory::RemoveManagedItem(Item* item)
{
void Inventory::RemoveManagedItem(Item* item) {
const auto id = item->GetId();
if (items.find(id) == items.end())
{
if (items.find(id) == items.end()) {
Game::logger->Log("Inventory", "Attempting to remove an item with an invalid id (%llu), lot (%i)!", id, item->GetLot());
return;
@@ -268,8 +224,7 @@ void Inventory::RemoveManagedItem(Item* item)
free++;
}
eInventoryType Inventory::FindInventoryTypeForLot(const LOT lot)
{
eInventoryType Inventory::FindInventoryTypeForLot(const LOT lot) {
auto itemComponent = FindItemComponent(lot);
const auto itemType = static_cast<eItemType>(itemComponent.itemType);
@@ -315,16 +270,14 @@ eInventoryType Inventory::FindInventoryTypeForLot(const LOT lot)
}
}
const CDItemComponent& Inventory::FindItemComponent(const LOT lot)
{
const CDItemComponent& Inventory::FindItemComponent(const LOT lot) {
auto* registry = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
auto* itemComponents = CDClientManager::Instance()->GetTable<CDItemComponentTable>("ItemComponent");
const auto componentId = registry->GetByIDAndType(lot, COMPONENT_TYPE_ITEM);
if (componentId == 0)
{
if (componentId == 0) {
Game::logger->Log("Inventory", "Failed to find item component for (%i)!", lot);
return CDItemComponentTable::Default;
@@ -335,8 +288,7 @@ const CDItemComponent& Inventory::FindItemComponent(const LOT lot)
return itemComponent;
}
bool Inventory::IsValidItem(const LOT lot)
{
bool Inventory::IsValidItem(const LOT lot) {
auto* registry = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
const auto componentId = registry->GetByIDAndType(lot, COMPONENT_TYPE_ITEM);
@@ -344,15 +296,12 @@ bool Inventory::IsValidItem(const LOT lot)
return componentId != 0;
}
const std::vector<LOT>& Inventory::GetAllGMItems()
{
const std::vector<LOT>& Inventory::GetAllGMItems() {
return m_GameMasterRestrictedItems;
}
Inventory::~Inventory()
{
for (auto item : items)
{
Inventory::~Inventory() {
for (auto item : items) {
delete item.second;
}