From 8c6ef98b227ee898f03ced7645b189e16ad65a33 Mon Sep 17 00:00:00 2001 From: cooltrain7 Date: Mon, 13 Dec 2021 01:29:38 +0000 Subject: [PATCH 01/33] Replaced cout with correct logger->log call - Use of cout breaks the flow of the console --- dDatabase/Database.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dDatabase/Database.cpp b/dDatabase/Database.cpp index 23fed182..cdadbbaa 100644 --- a/dDatabase/Database.cpp +++ b/dDatabase/Database.cpp @@ -28,7 +28,7 @@ void Database::Connect(const string& host, const string& database, const string& void Database::Destroy() { if (!con) return; - cout << "Destroying MySQL connection!" << endl; + Game::logger->Log("Database", "Destroying MySQL connection!\n"); con->close(); delete con; } //Destroy From 932128a084aaa8e8bb7fc17e441d20aec579f8a1 Mon Sep 17 00:00:00 2001 From: cooltrain7 Date: Mon, 13 Dec 2021 01:31:39 +0000 Subject: [PATCH 02/33] Replaced printf with correct logger->log call - Use of printf breaks the flow of the console --- dMasterServer/MasterServer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 926168a3..6fbe34f7 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -646,7 +646,7 @@ void HandlePacket(Packet* packet) { } case MSG_MASTER_SHUTDOWN_UNIVERSE: { - Game::logger->Log("MasterServer","Received shutdown universe command, ""shutting down in 10 minutes.\n"); + Game::logger->Log("MasterServer","Received shutdown universe command, shutting down in 10 minutes.\n"); shouldShutdown = true; break; } @@ -677,7 +677,7 @@ void ShutdownSequence() { auto* objIdManager = ObjectIDManager::TryInstance(); if (objIdManager != nullptr) { objIdManager->SaveToDatabase(); - printf("Saved objidtracker...\n"); + Game::logger->Log("MasterServer", "Saved ObjectIDTracker to DB\n"); } auto t = std::chrono::high_resolution_clock::now(); @@ -687,7 +687,8 @@ void ShutdownSequence() { exit(0); } - printf("Attempting to shutdown instances, max 60 seconds...\n"); + Game::logger->Log("MasterServer", "Attempting to shutdown instances, max 60 seconds...\n"); + while (true) { auto done = true; From ed151e6d45d28814a6a8bf40e73b70e980283eda Mon Sep 17 00:00:00 2001 From: cooltrain7 Date: Mon, 13 Dec 2021 01:33:51 +0000 Subject: [PATCH 03/33] Added extra information to connection log - Added correct class name to log calls - Added extra zone and instance information in ambiguous log call --- dNet/dServer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dNet/dServer.cpp b/dNet/dServer.cpp index 2a9a612e..245b7683 100644 --- a/dNet/dServer.cpp +++ b/dNet/dServer.cpp @@ -104,13 +104,13 @@ Packet* dServer::ReceiveFromMaster() { if (packet->length < 1) { mMasterPeer->DeallocatePacket(packet); return nullptr; } if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { - mLogger->Log("Server", "Lost our connection to master, shutting DOWN!\n"); + mLogger->Log("dServer", "Lost our connection to master, shutting DOWN!\n"); mMasterConnectionActive = false; //ConnectToMaster(); //We'll just shut down now } if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) { - mLogger->Log("Server", "Established connection to master\n"); + mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)\n",this->GetZoneID(), this->GetInstanceID()); mMasterConnectionActive = true; mMasterSystemAddress = packet->systemAddress; MasterPackets::SendServerInfo(this, packet); @@ -147,7 +147,7 @@ Packet* dServer::ReceiveFromMaster() { } default: - mLogger->Log("Server", "Unknown packet ID from master: %i\n", packet->data[3]); + mLogger->Log("dServer", "Unknown packet ID from master: %i\n", packet->data[3]); } } } From 9b1fbe6c2cb60bc621a2d54917d00d9a04c251fd Mon Sep 17 00:00:00 2001 From: cooltrain7 Date: Mon, 13 Dec 2021 01:37:09 +0000 Subject: [PATCH 04/33] Added extra log information and replaced incorrect print statements - Added extra Zone and Instance information to ambiguous log calls during loading. chat connection, chat connection loss, and shutdown - Fixed correct class names in some log lines - Replaced printf during world shutdown with correct log call with instance and zone info --- dWorldServer/WorldServer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 5d155f29..3e9a8961 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -416,7 +416,7 @@ int main(int argc, char** argv) { if (framesSinceMasterStatus >= 200) { - Game::logger->Log("WorldServer", "Finished loading world, ready up!\n"); + Game::logger->Log("WorldServer", "Finished loading world with zone (%i), ready up!\n", Game::server->GetZoneID()); MasterPackets::SendWorldReady(Game::server, Game::server->GetZoneID(), Game::server->GetInstanceID()); @@ -487,7 +487,7 @@ int main(int argc, char** argv) { if (Game::physicsWorld) Game::physicsWorld = nullptr; if (Game::zoneManager) delete Game::zoneManager; - Game::logger->Log("Test", "Quitting\n"); + Game::logger->Log("WorldServer", "Shutdown complete, zone (%i), instance (%i)\n", Game::server->GetZoneID(), instanceID); Metrics::Clear(); Database::Destroy(); @@ -512,11 +512,11 @@ dLogger * SetupLogger(int zoneID, int instanceID) { void HandlePacketChat(Packet* packet) { if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { - Game::logger->Log("WorldServer", "Lost our connection to chat.\n"); + Game::logger->Log("WorldServer", "Lost our connection to chat, zone(%i), instance(%i)\n", Game::server->GetZoneID(), Game::server->GetInstanceID()); } if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) { - Game::logger->Log("WorldServer", "Established connection to chat\n"); + Game::logger->Log("WorldServer", "Established connection to chat, zone(%i), instance (%i)\n",Game::server -> GetZoneID(), Game::server -> GetInstanceID()); Game::chatSysAddr = packet->systemAddress; } @@ -798,7 +798,7 @@ void HandlePacket(Packet* packet) { case MSG_MASTER_SHUTDOWN: { worldShutdownSequenceStarted = true; - Game::logger->Log("WorldServer", "Got shutdown request\n"); + Game::logger->Log("WorldServer", "Got shutdown request from master, zone (%i), instance (%i)\n", Game::server->GetZoneID(), Game::server->GetInstanceID()); break; } @@ -1095,11 +1095,11 @@ void HandlePacket(Packet* packet) { } } else { - Game::logger->Log("WorldMain", "Couldn't find character to log in with for user %s (%i)!\n", user->GetUsername().c_str(), user->GetAccountID()); + Game::logger->Log("WorldServer", "Couldn't find character to log in with for user %s (%i)!\n", user->GetUsername().c_str(), user->GetAccountID()); Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_CHARACTER_NOT_FOUND); } } else { - Game::logger->Log("WorldMain", "Couldn't get user for level load complete!\n"); + Game::logger->Log("WorldServer", "Couldn't get user for level load complete!\n"); } break; } @@ -1205,7 +1205,7 @@ void WorldShutdownSequence() auto t = std::chrono::high_resolution_clock::now(); auto ticks = 0; - printf("Attempting to shutdown world, max 10 seconds...");; + Game::logger->Log("WorldServer", "Attempting to shutdown world, zone (%i), instance (%i), max 10 seconds...\n", Game::server->GetZoneID(), instanceID); while (true) { From 995042f130c9276275eb1901a5a72df10b73e6ac Mon Sep 17 00:00:00 2001 From: cooltrain7 Date: Mon, 13 Dec 2021 19:45:08 +0000 Subject: [PATCH 05/33] Added missing log newline character --- dGame/dGameMessages/GameMessages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index fad5d7de..4ad302e1 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5673,7 +5673,7 @@ void GameMessages::HandleDoneArrangingWithItem(RakNet::BitStream* inStream, Enti return; } - Game::logger->Log("GameMessages", "Build area found: %llu", buildArea->GetObjectID()); + Game::logger->Log("GameMessages", "Build area found: %llu\n", buildArea->GetObjectID()); GameMessages::SendStartArrangingWithItem( character, From eae1a38705f6dd814f72824e870d815236bdc25e Mon Sep 17 00:00:00 2001 From: Verathian Date: Tue, 21 Dec 2021 22:51:38 -0500 Subject: [PATCH 06/33] Portal Stun Time Reductions --- dScripts/NtAssemblyTubeServer.cpp | 2 +- dScripts/NtParadoxTeleServer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dScripts/NtAssemblyTubeServer.cpp b/dScripts/NtAssemblyTubeServer.cpp index 4653e1c7..5f05f54e 100644 --- a/dScripts/NtAssemblyTubeServer.cpp +++ b/dScripts/NtAssemblyTubeServer.cpp @@ -97,7 +97,7 @@ void NtAssemblyTubeServer::TeleportPlayer(Entity* self, Entity* player) GameMessages::SendPlayAnimation(player, u"tube-resurrect", 4.0f); - const auto animTime = 4; + const auto animTime = 2; const auto playerID = player->GetObjectID(); diff --git a/dScripts/NtParadoxTeleServer.cpp b/dScripts/NtParadoxTeleServer.cpp index dddd17e5..41d21cb7 100644 --- a/dScripts/NtParadoxTeleServer.cpp +++ b/dScripts/NtParadoxTeleServer.cpp @@ -88,7 +88,7 @@ void NtParadoxTeleServer::TeleportPlayer(Entity* self, Entity* player) GameMessages::SendPlayAnimation(player, u"paradox-teleport-in", 4.0f); - const auto animTime = 4; + const auto animTime = 2; const auto playerID = player->GetObjectID(); From 23e269940bd1ae7ea5f6c301cde51c20285075a4 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 21 Dec 2021 23:26:54 -0800 Subject: [PATCH 07/33] Implemented sourceType for SendSetCurrency Implemented sourceType for the function SendSetCurrency. --- dGame/Character.cpp | 11 ++++------- dGame/Character.h | 2 +- dGame/TradingManager.cpp | 4 ++-- dGame/dComponents/DestroyableComponent.cpp | 2 +- dGame/dGameMessages/GameMessages.cpp | 11 +++++------ dGame/dGameMessages/GameMessages.h | 2 +- dGame/dMission/Mission.cpp | 10 ++++++---- dGame/dUtilities/Loot.cpp | 2 +- dGame/dUtilities/Mail.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 4 ++-- 10 files changed, 24 insertions(+), 26 deletions(-) diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 267e4577..55b37420 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); + SetCoins(1000000, 0); } } @@ -567,18 +567,15 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const return pair->second; } -void Character::SetCoins(int64_t newCoins, const bool message) { +void Character::SetCoins(int64_t newCoins, int lootType) { if (newCoins < 0) { newCoins = 0; } m_Coins = newCoins; - - if (message) - { - GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true); - } + + GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootType); } bool Character::HasBeenToWorld(LWOMAPID mapID) const diff --git a/dGame/Character.h b/dGame/Character.h index 57da8640..1f8f27e9 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -314,7 +314,7 @@ public: * @param newCoins the amount of coins to update by * @param message whether to notify the client of the change */ - void SetCoins(int64_t newCoins, bool message = true); + void SetCoins(int64_t newCoins, int lootType); /** * Get the entity this character belongs to diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 20af95e0..294085a5 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); - characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA); + characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, 6); + characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, 6); for (const auto& tradeItem : m_ItemsA) { diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index c84e906a..6a68ce6d 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); + character->SetCoins(coinsTotal, 11); 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 fad5d7de..4f2d464d 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -706,7 +706,7 @@ void GameMessages::SendBroadcastTextToChatbox(Entity* entity, const SystemAddres SEND_PACKET_BROADCAST } -void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent) { +void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int sourceType) { CBITSTREAM CMSGHEADER @@ -729,7 +729,6 @@ void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootTyp bitStream.Write(sourceTradeID != LWOOBJID_EMPTY); if (sourceTradeID != LWOOBJID_EMPTY) bitStream.Write(sourceTradeID); - int sourceType = 0; //For now. bitStream.Write(sourceType != LOOTTYPE_NONE); if (sourceType != LOOTTYPE_NONE) bitStream.Write(sourceType); @@ -4685,7 +4684,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); } - character->SetCoins(character->GetCoins() - (coinCost)); + character->SetCoins(character->GetCoins() - (coinCost), 9); inv->AddItem(item, count); } @@ -4734,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))); + character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), 9); //EntityManager::Instance()->SerializeEntity(player); // so inventory updates GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -4796,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); + character->SetCoins(character->GetCoins() - cost, 9); //EntityManager::Instance()->SerializeEntity(player); // so inventory updates GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -5240,7 +5239,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent auto* ch = entity->GetCharacter(); if (entity->CanPickupCoins(currency)) { - ch->SetCoins(ch->GetCoins() + currency); + ch->SetCoins(ch->GetCoins() + currency, 11); } } diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index e11f502a..993223fe 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -78,7 +78,7 @@ namespace GameMessages { void SendPlayFXEffect(const LWOOBJID& entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary = LWOOBJID_EMPTY, float priority = 1, float scale = 1, bool serialize = true); void SendStopFXEffect(Entity* entity, bool killImmediate, std::string name); void SendBroadcastTextToChatbox(Entity* entity, const SystemAddress& sysAddr, const std::u16string& attrs, const std::u16string& wsText); - void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent); + void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int sourceType); void SendRebuildNotifyState(Entity* entity, int prevState, int state, const LWOOBJID& playerID); void SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID); diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 7f5104e6..8f88478c 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -444,7 +444,7 @@ void Mission::YieldRewards() { auto count = pair.second > 0 ? pair.second : 1; - // Sanitfy check, 6 is the max any mission yields + // Sanity check, 6 is the max any mission yields if (count > 6) { count = 0; } @@ -453,7 +453,7 @@ void Mission::YieldRewards() { } if (info->reward_currency_repeatable > 0) { - character->SetCoins(character->GetCoins() + info->reward_currency_repeatable); + character->SetCoins(character->GetCoins() + info->reward_currency_repeatable, 2); } return; @@ -481,8 +481,10 @@ void Mission::YieldRewards() { inventoryComponent->AddItem(pair.first, count); } - if (info->reward_currency > 0) { - character->SetCoins(character->GetCoins() + info->reward_currency, info->isMission); + if (info->reward_currency > 0 && info->isMission) { + character->SetCoins(character->GetCoins() + info->reward_currency, 2); + } else if (info->reward_currency && !info->isMission) { + character->SetCoins(character->GetCoins() + info->reward_currency, 5); } if (info->reward_maxinventory > 0) { diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 7e0f8323..892ba4d5 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); + character->SetCoins(character->GetCoins() + coins, 10); } 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 2c3baf8c..ecfbaf7e 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); + entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, 3); 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 8be99612..738d30fe 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); + ch->SetCoins(ch->GetCoins() + money, 14); } 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); + ch->SetCoins(money, 14); } // Allow for this on even while not a GM, as it sometimes toggles incorrrectly. From c575294587df9982c3cff2dfbf7d6fd04b769d12 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 21 Dec 2021 23:32:39 -0800 Subject: [PATCH 08/33] Changed variable names Changed variable names to more accurately match what they are --- dGame/Character.cpp | 4 ++-- dGame/Character.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 55b37420..fe18cda8 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -567,7 +567,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const return pair->second; } -void Character::SetCoins(int64_t newCoins, int lootType) { +void Character::SetCoins(int64_t newCoins, int coinSource) { if (newCoins < 0) { newCoins = 0; @@ -575,7 +575,7 @@ void Character::SetCoins(int64_t newCoins, int lootType) { m_Coins = newCoins; - GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootType); + GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, coinSource); } bool Character::HasBeenToWorld(LWOMAPID mapID) const diff --git a/dGame/Character.h b/dGame/Character.h index 1f8f27e9..5d663d3f 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -312,9 +312,9 @@ public: * Updates the current amount of coins of the character by a specified amount, for achievements this is not sent * as it's tracked by the client * @param newCoins the amount of coins to update by - * @param message whether to notify the client of the change + * @param coinSource The source of the loot */ - void SetCoins(int64_t newCoins, int lootType); + void SetCoins(int64_t newCoins, int coinSource); /** * Get the entity this character belongs to 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 09/33] 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. From 29cf7f8998fa8814be4d031ef7ac8b2e18fb2aef Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 22 Dec 2021 00:15:08 -0800 Subject: [PATCH 10/33] Changed ambiguous variables Changed ambiguous variables from int to int32_t to clarify what they are. --- dGame/Character.cpp | 2 +- dGame/Character.h | 2 +- dGame/dGameMessages/GameMessages.cpp | 2 +- dGame/dGameMessages/GameMessages.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dGame/Character.cpp b/dGame/Character.cpp index b6f5fce9..804bf47e 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -567,7 +567,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const return pair->second; } -void Character::SetCoins(int64_t newCoins, int coinSource) { +void Character::SetCoins(int64_t newCoins, int32_t coinSource) { if (newCoins < 0) { newCoins = 0; diff --git a/dGame/Character.h b/dGame/Character.h index 5d663d3f..6b000dd0 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -314,7 +314,7 @@ public: * @param newCoins the amount of coins to update by * @param coinSource The source of the loot */ - void SetCoins(int64_t newCoins, int coinSource); + void SetCoins(int64_t newCoins, int32_t coinSource); /** * Get the entity this character belongs to diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index e9283213..34339895 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -706,7 +706,7 @@ void GameMessages::SendBroadcastTextToChatbox(Entity* entity, const SystemAddres SEND_PACKET_BROADCAST } -void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int sourceType) { +void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int32_t sourceType) { CBITSTREAM CMSGHEADER diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 993223fe..a2182e00 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -78,7 +78,7 @@ namespace GameMessages { void SendPlayFXEffect(const LWOOBJID& entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary = LWOOBJID_EMPTY, float priority = 1, float scale = 1, bool serialize = true); void SendStopFXEffect(Entity* entity, bool killImmediate, std::string name); void SendBroadcastTextToChatbox(Entity* entity, const SystemAddress& sysAddr, const std::u16string& attrs, const std::u16string& wsText); - void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int sourceType); + void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int32_t sourceType); void SendRebuildNotifyState(Entity* entity, int prevState, int state, const LWOOBJID& playerID); void SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID); From f772fedf19b9612b2610770136a0418b9a13b0fa Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 22 Dec 2021 00:43:42 -0800 Subject: [PATCH 11/33] Updated description of SetCoins Updated the description of the Character::SetCoins function to more accurately describe how the function works. --- dGame/Character.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dGame/Character.h b/dGame/Character.h index 6b000dd0..089ec00f 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -309,8 +309,7 @@ public: const int64_t GetCoins() const { return m_Coins; } /** - * Updates the current amount of coins of the character by a specified amount, for achievements this is not sent - * as it's tracked by the client + * Updates the current amount of coins of the character by a specified amount * @param newCoins the amount of coins to update by * @param coinSource The source of the loot */ From 6ff5ae78aa0f27b8e13bb65eea75085fe6c6669c Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 23 Dec 2021 18:46:21 -0800 Subject: [PATCH 12/33] Corrected enum name Corrected the enum name and prefixes of the elements in the enum. --- dCommon/dCommonVars.h | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index 521f856e..4920249d 100644 --- a/dCommon/dCommonVars.h +++ b/dCommon/dCommonVars.h @@ -469,29 +469,29 @@ 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 eLootSourceType : int32_t { + LOOT_SOURCE_NONE = 0, + LOOT_SOURCE_CHEST, + LOOT_SOURCE_MISSION, + LOOT_SOURCE_MAIL, + LOOT_SOURCE_CURRENCY, + LOOT_SOURCE_ACHIEVEMENT, + LOOT_SOURCE_TRADE, + LOOT_SOURCE_QUICKBUILD, + LOOT_SOURCE_DELETION, + LOOT_SOURCE_VENDOR, + LOOT_SOURCE_ACTIVITY, + LOOT_SOURCE_PICKUP, + LOOT_SOURCE_BRICK, + LOOT_SOURCE_PROPERTY, + LOOT_SOURCE_MODERATION, + LOOT_SOURCE_EXHIBIT, + LOOT_SOURCE_INVENTORY, + LOOT_SOURCE_CLAIMCODE, + LOOT_SOURCE_CONSUMPTION, + LOOT_SOURCE_CRAFTING, + LOOT_SOURCE_LEVELREWARD, + LOOT_SOURCE_RELOCATE }; enum eGameActivities : uint32_t { From 6aad799f9551af5cbd0d4a4f93d9b17d2bd24392 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 23 Dec 2021 18:48:08 -0800 Subject: [PATCH 13/33] Updated variable names Updated the variable names to match the enum name update. --- dGame/Character.cpp | 6 +++--- dGame/TradingManager.cpp | 4 ++-- dGame/dComponents/DestroyableComponent.cpp | 2 +- dGame/dGameMessages/GameMessages.cpp | 8 ++++---- dGame/dUtilities/Loot.cpp | 2 +- dGame/dUtilities/Mail.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 804bf47e..4034a21c 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, COIN_SOURCE_NONE); + SetCoins(1000000, LOOT_SOURCE_NONE); } } @@ -567,7 +567,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const return pair->second; } -void Character::SetCoins(int64_t newCoins, int32_t coinSource) { +void Character::SetCoins(int64_t newCoins, int32_t lootSource) { if (newCoins < 0) { newCoins = 0; @@ -575,7 +575,7 @@ void Character::SetCoins(int64_t newCoins, int32_t coinSource) { m_Coins = newCoins; - GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, coinSource); + GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource); } bool Character::HasBeenToWorld(LWOMAPID mapID) const diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 34165e3c..d0ec08d8 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, COIN_SOURCE_TRADE); - characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, COIN_SOURCE_TRADE); + characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, LOOT_SOURCE_TRADE); + characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, LOOT_SOURCE_TRADE); for (const auto& tradeItem : m_ItemsA) { diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 058b7252..686e44e4 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, COIN_SOURCE_PICKUP); + character->SetCoins(coinsTotal, LOOT_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 34339895..0e26252a 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), COIN_SOURCE_VENDOR); + character->SetCoins(character->GetCoins() - (coinCost), LOOT_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)), COIN_SOURCE_VENDOR); + character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), LOOT_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, COIN_SOURCE_VENDOR); + character->SetCoins(character->GetCoins() - cost, LOOT_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, COIN_SOURCE_PICKUP); + ch->SetCoins(ch->GetCoins() + currency, LOOT_SOURCE_PICKUP); } } diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index ecd8bfe7..f051fecd 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, COIN_SOURCE_ACTIVITY); + character->SetCoins(character->GetCoins() + coins, LOOT_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 9cc5a05c..302ba1cd 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, COIN_SOURCE_MAIL); + entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, LOOT_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 c5f4a64b..ed7fddaa 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, COIN_SOURCE_MODERATION); + ch->SetCoins(ch->GetCoins() + money, LOOT_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, COIN_SOURCE_MODERATION); + ch->SetCoins(money, LOOT_SOURCE_MODERATION); } // Allow for this on even while not a GM, as it sometimes toggles incorrrectly. From e84811bdcee9218b4c88c5ad6a3a4e63298cebcf Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 23 Dec 2021 18:49:01 -0800 Subject: [PATCH 14/33] Refactored if statement for coins Refactored the if statement for coins so there is only one SetCoins call for the function. --- dGame/dMission/Mission.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 1d5ab4a0..ac503b51 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, COIN_SOURCE_MISSION); + character->SetCoins(character->GetCoins() + info->reward_currency_repeatable, LOOT_SOURCE_MISSION); } return; @@ -480,11 +480,15 @@ void Mission::YieldRewards() { inventoryComponent->AddItem(pair.first, count); } - - if (info->reward_currency > 0 && info->isMission) { - character->SetCoins(character->GetCoins() + info->reward_currency, COIN_SOURCE_MISSION); - } else if (info->reward_currency && !info->isMission) { - character->SetCoins(character->GetCoins() + info->reward_currency, COIN_SOURCE_ACHIEVEMENT); + + int32_t lootSource = LOOT_SOURCE_NONE; + if (info->reward_currency > 0) { + if(info->isMission) { + lootSource = LOOT_SOURCE_MISSION; + } else { + lootSource = LOOT_SOURCE_ACHIEVEMENT; + } + character->SetCoins(character->GetCoins() + info->reward_currency, lootSource); } if (info->reward_maxinventory > 0) { From e95af79c8adefac38a7c49357d187a4fffbb7cde Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 23 Dec 2021 19:43:19 -0800 Subject: [PATCH 15/33] Consolidated if statement Changed default variable to achievement and removed the else. --- dGame/dMission/Mission.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index ac503b51..a180d32f 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -481,12 +481,10 @@ void Mission::YieldRewards() { inventoryComponent->AddItem(pair.first, count); } - int32_t lootSource = LOOT_SOURCE_NONE; + int32_t lootSource = LOOT_SOURCE_ACHIEVEMENT; if (info->reward_currency > 0) { if(info->isMission) { lootSource = LOOT_SOURCE_MISSION; - } else { - lootSource = LOOT_SOURCE_ACHIEVEMENT; } character->SetCoins(character->GetCoins() + info->reward_currency, lootSource); } From 5e605b30de5709e8c15a5d13c5b829960d9c86a0 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 23 Dec 2021 19:50:17 -0800 Subject: [PATCH 16/33] Grammatical change in a comment Small grammatical change in a comment --- dGame/dMission/Mission.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index a180d32f..5809650c 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -473,7 +473,7 @@ void Mission::YieldRewards() { auto count = pair.second > 0 ? pair.second : 1; - // Sanitfy check, 6 is the max any mission yields + // Sanity check, 6 is the max any mission yields if (count > 6) { count = 0; } From 6e6eee71b3bfc9b3fe8ed9cc70e8c743ee9f2097 Mon Sep 17 00:00:00 2001 From: cooltrain7 Date: Tue, 28 Dec 2021 19:27:46 +0000 Subject: [PATCH 17/33] Added more missing newline characters --- dChatServer/ChatPacketHandler.cpp | 2 +- dGame/dBehaviors/VerifyBehavior.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 737bbba4..899fd355 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -354,7 +354,7 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) if (team->memberIDs.size() > 3) { // no more teams greater than 4 - Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team"); + Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team\n"); return; } diff --git a/dGame/dBehaviors/VerifyBehavior.cpp b/dGame/dBehaviors/VerifyBehavior.cpp index 71f75a18..f4edfece 100644 --- a/dGame/dBehaviors/VerifyBehavior.cpp +++ b/dGame/dBehaviors/VerifyBehavior.cpp @@ -23,7 +23,7 @@ void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS if (self == nullptr) { - Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)", context->originator); + Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)\n", context->originator); return; } From 7c1f392fdf0f5bc55e3dbba5e0b562f89b20289d Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Thu, 30 Dec 2021 19:02:02 +0100 Subject: [PATCH 18/33] Fix initial character XML being malformed XML was missing a space between attributes `lzrw` and `stt`. --- dGame/UserManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 5418e9f3..24b0319e 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -292,7 +292,7 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) xml << "GetAccountID() << "\" cc=\"0\" gm=\"0\" ft=\"0\" llog=\"" << time(NULL) << "\" "; xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\""; - xml << "stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\">"; + xml << " stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\">"; xml << ""; xml << ""; std::string xmlSave1 = xml.str(); From df369612be8a9c426519c653a9f28d1a28276bd0 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Sat, 1 Jan 2022 18:23:14 +0100 Subject: [PATCH 19/33] Add XML attribute spaces consistently --- dGame/UserManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 24b0319e..c01c5687 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -287,12 +287,12 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) std::stringstream xml; xml << ""; + xml << "\" hdc=\"0\" cd=\"" << shirtStyle << "\" lh=\"" << lh << "\" rh=\"" << rh << "\" es=\"" << eyebrows << "\" "; + xml << "ess=\"" << eyes << "\" ms=\"" << mouth << "\"/>"; xml << "GetAccountID() << "\" cc=\"0\" gm=\"0\" ft=\"0\" llog=\"" << time(NULL) << "\" "; - xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\""; - xml << " stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\">"; + xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\" "; + xml << "stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\">"; xml << ""; xml << ""; std::string xmlSave1 = xml.str(); From 74013e07a87231bba52c6c4a0adf47c011277c91 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 03:11:04 -0800 Subject: [PATCH 20/33] Encapsulated variable properly lootSource was not encapsulated properly so this is now fixed. --- dGame/dMission/Mission.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 5809650c..9dde1256 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -481,8 +481,8 @@ void Mission::YieldRewards() { inventoryComponent->AddItem(pair.first, count); } - int32_t lootSource = LOOT_SOURCE_ACHIEVEMENT; if (info->reward_currency > 0) { + int32_t lootSource = LOOT_SOURCE_ACHIEVEMENT; if(info->isMission) { lootSource = LOOT_SOURCE_MISSION; } From a591dbfe9cedbb28c4f671d7dbb5a8015c212137 Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Mon, 3 Jan 2022 16:00:21 +0100 Subject: [PATCH 21/33] Basic tests infrastructure --- CMakeLists.txt | 6 +++++- dCommon/NiPoint3.cpp | 9 ++------- tests/CMakeLists.txt | 21 +++++++++++++++++++++ tests/CommonCxxTests.cpp | 0 tests/CommonCxxTests.h | 4 ++++ tests/TestLDFFormat.cpp | 31 +++++++++++++++++++++++++++++++ tests/TestNiPoint3.cpp | 13 +++++++++++++ 7 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/CommonCxxTests.cpp create mode 100644 tests/CommonCxxTests.h create mode 100644 tests/TestLDFFormat.cpp create mode 100644 tests/TestNiPoint3.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a8395c8a..cb94a2d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.12) project(Darkflame) +include(CTest) # Read variables from file FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables) @@ -492,4 +493,7 @@ if(WIN32) add_dependencies(MasterServer WorldServer) add_dependencies(MasterServer AuthServer) add_dependencies(MasterServer ChatServer) -endif() \ No newline at end of file +endif() + +# Finally, add the tests +add_subdirectory(tests) \ No newline at end of file diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index d74be90b..4baefa13 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -93,14 +93,9 @@ Vector3 NiPoint3::CrossProduct(const Vector3& vec) const { //! Unitize the vector NiPoint3 NiPoint3::Unitize(void) const { - NiPoint3 unitVec; float length = this->Length(); - - unitVec.x = length != 0 ? this->x / length : 0; - unitVec.y = length != 0 ? this->y / length : 0; - unitVec.z = length != 0 ? this->z / length : 0; - - return unitVec; + + return length != 0 ? *this / length : NiPoint3::ZERO; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..eab4bbc9 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,21 @@ +# create the testing file and list of tests +create_test_sourcelist (Tests + CommonCxxTests.cpp + TestNiPoint3.cpp + TestLDFFormat.cpp +) + +# add the executable +add_executable (CommonCxxTests ${Tests}) +target_link_libraries(CommonCxxTests dCommon raknet) + +# remove the test driver source file +set (TestsToRun ${Tests}) +remove (TestsToRun CommonCxxTests.cpp) + +# Add all the ADD_TEST for each test +foreach (test ${TestsToRun}) + get_filename_component (TName ${test} NAME_WE) + add_test (NAME ${TName} COMMAND CommonCxxTests ${TName}) + set_property(TEST ${TName} PROPERTY ENVIRONMENT CTEST_OUTPUT_ON_FAILURE=1) +endforeach () diff --git a/tests/CommonCxxTests.cpp b/tests/CommonCxxTests.cpp new file mode 100644 index 00000000..e69de29b diff --git a/tests/CommonCxxTests.h b/tests/CommonCxxTests.h new file mode 100644 index 00000000..8d2dbbab --- /dev/null +++ b/tests/CommonCxxTests.h @@ -0,0 +1,4 @@ +#include + +#define ASSERT_EQ(a,b) { if (!(a == b)) { printf("Failed assertion: " #a " == " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }} +#define ASSERT_NE(a,b) { if (!(a != b)) { printf("Failed assertion: " #a " != " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }} \ No newline at end of file diff --git a/tests/TestLDFFormat.cpp b/tests/TestLDFFormat.cpp new file mode 100644 index 00000000..276a8175 --- /dev/null +++ b/tests/TestLDFFormat.cpp @@ -0,0 +1,31 @@ +#include "LDFFormat.h" +#include "CommonCxxTests.h" + +/** + * @brief Test parsing an LDF value + * + * @param argc Number of command line arguments for this test + * @param argv Command line arguments + * @return 0 on success, non-zero on failure + */ +int TestLDFFormat(int argc, char** argv) { + // Create + auto* data = LDFBaseData::DataFromString("KEY=0:VALUE"); + + // Check that the data type is correct + ASSERT_EQ(data->GetValueType(), eLDFType::LDF_TYPE_UTF_16); + + // Check that the key is correct + ASSERT_EQ(data->GetKey(), u"KEY"); + + // Check that the value is correct + ASSERT_EQ(((LDFData* )data)->GetValue(), u"VALUE"); + + // Check that the serialization is correct + ASSERT_EQ(data->GetString(), "KEY=0:VALUE"); + + // Cleanup the object + delete data; + + return 0; +} diff --git a/tests/TestNiPoint3.cpp b/tests/TestNiPoint3.cpp new file mode 100644 index 00000000..68da4571 --- /dev/null +++ b/tests/TestNiPoint3.cpp @@ -0,0 +1,13 @@ +#include + +#include "NiPoint3.h" +#include "CommonCxxTests.h" + +int TestNiPoint3(int argc, char** argv) { + // Check that Unitize works + ASSERT_EQ(NiPoint3(3,0,0).Unitize(), NiPoint3::UNIT_X); + // Check what unitize does to a vector of length 0 + ASSERT_EQ(NiPoint3::ZERO.Unitize(), NiPoint3::ZERO); + // If we get here, all was successful + return 0; +} From 1100c57e2db5b4c109feccda11906fd27c92a4ad Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Mon, 3 Jan 2022 16:00:32 +0100 Subject: [PATCH 22/33] Run tests with CI --- .github/workflows/{build.yml => build-and-test.yml} | 1 + 1 file changed, 1 insertion(+) rename .github/workflows/{build.yml => build-and-test.yml} (95%) diff --git a/.github/workflows/build.yml b/.github/workflows/build-and-test.yml similarity index 95% rename from .github/workflows/build.yml rename to .github/workflows/build-and-test.yml index ae7501e8..d91244a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-and-test.yml @@ -20,6 +20,7 @@ jobs: with: configurePreset: 'default' buildPreset: 'default' + testPreset: 'default' - name: artifacts uses: actions/upload-artifact@v2 with: From eb18115c993aa413e70d41c54431c61bfbbd7991 Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Mon, 3 Jan 2022 16:25:47 +0100 Subject: [PATCH 23/33] Update CMakePresets --- CMakePresets.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakePresets.json b/CMakePresets.json index 8b25452f..77d41205 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -36,5 +36,19 @@ "description": "Default Build", "jobs": 2 } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "displayName": "Default Tests", + "description": "Runs all tests", + "execution": { + "jobs": 2 + }, + "output": { + "outputOnFailure": true + } + } ] } From 03d4d84eeb0e9421149f437b1accb74e750619bc Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Mon, 3 Jan 2022 16:28:16 +0100 Subject: [PATCH 24/33] Update CI pipeline --- .github/workflows/build-and-test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d91244a7..cd763ca7 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - build: + build-and-test: runs-on: ubuntu-latest @@ -15,11 +15,17 @@ jobs: - uses: actions/checkout@v2 with: submodules: true - - name: cmake + - name: cmake-configure uses: lukka/run-cmake@v10 with: configurePreset: 'default' + - name: cmake-build + uses: lukka/run-cmake@v10 + with: buildPreset: 'default' + - name: cmake-test + uses: lukka/run-cmake@v10 + with: testPreset: 'default' - name: artifacts uses: actions/upload-artifact@v2 From a06fa39a5d94cb6b59dbfd3ee077f1d0132dfbc8 Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Mon, 3 Jan 2022 16:30:29 +0100 Subject: [PATCH 25/33] Add newline at EOF; re-merge cmake steps --- .github/workflows/build-and-test.yml | 8 +------- tests/CommonCxxTests.h | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cd763ca7..1f4d0dca 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,17 +15,11 @@ jobs: - uses: actions/checkout@v2 with: submodules: true - - name: cmake-configure + - name: cmake uses: lukka/run-cmake@v10 with: configurePreset: 'default' - - name: cmake-build - uses: lukka/run-cmake@v10 - with: buildPreset: 'default' - - name: cmake-test - uses: lukka/run-cmake@v10 - with: testPreset: 'default' - name: artifacts uses: actions/upload-artifact@v2 diff --git a/tests/CommonCxxTests.h b/tests/CommonCxxTests.h index 8d2dbbab..f1894927 100644 --- a/tests/CommonCxxTests.h +++ b/tests/CommonCxxTests.h @@ -1,4 +1,4 @@ #include #define ASSERT_EQ(a,b) { if (!(a == b)) { printf("Failed assertion: " #a " == " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }} -#define ASSERT_NE(a,b) { if (!(a != b)) { printf("Failed assertion: " #a " != " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }} \ No newline at end of file +#define ASSERT_NE(a,b) { if (!(a != b)) { printf("Failed assertion: " #a " != " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }} From f74cc9cb1077dd8cc5b46c215aa6104c4c652ed2 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 16:01:28 -0800 Subject: [PATCH 26/33] Updated variable assignment Changed the variable assignment to be a ternary operator. --- dGame/dMission/Mission.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 9dde1256..ed14429b 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -482,10 +482,7 @@ void Mission::YieldRewards() { } if (info->reward_currency > 0) { - int32_t lootSource = LOOT_SOURCE_ACHIEVEMENT; - if(info->isMission) { - lootSource = LOOT_SOURCE_MISSION; - } + int32_t lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; character->SetCoins(character->GetCoins() + info->reward_currency, lootSource); } From a9da275673c7158e975e010230413c0ae5af5e6f Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 16:01:54 -0800 Subject: [PATCH 27/33] removed extra tab removed extra tab --- dGame/dMission/Mission.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index ed14429b..0eb1a6bb 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -480,7 +480,7 @@ void Mission::YieldRewards() { inventoryComponent->AddItem(pair.first, count); } - + if (info->reward_currency > 0) { int32_t lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; character->SetCoins(character->GetCoins() + info->reward_currency, lootSource); From a92e05c640e71098cf8d250450c5ba5cbcd66c86 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 22:37:40 -0800 Subject: [PATCH 28/33] Update dGame/dGameMessages/GameMessages.cpp Co-authored-by: Xiphoseer --- dGame/dGameMessages/GameMessages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 0e26252a..1df0a3f2 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -706,7 +706,7 @@ void GameMessages::SendBroadcastTextToChatbox(Entity* entity, const SystemAddres SEND_PACKET_BROADCAST } -void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int32_t sourceType) { +void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, eLootSourceType sourceType) { CBITSTREAM CMSGHEADER From 7aed5f0500f7cacc5119863d611bbac09da2dd2f Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 22:37:49 -0800 Subject: [PATCH 29/33] Update dGame/Character.h Co-authored-by: Xiphoseer --- dGame/Character.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/Character.h b/dGame/Character.h index 089ec00f..61017ccb 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -313,7 +313,7 @@ public: * @param newCoins the amount of coins to update by * @param coinSource The source of the loot */ - void SetCoins(int64_t newCoins, int32_t coinSource); + void SetCoins(int64_t newCoins, eLootSourceType coinSource); /** * Get the entity this character belongs to From cb9ce85bdae113fe4da07bf334fa1251800a16e7 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 22:37:53 -0800 Subject: [PATCH 30/33] Update dGame/Character.cpp Co-authored-by: Xiphoseer --- dGame/Character.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 4034a21c..4383ee46 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -567,7 +567,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const return pair->second; } -void Character::SetCoins(int64_t newCoins, int32_t lootSource) { +void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) { if (newCoins < 0) { newCoins = 0; From 329d3d66b37bc4256f0953cfb9f356e28b866fba Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 22:37:58 -0800 Subject: [PATCH 31/33] Update dGame/dGameMessages/GameMessages.h Co-authored-by: Xiphoseer --- dGame/dGameMessages/GameMessages.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index a2182e00..0bc51c01 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -78,7 +78,7 @@ namespace GameMessages { void SendPlayFXEffect(const LWOOBJID& entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary = LWOOBJID_EMPTY, float priority = 1, float scale = 1, bool serialize = true); void SendStopFXEffect(Entity* entity, bool killImmediate, std::string name); void SendBroadcastTextToChatbox(Entity* entity, const SystemAddress& sysAddr, const std::u16string& attrs, const std::u16string& wsText); - void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, int32_t sourceType); + void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, eLootSourceType sourceType); void SendRebuildNotifyState(Entity* entity, int prevState, int state, const LWOOBJID& playerID); void SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID); From cca5b79e9144eddd2f1b91be56d185e340428d56 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 3 Jan 2022 23:05:56 -0800 Subject: [PATCH 32/33] Update Mission.cpp --- dGame/dMission/Mission.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 0eb1a6bb..8fadc49a 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -482,7 +482,7 @@ void Mission::YieldRewards() { } if (info->reward_currency > 0) { - int32_t lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; + eLootSourceType lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; character->SetCoins(character->GetCoins() + info->reward_currency, lootSource); } From 227b82c446e2fe256bf3d6791a29e5ad4d39ee2c Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Tue, 4 Jan 2022 09:26:43 +0100 Subject: [PATCH 33/33] Add newline at EOF [skip ci] --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb94a2d3..85d2316a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,4 +496,5 @@ add_dependencies(MasterServer ChatServer) endif() # Finally, add the tests -add_subdirectory(tests) \ No newline at end of file +add_subdirectory(tests) +