源码求助实现判定功能
#include "Creature.h"#include "Database/DatabaseEnv.h"
#include "WorldPacket.h"
#include "World.h"
#include "ObjectMgr.h"
#include "ScriptMgr.h"
#include "ObjectGuid.h"
#include "SQLStorages.h"
#include "SpellMgr.h"
#include "QuestDef.h"
#include "GossipDef.h"
#include "Player.h"
#include "GameEventMgr.h"
#include "PoolManager.h"
#include "Opcodes.h"
#include "Log.h"
#include "LootMgr.h"
#include "MapManager.h"
#include "CreatureAI.h"
#include "CreatureAISelector.h"
#include "Formulas.h"
#include "WaypointMovementGenerator.h"
#include "InstanceData.h"
#include "MapPersistentStateMgr.h"
#include "BattleGround/BattleGroundMgr.h"
#include "OutdoorPvP/OutdoorPvP.h"
#include "Spell.h"
#include "Util.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
#include "movement/MoveSplineInit.h"
#include "CreatureLinkingMgr.h"
// apply implementation of the singletons
#include "Policies/Singleton.h"
// Dead player can see ghosts
if (GetCreatureInfo()->CreatureTypeFlags & CREATURE_TYPEFLAGS_GHOST_VISIBLE)
return true;
// and not see any other
return false;
}
void Creature::SendAIReaction(AiReaction reactionType)
{
WorldPacket data(SMSG_AI_REACTION, 12);
data << GetObjectGuid();
data << uint32(reactionType);
((WorldObject*)this)->SendMessageToSet(&data, true);
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "WORLD: Sent SMSG_AI_REACTION, type %u.", reactionType);
}
void Creature::CallAssistance()
{
// FIXME: should player pets call for assistance?
if (!m_AlreadyCallAssistance && getVictim() && !isCharmed())
{
SetNoCallAssistance(true);
if (GetCreatureInfo()->ExtraFlags & CREATURE_EXTRA_FLAG_NO_CALL_ASSIST)
return;
AI()->SendAIEventAround(AI_EVENT_CALL_ASSISTANCE, getVictim(), sWorld.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY), sWorld.getConfig(CONFIG_FLOAT_CREATURE_FAMILY_ASSISTANCE_RADIUS));
}
}
void Creature::CallForHelp(float fRadius)
{
if (fRadius <= 0.0f || !getVictim() || IsPet() || isCharmed())
return;
MaNGOS::CallOfHelpCreatureInRangeDo u_do(this, getVictim(), fRadius);
MaNGOS::CreatureWorker<MaNGOS::CallOfHelpCreatureInRangeDo> worker(this, u_do);
Cell::VisitGridObjects(this, worker, fRadius);
}
/// if enemy provided, check for initial combat help against enemy
bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /*= true*/) const
{
// we don't need help from zombies :)
if (!isAlive())
return false;
// we don't need help from non-combatant ;)
if (GetCreatureInfo()->ExtraFlags & CREATURE_EXTRA_FLAG_NO_AGGRO)
return false;
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_PASSIVE))
return false;
// skip fighting creature
if (enemy && isInCombat())
return false;
// only free creature
if (GetCharmerOrOwnerGuid())
return false;
// only from same creature faction
if (checkfaction)
{
if (getFaction() != u->getFaction())
return false;
}
else
{
if (!IsFriendlyTo(u))
return false;
}
// skip non hostile to caster enemy creatures
if (enemy && !IsHostileTo(enemy))
return false;
return true;
}
bool Creature::CanInitiateAttack()
{
if (hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED))
return false;
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
return false;
if (isPassiveToHostile())
return false;
if (m_aggroDelay != 0)
return false;
return true;
}
void Creature::SaveRespawnTime()
{
if (IsPet() || !HasStaticDBSpawnData())
return;
if (m_respawnTime > time(nullptr)) // dead (no corpse)
GetMap()->GetPersistentState()->SaveCreatureRespawnTime(GetGUIDLow(), m_respawnTime);
else if (m_corpseDecayTimer > 0) // dead (corpse)
GetMap()->GetPersistentState()->SaveCreatureRespawnTime(GetGUIDLow(), time(nullptr) + m_respawnDelay + m_corpseDecayTimer / IN_MILLISECONDS);
}
bool Creature::IsOutOfThreatArea(Unit* pVictim) const
{
if (!pVictim)
return true;
if (!pVictim->Attack
return false
if (!pVictim->IsInMap(this))
return true;
if (!pVictim->isTargetableForAttack())
return true;
if (!pVictim->isInAccessablePlaceFor(this))
return true;
if (!pVictim->isVisibleForOrDetect(this, this, false))
return true;
if (sMapStore.LookupEntry(GetMapId())->IsDungeon())
return false;
float AttackDist = GetAttackDistance(pVictim);
float ThreatRadius = sWorld.getConfig(CONFIG_FLOAT_THREAT_RADIUS);
// Use AttackDistance in distance check if threat radius is lower. This prevents creature bounce in and out of combat every update tick.
return !pVictim->IsWithinDist3d(m_combatStartX, m_combatStartY, m_combatStartZ,
ThreatRadius > AttackDist ? ThreatRadius : AttackDist);
}
这是一段魔兽世界 生物战斗的源码,求大神帮忙添加判定函数,判定10秒内不攻击则脱离战斗,否则一直战斗的函数,谢谢。