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>
This commit is contained in:
Aaron Kimbrell
2026-11-27 21:35:03 -06:00
parent 145fbced64
commit 8d059ab1c8
15 changed files with 1619 additions and 1446 deletions

View File

@@ -1,5 +1,6 @@
set(DSCRIPTS_SOURCES_AI_MINIGAME_SG_GF
"ZoneSGServer.cpp")
"ZoneSGServer.cpp"
"GfShootingGalleryData.cpp")
add_subdirectory(SERVER)

View File

@@ -0,0 +1,135 @@
#include "GfShootingGalleryData.h"
namespace {
// o_ShootingGallery.lua AddSpawn: [Template ID], [Initial Spawn Time Min], [Initial Spawn Time Max], [Does Respawn],
// [Respawn Time Min], [Respawn Time Max], [Initial Speed], [Score], [Change Speed at Waypoints],
// [Chance to Change Speed], [Min Speed], [Max Speed], [Is Moving Platform], [Despawn On Last Waypoint], [Time Score]
ShootingGallery::Spawn AddSpawn(std::vector<std::string> paths, const LOT id, const float initSpawnTimeMin, const float initSpawnTimeMax,
const bool bRespawn, const float mintime, const float maxtime, const float speed, const int32_t score, const bool bChangeSpeed,
const float chanceChangeSpeed, const float minSpeed, const float maxSpeed, const bool bMovingPlatform, const bool despawnTime,
const float timeScore) {
ShootingGallery::Spawn spawn;
spawn.path = std::move(paths);
spawn.id = id;
spawn.initSpawnTimeMin = initSpawnTimeMin;
spawn.initSpawnTimeMax = initSpawnTimeMax;
spawn.bRespawn = bRespawn;
spawn.minTime = mintime;
spawn.maxTime = maxtime;
spawn.speed = speed;
spawn.score = score;
spawn.bChangeSpeed = bChangeSpeed;
spawn.speedChangeChance = chanceChangeSpeed;
spawn.minSpeed = minSpeed;
spawn.maxSpeed = maxSpeed;
spawn.bMovingPlatform = bMovingPlatform;
spawn.despawnTime = despawnTime;
spawn.timeScore = timeScore;
return spawn;
}
ShootingGallery::Constants MakeConstants() {
ShootingGallery::Constants constants;
// cannon constants
constants.CANNON_TEMPLATEID = 1864;
constants.IMPACT_SKILLID = 34;
constants.PROJECTILE_TEMPLATEID = 1822;
constants.CANNON_PLAYER_OFFSET = NiPoint3(6.652f, -2.0f, 1.5f);
constants.Reward_Model_Matrix = 157;
constants.CANNON_VELOCITY = 129.0f;
constants.CANNON_MIN_DISTANCE = 30.0f;
constants.CANNON_REFIRE_RATE = 800.0f;
constants.CANNON_BARREL_OFFSET = NiPoint3(0.0f, 4.3f, 9.0f);
constants.CANNON_SUPER_CHARGE = 6297;
constants.CANNON_PROJECTILE = 1822;
constants.CANNON_SUPERCHARGE_SKILL = 249;
constants.CANNON_SKILL = 228;
constants.CANNON_TIMEOUT = -1.0f;
constants.CANNON_FOV = 58.6f;
constants.CANNON_USE_LEADERBOARDS = true;
constants.STREAK_MOD = 2;
// Super Charger is charged for this amount of time
constants.ChargedTime = 10.0f;
// The amount of points needed to super charge
constants.ChargedPoints = 25000;
// Model reward group name
constants.Reward_Model_GrpName = "QBRewardGroup";
constants.ActivityID = 1864;
// Reward Score and Loot Matrix 1 to 5
constants.Score_Reward = { 50000, 100000, 200000, 400000, 800000 };
constants.Score_LootMatrix = { 157, 187, 188, 189, 190 };
// Wave Data: AddWave(waves, 30.0, "Wave;One") and so on
constants.waveTimeLimits = { 30.0f, 30.0f, 30.0f };
constants.FIRST_WAVE_START_TIME = 4.0f;
constants.IN_BETWEEN_WAVE_PAUSE = 7.0f;
return constants;
}
};
const ShootingGallery::Constants& GfShootingGalleryData::GetConstants() {
static const auto constants = MakeConstants();
return constants;
}
// SG_CANNON.lua: targetSettings
ShootingGallery::SpawnTable GfShootingGalleryData::GetTargetSettings() {
return {
// Wave 1 Spawns
{
// Ship 1
AddSpawn({ "Wave_1_Ship_1", "Wave_1_Ship_3" }, 6015, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 2
AddSpawn({ "Wave_1_Ship_2", "Wave_1_Ship_4" }, 6300, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Sub
AddSpawn({ "Wave_1_Sub_1", "Wave_1_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 10.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Sub 2
AddSpawn({ "Wave_2_Sub_1", "Wave_2_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Friendly
AddSpawn({ "Wave_3_FShip_1", "Wave_3_FShip_2" }, 2168, 0.0f, 5.0f, true, 2.0f, 5.0f, 1.0f, -1000, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
},
// Wave 2 Spawns
{
// Ship 1
AddSpawn({ "Wave_1_Ship_1", "Wave_1_Ship_3" }, 6015, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 2
AddSpawn({ "Wave_1_Ship_2", "Wave_1_Ship_4" }, 6300, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 3
AddSpawn({ "Wave_2_Ship_1" }, 6300, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 4
AddSpawn({ "Wave_2_Ship_2" }, 6015, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Sub 1
AddSpawn({ "Wave_1_Sub_1", "Wave_1_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Sub 2
AddSpawn({ "Wave_2_Sub_1", "Wave_2_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Duck
AddSpawn({ "Wave_1_Duck_1", "Wave_1_Duck_2" }, 5946, 5.0f, 10.0f, true, 5.0f, 10.0f, 4.0f, 5000, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Friendly
AddSpawn({ "Wave_3_FShip_1", "Wave_3_FShip_2" }, 2168, 0.0f, 5.0f, true, 2.0f, 5.0f, 1.0f, -1000, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
},
// Wave 3 Spawns
{
// Ship 1
AddSpawn({ "Wave_1_Ship_1", "Wave_1_Ship_3" }, 6015, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 2
AddSpawn({ "Wave_1_Ship_2", "Wave_1_Ship_4" }, 6300, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 3
AddSpawn({ "Wave_2_Ship_1", "Wave_2_Ship_2" }, 6015, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ship 4
AddSpawn({ "Wave_3_Ship_1", "Wave_3_Ship_2" }, 6300, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1500, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Sub 1
AddSpawn({ "Wave_1_Sub_1", "Wave_1_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Sub 2
AddSpawn({ "Wave_2_Sub_1", "Wave_2_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Sub 3
AddSpawn({ "Wave_3_Sub_1", "Wave_3_Sub_2" }, 6016, 0.0f, 2.0f, true, 0.0f, 2.0f, 2.0f, 1000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Duck
AddSpawn({ "Wave_1_Duck_1", "Wave_1_Duck_2" }, 5946, 5.0f, 10.0f, true, 5.0f, 10.0f, 4.0f, 5000, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Ness
AddSpawn({ "Wave_1_Ness_1", "Wave_1_Ness_2", "Wave_2_Ness_1" }, 2565, 10.0f, 15.0f, true, 10.0f, 15.0f, 2.0f, 10000, false, 0.0f, 1.0f, 1.0f, true, true, 0.0f),
// Friendly
AddSpawn({ "Wave_3_FShip_1", "Wave_3_FShip_2" }, 2168, 0.0f, 5.0f, true, 2.0f, 5.0f, 1.0f, -1000, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
// Friendly 2
AddSpawn({ "Wave_3_FShip_3", "Wave_3_FShip_4" }, 2168, 0.0f, 5.0f, true, 2.0f, 5.0f, 1.0f, -1000, false, 0.0f, 1.0f, 1.0f, false, true, 0.0f),
},
};
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "../ShootingGallery/ShootingGalleryTypes.h"
/**
* Gnarled Forest's shooting gallery (Cannon Cove, zone 1302): the zone script's CONSTANTS (L_ZONE_SG_SERVER.lua) and
* the cannon's targetSettings (SG_CANNON.lua).
*/
namespace GfShootingGalleryData {
const ShootingGallery::Constants& GetConstants();
ShootingGallery::SpawnTable GetTargetSettings();
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,162 +1,12 @@
#pragma once
#include <memory>
#include <regex>
#include "ActivityManager.h"
#include "../../ShootingGallery/ShootingGalleryCannon.h"
struct SGEnemy {
std::vector<std::string> spawnPaths{};
LOT lot;
float_t minSpawnTime;
float_t maxSpawnTime;
bool respawns;
float_t minRespawnTime;
float_t maxRespawnTime;
float_t initialSpeed;
int32_t score;
bool changeSpeedAtWaypoint;
float_t speedChangeChance;
float_t minSpeed;
float_t maxSpeed;
bool isMovingPlatform;
bool despawnOnLastWaypoint;
};
struct SGConstants {
Vector3 playerStartPosition;
Quaternion playerStartRotation = QuatUtils::IDENTITY;
LOT cannonLot;
uint32_t impactSkillID;
LOT projectileLot;
Vector3 playerOffset;
uint32_t rewardModelMatrix;
float_t cannonVelocity;
float_t cannonMinDistance;
float_t cannonRefireRate;
Vector3 cannonBarrelOffset;
LOT cannonSuperchargedProjectileLot;
LOT cannonProjectileLot;
uint32_t cannonSuperChargeSkill;
uint32_t cannonSkill;
int32_t cannonTimeout;
float_t cannonFOV;
bool useLeaderboards;
uint32_t streakModifier;
uint32_t chargedTime;
uint32_t chargedPoints;
std::string rewardModelGroup;
uint32_t activityID;
std::map<std::string, uint32_t> scoreRewards;
uint32_t scoreLootMatrix1;
uint32_t scoreLootMatrix2;
uint32_t scoreLootMatrix3;
uint32_t scoreLootMatrix4;
uint32_t scoreLootMatrix5;
float_t firstWaveStartTime;
float_t inBetweenWavePause;
};
class SGCannon : public ActivityManager {
/**
* Gnarled Forest's shooting gallery cannon (SG_CANNON.lua, LOT 1864): the shared cannon with GF's constants and
* targets.
*/
class SGCannon : public ShootingGalleryCannon {
public:
void OnStartup(Entity* self) override;
void OnPlayerLoaded(Entity* self, Entity* player) override;
void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override;
void OnActivityTimerDone(Entity* self, const std::string& name) override;
void OnActivityTimerUpdate(Entity* self, const std::string& name, float_t timeRemaining, float_t elapsedTime) override;
void OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled) override;
void OnActivityNotify(Entity* self, GameMessages::ActivityNotify& notify) override;
void OnShootingGalleryFire(Entity& self, GameMessages::ShootingGalleryFire& fire) override;
void SuperChargeTimerFunc(Entity* self);
void SpawnWaveTimerFunc(Entity* self);
void EndWaveTimerFunc(Entity* self);
void GameOverTimerFunc(Entity* self);
void DoSpawnTimerFunc(Entity* self, const std::string& name);
void EndGameBufferTimerFunc(Entity* self);
private:
static std::vector<std::vector<SGEnemy>> GetWaves();
static SGConstants GetConstants();
void ResetVars(Entity* self);
void StartGame(Entity* self);
void DoGameStartup(Entity* self);
void SpawnNewModel(Entity* self);
void TimerToggle(Entity* self, bool start = false);
void SpawnObject(Entity* self, const SGEnemy& toSpawn, bool spawnNow = false);
void StartChargedCannon(Entity* self, uint32_t optionalTime = 0);
void ToggleSuperCharge(Entity* self, bool enable);
void RecordPlayerScore(Entity* self);
void PlaySceneAnimation(Entity* self, const std::u16string& animationName, bool onCannon, bool onPlayer, float_t priority);
static void RemovePlayer(LWOOBJID playerID);
void PauseChargeCannon(Entity* self);
void StopGame(Entity* self, bool cancel = false);
void RegisterHit(Entity* self, Entity* target, const std::string& timerName);
// sg_cannon.lua (checkSpawn): a target that respawns gets its next spawn, while its wave runs
void CheckSpawn(Entity* self, Entity* target, const std::string& timerName);
// SG_TARGET.lua (onArrived at the last waypoint): the cannon spawns the next one, and the target is gone a moment later
void UpdateStreak(Entity* self);
float_t GetCurrentBonus(Entity* self);
LOT m_CannonLot = 1864;
std::u16string PlayerIDVariable = u"PlayerID";
std::u16string HideScoreBoardVariable = u"HideScoreBoard";
std::u16string ReSetSuperChargeVariable = u"ReSetSuperCharge";
std::u16string ShowLoadingUI = u"showLoadingUI";
std::u16string SpawnNumberVariable = u"SpawnNum";
std::u16string CurrentSpawnNumberVariable = u"CurSpawnNum";
std::u16string ThisWaveVariable = u"ThisWave";
std::u16string GameScoreVariable = u"GameScore";
std::u16string GameTimeVariable = u"GameTime";
std::u16string GameStartedVariable = u"GameStarted";
std::u16string ShotsFiredVariable = u"ShotsFired";
std::u16string MaxStreakVariable = u"MaxStreak";
std::u16string MissesVariable = u"Misses";
std::u16string CurrentStreakVariable = u"CurrentStreak";
std::u16string CurrentSuperChargedTimeVariable = u"CurrentSuperChargedTime";
std::u16string StreakBonusVariable = u"StreakBonus";
std::u16string LastSuperTotalVariable = u"LastSuperTotal";
std::u16string CurrentRewardVariable = u"CurrentReward";
std::u16string RewardsVariable = u"Rewards";
std::u16string TotalScoreVariable = u"TotalScore";
std::u16string InitVariable = u"Init";
std::u16string ImpactSkillVariale = u"ImpactSkill";
std::u16string PlayerScoresVariable = u"PlayerScores";
std::u16string InitialVelocityVariable = u"InitialVelocity";
std::u16string ValidActorsVariable = u"ValidActors";
std::u16string ValidEffectsVariable = u"ValidEffects";
std::u16string SuperChargeActiveVariable = u"SuperChargeActive";
std::u16string MatrixVariable = u"Matrix";
std::u16string TimeLimitVariable = u"game_timelimit";
std::u16string AudioStartIntroVariable = u"Audio_Start_Intro";
std::u16string ClearVariable = u"Clear";
std::u16string FirstTimeDoneVariable = u"FirstTimeDone";
std::u16string RewardAddedVariable = u"rewardAdded";
std::u16string SuperChargePausedVariable = u"Super_Charge_Paused";
std::u16string WaveStatusVariable = u"WaveStatus";
std::u16string CountVariable = u"count";
std::u16string StopVariable = u"Stop";
std::u16string ActiveSpawnsVariable = u"ActiveSpawns";
std::u16string SpawnedObjects = u"SpawnedObjects";
std::u16string WaveNumVariable = u"wave.waveNum";
std::u16string WaveStrVariable = u"wave.waveStr";
std::u16string ChargeCountingVariable = u"charge_counting";
std::u16string SuperChargeBarVariable = u"SuperChargeBar";
std::u16string NumberOfChargesVariable = u"NumberOfCharges";
std::u16string CannonBallSkillIDVariable = u"cbskill";
std::u16string HideSuperChargeVariable = u"HideSuper";
std::u16string AudioFinalWaveDoneVariable = u"Audio_Final_Wave_Done";
std::u16string ModelPercentVariable = u"modelPercent";
std::string SpawnWaveTimer = "SpawnWave";
std::string EndWaveTimer = "EndWave";
std::string GameOverTimer = "GameOver";
std::string DoSpawnTimer = "DoSpawn";
std::string EndGameBufferTimer = "endGameBuffer";
std::string SuperChargeTimer = "SuperChargeTimer";
std::string ModelToBuildEvent = "modelToBuild";
std::regex DoSpawnRegex = std::regex("\\d*");
SGConstants constants{};
std::vector<std::vector<SGEnemy>> m_Waves{};
const ShootingGallery::Constants& GetConstants() const override;
ShootingGallery::SpawnTable TargetSettings() const override;
};

View File

@@ -7,7 +7,7 @@
#include "GeneralUtils.h"
#include "MovementAIComponent.h"
#include "RenderComponent.h"
#include "SGCannon.h"
#include "ShootingGalleryTypes.h"
#include "Zone.h"
#include "dZoneManager.h"
#include "eKillType.h"
@@ -18,7 +18,7 @@ void SgTarget::OnStartup(Entity* self) {
int32_t SgTarget::GetActivityPoints(Entity* self) {
if (!self->HasVar(u"SpawnData")) return 0;
const int32_t points = self->GetVar<SGEnemy>(u"SpawnData").score;
const int32_t points = self->GetVar<ShootingGallery::SpawnData>(u"SpawnData").sdScore;
// SetActivityUserData{userID = zone control's GetActivityUser, typeIndex 5, value = points} on the target: only an
// activity takes it, and the zone control without one has no user
const auto* const zoneControl = Game::entityManager->GetZoneControlEntity();
@@ -66,10 +66,10 @@ void SgTarget::NotifyParentToRespawn(Entity* self) {
return;
}
// 2 s for a moving platform, so the clients' platforms get to the end of the path first
const auto& spawnData = self->GetVar<SGEnemy>(u"SpawnData");
if (!spawnData.despawnOnLastWaypoint) return;
const auto& spawnData = self->GetVar<ShootingGallery::SpawnData>(u"SpawnData");
if (!spawnData.sdDespawnTime) return;
self->CancelTimer("Despawn");
self->AddTimer("Despawn", spawnData.isMovingPlatform ? 2.0f : 1.0f);
self->AddTimer("Despawn", spawnData.sdMovingPlat ? 2.0f : 1.0f);
}
// ChangeSpeed: a speed of 1 to 4 every 5 s (the script's startup never starts this timer); Despawn: dies silently
@@ -87,9 +87,9 @@ void SgTarget::OnTimerDone(Entity* self, std::string timerName) {
// With its spawn data's chance, a new speed between its least and most (whole numbers, as Lua's math.random)
void SgTarget::ChangeSpeed(Entity* self) {
if (!self->HasVar(u"SpawnData")) return;
const auto& spawnData = self->GetVar<SGEnemy>(u"SpawnData");
if (!spawnData.changeSpeedAtWaypoint || GeneralUtils::GenerateRandomNumber<float>(0.0f, 1.0f) > spawnData.speedChangeChance) return;
SetPathingSpeed(self, static_cast<float>(GeneralUtils::GenerateRandomNumber<int32_t>(static_cast<int32_t>(spawnData.minSpeed), static_cast<int32_t>(spawnData.maxSpeed))));
const auto& spawnData = self->GetVar<ShootingGallery::SpawnData>(u"SpawnData");
if (!spawnData.sdChangeSpeed || GeneralUtils::GenerateRandomNumber<float>(0.0f, 1.0f) > spawnData.sdSpeedChance) return;
SetPathingSpeed(self, static_cast<float>(GeneralUtils::GenerateRandomNumber<int32_t>(static_cast<int32_t>(spawnData.sdMinSpeed), static_cast<int32_t>(spawnData.sdMaxSpeed))));
}
// SetPathingSpeed: only an object following waypoints takes it (a moving platform has no handler for it)

View File

@@ -14,7 +14,7 @@ public:
void OnWaypointReached(Entity* self, uint32_t waypointIndex) override;
void OnTimerDone(Entity* self, std::string timerName) override;
// The points a hit gives (the script's GetActivityPoints: its spawn data's score; the spawn data has no time score).
// The points a hit gives (the script's GetActivityPoints: its spawn data's score).
// Also writes them as user data 5 of the zone control's activity user on the target's own activity, if it has one.
static int32_t GetActivityPoints(Entity* self);
// The animation a waypoint's first action names when that action is PlayAim, else empty

View File

@@ -1,26 +1,7 @@
#include "ZoneSGServer.h"
#include "EntityManager.h"
void ZoneSGServer::OnStartup(Entity* self) {
const auto cannons = Game::entityManager->GetEntitiesByLOT(1864);
for (const auto& cannon : cannons)
self->SetVar<LWOOBJID>(CannonIDVariable, cannon->GetObjectID());
}
void ZoneSGServer::OnActivityStateChangeRequest(Entity* self, const LWOOBJID senderID, const int32_t value1,
const int32_t value2, const std::u16string& stringValue) {
auto* cannon = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(CannonIDVariable));
if (cannon != nullptr) {
cannon->OnActivityStateChangeRequest(senderID, value1, value2, stringValue);
}
}
void ZoneSGServer::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) {
auto* cannon = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(CannonIDVariable));
if (cannon != nullptr) {
cannon->OnFireEventServerSide(sender, args, param1, param2, param3);
}
#include "GfShootingGalleryData.h"
const ShootingGallery::Constants& ZoneSGServer::GetConstants() const {
return GfShootingGalleryData::GetConstants();
}

View File

@@ -1,13 +1,11 @@
#pragma once
#include "CppScripts.h"
#include "../ShootingGallery/ShootingGalleryZone.h"
class ZoneSGServer : public CppScripts::Script {
/**
* Gnarled Forest's shooting gallery zone (L_ZONE_SG_SERVER.lua, zone 1302): the shared zone script with GF's
* constants. Its own copy of the targets (targetSettings) is not ported: nothing reads it, the cannon has its own.
*/
class ZoneSGServer : public ShootingGalleryZone {
public:
void OnStartup(Entity* self) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1,
int32_t value2, const std::u16string& stringValue) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) override;
private:
std::u16string CannonIDVariable = u"CannonID";
const ShootingGallery::Constants& GetConstants() const override;
};

View File

@@ -1,3 +1,5 @@
set(DSCRIPTS_SOURCES_AI_MINIGAME_SHOOTING_GALLERY
"ShootingGalleryCannon.cpp"
"ShootingGalleryLogic.cpp"
"ShootingGalleryZone.cpp"
PARENT_SCOPE)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,144 @@
#pragma once
#include "GameMessages.h"
#include "ActivityManager.h"
#include "ShootingGalleryTypes.h"
#include <map>
#include <optional>
/**
* A shooting gallery cannon: SG_CANNON.lua, line for line. A gallery gives it its zone's constants and its
* targetSettings, and may change what a target at the end of its path does; the rest (waves, spawning, scoring,
* streaks, the super charge, reward models, the end of the game) is shared. Each function names the Lua function it
* comes from.
*
* The Lua's notifications from the zone control (ActivityStateChangeRequest, MessageBoxRespond, ObjectLoaded) come in
* through the Notify* functions, which the gallery's zone script (ShootingGalleryZone) calls.
*/
class ShootingGalleryCannon : public ActivityManager {
public:
// The gallery's zone CONSTANTS
virtual const ShootingGallery::Constants& GetConstants() const = 0;
// targetSettings: the spawn table
virtual ShootingGallery::SpawnTable TargetSettings() const = 0;
void OnStartup(Entity* self) override;
void OnShootingGalleryFire(Entity& self, GameMessages::ShootingGalleryFire& fire) override;
void OnActivityTimerUpdate(Entity* self, const std::string& name, float_t timeRemaining, float_t elapsedTime) override;
void OnActivityTimerDone(Entity* self, const std::string& name) override;
void OnActivityNotify(Entity* self, GameMessages::ActivityNotify& notify) override;
void OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled) override;
void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override;
// RequestActivityEnter{bStart = false, userID} (the zone's enterCannon): the activity takes the player, then
// onRequestActivityEnter
void RequestActivityEnter(Entity* self, Entity* player);
// notifyActivityStateChangeRequest (from the zone control)
void NotifyActivityStateChangeRequest(Entity* self, int32_t iNumValue1);
// notifyMessageBoxRespond (from the zone control)
void NotifyMessageBoxRespond(Entity* self, Entity* sender, int32_t iButton, const std::u16string& identifier);
// notifyObjectLoaded (from the zone control)
void NotifyObjectLoaded(Entity* self, LWOOBJID objectID, LOT templateID);
// onDoCalculateActivityRating: the last game's score
uint32_t CalculateActivityRating(Entity* self, LWOOBJID playerID) override;
// The cannon's script state: the Lua's script globals (spawns, SPAWN_DATA, LOCALS, PLAYER_SCORE, EFFECTS,
// m_totalScore) and its SetVar vars
struct State {
ShootingGallery::SpawnTable spawns{};
std::map<uint32_t, ShootingGallery::SpawnData> SPAWN_DATA{};
std::vector<int32_t> PLAYER_SCORE{};
std::vector<LWOOBJID> EFFECTS{};
std::vector<LWOOBJID> ACTORS{};
int32_t m_totalScore = 0;
// g_const.FIRST_WAVE_START_TIME, which DoGameStartup raises to 1
float FIRST_WAVE_START_TIME = 0.0f;
// LOCALS
uint32_t SpawnNum = 0;
uint32_t CurSpawnNum = 0;
uint32_t ThisWave = 0;
bool GameStarted = false;
LWOOBJID activityPlayer = LWOOBJID_EMPTY;
std::map<uint32_t, LWOOBJID> spawnObject{};
// self:SetVar
float TIME_LIMIT = 0.0f;
uint32_t ImpactSkillID = 0;
int32_t m_shotsFired = 0;
int32_t m_maxStreak = 0;
int32_t m_misses = 0;
int32_t m_curStreak = 0;
float Current_Super_Charged_Time = 0.0f;
int32_t StreakBonus = 0;
std::optional<int32_t> LastSuperTotal{};
LOT currentReward = LOT_NULL;
std::vector<LOT> rewards{ LOT_NULL };
int32_t Mym_totalScore = 0;
bool Super_Charge_Active = false;
bool Super_Charge_Paused = false;
uint32_t Matrix = 1;
bool bInit = false;
bool WaveStatus = false;
uint32_t ThisWaveVar = 0;
bool Started = false;
bool firstTimeDone = false;
std::vector<LWOOBJID> CannonBallKills{};
bool friendly_hit = false;
std::optional<std::string> lastRandomPath{};
int32_t NumberOfCharges = 0;
};
State& GetState(const Entity* self);
protected:
// onNotifyObject: FinishedPath from a target at the end of its path
virtual void OnTargetFinishedPath(Entity* self, Entity* target);
// checkSpawn: a target that respawns has its next one spawned, while its wave runs
void CheckSpawn(Entity* self, Entity* target);
// The player in the activity (getActivityUser), or nullptr
Entity* GetActivityUser(const Entity* self) const;
// getObjectByName("activityPlayer")
Entity* GetActivityPlayer(Entity* self);
private:
void ResetVars(Entity* self);
void PlaySceneAnimation(Entity* self, const std::string& anim, bool bPlayCannon, bool bPlayPlayer, bool bMustPlay = false);
void PlaySceneEffect(Entity* self, const std::u16string& effectName);
void ToggleSuperCharge(Entity* self, bool enable);
void TimerToggle(Entity* self, bool bStart = false);
void PauseChargeCannon(Entity* self);
void StartChargedCannon(Entity* self, std::optional<float> optionalTime = std::nullopt);
void UpdateStreak(Entity* self);
void RegisterHit(Entity* self, Entity* target, LOT shotType);
void UpdateMissionTaskKill(Entity* self, Entity* target);
void SpawnNewModel(Entity* self);
void StartGame(Entity* self);
void StopGame(Entity* self, bool bCanceling);
void AwardModels(const std::vector<LOT>& rewards, Entity* player);
void DisplayWaveNumberToPlayer(Entity* self, uint32_t waveNum);
void ShowSummaryDialog(Entity* self, int32_t shots, int32_t kills, int32_t streak);
void RecordPlayerWaveScore(Entity* self);
static void RemovePlayerFromZone(Entity* player);
void DoGameStartup(Entity* self);
void OnChildLoaded(Entity* self, Entity* child);
bool IsValidActor(LOT templateID) const;
bool IsValidEffect(LOT templateID) const;
void DoGameShutdown(Entity* self);
std::optional<std::string> GetRandomPath(Entity* self, const ShootingGallery::Spawn& spawn, const std::optional<std::string>& lastPath);
void SpawnObject(uint32_t num, ShootingGallery::Spawn& spawn, Entity* self, bool bSpawnNow);
void DestroyAllSpawns(Entity* self);
ShootingGallery::SpawnData* GetLatestSpawnDataByTemplate(Entity* self, LOT templateID);
void DoSpawn(Entity* self, uint32_t spawnNum);
// The engine side of a few of the Lua's messages
void SetShootingGalleryParams(Entity* self, float cooldown, float timeLimit);
void RequestActivitySummaryLeaderboardData(Entity* self);
void ActivityStop(Entity* self, Entity* player, bool bExit, bool bUserCanceled);
void ActivityPause(Entity* self, Entity* player, bool bPause);
std::map<LWOOBJID, State> m_States{};
};

View File

@@ -0,0 +1,97 @@
#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);
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include "CppScripts.h"
#include "ShootingGalleryTypes.h"
#include <map>
class ShootingGalleryCannon;
/**
* A shooting gallery's zone control: L_GF_SG.lua (every gallery's zone script includes it). It puts the player in
* the cannon once both are loaded, and passes on to the cannon what the cannon asked to be told
* (SendLuaNotificationRequest: ActivityStateChangeRequest, MessageBoxRespond, ObjectLoaded).
*/
class ShootingGalleryZone : public CppScripts::Script {
public:
// The gallery's zone CONSTANTS
virtual const ShootingGallery::Constants& GetConstants() const = 0;
void OnStartup(Entity* self) override;
void OnPlayerLoaded(Entity* self, Entity* player) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override;
struct State {
LWOOBJID cannonObject = LWOOBJID_EMPTY;
LWOOBJID activityPlayer = LWOOBJID_EMPTY;
bool bLoaded = false;
};
State& GetState(const Entity* self) { return m_States[self->GetObjectID()]; }
protected:
// The stored cannon and its script, or nullptr
Entity* GetCannon(Entity* self);
ShootingGalleryCannon* GetCannonScript(Entity* self);
// mainObjectLoaded: sent from an object after loading into zone
virtual void MainObjectLoaded(Entity* self, LWOOBJID objectID, LOT templateID);
private:
void EnterCannon(Entity* self);
static void FreezePlayer(Entity* player, bool bFreeze);
bool OnObjectLoaded(Entity* self, GameMessages::GameMsg& msg);
std::map<LWOOBJID, State> m_States{};
};

View File

@@ -16,7 +16,7 @@
#include "MovementMessages.h"
#include "MovingPlatformComponent.h"
#include "02_server/Map/General/SimpleOnceOnlyMoverSpinnerEvent.h"
#include "ai/MINIGAME/SG_GF/SERVER/SGCannon.h"
#include "ai/MINIGAME/ShootingGallery/ShootingGalleryTypes.h"
#include "ai/MINIGAME/SG_GF/SERVER/SgTarget.h"
#include "ScriptComponent.h"
#include "ScriptedActivityComponent.h"
@@ -1241,14 +1241,14 @@ TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetAtTheEndOfItsPath) {
path.pathWaypoints = { first, second };
const_cast<Zone*>(Game::zoneManager->GetZone())->AddPath(path);
SGEnemy spawnData{};
spawnData.score = 1500;
spawnData.isMovingPlatform = true;
spawnData.despawnOnLastWaypoint = true;
ShootingGallery::SpawnData spawnData{};
spawnData.sdScore = 1500;
spawnData.sdMovingPlat = true;
spawnData.sdDespawnTime = true;
info.settings.Insert<std::string>(u"attached_path", "TestTargetPath");
Entity entity(288300744895900134, info);
info.settings.values.clear();
entity.SetVar<SGEnemy>(u"SpawnData", spawnData);
entity.SetVar<ShootingGallery::SpawnData>(u"SpawnData", spawnData);
SgTarget script;
EXPECT_EQ(SgTarget::GetActivityPoints(&entity), 1500);
@@ -1285,7 +1285,7 @@ TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetPlayAimAction) {
info.settings.Insert<std::string>(u"attached_path", "TestAimPath");
Entity entity(288300744895900140, info);
info.settings.values.clear();
entity.SetVar<SGEnemy>(u"SpawnData", SGEnemy{});
entity.SetVar<ShootingGallery::SpawnData>(u"SpawnData", ShootingGallery::SpawnData{});
SgTarget script;
script.OnWaypointReached(&entity, 0);
entity.Update(0.0f);
@@ -1310,9 +1310,9 @@ TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetChangeSpeedTimer) {
// control's activity user (none here: no zone control)
TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetWritesItsTimeScore) {
Entity entity(288300744895900142, info);
SGEnemy spawnData{};
spawnData.score = 500;
entity.SetVar<SGEnemy>(u"SpawnData", spawnData);
ShootingGallery::SpawnData spawnData{};
spawnData.sdScore = 500;
entity.SetVar<ShootingGallery::SpawnData>(u"SpawnData", spawnData);
auto* const activity = entity.AddComponent<ScriptedActivityComponent>(-1);
EXPECT_EQ(SgTarget::GetActivityPoints(&entity), 500);
EXPECT_FLOAT_EQ(activity->GetActivityValue(LWOOBJID_EMPTY, 5), 500.0f);