From 6b44936c68f1755db3658bf30c904b53fb0a521a Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 12 Apr 2022 14:06:03 -0500 Subject: [PATCH 01/48] check if map exists for testmap --- dGame/dUtilities/SlashCommandHandler.cpp | 231 ++++++++++------------- 1 file changed, 99 insertions(+), 132 deletions(-) diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 901bccbf9..5811eae03 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -66,22 +66,22 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr) { std::string chatCommand; std::vector args; - + uint32_t breakIndex = 0; for (uint32_t i = 1; i < command.size(); ++i) { if (command[i] == L' ') { breakIndex = i; break; } - + chatCommand.push_back(static_cast(command[i])); breakIndex++; } - + uint32_t index = ++breakIndex; while (true) { std::string arg; - + while (index < command.size()) { if (command[index] == L' ') { args.push_back(arg); @@ -89,24 +89,24 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit index++; continue; } - + arg.push_back(static_cast(command[index])); index++; } - + if (arg != "") { args.push_back(arg); } - + break; } //Game::logger->Log("SlashCommandHandler", "Received chat command \"%s\"\n", GeneralUtils::UTF16ToWTF8(command).c_str()); - + User* user = UserManager::Instance()->GetUser(sysAddr); if ((chatCommand == "setgmlevel" || chatCommand == "makegm" || chatCommand == "gmlevel") && user->GetMaxGMLevel() > GAME_MASTER_LEVEL_CIVILIAN) { if (args.size() != 1) return; - + uint32_t level; if (!GeneralUtils::TryParse(args[0], level)) @@ -129,7 +129,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (level == entity->GetGMLevel()) return; bool success = user->GetMaxGMLevel() >= level; - + if (success) { if (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN && level == GAME_MASTER_LEVEL_CIVILIAN) { @@ -174,10 +174,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit character->SetPvpEnabled(!character->GetPvpEnabled()); EntityManager::Instance()->SerializeEntity(entity); - + std::stringstream message; message << character->GetName() << " changed their PVP flag to " << std::to_string(character->GetPvpEnabled()) << "!"; - + ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, GeneralUtils::ASCIIToUTF16(message.str()), true); return; @@ -206,14 +206,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit { std::stringstream message; message << "Your latest ping: " << std::to_string(Game::server->GetLatestPing(sysAddr)) << "ms"; - + ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message.str())); } else { std::stringstream message; message << "Your average ping: " << std::to_string(Game::server->GetPing(sysAddr)) << "ms"; - + ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message.str())); } return; @@ -293,7 +293,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit Game::logger->Log("SlashCommandHandler", "Sending \n%s\n", customText.c_str()); GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", &args); - + delete visiable; delete text; }); @@ -345,7 +345,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if ((chatCommand == "join" && !args.empty())) { ChatPackets::SendSystemMessage(sysAddr, u"Requesting private map..."); const auto& password = args[0]; - + ZoneInstanceManager::Instance()->RequestPrivateZone(Game::server, false, password, [=](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) { Game::logger->Log("UserManager", "Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i\n", sysAddr.ToString(), zoneID, zoneInstance, zoneClone, mythranShift == true ? "true" : "false", serverIP.c_str(), serverPort); @@ -369,12 +369,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "resurrect") { ScriptedActivityComponent* scriptedActivityComponent = dZoneManager::Instance()->GetZoneControlObject()->GetComponent(); - + if (scriptedActivityComponent) { // check if user is in activity world and if so, they can't resurrect ChatPackets::SendSystemMessage(sysAddr, u"You cannot resurrect in an activity world."); return; } - + GameMessages::SendResurrect(entity); } @@ -397,7 +397,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit stmt->setString(2, GeneralUtils::UTF16ToWTF8(command).c_str()); stmt->execute(); delete stmt; - + if (chatCommand == "setminifig" && args.size() == 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { // could break characters so only allow if GM > 0 int32_t minifigItemId; if (!GeneralUtils::TryParse(args[1], minifigItemId)) { @@ -435,13 +435,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig item to change, try one of the following: Eyebrows, Eyes, HairColor, HairStyle, Pants, LeftHand, Mouth, RightHand, Shirt, Hands"); return; } - + EntityManager::Instance()->ConstructEntity(entity); ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(lowerName) + u" set to " + (GeneralUtils::to_u16string(minifigItemId))); GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); // need to retoggle because it gets reenabled on creation of new character } - + if ((chatCommand == "playanimation" || chatCommand == "playanim") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { std::u16string anim = GeneralUtils::ASCIIToUTF16(args[0], args[0].size()); GameMessages::SendPlayAnimation(entity, anim); @@ -451,15 +451,15 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit for (const auto& pair : EntityManager::Instance()->GetSpawnPointEntities()) { ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(pair.first)); } - + ChatPackets::SendSystemMessage(sysAddr, u"Current: " + GeneralUtils::ASCIIToUTF16(entity->GetCharacter()->GetTargetScene())); return; } - + if (chatCommand == "unlock-emote" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { int32_t emoteID; - + if (!GeneralUtils::TryParse(args[0], emoteID)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid emote ID."); @@ -491,7 +491,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "speedboost" && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { float boost; - + if (!GeneralUtils::TryParse(args[0], boost)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid boost."); @@ -515,7 +515,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit entity->SetVar(u"freecam", state); GameMessages::SendSetPlayerControlScheme(entity, static_cast(state ? 9 : 1)); - + ChatPackets::SendSystemMessage(sysAddr, u"Toggled freecam."); return; } @@ -528,9 +528,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid control scheme."); return; } - + GameMessages::SendSetPlayerControlScheme(entity, static_cast(scheme)); - + ChatPackets::SendSystemMessage(sysAddr, u"Switched control scheme."); return; } @@ -552,7 +552,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit AMFArrayValue args; args.InsertValue("state", value); GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, "pushGameState", &args); - + ChatPackets::SendSystemMessage(sysAddr, u"Switched UI state."); delete value; @@ -566,7 +566,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit AMFArrayValue amfArgs; amfArgs.InsertValue("visible", value); GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, args[0], &amfArgs); - + ChatPackets::SendSystemMessage(sysAddr, u"Toggled UI state."); delete value; @@ -584,12 +584,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid size."); return; } - + InventoryComponent* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); if (inventory) { auto* items = inventory->GetInventory(ITEMS); - + items->SetSize(size); } @@ -610,7 +610,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit else { ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?"); } - + return; } @@ -624,7 +624,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid mission id."); return; } - + auto comp = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); if (comp) comp->AcceptMission(missionID, true); return; @@ -640,7 +640,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid mission id."); return; } - + auto comp = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); if (comp) comp->CompleteMission(missionID, true); return; @@ -697,7 +697,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid mission id."); return; } - + auto* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); if (comp == nullptr) { @@ -709,7 +709,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (mission == nullptr) { return; } - + mission->SetMissionState(MissionState::MISSION_STATE_ACTIVE); return; @@ -791,7 +791,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid item LOT."); return; } - + InventoryComponent * inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); inventory->AddItem(itemLOT, 1); @@ -839,7 +839,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (receiverID == 0) { ChatPackets::SendSystemMessage(sysAddr, u"Failed to find that player"); - + return; } @@ -866,7 +866,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ins->setInt(11, 1); ins->execute(); delete ins; - + ChatPackets::SendSystemMessage(sysAddr, u"Mail sent"); return; @@ -883,7 +883,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS); } - + if (chatCommand == "title" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { std::string name = entity->GetCharacter()->GetName() + " - "; @@ -901,19 +901,19 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (args.size() == 3) { float x, y, z; - + if (!GeneralUtils::TryParse(args[0], x)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid x."); return; } - + if (!GeneralUtils::TryParse(args[1], y)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid y."); return; } - + if (!GeneralUtils::TryParse(args[2], z)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid z."); @@ -923,7 +923,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit pos.SetX(x); pos.SetY(y); pos.SetZ(z); - + Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to %f, %f, %f\n", entity->GetObjectID(), pos.x, pos.y, pos.z); GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr); } else if (args.size() == 2) { @@ -945,7 +945,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit pos.SetY(0.0f); pos.SetZ(z); - + Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to X: %f, Z: %f\n", entity->GetObjectID(), pos.x, pos.z); GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr); } else { @@ -1018,7 +1018,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (player == nullptr) { auto* accountQuery = Database::CreatePreppedStmt("SELECT account_id, id FROM charinfo WHERE name=? LIMIT 1;"); - + accountQuery->setString(1, args[0]); auto result = accountQuery->executeQuery(); @@ -1028,7 +1028,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit while (result->next()) { accountId = result->getUInt(1); characterId = result->getUInt64(2); - + characterId = GeneralUtils::SetBit(characterId, OBJECT_BIT_CHARACTER); characterId = GeneralUtils::SetBit(characterId, OBJECT_BIT_PERSISTENT); } @@ -1086,7 +1086,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit userUpdate->executeUpdate(); delete userUpdate; - + char buffer[32] = "brought up for review.\0"; if (expire != 1) @@ -1095,12 +1095,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit // Format: Mo, 15.06.2009 20:20:00 std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", ptm); } - + const auto timeStr = GeneralUtils::ASCIIToUTF16(std::string(buffer)); ChatPackets::SendSystemMessage(sysAddr, u"Muted: " + GeneralUtils::ASCIIToUTF16(args[0]) + u" until " + timeStr); - //Notify chat about it + //Notify chat about it CBITSTREAM; PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_MUTE_UPDATE); @@ -1143,7 +1143,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (player == nullptr) { auto* accountQuery = Database::CreatePreppedStmt("SELECT account_id FROM charinfo WHERE name=? LIMIT 1;"); - + accountQuery->setString(1, args[0]); auto result = accountQuery->executeQuery(); @@ -1189,7 +1189,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } //------------------------------------------------- - + if (chatCommand == "buffme" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); if (dest) { @@ -1200,13 +1200,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetImagination(999); dest->SetMaxImagination(999.0f); } - + EntityManager::Instance()->SerializeEntity(entity); } if (chatCommand == "startcelebration" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { int32_t celebration; - + if (!GeneralUtils::TryParse(args[0], celebration)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid celebration."); @@ -1215,7 +1215,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit GameMessages::SendStartCelebrationEffect(entity, entity->GetSystemAddress(), celebration); } - + if (chatCommand == "buffmed" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); if (dest) { @@ -1229,7 +1229,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit EntityManager::Instance()->SerializeEntity(entity); } - + if (chatCommand == "refillstats" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); if (dest) { @@ -1240,7 +1240,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit EntityManager::Instance()->SerializeEntity(entity); } - + if (chatCommand == "lookup" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { std::string query = "SELECT `id`, `name` FROM `Objects` WHERE `displayName` LIKE '%" + args[0] + "%' OR `name` LIKE '%" + args[0] + "%' OR `description` LIKE '%" + args[0] + "%'"; auto tables = CDClientDatabase::ExecuteQuery(query.c_str()); @@ -1250,13 +1250,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit tables.nextRow(); } } - + if (chatCommand == "spawn" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); if (!comp) return; uint32_t lot; - + if (!GeneralUtils::TryParse(args[0], lot)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid lot."); @@ -1292,7 +1292,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit CharacterComponent* character = entity->GetComponent(); if (character) character->SetUScore(character->GetUScore() + uscore); - // LOOT_SOURCE_MODERATION should work but it doesn't. Relog to see uscore changes + // LOOT_SOURCE_MODERATION should work but it doesn't. Relog to see uscore changes GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, LOOT_SOURCE_MODERATION); } @@ -1300,7 +1300,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit const auto position = entity->GetPosition(); ChatPackets::SendSystemMessage(sysAddr, u"<" + (GeneralUtils::to_u16string(position.x)) + u", " + (GeneralUtils::to_u16string(position.y)) + u", " + (GeneralUtils::to_u16string(position.z)) + u">"); - + std::cout << position.x << ", " << position.y << ", " << position.z << std::endl; } @@ -1357,7 +1357,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "gminvis" && entity->GetParentUser()->GetMaxGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); - + return; } @@ -1377,7 +1377,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit { destroyableComponent->SetIsGMImmune(state); } - + return; } @@ -1404,7 +1404,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit { buffComponent->ApplyBuff(id, duration, entity->GetObjectID()); } - + return; } @@ -1439,10 +1439,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } const auto objid = entity->GetObjectID(); - + if (force || CheckIfAccessibleZone(reqZone)) { // to prevent tomfoolery bool darwin = true; //Putting this on true, as I'm sick of having to wait 3-4 seconds on a transfer while trying to quickly moderate properties - + Character* character = entity->GetCharacter(); if (character) { std::string lowerName = character->GetName(); @@ -1487,7 +1487,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); }); - + return; }); } else { @@ -1518,7 +1518,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit const auto& password = args[2]; ZoneInstanceManager::Instance()->CreatePrivateZone(Game::server, zone, clone, password); - + ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16("Sent request for private zone with password: " + password)); return; @@ -1593,7 +1593,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } } } - + if (chatCommand == "triggerspawner" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { auto spawners = dZoneManager::Instance()->GetSpawnersByName(args[0]); @@ -1675,13 +1675,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage( sysAddr, - GeneralUtils::ASCIIToUTF16(Metrics::MetricVariableToString(variable)) + - u": " + - GeneralUtils::to_u16string(Metrics::ToMiliseconds(metric->average)) + + GeneralUtils::ASCIIToUTF16(Metrics::MetricVariableToString(variable)) + + u": " + + GeneralUtils::to_u16string(Metrics::ToMiliseconds(metric->average)) + u"ms" ); } - + ChatPackets::SendSystemMessage( sysAddr, u"Peak RSS: " + GeneralUtils::to_u16string((float) ((double) Metrics::GetPeakRSS() / 1.024e6)) + @@ -1728,11 +1728,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } std::u16string message = u"Ran loot drops looking for " - + GeneralUtils::to_u16string(targetLot) - + u", " - + GeneralUtils::to_u16string(loops) - + u" times. It ran " - + GeneralUtils::to_u16string(totalRuns) + + GeneralUtils::to_u16string(targetLot) + + u", " + + GeneralUtils::to_u16string(loops) + + u" times. It ran " + + GeneralUtils::to_u16string(totalRuns) + u" times. Averaging out at " + GeneralUtils::to_u16string((float) totalRuns / loops); @@ -1763,7 +1763,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit auto closestDistance = 0.0f; const auto candidates = EntityManager::Instance()->GetEntitiesByComponent(component); - + for (auto* candidate : candidates) { if (candidate->GetLOT() == 1 || candidate->GetLOT() == 8092) @@ -1775,16 +1775,16 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit { continue; } - + if (closest == nullptr) { closest = candidate; closestDistance = NiPoint3::Distance(candidate->GetPosition(), reference); - + continue; } - + const auto distance = NiPoint3::Distance(candidate->GetPosition(), reference); if (distance < closestDistance) @@ -1811,7 +1811,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit header << info.name << " [" << std::to_string(info.id) << "]" << " " << std::to_string(closestDistance) << " " << std::to_string(closest->IsSleeping()); ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(header.str())); - + for (const auto& pair : closest->GetComponents()) { auto id = pair.first; @@ -1824,7 +1824,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (args.size() >= 2) - { + { if (args[1] == "-m" && args.size() >= 3) { auto* movingPlatformComponent = closest->GetComponent(); @@ -1868,7 +1868,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit const auto postion = closest->GetPosition(); ChatPackets::SendSystemMessage( - sysAddr, + sysAddr, GeneralUtils::ASCIIToUTF16("< " + std::to_string(postion.x) + ", " + std::to_string(postion.y) + ", " + std::to_string(postion.z) + " >") ); } @@ -1931,54 +1931,21 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } bool SlashCommandHandler::CheckIfAccessibleZone(const unsigned int zoneID) { - switch (zoneID) { - case 98: - case 1000: - case 1001: - - case 1100: - case 1101: - case 1150: - case 1151: - case 1152: - - case 1200: - case 1201: - - case 1250: - case 1251: - case 1260: - - case 1300: - case 1350: - case 1351: - - case 1400: - case 1401: - case 1450: - case 1451: - - case 1600: - case 1601: - case 1602: - case 1603: - case 1604: - - case 1700: - case 1800: - case 1900: - case 2000: - - case 58004: - case 58005: - case 58006: + //We're gonna go ahead and presume we've got the db loaded already: + CDZoneTableTable * zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + const CDZoneTable* zone = zoneTable->Query(zoneID); + if (zone != nullptr) { + std::string zonePath = "./res/maps/" + zone->zoneName; + std::transform(zonePath.begin(), zonePath.end(), zonePath.begin(), ::tolower); + std::ifstream f(zonePath.c_str()); + if (f.good()){ return true; - - default: + } else { return false; + } + } else { + return false; } - - return false; } void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::string& message) { @@ -1998,7 +1965,7 @@ void SlashCommandHandler::SendAnnouncement(const std::string& title, const std:: titleValue = nullptr; messageValue = nullptr; - //Notify chat about it + //Notify chat about it CBITSTREAM; PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_ANNOUNCEMENT); From 40d396c7e26bac306bbfabd1a40c3cc8446ed66e Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 12 Apr 2022 18:05:22 -0500 Subject: [PATCH 02/48] simplify --- dGame/dUtilities/SlashCommandHandler.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 5811eae03..5907d7d8f 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1931,18 +1931,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } bool SlashCommandHandler::CheckIfAccessibleZone(const unsigned int zoneID) { - //We're gonna go ahead and presume we've got the db loaded already: + //We're gonna go ahead and presume we've got the db loaded already: CDZoneTableTable * zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); const CDZoneTable* zone = zoneTable->Query(zoneID); if (zone != nullptr) { std::string zonePath = "./res/maps/" + zone->zoneName; std::transform(zonePath.begin(), zonePath.end(), zonePath.begin(), ::tolower); std::ifstream f(zonePath.c_str()); - if (f.good()){ - return true; - } else { - return false; - } + return f.good() } else { return false; } From 4a98c46fb938871f9ef34ab73b0f6cb1d682d801 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 12 Apr 2022 18:30:46 -0500 Subject: [PATCH 03/48] fix tabs/spaces --- dGame/dUtilities/SlashCommandHandler.cpp | 240 +++++++++++------------ 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 5907d7d8f..42a4a565b 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -64,48 +64,48 @@ #include "ScriptedActivityComponent.h" void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr) { - std::string chatCommand; - std::vector args; + std::string chatCommand; + std::vector args; - uint32_t breakIndex = 0; - for (uint32_t i = 1; i < command.size(); ++i) { - if (command[i] == L' ') { - breakIndex = i; - break; - } + uint32_t breakIndex = 0; + for (uint32_t i = 1; i < command.size(); ++i) { + if (command[i] == L' ') { + breakIndex = i; + break; + } - chatCommand.push_back(static_cast(command[i])); - breakIndex++; - } + chatCommand.push_back(static_cast(command[i])); + breakIndex++; + } - uint32_t index = ++breakIndex; - while (true) { - std::string arg; + uint32_t index = ++breakIndex; + while (true) { + std::string arg; - while (index < command.size()) { - if (command[index] == L' ') { - args.push_back(arg); - arg = ""; - index++; - continue; - } + while (index < command.size()) { + if (command[index] == L' ') { + args.push_back(arg); + arg = ""; + index++; + continue; + } - arg.push_back(static_cast(command[index])); - index++; - } + arg.push_back(static_cast(command[index])); + index++; + } - if (arg != "") { - args.push_back(arg); - } + if (arg != "") { + args.push_back(arg); + } - break; - } + break; + } - //Game::logger->Log("SlashCommandHandler", "Received chat command \"%s\"\n", GeneralUtils::UTF16ToWTF8(command).c_str()); + //Game::logger->Log("SlashCommandHandler", "Received chat command \"%s\"\n", GeneralUtils::UTF16ToWTF8(command).c_str()); - User* user = UserManager::Instance()->GetUser(sysAddr); - if ((chatCommand == "setgmlevel" || chatCommand == "makegm" || chatCommand == "gmlevel") && user->GetMaxGMLevel() > GAME_MASTER_LEVEL_CIVILIAN) { - if (args.size() != 1) return; + User* user = UserManager::Instance()->GetUser(sysAddr); + if ((chatCommand == "setgmlevel" || chatCommand == "makegm" || chatCommand == "gmlevel") && user->GetMaxGMLevel() > GAME_MASTER_LEVEL_CIVILIAN) { + if (args.size() != 1) return; uint32_t level; @@ -127,10 +127,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit level = user->GetMaxGMLevel(); } - if (level == entity->GetGMLevel()) return; - bool success = user->GetMaxGMLevel() >= level; + if (level == entity->GetGMLevel()) return; + bool success = user->GetMaxGMLevel() >= level; - if (success) { + if (success) { if (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN && level == GAME_MASTER_LEVEL_CIVILIAN) { GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); @@ -140,12 +140,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); } - WorldPackets::SendGMLevelChange(sysAddr, success, user->GetMaxGMLevel(), entity->GetGMLevel(), level); - GameMessages::SendChatModeUpdate(entity->GetObjectID(), level); - entity->SetGMLevel(level); - Game::logger->Log("SlashCommandHandler", "User %s (%i) has changed their GM level to %i for charID %llu\n", user->GetUsername().c_str(), user->GetAccountID(), level, entity->GetObjectID()); - } - } + WorldPackets::SendGMLevelChange(sysAddr, success, user->GetMaxGMLevel(), entity->GetGMLevel(), level); + GameMessages::SendChatModeUpdate(entity->GetObjectID(), level); + entity->SetGMLevel(level); + Game::logger->Log("SlashCommandHandler", "User %s (%i) has changed their GM level to %i for charID %llu\n", user->GetUsername().c_str(), user->GetAccountID(), level, entity->GetObjectID()); + } + } #ifndef DEVELOPER_SERVER if ((entity->GetGMLevel() > user->GetMaxGMLevel()) || (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN && user->GetMaxGMLevel() == GAME_MASTER_LEVEL_JUNIOR_DEVELOPER)) @@ -362,7 +362,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit }); } - if (user->GetMaxGMLevel() == 0 || entity->GetGMLevel() >= 0) { + if (user->GetMaxGMLevel() == 0 || entity->GetGMLevel() >= 0) { if (chatCommand == "die") { entity->Smash(entity->GetObjectID()); } @@ -389,14 +389,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (entity->GetGMLevel() == 0) return; - } + } // Log command to database - auto stmt = Database::CreatePreppedStmt("INSERT INTO command_log (character_id, command) VALUES (?, ?);"); - stmt->setInt(1, entity->GetCharacter()->GetID()); + auto stmt = Database::CreatePreppedStmt("INSERT INTO command_log (character_id, command) VALUES (?, ?);"); + stmt->setInt(1, entity->GetCharacter()->GetID()); stmt->setString(2, GeneralUtils::UTF16ToWTF8(command).c_str()); - stmt->execute(); - delete stmt; + stmt->execute(); + delete stmt; if (chatCommand == "setminifig" && args.size() == 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { // could break characters so only allow if GM > 0 int32_t minifigItemId; @@ -656,7 +656,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - entity->GetCharacter()->SetPlayerFlag(flagId, true); + entity->GetCharacter()->SetPlayerFlag(flagId, true); } if (chatCommand == "setflag" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 2) @@ -672,7 +672,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, u"Invalid flag type."); return; } - entity->GetCharacter()->SetPlayerFlag(flagId, onOffFlag == "on"); + entity->GetCharacter()->SetPlayerFlag(flagId, onOffFlag == "on"); } if (chatCommand == "clearflag" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { @@ -684,7 +684,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - entity->GetCharacter()->SetPlayerFlag(flagId, false); + entity->GetCharacter()->SetPlayerFlag(flagId, false); } if (chatCommand == "resetmission" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { @@ -782,8 +782,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage(sysAddr, msg); } - if (chatCommand == "gmadditem" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - if (args.size() == 1) { + if (chatCommand == "gmadditem" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { + if (args.size() == 1) { uint32_t itemLOT; if (!GeneralUtils::TryParse(args[0], itemLOT)) @@ -795,7 +795,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit InventoryComponent * inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); inventory->AddItem(itemLOT, 1); - } else if(args.size() == 2) { + } else if(args.size() == 2) { uint32_t itemLOT; if (!GeneralUtils::TryParse(args[0], itemLOT)) @@ -817,9 +817,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit inventory->AddItem(itemLOT, count); } else { - ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /gmadditem "); - } - } + ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /gmadditem "); + } + } if (chatCommand == "mailitem" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_MODERATOR && args.size() >= 2) { const auto& playerName = args[0]; @@ -896,9 +896,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS); } - if ((chatCommand == "teleport" || chatCommand == "tele") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_MODERATOR) { - NiPoint3 pos {}; - if (args.size() == 3) { + if ((chatCommand == "teleport" || chatCommand == "tele") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_MODERATOR) { + NiPoint3 pos {}; + if (args.size() == 3) { float x, y, z; @@ -920,13 +920,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - pos.SetX(x); - pos.SetY(y); - pos.SetZ(z); + pos.SetX(x); + pos.SetY(y); + pos.SetZ(z); - Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to %f, %f, %f\n", entity->GetObjectID(), pos.x, pos.y, pos.z); - GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr); - } else if (args.size() == 2) { + Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to %f, %f, %f\n", entity->GetObjectID(), pos.x, pos.y, pos.z); + GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr); + } else if (args.size() == 2) { float x, z; if (!GeneralUtils::TryParse(args[0], x)) @@ -946,11 +946,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit pos.SetZ(z); - Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to X: %f, Z: %f\n", entity->GetObjectID(), pos.x, pos.z); - GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr); - } else { - ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /teleport () - if no Y given, will teleport to the height of the terrain (or any physics object)."); - } + Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to X: %f, Z: %f\n", entity->GetObjectID(), pos.x, pos.z); + GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr); + } else { + ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /teleport () - if no Y given, will teleport to the height of the terrain (or any physics object)."); + } auto* possessorComponent = entity->GetComponent(); @@ -972,7 +972,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } } } - } + } if (chatCommand == "tpall" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { @@ -1190,7 +1190,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit //------------------------------------------------- - if (chatCommand == "buffme" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { + if (chatCommand == "buffme" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); if (dest) { dest->SetHealth(999); @@ -1201,8 +1201,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetMaxImagination(999.0f); } - EntityManager::Instance()->SerializeEntity(entity); - } + EntityManager::Instance()->SerializeEntity(entity); + } if (chatCommand == "startcelebration" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { int32_t celebration; @@ -1216,7 +1216,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit GameMessages::SendStartCelebrationEffect(entity, entity->GetSystemAddress(), celebration); } - if (chatCommand == "buffmed" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { + if (chatCommand == "buffmed" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); if (dest) { dest->SetHealth(9); @@ -1227,10 +1227,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetMaxImagination(9.0f); } - EntityManager::Instance()->SerializeEntity(entity); - } + EntityManager::Instance()->SerializeEntity(entity); + } - if (chatCommand == "refillstats" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { + if (chatCommand == "refillstats" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); if (dest) { dest->SetHealth((int)dest->GetMaxHealth()); @@ -1238,22 +1238,22 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetImagination((int)dest->GetMaxImagination()); } - EntityManager::Instance()->SerializeEntity(entity); - } + EntityManager::Instance()->SerializeEntity(entity); + } - if (chatCommand == "lookup" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { - std::string query = "SELECT `id`, `name` FROM `Objects` WHERE `displayName` LIKE '%" + args[0] + "%' OR `name` LIKE '%" + args[0] + "%' OR `description` LIKE '%" + args[0] + "%'"; - auto tables = CDClientDatabase::ExecuteQuery(query.c_str()); - while (!tables.eof()) { - std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1); - ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message, message.size())); - tables.nextRow(); - } - } + if (chatCommand == "lookup" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { + std::string query = "SELECT `id`, `name` FROM `Objects` WHERE `displayName` LIKE '%" + args[0] + "%' OR `name` LIKE '%" + args[0] + "%' OR `description` LIKE '%" + args[0] + "%'"; + auto tables = CDClientDatabase::ExecuteQuery(query.c_str()); + while (!tables.eof()) { + std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1); + ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message, message.size())); + tables.nextRow(); + } + } - if (chatCommand == "spawn" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { - ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); - if (!comp) return; + if (chatCommand == "spawn" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { + ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + if (!comp) return; uint32_t lot; @@ -1263,23 +1263,23 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - EntityInfo info; - info.lot = lot; - info.pos = comp->GetPosition(); - info.rot = comp->GetRotation(); + EntityInfo info; + info.lot = lot; + info.pos = comp->GetPosition(); + info.rot = comp->GetRotation(); info.spawner = nullptr; info.spawnerID = entity->GetObjectID(); info.spawnerNodeID = 0; - Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); + Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); - if (newEntity == nullptr) { + if (newEntity == nullptr) { ChatPackets::SendSystemMessage(sysAddr, u"Failed to spawn entity."); return; - } + } - EntityManager::Instance()->ConstructEntity(newEntity); - } + EntityManager::Instance()->ConstructEntity(newEntity); + } if ((chatCommand == "giveuscore") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { int32_t uscore; @@ -1323,9 +1323,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit GameMessages::SendPlayFXEffect(entity, 7074, u"create", "7074", LWOOBJID_EMPTY, 1.0f, 1.0f, true); } - if (chatCommand == "playrebuildfx" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - GameMessages::SendPlayFXEffect(entity, 230, u"rebuild", "230", LWOOBJID_EMPTY, 1.0f, 1.0f, true); - } + if (chatCommand == "playrebuildfx" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { + GameMessages::SendPlayFXEffect(entity, 230, u"rebuild", "230", LWOOBJID_EMPTY, 1.0f, 1.0f, true); + } if ((chatCommand == "freemoney" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) && args.size() == 1) { int32_t money; @@ -1408,8 +1408,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - if ((chatCommand == "testmap" && args.size() >= 1) && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { - ChatPackets::SendSystemMessage(sysAddr, u"Requesting map change..."); + if ((chatCommand == "testmap" && args.size() >= 1) && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { + ChatPackets::SendSystemMessage(sysAddr, u"Requesting map change..."); uint32_t reqZone; LWOCLONEID cloneId = 0; bool force = false; @@ -1440,7 +1440,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit const auto objid = entity->GetObjectID(); - if (force || CheckIfAccessibleZone(reqZone)) { // to prevent tomfoolery + if (force || CheckIfAccessibleZone(reqZone)) { // to prevent tomfoolery bool darwin = true; //Putting this on true, as I'm sick of having to wait 3-4 seconds on a transfer while trying to quickly moderate properties Character* character = entity->GetCharacter(); @@ -1460,12 +1460,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ); } - ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, reqZone, cloneId, false, [objid, darwin](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) { + ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, reqZone, cloneId, false, [objid, darwin](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) { auto* entity = EntityManager::Instance()->GetEntity(objid); - if (entity == nullptr) { - return; - } + if (entity == nullptr) { + return; + } float transferTime = 3.32999992370605f; if (darwin) transferTime = 0.0f; @@ -1488,14 +1488,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); }); - return; - }); - } else { - std::string msg = "ZoneID not found or allowed: "; - msg.append(args[0]); - ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(msg, msg.size())); - } - } + return; + }); + } else { + std::string msg = "ZoneID not found or allowed: "; + msg.append(args[0]); + ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(msg, msg.size())); + } + } if (chatCommand == "createprivate" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 3) { From 959c90985c498043c3ea361eabbc498803d73923 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 12 Apr 2022 18:32:52 -0500 Subject: [PATCH 04/48] missed a semicolon --- dGame/dUtilities/SlashCommandHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 42a4a565b..2e3e2be77 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1938,7 +1938,7 @@ bool SlashCommandHandler::CheckIfAccessibleZone(const unsigned int zoneID) { std::string zonePath = "./res/maps/" + zone->zoneName; std::transform(zonePath.begin(), zonePath.end(), zonePath.begin(), ::tolower); std::ifstream f(zonePath.c_str()); - return f.good() + return f.good(); } else { return false; } From 59ec28a5a4bfabf054c0eeb7f288aff52ce793fe Mon Sep 17 00:00:00 2001 From: NinjaOfLU Date: Wed, 13 Apr 2022 01:58:00 +0100 Subject: [PATCH 05/48] Prevent integer underflow in item removal Previously, the only check that the user wasn't trashing more items than they had was clientsided, and this could be bypassed by contacting the server to remove items via a console or the like, and then trashing them before the server could respond, resulting in the count for the items being less than iStackCount. This check prevents that underflow. --- 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 1ede443ba..35e1a13c9 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5441,7 +5441,7 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En } } - item->SetCount(item->GetCount() - iStackCount, true); + item->SetCount(item->GetCount() - std::min(item->GetCount(), iStackCount), true); EntityManager::Instance()->SerializeEntity(entity); auto* missionComponent = entity->GetComponent(); From a32c5a2f3c2cfac1234931fcd21a94d5325f9ebb Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 13 Apr 2022 01:49:55 -0700 Subject: [PATCH 06/48] Vault corrections --- dGame/Entity.cpp | 12 ++++++++++++ dGame/Entity.h | 6 +++++- dGame/UserManager.cpp | 2 +- dGame/dComponents/InventoryComponent.cpp | 1 + dGame/dMission/Mission.cpp | 4 +++- dWorldServer/WorldServer.cpp | 2 ++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index bca7ffa25..57b7af14d 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -2173,3 +2173,15 @@ void Entity::AddToGroup(const std::string& group) { m_Groups.push_back(group); } } + +void Entity::RetroactiveVaultSize() { + auto inventoryComponent = GetComponent(); + if (!inventoryComponent) return; + + auto itemsVault = inventoryComponent->GetInventory(eInventoryType::VAULT_ITEMS); + auto modelVault = inventoryComponent->GetInventory(eInventoryType::VAULT_MODELS); + + if (itemsVault->GetSize() == modelVault->GetSize()) return; + + modelVault->SetSize(itemsVault->GetSize()); +} diff --git a/dGame/Entity.h b/dGame/Entity.h index 31b2b3039..cef7b97ff 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -220,7 +220,11 @@ public: /* * Utility */ - + /** + * Retroactively corrects the model vault size due to incorrect initialization in a previous patch. + * + */ + void RetroactiveVaultSize(); bool GetBoolean(const std::u16string& name) const; int32_t GetI32(const std::u16string& name) const; int64_t GetI64(const std::u16string& name) const; diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index adae72b0d..1d14cb0aa 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -291,7 +291,7 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) 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 << ""; + xml << ""; std::string xmlSave1 = xml.str(); ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t idforshirt) { diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 63080b2d5..5d3dda2ec 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -84,6 +84,7 @@ Inventory* InventoryComponent::GetInventory(const eInventoryType type) case eInventoryType::ITEMS: size = 20u; break; + case eInventoryType::VAULT_MODELS: case eInventoryType::VAULT_ITEMS: size = 40u; break; diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index f7b570712..14fc5a24a 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -511,9 +511,11 @@ void Mission::YieldRewards() { } if (info->reward_bankinventory > 0) { - auto* inventory = inventoryComponent->GetInventory(VAULT_ITEMS); + auto* inventory = inventoryComponent->GetInventory(eInventoryType::VAULT_ITEMS); + auto modelInventory = inventoryComponent->GetInventory(eInventoryType::VAULT_MODELS); inventory->SetSize(inventory->GetSize() + info->reward_bankinventory); + modelInventory->SetSize(modelInventory->GetSize() + info->reward_bankinventory); } if (info->reward_reputation > 0) { diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index a4056de9c..9d0c84ccb 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -975,6 +975,8 @@ void HandlePacket(Packet* packet) { player->GetComponent()->SetLastRocketConfig(u""); c->SetRetroactiveFlags(); + + player->RetroactiveVaultSize(); player->GetCharacter()->SetTargetScene(""); From 1d1f47938769a6a40f0472c6643e68e8813b9227 Mon Sep 17 00:00:00 2001 From: NinjaOfLU Date: Thu, 14 Apr 2022 00:11:35 +0100 Subject: [PATCH 07/48] Ensure items correctly removed from missions Doubt it would have affected anyone, but technically if you had a mission to collect something interactable, and you deleted the items at the same time as interacting with something, this would have counted incorrectly. I'm being defensive because I was an idiot who couldn't read, but in my defence, it was late when I made the first edit, and I'm also a blundering idiot! --- 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 35e1a13c9..c8c1e7aa5 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5448,7 +5448,7 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En if (missionComponent != nullptr) { - missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, item->GetLot(), LWOOBJID_EMPTY, "", -iStackCount); + missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, item->GetLot(), LWOOBJID_EMPTY, "", -std::min(item->GetCount(), iStackCount); } } } From cdbb42badff3247cec8a2e4e016669d0d676f036 Mon Sep 17 00:00:00 2001 From: NinjaOfLU Date: Thu, 14 Apr 2022 00:15:45 +0100 Subject: [PATCH 08/48] Added a bracket... -_- Maybe I should write and test code on my computer rather than using Git as an IDE and commits as the save button... --- 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 c8c1e7aa5..e1fb21ac2 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5448,7 +5448,7 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En if (missionComponent != nullptr) { - missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, item->GetLot(), LWOOBJID_EMPTY, "", -std::min(item->GetCount(), iStackCount); + missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, item->GetLot(), LWOOBJID_EMPTY, "", -std::min(item->GetCount(), iStackCount)); } } } From 3d6d5e58a789ccf8df667a2683cad297d27a49e5 Mon Sep 17 00:00:00 2001 From: NinjaOfLU Date: Thu, 14 Apr 2022 10:09:40 +0100 Subject: [PATCH 09/48] Update GameMessages.cpp I promise I'm not farming changes. I woke up at like 4AM and realised that I'd screwed up in an obvious way. Note to self: You are ALLOWED to change variables. Wasn't caught in testing because, well, it turns out it's actually impossible to test the edge case this covers, due to the script for the brick console. --- dGame/dGameMessages/GameMessages.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index e1fb21ac2..9e68941c8 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5433,6 +5433,8 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En return; } + iStackCount = std::min(item->GetCount(), iStackCount); + if (bConfirmed) { for (auto i = 0; i < iStackCount; ++i) { if (eInvType == eInventoryType::MODELS) @@ -5441,14 +5443,14 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En } } - item->SetCount(item->GetCount() - std::min(item->GetCount(), iStackCount), true); + item->SetCount(item->GetCount() - iStackCount, true); EntityManager::Instance()->SerializeEntity(entity); auto* missionComponent = entity->GetComponent(); if (missionComponent != nullptr) { - missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, item->GetLot(), LWOOBJID_EMPTY, "", -std::min(item->GetCount(), iStackCount)); + missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ITEM_COLLECTION, item->GetLot(), LWOOBJID_EMPTY, "", -iStackCount); } } } From b4acf329b492d44db939763cbece4a31ab93ceb5 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 16 Apr 2022 23:32:15 -0500 Subject: [PATCH 10/48] implement some missing scripts --- dScripts/CppScripts.cpp | 10 +++++ dScripts/RockHydrantBroken.cpp | 46 ++++++++++++++++++++++ dScripts/RockHydrantBroken.h | 10 +++++ dScripts/WhFans.cpp | 72 ++++++++++++++++++++++++++++++++++ dScripts/WhFans.h | 17 ++++++++ 5 files changed, 155 insertions(+) create mode 100644 dScripts/RockHydrantBroken.cpp create mode 100644 dScripts/RockHydrantBroken.h create mode 100644 dScripts/WhFans.cpp create mode 100644 dScripts/WhFans.h diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index b9fa50ef2..95269dabd 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -274,6 +274,10 @@ #include "AgSurvivalMech.h" #include "AgSurvivalSpiderling.h" +// Frostburgh Scripts +#include "RockHydrantBroken.h" +#include "WhFans.h" + //Big bad global bc this is a namespace and not a class: InvalidScript* invalidToReturn = new InvalidScript(); std::map m_Scripts; @@ -795,6 +799,12 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr else if (scriptName == "scripts\\EquipmentScripts\\BuccaneerValiantShip.lua") script = new BuccaneerValiantShip(); + // FB + else if (scriptName = "scripts\\ai\\NS\\WH\\L_ROCKHYDRANT_BROKEN.lua") + script = new RockHydrantBroken(); + else if (scriptName = "L_NS_WH_FANS.lua") + script = new WhFans(); + //Ignore these scripts: else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") script = invalidToReturn; diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp new file mode 100644 index 000000000..2c145b366 --- /dev/null +++ b/dScripts/RockHydrantBroken.cpp @@ -0,0 +1,46 @@ +#include "RockHydrantBroken.h" +#include "EntityManager.h" +#include "GameMessages.h" + +void RockHydrantBroken::OnStartup(Entity* self) +{ + self->AddTimer("playEffect", 1); + + const auto hydrant = "hydrant" + self->GetVar(u"hydrant"); + + const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); + + Game::logger->Log("RockHydrantBroken", "Broken Hydrant spawned (%s)\n", hydrant.c_str()); + + for (auto* bouncer : bouncers) + { + self->SetVar(u"bouncer", bouncer->GetObjectID()); + + GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); + + GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"enableCollision", UNASSIGNED_SYSTEM_ADDRESS); + } + + self->AddTimer("KillBroken", 25); +} + +void RockHydrantBroken::OnTimerDone(Entity* self, std::string timerName) +{ + if (timerName == "KillBroken") + { + auto* bouncer = EntityManager::Instance()->GetEntity(self->GetVar(u"bouncer")); + + if (bouncer != nullptr) + { + GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); + + GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"disableCollision", UNASSIGNED_SYSTEM_ADDRESS); + } + + self->Kill(); + } + else if (timerName == "playEffect") + { + GameMessages::SendPlayFXEffect(self->GetObjectID(), 384, u"water", "water", LWOOBJID_EMPTY, 1, 1, true); + } +} diff --git a/dScripts/RockHydrantBroken.h b/dScripts/RockHydrantBroken.h new file mode 100644 index 000000000..3bea8341c --- /dev/null +++ b/dScripts/RockHydrantBroken.h @@ -0,0 +1,10 @@ +#pragma once +#include "CppScripts.h" + +class RockHydrantBroken : public CppScripts::Script +{ +public: + void OnStartup(Entity* self) override; + void OnTimerDone(Entity* self, std::string timerName) override; +}; + diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp new file mode 100644 index 000000000..eee0cd302 --- /dev/null +++ b/dScripts/WhFans.cpp @@ -0,0 +1,72 @@ +#include "AgFans.h" + +#include "RenderComponent.h" + +void AgFans::OnStartup(Entity* self) { + self->SetVar(u"alive", true); + self->SetVar(u"on", false); + + ToggleFX(self, false); + + auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + + if (renderComponent == nullptr) { + return; + } + + renderComponent->PlayEffect(495, u"fanOn", "fanOn"); +} + +void AgFans::ToggleFX(Entity* self, bool hit) { + std::string fanGroup = self->GetGroups()[0]; + std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); + + auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + + if (renderComponent == nullptr) { + return; + } + + if (fanVolumes.size() == 0 || !self->GetVar(u"alive")) return; + + if (self->GetVar(u"on")) { + GameMessages::SendPlayAnimation(self, u"fan-off"); + + renderComponent->StopEffect("fanOn"); + self->SetVar(u"on", false); + + for (Entity* volume : fanVolumes) { + PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + if (!volumePhys) continue; + volumePhys->SetPhysicsEffectActive(false); + EntityManager::Instance()->SerializeEntity(volume); + } + } + else if (!self->GetVar(u"on") && self->GetVar(u"alive")) { + GameMessages::SendPlayAnimation(self, u"fan-on"); + + self->SetVar(u"on", true); + + for (Entity* volume : fanVolumes) { + PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + if (!volumePhys) continue; + volumePhys->SetPhysicsEffectActive(true); + EntityManager::Instance()->SerializeEntity(volume); + } + } +} + +void AgFans::OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, + int32_t param3) { + if (args.length() == 0 || !self->GetVar(u"alive")) return; + + if ((args == "turnOn" && self->GetVar(u"on")) || (args == "turnOff" && !self->GetVar(u"on"))) return; + ToggleFX(self, false); +} + +void AgFans::OnDie(Entity* self, Entity* killer) { + if (self->GetVar(u"on")) { + ToggleFX(self, true); + } + self->SetVar(u"alive", false); +} \ No newline at end of file diff --git a/dScripts/WhFans.h b/dScripts/WhFans.h new file mode 100644 index 000000000..9b87430b0 --- /dev/null +++ b/dScripts/WhFans.h @@ -0,0 +1,17 @@ +#pragma once +#include "CppScripts.h" +#include "GameMessages.h" +#include "EntityManager.h" +#include "PhantomPhysicsComponent.h" + +class WhFans : public CppScripts::Script +{ +public: + void OnStartup(Entity* self); + void OnDie(Entity* self, Entity* killer); + void OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, + int32_t param3); +private: + void ToggleFX(Entity* self, bool hit); +}; + From 0e5a1c97219c224d90e53b54c5ea5ad65faf8fb5 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 16 Apr 2022 23:33:44 -0500 Subject: [PATCH 11/48] fix comparator --- dScripts/CppScripts.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 95269dabd..c81b01f43 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -1,4 +1,4 @@ -//I can feel my soul being torn apart with every script added to this monstrosity. +//I can feel my soul being torn apart with every script added to this monstrosity. // skate fast eat trash // do you think god stays in heaven because he too lives in fear of what he's created? @@ -800,9 +800,9 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr script = new BuccaneerValiantShip(); // FB - else if (scriptName = "scripts\\ai\\NS\\WH\\L_ROCKHYDRANT_BROKEN.lua") + else if (scriptName == "scripts\\ai\\NS\\WH\\L_ROCKHYDRANT_BROKEN.lua") script = new RockHydrantBroken(); - else if (scriptName = "L_NS_WH_FANS.lua") + else if (scriptName == "L_NS_WH_FANS.lua") script = new WhFans(); //Ignore these scripts: From b3695c42b2d5697ae8c3c1d9aecc686d18bd39fd Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 16 Apr 2022 23:35:22 -0500 Subject: [PATCH 12/48] fix copy past error --- dScripts/WhFans.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index eee0cd302..da9af43f9 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -1,8 +1,8 @@ -#include "AgFans.h" +#include "WhFans.h" #include "RenderComponent.h" -void AgFans::OnStartup(Entity* self) { +void WhFans::OnStartup(Entity* self) { self->SetVar(u"alive", true); self->SetVar(u"on", false); @@ -17,7 +17,7 @@ void AgFans::OnStartup(Entity* self) { renderComponent->PlayEffect(495, u"fanOn", "fanOn"); } -void AgFans::ToggleFX(Entity* self, bool hit) { +void WhFans::ToggleFX(Entity* self, bool hit) { std::string fanGroup = self->GetGroups()[0]; std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); @@ -56,7 +56,7 @@ void AgFans::ToggleFX(Entity* self, bool hit) { } } -void AgFans::OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, +void WhFans::OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, int32_t param3) { if (args.length() == 0 || !self->GetVar(u"alive")) return; @@ -64,7 +64,7 @@ void AgFans::OnFireEventServerSide(Entity *self, Entity *sender, std::string arg ToggleFX(self, false); } -void AgFans::OnDie(Entity* self, Entity* killer) { +void WhFans::OnDie(Entity* self, Entity* killer) { if (self->GetVar(u"on")) { ToggleFX(self, true); } From 5b0f9174857dc16dd091924f80ae8db43b851a92 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 00:05:04 -0500 Subject: [PATCH 13/48] update script path for fans --- dScripts/CppScripts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index c81b01f43..8be1c0d47 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -802,7 +802,7 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr // FB else if (scriptName == "scripts\\ai\\NS\\WH\\L_ROCKHYDRANT_BROKEN.lua") script = new RockHydrantBroken(); - else if (scriptName == "L_NS_WH_FANS.lua") + else if (scriptName == "scripts\\ai\\NS\\L_NS_WH_FANS.lua") script = new WhFans(); //Ignore these scripts: From 23677b4bd37fd88e86bb4a92f12e018b336c27ff Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 12:38:12 -0500 Subject: [PATCH 14/48] Simplify some stuff Remove render component in startup --- dScripts/WhFans.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index da9af43f9..b11da6e55 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -7,22 +7,13 @@ void WhFans::OnStartup(Entity* self) { self->SetVar(u"on", false); ToggleFX(self, false); - - auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); - - if (renderComponent == nullptr) { - return; - } - - renderComponent->PlayEffect(495, u"fanOn", "fanOn"); } void WhFans::ToggleFX(Entity* self, bool hit) { std::string fanGroup = self->GetGroups()[0]; std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); - auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); - + auto renderComponent = self->GetComponent(); if (renderComponent == nullptr) { return; } @@ -36,7 +27,7 @@ void WhFans::ToggleFX(Entity* self, bool hit) { self->SetVar(u"on", false); for (Entity* volume : fanVolumes) { - PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + auto phantomPhysicsComponent = volume->GetComponent(); if (!volumePhys) continue; volumePhys->SetPhysicsEffectActive(false); EntityManager::Instance()->SerializeEntity(volume); @@ -48,7 +39,7 @@ void WhFans::ToggleFX(Entity* self, bool hit) { self->SetVar(u"on", true); for (Entity* volume : fanVolumes) { - PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + auto phantomPhysicsComponent = volume->GetComponent(); if (!volumePhys) continue; volumePhys->SetPhysicsEffectActive(true); EntityManager::Instance()->SerializeEntity(volume); From 67615d568872c63900c6ed78ab244f5598e08f07 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 12:46:41 -0500 Subject: [PATCH 15/48] fix volumen physics name --- dScripts/WhFans.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index b11da6e55..39bbab3b9 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -27,7 +27,7 @@ void WhFans::ToggleFX(Entity* self, bool hit) { self->SetVar(u"on", false); for (Entity* volume : fanVolumes) { - auto phantomPhysicsComponent = volume->GetComponent(); + auto volumePhys = volume->GetComponent(); if (!volumePhys) continue; volumePhys->SetPhysicsEffectActive(false); EntityManager::Instance()->SerializeEntity(volume); @@ -39,7 +39,7 @@ void WhFans::ToggleFX(Entity* self, bool hit) { self->SetVar(u"on", true); for (Entity* volume : fanVolumes) { - auto phantomPhysicsComponent = volume->GetComponent(); + auto volumePhys = volume->GetComponent(); if (!volumePhys) continue; volumePhys->SetPhysicsEffectActive(true); EntityManager::Instance()->SerializeEntity(volume); From 1e85ae203563ebf6f5fc366aaa6a8d6b4afae8b5 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 15:58:26 -0500 Subject: [PATCH 16/48] tabs and log --- dScripts/RockHydrantBroken.cpp | 51 +++++++++++++++++----------------- dScripts/WhFans.cpp | 2 ++ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp index 2c145b366..b3d7f717a 100644 --- a/dScripts/RockHydrantBroken.cpp +++ b/dScripts/RockHydrantBroken.cpp @@ -4,43 +4,44 @@ void RockHydrantBroken::OnStartup(Entity* self) { - self->AddTimer("playEffect", 1); + self->AddTimer("playEffect", 1); - const auto hydrant = "hydrant" + self->GetVar(u"hydrant"); + const auto hydrant = "hydrant" + self->GetVar(u"hydrant"); - const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); + const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); - Game::logger->Log("RockHydrantBroken", "Broken Hydrant spawned (%s)\n", hydrant.c_str()); + Game::logger->Log("RockHydrantBroken", "Broken Rock Hydrant spawned (%s)\n", hydrant.c_str()); - for (auto* bouncer : bouncers) - { - self->SetVar(u"bouncer", bouncer->GetObjectID()); + for (auto* bouncer : bouncers) + { + self->SetVar(u"bouncer", bouncer->GetObjectID()); + Game::logger->Log("RockHydrantBroken", "Activate Bouncer (%s)\n", bouncer.c_str()); - GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); + GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"enableCollision", UNASSIGNED_SYSTEM_ADDRESS); - } + GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"enableCollision", UNASSIGNED_SYSTEM_ADDRESS); + } - self->AddTimer("KillBroken", 25); + self->AddTimer("KillBroken", 10); } void RockHydrantBroken::OnTimerDone(Entity* self, std::string timerName) { - if (timerName == "KillBroken") - { - auto* bouncer = EntityManager::Instance()->GetEntity(self->GetVar(u"bouncer")); + if (timerName == "KillBroken") + { + auto* bouncer = EntityManager::Instance()->GetEntity(self->GetVar(u"bouncer")); - if (bouncer != nullptr) - { - GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); + if (bouncer != nullptr) + { + GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"disableCollision", UNASSIGNED_SYSTEM_ADDRESS); - } + GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"disableCollision", UNASSIGNED_SYSTEM_ADDRESS); + } - self->Kill(); - } - else if (timerName == "playEffect") - { - GameMessages::SendPlayFXEffect(self->GetObjectID(), 384, u"water", "water", LWOOBJID_EMPTY, 1, 1, true); - } + self->Kill(); + } + else if (timerName == "playEffect") + { + GameMessages::SendPlayFXEffect(self->GetObjectID(), 384, u"water", "water", LWOOBJID_EMPTY, 1, 1, true); + } } diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index 39bbab3b9..dffedc148 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -11,6 +11,8 @@ void WhFans::OnStartup(Entity* self) { void WhFans::ToggleFX(Entity* self, bool hit) { std::string fanGroup = self->GetGroups()[0]; + + Game::logger->Log("WhFans", "Toggling FX for Fan Group(%s)\n", fanGroup.c_str()); std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); auto renderComponent = self->GetComponent(); From a8fcb4c15375c2d3e86b7430cd72106e125b8311 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 16:44:46 -0500 Subject: [PATCH 17/48] make the hydrant match the lua script --- dScripts/RockHydrantBroken.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp index b3d7f717a..8bae7f791 100644 --- a/dScripts/RockHydrantBroken.cpp +++ b/dScripts/RockHydrantBroken.cpp @@ -6,7 +6,7 @@ void RockHydrantBroken::OnStartup(Entity* self) { self->AddTimer("playEffect", 1); - const auto hydrant = "hydrant" + self->GetVar(u"hydrant"); + const auto hydrant = "hydrant0" + self->GetVar(u"hydrant"); const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); From e696d26941e6240b718292aea351dc4c7153f807 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 17:41:10 -0500 Subject: [PATCH 18/48] update the Effect ID --- dScripts/RockHydrantBroken.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp index 8bae7f791..681335f28 100644 --- a/dScripts/RockHydrantBroken.cpp +++ b/dScripts/RockHydrantBroken.cpp @@ -42,6 +42,6 @@ void RockHydrantBroken::OnTimerDone(Entity* self, std::string timerName) } else if (timerName == "playEffect") { - GameMessages::SendPlayFXEffect(self->GetObjectID(), 384, u"water", "water", LWOOBJID_EMPTY, 1, 1, true); + GameMessages::SendPlayFXEffect(self->GetObjectID(), 4737, u"water", "water", LWOOBJID_EMPTY, 1, 1, true); } } From cc68b0768b4538b6723def491687c19f624ea985 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 17:43:25 -0500 Subject: [PATCH 19/48] remove log --- dScripts/RockHydrantBroken.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp index 681335f28..0347466c0 100644 --- a/dScripts/RockHydrantBroken.cpp +++ b/dScripts/RockHydrantBroken.cpp @@ -15,7 +15,7 @@ void RockHydrantBroken::OnStartup(Entity* self) for (auto* bouncer : bouncers) { self->SetVar(u"bouncer", bouncer->GetObjectID()); - Game::logger->Log("RockHydrantBroken", "Activate Bouncer (%s)\n", bouncer.c_str()); + GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); From a343ed94933cb30b055d9928471e289005ece085 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 19:43:17 -0500 Subject: [PATCH 20/48] rock hydrants work --- dScripts/RockHydrantBroken.cpp | 2 +- dScripts/RockHydrantSmashable.cpp | 33 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp index 0347466c0..7895b00bb 100644 --- a/dScripts/RockHydrantBroken.cpp +++ b/dScripts/RockHydrantBroken.cpp @@ -6,7 +6,7 @@ void RockHydrantBroken::OnStartup(Entity* self) { self->AddTimer("playEffect", 1); - const auto hydrant = "hydrant0" + self->GetVar(u"hydrant"); + const auto hydrant = "hydrant" + self->GetVar(u"hydrant"); const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); diff --git a/dScripts/RockHydrantSmashable.cpp b/dScripts/RockHydrantSmashable.cpp index a54f0b9da..04b39c849 100644 --- a/dScripts/RockHydrantSmashable.cpp +++ b/dScripts/RockHydrantSmashable.cpp @@ -1,24 +1,23 @@ #include "RockHydrantSmashable.h" #include "EntityManager.h" -#include "SimplePhysicsComponent.h" -#include "Entity.h" -#include "GameMessages.h" -#include "Game.h" -#include "dLogger.h" +#include "GeneralUtils.h" -void RockHydrantSmashable::OnDie(Entity* self, Entity* killer) { - SimplePhysicsComponent* physics = self->GetComponent(); - NiPoint3 pos = physics->GetPosition(); +void RockHydrantSmashable::OnDie(Entity* self, Entity* killer) +{ + const auto hydrantName = self->GetVar(u"hydrant"); - EntityInfo info; + LDFBaseData* data = new LDFData(u"hydrant", GeneralUtils::UTF16ToWTF8(hydrantName)); + + EntityInfo info {}; info.lot = 12293; - info.pos = pos; - info.spawner = nullptr; + info.pos = self->GetPosition(); + info.rot = self->GetRotation(); + info.settings = {data}; info.spawnerID = self->GetSpawnerID(); - info.spawnerNodeID = 0; - Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); - if (newEntity) { - EntityManager::Instance()->ConstructEntity(newEntity); - } -} \ No newline at end of file + Game::logger->Log("RockHydrantBroken", "Rock Hydrant spawned (%s)\n", data->GetString().c_str()); + + auto* hydrant = EntityManager::Instance()->CreateEntity(info); + + EntityManager::Instance()->ConstructEntity(hydrant); +} From 235934714fca427bacaa92c0eae393b06c7f6045 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 20:16:27 -0500 Subject: [PATCH 21/48] honor the logic in the lua script --- dScripts/WhFans.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index dffedc148..c6c798d9f 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -10,7 +10,11 @@ void WhFans::OnStartup(Entity* self) { } void WhFans::ToggleFX(Entity* self, bool hit) { - std::string fanGroup = self->GetGroups()[0]; + try { + std::string fanGroup = self->GetGroups()[0]; + } catch(...) { + std::string fanGroup = "" + } Game::logger->Log("WhFans", "Toggling FX for Fan Group(%s)\n", fanGroup.c_str()); std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); From 0778b4f81ce3e742e069c949040f7c9215584985 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 20:17:36 -0500 Subject: [PATCH 22/48] missed semicolon --- dScripts/WhFans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index c6c798d9f..fe1aa01a7 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -13,7 +13,7 @@ void WhFans::ToggleFX(Entity* self, bool hit) { try { std::string fanGroup = self->GetGroups()[0]; } catch(...) { - std::string fanGroup = "" + std::string fanGroup = ""; } Game::logger->Log("WhFans", "Toggling FX for Fan Group(%s)\n", fanGroup.c_str()); From 6cef7a437aef98758c2cc6c4c840291b1fcdbded Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 20:24:19 -0500 Subject: [PATCH 23/48] scope --- dScripts/WhFans.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index fe1aa01a7..ccf556bec 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -10,10 +10,11 @@ void WhFans::OnStartup(Entity* self) { } void WhFans::ToggleFX(Entity* self, bool hit) { + std::string fanGroup = "" try { - std::string fanGroup = self->GetGroups()[0]; + fanGroup = self->GetGroups()[0]; } catch(...) { - std::string fanGroup = ""; + fanGroup = ""; } Game::logger->Log("WhFans", "Toggling FX for Fan Group(%s)\n", fanGroup.c_str()); From 263eaf03b07eb52a757a0c632e80e31fce95c59a Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 20:24:49 -0500 Subject: [PATCH 24/48] ugh, another semicolon --- dScripts/WhFans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index ccf556bec..0139eb1d9 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -10,7 +10,7 @@ void WhFans::OnStartup(Entity* self) { } void WhFans::ToggleFX(Entity* self, bool hit) { - std::string fanGroup = "" + std::string fanGroup = ""; try { fanGroup = self->GetGroups()[0]; } catch(...) { From 2122448284a1b8f55c582a3814903fb61860a4f1 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 17 Apr 2022 21:30:25 -0500 Subject: [PATCH 25/48] cleaning up some stuff --- dScripts/WhFans.cpp | 6 +----- dScripts/WhFans.h | 10 ++++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index 0139eb1d9..f2000d69b 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -17,13 +17,9 @@ void WhFans::ToggleFX(Entity* self, bool hit) { fanGroup = ""; } - Game::logger->Log("WhFans", "Toggling FX for Fan Group(%s)\n", fanGroup.c_str()); std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); - auto renderComponent = self->GetComponent(); - if (renderComponent == nullptr) { - return; - } + auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); if (fanVolumes.size() == 0 || !self->GetVar(u"alive")) return; diff --git a/dScripts/WhFans.h b/dScripts/WhFans.h index 9b87430b0..cac7236dd 100644 --- a/dScripts/WhFans.h +++ b/dScripts/WhFans.h @@ -9,8 +9,14 @@ class WhFans : public CppScripts::Script public: void OnStartup(Entity* self); void OnDie(Entity* self, Entity* killer); - void OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, - int32_t param3); + void OnFireEventServerSide( + Entity *self, + Entity *sender, + std::string args, + int32_t param1, + int32_t param2, + int32_t param3 + ); private: void ToggleFX(Entity* self, bool hit); }; From 5691df9009556fc2ecbfff706c96afb3eb90dfd9 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 18 Apr 2022 01:04:29 -0700 Subject: [PATCH 26/48] Fixed Racing Mission * Try, Try Again achievement now progresses when the player gets last place in a race of 3 or more players, or when solo racing is enabled. * Race Series 1 mission from Velocity Lane now progresses correctly. --- dGame/dComponents/RacingControlComponent.cpp | 11 ++++++---- dGame/dMission/MissionTask.cpp | 21 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 27df339db..f3957fff2 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -410,10 +410,13 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity *player, // If solo racing is enabled OR if there are 3 players in the race, progress placement tasks. if(m_SoloRacing || m_LoadedPlayers > 2) { missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, data->finished, (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_FINISH_WITH_PLACEMENT); // Finish in 1st place on a race - missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, data->finished, (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_FIRST_PLACE_MULTIPLE_TRACKS); // Finish in 1st place on multiple tracks. - if(m_Finished != 1) return; - missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_WIN_RACE_IN_WORLD); // Finished first place in specific world. - + if(data->finished == 1) { + missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_FIRST_PLACE_MULTIPLE_TRACKS); // Finish in 1st place on multiple tracks. + missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_WIN_RACE_IN_WORLD); // Finished first place in specific world. + } + if (data->finished == m_LoadedPlayers) { + missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_LAST_PLACE_FINISH); // Finished first place in specific world. + } } } else if (id == "ACT_RACE_EXIT_THE_RACE?" || id == "Exit") { auto *vehicle = EntityManager::Instance()->GetEntity(data->vehicleID); diff --git a/dGame/dMission/MissionTask.cpp b/dGame/dMission/MissionTask.cpp index 1a340b234..30cd58a13 100644 --- a/dGame/dMission/MissionTask.cpp +++ b/dGame/dMission/MissionTask.cpp @@ -183,7 +183,13 @@ bool MissionTask::InParameters(const uint32_t value) const bool MissionTask::IsComplete() const { - return progress >= info->targetValue; + // Mission 668 has task uid 984 which is a bit mask. Its completion value is 3. + if (info->uid == 984) { + return progress >= 3; + } + else { + return progress >= info->targetValue; + } } @@ -423,12 +429,23 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string& if (parameters[0] != associate) break; - if (associate == 1 || associate == 15 || associate == 2 || associate == 3) + if (associate == 1 || associate == 2 || associate == 3) { if (value > info->targetValue) break; AddProgress(info->targetValue); } + // task 15 is a bit mask! + else if (associate == 15) { + if (!InAllTargets(value)) break; + + auto tempProgress = GetProgress(); + // If we won at Nimbus Station, set bit 0 + if (value == 1203) SetProgress(tempProgress |= 1 << 0); + // If we won at Gnarled Forest, set bit 1 + else if (value == 1303) SetProgress(tempProgress |= 1 << 1); + // If both bits are set, then the client sees the mission as complete. + } else if (associate == 10) { // If the player did not crash during the race, progress this task by count. From d05601ce642330910c6e23c43df9e81af823068f Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 18 Apr 2022 08:27:37 -0500 Subject: [PATCH 27/48] Fixes --- dScripts/WhFans.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index f2000d69b..24e6234ca 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -10,16 +10,19 @@ void WhFans::OnStartup(Entity* self) { } void WhFans::ToggleFX(Entity* self, bool hit) { - std::string fanGroup = ""; - try { - fanGroup = self->GetGroups()[0]; - } catch(...) { + std::string fanGroup; + const auto& groups = self->GetGroups(); + if (!groups.empty()) { + fanGroup = groups[0]; + } else { fanGroup = ""; } std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); - auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* renderComponent = self->GetComponent(); + + if (renderComponent == nullptr) return; if (fanVolumes.size() == 0 || !self->GetVar(u"alive")) return; From 8fe5c009845fbc403bc963b84092dc3aef7e115f Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 18 Apr 2022 08:36:11 -0500 Subject: [PATCH 28/48] remove dereference (I think that's what it is called) --- dScripts/WhFans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index 24e6234ca..fc8fae0f8 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -20,7 +20,7 @@ void WhFans::ToggleFX(Entity* self, bool hit) { std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); - auto* renderComponent = self->GetComponent(); + auto* renderComponent = self->GetComponent(); if (renderComponent == nullptr) return; From f3dd71ccb1653d9d1d406ea22bfdd1a8aed7ea57 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 18 Apr 2022 21:02:04 -0500 Subject: [PATCH 29/48] cleanup logs, fix overrides, define LOTs in header --- dScripts/HydrantBroken.cpp | 8 +++----- dScripts/HydrantSmashable.cpp | 6 ++---- dScripts/HydrantSmashable.h | 6 ++++-- dScripts/RockHydrantBroken.cpp | 2 -- dScripts/RockHydrantSmashable.cpp | 8 +++----- dScripts/RockHydrantSmashable.h | 2 ++ dScripts/WhFans.cpp | 2 +- dScripts/WhFans.h | 6 +++--- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/dScripts/HydrantBroken.cpp b/dScripts/HydrantBroken.cpp index 934243253..2b620a210 100644 --- a/dScripts/HydrantBroken.cpp +++ b/dScripts/HydrantBroken.cpp @@ -2,7 +2,7 @@ #include "EntityManager.h" #include "GameMessages.h" -void HydrantBroken::OnStartup(Entity* self) +void HydrantBroken::OnStartup(Entity* self) { self->AddTimer("playEffect", 1); @@ -10,8 +10,6 @@ void HydrantBroken::OnStartup(Entity* self) const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); - Game::logger->Log("HydrantBroken", "Broken Hydrant spawned (%s)\n", hydrant.c_str()); - for (auto* bouncer : bouncers) { self->SetVar(u"bouncer", bouncer->GetObjectID()); @@ -20,11 +18,11 @@ void HydrantBroken::OnStartup(Entity* self) GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"enableCollision", UNASSIGNED_SYSTEM_ADDRESS); } - + self->AddTimer("KillBroken", 25); } -void HydrantBroken::OnTimerDone(Entity* self, std::string timerName) +void HydrantBroken::OnTimerDone(Entity* self, std::string timerName) { if (timerName == "KillBroken") { diff --git a/dScripts/HydrantSmashable.cpp b/dScripts/HydrantSmashable.cpp index e39f7a353..5cdf84c9b 100644 --- a/dScripts/HydrantSmashable.cpp +++ b/dScripts/HydrantSmashable.cpp @@ -2,20 +2,18 @@ #include "EntityManager.h" #include "GeneralUtils.h" -void HydrantSmashable::OnDie(Entity* self, Entity* killer) +void HydrantSmashable::OnDie(Entity* self, Entity* killer) { const auto hydrantName = self->GetVar(u"hydrant"); LDFBaseData* data = new LDFData(u"hydrant", GeneralUtils::UTF16ToWTF8(hydrantName)); EntityInfo info {}; - info.lot = 7328; + info.lot = HYDRANT_BROKEN; info.pos = self->GetPosition(); info.rot = self->GetRotation(); info.settings = {data}; info.spawnerID = self->GetSpawnerID(); - - Game::logger->Log("HydrantBroken", "Hydrant spawned (%s)\n", data->GetString().c_str()); auto* hydrant = EntityManager::Instance()->CreateEntity(info); diff --git a/dScripts/HydrantSmashable.h b/dScripts/HydrantSmashable.h index c7e230732..90b0f3a61 100644 --- a/dScripts/HydrantSmashable.h +++ b/dScripts/HydrantSmashable.h @@ -1,8 +1,10 @@ #pragma once #include "CppScripts.h" -class HydrantSmashable : public CppScripts::Script +class HydrantSmashable : public CppScripts::Script { public: - void OnDie(Entity* self, Entity* killer) override; + void OnDie(Entity* self, Entity* killer) override; +private: + LOT HYDRANT_BROKEN = 7328; }; \ No newline at end of file diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp index 7895b00bb..50e3c88d0 100644 --- a/dScripts/RockHydrantBroken.cpp +++ b/dScripts/RockHydrantBroken.cpp @@ -10,8 +10,6 @@ void RockHydrantBroken::OnStartup(Entity* self) const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant); - Game::logger->Log("RockHydrantBroken", "Broken Rock Hydrant spawned (%s)\n", hydrant.c_str()); - for (auto* bouncer : bouncers) { self->SetVar(u"bouncer", bouncer->GetObjectID()); diff --git a/dScripts/RockHydrantSmashable.cpp b/dScripts/RockHydrantSmashable.cpp index 04b39c849..8d5b58611 100644 --- a/dScripts/RockHydrantSmashable.cpp +++ b/dScripts/RockHydrantSmashable.cpp @@ -9,15 +9,13 @@ void RockHydrantSmashable::OnDie(Entity* self, Entity* killer) LDFBaseData* data = new LDFData(u"hydrant", GeneralUtils::UTF16ToWTF8(hydrantName)); EntityInfo info {}; - info.lot = 12293; + info.lot = ROCK_HYDRANT_BROKEN; info.pos = self->GetPosition(); info.rot = self->GetRotation(); info.settings = {data}; info.spawnerID = self->GetSpawnerID(); - Game::logger->Log("RockHydrantBroken", "Rock Hydrant spawned (%s)\n", data->GetString().c_str()); + auto* hydrant = EntityManager::Instance()->CreateEntity(info); - auto* hydrant = EntityManager::Instance()->CreateEntity(info); - - EntityManager::Instance()->ConstructEntity(hydrant); + EntityManager::Instance()->ConstructEntity(hydrant); } diff --git a/dScripts/RockHydrantSmashable.h b/dScripts/RockHydrantSmashable.h index 12c21fb08..0578cb2e1 100644 --- a/dScripts/RockHydrantSmashable.h +++ b/dScripts/RockHydrantSmashable.h @@ -5,5 +5,7 @@ class RockHydrantSmashable : public CppScripts::Script { public: void OnDie(Entity* self, Entity* killer); +private: + LOT ROCK_HYDRANT_BROKEN = 12293; }; diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp index fc8fae0f8..3a594a4c4 100644 --- a/dScripts/WhFans.cpp +++ b/dScripts/WhFans.cpp @@ -66,4 +66,4 @@ void WhFans::OnDie(Entity* self, Entity* killer) { ToggleFX(self, true); } self->SetVar(u"alive", false); -} \ No newline at end of file +} diff --git a/dScripts/WhFans.h b/dScripts/WhFans.h index cac7236dd..91aaa9d8f 100644 --- a/dScripts/WhFans.h +++ b/dScripts/WhFans.h @@ -7,8 +7,8 @@ class WhFans : public CppScripts::Script { public: - void OnStartup(Entity* self); - void OnDie(Entity* self, Entity* killer); + void OnStartup(Entity* self) override; + void OnDie(Entity* self, Entity* killer) override; void OnFireEventServerSide( Entity *self, Entity *sender, @@ -16,7 +16,7 @@ public: int32_t param1, int32_t param2, int32_t param3 - ); + ) override; private: void ToggleFX(Entity* self, bool hit); }; From 8db7dfef755b61a63b6b9315a2677897a69a7692 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 18 Apr 2022 21:09:27 -0500 Subject: [PATCH 30/48] also apply overrides to AG fans --- dScripts/AgFans.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dScripts/AgFans.h b/dScripts/AgFans.h index 0efe9c6d8..09cc89d9b 100644 --- a/dScripts/AgFans.h +++ b/dScripts/AgFans.h @@ -7,10 +7,16 @@ class AgFans : public CppScripts::Script { public: - void OnStartup(Entity* self); - void OnDie(Entity* self, Entity* killer); - void OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, - int32_t param3); + void OnStartup(Entity* self) override; + void OnDie(Entity* self, Entity* killer) override; + void OnFireEventServerSide( + Entity *self, + Entity *sender, + std::string args, + int32_t param1, + int32_t param2, + int32_t param3 + ) override; private: void ToggleFX(Entity* self, bool hit); }; From 6933b2c301985de163379abe3f1157bdda54f7a4 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 18 Apr 2022 23:33:09 -0500 Subject: [PATCH 31/48] case for putting you back into FB when leavign space blizzard --- dGame/dComponents/RacingControlComponent.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 27df339db..8647cfb78 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -53,6 +53,11 @@ RacingControlComponent::RacingControlComponent(Entity *parent) m_MainWorld = 1200; break; + case 1261: + m_ActivityID = 60; + m_MainWorld = 1260; + break; + case 1303: m_ActivityID = 39; m_MainWorld = 1300; @@ -413,7 +418,7 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity *player, missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, data->finished, (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_FIRST_PLACE_MULTIPLE_TRACKS); // Finish in 1st place on multiple tracks. if(m_Finished != 1) return; missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)RacingTaskParam::RACING_TASK_PARAM_WIN_RACE_IN_WORLD); // Finished first place in specific world. - + } } else if (id == "ACT_RACE_EXIT_THE_RACE?" || id == "Exit") { auto *vehicle = EntityManager::Instance()->GetEntity(data->vehicleID); From a3331d009db3d1c699dd565cc90bf2c40b387e90 Mon Sep 17 00:00:00 2001 From: Majo Date: Tue, 19 Apr 2022 12:33:57 +0200 Subject: [PATCH 32/48] Fix solo_racing for Frostburgh's Space Blizzard Racetrack --- dGame/dComponents/ScriptedActivityComponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dComponents/ScriptedActivityComponent.cpp b/dGame/dComponents/ScriptedActivityComponent.cpp index 55add0b66..026fafcea 100644 --- a/dGame/dComponents/ScriptedActivityComponent.cpp +++ b/dGame/dComponents/ScriptedActivityComponent.cpp @@ -28,7 +28,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit const auto mapID = m_ActivityInfo.instanceMapID; - if ((mapID == 1203 || mapID == 1303 || mapID == 1403) && Game::config->GetValue("solo_racing") == "1") { + if ((mapID == 1203 || mapID == 1261 || mapID == 1303 || mapID == 1403) && Game::config->GetValue("solo_racing") == "1") { m_ActivityInfo.minTeamSize = 1; m_ActivityInfo.minTeams = 1; } From d4adb0e6e5b1dfe60ad6ab700bbd4641d495d151 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 19 Apr 2022 21:30:38 -0500 Subject: [PATCH 33/48] Fix migration 0 for cd server setting every component to 1901 instead of just component 39 Add migration to fix it for existing users and set the values back to what they were --- migrations/cdserver/0_nt_footrace.sql | 2 +- migrations/cdserver/4_nt_footrace_parrot.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 migrations/cdserver/4_nt_footrace_parrot.sql diff --git a/migrations/cdserver/0_nt_footrace.sql b/migrations/cdserver/0_nt_footrace.sql index 2019f07d2..fd37599ef 100644 --- a/migrations/cdserver/0_nt_footrace.sql +++ b/migrations/cdserver/0_nt_footrace.sql @@ -1,6 +1,6 @@ BEGIN TRANSACTION; -UPDATE ComponentsRegistry SET component_id = 1901 WHERE id = 12916; +UPDATE ComponentsRegistry SET component_id = 1901 WHERE id = 12916 AND component_type = 39; INSERT INTO ActivityRewards (objectTemplate, ActivityRewardIndex, activityRating, LootMatrixIndex, CurrencyIndex, ChallengeRating, description) VALUES (1901, 166, -1, 598, 1, 4, 'NT Foot Race'); COMMIT; diff --git a/migrations/cdserver/4_nt_footrace_parrot.sql b/migrations/cdserver/4_nt_footrace_parrot.sql new file mode 100644 index 000000000..b1e7e012e --- /dev/null +++ b/migrations/cdserver/4_nt_footrace_parrot.sql @@ -0,0 +1,3 @@ +UPDATE ComponentsRegistry SET component_id = 12702 WHERE id = 12916 AND component_type = 2; +UPDATE ComponentsRegistry SET component_id = 6280 WHERE id = 12916 AND component_type = 3; +UPDATE ComponentsRegistry SET component_id = 1791 WHERE id = 12916 AND component_type = 7; \ No newline at end of file From d42cbb24739d20c69951a9279ffd3283b591befa Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 19 Apr 2022 21:36:09 -0500 Subject: [PATCH 34/48] make newline at end of file --- migrations/cdserver/4_nt_footrace_parrot.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/cdserver/4_nt_footrace_parrot.sql b/migrations/cdserver/4_nt_footrace_parrot.sql index b1e7e012e..3d5498158 100644 --- a/migrations/cdserver/4_nt_footrace_parrot.sql +++ b/migrations/cdserver/4_nt_footrace_parrot.sql @@ -1,3 +1,3 @@ UPDATE ComponentsRegistry SET component_id = 12702 WHERE id = 12916 AND component_type = 2; UPDATE ComponentsRegistry SET component_id = 6280 WHERE id = 12916 AND component_type = 3; -UPDATE ComponentsRegistry SET component_id = 1791 WHERE id = 12916 AND component_type = 7; \ No newline at end of file +UPDATE ComponentsRegistry SET component_id = 1791 WHERE id = 12916 AND component_type = 7; From 2e61839d93728d4193b5542558369f8cf05be61d Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Fri, 22 Apr 2022 00:10:15 -0700 Subject: [PATCH 35/48] isPlayer changes Changed isPlayer to check for whether the entity has a character instead of checking system address of entity. --- dGame/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 57b7af14d..780ae45c9 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1739,7 +1739,7 @@ void Entity::CancelAllTimers() { } bool Entity::IsPlayer() const { - return m_TemplateID == 1 && GetSystemAddress() != UNASSIGNED_SYSTEM_ADDRESS; + return m_TemplateID == 1 && GetCharacter() != nullptr; } void Entity::TriggerEvent(std::string eventID, Entity* optionalTarget) { From 834b53b4ecbb51978b6afa63b7933a06886dfcb5 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 04:13:23 -0700 Subject: [PATCH 36/48] Grammar error Level reward needed an underscore --- dCommon/dCommonVars.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index 680c0c1ea..cbecdd37d 100644 --- a/dCommon/dCommonVars.h +++ b/dCommon/dCommonVars.h @@ -493,7 +493,7 @@ enum eLootSourceType : int32_t { LOOT_SOURCE_CLAIMCODE, LOOT_SOURCE_CONSUMPTION, LOOT_SOURCE_CRAFTING, - LOOT_SOURCE_LEVELREWARD, + LOOT_SOURCE_LEVEL_REWARD, LOOT_SOURCE_RELOCATE }; From d0233a2cd064c78d2aa21dee0a7bacfb516204d0 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 04:14:55 -0700 Subject: [PATCH 37/48] Updated AddItemToInventorySync AddItemToInventorySync now sends the correct loot source type --- dGame/dGameMessages/GameMessages.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 9e68941c8..881b6ff50 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -411,7 +411,7 @@ void GameMessages::SendGMLevelBroadcast(const LWOOBJID& objectID, uint8_t level) SEND_PACKET_BROADCAST } -void GameMessages::SendAddItemToInventoryClientSync(Entity* entity, const SystemAddress& sysAddr, Item* item, const LWOOBJID& objectID, bool showFlyingLoot, int itemCount, LWOOBJID subKey) { +void GameMessages::SendAddItemToInventoryClientSync(Entity* entity, const SystemAddress& sysAddr, Item* item, const LWOOBJID& objectID, bool showFlyingLoot, int itemCount, LWOOBJID subKey, eLootSourceType lootSourceType) { CBITSTREAM CMSGHEADER @@ -421,8 +421,8 @@ void GameMessages::SendAddItemToInventoryClientSync(Entity* entity, const System bitStream.Write(item->GetInfo().isBOE); bitStream.Write(item->GetInfo().isBOP); - bitStream.Write0(); // Loot source - //if (invType != LOOTTYPE_NONE) bitStream.Write(invType); + bitStream.Write(lootSourceType != eLootSourceType::LOOT_SOURCE_NONE); // Loot source + if (lootSourceType != eLootSourceType::LOOT_SOURCE_NONE) bitStream.Write(lootSourceType); LWONameValue extraInfo; From 0eece14b6849cb1cbf71436bb4a86928c19cdd5f Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 04:16:10 -0700 Subject: [PATCH 38/48] Vendor buyback inventory Fixed vendor buyback inventory so it properly scrolls when the player adds enough items to it. --- dGame/dComponents/InventoryComponent.cpp | 4 +++- dGame/dInventory/Inventory.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 5d3dda2ec..cca5dde08 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -88,7 +88,9 @@ Inventory* InventoryComponent::GetInventory(const eInventoryType type) case eInventoryType::VAULT_ITEMS: size = 40u; break; - + case eInventoryType::VENDOR_BUYBACK: + size = 27u; + break; default: break; } diff --git a/dGame/dInventory/Inventory.cpp b/dGame/dInventory/Inventory.cpp index b77be4b28..ae1715d75 100644 --- a/dGame/dInventory/Inventory.cpp +++ b/dGame/dInventory/Inventory.cpp @@ -90,17 +90,17 @@ int32_t Inventory::FindEmptySlot() { if (free <= 6) // Up from 1 { - if (type != ITEMS && type != VAULT_ITEMS) + if (type != ITEMS && type != VAULT_ITEMS && type != eInventoryType::VAULT_MODELS) { uint32_t newSize = size; - if (type == MODELS || type == VAULT_MODELS) + if (type == MODELS) { newSize = 240; } - else + else if (type == eInventoryType::VENDOR_BUYBACK) { - newSize += 20; + newSize += 9u; } if (newSize > GetSize()) From a4d934913c3ecf181ce3174ad8c41eaf211cb196 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 05:13:06 -0700 Subject: [PATCH 39/48] added lootsource send in GM WIP commit --- dGame/Entity.cpp | 2 +- dGame/TradingManager.cpp | 4 ++-- dGame/dComponents/CharacterComponent.cpp | 2 +- dGame/dComponents/InventoryComponent.cpp | 17 ++++++++++------- dGame/dComponents/InventoryComponent.h | 3 ++- dGame/dComponents/PetComponent.cpp | 2 +- .../dComponents/PropertyManagementComponent.cpp | 4 ++-- dGame/dGameMessages/GameMessages.cpp | 16 ++++++++-------- dGame/dGameMessages/GameMessages.h | 2 +- dGame/dInventory/Item.cpp | 15 ++++++++------- dGame/dInventory/Item.h | 6 ++++-- dGame/dMission/Mission.cpp | 4 ++-- dGame/dUtilities/Loot.cpp | 2 +- dGame/dUtilities/Mail.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 6 +++--- dScripts/AmDropshipComputer.cpp | 2 +- dScripts/NPCAddRemoveItem.cpp | 2 +- dScripts/NjColeNPC.cpp | 2 +- dScripts/NjScrollChestServer.cpp | 2 +- dScripts/NpcCowboyServer.cpp | 2 +- dScripts/NpcPirateServer.cpp | 2 +- dScripts/NpcWispServer.cpp | 2 +- dScripts/NsConcertInstrument.cpp | 4 ++-- dScripts/NsTokenConsoleServer.cpp | 8 ++++---- dScripts/NtDukeServer.cpp | 2 +- dScripts/SGCannon.cpp | 2 +- dScripts/TokenConsoleServer.cpp | 12 +++++++----- dScripts/VeBricksampleServer.cpp | 2 +- dScripts/VeMissionConsole.cpp | 2 +- 29 files changed, 71 insertions(+), 62 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 780ae45c9..8a1d3c826 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1637,7 +1637,7 @@ void Entity::PickupItem(const LWOOBJID& objectID) { } } else { - inv->AddItem(p.second.lot, p.second.count, INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, INVALID, 1); + inv->AddItem(p.second.lot, p.second.count, INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_PICKUP); } } } diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 0963aa6ff..e178d1302 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -170,12 +170,12 @@ void Trade::Complete() for (const auto& tradeItem : m_ItemsA) { - inventoryB->AddItem(tradeItem.itemLot, tradeItem.itemCount); + inventoryB->AddItem(tradeItem.itemLot, tradeItem.itemCount, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_TRADE); } for (const auto& tradeItem : m_ItemsB) { - inventoryA->AddItem(tradeItem.itemLot, tradeItem.itemCount); + inventoryA->AddItem(tradeItem.itemLot, tradeItem.itemCount, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_TRADE); } TradingManager::Instance()->CancelTrade(m_TradeId); diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 590758b6a..67b820c26 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -217,7 +217,7 @@ void CharacterComponent::HandleLevelUp() switch (reward->rewardType) { case 0: - inventoryComponent->AddItem(reward->value, reward->count); + inventoryComponent->AddItem(reward->value, reward->count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD); break; case 4: { diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index cca5dde08..d7a059a06 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -150,7 +150,8 @@ void InventoryComponent::AddItem( const eInventoryType inventorySourceType, const int32_t sourceType, const bool bound, - int32_t preferredSlot) + int32_t preferredSlot, + eLootSourceType lootSourceType) { if (count == 0) { @@ -188,8 +189,7 @@ void InventoryComponent::AddItem( return; } - - auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound); + auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound, lootSourceType); if (missions != nullptr && !IsTransferInventory(inventoryType)) { @@ -255,6 +255,9 @@ void InventoryComponent::AddItem( if (slot == -1) { + // if (inventoryType == eInventoryType::VAULT_ITEMS || inventoryType == eInventoryType::VAULT_MODELS) { + + // } auto* player = dynamic_cast(GetParent()); if (player == nullptr) @@ -284,8 +287,8 @@ void InventoryComponent::AddItem( continue; } - - auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey); + Game::logger->Log("InventoryComponent", "new item with source %i\n", lootSourceType); + auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType); isModMoveAndEquip = false; } @@ -369,7 +372,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in left -= delta; - AddItem(lot, delta, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot); + AddItem(lot, delta, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot, eLootSourceType::LOOT_SOURCE_NONE); item->SetCount(item->GetCount() - delta, false, false); @@ -387,7 +390,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in const auto delta = std::min(item->GetCount(), count); - AddItem(lot, delta, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot); + AddItem(lot, delta, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot, eLootSourceType::LOOT_SOURCE_NONE); item->SetCount(item->GetCount() - delta, false, false); } diff --git a/dGame/dComponents/InventoryComponent.h b/dGame/dComponents/InventoryComponent.h index 0a4cfdb34..d73ee51d3 100644 --- a/dGame/dComponents/InventoryComponent.h +++ b/dGame/dComponents/InventoryComponent.h @@ -100,7 +100,8 @@ public: eInventoryType inventorySourceType = INVALID, int32_t sourceType = 0, bool bound = false, - int32_t preferredSlot = -1 + int32_t preferredSlot = -1, + eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE ); /** diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index a5c1168d1..4b61384d1 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -615,7 +615,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) GameMessages::SendRegisterPetDBID(m_Tamer, petSubKey, tamer->GetSystemAddress()); - inventoryComponent->AddItem(m_Parent->GetLOT(), 1, MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey); + inventoryComponent->AddItem(m_Parent->GetLOT(), 1, MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); auto* item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS); if (item == nullptr) diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index f982326ce..ad0ec7c35 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -491,7 +491,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet settings.push_back(propertyObjectID); settings.push_back(modelType); - inventoryComponent->AddItem(6662, 1, HIDDEN, settings, LWOOBJID_EMPTY, false, false, spawnerId, INVALID, 13, false, -1); + inventoryComponent->AddItem(6662, 1, HIDDEN, settings, LWOOBJID_EMPTY, false, false, spawnerId, INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); auto* item = inventoryComponent->FindItemBySubKey(spawnerId); if (item == nullptr) { @@ -526,7 +526,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet return; } - inventoryComponent->AddItem(model->GetLOT(), 1, INVALID, {}, LWOOBJID_EMPTY, false); + inventoryComponent->AddItem(model->GetLOT(), 1, INVALID, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); auto* item = inventoryComponent->FindItemByLot(model->GetLOT()); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 881b6ff50..d363f437f 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -423,7 +423,7 @@ void GameMessages::SendAddItemToInventoryClientSync(Entity* entity, const System bitStream.Write(lootSourceType != eLootSourceType::LOOT_SOURCE_NONE); // Loot source if (lootSourceType != eLootSourceType::LOOT_SOURCE_NONE) bitStream.Write(lootSourceType); - + Game::logger->Log("GameMessages", "lootSource %i\n", lootSourceType); LWONameValue extraInfo; auto config = item->GetConfig(); @@ -451,8 +451,8 @@ void GameMessages::SendAddItemToInventoryClientSync(Entity* entity, const System auto* inventory = item->GetInventory(); const auto inventoryType = inventory->GetType(); - bitStream.Write(inventoryType != INVENTORY_DEFAULT); - if (inventoryType != INVENTORY_DEFAULT) bitStream.Write(inventoryType); + bitStream.Write(inventoryType != eInventoryType::ITEMS); + if (inventoryType != eInventoryType::ITEMS) bitStream.Write(inventoryType); bitStream.Write(itemCount != 1); if (itemCount != 1) bitStream.Write(itemCount); @@ -4700,7 +4700,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(tokenId, altCurrencyCost); - inv->AddItem(item, count); + inv->AddItem(item, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); } else { @@ -4726,7 +4726,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti } character->SetCoins(character->GetCoins() - (coinCost), LOOT_SOURCE_VENDOR); - inv->AddItem(item, count); + inv->AddItem(item, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); } GameMessages::SendVendorTransactionResult(entity, sysAddr); @@ -4769,7 +4769,7 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit if (Inventory::IsValidItem(itemComp.currencyLOT)) { const auto altCurrency = (itemComp.altCurrencyCost * sellScalar) * count; - inv->AddItem(itemComp.currencyLOT, std::floor(altCurrency)); // Return alt currencies like faction tokens. + inv->AddItem(itemComp.currencyLOT, std::floor(altCurrency), eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); // Return alt currencies like faction tokens. } //inv->RemoveItem(count, -1, iObjID); @@ -5590,11 +5590,11 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity* if (count == 3) { - inv->AddItem(6416, 1, MODELS, config); + inv->AddItem(6416, 1, eInventoryType::MODELS, config, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_QUICKBUILD); } else if (count == 7) { - inv->AddItem(8092, 1, MODELS, config); + inv->AddItem(8092, 1, eInventoryType::MODELS, config, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_QUICKBUILD); } auto* missionComponent = character->GetComponent(); diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index ababed5f2..f3997200f 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -61,7 +61,7 @@ namespace GameMessages { void SendGMLevelBroadcast(const LWOOBJID& objectID, uint8_t level); void SendChatModeUpdate(const LWOOBJID& objectID, uint8_t level); - void SendAddItemToInventoryClientSync(Entity* entity, const SystemAddress& sysAddr, Item* item, const LWOOBJID& objectID, bool showFlyingLoot, int itemCount, LWOOBJID subKey = LWOOBJID_EMPTY); + void SendAddItemToInventoryClientSync(Entity* entity, const SystemAddress& sysAddr, Item* item, const LWOOBJID& objectID, bool showFlyingLoot, int itemCount, LWOOBJID subKey = LWOOBJID_EMPTY, eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE); void SendNotifyClientFlagChange(const LWOOBJID& objectID, int iFlagID, bool bFlag, const SystemAddress& sysAddr); void SendChangeObjectWorldState(const LWOOBJID& objectID, int state, const SystemAddress& sysAddr); diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index 20f5321ab..31601673f 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -14,7 +14,7 @@ class Inventory; -Item::Item(const LWOOBJID id, const LOT lot, Inventory* inventory, const uint32_t slot, const uint32_t count, const bool bound, const std::vector& config, const LWOOBJID parent, LWOOBJID subKey) +Item::Item(const LWOOBJID id, const LOT lot, Inventory* inventory, const uint32_t slot, const uint32_t count, const bool bound, const std::vector& config, const LWOOBJID parent, LWOOBJID subKey, eLootSourceType lootSourceType) { if (!Inventory::IsValidItem(lot)) { @@ -46,7 +46,8 @@ Item::Item( bool showFlyingLoot, bool isModMoveAndEquip, LWOOBJID subKey, - bool bound) + bool bound, + eLootSourceType lootSourceType) { if (!Inventory::IsValidItem(lot)) { @@ -80,8 +81,8 @@ Item::Item( inventory->AddManagedItem(this); auto* entity = inventory->GetComponent()->GetParent(); - - GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, static_cast(this->count), subKey); + Game::logger->Log("test", "source %i\n", lootSourceType); + GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, static_cast(this->count), subKey, lootSourceType); if (isModMoveAndEquip) { @@ -176,7 +177,7 @@ void Item::SetCount(const uint32_t value, const bool silent, const bool disassem if (value > count) { - GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, delta); + GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, delta, 0LL); } else { @@ -374,7 +375,7 @@ void Item::Disassemble(const eInventoryType inventoryType) for (const auto mod : modArray) { - inventory->GetComponent()->AddItem(mod, 1, inventoryType); + inventory->GetComponent()->AddItem(mod, 1, inventoryType, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); } } } @@ -472,7 +473,7 @@ void Item::DisassembleModel() continue; } - GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1); + GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); } } diff --git a/dGame/dInventory/Item.h b/dGame/dInventory/Item.h index 83ebb633a..dd81d7fec 100644 --- a/dGame/dInventory/Item.h +++ b/dGame/dInventory/Item.h @@ -36,7 +36,8 @@ public: bool bound, const std::vector& config, LWOOBJID parent, - LWOOBJID subKey + LWOOBJID subKey, + eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE ); /** @@ -62,7 +63,8 @@ public: bool showFlyingLoot = true, bool isModMoveAndEquip = false, LWOOBJID subKey = LWOOBJID_EMPTY, - bool bound = false + bool bound = false, + eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE ); ~Item(); diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 14fc5a24a..93a60ae94 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -463,7 +463,7 @@ void Mission::YieldRewards() { count = 0; } - inventoryComponent->AddItem(pair.first, count); + inventoryComponent->AddItem(pair.first, count, eInventoryType::INVALID, {}, 0LL, IsMission(), false, 0LL, eInventoryType::INVALID, 0, false, -1, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); } if (info->reward_currency_repeatable > 0 || coinsToSend > 0) { @@ -496,7 +496,7 @@ void Mission::YieldRewards() { count = 0; } - inventoryComponent->AddItem(pair.first, count); + inventoryComponent->AddItem(pair.first, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); } if (info->reward_currency > 0 || coinsToSend > 0) { diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 635b26202..0cceaeb2c 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -285,7 +285,7 @@ void LootGenerator::GiveLoot(Entity* player, std::unordered_map& r return; for (const auto& pair : result) { - inventoryComponent->AddItem(pair.first, pair.second); + inventoryComponent->AddItem(pair.first, pair.second, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } } diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index 302ba1cd1..d0718f4c9 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -363,7 +363,7 @@ void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddres auto inv = static_cast(player->GetComponent(COMPONENT_TYPE_INVENTORY)); if (!inv) return; - inv->AddItem(attachmentLOT, attachmentCount); + inv->AddItem(attachmentLOT, attachmentCount, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MAIL); Mail::SendAttachmentRemoveConfirm(sysAddr, mailID); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 2e3e2be77..69ee60b02 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -794,7 +794,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit InventoryComponent * inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); - inventory->AddItem(itemLOT, 1); + inventory->AddItem(itemLOT, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MODERATION); } else if(args.size() == 2) { uint32_t itemLOT; @@ -814,7 +814,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit InventoryComponent* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); - inventory->AddItem(itemLOT, count); + inventory->AddItem(itemLOT, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MODERATION); } else { ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /gmadditem "); @@ -1626,7 +1626,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit std::vector data {}; data.push_back(new LDFData(u"reforgedLOT", reforgedItem)); - inventoryComponent->AddItem(baseItem, 1, INVALID, data); + inventoryComponent->AddItem(baseItem, 1, eInventoryType::INVALID, data, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MODERATION); } if (chatCommand == "crash" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_OPERATOR) diff --git a/dScripts/AmDropshipComputer.cpp b/dScripts/AmDropshipComputer.cpp index 4101f526d..7f25574a6 100644 --- a/dScripts/AmDropshipComputer.cpp +++ b/dScripts/AmDropshipComputer.cpp @@ -32,7 +32,7 @@ void AmDropshipComputer::OnUse(Entity* self, Entity* user) return; } - inventoryComponent->AddItem(12323, 1); + inventoryComponent->AddItem(12323, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } void AmDropshipComputer::OnDie(Entity* self, Entity* killer) diff --git a/dScripts/NPCAddRemoveItem.cpp b/dScripts/NPCAddRemoveItem.cpp index 7d36c1e1b..8cc2b6fd7 100644 --- a/dScripts/NPCAddRemoveItem.cpp +++ b/dScripts/NPCAddRemoveItem.cpp @@ -11,7 +11,7 @@ void NPCAddRemoveItem::OnMissionDialogueOK(Entity *self, Entity *target, int mis for (const auto& itemSetting : missionSetting.second) { for (const auto& lot : itemSetting.items) { if (itemSetting.add && (missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE)) { - inventory->AddItem(lot, 1); + inventory->AddItem(lot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (itemSetting.remove && (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE)) { inventory->RemoveItem(lot, 1); } diff --git a/dScripts/NjColeNPC.cpp b/dScripts/NjColeNPC.cpp index 54d38bda0..e342e429f 100644 --- a/dScripts/NjColeNPC.cpp +++ b/dScripts/NjColeNPC.cpp @@ -54,6 +54,6 @@ void NjColeNPC::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, return; } - inventoryComponent->AddItem(16644, 1); + inventoryComponent->AddItem(16644, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); } } diff --git a/dScripts/NjScrollChestServer.cpp b/dScripts/NjScrollChestServer.cpp index ba3fda7af..4677f8276 100644 --- a/dScripts/NjScrollChestServer.cpp +++ b/dScripts/NjScrollChestServer.cpp @@ -12,6 +12,6 @@ void NjScrollChestServer::OnUse(Entity *self, Entity *user) { playerInventory->RemoveItem(keyLOT, 1); // Reward the player with the item set - playerInventory->AddItem(rewardItemLOT, 1); + playerInventory->AddItem(rewardItemLOT, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } } diff --git a/dScripts/NpcCowboyServer.cpp b/dScripts/NpcCowboyServer.cpp index 7ec031b9c..b92d921fe 100644 --- a/dScripts/NpcCowboyServer.cpp +++ b/dScripts/NpcCowboyServer.cpp @@ -23,7 +23,7 @@ void NpcCowboyServer::OnMissionDialogueOK(Entity* self, Entity* target, int miss { if (inventoryComponent->GetLotCount(14378) == 0) { - inventoryComponent->AddItem(14378, 1); + inventoryComponent->AddItem(14378, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) diff --git a/dScripts/NpcPirateServer.cpp b/dScripts/NpcPirateServer.cpp index 4a1db1f68..acf7e67fa 100644 --- a/dScripts/NpcPirateServer.cpp +++ b/dScripts/NpcPirateServer.cpp @@ -9,7 +9,7 @@ void NpcPirateServer::OnMissionDialogueOK(Entity *self, Entity *target, int miss // Add or remove the lucky shovel based on whether the mission was completed or started if ((missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE) && luckyShovel == nullptr) { - inventory->AddItem(14591, 1); + inventory->AddItem(14591, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) { inventory->RemoveItem(14591, 1); } diff --git a/dScripts/NpcWispServer.cpp b/dScripts/NpcWispServer.cpp index 2f94236d6..3000b4c91 100644 --- a/dScripts/NpcWispServer.cpp +++ b/dScripts/NpcWispServer.cpp @@ -20,7 +20,7 @@ void NpcWispServer::OnMissionDialogueOK(Entity* self, Entity* target, int missio // For the daily we add the maelstrom vacuum if the player doesn't have it yet if (missionID == 1883 && (missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE) && maelstromVacuum == nullptr) { - inventory->AddItem(maelstromVacuumLot, 1); + inventory->AddItem(maelstromVacuumLot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) { inventory->RemoveItem(maelstromVacuumLot, 1); } diff --git a/dScripts/NsConcertInstrument.cpp b/dScripts/NsConcertInstrument.cpp index f0257c93e..d1de993c6 100644 --- a/dScripts/NsConcertInstrument.cpp +++ b/dScripts/NsConcertInstrument.cpp @@ -195,7 +195,7 @@ void NsConcertInstrument::EquipInstruments(Entity *self, Entity *player) { // Equip the left hand instrument const auto leftInstrumentLot = instrumentLotLeft.find(GetInstrumentLot(self))->second; if (leftInstrumentLot != LOT_NULL) { - inventory->AddItem(leftInstrumentLot, 1, TEMP_ITEMS, {}, LWOOBJID_EMPTY, false); + inventory->AddItem(leftInstrumentLot, 1, TEMP_ITEMS, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); auto* leftInstrument = inventory->FindItemByLot(leftInstrumentLot, TEMP_ITEMS); leftInstrument->Equip(); } @@ -203,7 +203,7 @@ void NsConcertInstrument::EquipInstruments(Entity *self, Entity *player) { // Equip the right hand instrument const auto rightInstrumentLot = instrumentLotRight.find(GetInstrumentLot(self))->second; if (rightInstrumentLot != LOT_NULL) { - inventory->AddItem(rightInstrumentLot, 1, TEMP_ITEMS, {}, LWOOBJID_EMPTY, false); + inventory->AddItem(rightInstrumentLot, 1, TEMP_ITEMS, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); auto* rightInstrument = inventory->FindItemByLot(rightInstrumentLot, TEMP_ITEMS); rightInstrument->Equip(); } diff --git a/dScripts/NsTokenConsoleServer.cpp b/dScripts/NsTokenConsoleServer.cpp index f6b022d0d..0416a0301 100644 --- a/dScripts/NsTokenConsoleServer.cpp +++ b/dScripts/NsTokenConsoleServer.cpp @@ -50,19 +50,19 @@ void NsTokenConsoleServer::OnUse(Entity* self, Entity* user) if (character->GetPlayerFlag(46)) { - inventoryComponent->AddItem(8321, 5); + inventoryComponent->AddItem(8321, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); } else if (character->GetPlayerFlag(47)) { - inventoryComponent->AddItem(8318, 5); + inventoryComponent->AddItem(8318, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); } else if (character->GetPlayerFlag(48)) { - inventoryComponent->AddItem(8320, 5); + inventoryComponent->AddItem(8320, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); } else if (character->GetPlayerFlag(49)) { - inventoryComponent->AddItem(8319, 5); + inventoryComponent->AddItem(8319, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); } missionComponent->ForceProgressTaskType(863, 1, 1, false); diff --git a/dScripts/NtDukeServer.cpp b/dScripts/NtDukeServer.cpp index 0f56d6cca..db278aa17 100644 --- a/dScripts/NtDukeServer.cpp +++ b/dScripts/NtDukeServer.cpp @@ -29,7 +29,7 @@ void NtDukeServer::OnMissionDialogueOK(Entity *self, Entity *target, int mission auto lotCount = inventoryComponent->GetLotCount(m_SwordLot); if ((state == MissionState::MISSION_STATE_AVAILABLE || state == MissionState::MISSION_STATE_ACTIVE) && lotCount < 1) { - inventoryComponent->AddItem(m_SwordLot, 1); + inventoryComponent->AddItem(m_SwordLot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (state == MissionState::MISSION_STATE_READY_TO_COMPLETE) { inventoryComponent->RemoveItem(m_SwordLot, lotCount); } diff --git a/dScripts/SGCannon.cpp b/dScripts/SGCannon.cpp index 4b991253f..efb7d7fcd 100644 --- a/dScripts/SGCannon.cpp +++ b/dScripts/SGCannon.cpp @@ -574,7 +574,7 @@ void SGCannon::StopGame(Entity *self, bool cancel) { auto* inventory = player->GetComponent(); if (inventory != nullptr) { for (const auto rewardLot : self->GetVar>(RewardsVariable)) { - inventory->AddItem(rewardLot, 1, eInventoryType::MODELS); + inventory->AddItem(rewardLot, 1, eInventoryType::MODELS, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } } diff --git a/dScripts/TokenConsoleServer.cpp b/dScripts/TokenConsoleServer.cpp index dcefe2f26..0ca18e765 100644 --- a/dScripts/TokenConsoleServer.cpp +++ b/dScripts/TokenConsoleServer.cpp @@ -21,15 +21,17 @@ void TokenConsoleServer::OnUse(Entity* self, Entity* user) { //figure out which faction the player belongs to: auto character = user->GetCharacter(); if (!character) return; - + // At this point the player has to be in a faction. + LOT tokenLOT = 0; if (character->GetPlayerFlag(ePlayerFlags::VENTURE_FACTION)) //venture - inv->AddItem(8321, tokensToGive); + tokenLOT = 8321; else if (character->GetPlayerFlag(ePlayerFlags::ASSEMBLY_FACTION)) //assembly - inv->AddItem(8318, tokensToGive); + tokenLOT = 8318; else if (character->GetPlayerFlag(ePlayerFlags::PARADOX_FACTION)) //paradox - inv->AddItem(8320, tokensToGive); + tokenLOT = 8320; else if (character->GetPlayerFlag(ePlayerFlags::SENTINEL_FACTION)) //sentinel - inv->AddItem(8319, tokensToGive); + tokenLOT = 8319; + inv->AddItem(tokenLOT, tokensToGive, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); } GameMessages::SendTerminateInteraction(user->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID()); diff --git a/dScripts/VeBricksampleServer.cpp b/dScripts/VeBricksampleServer.cpp index 42ccd460a..f9d5f3d2f 100644 --- a/dScripts/VeBricksampleServer.cpp +++ b/dScripts/VeBricksampleServer.cpp @@ -10,7 +10,7 @@ void VeBricksampleServer::OnUse(Entity *self, Entity *user) { auto* inventoryComponent = user->GetComponent(); if (loot && inventoryComponent != nullptr && inventoryComponent->GetLotCount(loot) == 0) { - inventoryComponent->AddItem(loot, 1); + inventoryComponent->AddItem(loot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); for (auto* brickEntity : EntityManager::Instance()->GetEntitiesInGroup("Bricks")) { GameMessages::SendNotifyClientObject(brickEntity->GetObjectID(), u"Pickedup"); diff --git a/dScripts/VeMissionConsole.cpp b/dScripts/VeMissionConsole.cpp index 4a506dac3..9e5602448 100644 --- a/dScripts/VeMissionConsole.cpp +++ b/dScripts/VeMissionConsole.cpp @@ -8,7 +8,7 @@ void VeMissionConsole::OnUse(Entity *self, Entity *user) { auto* inventoryComponent = user->GetComponent(); if (inventoryComponent != nullptr) { - inventoryComponent->AddItem(12547, 1); // Add the panel required for pickup + inventoryComponent->AddItem(12547, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); // Add the panel required for pickup } // The flag to set is 101 From 8e10f090fd6309f5649184722fb6e864fbd0d066 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 18:52:21 -0700 Subject: [PATCH 40/48] corrected number --- dGame/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 8a1d3c826..fbec11570 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1637,7 +1637,7 @@ void Entity::PickupItem(const LWOOBJID& objectID) { } } else { - inv->AddItem(p.second.lot, p.second.count, INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_PICKUP); + inv->AddItem(p.second.lot, p.second.count, INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, INVALID, 1, false, -1, eLootSourceType::LOOT_SOURCE_PICKUP); } } } From ceab229a63341ab763490f97724986bdf4c7e34d Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:32:31 -0700 Subject: [PATCH 41/48] Specified enum the LOOT_SOURCE enum is now attached to all loot sources. --- dGame/Character.cpp | 2 +- dGame/TradingManager.cpp | 4 ++-- dGame/dComponents/CharacterComponent.cpp | 2 +- dGame/dComponents/DestroyableComponent.cpp | 2 +- dGame/dComponents/InventoryComponent.cpp | 2 +- dGame/dGameMessages/GameMessages.cpp | 28 +++++++++++----------- dGame/dMission/Mission.cpp | 6 ++--- dGame/dUtilities/Mail.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 6 ++--- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/dGame/Character.cpp b/dGame/Character.cpp index d396382cf..ce61ae700 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -534,7 +534,7 @@ void Character::OnZoneLoad() */ if (HasPermission(PermissionMap::Old)) { if (GetCoins() > 1000000) { - SetCoins(1000000, LOOT_SOURCE_NONE); + SetCoins(1000000, eLootSourceType::LOOT_SOURCE_NONE); } } diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index e178d1302..c489c47b6 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, LOOT_SOURCE_TRADE); - characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, LOOT_SOURCE_TRADE); + characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, eLootSourceType::LOOT_SOURCE_TRADE); + characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, eLootSourceType::LOOT_SOURCE_TRADE); for (const auto& tradeItem : m_ItemsA) { diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 67b820c26..8c4b0962c 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -221,7 +221,7 @@ void CharacterComponent::HandleLevelUp() break; case 4: { - auto* items = inventoryComponent->GetInventory(ITEMS); + auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS); items->SetSize(items->GetSize() + reward->value); } break; diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 31b3af190..8a99c0692 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -821,7 +821,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType coinsTotal -= coinsToLoose; LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose); - character->SetCoins(coinsTotal, LOOT_SOURCE_PICKUP); + character->SetCoins(coinsTotal, eLootSourceType::LOOT_SOURCE_PICKUP); } } diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index d7a059a06..85d58065d 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -207,7 +207,7 @@ void InventoryComponent::AddItem( auto stack = static_cast(info.stackSize); - if (inventoryType == BRICKS) + if (inventoryType == eInventoryType::BRICKS) { stack = 999; } diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index d363f437f..b051ad457 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -566,8 +566,8 @@ void GameMessages::SendModifyLEGOScore(Entity* entity, const SystemAddress& sysA bitStream.Write((uint16_t)GAME_MSG_MODIFY_LEGO_SCORE); bitStream.Write(score); - bitStream.Write(sourceType != LOOT_SOURCE_NONE); - if (sourceType != LOOT_SOURCE_NONE) bitStream.Write(sourceType); + bitStream.Write(sourceType != eLootSourceType::LOOT_SOURCE_NONE); + if (sourceType != eLootSourceType::LOOT_SOURCE_NONE) bitStream.Write(sourceType); SEND_PACKET } @@ -4725,8 +4725,8 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); } - character->SetCoins(character->GetCoins() - (coinCost), LOOT_SOURCE_VENDOR); inv->AddItem(item, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); + character->SetCoins(character->GetCoins() - (coinCost), eLootSourceType::LOOT_SOURCE_VENDOR); } GameMessages::SendVendorTransactionResult(entity, sysAddr); @@ -4773,8 +4773,8 @@ 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)), LOOT_SOURCE_VENDOR); + inv->MoveItemToInventory(item, eInventoryType::VENDOR_BUYBACK, count, true, false, true); + character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), eLootSourceType::LOOT_SOURCE_VENDOR); //EntityManager::Instance()->SerializeEntity(player); // so inventory updates GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -4836,7 +4836,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, LOOT_SOURCE_VENDOR); + character->SetCoins(character->GetCoins() - cost, eLootSourceType::LOOT_SOURCE_VENDOR); //EntityManager::Instance()->SerializeEntity(player); // so inventory updates GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -5269,7 +5269,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent auto* ch = entity->GetCharacter(); if (entity->CanPickupCoins(currency)) { - ch->SetCoins(ch->GetCoins() + currency, LOOT_SOURCE_PICKUP); + ch->SetCoins(ch->GetCoins() + currency, eLootSourceType::LOOT_SOURCE_PICKUP); } } @@ -5484,8 +5484,8 @@ void GameMessages::HandleMoveItemInInventory(RakNet::BitStream* inStream, Entity } void GameMessages::HandleMoveItemBetweenInventoryTypes(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { - int inventoryTypeA; - int inventoryTypeB; + eInventoryType inventoryTypeA; + eInventoryType inventoryTypeB; LWOOBJID objectID; bool showFlyingLoot = true; bool stackCountIsDefault = false; @@ -5502,7 +5502,7 @@ void GameMessages::HandleMoveItemBetweenInventoryTypes(RakNet::BitStream* inStre inStream->Read(templateIDIsDefault); if (templateIDIsDefault) inStream->Read(templateID); - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto inv = entity->GetComponent(); if (!inv) return; auto* item = inv->FindItemById(objectID); @@ -5523,7 +5523,7 @@ void GameMessages::HandleMoveItemBetweenInventoryTypes(RakNet::BitStream* inStre } } - inv->MoveItemToInventory(item, static_cast(inventoryTypeB), stackCount, showFlyingLoot, false); + inv->MoveItemToInventory(item, inventoryTypeB, stackCount, showFlyingLoot); EntityManager::Instance()->SerializeEntity(entity); } @@ -5624,7 +5624,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity* for (auto* item : items) { - inv->MoveItemToInventory(item, MODELS, item->GetCount(), false); + inv->MoveItemToInventory(item, eInventoryType::MODELS, item->GetCount(), false); } } @@ -5739,7 +5739,7 @@ void GameMessages::HandleDoneArrangingWithItem(RakNet::BitStream* inStream, Enti for (auto* item : items) { - inv->MoveItemToInventory(item, MODELS, item->GetCount(), false, false); + inv->MoveItemToInventory(item, eInventoryType::MODELS, item->GetCount(), false, false); } } @@ -5765,7 +5765,7 @@ void GameMessages::HandleModularBuildMoveAndEquip(RakNet::BitStream* inStream, E return; } - inv->MoveItemToInventory(item, MODELS, 1, false, true); + inv->MoveItemToInventory(item, eInventoryType::MODELS, 1, false, true); } void GameMessages::HandlePickupItem(RakNet::BitStream* inStream, Entity* entity) { diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 93a60ae94..9732bb5b7 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -430,7 +430,7 @@ void Mission::YieldRewards() { int32_t coinsToSend = 0; if (info->LegoScore > 0) { - eLootSourceType lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; + eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT; if(characterComponent->GetLevel() >= dZoneManager::Instance()->GetMaxLevel()) { // Since the character is at the level cap we reward them with coins instead of UScore. coinsToSend += info->LegoScore * dZoneManager::Instance()->GetLevelCapCurrencyConversion(); @@ -467,7 +467,7 @@ void Mission::YieldRewards() { } if (info->reward_currency_repeatable > 0 || coinsToSend > 0) { - eLootSourceType lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; + eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT; character->SetCoins(character->GetCoins() + info->reward_currency_repeatable + coinsToSend, lootSource); } @@ -500,7 +500,7 @@ void Mission::YieldRewards() { } if (info->reward_currency > 0 || coinsToSend > 0) { - eLootSourceType lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT; + eLootSourceType lootSource = info->isMission ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT; character->SetCoins(character->GetCoins() + info->reward_currency + coinsToSend, lootSource); } diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index d0718f4c9..89cc0fff9 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, LOOT_SOURCE_MAIL); + entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, eLootSourceType::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 69ee60b02..d94c8d473 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1293,7 +1293,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit CharacterComponent* character = entity->GetComponent(); if (character) character->SetUScore(character->GetUScore() + uscore); // LOOT_SOURCE_MODERATION should work but it doesn't. Relog to see uscore changes - GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, LOOT_SOURCE_MODERATION); + GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, eLootSourceType::LOOT_SOURCE_MODERATION); } if (chatCommand == "pos" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { @@ -1337,7 +1337,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } auto* ch = entity->GetCharacter(); - ch->SetCoins(ch->GetCoins() + money, LOOT_SOURCE_MODERATION); + ch->SetCoins(ch->GetCoins() + money, eLootSourceType::LOOT_SOURCE_MODERATION); } if ((chatCommand == "setcurrency") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { @@ -1350,7 +1350,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } auto* ch = entity->GetCharacter(); - ch->SetCoins(money, LOOT_SOURCE_MODERATION); + ch->SetCoins(money, eLootSourceType::LOOT_SOURCE_MODERATION); } // Allow for this on even while not a GM, as it sometimes toggles incorrrectly. From 7a051afd97f49583a5fbfba7136a8077e41bb81f Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:35:34 -0700 Subject: [PATCH 42/48] loot source for item drops Added support for Items to have a loot source attached to them when dropped or rolled. This fixes the issue where achievements would give the item before it appeared in the achievement window. --- dGame/Entity.cpp | 2 +- dGame/TradingManager.cpp | 4 ++-- dGame/dComponents/CharacterComponent.cpp | 2 +- dGame/dComponents/InventoryComponent.cpp | 15 ++++++--------- dGame/dComponents/InventoryComponent.h | 5 +++-- dGame/dComponents/PetComponent.cpp | 2 +- dGame/dComponents/PropertyManagementComponent.cpp | 4 ++-- dGame/dGameMessages/GameMessages.cpp | 12 ++++++------ dGame/dInventory/Item.cpp | 10 +++++----- dGame/dInventory/Item.h | 2 +- dGame/dMission/Mission.cpp | 4 ++-- dGame/dUtilities/Loot.cpp | 12 ++++++------ dGame/dUtilities/Loot.h | 4 ++-- dGame/dUtilities/Mail.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 6 +++--- dScripts/AmDropshipComputer.cpp | 2 +- dScripts/NPCAddRemoveItem.cpp | 2 +- dScripts/NjColeNPC.cpp | 2 +- dScripts/NjScrollChestServer.cpp | 2 +- dScripts/NpcCowboyServer.cpp | 2 +- dScripts/NpcPirateServer.cpp | 2 +- dScripts/NpcWispServer.cpp | 2 +- dScripts/NsConcertInstrument.cpp | 4 ++-- dScripts/NsTokenConsoleServer.cpp | 13 +++++++++---- dScripts/NtDukeServer.cpp | 2 +- dScripts/SGCannon.cpp | 2 +- dScripts/TokenConsoleServer.cpp | 2 +- dScripts/VeBricksampleServer.cpp | 2 +- dScripts/VeMissionConsole.cpp | 2 +- 29 files changed, 65 insertions(+), 62 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index fbec11570..799e78032 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1637,7 +1637,7 @@ void Entity::PickupItem(const LWOOBJID& objectID) { } } else { - inv->AddItem(p.second.lot, p.second.count, INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, INVALID, 1, false, -1, eLootSourceType::LOOT_SOURCE_PICKUP); + inv->AddItem(p.second.lot, p.second.count, eLootSourceType::LOOT_SOURCE_PICKUP, eInventoryType::INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, eInventoryType::INVALID, 1); } } } diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index c489c47b6..04a0501d2 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -170,12 +170,12 @@ void Trade::Complete() for (const auto& tradeItem : m_ItemsA) { - inventoryB->AddItem(tradeItem.itemLot, tradeItem.itemCount, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_TRADE); + inventoryB->AddItem(tradeItem.itemLot, tradeItem.itemCount, eLootSourceType::LOOT_SOURCE_TRADE); } for (const auto& tradeItem : m_ItemsB) { - inventoryA->AddItem(tradeItem.itemLot, tradeItem.itemCount, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_TRADE); + inventoryA->AddItem(tradeItem.itemLot, tradeItem.itemCount, eLootSourceType::LOOT_SOURCE_TRADE); } TradingManager::Instance()->CancelTrade(m_TradeId); diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 8c4b0962c..815a3d59b 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -217,7 +217,7 @@ void CharacterComponent::HandleLevelUp() switch (reward->rewardType) { case 0: - inventoryComponent->AddItem(reward->value, reward->count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD); + inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD); break; case 4: { diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 85d58065d..e03f4e924 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -141,6 +141,7 @@ const EquipmentMap& InventoryComponent::GetEquippedItems() const void InventoryComponent::AddItem( const LOT lot, const uint32_t count, + eLootSourceType lootSourceType, eInventoryType inventoryType, const std::vector& config, const LWOOBJID parent, @@ -150,8 +151,7 @@ void InventoryComponent::AddItem( const eInventoryType inventorySourceType, const int32_t sourceType, const bool bound, - int32_t preferredSlot, - eLootSourceType lootSourceType) + int32_t preferredSlot) { if (count == 0) { @@ -181,7 +181,7 @@ void InventoryComponent::AddItem( if (!config.empty() || bound) { - const auto slot = inventory->FindEmptySlot(); + const auto slot = preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot) ? preferredSlot : inventory->FindEmptySlot(); if (slot == -1) { @@ -224,7 +224,7 @@ void InventoryComponent::AddItem( left -= delta; - existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot); + existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot, lootSourceType); if (isModMoveAndEquip) { @@ -255,9 +255,6 @@ void InventoryComponent::AddItem( if (slot == -1) { - // if (inventoryType == eInventoryType::VAULT_ITEMS || inventoryType == eInventoryType::VAULT_MODELS) { - - // } auto* player = dynamic_cast(GetParent()); if (player == nullptr) @@ -372,7 +369,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in left -= delta; - AddItem(lot, delta, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot, eLootSourceType::LOOT_SOURCE_NONE); + AddItem(lot, delta, eLootSourceType::LOOT_SOURCE_NONE, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot); item->SetCount(item->GetCount() - delta, false, false); @@ -390,7 +387,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in const auto delta = std::min(item->GetCount(), count); - AddItem(lot, delta, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot, eLootSourceType::LOOT_SOURCE_NONE); + AddItem(lot, delta, eLootSourceType::LOOT_SOURCE_NONE, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot); item->SetCount(item->GetCount() - delta, false, false); } diff --git a/dGame/dComponents/InventoryComponent.h b/dGame/dComponents/InventoryComponent.h index d73ee51d3..bf18d1324 100644 --- a/dGame/dComponents/InventoryComponent.h +++ b/dGame/dComponents/InventoryComponent.h @@ -87,10 +87,12 @@ public: * @param sourceType the source of the item, used to determine if the item is dropped or mailed if the inventory is full * @param bound whether this item is bound * @param preferredSlot the preferred slot to store this item + * @param lootSourceType The source of the loot. Defaults to none. */ void AddItem( LOT lot, uint32_t count, + eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE, eInventoryType inventoryType = INVALID, const std::vector& config = {}, LWOOBJID parent = LWOOBJID_EMPTY, @@ -100,8 +102,7 @@ public: eInventoryType inventorySourceType = INVALID, int32_t sourceType = 0, bool bound = false, - int32_t preferredSlot = -1, - eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE + int32_t preferredSlot = -1 ); /** diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 4b61384d1..97c7e95b1 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -615,7 +615,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) GameMessages::SendRegisterPetDBID(m_Tamer, petSubKey, tamer->GetSystemAddress()); - inventoryComponent->AddItem(m_Parent->GetLOT(), 1, MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(m_Parent->GetLOT(), 1, eLootSourceType::LOOT_SOURCE_ACTIVITY, eInventoryType::MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey); auto* item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS); if (item == nullptr) diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index ad0ec7c35..0a428e040 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -491,7 +491,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet settings.push_back(propertyObjectID); settings.push_back(modelType); - inventoryComponent->AddItem(6662, 1, HIDDEN, settings, LWOOBJID_EMPTY, false, false, spawnerId, INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); + inventoryComponent->AddItem(6662, 1, eLootSourceType::LOOT_SOURCE_DELETION, eInventoryType::HIDDEN, settings, LWOOBJID_EMPTY, false, false, spawnerId); auto* item = inventoryComponent->FindItemBySubKey(spawnerId); if (item == nullptr) { @@ -526,7 +526,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet return; } - inventoryComponent->AddItem(model->GetLOT(), 1, INVALID, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); + inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::LOOT_SOURCE_DELETION, INVALID, {}, LWOOBJID_EMPTY, false); auto* item = inventoryComponent->FindItemByLot(model->GetLOT()); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index b051ad457..e0f38dbe2 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -4700,7 +4700,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(tokenId, altCurrencyCost); - inv->AddItem(item, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); + inv->AddItem(item, count, eLootSourceType::LOOT_SOURCE_VENDOR); } else { @@ -4725,8 +4725,8 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); } - inv->AddItem(item, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); character->SetCoins(character->GetCoins() - (coinCost), eLootSourceType::LOOT_SOURCE_VENDOR); + inv->AddItem(item, count, eLootSourceType::LOOT_SOURCE_VENDOR); } GameMessages::SendVendorTransactionResult(entity, sysAddr); @@ -4769,7 +4769,7 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit if (Inventory::IsValidItem(itemComp.currencyLOT)) { const auto altCurrency = (itemComp.altCurrencyCost * sellScalar) * count; - inv->AddItem(itemComp.currencyLOT, std::floor(altCurrency), eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); // Return alt currencies like faction tokens. + inv->AddItem(itemComp.currencyLOT, std::floor(altCurrency), eLootSourceType::LOOT_SOURCE_VENDOR); // Return alt currencies like faction tokens. } //inv->RemoveItem(count, -1, iObjID); @@ -5103,7 +5103,7 @@ void GameMessages::HandleModularBuildConvertModel(RakNet::BitStream* inStream, E item->Disassemble(TEMP_MODELS); - item->SetCount(item->GetCount() - 1, false, false); + item->SetCount(item->GetCount() - 1, false, false, true, eLootSourceType::LOOT_SOURCE_QUICKBUILD); } void GameMessages::HandleSetFlag(RakNet::BitStream* inStream, Entity* entity) { @@ -5590,11 +5590,11 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity* if (count == 3) { - inv->AddItem(6416, 1, eInventoryType::MODELS, config, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_QUICKBUILD); + inv->AddItem(6416, 1, eLootSourceType::LOOT_SOURCE_QUICKBUILD, eInventoryType::MODELS, config); } else if (count == 7) { - inv->AddItem(8092, 1, eInventoryType::MODELS, config, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_QUICKBUILD); + inv->AddItem(8092, 1, eLootSourceType::LOOT_SOURCE_QUICKBUILD, eInventoryType::MODELS, config); } auto* missionComponent = character->GetComponent(); diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index 31601673f..213430d22 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -149,7 +149,7 @@ PreconditionExpression* Item::GetPreconditionExpression() const return preconditions; } -void Item::SetCount(const uint32_t value, const bool silent, const bool disassemble, const bool showFlyingLoot) +void Item::SetCount(const uint32_t value, const bool silent, const bool disassemble, const bool showFlyingLoot, eLootSourceType lootSourceType) { if (value == count) { @@ -177,7 +177,7 @@ void Item::SetCount(const uint32_t value, const bool silent, const bool disassem if (value > count) { - GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, delta, 0LL); + GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, delta, LWOOBJID_EMPTY, lootSourceType); } else { @@ -341,7 +341,7 @@ bool Item::UseNonEquip() return false; } - LootGenerator::Instance().GiveLoot(inventory->GetComponent()->GetParent(), result); + LootGenerator::Instance().GiveLoot(inventory->GetComponent()->GetParent(), result, eLootSourceType::LOOT_SOURCE_CONSUMPTION); } inventory->GetComponent()->RemoveItem(lot, 1); @@ -375,7 +375,7 @@ void Item::Disassemble(const eInventoryType inventoryType) for (const auto mod : modArray) { - inventory->GetComponent()->AddItem(mod, 1, inventoryType, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); + inventory->GetComponent()->AddItem(mod, 1, eLootSourceType::LOOT_SOURCE_DELETION, inventoryType); } } } @@ -473,7 +473,7 @@ void Item::DisassembleModel() continue; } - GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION); + GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1, eLootSourceType::LOOT_SOURCE_DELETION); } } diff --git a/dGame/dInventory/Item.h b/dGame/dInventory/Item.h index dd81d7fec..0be9449a6 100644 --- a/dGame/dInventory/Item.h +++ b/dGame/dInventory/Item.h @@ -88,7 +88,7 @@ public: * @param disassemble if items were removed, this returns all the sub parts of the item individually if it had assembly part lots * @param showFlyingLoot shows flying loot to the client, if not silent */ - void SetCount(uint32_t value, bool silent = false, bool disassemble = true, bool showFlyingLoot = true); + void SetCount(uint32_t value, bool silent = false, bool disassemble = true, bool showFlyingLoot = true, eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE); /** * Returns the number of items this item represents (e.g. for stacks) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 9732bb5b7..c2553f24b 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -463,7 +463,7 @@ void Mission::YieldRewards() { count = 0; } - inventoryComponent->AddItem(pair.first, count, eInventoryType::INVALID, {}, 0LL, IsMission(), false, 0LL, eInventoryType::INVALID, 0, false, -1, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); + inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); } if (info->reward_currency_repeatable > 0 || coinsToSend > 0) { @@ -496,7 +496,7 @@ void Mission::YieldRewards() { count = 0; } - inventoryComponent->AddItem(pair.first, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); + inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); } if (info->reward_currency > 0 || coinsToSend > 0) { diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 0cceaeb2c..8305e152a 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -268,15 +268,15 @@ std::unordered_map LootGenerator::RollLootMatrix(uint32_t matrixIn return drops; } -void LootGenerator::GiveLoot(Entity* player, uint32_t matrixIndex) { +void LootGenerator::GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType) { player = player->GetOwner(); // If the owner is overwritten, we collect that here std::unordered_map result = RollLootMatrix(player, matrixIndex); - GiveLoot(player, result); + GiveLoot(player, result, lootSourceType); } -void LootGenerator::GiveLoot(Entity* player, std::unordered_map& result) { +void LootGenerator::GiveLoot(Entity* player, std::unordered_map& result, eLootSourceType lootSourceType) { player = player->GetOwner(); // if the owner is overwritten, we collect that here auto* inventoryComponent = player->GetComponent(); @@ -285,7 +285,7 @@ void LootGenerator::GiveLoot(Entity* player, std::unordered_map& r return; for (const auto& pair : result) { - inventoryComponent->AddItem(pair.first, pair.second, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(pair.first, pair.second, lootSourceType); } } @@ -314,13 +314,13 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac maxCoins = currencyTable[0].maxvalue; } - GiveLoot(player, selectedReward->LootMatrixIndex); + GiveLoot(player, selectedReward->LootMatrixIndex, eLootSourceType::LOOT_SOURCE_ACTIVITY); uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber(0, 1) * (maxCoins - minCoins)); auto* character = player->GetCharacter(); - character->SetCoins(character->GetCoins() + coins, LOOT_SOURCE_ACTIVITY); + character->SetCoins(character->GetCoins() + coins, eLootSourceType::LOOT_SOURCE_ACTIVITY); } void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) { diff --git a/dGame/dUtilities/Loot.h b/dGame/dUtilities/Loot.h index 23c6463dc..b16c834a8 100644 --- a/dGame/dUtilities/Loot.h +++ b/dGame/dUtilities/Loot.h @@ -47,8 +47,8 @@ class LootGenerator : public Singleton { std::unordered_map RollLootMatrix(Entity* player, uint32_t matrixIndex); std::unordered_map RollLootMatrix(uint32_t matrixIndex); - void GiveLoot(Entity* player, uint32_t matrixIndex); - void GiveLoot(Entity* player, std::unordered_map& result); + void GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE); + void GiveLoot(Entity* player, std::unordered_map& result, eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE); void GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating = 0); void DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins); void DropLoot(Entity* player, Entity* killedObject, std::unordered_map& result, uint32_t minCoins, uint32_t maxCoins); diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index 89cc0fff9..79e99c7db 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -363,7 +363,7 @@ void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddres auto inv = static_cast(player->GetComponent(COMPONENT_TYPE_INVENTORY)); if (!inv) return; - inv->AddItem(attachmentLOT, attachmentCount, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MAIL); + inv->AddItem(attachmentLOT, attachmentCount, eLootSourceType::LOOT_SOURCE_MAIL); Mail::SendAttachmentRemoveConfirm(sysAddr, mailID); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index d94c8d473..ca8589200 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -794,7 +794,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit InventoryComponent * inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); - inventory->AddItem(itemLOT, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MODERATION); + inventory->AddItem(itemLOT, 1, eLootSourceType::LOOT_SOURCE_MODERATION); } else if(args.size() == 2) { uint32_t itemLOT; @@ -814,7 +814,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit InventoryComponent* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); - inventory->AddItem(itemLOT, count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MODERATION); + inventory->AddItem(itemLOT, count, eLootSourceType::LOOT_SOURCE_MODERATION); } else { ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /gmadditem "); @@ -1626,7 +1626,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit std::vector data {}; data.push_back(new LDFData(u"reforgedLOT", reforgedItem)); - inventoryComponent->AddItem(baseItem, 1, eInventoryType::INVALID, data, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_MODERATION); + inventoryComponent->AddItem(baseItem, 1, eLootSourceType::LOOT_SOURCE_MODERATION); } if (chatCommand == "crash" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_OPERATOR) diff --git a/dScripts/AmDropshipComputer.cpp b/dScripts/AmDropshipComputer.cpp index 7f25574a6..d90bfa973 100644 --- a/dScripts/AmDropshipComputer.cpp +++ b/dScripts/AmDropshipComputer.cpp @@ -32,7 +32,7 @@ void AmDropshipComputer::OnUse(Entity* self, Entity* user) return; } - inventoryComponent->AddItem(12323, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(12323, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } void AmDropshipComputer::OnDie(Entity* self, Entity* killer) diff --git a/dScripts/NPCAddRemoveItem.cpp b/dScripts/NPCAddRemoveItem.cpp index 8cc2b6fd7..484cc8273 100644 --- a/dScripts/NPCAddRemoveItem.cpp +++ b/dScripts/NPCAddRemoveItem.cpp @@ -11,7 +11,7 @@ void NPCAddRemoveItem::OnMissionDialogueOK(Entity *self, Entity *target, int mis for (const auto& itemSetting : missionSetting.second) { for (const auto& lot : itemSetting.items) { if (itemSetting.add && (missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE)) { - inventory->AddItem(lot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(lot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (itemSetting.remove && (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE)) { inventory->RemoveItem(lot, 1); } diff --git a/dScripts/NjColeNPC.cpp b/dScripts/NjColeNPC.cpp index e342e429f..d2388d7bb 100644 --- a/dScripts/NjColeNPC.cpp +++ b/dScripts/NjColeNPC.cpp @@ -54,6 +54,6 @@ void NjColeNPC::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, return; } - inventoryComponent->AddItem(16644, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_VENDOR); + inventoryComponent->AddItem(16644, 1, eLootSourceType::LOOT_SOURCE_VENDOR); } } diff --git a/dScripts/NjScrollChestServer.cpp b/dScripts/NjScrollChestServer.cpp index 4677f8276..8a2f77505 100644 --- a/dScripts/NjScrollChestServer.cpp +++ b/dScripts/NjScrollChestServer.cpp @@ -12,6 +12,6 @@ void NjScrollChestServer::OnUse(Entity *self, Entity *user) { playerInventory->RemoveItem(keyLOT, 1); // Reward the player with the item set - playerInventory->AddItem(rewardItemLOT, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + playerInventory->AddItem(rewardItemLOT, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } } diff --git a/dScripts/NpcCowboyServer.cpp b/dScripts/NpcCowboyServer.cpp index b92d921fe..b638d24fa 100644 --- a/dScripts/NpcCowboyServer.cpp +++ b/dScripts/NpcCowboyServer.cpp @@ -23,7 +23,7 @@ void NpcCowboyServer::OnMissionDialogueOK(Entity* self, Entity* target, int miss { if (inventoryComponent->GetLotCount(14378) == 0) { - inventoryComponent->AddItem(14378, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(14378, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) diff --git a/dScripts/NpcPirateServer.cpp b/dScripts/NpcPirateServer.cpp index acf7e67fa..b56380f32 100644 --- a/dScripts/NpcPirateServer.cpp +++ b/dScripts/NpcPirateServer.cpp @@ -9,7 +9,7 @@ void NpcPirateServer::OnMissionDialogueOK(Entity *self, Entity *target, int miss // Add or remove the lucky shovel based on whether the mission was completed or started if ((missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE) && luckyShovel == nullptr) { - inventory->AddItem(14591, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(14591, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) { inventory->RemoveItem(14591, 1); } diff --git a/dScripts/NpcWispServer.cpp b/dScripts/NpcWispServer.cpp index 3000b4c91..a0f8392ce 100644 --- a/dScripts/NpcWispServer.cpp +++ b/dScripts/NpcWispServer.cpp @@ -20,7 +20,7 @@ void NpcWispServer::OnMissionDialogueOK(Entity* self, Entity* target, int missio // For the daily we add the maelstrom vacuum if the player doesn't have it yet if (missionID == 1883 && (missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE) && maelstromVacuum == nullptr) { - inventory->AddItem(maelstromVacuumLot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(maelstromVacuumLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) { inventory->RemoveItem(maelstromVacuumLot, 1); } diff --git a/dScripts/NsConcertInstrument.cpp b/dScripts/NsConcertInstrument.cpp index d1de993c6..92341ee93 100644 --- a/dScripts/NsConcertInstrument.cpp +++ b/dScripts/NsConcertInstrument.cpp @@ -195,7 +195,7 @@ void NsConcertInstrument::EquipInstruments(Entity *self, Entity *player) { // Equip the left hand instrument const auto leftInstrumentLot = instrumentLotLeft.find(GetInstrumentLot(self))->second; if (leftInstrumentLot != LOT_NULL) { - inventory->AddItem(leftInstrumentLot, 1, TEMP_ITEMS, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(leftInstrumentLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); auto* leftInstrument = inventory->FindItemByLot(leftInstrumentLot, TEMP_ITEMS); leftInstrument->Equip(); } @@ -203,7 +203,7 @@ void NsConcertInstrument::EquipInstruments(Entity *self, Entity *player) { // Equip the right hand instrument const auto rightInstrumentLot = instrumentLotRight.find(GetInstrumentLot(self))->second; if (rightInstrumentLot != LOT_NULL) { - inventory->AddItem(rightInstrumentLot, 1, TEMP_ITEMS, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(rightInstrumentLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); auto* rightInstrument = inventory->FindItemByLot(rightInstrumentLot, TEMP_ITEMS); rightInstrument->Equip(); } diff --git a/dScripts/NsTokenConsoleServer.cpp b/dScripts/NsTokenConsoleServer.cpp index 0416a0301..0e9ac09e8 100644 --- a/dScripts/NsTokenConsoleServer.cpp +++ b/dScripts/NsTokenConsoleServer.cpp @@ -47,24 +47,29 @@ void NsTokenConsoleServer::OnUse(Entity* self, Entity* user) { GameMessages::SendPlayNDAudioEmitter(self, UNASSIGNED_SYSTEM_ADDRESS, useSound); } + + // Player must be in faction to interact with this entity. + LOT tokenLOT = 0; if (character->GetPlayerFlag(46)) { - inventoryComponent->AddItem(8321, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); + tokenLOT = 8321; } else if (character->GetPlayerFlag(47)) { - inventoryComponent->AddItem(8318, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); + tokenLOT = 8318; } else if (character->GetPlayerFlag(48)) { - inventoryComponent->AddItem(8320, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); + tokenLOT = 8320; } else if (character->GetPlayerFlag(49)) { - inventoryComponent->AddItem(8319, 5, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); + tokenLOT = 8319; } + inventoryComponent->AddItem(tokenLOT, 5, eLootSourceType::LOOT_SOURCE_NONE); + missionComponent->ForceProgressTaskType(863, 1, 1, false); GameMessages::SendTerminateInteraction(user->GetObjectID(), FROM_INTERACTION, self->GetObjectID()); diff --git a/dScripts/NtDukeServer.cpp b/dScripts/NtDukeServer.cpp index db278aa17..d82be277b 100644 --- a/dScripts/NtDukeServer.cpp +++ b/dScripts/NtDukeServer.cpp @@ -29,7 +29,7 @@ void NtDukeServer::OnMissionDialogueOK(Entity *self, Entity *target, int mission auto lotCount = inventoryComponent->GetLotCount(m_SwordLot); if ((state == MissionState::MISSION_STATE_AVAILABLE || state == MissionState::MISSION_STATE_ACTIVE) && lotCount < 1) { - inventoryComponent->AddItem(m_SwordLot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(m_SwordLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); } else if (state == MissionState::MISSION_STATE_READY_TO_COMPLETE) { inventoryComponent->RemoveItem(m_SwordLot, lotCount); } diff --git a/dScripts/SGCannon.cpp b/dScripts/SGCannon.cpp index efb7d7fcd..a5c2c8433 100644 --- a/dScripts/SGCannon.cpp +++ b/dScripts/SGCannon.cpp @@ -574,7 +574,7 @@ void SGCannon::StopGame(Entity *self, bool cancel) { auto* inventory = player->GetComponent(); if (inventory != nullptr) { for (const auto rewardLot : self->GetVar>(RewardsVariable)) { - inventory->AddItem(rewardLot, 1, eInventoryType::MODELS, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(rewardLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY, eInventoryType::MODELS); } } diff --git a/dScripts/TokenConsoleServer.cpp b/dScripts/TokenConsoleServer.cpp index 0ca18e765..58565869a 100644 --- a/dScripts/TokenConsoleServer.cpp +++ b/dScripts/TokenConsoleServer.cpp @@ -31,7 +31,7 @@ void TokenConsoleServer::OnUse(Entity* self, Entity* user) { tokenLOT = 8320; else if (character->GetPlayerFlag(ePlayerFlags::SENTINEL_FACTION)) //sentinel tokenLOT = 8319; - inv->AddItem(tokenLOT, tokensToGive, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_NONE); + inv->AddItem(tokenLOT, tokensToGive, eLootSourceType::LOOT_SOURCE_NONE); } GameMessages::SendTerminateInteraction(user->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID()); diff --git a/dScripts/VeBricksampleServer.cpp b/dScripts/VeBricksampleServer.cpp index f9d5f3d2f..f42cd9a4a 100644 --- a/dScripts/VeBricksampleServer.cpp +++ b/dScripts/VeBricksampleServer.cpp @@ -10,7 +10,7 @@ void VeBricksampleServer::OnUse(Entity *self, Entity *user) { auto* inventoryComponent = user->GetComponent(); if (loot && inventoryComponent != nullptr && inventoryComponent->GetLotCount(loot) == 0) { - inventoryComponent->AddItem(loot, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(loot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); for (auto* brickEntity : EntityManager::Instance()->GetEntitiesInGroup("Bricks")) { GameMessages::SendNotifyClientObject(brickEntity->GetObjectID(), u"Pickedup"); diff --git a/dScripts/VeMissionConsole.cpp b/dScripts/VeMissionConsole.cpp index 9e5602448..f815ebdc1 100644 --- a/dScripts/VeMissionConsole.cpp +++ b/dScripts/VeMissionConsole.cpp @@ -8,7 +8,7 @@ void VeMissionConsole::OnUse(Entity *self, Entity *user) { auto* inventoryComponent = user->GetComponent(); if (inventoryComponent != nullptr) { - inventoryComponent->AddItem(12547, 1, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY); // Add the panel required for pickup + inventoryComponent->AddItem(12547, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); // Add the panel required for pickup } // The flag to set is 101 From c6480192f8ef09ada262b0f9eac5038064aa6fe8 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:35:39 -0700 Subject: [PATCH 43/48] Revert "isPlayer changes" This reverts commit 2e61839d93728d4193b5542558369f8cf05be61d. --- dGame/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 799e78032..75d8d8b61 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1739,7 +1739,7 @@ void Entity::CancelAllTimers() { } bool Entity::IsPlayer() const { - return m_TemplateID == 1 && GetCharacter() != nullptr; + return m_TemplateID == 1 && GetSystemAddress() != UNASSIGNED_SYSTEM_ADDRESS; } void Entity::TriggerEvent(std::string eventID, Entity* optionalTarget) { From 18fc01cd499fc4a97805511146259fbbaeb0cb3f Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:44:08 -0700 Subject: [PATCH 44/48] missed change for forge --- dGame/dUtilities/SlashCommandHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index ca8589200..324da7515 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1626,7 +1626,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit std::vector data {}; data.push_back(new LDFData(u"reforgedLOT", reforgedItem)); - inventoryComponent->AddItem(baseItem, 1, eLootSourceType::LOOT_SOURCE_MODERATION); + inventoryComponent->AddItem(baseItem, 1, eLootSourceType::LOOT_SOURCE_MODERATION, eInventoryType::INVALID, data); } if (chatCommand == "crash" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_OPERATOR) From dc770299d1c44ac5ceae051bd6c1848a0633c8de Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 23 Apr 2022 22:22:21 -0700 Subject: [PATCH 45/48] removed debug logs --- dGame/dComponents/InventoryComponent.cpp | 1 - dGame/dGameMessages/GameMessages.cpp | 1 - dGame/dInventory/Item.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index e03f4e924..d22921682 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -284,7 +284,6 @@ void InventoryComponent::AddItem( continue; } - Game::logger->Log("InventoryComponent", "new item with source %i\n", lootSourceType); auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType); isModMoveAndEquip = false; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index e0f38dbe2..a1fbdb47a 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -423,7 +423,6 @@ void GameMessages::SendAddItemToInventoryClientSync(Entity* entity, const System bitStream.Write(lootSourceType != eLootSourceType::LOOT_SOURCE_NONE); // Loot source if (lootSourceType != eLootSourceType::LOOT_SOURCE_NONE) bitStream.Write(lootSourceType); - Game::logger->Log("GameMessages", "lootSource %i\n", lootSourceType); LWONameValue extraInfo; auto config = item->GetConfig(); diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index 213430d22..a8e8d4080 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -81,7 +81,6 @@ Item::Item( inventory->AddManagedItem(this); auto* entity = inventory->GetComponent()->GetParent(); - Game::logger->Log("test", "source %i\n", lootSourceType); GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, static_cast(this->count), subKey, lootSourceType); if (isModMoveAndEquip) From e56732184fcad14f0b6fb0b9217465479d5c810b Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 24 Apr 2022 17:25:45 -0700 Subject: [PATCH 46/48] commit --- dGame/dComponents/DestroyableComponent.cpp | 26 +++++++++++----------- dGame/dMission/Mission.cpp | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 31b3af190..c0cad3ba0 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -215,6 +215,8 @@ void DestroyableComponent::SetHealth(int32_t value) { void DestroyableComponent::SetMaxHealth(float value, bool playAnim) { m_DirtyHealth = true; + // Used for playAnim if opted in for. + int32_t difference = static_cast(std::abs(m_fMaxHealth - value)); m_fMaxHealth = value; if (m_iHealth > m_fMaxHealth) { @@ -225,22 +227,21 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) { // Now update the player bar if (!m_Parent->GetParentUser()) return; AMFStringValue* amount = new AMFStringValue(); - amount->SetStringValue(std::to_string(value)); + amount->SetStringValue(std::to_string(difference)); AMFStringValue* type = new AMFStringValue(); type->SetStringValue("health"); AMFArrayValue args; args.InsertValue("amount", amount); args.InsertValue("type", type); - + Game::logger->Log("DestComp", "Setting max health diff %i\n", difference); GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args); delete amount; delete type; } - else { - EntityManager::Instance()->SerializeEntity(m_Parent); - } + + EntityManager::Instance()->SerializeEntity(m_Parent); } void DestroyableComponent::SetArmor(int32_t value) { @@ -287,9 +288,8 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) { delete amount; delete type; } - else { - EntityManager::Instance()->SerializeEntity(m_Parent); - } + + EntityManager::Instance()->SerializeEntity(m_Parent); } void DestroyableComponent::SetImagination(int32_t value) { @@ -310,6 +310,8 @@ void DestroyableComponent::SetImagination(int32_t value) { void DestroyableComponent::SetMaxImagination(float value, bool playAnim) { m_DirtyHealth = true; + // Used for playAnim if opted in for. + int32_t difference = static_cast(std::abs(m_fMaxImagination - value)); m_fMaxImagination = value; if (m_iImagination > m_fMaxImagination) { @@ -320,22 +322,20 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) { // Now update the player bar if (!m_Parent->GetParentUser()) return; AMFStringValue* amount = new AMFStringValue(); - amount->SetStringValue(std::to_string(value)); + amount->SetStringValue(std::to_string(difference)); AMFStringValue* type = new AMFStringValue(); type->SetStringValue("imagination"); AMFArrayValue args; args.InsertValue("amount", amount); args.InsertValue("type", type); - + Game::logger->Log("DestComp", "Setting max imagiantion diff %i\n", difference); GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args); delete amount; delete type; } - else { - EntityManager::Instance()->SerializeEntity(m_Parent); - } + EntityManager::Instance()->SerializeEntity(m_Parent); } void DestroyableComponent::SetDamageToAbsorb(int32_t value) diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 14fc5a24a..a7d67c505 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -528,11 +528,11 @@ void Mission::YieldRewards() { } if (info->reward_maxhealth > 0) { - destroyableComponent->SetMaxHealth(destroyableComponent->GetMaxHealth() + static_cast(info->reward_maxhealth)); + destroyableComponent->SetMaxHealth(destroyableComponent->GetMaxHealth() + static_cast(info->reward_maxhealth), true); } if (info->reward_maximagination > 0) { - destroyableComponent->SetMaxImagination(destroyableComponent->GetMaxImagination() + static_cast(info->reward_maximagination)); + destroyableComponent->SetMaxImagination(destroyableComponent->GetMaxImagination() + static_cast(info->reward_maximagination), true); } EntityManager::Instance()->SerializeEntity(entity); From 2e29dce77c262fb3dae26ff421db6c357785f27c Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 24 Apr 2022 17:27:25 -0700 Subject: [PATCH 47/48] removed logs --- dGame/dComponents/DestroyableComponent.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index c0cad3ba0..0e3481827 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -234,7 +234,6 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) { AMFArrayValue args; args.InsertValue("amount", amount); args.InsertValue("type", type); - Game::logger->Log("DestComp", "Setting max health diff %i\n", difference); GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args); delete amount; @@ -329,7 +328,6 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) { AMFArrayValue args; args.InsertValue("amount", amount); args.InsertValue("type", type); - Game::logger->Log("DestComp", "Setting max imagiantion diff %i\n", difference); GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args); delete amount; From 4fd1467cbf7d711c777c83ec8da41044e748a60f Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:40:20 -0700 Subject: [PATCH 48/48] changed loot sources to none Changed loot sources for some scripts to none so they properly give loot to the player. --- dScripts/AmDropshipComputer.cpp | 2 +- dScripts/NPCAddRemoveItem.cpp | 2 +- dScripts/NjColeNPC.cpp | 2 +- dScripts/NjScrollChestServer.cpp | 2 +- dScripts/NpcCowboyServer.cpp | 2 +- dScripts/NpcPirateServer.cpp | 2 +- dScripts/NpcWispServer.cpp | 2 +- dScripts/NtDukeServer.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dScripts/AmDropshipComputer.cpp b/dScripts/AmDropshipComputer.cpp index d90bfa973..836b09b08 100644 --- a/dScripts/AmDropshipComputer.cpp +++ b/dScripts/AmDropshipComputer.cpp @@ -32,7 +32,7 @@ void AmDropshipComputer::OnUse(Entity* self, Entity* user) return; } - inventoryComponent->AddItem(12323, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(12323, 1, eLootSourceType::LOOT_SOURCE_NONE); } void AmDropshipComputer::OnDie(Entity* self, Entity* killer) diff --git a/dScripts/NPCAddRemoveItem.cpp b/dScripts/NPCAddRemoveItem.cpp index 484cc8273..58c46ac0a 100644 --- a/dScripts/NPCAddRemoveItem.cpp +++ b/dScripts/NPCAddRemoveItem.cpp @@ -11,7 +11,7 @@ void NPCAddRemoveItem::OnMissionDialogueOK(Entity *self, Entity *target, int mis for (const auto& itemSetting : missionSetting.second) { for (const auto& lot : itemSetting.items) { if (itemSetting.add && (missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE)) { - inventory->AddItem(lot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(lot, 1, eLootSourceType::LOOT_SOURCE_NONE); } else if (itemSetting.remove && (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE)) { inventory->RemoveItem(lot, 1); } diff --git a/dScripts/NjColeNPC.cpp b/dScripts/NjColeNPC.cpp index d2388d7bb..1b889445a 100644 --- a/dScripts/NjColeNPC.cpp +++ b/dScripts/NjColeNPC.cpp @@ -54,6 +54,6 @@ void NjColeNPC::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, return; } - inventoryComponent->AddItem(16644, 1, eLootSourceType::LOOT_SOURCE_VENDOR); + inventoryComponent->AddItem(16644, 1, eLootSourceType::LOOT_SOURCE_NONE); } } diff --git a/dScripts/NjScrollChestServer.cpp b/dScripts/NjScrollChestServer.cpp index 8a2f77505..b72f93cfd 100644 --- a/dScripts/NjScrollChestServer.cpp +++ b/dScripts/NjScrollChestServer.cpp @@ -12,6 +12,6 @@ void NjScrollChestServer::OnUse(Entity *self, Entity *user) { playerInventory->RemoveItem(keyLOT, 1); // Reward the player with the item set - playerInventory->AddItem(rewardItemLOT, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + playerInventory->AddItem(rewardItemLOT, 1, eLootSourceType::LOOT_SOURCE_NONE); } } diff --git a/dScripts/NpcCowboyServer.cpp b/dScripts/NpcCowboyServer.cpp index b638d24fa..9223dcd4c 100644 --- a/dScripts/NpcCowboyServer.cpp +++ b/dScripts/NpcCowboyServer.cpp @@ -23,7 +23,7 @@ void NpcCowboyServer::OnMissionDialogueOK(Entity* self, Entity* target, int miss { if (inventoryComponent->GetLotCount(14378) == 0) { - inventoryComponent->AddItem(14378, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(14378, 1, eLootSourceType::LOOT_SOURCE_NONE); } } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) diff --git a/dScripts/NpcPirateServer.cpp b/dScripts/NpcPirateServer.cpp index b56380f32..04c62b476 100644 --- a/dScripts/NpcPirateServer.cpp +++ b/dScripts/NpcPirateServer.cpp @@ -9,7 +9,7 @@ void NpcPirateServer::OnMissionDialogueOK(Entity *self, Entity *target, int miss // Add or remove the lucky shovel based on whether the mission was completed or started if ((missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE) && luckyShovel == nullptr) { - inventory->AddItem(14591, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(14591, 1, eLootSourceType::LOOT_SOURCE_NONE); } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) { inventory->RemoveItem(14591, 1); } diff --git a/dScripts/NpcWispServer.cpp b/dScripts/NpcWispServer.cpp index a0f8392ce..03c8f071a 100644 --- a/dScripts/NpcWispServer.cpp +++ b/dScripts/NpcWispServer.cpp @@ -20,7 +20,7 @@ void NpcWispServer::OnMissionDialogueOK(Entity* self, Entity* target, int missio // For the daily we add the maelstrom vacuum if the player doesn't have it yet if (missionID == 1883 && (missionState == MissionState::MISSION_STATE_AVAILABLE || missionState == MissionState::MISSION_STATE_COMPLETE_AVAILABLE) && maelstromVacuum == nullptr) { - inventory->AddItem(maelstromVacuumLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventory->AddItem(maelstromVacuumLot, 1, eLootSourceType::LOOT_SOURCE_NONE); } else if (missionState == MissionState::MISSION_STATE_READY_TO_COMPLETE || missionState == MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE) { inventory->RemoveItem(maelstromVacuumLot, 1); } diff --git a/dScripts/NtDukeServer.cpp b/dScripts/NtDukeServer.cpp index d82be277b..fe196811d 100644 --- a/dScripts/NtDukeServer.cpp +++ b/dScripts/NtDukeServer.cpp @@ -29,7 +29,7 @@ void NtDukeServer::OnMissionDialogueOK(Entity *self, Entity *target, int mission auto lotCount = inventoryComponent->GetLotCount(m_SwordLot); if ((state == MissionState::MISSION_STATE_AVAILABLE || state == MissionState::MISSION_STATE_ACTIVE) && lotCount < 1) { - inventoryComponent->AddItem(m_SwordLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY); + inventoryComponent->AddItem(m_SwordLot, 1, eLootSourceType::LOOT_SOURCE_NONE); } else if (state == MissionState::MISSION_STATE_READY_TO_COMPLETE) { inventoryComponent->RemoveItem(m_SwordLot, lotCount); }