Files
DarkflameServer/dScripts/ai/MINIGAME/ShootingGallery/ShootingGalleryZone.cpp
Aaron Kimbrell 8d059ab1c8 feat(scripts): shooting gallery cannon and zone re-ported from the original
SG_CANNON.lua and L_GF_SG.lua line for line, as a shared cannon and
zone script (ShootingGallery folder) that a gallery fills with its
constants and targets; GF's (SGCannon, ZoneSGServer) is now that data.
The cannon gets the zone control's ActivityStateChangeRequest,
MessageBoxRespond and ObjectLoaded from the zone script, as the
original asked to be told of them.

As the original: waves end through their own EndWave<n> timer and the
last one through GameOver; targets spawn 1 s or more after their timer
starts; scores are counted at the shot's end and can go below 0; the
super charge is the shot of its cannon ball; one activity reward roll,
rated by the score; the wave, fire and preload animations and effects;
GF's spawn table as the original's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 21:54:26 -06:00

98 lines
4.0 KiB
C++

#include "ShootingGalleryZone.h"
#include "ShootingGalleryCannon.h"
#include "CombatMessages.h"
#include "Entity.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "eStateChangeType.h"
void ShootingGalleryZone::OnStartup(Entity* self) {
// onObjectLoaded: ObjectLoaded is a message objects send the zone control
self->RegisterMsg(MessageType::Game::OBJECT_LOADED, [this, self](GameMessages::GameMsg& msg) { return OnObjectLoaded(self, msg); });
// SetVar("CONSTANTS") and SetVar("timelimit"): the cannon takes the same constants (GetConstants)
}
Entity* ShootingGalleryZone::GetCannon(Entity* self) {
return Game::entityManager->GetEntity(GetState(self).cannonObject);
}
ShootingGalleryCannon* ShootingGalleryZone::GetCannonScript(Entity* self) {
auto* const cannon = GetCannon(self);
return cannon != nullptr ? dynamic_cast<ShootingGalleryCannon*>(cannon->GetScript()) : nullptr;
}
// --------------------------------------------------------------
// enterCannon: put the player in the cannon, does not start the cannon
// --------------------------------------------------------------
void ShootingGalleryZone::EnterCannon(Entity* self) {
auto& state = GetState(self);
if (state.bLoaded) return;
// get the cannon and the player
auto* const cannon = GetCannon(self);
auto* const player = Game::entityManager->GetEntity(state.activityPlayer);
if (cannon == nullptr || player == nullptr) return;
// if we have both start it
FreezePlayer(player, true);
state.bLoaded = true;
if (auto* const cannonScript = GetCannonScript(self)) cannonScript->RequestActivityEnter(cannon, player);
}
// freezePlayer
void ShootingGalleryZone::FreezePlayer(Entity* player, const bool bFreeze) {
GameMessages::SetStunned stun;
stun.target = player->GetObjectID();
stun.StateChangeType = bFreeze ? eStateChangeType::PUSH : eStateChangeType::POP;
stun.bCantMove = true;
stun.bCantAttack = true;
stun.bCantInteract = true;
stun.Send(player->GetSystemAddress());
}
// --------------------------------------------------------------
// mainPlayerLoaded: called when Player Loads into Zone
// --------------------------------------------------------------
void ShootingGalleryZone::OnPlayerLoaded(Entity* self, Entity* player) {
// CancelMission{missionID = 30}: there is no mission 30
GetState(self).activityPlayer = player->GetObjectID();
}
// onObjectLoaded, then the cannon's notifyObjectLoaded
bool ShootingGalleryZone::OnObjectLoaded(Entity* self, GameMessages::GameMsg& msg) {
const auto& objectLoaded = static_cast<const GameMessages::ObjectLoaded&>(msg);
MainObjectLoaded(self, objectLoaded.objectID, objectLoaded.lot);
auto* const cannon = GetCannon(self);
if (auto* const cannonScript = GetCannonScript(self)) cannonScript->NotifyObjectLoaded(cannon, objectLoaded.objectID, objectLoaded.lot);
return true;
}
void ShootingGalleryZone::MainObjectLoaded(Entity* self, const LWOOBJID objectID, const LOT templateID) {
// Cannon Object Loaded
if (templateID == GetConstants().CANNON_TEMPLATEID) {
// store the cannon object for use later
GetState(self).cannonObject = objectID;
// try to put the player in the cannon
EnterCannon(self);
}
}
// onActivityStateChangeRequest, then the cannon's notifyActivityStateChangeRequest
void ShootingGalleryZone::OnActivityStateChangeRequest(Entity* self, const LWOOBJID senderID, const int32_t value1, const int32_t value2, const std::u16string& stringValue) {
if (stringValue == u"clientready") {
// put the player in the cannon
EnterCannon(self);
}
auto* const cannon = GetCannon(self);
if (auto* const cannonScript = GetCannonScript(self)) cannonScript->NotifyActivityStateChangeRequest(cannon, value1);
}
// The cannon's notifyMessageBoxRespond
void ShootingGalleryZone::OnMessageBoxResponse(Entity* self, Entity* sender, const int32_t button, const std::u16string& identifier, const std::u16string& userData) {
auto* const cannon = GetCannon(self);
if (auto* const cannonScript = GetCannonScript(self)) cannonScript->NotifyMessageBoxRespond(cannon, sender, button, identifier);
}