#include "ZoneAgProperty.h" #include "EntityManager.h" #include "BasePropertyServer.h" #include "Character.h" #include "Entity.h" #include "GameMessages.h" #include "dZoneManager.h" #include "LDFFormat.h" #include "RenderComponent.h" #include "dLogger.h" #include "MissionComponent.h" void ZoneAgProperty::SetGameVariables(Entity *self) { self->SetVar(GuardGroup, "Guard"); self->SetVar(PropertyPlaqueGroup, "PropertyPlaque"); self->SetVar(PropertyVendorGroup, "PropertyVendor"); self->SetVar(PropertyBorderGroup, "PropertyBorder"); self->SetVar(LandTargetGroup, "Land_Target"); self->SetVar(SpiderScreamGroup, "Spider_Scream"); self->SetVar>(ROFTargetsGroup, { "ROF_Targets_00", "ROF_Targets_01", "ROF_Targets_02", "ROF_Targets_03", "ROF_Targets_04" }); self->SetVar(SpiderEggsGroup, "SpiderEggs"); self->SetVar(RocksGroup, "Rocks"); self->SetVar(EnemiesGroup, "SpiderBoss"); self->SetVar>(ZoneVolumesGroup, { "Zone1Vol", "Zone2Vol", "Zone3Vol", "Zone4Vol", "Zone5Vol", "Zone6Vol", "Zone7Vol", "Zone8Vol", "AggroVol", "TeleVol" }); self->SetVar(FXManagerGroup, "FXObject"); self->SetVar(EnemiesSpawner, "SpiderBoss"); self->SetVar>(BossSensorSpawner, { "Zone1Vol", "Zone2Vol", "Zone3Vol", "Zone4Vol", "Zone5Vol", "Zone6Vol", "Zone7Vol", "Zone8Vol", "RFS_Targets", "AggroVol", "TeleVol" }); self->SetVar(LandTargetSpawner, "Land_Target"); self->SetVar(SpiderScreamSpawner, "Spider_Scream"); self->SetVar>(ROFTargetsSpawner,{ "ROF_Targets_00", "ROF_Targets_01", "ROF_Targets_02", "ROF_Targets_03", "ROF_Targets_04" }); self->SetVar(PropertyMGSpawner, "PropertyGuard"); self->SetVar(FXManagerSpawner, "FXObject"); self->SetVar(PropObjsSpawner, "BankObj"); self->SetVar(SpiderEggsSpawner, "SpiderEggs"); self->SetVar(RocksSpawner, "Rocks"); self->SetVar>(AmbientFXSpawner, { "BirdFX", "SunBeam" }); self->SetVar>(SpiderRocketSpawner, { "SpiderRocket_Bot", "SpiderRocket_Mid", "SpiderRocket_Top" }); self->SetVar(MailboxSpawner, "Mailbox"); self->SetVar(LauncherSpawner, "Launcher"); self->SetVar(InstancerSpawner, "Instancer"); self->SetVar(defeatedProperyFlag, 71); self->SetVar(placedModelFlag, 73); self->SetVar(guardFirstMissionFlag, 891); self->SetVar(guardMissionFlag, 320); self->SetVar(brickLinkMissionIDFlag, 951); } void ZoneAgProperty::OnStartup(Entity *self) { LoadProperty(self); } void ZoneAgProperty::OnPlayerLoaded(Entity* self, Entity* player) { CheckForOwner(self); auto rented = self->GetVar(u"PropertyOwner") == LWOOBJID_EMPTY; self->SetVar(u"rented", rented); if (!rented) { const auto numberOfPlayers = self->GetVar(u"numberOfPlayers"); self->SetVar(u"numberOfPlayers", numberOfPlayers + 1); } if (dZoneManager::Instance()->GetZone()->GetZoneID().GetMapID() == 1102) { GameMessages::SendPlay2DAmbientSound(player, GUIDMaelstrom); GameMessages::SendNotifyClientObject(self->GetObjectID(), u"maelstromSkyOn", 0, 0, LWOOBJID_EMPTY, "", player->GetSystemAddress()); self->SetNetworkVar(u"unclaimed", true); return; } BasePlayerLoaded(self, player); } void ZoneAgProperty::PropGuardCheck(Entity* self, Entity* player) { auto* missionComponent = player->GetComponent(); if (missionComponent == nullptr) return; const auto state = missionComponent->GetMissionState(self->GetVar(guardMissionFlag)); const auto firstState = missionComponent->GetMissionState(self->GetVar(guardFirstMissionFlag)); if (firstState < MissionState::MISSION_STATE_COMPLETE || (state != MissionState::MISSION_STATE_COMPLETE && state != MissionState::MISSION_STATE_COMPLETE_READY_TO_COMPLETE)) ActivateSpawner(self->GetVar(PropertyMGSpawner)); } void ZoneAgProperty::OnZoneLoadedInfo(Entity* self) { LoadProperty(self); } void ZoneAgProperty::LoadInstance(Entity* self) { SetGameVariables(self); for (auto* spawner : dZoneManager::Instance()->GetSpawnersByName(self->GetVar(InstancerSpawner))) { for (auto* spawnerNode : spawner->m_Info.nodes) { spawnerNode->config.push_back( new LDFData(u"custom_script_server", R"(scripts\ai\GENERAL\L_INSTANCE_EXIT_TRANSFER_PLAYER_TO_LAST_NON_INSTANCE.lua)")); spawnerNode->config.push_back(new LDFData(u"transferText", u"SPIDER_QUEEN_EXIT_QUESTION")); } } ActivateSpawner(self->GetVar(InstancerSpawner)); } void ZoneAgProperty::LoadProperty(Entity* self) { SetGameVariables(self); ActivateSpawner(self->GetVar(LauncherSpawner)); ActivateSpawner(self->GetVar(MailboxSpawner)); } void ZoneAgProperty::ProcessGroupObjects(Entity* self, std::string group) { } void ZoneAgProperty::SpawnSpots(Entity* self) { for (const auto& spot : self->GetVar>(ROFTargetsSpawner)) { ActivateSpawner(spot); } ActivateSpawner(self->GetVar(LandTargetSpawner)); } void ZoneAgProperty::KillSpots(Entity* self) { for (const auto& spot : self->GetVar>(ROFTargetsSpawner)) { DeactivateSpawner(spot); } for (const auto& groupName : self->GetVar>(ROFTargetsGroup)) { for (auto* spot : EntityManager::Instance()->GetEntitiesInGroup(groupName)) { spot->Kill(); } } DeactivateSpawner(self->GetVar(LandTargetSpawner)); for (auto* landTarget : EntityManager::Instance()->GetEntitiesInGroup(self->GetVar(LandTargetSpawner))) { landTarget->Kill(); } } void ZoneAgProperty::SpawnCrashedRocket(Entity* self) { for (const auto& rocket : self->GetVar>(SpiderRocketSpawner)) { ActivateSpawner(rocket); } } void ZoneAgProperty::KillCrashedRocket(Entity* self) { for (const auto& rocket : self->GetVar>(SpiderRocketSpawner)) { DeactivateSpawner(rocket); DestroySpawner(rocket); } } void ZoneAgProperty::StartMaelstrom(Entity* self, Entity* player) { ActivateSpawner(self->GetVar(EnemiesSpawner)); for (const auto& sensor : self->GetVar>(BossSensorSpawner)) { ActivateSpawner(sensor); } ActivateSpawner(self->GetVar(FXManagerSpawner)); ActivateSpawner(self->GetVar(SpiderScreamSpawner)); ActivateSpawner(self->GetVar(SpiderEggsSpawner)); ActivateSpawner(self->GetVar(RocksSpawner)); SpawnCrashedRocket(self); for (const auto& ambient : self->GetVar>(AmbientFXSpawner)) { DeactivateSpawner(ambient); DestroySpawner(ambient); ResetSpawner(ambient); } StartTornadoFx(self); if (player != nullptr) { GameMessages::SendNotifyClientObject(self->GetObjectID(), u"maelstromSkyOn", 0, 0, LWOOBJID_EMPTY, "", player->GetSystemAddress()); } } uint32_t ZoneAgProperty::RetrieveSpawnerId(Entity* self, const std::string& spawner) { auto spawnerIDs = dZoneManager::Instance()->GetSpawnersByName(spawner); if (spawnerIDs.empty()) return 0; return spawnerIDs[0]->m_Info.spawnerID; } void ZoneAgProperty::OnTimerDone(Entity *self, std::string timerName) { BaseTimerDone(self, timerName); } void ZoneAgProperty::BaseTimerDone(Entity *self, const std::string &timerName) { if (timerName == "GuardFlyAway") { const auto zoneId = dZoneManager::Instance()->GetZone()->GetWorldID(); if (zoneId != 1150) return; const auto entities = EntityManager::Instance()->GetEntitiesInGroup(self->GetVar(GuardGroup)); if (entities.empty()) return; auto* entity = entities[0]; GameMessages::SendNotifyClientObject(EntityManager::Instance()->GetZoneControlEntity()->GetObjectID(), u"GuardChat", 0, 0, entity->GetObjectID(), "", UNASSIGNED_SYSTEM_ADDRESS); LoadProperty(self); self->AddTimer("KillGuard", 5); } else if (timerName == "KillGuard") { KillGuard(self); } else if (timerName == "tornadoOff") { for (auto* entity : EntityManager::Instance()->GetEntitiesInGroup(self->GetVar(FXManagerGroup))) { auto* renderComponent = entity->GetComponent(); if (renderComponent != nullptr) { renderComponent->StopEffect("TornadoDebris", false); renderComponent->StopEffect("TornadoVortex", false); renderComponent->StopEffect("silhouette", false); } } self->AddTimer("ShowVendor", 1.2f); self->AddTimer("ShowClearEffects", 2); } else if (timerName == "ShowClearEffects") { for (auto* entity : EntityManager::Instance()->GetEntitiesInGroup(self->GetVar(FXManagerGroup))) { auto* renderComponent = entity->GetComponent(); if (renderComponent != nullptr) { renderComponent->PlayEffect(-1, u"beamOn", "beam"); } } self->AddTimer("killSpider", 2); self->AddTimer("turnSkyOff", 1.5f); self->AddTimer("killFXObject", 8); } else if (timerName == "turnSkyOff") { GameMessages::SendNotifyClientObject(self->GetObjectID(), u"SkyOff", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS); } else if (timerName == "killSpider") { for (auto* entity : EntityManager::Instance()->GetEntitiesInGroup(self->GetVar(EnemiesGroup))) { entity->Kill(); } for (const auto& sensor : self->GetVar>(BossSensorSpawner)) { DeactivateSpawner(sensor); DestroySpawner(sensor); } DeactivateSpawner(self->GetVar(SpiderEggsSpawner)); DestroySpawner(self->GetVar(SpiderEggsSpawner)); DeactivateSpawner(self->GetVar(RocksSpawner)); DestroySpawner(self->GetVar(RocksSpawner)); KillSpots(self); KillCrashedRocket(self); DeactivateSpawner(self->GetVar(SpiderScreamSpawner)); DestroySpawner(self->GetVar(SpiderScreamSpawner)); for (auto* player : EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CHARACTER)) { GameMessages::SendStop2DAmbientSound(player, true, GUIDMaelstrom); GameMessages::SendPlay2DAmbientSound(player, GUIDPeaceful); } } else if (timerName == "ShowVendor") { GameMessages::SendNotifyClientObject(self->GetObjectID(), u"vendorOn", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS); for (const auto& ambient : self->GetVar>(AmbientFXSpawner)) { ActivateSpawner(ambient); } } else if (timerName == "BoundsVisOn") { GameMessages::SendNotifyClientObject(self->GetObjectID(), u"boundsAnim", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS); } else if (timerName == "runPlayerLoadedAgain") { CheckForOwner(self); } else if (timerName == "pollTornadoFX") { StartTornadoFx(self); } else if (timerName == "killFXObject") { for (auto* entity : EntityManager::Instance()->GetEntitiesInGroup(self->GetVar(FXManagerGroup))) { auto* renderComponent = entity->GetComponent(); if (renderComponent != nullptr) { renderComponent->StopEffect("beam"); } } DestroySpawner(self->GetVar(FXManagerSpawner)); self->SetVar(u"FXObjectGone", true); } else if (timerName == "ProcessGroupObj") { // TODO } } void ZoneAgProperty::OnZonePropertyRented(Entity* self, Entity* player) { BaseZonePropertyRented(self, player); auto* character = player->GetCharacter(); if (character == nullptr) return; character->SetPlayerFlag(108, true); } void ZoneAgProperty::OnZonePropertyModelPlaced(Entity* self, Entity* player) { auto* character = player->GetCharacter(); auto* missionComponent = player->GetComponent(); if (!character->GetPlayerFlag(101)) { BaseZonePropertyModelPlaced(self, player); character->SetPlayerFlag(101, true); if (missionComponent->GetMissionState(871) == MissionState::MISSION_STATE_ACTIVE) { self->SetNetworkVar(u"Tooltip", u"AnotherModel"); } } else if (!character->GetPlayerFlag(102)) { character->SetPlayerFlag(102, true); if (missionComponent->GetMissionState(871) == MissionState::MISSION_STATE_ACTIVE) { self->SetNetworkVar(u"Tooltip", u"TwoMoreModels"); } } else if (!character->GetPlayerFlag(103)) { character->SetPlayerFlag(103, true); } else if (!character->GetPlayerFlag(104)) { character->SetPlayerFlag(104, true); self->SetNetworkVar(u"Tooltip", u"TwoMoreModelsOff"); } else if (self->GetVar(u"tutorial") == "place_model") { self->SetVar(u"tutorial", ""); self->SetNetworkVar(u"Tooltip", u"PutAway"); } } void ZoneAgProperty::OnZonePropertyModelPickedUp(Entity* self, Entity* player) { auto* character = player->GetCharacter(); auto* missionComponent = player->GetComponent(); if (!character->GetPlayerFlag(109)) { character->SetPlayerFlag(109, true); if (missionComponent->GetMissionState(891) == MissionState::MISSION_STATE_ACTIVE && !character->GetPlayerFlag(110)) { self->SetNetworkVar(u"Tooltip", u"Rotate"); } } } void ZoneAgProperty::OnZonePropertyModelRemoved(Entity* self, Entity* player) { Game::logger->Log("OnZonePropertyModelRemoved", "Removed flag updated!\n"); auto* character = player->GetCharacter(); character->SetPlayerFlag(111, true); } void ZoneAgProperty::OnZonePropertyModelRemovedWhileEquipped(Entity* self, Entity* player) { ZoneAgProperty::OnZonePropertyModelRemoved(self, player); } void ZoneAgProperty::OnZonePropertyModelRotated(Entity* self, Entity* player) { auto* character = player->GetCharacter(); auto* missionComponent = player->GetComponent(); if (!character->GetPlayerFlag(110)) { character->SetPlayerFlag(110, true); if (missionComponent->GetMissionState(891) == MissionState::MISSION_STATE_ACTIVE) { self->SetNetworkVar(u"Tooltip", u"PlaceModel"); self->SetVar(u"tutorial", "place_model"); } } } void ZoneAgProperty::OnZonePropertyModelEquipped(Entity* self) { self->SetNetworkVar(u"PlayerAction", u"ModelEquipped"); } void ZoneAgProperty::OnZonePropertyEditBegin(Entity* self) { self->SetNetworkVar(u"PlayerAction", u"Enter"); } void ZoneAgProperty::OnZonePropertyEditEnd(Entity* self) { self->SetNetworkVar(u"PlayerAction", u"Exit"); } void ZoneAgProperty::OnPlayerExit(Entity* self) { // TODO: Destroy stuff } void ZoneAgProperty::RemovePlayerRef(Entity* self) { // TODO: Destroy stuff } void ZoneAgProperty::BaseOnFireEventServerSide(Entity *self, Entity *sender, std::string args) { if (args == "propertyRented") { const auto playerId = self->GetVar(u"playerID"); auto* player = EntityManager::Instance()->GetEntity(playerId); if (player == nullptr) return; OnZonePropertyRented(self, player); } else if (args == "RetrieveZoneData") { self->SetVar(u"SpiderBossID", sender->GetObjectID()); sender->SetVar(u"SpiderEggNetworkID", RetrieveSpawnerId(self, self->GetVar(SpiderEggsSpawner))); std::vector table; for (const auto& target : self->GetVar>(ROFTargetsSpawner)) { table.push_back(RetrieveSpawnerId(self, target)); } ROFTargetGroupIdTable = table; ProcessGroupObjects(self, self->GetVar(LandTargetGroup)); ProcessGroupObjects(self, self->GetVar(SpiderScreamGroup)); // ProcessGroupObjects(self, groups.ZoneVolumes); } else if (args == "CheckForPropertyOwner") { sender->SetNetworkVar(u"PropertyOwnerID", std::to_string(self->GetVar(u"PropertyOwner"))); } else if (args == "ClearProperty") { const auto playerId = self->GetVar(u"playerID"); auto* player = EntityManager::Instance()->GetEntity(playerId); if (player == nullptr) return; player->GetCharacter()->SetPlayerFlag(self->GetVar(defeatedProperyFlag), true); GameMessages::SendNotifyClientObject(self->GetObjectID(), u"PlayCinematic", 0, 0, LWOOBJID_EMPTY,destroyedCinematic, UNASSIGNED_SYSTEM_ADDRESS); self->AddTimer("tornadoOff", 0.5f); } } void ZoneAgProperty::NotifyDie(Entity *self) { // TODO }