feat(core): Ensure that all actions are compared to fixed point in time (#1236) (#1458)

i.e. world update start
This commit is contained in:
Viste(Кирилл)
2019-02-14 21:22:17 +03:00
committed by Francesco Borzì
parent 1b7522ff0e
commit 51b8773528
108 changed files with 933 additions and 509 deletions

View File

@@ -14,6 +14,7 @@
#include "DatabaseEnv.h"
#include "Formulas.h"
#include "GameEventMgr.h"
#include "GameTime.h"
#include "GossipDef.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
@@ -46,6 +47,9 @@
#include "LuaEngine.h"
#endif
VendorItemCount::VendorItemCount(uint32 _item, uint32 _count)
: itemId(_item), count(_count), lastIncrementTime(GameTime::GetGameTime()) { }
TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
{
TrainerSpellMap::const_iterator itr = spellList.find(spell_id);
@@ -268,7 +272,7 @@ void Creature::RemoveCorpse(bool setSpawnTime, bool skipVisibility)
if (getDeathState() != CORPSE)
return;
m_corpseRemoveTime = time(NULL);
m_corpseRemoveTime = GameTime::GetGameTime();
setDeathState(DEAD);
RemoveAllAuras();
if (!skipVisibility) // pussywizard
@@ -281,7 +285,7 @@ void Creature::RemoveCorpse(bool setSpawnTime, bool skipVisibility)
// Should get removed later, just keep "compatibility" with scripts
if (setSpawnTime)
{
m_respawnTime = time(NULL) + respawnDelay;
m_respawnTime = GameTime::GetGameTime() + respawnDelay;
//SaveRespawnTime();
}
@@ -506,7 +510,7 @@ void Creature::Update(uint32 diff)
break;
case DEAD:
{
time_t now = time(NULL);
time_t now = GameTime::GetGameTime();
if (m_respawnTime <= now)
{
bool allowed = IsAIEnabled ? AI()->CanRespawn() : true; // First check if there are any scripts that object to us respawning
@@ -548,7 +552,7 @@ void Creature::Update(uint32 diff)
}
else m_groupLootTimer -= diff;
}
else if (m_corpseRemoveTime <= time(NULL))
else if (m_corpseRemoveTime <= GameTime::GetGameTime())
{
RemoveCorpse(false);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
@@ -1477,7 +1481,7 @@ bool Creature::IsInvisibleDueToDespawn() const
if (Unit::IsInvisibleDueToDespawn())
return true;
if (IsAlive() || m_corpseRemoveTime > time(NULL))
if (IsAlive() || m_corpseRemoveTime > GameTime::GetGameTime())
return false;
return true;
@@ -1542,8 +1546,8 @@ void Creature::setDeathState(DeathState s, bool despawn)
if (s == JUST_DIED)
{
m_corpseRemoveTime = time(NULL) + m_corpseDelay;
m_respawnTime = time(NULL) + m_respawnDelay + m_corpseDelay;
m_corpseRemoveTime = GameTime::GetGameTime() + m_corpseDelay;
m_respawnTime = GameTime::GetGameTime() + m_respawnDelay + m_corpseDelay;
// always save boss respawn time at death to prevent crash cheating
if (GetMap()->IsDungeon() || isWorldBoss() || GetCreatureTemplate()->rank >= CREATURE_ELITE_ELITE)
@@ -2126,7 +2130,7 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool skipDistCheck) const
// pussywizard: don't check distance to home position if recently damaged (allow kiting away from spawnpoint!)
// xinef: this should include taunt auras
if (!isWorldBoss() && (GetLastDamagedTime() > sWorld->GetGameTime() || HasAuraType(SPELL_AURA_MOD_TAUNT)))
if (!isWorldBoss() && (GetLastDamagedTime() > GameTime::GetGameTime() || HasAuraType(SPELL_AURA_MOD_TAUNT)))
return true;
}
@@ -2294,7 +2298,7 @@ void Creature::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs
{
for (uint8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i)
if (idSchoolMask & (1 << i))
m_ProhibitSchoolTime[i] = World::GetGameTimeMS() + unTimeMs;
m_ProhibitSchoolTime[i] = GameTime::GetGameTimeMS() + unTimeMs;
}
bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const
@@ -2305,7 +2309,7 @@ bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const
for (uint8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i)
if (idSchoolMask & (1 << i))
if (m_ProhibitSchoolTime[i] >= World::GetGameTimeMS())
if (m_ProhibitSchoolTime[i] >= GameTime::GetGameTimeMS())
return true;
return false;
@@ -2313,7 +2317,7 @@ bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const
void Creature::_AddCreatureSpellCooldown(uint32 spell_id, uint32 end_time)
{
m_CreatureSpellCooldowns[spell_id] = World::GetGameTimeMS()+end_time;
m_CreatureSpellCooldowns[spell_id] = GameTime::GetGameTimeMS()+end_time;
}
void Creature::AddSpellCooldown(uint32 spell_id, uint32 /*itemid*/, uint32 end_time, bool /*needSendToClient*/, bool /*forceSendToSpectator*/)
@@ -2360,13 +2364,13 @@ uint32 Creature::GetSpellCooldown(uint32 spell_id) const
if (itr == m_CreatureSpellCooldowns.end())
return 0;
return itr->second > World::GetGameTimeMS() ? itr->second - World::GetGameTimeMS() : 0;
return itr->second > GameTime::GetGameTimeMS() ? itr->second - GameTime::GetGameTimeMS() : 0;
}
bool Creature::HasSpellCooldown(uint32 spell_id) const
{
CreatureSpellCooldowns::const_iterator itr = m_CreatureSpellCooldowns.find(spell_id);
return (itr != m_CreatureSpellCooldowns.end() && itr->second > World::GetGameTimeMS());
return (itr != m_CreatureSpellCooldowns.end() && itr->second > GameTime::GetGameTimeMS());
}
bool Creature::HasSpell(uint32 spellID) const
@@ -2380,13 +2384,18 @@ bool Creature::HasSpell(uint32 spellID) const
time_t Creature::GetRespawnTimeEx() const
{
time_t now = time(NULL);
time_t now = GameTime::GetGameTime();
if (m_respawnTime > now)
return m_respawnTime;
else
return now;
}
void Creature::SetRespawnTime(uint32 respawn)
{
m_respawnTime = respawn ? GameTime::GetGameTime() + respawn : 0;
}
void Creature::GetRespawnPosition(float &x, float &y, float &z, float* ori, float* dist) const
{
if (m_DBTableGuid)
@@ -2431,7 +2440,7 @@ void Creature::AllLootRemovedFromCorpse()
{
if (!HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE))
{
time_t now = time(NULL);
time_t now = GameTime::GetGameTime();
if (m_corpseRemoveTime <= now)
return;
@@ -2445,7 +2454,7 @@ void Creature::AllLootRemovedFromCorpse()
// corpse skinnable, but without skinning flag, and then skinned, corpse will despawn next update
if (cinfo && cinfo->SkinLootId)
m_corpseRemoveTime = time(NULL);
m_corpseRemoveTime = GameTime::GetGameTime();
else
m_corpseRemoveTime -= diff;
}
@@ -2499,7 +2508,7 @@ uint32 Creature::GetVendorItemCurrentCount(VendorItem const* vItem)
VendorItemCount* vCount = &*itr;
time_t ptime = time(NULL);
time_t ptime = GameTime::GetGameTime();
if (time_t(vCount->lastIncrementTime + vItem->incrtime) <= ptime)
{
@@ -2538,7 +2547,7 @@ uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 us
VendorItemCount* vCount = &*itr;
time_t ptime = time(NULL);
time_t ptime = GameTime::GetGameTime();
if (time_t(vCount->lastIncrementTime + vItem->incrtime) <= ptime)
{
@@ -2857,3 +2866,13 @@ float Creature::GetAttackDistance(Unit const* player) const
return (retDistance*aggroRate);
}
void Creature::SetPickPocketLootTime()
{
lootPickPocketRestoreTime = GameTime::GetGameTime() + MINUTE + GetCorpseDelay() + GetRespawnTime();
}
bool Creature::CanGeneratePickPocketLoot() const
{
return (lootPickPocketRestoreTime == 0 || lootPickPocketRestoreTime < GameTime::GetGameTime());
}