mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 13:16:23 +00:00
fix(Core): Activate creatures and objects during opening cinematics (#4045)
Co-authored-by: Si1ker <55638679+Sombranator@users.noreply.github.com> Co-authored-by: Stefano Borzì <stefanoborzi32@gmail.com>
This commit is contained in:
@@ -97,6 +97,9 @@
|
||||
#define SKILL_PERM_BONUS(x) int16(PAIR32_HIPART(x))
|
||||
#define MAKE_SKILL_BONUS(t, p) MAKE_PAIR32(t, p)
|
||||
|
||||
#define CINEMATIC_LOOKAHEAD (2 * IN_MILLISECONDS)
|
||||
#define CINEMATIC_UPDATEDIFF 500
|
||||
|
||||
enum CharacterFlags
|
||||
{
|
||||
CHARACTER_FLAG_NONE = 0x00000000,
|
||||
@@ -944,6 +947,13 @@ Player::Player(WorldSession* session): Unit(true), m_mover(this)
|
||||
|
||||
_activeCheats = CHEAT_NONE;
|
||||
|
||||
m_cinematicDiff = 0;
|
||||
m_lastCinematicCheck = 0;
|
||||
m_activeCinematicCameraId = 0;
|
||||
m_cinematicCamera = nullptr;
|
||||
m_remoteSightPosition = Position(0.0f, 0.0f, 0.0f);
|
||||
m_CinematicObject = nullptr;
|
||||
|
||||
m_achievementMgr = new AchievementMgr(this);
|
||||
m_reputationMgr = new ReputationMgr(this);
|
||||
|
||||
@@ -1589,6 +1599,14 @@ void Player::Update(uint32 p_time)
|
||||
m_nextMailDelivereTime = 0;
|
||||
}
|
||||
|
||||
// Update cinematic location, if 500ms have passed and we're doing a cinematic now.
|
||||
m_cinematicDiff += p_time;
|
||||
if (m_cinematicCamera && m_activeCinematicCameraId && GetMSTimeDiffToNow(m_lastCinematicCheck) > CINEMATIC_UPDATEDIFF)
|
||||
{
|
||||
m_lastCinematicCheck = getMSTime();
|
||||
UpdateCinematicLocation(p_time);
|
||||
}
|
||||
|
||||
//used to implement delayed far teleports
|
||||
SetMustDelayTeleport(true);
|
||||
Unit::Update(p_time);
|
||||
@@ -6980,6 +6998,10 @@ void Player::SendCinematicStart(uint32 CinematicSequenceId)
|
||||
WorldPacket data(SMSG_TRIGGER_CINEMATIC, 4);
|
||||
data << uint32(CinematicSequenceId);
|
||||
SendDirectMessage(&data);
|
||||
if (const CinematicSequencesEntry* sequence = sCinematicSequencesStore.LookupEntry(CinematicSequenceId))
|
||||
{
|
||||
SetActiveCinematicCamera(sequence->cinematicCamera);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::SendMovieStart(uint32 MovieId)
|
||||
@@ -27695,6 +27717,142 @@ bool Player::SetFeatherFall(bool apply, bool packetOnly /*= false*/)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Player::BeginCinematic()
|
||||
{
|
||||
// Sanity check for active camera set
|
||||
if (m_activeCinematicCameraId == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto itr = sFlyByCameraStore.find(m_activeCinematicCameraId);
|
||||
if (itr != sFlyByCameraStore.end())
|
||||
{
|
||||
// Initialize diff, and set camera
|
||||
m_cinematicDiff = 0;
|
||||
m_cinematicCamera = &itr->second;
|
||||
|
||||
auto camitr = m_cinematicCamera->begin();
|
||||
if (camitr != m_cinematicCamera->end())
|
||||
{
|
||||
Position pos(camitr->locations.x, camitr->locations.y, camitr->locations.z, camitr->locations.w);
|
||||
if (!pos.IsPositionValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_mapRef->LoadGrid(camitr->locations.x, camitr->locations.y);
|
||||
m_CinematicObject = SummonCreature(VISUAL_WAYPOINT, pos.m_positionX, pos.m_positionY, pos.m_positionZ, 0.0f, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 120000);
|
||||
if (m_CinematicObject)
|
||||
{
|
||||
m_CinematicObject->setActive(true);
|
||||
SetViewpoint(m_CinematicObject, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::EndCinematic()
|
||||
{
|
||||
m_cinematicDiff = 0;
|
||||
m_cinematicCamera = nullptr;
|
||||
m_activeCinematicCameraId = 0;
|
||||
if (m_CinematicObject)
|
||||
{
|
||||
if (m_seer && m_seer == m_CinematicObject)
|
||||
{
|
||||
SetViewpoint(m_CinematicObject, false);
|
||||
}
|
||||
m_CinematicObject->AddObjectToRemoveList();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::UpdateCinematicLocation(uint32 /*diff*/)
|
||||
{
|
||||
Position lastPosition;
|
||||
uint32 lastTimestamp = 0;
|
||||
Position nextPosition;
|
||||
uint32 nextTimestamp = 0;
|
||||
|
||||
if (m_cinematicCamera->size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Obtain direction of travel
|
||||
for (FlyByCamera cam : *m_cinematicCamera)
|
||||
{
|
||||
if (cam.timeStamp > m_cinematicDiff)
|
||||
{
|
||||
nextPosition = Position(cam.locations.x, cam.locations.y, cam.locations.z, cam.locations.w);
|
||||
nextTimestamp = cam.timeStamp;
|
||||
break;
|
||||
}
|
||||
lastPosition = Position(cam.locations.x, cam.locations.y, cam.locations.z, cam.locations.w);
|
||||
lastTimestamp = cam.timeStamp;
|
||||
}
|
||||
float angle = lastPosition.GetAngle(&nextPosition);
|
||||
angle -= lastPosition.GetOrientation();
|
||||
if (angle < 0)
|
||||
{
|
||||
angle += 2 * float(M_PI);
|
||||
}
|
||||
|
||||
// Look for position around 2 second ahead of us.
|
||||
int32 workDiff = m_cinematicDiff;
|
||||
|
||||
// Modify result based on camera direction (Humans for example, have the camera point behind)
|
||||
workDiff += static_cast<int32>(float(CINEMATIC_LOOKAHEAD) * cos(angle));
|
||||
|
||||
// Get an iterator to the last entry in the cameras, to make sure we don't go beyond the end
|
||||
FlyByCameraCollection::const_reverse_iterator endItr = m_cinematicCamera->rbegin();
|
||||
if (endItr != m_cinematicCamera->rend() && workDiff > static_cast<int32>(endItr->timeStamp))
|
||||
{
|
||||
workDiff = endItr->timeStamp;
|
||||
}
|
||||
|
||||
// Never try to go back in time before the start of cinematic!
|
||||
if (workDiff < 0)
|
||||
{
|
||||
workDiff = m_cinematicDiff;
|
||||
}
|
||||
|
||||
// Obtain the previous and next waypoint based on timestamp
|
||||
for (FlyByCamera cam : *m_cinematicCamera)
|
||||
{
|
||||
if (static_cast<int32>(cam.timeStamp) >= workDiff)
|
||||
{
|
||||
nextPosition = Position(cam.locations.x, cam.locations.y, cam.locations.z, cam.locations.w);
|
||||
nextTimestamp = cam.timeStamp;
|
||||
break;
|
||||
}
|
||||
lastPosition = Position(cam.locations.x, cam.locations.y, cam.locations.z, cam.locations.w);
|
||||
lastTimestamp = cam.timeStamp;
|
||||
}
|
||||
|
||||
// Never try to go beyond the end of the cinematic
|
||||
if (workDiff > static_cast<int32>(nextTimestamp))
|
||||
{
|
||||
workDiff = static_cast<int32>(nextTimestamp);
|
||||
}
|
||||
|
||||
// Interpolate the position for this moment in time (or the adjusted moment in time)
|
||||
uint32 timeDiff = nextTimestamp - lastTimestamp;
|
||||
uint32 interDiff = workDiff - lastTimestamp;
|
||||
float xDiff = nextPosition.m_positionX - lastPosition.m_positionX;
|
||||
float yDiff = nextPosition.m_positionY - lastPosition.m_positionY;
|
||||
float zDiff = nextPosition.m_positionZ - lastPosition.m_positionZ;
|
||||
Position interPosition(lastPosition.m_positionX + (xDiff * (float(interDiff) / float (timeDiff))), lastPosition.m_positionY +
|
||||
(yDiff * (float(interDiff) / float (timeDiff))), lastPosition.m_positionZ + (zDiff * (float(interDiff) / float (timeDiff))));
|
||||
|
||||
// Advance (at speed) to this position. The remote sight object is used
|
||||
// to send update information to player in cinematic
|
||||
if (m_CinematicObject && interPosition.IsPositionValid())
|
||||
{
|
||||
m_CinematicObject->MonsterMoveWithSpeed(interPosition.m_positionX, interPosition.m_positionY, interPosition.m_positionZ, 200.0f);
|
||||
}
|
||||
}
|
||||
|
||||
Guild* Player::GetGuild() const
|
||||
{
|
||||
uint32 guildId = GetGuildId();
|
||||
|
||||
@@ -2641,6 +2641,17 @@ public:
|
||||
|
||||
static std::unordered_map<int, bgZoneRef> bgZoneIdToFillWorldStates; // zoneId -> FillInitialWorldStates
|
||||
|
||||
// Cinematic camera data and remote sight functions
|
||||
[[nodiscard]] uint32 GetActiveCinematicCamera() const { return m_activeCinematicCameraId; }
|
||||
void SetActiveCinematicCamera(uint32 cinematicCameraId = 0) { m_activeCinematicCameraId = cinematicCameraId; }
|
||||
[[nodiscard]] bool IsOnCinematic() const { return (m_cinematicCamera != nullptr); }
|
||||
void BeginCinematic();
|
||||
void EndCinematic();
|
||||
void UpdateCinematicLocation(uint32 diff);
|
||||
|
||||
std::string GetMapAreaAndZoneString();
|
||||
std::string GetCoordsMapAreaAndZoneString();
|
||||
|
||||
protected:
|
||||
// Gamemaster whisper whitelist
|
||||
WhisperListContainer WhisperList;
|
||||
@@ -2990,6 +3001,14 @@ private:
|
||||
uint32 manaBeforeDuel;
|
||||
|
||||
bool m_isInstantFlightOn;
|
||||
|
||||
// Remote location information
|
||||
uint32 m_cinematicDiff;
|
||||
uint32 m_lastCinematicCheck;
|
||||
uint32 m_activeCinematicCameraId;
|
||||
FlyByCameraCollection* m_cinematicCamera;
|
||||
Position m_remoteSightPosition;
|
||||
Creature* m_CinematicObject;
|
||||
};
|
||||
|
||||
void AddItemsSetItem(Player* player, Item* item);
|
||||
|
||||
Reference in New Issue
Block a user