Skip to content

Commit

Permalink
instance script rework (The-Legion-Preservation-Project#55)
Browse files Browse the repository at this point in the history
* minor organizing

* use InstanceMap instead of Map in InstanceScript

* rework instance saving and loading

* add some minimal ragefire chasm scripts

* scholomance fixes and encounter data
  • Loading branch information
jasongdove authored Oct 10, 2024
1 parent 228c853 commit 673f8f9
Show file tree
Hide file tree
Showing 320 changed files with 1,875 additions and 2,299 deletions.
1 change: 1 addition & 0 deletions sql/updates/world/0032_dungeon_level_scaling.sql
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ UPDATE creature_template SET minlevel = 41, maxlevel = 41, ScaleLevelMin = 38, S
UPDATE creature_template SET minlevel = 41, maxlevel = 41, ScaleLevelMin = 38, ScaleLevelMax = 60, ScaleLevelDelta = 0 WHERE entry = 59503;
UPDATE creature_template SET minlevel = 42, maxlevel = 42, ScaleLevelMin = 38, ScaleLevelMax = 60, ScaleLevelDelta = 1 WHERE entry = 59613;
UPDATE creature_template SET minlevel = 41, maxlevel = 41, ScaleLevelMin = 38, ScaleLevelMax = 60, ScaleLevelDelta = 0 WHERE entry = 59614;
UPDATE `creature` SET `spawnMask` = 4 where `id` = 59369; -- Doctor Theolen Krastinov <The Butcher> is heroic only

-- zul'farrak
UPDATE creature_template SET minlevel = 47, maxlevel = 48, ScaleLevelMin = 44, ScaleLevelMax = 60, ScaleLevelDelta = 0 WHERE entry = 5648;
Expand Down
21 changes: 21 additions & 0 deletions sql/updates/world/0033_add_ragefire_chasm_encounters.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DELETE FROM `instance_encounters` WHERE `entry` IN (1443, 1444, 1445, 1446);

INSERT INTO `instance_encounters` (`entry`, `difficulty`, `creditType`, `creditEntry`, `lastEncounterDungeon`, `comment`) VALUES
(1443, -1, 0, 61408, 0, 'Adarogg'),
(1444, -1, 0, 61412, 0, 'Dark Shaman Koranthal'),
(1445, -1, 0, 61463, 0, 'Slagmaw'),
(1446, -1, 0, 61528, 4, 'Lava Guard Gordoth');

DELETE FROM `instance_template` WHERE `map` = 389;

INSERT INTO `instance_template` (`map`, `parent`, `script`, `allowMount`, `bonusChance`) VALUES
(389, 1, 'instance_ragefire_chasm', 1, 20);

UPDATE `creature_template` SET `ScriptName` = 'boss_adarogg' WHERE `entry` = 61408;
UPDATE `creature_template` SET `ScriptName` = 'boss_dark_shaman_koranthal' WHERE `entry` = 61412;
UPDATE `creature_template` SET `ScriptName` = 'boss_slagmaw' WHERE `entry` = 61463;
UPDATE `creature_template` SET `ScriptName` = 'boss_lava_guard_gordoth' WHERE `entry` = 61528;

DELETE FROM `areatrigger_scripts` WHERE `entry`=7899;
INSERT INTO `areatrigger_scripts` (`entry`, `ScriptName`) VALUES
(7899, 'at_lava_guard_gordoth_intro');
8 changes: 8 additions & 0 deletions src/common/Utilities/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ float frand(float min, float max)
return float(GetRng()->Random() * (max - min) + min);
}

Milliseconds randtime(Milliseconds min, Milliseconds max)
{
long long diff = max.count() - min.count();
ASSERT(diff >= 0);
ASSERT(diff <= 0xFFFFFFFF);
return min + Milliseconds(urand(0, uint32(diff)));
}

uint32 rand32()
{
return GetRng()->BRandom();
Expand Down
4 changes: 4 additions & 0 deletions src/common/Utilities/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define Random_h__

#include "Define.h"
#include "Duration.h"
#include <limits>
#include <random>

Expand All @@ -34,6 +35,9 @@ uint32 urandms(uint32 min, uint32 max);
/* Return a random number in the range 0 .. UINT32_MAX. */
uint32 rand32();

/* Return a random time in the range min..max (up to millisecond precision). Only works for values where millisecond difference is a valid uint32. */
Milliseconds randtime(Milliseconds min, Milliseconds max);

/* Return a random number in the range min..max */
float frand(float min, float max);

Expand Down
3 changes: 2 additions & 1 deletion src/server/game/AI/CoreAI/UnitAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class UnitAI
// Called at any Damage from any attacker (before damage apply)
// Note: it for recalculation damage or special reaction at damage
// for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also
virtual void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/, DamageEffectType dmgType) {}
virtual void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/, DamageEffectType dmgType) { }

// Called when the creature receives heal
virtual void HealReceived(Unit* /*done_by*/, uint32& /*addhealth*/) {}
Expand All @@ -235,6 +235,7 @@ class UnitAI
void DoAddAuraToAllHostilePlayers(uint32 spellid);
void DoCast(uint32 spellId);
void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
void DoCastSelf(uint32 spellId, bool triggered = false) { DoCast(me, spellId, triggered); }
void DoCastToAllHostilePlayers(uint32 spellid, bool triggered = false);
void DoFunctionToHostilePlayers(uint8 playersCount, std::function<void(Unit*, Player*)> const& function);
void DoCastVictim(uint32 spellId, bool triggered = false);
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/CreatureAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class CreatureAI : public UnitAI
protected:
virtual void MoveInLineOfSight(Unit* /*who*/);

bool _EnterEvadeMode();
virtual bool _EnterEvadeMode();

private:
bool m_MoveInLineOfSight_locked;
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/AI/EventMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ void EventMap::RemovePhase(uint8 phase)
_phase &= ~(1 << (phase - 1));
}

void EventMap::ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group, uint32 phase)
{
ScheduleEvent(eventId, time.count(), group, phase);
}

void EventMap::ScheduleEvent(uint32 eventId, Seconds time, uint32 group, uint32 phase)
{
ScheduleEvent(eventId, time.count(), group, phase);
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/EventMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class EventMap : std::map<uint32, uint64>
void AddPhase(uint8 phase);
void RemovePhase(uint8 phase);

void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group = 0, uint32 phase = 0);
void ScheduleEvent(uint32 eventId, Seconds time, uint32 group = 0, uint32 phase = 0);
void ScheduleEvent(uint32 eventId, Minutes time, uint32 group = 0, uint32 phase = 0);
void ScheduleEvent(uint32 eventId, uint32 time, uint32 group = 0, uint32 phase = 0);
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/AI/ScriptedAI/ScriptedCreature.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct ScriptedAI : public CreatureAI
void AttackStart(Unit* who);

// Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/, DamageEffectType dmgType) {}
void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/, DamageEffectType dmgType) override { }

//Called at World update tick
virtual void UpdateAI(uint32 diff);
Expand Down Expand Up @@ -371,6 +371,7 @@ class BossAI : public ScriptedAI
void _EnterCombat();
void _JustDied();
void _JustReachedHome();
bool _EnterEvadeMode() override;

void _DespawnAtEvade(uint32 delayToRespawn = 30, Creature* who = nullptr);

Expand All @@ -389,7 +390,6 @@ class BossAI : public ScriptedAI
TaskScheduler scheduler;

private:
virtual bool _EnterEvadeMode();

BossBoundaryMap const* const _boundary;
uint32 const _bossId;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Challenge/Challenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "MiscPackets.h"
#include "WorldStatePackets.h"

Challenge::Challenge(Map* map, Player* player, uint32 instanceID, Scenario* scenario) : InstanceScript(map), _instanceScript(nullptr), _challengeEntry(nullptr), _isKeyDepleted(false), _scenario(scenario)
Challenge::Challenge(InstanceMap* map, Player* player, uint32 instanceID, Scenario* scenario) : InstanceScript(map), _instanceScript(nullptr), _challengeEntry(nullptr), _isKeyDepleted(false), _scenario(scenario)
{
if (!player)
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Challenge/Challenge.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum MiscChallengeData : uint32
class Challenge : public InstanceScript
{
public:
Challenge(Map* map, Player* player, uint32 instanceID, Scenario* scenario);
Challenge(InstanceMap* map, Player* player, uint32 instanceID, Scenario* scenario);
~Challenge();

void OnPlayerEnterForScript(Player* player) override;
Expand Down
17 changes: 0 additions & 17 deletions src/server/game/Entities/Creature/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,6 @@ struct CreatureAIInstance

typedef std::unordered_map<uint32, CreatureAIInstance> CreatureAIInstanceContainer;

// `creature_ai_instance_door` table

enum DoorType
{
DOOR_TYPE_ROOM = 0, // Door can open if encounter is not in progress
DOOR_TYPE_PASSAGE = 1, // Door can open if encounter is done
DOOR_TYPE_SPAWN_HOLE = 2, // Door can open if encounter is in progress, typically used for spawning places
MAX_DOOR_TYPES
};

struct DoorData
{
uint32 entry, bossId;
DoorType type;
uint32 boundary;
};

enum BoundaryType
{
BOUNDARY_NONE = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ void WorldObject::GetZoneAndAreaId(uint32& zoneid, uint32& areaid) const
map->GetZoneAndAreaId(zoneid, areaid, m_positionX, m_positionY, m_positionZ);
}

InstanceScript* WorldObject::GetInstanceScript()
InstanceScript* WorldObject::GetInstanceScript() const
{
Map* map = GetMap();
if (!map)
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class WorldObject : public Object, public WorldLocation
uint32 GetAreaId() const;
void GetZoneAndAreaId(uint32& zoneid, uint32& areaid) const;

InstanceScript* GetInstanceScript();
InstanceScript* GetInstanceScript() const;

const char* GetName() const { return m_name.c_str(); }
void SetName(std::string const& newname) { m_name=newname; }
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Globals/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ class ObjectMgr
void LoadCreatureAIInstance();
void LoadCreatureActionData();
void LoadDisplayChoiceData();
void LoadPlayerChoicesLocale();
void LoadLinkedRespawn();
void LoadPlayerChoicesLocale();
void LoadLinkedRespawn();
bool SetCreatureLinkedRespawn(ObjectGuid::LowType const& guid, ObjectGuid::LowType const& linkedGuid);
void LoadCreatureAddons();
void LoadCreatureModelInfo();
Expand Down
Loading

0 comments on commit 673f8f9

Please sign in to comment.