From 97f8e9e9fc62763bfd60df7a4dc43c32c917845b Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 22 Dec 2021 00:01:55 -0800 Subject: [PATCH] Added enum for coin sources Added an enum for coin sources as to avoid leaving a random number in the code. --- dCommon/dCommonVars.h | 25 ++++++++++++++++++++++ dGame/Character.cpp | 2 +- dGame/TradingManager.cpp | 4 ++-- dGame/dComponents/DestroyableComponent.cpp | 2 +- dGame/dGameMessages/GameMessages.cpp | 8 +++---- dGame/dMission/Mission.cpp | 6 +++--- dGame/dUtilities/Loot.cpp | 2 +- dGame/dUtilities/Mail.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 4 ++-- 9 files changed, 40 insertions(+), 15 deletions(-) diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index 77570282..521f856e 100644 --- a/dCommon/dCommonVars.h +++ b/dCommon/dCommonVars.h @@ -469,6 +469,31 @@ enum eRebuildState : uint32_t { REBUILD_INCOMPLETE }; +enum eCoinSourceType : int32_t { + COIN_SOURCE_NONE = 0, + COIN_SOURCE_CHEST, + COIN_SOURCE_MISSION, + COIN_SOURCE_MAIL, + COIN_SOURCE_CURRENCY, + COIN_SOURCE_ACHIEVEMENT, + COIN_SOURCE_TRADE, + COIN_SOURCE_QUICKBUILD, + COIN_SOURCE_DELETION, + COIN_SOURCE_VENDOR, + COIN_SOURCE_ACTIVITY, + COIN_SOURCE_PICKUP, + COIN_SOURCE_BRICK, + COIN_SOURCE_PROPERTY, + COIN_SOURCE_MODERATION, + COIN_SOURCE_EXHIBIT, + COIN_SOURCE_INVENTORY, + COIN_SOURCE_CLAIMCODE, + COIN_SOURCE_CONSUMPTION, + COIN_SOURCE_CRAFTING, + COIN_SOURCE_LEVELREWARD, + COIN_SOURCE_RELOCATE +}; + enum eGameActivities : uint32_t { ACTIVITY_NONE, ACTIVITY_QUICKBUILDING, diff --git a/dGame/Character.cpp b/dGame/Character.cpp index fe18cda8..b6f5fce9 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -527,7 +527,7 @@ void Character::OnZoneLoad() */ if (HasPermission(PermissionMap::Old)) { if (GetCoins() > 1000000) { - SetCoins(1000000, 0); + SetCoins(1000000, COIN_SOURCE_NONE); } } diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 294085a5..34165e3c 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -151,8 +151,8 @@ void Trade::Complete() if (inventoryA == nullptr || inventoryB == nullptr || characterA == nullptr || characterB == nullptr || missionsA == nullptr || missionsB == nullptr) return; - characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, 6); - characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, 6); + characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, COIN_SOURCE_TRADE); + characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, COIN_SOURCE_TRADE); for (const auto& tradeItem : m_ItemsA) { diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 6a68ce6d..058b7252 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -818,7 +818,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose); } - character->SetCoins(coinsTotal, 11); + character->SetCoins(coinsTotal, COIN_SOURCE_PICKUP); Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity(); for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) { diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 4f2d464d..e9283213 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -4684,7 +4684,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); } - character->SetCoins(character->GetCoins() - (coinCost), 9); + character->SetCoins(character->GetCoins() - (coinCost), COIN_SOURCE_VENDOR); inv->AddItem(item, count); } @@ -4733,7 +4733,7 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit //inv->RemoveItem(count, -1, iObjID); inv->MoveItemToInventory(item, VENDOR_BUYBACK, count, true, false, true); - character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), 9); + character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), COIN_SOURCE_VENDOR); //EntityManager::Instance()->SerializeEntity(player); // so inventory updates GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -4795,7 +4795,7 @@ void GameMessages::HandleBuybackFromVendor(RakNet::BitStream* inStream, Entity* //inv->RemoveItem(count, -1, iObjID); inv->MoveItemToInventory(item, Inventory::FindInventoryTypeForLot(item->GetLot()), count, true, false); - character->SetCoins(character->GetCoins() - cost, 9); + character->SetCoins(character->GetCoins() - cost, COIN_SOURCE_VENDOR); //EntityManager::Instance()->SerializeEntity(player); // so inventory updates GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -5239,7 +5239,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent auto* ch = entity->GetCharacter(); if (entity->CanPickupCoins(currency)) { - ch->SetCoins(ch->GetCoins() + currency, 11); + ch->SetCoins(ch->GetCoins() + currency, COIN_SOURCE_PICKUP); } } diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 8f88478c..1d5ab4a0 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -453,7 +453,7 @@ void Mission::YieldRewards() { } if (info->reward_currency_repeatable > 0) { - character->SetCoins(character->GetCoins() + info->reward_currency_repeatable, 2); + character->SetCoins(character->GetCoins() + info->reward_currency_repeatable, COIN_SOURCE_MISSION); } return; @@ -482,9 +482,9 @@ void Mission::YieldRewards() { } if (info->reward_currency > 0 && info->isMission) { - character->SetCoins(character->GetCoins() + info->reward_currency, 2); + character->SetCoins(character->GetCoins() + info->reward_currency, COIN_SOURCE_MISSION); } else if (info->reward_currency && !info->isMission) { - character->SetCoins(character->GetCoins() + info->reward_currency, 5); + character->SetCoins(character->GetCoins() + info->reward_currency, COIN_SOURCE_ACHIEVEMENT); } if (info->reward_maxinventory > 0) { diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 892ba4d5..ecd8bfe7 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -316,7 +316,7 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac auto* character = player->GetCharacter(); - character->SetCoins(character->GetCoins() + coins, 10); + character->SetCoins(character->GetCoins() + coins, COIN_SOURCE_ACTIVITY); } void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) { diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index ecfbaf7e..9cc5a05c 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -262,7 +262,7 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd } Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::Success); - entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, 3); + entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, COIN_SOURCE_MAIL); Game::logger->Log("Mail", "Seeing if we need to remove item with ID/count/LOT: %i %i %i\n", itemID, attachmentCount, itemLOT); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 738d30fe..c5f4a64b 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1326,7 +1326,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } auto* ch = entity->GetCharacter(); - ch->SetCoins(ch->GetCoins() + money, 14); + ch->SetCoins(ch->GetCoins() + money, COIN_SOURCE_MODERATION); } if ((chatCommand == "setcurrency") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { @@ -1339,7 +1339,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } auto* ch = entity->GetCharacter(); - ch->SetCoins(money, 14); + ch->SetCoins(money, COIN_SOURCE_MODERATION); } // Allow for this on even while not a GM, as it sometimes toggles incorrrectly.