mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 18:36:31 +01:00
- Logging System is asyncronous to improve performance.
- Each msg and Logger has a Log Type and Log Level assigned. Each msg is assigned the Logger of same Log Type or "root" Logger is selected if there is no Logger configured for the given Log Type
- Loggers have a list of Appenders to send the msg to. The Msg in the Logger is not sent to Appenders if the msg LogLevel is lower than Logger LogLevel.
- There are three (at the moment) types of Appenders: Console, File or DB (this is WIP, not working ATM). Msg is not written to the resource if msg LogLevel is lower than Appender LogLevel.
- Appender and Console Log levels can be changed while server is active with command '.set loglevel (a/l) name level'
Explanation of use with Sample config:
Appender.Console.Type=1 (1 = Console)
Appender.Console.Level=2 (2 = Debug)
Appender.Server.Type=2 (2 = File)
Appender.Server.Level=3 (3 = Info)
Appender.Server.File=Server.log
Appender.SQL.Type=2 (2 = File)
Appender.SQL.Level=1 (1 = Trace)
Appender.SQL.File=sql.log
Appenders=Console Server (NOTE: SQL has not been included here... that will make core ignore the config for "SQL" as it's not in this list)
Logger.root.Type=0 (0 = Default - if it's not created by config, server will create it with LogLevel = DISABLED)
Logger.root.Level=5 (5 = Error)
Logger.root.Appenders=Console
Logger.SQL.Type=26 (26 = SQL)
Logger.SQL.Level=3 (2 = Debug)
Logger.SQL.Appenders=Console Server SQL
Logger.SomeRandomName.Type=24 (24 = Guild)
Logger.SomeRandomName.Level=5 (5 = Error)
Loggers=root SQL SomeRandomName
* At loading Appender SQL will be ignored, as it's not present on "Appenders"
* sLog->outDebug(LOG_FILTER_GUILD, "Some log msg related to Guilds")
- Msg is sent to Logger of Type LOG_FILTER_GUILD (24). Logger with name SomeRandomName is found but it's LogLevel = 5 and Msg LogLevel=2... Msg is not logged
* sLog->outError(LOG_FILTER_GUILD, "Some error log msg related to Guilds")
- Msg is sent to Logger of Type LOG_FILTER_GUILD (24). Logger with name SomeRandomeName is found with proper LogLevel but Logger does not have any Appenders assigned to that logger... Msg is not logged
* sLog->outDebug(LOG_FILTER_SQL, "Some msg related to SQLs")
- Msg is sent to Logger SQL (matches type), as it matches LogLevel the msg is sent to Appenders Console, Server and SQL
- Appender Console has lower Log Level: Msg is logged to Console
- Appender Server has higher Log Level: Msg is not logged to file
- Appender SQL has lower Log Level: Msg is logged to file sql.log
* sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Some msg related to Battelgrounds")
- Msg is sent to Logger root (Type 0) as no Logger was found with Type LOG_FILTER_BATTLEGROUND (13). As Logger has higher LogLevel msg is not sent to any appender
* sLog->outError(LOG_FILTER_BATTLEGROUND, "Some error msg related to Battelgrounds")
- Msg is sent to Logger root (Type 0) as no Logger was found with Type LOG_FILTER_BATTLEGROUND (13). Msg has lower LogLevel and is sent to Appender Console
- Appender Console has lower LogLevel: Msg is logged to Console
170 lines
5.8 KiB
C++
Executable File
170 lines
5.8 KiB
C++
Executable File
/*
|
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "CreatureAI.h"
|
|
#include "CreatureAIImpl.h"
|
|
#include "Creature.h"
|
|
#include "World.h"
|
|
#include "SpellMgr.h"
|
|
#include "Vehicle.h"
|
|
#include "Log.h"
|
|
#include "MapReference.h"
|
|
#include "Player.h"
|
|
#include "CreatureTextMgr.h"
|
|
|
|
//Disable CreatureAI when charmed
|
|
void CreatureAI::OnCharmed(bool /*apply*/)
|
|
{
|
|
//me->IsAIEnabled = !apply;*/
|
|
me->NeedChangeAI = true;
|
|
me->IsAIEnabled = false;
|
|
}
|
|
|
|
AISpellInfoType* UnitAI::AISpellInfo;
|
|
AISpellInfoType* GetAISpellInfo(uint32 i) { return &CreatureAI::AISpellInfo[i]; }
|
|
|
|
void CreatureAI::Talk(uint8 id, uint64 WhisperGuid)
|
|
{
|
|
sCreatureTextMgr->SendChat(me, id, WhisperGuid);
|
|
}
|
|
|
|
void CreatureAI::DoZoneInCombat(Creature* creature /*= NULL*/, float maxRangeToNearestTarget /* = 50.0f*/)
|
|
{
|
|
if (!creature)
|
|
creature = me;
|
|
|
|
if (!creature->CanHaveThreatList())
|
|
return;
|
|
|
|
Map* map = creature->GetMap();
|
|
if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated
|
|
{
|
|
sLog->outError(LOG_FILTER_GENERAL, "DoZoneInCombat call for map that isn't an instance (creature entry = %d)", creature->GetTypeId() == TYPEID_UNIT ? creature->ToCreature()->GetEntry() : 0);
|
|
return;
|
|
}
|
|
|
|
if (!creature->HasReactState(REACT_PASSIVE) && !creature->getVictim())
|
|
{
|
|
if (Unit* nearTarget = creature->SelectNearestTarget(maxRangeToNearestTarget))
|
|
creature->AI()->AttackStart(nearTarget);
|
|
else if (creature->isSummon())
|
|
{
|
|
if (Unit* summoner = creature->ToTempSummon()->GetSummoner())
|
|
{
|
|
Unit* target = summoner->getAttackerForHelper();
|
|
if (!target && summoner->CanHaveThreatList() && !summoner->getThreatManager().isThreatListEmpty())
|
|
target = summoner->getThreatManager().getHostilTarget();
|
|
if (target && (creature->IsFriendlyTo(summoner) || creature->IsHostileTo(target)))
|
|
creature->AI()->AttackStart(target);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!creature->HasReactState(REACT_PASSIVE) && !creature->getVictim())
|
|
{
|
|
sLog->outError(LOG_FILTER_GENERAL, "DoZoneInCombat called for creature that has empty threat list (creature entry = %u)", creature->GetEntry());
|
|
return;
|
|
}
|
|
|
|
Map::PlayerList const& playerList = map->GetPlayers();
|
|
|
|
if (playerList.isEmpty())
|
|
return;
|
|
|
|
for (Map::PlayerList::const_iterator itr = playerList.begin(); itr != playerList.end(); ++itr)
|
|
{
|
|
if (Player* player = itr->getSource())
|
|
{
|
|
if (player->isGameMaster())
|
|
continue;
|
|
|
|
if (player->isAlive())
|
|
{
|
|
creature->SetInCombatWith(player);
|
|
player->SetInCombatWith(creature);
|
|
creature->AddThreat(player, 0.0f);
|
|
}
|
|
|
|
/* Causes certain things to never leave the threat list (Priest Lightwell, etc):
|
|
for (Unit::ControlList::const_iterator itr = player->m_Controlled.begin(); itr != player->m_Controlled.end(); ++itr)
|
|
{
|
|
creature->SetInCombatWith(*itr);
|
|
(*itr)->SetInCombatWith(creature);
|
|
creature->AddThreat(*itr, 0.0f);
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
|
|
// scripts does not take care about MoveInLineOfSight loops
|
|
// MoveInLineOfSight can be called inside another MoveInLineOfSight and cause stack overflow
|
|
void CreatureAI::MoveInLineOfSight_Safe(Unit* who)
|
|
{
|
|
if (m_MoveInLineOfSight_locked == true)
|
|
return;
|
|
m_MoveInLineOfSight_locked = true;
|
|
MoveInLineOfSight(who);
|
|
m_MoveInLineOfSight_locked = false;
|
|
}
|
|
|
|
void CreatureAI::MoveInLineOfSight(Unit* who)
|
|
{
|
|
if (me->getVictim())
|
|
return;
|
|
|
|
if (me->GetCreatureType() == CREATURE_TYPE_NON_COMBAT_PET) // non-combat pets should just stand there and look good;)
|
|
return;
|
|
|
|
if (me->canStartAttack(who, false))
|
|
AttackStart(who);
|
|
//else if (who->getVictim() && me->IsFriendlyTo(who)
|
|
// && me->IsWithinDistInMap(who, sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS))
|
|
// && me->canStartAttack(who->getVictim(), true)) // TODO: if we use true, it will not attack it when it arrives
|
|
// me->GetMotionMaster()->MoveChase(who->getVictim());
|
|
}
|
|
|
|
void CreatureAI::EnterEvadeMode()
|
|
{
|
|
if (!_EnterEvadeMode())
|
|
return;
|
|
|
|
sLog->outDebug(LOG_FILTER_UNITS, "Creature %u enters evade mode.", me->GetEntry());
|
|
|
|
if (!me->GetVehicle()) // otherwise me will be in evade mode forever
|
|
{
|
|
if (Unit* owner = me->GetCharmerOrOwner())
|
|
{
|
|
me->GetMotionMaster()->Clear(false);
|
|
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle(), MOTION_SLOT_ACTIVE);
|
|
}
|
|
else
|
|
me->GetMotionMaster()->MoveTargetedHome();
|
|
}
|
|
|
|
Reset();
|
|
|
|
if (me->IsVehicle()) // use the same sequence of addtoworld, aireset may remove all summons!
|
|
me->GetVehicleKit()->Reset(true);
|
|
}
|
|
|
|
/*void CreatureAI::AttackedBy(Unit* attacker)
|
|
{
|
|
if (!me->getVictim())
|
|
AttackStart(attacker);
|
|
}*/
|