This commit is contained in:
luis
2026-11-11 13:44:19 -03:00
parent 50c63ed0df
commit 6655599454
3 changed files with 321 additions and 0 deletions
@@ -0,0 +1,292 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "EventMap.h"
#include "InstanceScript.h"
#include "Map.h"
#include "Player.h"
#include "ScriptedCreature.h"
#include "ScriptedGossip.h"
#include "SpellScript.h"
/*
* Map 2162 is one fixed library of floors, and all wings and layers share it. A run walks a list of floors: only the
* floor it is on exists, spawned as a manual spawn group when the floor starts, so nothing here may be a plain spawn.
* Which scenario runs comes from the dungeon the door teleports with (LFGDungeons.ScenarioID).
*/
#include "torghast_floors.h"
namespace Torghast
{
static constexpr uint32 MAP_TORGHAST = 2162;
static constexpr uint32 MAP_TORGHAST_HUB = 2453;
static constexpr uint32 LFG_TWISTING_CORRIDORS_LAYER_1 = 2106;
static constexpr uint32 SPAWN_GROUP_START_SET = 216200;
static constexpr uint32 SPAWN_GROUP_FLOOR = 216200; // + floor
static constexpr uint32 SPAWN_GROUP_FLOOR_EXIT = 216220; // + floor, boss floors only
static constexpr float NEXT_FLOOR_RANGE = 15.0f;
static constexpr Position HubExitPosition = { 1595.43f, 2154.84f, 385.152f, 2.75608f };
enum Spells
{
SPELL_NEXT_FLOOR = 323473,
SPELL_EXIT_TORGHAST = 344497
};
enum Data
{
DATA_NEXT_FLOOR = 1
};
enum Events
{
EVENT_NEXT_FLOOR = 1,
EVENT_RETURN_TO_FLOOR
};
enum WorldStates
{
WORLD_STATE_FLOOR_INDEX = 19812,
WORLD_STATE_FLOOR_NUMBER = 19143,
WORLD_STATE_FLOOR_COUNT = 19149,
WORLD_STATE_LAYER = 19811
};
struct WorldStateValue
{
int32 Id;
int32 Value;
};
// Set once per run, values as sniffed for this dungeon
static constexpr WorldStateValue CorridorsLayer1States[] =
{
{ 18445, 30 }, { 18581, 4 }, { 18582, 4 }, { 18583, 1 }, { 18749, 1 }, { 19152, 1 }, { 20234, 1 },
{ WORLD_STATE_FLOOR_COUNT, 18 }, { WORLD_STATE_LAYER, 1 }
};
struct BossFloor
{
uint32 Floor;
uint32 Boss;
};
// These floors have no way forward until the boss dies. Floor 18 ends the run, it leaves through the exit NPC
static constexpr BossFloor BossFloors[] =
{
{ 6, 159755 }, // The Grand Malleare
{ 12, 152995 } // Warden of Souls
};
}
using namespace Torghast;
class instance_torghast : public InstanceMapScript
{
public:
instance_torghast() : InstanceMapScript("instance_torghast", MAP_TORGHAST) { }
struct instance_torghast_InstanceMapScript : public InstanceScript
{
instance_torghast_InstanceMapScript(InstanceMap* map) : InstanceScript(map), _floor(0), _changingFloor(false)
{
SetHeaders("TOR");
}
void OnPlayerEnter(Player* /*player*/) override
{
// Back into a run that has moved on: the door always sends the player to floor 1
if (_floor)
{
if (_floor > 1)
_events.ScheduleEvent(EVENT_RETURN_TO_FLOOR, 2s);
return;
}
if (instance->GetLfgDungeonsId() != LFG_TWISTING_CORRIDORS_LAYER_1)
return;
for (WorldStateValue const& state : CorridorsLayer1States)
DoUpdateWorldState(state.Id, state.Value);
instance->SpawnGroupSpawn(SPAWN_GROUP_START_SET);
StartFloor(1);
}
void OnUnitDeath(Unit* unit) override
{
for (BossFloor const& boss : BossFloors)
if (boss.Floor == _floor && unit->GetEntry() == boss.Boss)
instance->SpawnGroupSpawn(SPAWN_GROUP_FLOOR_EXIT + _floor);
}
uint32 GetData(uint32 type) const override
{
return type == DATA_NEXT_FLOOR && (_changingFloor || !_floor || _floor >= std::size(CorridorsLayer1Floors));
}
void SetData(uint32 type, uint32 /*value*/) override
{
if (type != DATA_NEXT_FLOOR || GetData(DATA_NEXT_FLOOR))
return;
_changingFloor = true;
_events.ScheduleEvent(EVENT_NEXT_FLOOR, 1s);
}
void Update(uint32 diff) override
{
_events.Update(diff);
while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_NEXT_FLOOR:
{
StartFloor(_floor + 1);
Position const& arrival = CorridorsLayer1Floors[_floor - 1];
instance->DoOnPlayers([&arrival](Player* player) { player->NearTeleportTo(arrival); });
_changingFloor = false;
break;
}
case EVENT_RETURN_TO_FLOOR:
{
Position const& arrival = CorridorsLayer1Floors[_floor - 1];
instance->DoOnPlayers([&arrival](Player* player) { player->NearTeleportTo(arrival); });
break;
}
default:
break;
}
}
}
private:
void StartFloor(uint32 floor)
{
if (_floor)
{
instance->SpawnGroupDespawn(SPAWN_GROUP_FLOOR + _floor, true);
for (BossFloor const& boss : BossFloors)
if (boss.Floor == _floor)
instance->SpawnGroupDespawn(SPAWN_GROUP_FLOOR_EXIT + _floor, true);
}
_floor = floor;
instance->SpawnGroupSpawn(SPAWN_GROUP_FLOOR + _floor);
DoUpdateWorldState(WORLD_STATE_FLOOR_INDEX, _floor);
DoUpdateWorldState(WORLD_STATE_FLOOR_NUMBER, _floor + 1);
}
EventMap _events;
uint32 _floor;
bool _changingFloor;
};
InstanceScript* GetInstanceScript(InstanceMap* map) const override
{
return new instance_torghast_InstanceMapScript(map);
}
};
// 156480 - Next Floor
struct npc_torghast_next_floor : public ScriptedAI
{
npc_torghast_next_floor(Creature* creature) : ScriptedAI(creature), _checkTimer(500) { }
void UpdateAI(uint32 diff) override
{
if (_checkTimer > diff)
{
_checkTimer -= diff;
return;
}
_checkTimer = 500;
InstanceScript* instance = me->GetInstanceScript();
if (!instance || instance->GetData(DATA_NEXT_FLOOR))
return;
Player* player = me->SelectNearestPlayer(NEXT_FLOOR_RANGE);
if (!player || !player->IsAlive())
return;
player->CastSpell(player, SPELL_NEXT_FLOOR, true);
instance->SetData(DATA_NEXT_FLOOR, 1);
}
private:
uint32 _checkTimer;
};
// 175074 - Exit Torghast
struct npc_torghast_exit : public ScriptedAI
{
using ScriptedAI::ScriptedAI;
bool OnGossipHello(Player* player) override
{
player->CastSpell(player, SPELL_EXIT_TORGHAST, true);
return true;
}
};
// 175029 - Twisting Corridors
struct npc_torghast_wing_door : public ScriptedAI
{
using ScriptedAI::ScriptedAI;
bool OnGossipSelect(Player* player, uint32 /*menuId*/, uint32 /*gossipListId*/) override
{
CloseGossipMenuFor(player);
player->TeleportTo({ .Location = WorldLocation(MAP_TORGHAST, CorridorsLayer1Floors[0]), .LfgDungeonsId = LFG_TWISTING_CORRIDORS_LAYER_1 });
return true;
}
};
// 344497 - Exit Torghast
class spell_torghast_exit_torghast : public SpellScript
{
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (Player* player = GetHitUnit()->ToPlayer())
player->TeleportTo(WorldLocation(MAP_TORGHAST_HUB, HubExitPosition));
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_torghast_exit_torghast::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
void AddSC_instance_torghast()
{
new instance_torghast();
RegisterCreatureAI(npc_torghast_next_floor);
RegisterCreatureAI(npc_torghast_exit);
RegisterCreatureAI(npc_torghast_wing_door);
RegisterSpellScript(spell_torghast_exit_torghast);
}
@@ -0,0 +1,23 @@
// Generated by trinitycore-tracking/torghast/build_floors.py from the 10-31 capture, do not edit by hand.
// Arrival point of each floor of Twisting Corridors Layer 1, in the order the capture walked them.
static constexpr Position CorridorsLayer1Floors[18] =
{
{ 3710.5269f, 3210.5886f, 81.1067f, 6.19460f }, // floor 1
{ 5108.7275f, 3309.3264f, 147.1085f, 3.12398f }, // floor 2
{ 4586.8180f, 2402.9966f, 34.0806f, 0.00000f }, // floor 3
{ 4601.3438f, 3181.6970f, 69.4775f, 4.59920f }, // floor 4
{ 5651.9600f, 3073.7560f, 90.3703f, 3.13734f }, // floor 5
{ 3316.5088f, 4933.8090f, 47.0063f, 0.04823f }, // floor 6
{ -880.5174f, -7266.1665f, 109.3294f, 6.25088f }, // floor 7
{ 6470.7334f, -3699.7656f, 112.3317f, 2.50363f }, // floor 8
{ 3044.3472f, -2927.2986f, 6.8949f, 3.14820f }, // floor 9
{ 3683.5625f, -3022.6320f, 16.3738f, 6.27456f }, // floor 10
{ -82.3074f, -2541.5600f, 105.5330f, 3.16123f }, // floor 11
{ -2447.9202f, 581.7535f, 111.0659f, 1.70116f }, // floor 12
{ 8736.0050f, 2088.0540f, 69.2113f, 3.14175f }, // floor 13
{ 6002.1000f, 5196.1300f, 49.3986f, 4.67614f }, // floor 14
{ 6543.8900f, 4847.9300f, 168.5450f, 6.25088f }, // floor 15
{ 4219.4697f, 2511.0486f, 74.6086f, 1.62141f }, // floor 16
{ 8223.5060f, 3900.4583f, 35.1331f, 1.57029f }, // floor 17
{ 3784.4905f, 4902.6084f, 57.0061f, 0.00000f }, // floor 18, no Next Floor
};
@@ -48,6 +48,9 @@ void AddSC_covenant_playerchoice_scripts();
void AddSC_oribos();
//Thorgast
void AddSC_instance_torghast();
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddShadowlandsScripts()
@@ -86,4 +89,7 @@ void AddShadowlandsScripts()
AddSC_covenant_playerchoice_scripts();
AddSC_oribos();
//Thorgast
AddSC_instance_torghast();
}