diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index 680c0c1e..cbecdd37 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 }; diff --git a/dGame/Character.cpp b/dGame/Character.cpp index d396382c..ce61ae70 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/Entity.cpp b/dGame/Entity.cpp index bca7ffa2..75d8d8b6 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, eLootSourceType::LOOT_SOURCE_PICKUP, eInventoryType::INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, eInventoryType::INVALID, 1); } } } @@ -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 31b2b303..cef7b97f 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/TradingManager.cpp b/dGame/TradingManager.cpp index 0963aa6f..04a0501d 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) { @@ -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, eLootSourceType::LOOT_SOURCE_TRADE); } for (const auto& tradeItem : m_ItemsB) { - inventoryA->AddItem(tradeItem.itemLot, tradeItem.itemCount); + inventoryA->AddItem(tradeItem.itemLot, tradeItem.itemCount, eLootSourceType::LOOT_SOURCE_TRADE); } TradingManager::Instance()->CancelTrade(m_TradeId); diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index adae72b0..1d14cb0a 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/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 590758b6..815a3d59 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -217,11 +217,11 @@ void CharacterComponent::HandleLevelUp() switch (reward->rewardType) { case 0: - inventoryComponent->AddItem(reward->value, reward->count); + inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD); 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 31b3af19..2c906253 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,20 @@ 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); - 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 +287,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 +309,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 +321,19 @@ 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); - 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) @@ -821,7 +819,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 63080b2d..d2292168 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -84,10 +84,13 @@ Inventory* InventoryComponent::GetInventory(const eInventoryType type) case eInventoryType::ITEMS: size = 20u; break; + case eInventoryType::VAULT_MODELS: case eInventoryType::VAULT_ITEMS: size = 40u; break; - + case eInventoryType::VENDOR_BUYBACK: + size = 27u; + break; default: break; } @@ -138,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, @@ -177,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) { @@ -185,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)) { @@ -204,7 +207,7 @@ void InventoryComponent::AddItem( auto stack = static_cast(info.stackSize); - if (inventoryType == BRICKS) + if (inventoryType == eInventoryType::BRICKS) { stack = 999; } @@ -221,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) { @@ -281,8 +284,7 @@ void InventoryComponent::AddItem( continue; } - - auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey); + auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType); isModMoveAndEquip = false; } @@ -366,7 +368,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, eLootSourceType::LOOT_SOURCE_NONE, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot); item->SetCount(item->GetCount() - delta, false, false); @@ -384,7 +386,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, 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 0a4cfdb3..bf18d132 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, diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index a5c1168d..97c7e95b 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, 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 f982326c..0a428e04 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, 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); + inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::LOOT_SOURCE_DELETION, INVALID, {}, LWOOBJID_EMPTY, false); auto* item = inventoryComponent->FindItemByLot(model->GetLOT()); diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 27df339d..1d86b274 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; @@ -410,10 +415,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/dComponents/ScriptedActivityComponent.cpp b/dGame/dComponents/ScriptedActivityComponent.cpp index 55add0b6..026fafce 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; } diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 1ede443b..a1fbdb47 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,9 +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; auto config = item->GetConfig(); @@ -451,8 +450,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); @@ -566,8 +565,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 } @@ -4700,7 +4699,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(tokenId, altCurrencyCost); - inv->AddItem(item, count); + inv->AddItem(item, count, eLootSourceType::LOOT_SOURCE_VENDOR); } else { @@ -4725,8 +4724,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); + character->SetCoins(character->GetCoins() - (coinCost), eLootSourceType::LOOT_SOURCE_VENDOR); + inv->AddItem(item, count, eLootSourceType::LOOT_SOURCE_VENDOR); } GameMessages::SendVendorTransactionResult(entity, sysAddr); @@ -4769,12 +4768,12 @@ 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), eLootSourceType::LOOT_SOURCE_VENDOR); // Return alt currencies like faction tokens. } //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 +4835,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); } @@ -5103,7 +5102,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) { @@ -5269,7 +5268,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); } } @@ -5433,6 +5432,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) @@ -5482,8 +5483,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; @@ -5500,7 +5501,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); @@ -5521,7 +5522,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); } @@ -5588,11 +5589,11 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity* if (count == 3) { - inv->AddItem(6416, 1, MODELS, config); + inv->AddItem(6416, 1, eLootSourceType::LOOT_SOURCE_QUICKBUILD, eInventoryType::MODELS, config); } else if (count == 7) { - inv->AddItem(8092, 1, MODELS, config); + inv->AddItem(8092, 1, eLootSourceType::LOOT_SOURCE_QUICKBUILD, eInventoryType::MODELS, config); } auto* missionComponent = character->GetComponent(); @@ -5622,7 +5623,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); } } @@ -5737,7 +5738,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); } } @@ -5763,7 +5764,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/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index ababed5f..f3997200 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/Inventory.cpp b/dGame/dInventory/Inventory.cpp index b77be4b2..ae1715d7 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()) diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index 20f5321a..a8e8d408 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,7 @@ Item::Item( inventory->AddManagedItem(this); auto* entity = inventory->GetComponent()->GetParent(); - - GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, static_cast(this->count), subKey); + GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, static_cast(this->count), subKey, lootSourceType); if (isModMoveAndEquip) { @@ -148,7 +148,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) { @@ -176,7 +176,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, LWOOBJID_EMPTY, lootSourceType); } else { @@ -340,7 +340,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); @@ -374,7 +374,7 @@ void Item::Disassemble(const eInventoryType inventoryType) for (const auto mod : modArray) { - inventory->GetComponent()->AddItem(mod, 1, inventoryType); + inventory->GetComponent()->AddItem(mod, 1, eLootSourceType::LOOT_SOURCE_DELETION, inventoryType); } } } @@ -472,7 +472,7 @@ void Item::DisassembleModel() continue; } - GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1); + GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1, eLootSourceType::LOOT_SOURCE_DELETION); } } diff --git a/dGame/dInventory/Item.h b/dGame/dInventory/Item.h index 83ebb633..0be9449a 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(); @@ -86,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 f7b57071..31987505 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(); @@ -463,11 +463,11 @@ void Mission::YieldRewards() { count = 0; } - inventoryComponent->AddItem(pair.first, count); + inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); } 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); } @@ -496,11 +496,11 @@ void Mission::YieldRewards() { count = 0; } - inventoryComponent->AddItem(pair.first, count); + inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::LOOT_SOURCE_MISSION : eLootSourceType::LOOT_SOURCE_ACHIEVEMENT); } 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); } @@ -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) { @@ -526,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); diff --git a/dGame/dMission/MissionTask.cpp b/dGame/dMission/MissionTask.cpp index 1a340b23..30cd58a1 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. diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 635b2620..8305e152 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); + 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 23c6463d..b16c834a 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 302ba1cd..79e99c7d 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); @@ -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, eLootSourceType::LOOT_SOURCE_MAIL); Mail::SendAttachmentRemoveConfirm(sysAddr, mailID); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 34272d5e..266986c9 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -70,49 +70,49 @@ #endif 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); - arg = ""; - index++; - continue; - } - - arg.push_back(static_cast(command[index])); - index++; - } - - if (arg != "") { - args.push_back(arg); - } - - break; - } + 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); + arg = ""; + 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; - //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)) @@ -133,10 +133,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit level = user->GetMaxGMLevel(); } - if (level == entity->GetGMLevel()) return; - bool success = user->GetMaxGMLevel() >= level; - - if (success) { + if (level == entity->GetGMLevel()) return; + bool success = user->GetMaxGMLevel() >= level; + + if (success) { if (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN && level == GAME_MASTER_LEVEL_CIVILIAN) { GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); @@ -146,12 +146,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)) @@ -180,10 +180,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; @@ -212,14 +212,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; @@ -299,7 +299,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; }); @@ -351,7 +351,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); @@ -368,19 +368,19 @@ 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()); } 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); } @@ -395,15 +395,15 @@ 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; if (!GeneralUtils::TryParse(args[1], minifigItemId)) { @@ -441,13 +441,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); @@ -457,15 +457,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."); @@ -497,7 +497,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."); @@ -521,7 +521,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; } @@ -534,9 +534,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; } @@ -558,7 +558,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; @@ -572,7 +572,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; @@ -590,12 +590,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); } @@ -616,7 +616,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit else { ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?"); } - + return; } @@ -702,7 +702,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; @@ -718,7 +718,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; @@ -734,7 +734,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) @@ -750,7 +750,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) { @@ -762,7 +762,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) { @@ -775,7 +775,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) { @@ -787,7 +787,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (mission == nullptr) { return; } - + mission->SetMissionState(MissionState::MISSION_STATE_ACTIVE); return; @@ -860,8 +860,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)) @@ -869,11 +869,11 @@ 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); - } else if(args.size() == 2) { + inventory->AddItem(itemLOT, 1, eLootSourceType::LOOT_SOURCE_MODERATION); + } else if(args.size() == 2) { uint32_t itemLOT; if (!GeneralUtils::TryParse(args[0], itemLOT)) @@ -892,12 +892,12 @@ 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, eLootSourceType::LOOT_SOURCE_MODERATION); } 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]; @@ -917,7 +917,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (receiverID == 0) { ChatPackets::SendSystemMessage(sysAddr, u"Failed to find that player"); - + return; } @@ -944,7 +944,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ins->setInt(11, 1); ins->execute(); delete ins; - + ChatPackets::SendSystemMessage(sysAddr, u"Mail sent"); return; @@ -961,7 +961,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() + " - "; @@ -974,37 +974,37 @@ 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; - + 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."); return; } - 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) { + 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) { float x, z; if (!GeneralUtils::TryParse(args[0], x)) @@ -1023,12 +1023,12 @@ 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 { - 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(); @@ -1050,7 +1050,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } } } - } + } if (chatCommand == "tpall" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { @@ -1096,7 +1096,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(); @@ -1106,7 +1106,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); } @@ -1164,7 +1164,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit userUpdate->executeUpdate(); delete userUpdate; - + char buffer[32] = "brought up for review.\0"; if (expire != 1) @@ -1173,12 +1173,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); @@ -1221,7 +1221,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(); @@ -1267,8 +1267,8 @@ 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); @@ -1278,13 +1278,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetImagination(999); 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; - + if (!GeneralUtils::TryParse(args[0], celebration)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid celebration."); @@ -1293,8 +1293,8 @@ 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); @@ -1305,10 +1305,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetMaxImagination(9.0f); } - EntityManager::Instance()->SerializeEntity(entity); - } - - if (chatCommand == "refillstats" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { + EntityManager::Instance()->SerializeEntity(entity); + } + + 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()); @@ -1316,48 +1316,48 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit dest->SetImagination((int)dest->GetMaxImagination()); } - 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 == "spawn" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { - ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); - if (!comp) return; + 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 == "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."); 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; @@ -1370,15 +1370,15 @@ 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); + // LOOT_SOURCE_MODERATION should work but it doesn't. Relog to see uscore changes + GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, eLootSourceType::LOOT_SOURCE_MODERATION); } if (chatCommand == "pos" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { 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; } @@ -1401,9 +1401,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; @@ -1415,7 +1415,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) { @@ -1428,14 +1428,14 @@ 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. if (chatCommand == "gminvis" && entity->GetParentUser()->GetMaxGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS); - + return; } @@ -1455,7 +1455,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit { destroyableComponent->SetIsGMImmune(state); } - + return; } @@ -1482,12 +1482,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit { buffComponent->ApplyBuff(id, duration, entity->GetObjectID()); } - + 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; @@ -1517,10 +1517,10 @@ 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(); if (character) { std::string lowerName = character->GetName(); @@ -1538,12 +1538,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; @@ -1565,15 +1565,15 @@ 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) { @@ -1596,7 +1596,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; @@ -1671,7 +1671,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]); @@ -1704,7 +1704,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, eLootSourceType::LOOT_SOURCE_MODERATION, eInventoryType::INVALID, data); } if (chatCommand == "crash" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_OPERATOR) @@ -1753,13 +1753,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)) + @@ -1806,11 +1806,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); @@ -1841,7 +1841,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) @@ -1853,16 +1853,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) @@ -1889,7 +1889,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; @@ -1902,7 +1902,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (args.size() >= 2) - { + { if (args[1] == "-m" && args.size() >= 3) { auto* movingPlatformComponent = closest->GetComponent(); @@ -1946,7 +1946,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) + " >") ); } @@ -2009,54 +2009,17 @@ 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: - return true; - - default: - return false; + //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()); + return f.good(); + } else { + return false; } - - return false; } void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::string& message) { @@ -2076,7 +2039,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); diff --git a/dScripts/AgFans.h b/dScripts/AgFans.h index 0efe9c6d..09cc89d9 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); }; diff --git a/dScripts/AmDropshipComputer.cpp b/dScripts/AmDropshipComputer.cpp index 4101f526..836b09b0 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, eLootSourceType::LOOT_SOURCE_NONE); } void AmDropshipComputer::OnDie(Entity* self, Entity* killer) diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 3fc4ef32..1f01a0e1 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? @@ -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 == "scripts\\ai\\NS\\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/HydrantBroken.cpp b/dScripts/HydrantBroken.cpp index 93424325..2b620a21 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 e39f7a35..5cdf84c9 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 c7e23073..90b0f3a6 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/NPCAddRemoveItem.cpp b/dScripts/NPCAddRemoveItem.cpp index 7d36c1e1..58c46ac0 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, 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 54d38bda..1b889445 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, eLootSourceType::LOOT_SOURCE_NONE); } } diff --git a/dScripts/NjScrollChestServer.cpp b/dScripts/NjScrollChestServer.cpp index ba3fda7a..b72f93cf 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, eLootSourceType::LOOT_SOURCE_NONE); } } diff --git a/dScripts/NpcCowboyServer.cpp b/dScripts/NpcCowboyServer.cpp index 7ec031b9..9223dcd4 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, 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 4a1db1f6..04c62b47 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, 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 2f94236d..03c8f071 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, 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/NsConcertInstrument.cpp b/dScripts/NsConcertInstrument.cpp index f0257c93..92341ee9 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, 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, eLootSourceType::LOOT_SOURCE_ACTIVITY); auto* rightInstrument = inventory->FindItemByLot(rightInstrumentLot, TEMP_ITEMS); rightInstrument->Equip(); } diff --git a/dScripts/NsTokenConsoleServer.cpp b/dScripts/NsTokenConsoleServer.cpp index f6b022d0..0e9ac09e 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); + tokenLOT = 8321; } else if (character->GetPlayerFlag(47)) { - inventoryComponent->AddItem(8318, 5); + tokenLOT = 8318; } else if (character->GetPlayerFlag(48)) { - inventoryComponent->AddItem(8320, 5); + tokenLOT = 8320; } else if (character->GetPlayerFlag(49)) { - inventoryComponent->AddItem(8319, 5); + 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 0f56d6cc..fe196811 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, eLootSourceType::LOOT_SOURCE_NONE); } else if (state == MissionState::MISSION_STATE_READY_TO_COMPLETE) { inventoryComponent->RemoveItem(m_SwordLot, lotCount); } diff --git a/dScripts/RockHydrantBroken.cpp b/dScripts/RockHydrantBroken.cpp new file mode 100644 index 00000000..50e3c88d --- /dev/null +++ b/dScripts/RockHydrantBroken.cpp @@ -0,0 +1,45 @@ +#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); + + 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", 10); +} + +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(), 4737, u"water", "water", LWOOBJID_EMPTY, 1, 1, true); + } +} diff --git a/dScripts/RockHydrantBroken.h b/dScripts/RockHydrantBroken.h new file mode 100644 index 00000000..3bea8341 --- /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/RockHydrantSmashable.cpp b/dScripts/RockHydrantSmashable.cpp index a54f0b9d..8d5b5861 100644 --- a/dScripts/RockHydrantSmashable.cpp +++ b/dScripts/RockHydrantSmashable.cpp @@ -1,24 +1,21 @@ #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; - info.lot = 12293; - info.pos = pos; - info.spawner = nullptr; + LDFBaseData* data = new LDFData(u"hydrant", GeneralUtils::UTF16ToWTF8(hydrantName)); + + EntityInfo info {}; + info.lot = ROCK_HYDRANT_BROKEN; + 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 + auto* hydrant = EntityManager::Instance()->CreateEntity(info); + + EntityManager::Instance()->ConstructEntity(hydrant); +} diff --git a/dScripts/RockHydrantSmashable.h b/dScripts/RockHydrantSmashable.h index 12c21fb0..0578cb2e 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/SGCannon.cpp b/dScripts/SGCannon.cpp index 4b991253..a5c2c843 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, eLootSourceType::LOOT_SOURCE_ACTIVITY, eInventoryType::MODELS); } } diff --git a/dScripts/TokenConsoleServer.cpp b/dScripts/TokenConsoleServer.cpp index dcefe2f2..58565869 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, eLootSourceType::LOOT_SOURCE_NONE); } GameMessages::SendTerminateInteraction(user->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID()); diff --git a/dScripts/VeBricksampleServer.cpp b/dScripts/VeBricksampleServer.cpp index 42ccd460..f42cd9a4 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, 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 4a506dac..f815ebdc 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, eLootSourceType::LOOT_SOURCE_ACTIVITY); // Add the panel required for pickup } // The flag to set is 101 diff --git a/dScripts/WhFans.cpp b/dScripts/WhFans.cpp new file mode 100644 index 00000000..3a594a4c --- /dev/null +++ b/dScripts/WhFans.cpp @@ -0,0 +1,69 @@ +#include "WhFans.h" + +#include "RenderComponent.h" + +void WhFans::OnStartup(Entity* self) { + self->SetVar(u"alive", true); + self->SetVar(u"on", false); + + ToggleFX(self, false); +} + +void WhFans::ToggleFX(Entity* self, bool hit) { + 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 = self->GetComponent(); + + 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) { + auto volumePhys = volume->GetComponent(); + 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) { + auto volumePhys = volume->GetComponent(); + if (!volumePhys) continue; + volumePhys->SetPhysicsEffectActive(true); + EntityManager::Instance()->SerializeEntity(volume); + } + } +} + +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; + + if ((args == "turnOn" && self->GetVar(u"on")) || (args == "turnOff" && !self->GetVar(u"on"))) return; + ToggleFX(self, false); +} + +void WhFans::OnDie(Entity* self, Entity* killer) { + if (self->GetVar(u"on")) { + ToggleFX(self, true); + } + self->SetVar(u"alive", false); +} diff --git a/dScripts/WhFans.h b/dScripts/WhFans.h new file mode 100644 index 00000000..91aaa9d8 --- /dev/null +++ b/dScripts/WhFans.h @@ -0,0 +1,23 @@ +#pragma once +#include "CppScripts.h" +#include "GameMessages.h" +#include "EntityManager.h" +#include "PhantomPhysicsComponent.h" + +class WhFans : public CppScripts::Script +{ +public: + 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); +}; + diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index a4056de9..9d0c84cc 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(""); diff --git a/migrations/cdserver/0_nt_footrace.sql b/migrations/cdserver/0_nt_footrace.sql index 2019f07d..fd37599e 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 00000000..3d549815 --- /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;