mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-03 11:03:47 +00:00
Merge branch 'master' into Playerbot
This commit is contained in:
@@ -348,7 +348,7 @@ void CreatureAI::MoveCircleChecks()
|
||||
!victim ||
|
||||
!me->IsFreeToMove() || me->HasUnitMovementFlag(MOVEMENTFLAG_ROOT) ||
|
||||
!me->IsWithinMeleeRange(victim) || me == victim->GetVictim() ||
|
||||
(victim->GetTypeId() != TYPEID_PLAYER && !victim->IsPet()) // only player & pets to save CPU
|
||||
(!victim->IsPlayer() && !victim->IsPet()) // only player & pets to save CPU
|
||||
)
|
||||
{
|
||||
return;
|
||||
@@ -357,14 +357,12 @@ void CreatureAI::MoveCircleChecks()
|
||||
me->GetMotionMaster()->MoveCircleTarget(me->GetVictim());
|
||||
}
|
||||
|
||||
void CreatureAI::MoveBackwardsChecks() {
|
||||
void CreatureAI::MoveBackwardsChecks()
|
||||
{
|
||||
Unit *victim = me->GetVictim();
|
||||
|
||||
if (
|
||||
!victim ||
|
||||
!me->IsFreeToMove() || me->HasUnitMovementFlag(MOVEMENTFLAG_ROOT) ||
|
||||
(victim->GetTypeId() != TYPEID_PLAYER && !victim->IsPet())
|
||||
)
|
||||
if (!victim || !me->IsFreeToMove() || me->HasUnitMovementFlag(MOVEMENTFLAG_ROOT) ||
|
||||
(!victim->IsPlayer() && !victim->IsPet()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -191,8 +191,7 @@ bool SummonList::IsAnyCreatureInCombat() const
|
||||
|
||||
ScriptedAI::ScriptedAI(Creature* creature) : CreatureAI(creature),
|
||||
me(creature),
|
||||
IsFleeing(false),
|
||||
_isCombatMovementAllowed(true)
|
||||
IsFleeing(false)
|
||||
{
|
||||
_isHeroic = me->GetMap()->IsHeroic();
|
||||
_difficulty = Difficulty(me->GetMap()->GetSpawnMode());
|
||||
@@ -209,7 +208,7 @@ void ScriptedAI::AttackStartNoMove(Unit* who)
|
||||
|
||||
void ScriptedAI::AttackStart(Unit* who)
|
||||
{
|
||||
if (IsCombatMovementAllowed())
|
||||
if (me->IsCombatMovementAllowed())
|
||||
CreatureAI::AttackStart(who);
|
||||
else
|
||||
AttackStartNoMove(who);
|
||||
@@ -537,11 +536,6 @@ void ScriptedAI::SetEquipmentSlots(bool loadDefault, int32 mainHand /*= EQUIP_NO
|
||||
me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2, uint32(ranged));
|
||||
}
|
||||
|
||||
void ScriptedAI::SetCombatMovement(bool allowMovement)
|
||||
{
|
||||
_isCombatMovementAllowed = allowMovement;
|
||||
}
|
||||
|
||||
enum eNPCs
|
||||
{
|
||||
NPC_BROODLORD = 12017,
|
||||
|
||||
@@ -373,14 +373,6 @@ struct ScriptedAI : public CreatureAI
|
||||
|
||||
void SetEquipmentSlots(bool loadDefault, int32 mainHand = EQUIP_NO_CHANGE, int32 offHand = EQUIP_NO_CHANGE, int32 ranged = EQUIP_NO_CHANGE);
|
||||
|
||||
// Used to control if MoveChase() is to be used or not in AttackStart(). Some creatures does not chase victims
|
||||
// NOTE: If you use SetCombatMovement while the creature is in combat, it will do NOTHING - This only affects AttackStart
|
||||
// You should make the necessary to make it happen so.
|
||||
// Remember that if you modified _isCombatMovementAllowed (e.g: using SetCombatMovement) it will not be reset at Reset().
|
||||
// It will keep the last value you set.
|
||||
void SetCombatMovement(bool allowMovement);
|
||||
bool IsCombatMovementAllowed() const { return _isCombatMovementAllowed; }
|
||||
|
||||
virtual bool CheckEvadeIfOutOfCombatArea() const { return false; }
|
||||
|
||||
// return true for heroic mode. i.e.
|
||||
@@ -452,7 +444,6 @@ struct ScriptedAI : public CreatureAI
|
||||
|
||||
private:
|
||||
Difficulty _difficulty;
|
||||
bool _isCombatMovementAllowed;
|
||||
bool _isHeroic;
|
||||
std::unordered_set<uint32> _uniqueTimedEvents;
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ void npc_escortAI::AttackStart(Unit* who)
|
||||
me->StopMoving();
|
||||
}
|
||||
|
||||
if (IsCombatMovementAllowed())
|
||||
if (me->IsCombatMovementAllowed())
|
||||
me->GetMotionMaster()->MoveChase(who);
|
||||
}
|
||||
}
|
||||
@@ -178,8 +178,8 @@ void npc_escortAI::JustRespawned()
|
||||
{
|
||||
RemoveEscortState(STATE_ESCORT_ESCORTING | STATE_ESCORT_RETURNING | STATE_ESCORT_PAUSED);
|
||||
|
||||
if (!IsCombatMovementAllowed())
|
||||
SetCombatMovement(true);
|
||||
if (!me->IsCombatMovementAllowed())
|
||||
me->SetCombatMovement(true);
|
||||
|
||||
//add a small delay before going to first waypoint, normal in near all cases
|
||||
m_uiWPWaitTimer = 1000;
|
||||
|
||||
@@ -55,7 +55,7 @@ void FollowerAI::AttackStart(Unit* who)
|
||||
if (me->HasUnitState(UNIT_STATE_FOLLOW))
|
||||
me->ClearUnitState(UNIT_STATE_FOLLOW);
|
||||
|
||||
if (IsCombatMovementAllowed())
|
||||
if (me->IsCombatMovementAllowed())
|
||||
me->GetMotionMaster()->MoveChase(who);
|
||||
}
|
||||
}
|
||||
@@ -141,8 +141,8 @@ void FollowerAI::JustRespawned()
|
||||
{
|
||||
m_uiFollowState = STATE_FOLLOW_NONE;
|
||||
|
||||
if (!IsCombatMovementAllowed())
|
||||
SetCombatMovement(true);
|
||||
if (!me->IsCombatMovementAllowed())
|
||||
me->SetCombatMovement(true);
|
||||
|
||||
if (me->GetFaction() != me->GetCreatureTemplate()->faction)
|
||||
me->SetFaction(me->GetCreatureTemplate()->faction);
|
||||
|
||||
@@ -3456,6 +3456,8 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e,
|
||||
for (WorldObject* unit : units)
|
||||
if (IsPlayer(unit) && baseObject->IsInRange(unit, float(e.target.playerRange.minDist), float(e.target.playerRange.maxDist)))
|
||||
targets.push_back(unit);
|
||||
if (e.target.playerRange.maxCount)
|
||||
Acore::Containers::RandomResize(targets, e.target.playerRange.maxCount);
|
||||
break;
|
||||
}
|
||||
case SMART_TARGET_PLAYER_DISTANCE:
|
||||
|
||||
@@ -220,7 +220,7 @@ Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(),
|
||||
m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false),
|
||||
m_AlreadySearchedAssistance(false), m_regenHealth(true), m_regenPower(true), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_moveInLineOfSightDisabled(false), m_moveInLineOfSightStrictlyDisabled(false),
|
||||
m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_detectionDistance(20.0f), m_waypointID(0), m_path_id(0), m_formation(nullptr), _lastDamagedTime(nullptr), m_cannotReachTimer(0),
|
||||
_isMissingSwimmingFlagOutOfCombat(false), m_assistanceTimer(0), _playerDamageReq(0), _damagedByPlayer(false)
|
||||
_isMissingSwimmingFlagOutOfCombat(false), m_assistanceTimer(0), _playerDamageReq(0), _damagedByPlayer(false), _isCombatMovementAllowed(true)
|
||||
{
|
||||
m_regenTimer = CREATURE_REGEN_INTERVAL;
|
||||
m_valuesCount = UNIT_END;
|
||||
@@ -877,7 +877,7 @@ bool Creature::IsFreeToMove()
|
||||
{
|
||||
uint32 moveFlags = m_movementInfo.GetMovementFlags();
|
||||
// Do not reposition ourself when we are not allowed to move
|
||||
if ((IsMovementPreventedByCasting() || isMoving() || !CanFreeMove()) &&
|
||||
if ((IsMovementPreventedByCasting() || isMoving() || !CanFreeMove() || !IsCombatMovementAllowed()) &&
|
||||
(GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE ||
|
||||
moveFlags & MOVEMENTFLAG_SPLINE_ENABLED))
|
||||
{
|
||||
@@ -3739,6 +3739,11 @@ bool Creature::CanCastSpell(uint32 spellID) const
|
||||
return true;
|
||||
}
|
||||
|
||||
void Creature::SetCombatMovement(bool allowMovement)
|
||||
{
|
||||
_isCombatMovementAllowed = allowMovement;
|
||||
}
|
||||
|
||||
ObjectGuid Creature::GetSummonerGUID() const
|
||||
{
|
||||
if (TempSummon const* temp = ToTempSummon())
|
||||
|
||||
@@ -413,6 +413,14 @@ public:
|
||||
* */
|
||||
[[nodiscard]] ObjectGuid GetSummonerGUID() const;
|
||||
|
||||
// Used to control if MoveChase() is to be used or not in AttackStart(). Some creatures does not chase victims
|
||||
// NOTE: If you use SetCombatMovement while the creature is in combat, it will do NOTHING - This only affects AttackStart
|
||||
// You should make the necessary to make it happen so.
|
||||
// Remember that if you modified _isCombatMovementAllowed (e.g: using SetCombatMovement) it will not be reset at Reset().
|
||||
// It will keep the last value you set.
|
||||
void SetCombatMovement(bool allowMovement);
|
||||
bool IsCombatMovementAllowed() const { return _isCombatMovementAllowed; }
|
||||
|
||||
std::string GetDebugInfo() const override;
|
||||
|
||||
protected:
|
||||
@@ -501,6 +509,7 @@ private:
|
||||
|
||||
uint32 _playerDamageReq;
|
||||
bool _damagedByPlayer;
|
||||
bool _isCombatMovementAllowed;
|
||||
};
|
||||
|
||||
class AssistDelayEvent : public BasicEvent
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "Config.h"
|
||||
#include "Log.h"
|
||||
#include "Timer.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
// create instance
|
||||
WorldUpdateTime sWorldUpdateTime;
|
||||
@@ -71,8 +73,34 @@ uint32 UpdateTime::GetLastUpdateTime() const
|
||||
return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.size() - 1];
|
||||
}
|
||||
|
||||
uint32 UpdateTime::GetDatasetSize() const
|
||||
{
|
||||
return _updateTimeDataTable[_updateTimeDataTable.size() - 1] == 0 ? _updateTimeTableIndex : _orderedUpdateTimeDataTable.size();
|
||||
}
|
||||
|
||||
uint32 UpdateTime::GetPercentile(uint8 p)
|
||||
{
|
||||
if (_needsReorder)
|
||||
SortUpdateTimeDataTable();
|
||||
|
||||
// Calculate the index of the element corresponding to the percentile
|
||||
double index = (double(p) / 100.0) * (GetDatasetSize() - 1);
|
||||
|
||||
// If the index is an integer, return the value at that index
|
||||
if (index == floor(index))
|
||||
return _orderedUpdateTimeDataTable[index];
|
||||
|
||||
// Otherwise, perform linear interpolation
|
||||
int lowerIndex = floor(index);
|
||||
int upperIndex = ceil(index);
|
||||
double fraction = index - lowerIndex;
|
||||
|
||||
return _orderedUpdateTimeDataTable[lowerIndex] * (1 - fraction) + _orderedUpdateTimeDataTable[upperIndex] * fraction;
|
||||
}
|
||||
|
||||
void UpdateTime::UpdateWithDiff(uint32 diff)
|
||||
{
|
||||
_needsReorder = true;
|
||||
_totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff;
|
||||
_updateTimeDataTable[_updateTimeTableIndex] = diff;
|
||||
|
||||
@@ -100,6 +128,26 @@ void UpdateTime::RecordUpdateTimeReset()
|
||||
_recordedTime = GetTimeMS();
|
||||
}
|
||||
|
||||
void UpdateTime::SortUpdateTimeDataTable()
|
||||
{
|
||||
if (!_needsReorder)
|
||||
return;
|
||||
|
||||
auto endUpdateTable = _updateTimeDataTable.end();
|
||||
if (!_updateTimeDataTable[_updateTimeDataTable.size() - 1])
|
||||
endUpdateTable = std::next(_updateTimeDataTable.begin(), _updateTimeTableIndex);
|
||||
|
||||
std::copy(_updateTimeDataTable.begin(), endUpdateTable, _orderedUpdateTimeDataTable.begin());
|
||||
|
||||
auto endOrderedUpdateTable = _orderedUpdateTimeDataTable.end();
|
||||
if (!_updateTimeDataTable[_updateTimeDataTable.size() - 1])
|
||||
endOrderedUpdateTable = std::next(_orderedUpdateTimeDataTable.begin(), _updateTimeTableIndex);
|
||||
|
||||
std::sort(_orderedUpdateTimeDataTable.begin(), endOrderedUpdateTable);
|
||||
|
||||
_needsReorder = false;
|
||||
}
|
||||
|
||||
void WorldUpdateTime::LoadFromConfig()
|
||||
{
|
||||
_recordUpdateTimeInverval = Milliseconds(sConfigMgr->GetOption<uint32>("RecordUpdateTimeDiffInterval", 60000));
|
||||
@@ -117,7 +165,10 @@ void WorldUpdateTime::RecordUpdateTime(Milliseconds gameTimeMs, uint32 diff, uin
|
||||
{
|
||||
if (GetMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval)
|
||||
{
|
||||
LOG_INFO("time.update", "Update time diff: {}. Players online: {}.", GetAverageUpdateTime(), sessionCount);
|
||||
LOG_INFO("time.update", "Last {} diffs summary with {} players online:", GetDatasetSize(), sessionCount);
|
||||
LOG_INFO("time.update", " - Mean: {};", GetAverageUpdateTime());
|
||||
LOG_INFO("time.update", " - Median: {};", GetPercentile(50));
|
||||
LOG_INFO("time.update", " - Percentiles (95, 99, max): {}, {}, {}.", GetPercentile(95), GetPercentile(99), GetPercentile(100));
|
||||
_lastRecordTime = gameTimeMs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
uint32 GetMaxUpdateTime() const;
|
||||
uint32 GetMaxUpdateTimeOfCurrentTable() const;
|
||||
uint32 GetLastUpdateTime() const;
|
||||
uint32 GetDatasetSize() const;
|
||||
uint32 GetPercentile(uint8 p);
|
||||
|
||||
void UpdateWithDiff(uint32 diff);
|
||||
|
||||
@@ -43,6 +45,8 @@ public:
|
||||
protected:
|
||||
UpdateTime();
|
||||
|
||||
void SortUpdateTimeDataTable();
|
||||
|
||||
private:
|
||||
DiffTableArray _updateTimeDataTable;
|
||||
uint32 _averageUpdateTime;
|
||||
@@ -52,6 +56,9 @@ private:
|
||||
uint32 _maxUpdateTimeOfLastTable;
|
||||
uint32 _maxUpdateTimeOfCurrentTable;
|
||||
|
||||
DiffTableArray _orderedUpdateTimeDataTable;
|
||||
bool _needsReorder;
|
||||
|
||||
Milliseconds _recordedTime;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user