[11523] Implement .npc aiinfo

Comamnd show information about used AI and scripts for targeted creature.
AI classes (including from script DLL) can provide additinal info about own state.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Schmoozerd 2011-05-23 03:01:43 +04:00 committed by VladimirMangos
parent ae2a9e1c6a
commit 4ba5aa83e3
14 changed files with 94 additions and 11 deletions

View file

@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) default NULL,
`creature_ai_version` varchar(120) default NULL,
`cache_id` int(10) default '0',
`required_11521_01_mangos_command` bit(1) default NULL
`required_11523_02_mangos_mangos_string` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';
--
@ -682,6 +682,7 @@ INSERT INTO `command` VALUES
('npc additem',2,'Syntax: .npc additem #itemId <#maxcount><#incrtime><#extendedcost>r\r\n\r\nAdd item #itemid to item list of selected vendor. Also optionally set max count item in vendor item list and time to item count restoring and items ExtendedCost.'),
('npc addmove',2,'Syntax: .npc addmove #creature_guid [#waittime]\r\n\r\nAdd your current location as a waypoint for creature with guid #creature_guid. And optional add wait time.'),
('npc addweapon',3,'Not yet implemented.'),
('npc aiinfo',2,'Syntax: .npc npc aiinfo\r\n\r\nShow npc AI and script information.'),
('npc allowmove',3,'Syntax: .npc allowmove\r\n\r\nEnable or disable movement creatures in world. Not implemented.'),
('npc changelevel',2,'Syntax: .npc changelevel #level\r\n\r\nChange the level of the selected creature to #level.\r\n\r\n#level may range from 1 to 63.'),
('npc delete',2,'Syntax: .npc delete [#guid]\r\n\r\nDelete creature with guid #guid (or the selected if no guid is provided)'),
@ -3870,7 +3871,13 @@ INSERT INTO `mangos_string` VALUES
(1500,'%u - [%s] AutoSpawn: %u MaxLimit: %u Creatures: %u GameObjecs: %u Pools %u Chance: %f %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1501,'%u - |cffffffff|Hpool:%u|h[%s]|h|r AutoSpawn: %u MaxLimit: %u Creatures: %u GameObjecs: %u Pools %u %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1502,'%u - [%s] AutoSpawn: %u MaxLimit: %u Creatures: %u GameObjecs: %u Pools %u %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1503,'Can not add spawn because no free guids for static spawn in reserved guids range. Server restart is required before command can be used. Also look GuidReserveSize.* config options.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
(1503,'Can not add spawn because no free guids for static spawn in reserved guids range. Server restart is required before command can be used. Also look GuidReserveSize.* config options.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1504,'AI-Information for Npc Entry %u',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1505,'AIName: %s (%s) ScriptName: %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1506,'Current phase = %u',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1507,'Combat-Movement is %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1508,'Melee attacking is %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `mangos_string` ENABLE KEYS */;
UNLOCK TABLES;

View file

@ -0,0 +1,6 @@
ALTER TABLE db_version CHANGE COLUMN required_11521_01_mangos_command required_11523_01_mangos_command bit;
DELETE FROM command WHERE name = 'npc aiinfo';
INSERT INTO command (name, security, help) VALUES
('npc aiinfo',2,'Syntax: .npc npc aiinfo\r\n\r\nShow npc AI and script information.');

View file

@ -0,0 +1,10 @@
ALTER TABLE db_version CHANGE COLUMN required_11523_01_mangos_command required_11523_02_mangos_mangos_string bit;
DELETE FROM mangos_string WHERE entry IN (1504,1505,1506,1507,1508);
INSERT INTO mangos_string VALUES
(1504,'AI-Information for Npc Entry %u',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1505,'AIName: %s (%s) ScriptName: %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1506,'Current phase = %u',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1507,'Combat-Movement is %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1508,'Melee attacking is %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

View file

@ -389,6 +389,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "add", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddCommand, "", NULL },
{ "additem", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddVendorItemCommand, "", NULL },
{ "addmove", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddMoveCommand, "", NULL },
{ "aiinfo", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAIInfoCommand, "", NULL },
{ "allowmove", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcAllowMovementCommand, "", NULL },
{ "changeentry", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcChangeEntryCommand, "", NULL },
{ "changelevel", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcChangeLevelCommand, "", NULL },
@ -809,6 +810,11 @@ const char *ChatHandler::GetMangosString(int32 entry) const
return m_session->GetMangosString(entry);
}
const char *ChatHandler::GetOnOffStr(bool value) const
{
return value ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF);
}
uint32 ChatHandler::GetAccountId() const
{
return m_session->GetAccountId();

View file

@ -90,6 +90,8 @@ class ChatHandler
// function with different implementation for chat/console
virtual const char *GetMangosString(int32 entry) const;
const char *GetOnOffStr(bool value) const;
virtual void SendSysMessage( const char *str);
void SendSysMessage( int32 entry);
@ -325,6 +327,7 @@ class ChatHandler
bool HandleNpcAddCommand(char* args);
bool HandleNpcAddMoveCommand(char* args);
bool HandleNpcAddVendorItemCommand(char* args);
bool HandleNpcAIInfoCommand(char* args);
bool HandleNpcAllowMovementCommand(char* args);
bool HandleNpcChangeEntryCommand(char* args);
bool HandleNpcChangeLevelCommand(char* args);

View file

@ -32,6 +32,7 @@ class Unit;
class Creature;
class Player;
struct SpellEntry;
class ChatHandler;
#define TIME_INTERVAL_LOOK 5000
#define VISIBILITY_RANGE 10000
@ -65,6 +66,9 @@ class MANGOS_DLL_SPEC CreatureAI
virtual ~CreatureAI();
///== Information about AI ========================
virtual void GetAIInformation(ChatHandler& /*reader*/) {}
///== Reactions At =================================
// Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter

View file

@ -28,6 +28,8 @@
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "InstanceData.h"
#include "Chat.h"
#include "Language.h"
bool CreatureEventAIHolder::UpdateRepeatTimer( Creature* creature, uint32 repeatMin, uint32 repeatMax )
{
@ -52,6 +54,13 @@ int CreatureEventAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
void CreatureEventAI::GetAIInformation(ChatHandler& reader)
{
reader.PSendSysMessage(LANG_NPC_EVENTAI_PHASE, (uint32)m_Phase);
reader.PSendSysMessage(LANG_NPC_EVENTAI_MOVE, reader.GetOnOffStr(m_CombatMovementEnabled));
reader.PSendSysMessage(LANG_NPC_EVENTAI_COMBAT, reader.GetOnOffStr(m_MeleeEnabled));
}
CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
{
// Need make copy for filter unneeded steps and safe in case table reload

View file

@ -575,13 +575,15 @@ struct CreatureEventAIHolder
class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
{
public:
explicit CreatureEventAI(Creature *c);
~CreatureEventAI()
{
m_CreatureEventAIList.clear();
}
void GetAIInformation(ChatHandler& reader);
void JustRespawned();
void Reset();
void JustReachedHome();

View file

@ -937,7 +937,12 @@ enum MangosStrings
LANG_POOL_POOL_LIST_CHAT = 1501,
LANG_POOL_POOL_LIST_CONSOLE = 1502,
LANG_NO_FREE_STATIC_GUID_FOR_SPAWN = 1503,
// Room for more Level 2 1504-1599 not used
LANG_NPC_AI_HEADER = 1504,
LANG_NPC_AI_NAMES = 1505,
LANG_NPC_EVENTAI_PHASE = 1506,
LANG_NPC_EVENTAI_MOVE = 1507,
LANG_NPC_EVENTAI_COMBAT = 1508,
// Room for more Level 2 1509-1599 not used
// FREE IDS 1600-9999

View file

@ -1708,7 +1708,7 @@ bool ChatHandler::HandleWhispersCommand(char* args)
{
if(!*args)
{
PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, GetOnOffStr(m_session->GetPlayer()->isAcceptWhispers()));
return true;
}

View file

@ -26,6 +26,7 @@
#include "TemporarySummon.h"
#include "Totem.h"
#include "Pet.h"
#include "CreatureAI.h"
#include "GameObject.h"
#include "Opcodes.h"
#include "Chat.h"
@ -34,6 +35,7 @@
#include "Language.h"
#include "World.h"
#include "GameEventMgr.h"
#include "ScriptMgr.h"
#include "SpellMgr.h"
#include "MapPersistentStateMgr.h"
#include "AccountMgr.h"
@ -1677,6 +1679,35 @@ bool ChatHandler::HandleNpcDelVendorItemCommand(char* args)
return true;
}
//show info about AI
bool ChatHandler::HandleNpcAIInfoCommand(char* /*args*/)
{
Creature* pTarget = getSelectedCreature();
if (!pTarget)
{
SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
PSendSysMessage(LANG_NPC_AI_HEADER, pTarget->GetEntry());
std::string strScript = pTarget->GetScriptName();
std::string strAI = pTarget->GetAIName();
char const* cstrAIClass = pTarget->AI() ? typeid(*pTarget->AI()).name() : " - ";
PSendSysMessage(LANG_NPC_AI_NAMES,
strAI.empty() ? " - " : strAI.c_str(),
cstrAIClass ? cstrAIClass : " - ",
strScript.empty() ? " - " : strScript.c_str());
if (pTarget->AI())
pTarget->AI()->GetAIInformation(*this);
return true;
}
//add move for creature
bool ChatHandler::HandleNpcAddMoveCommand(char* args)
{
@ -2608,7 +2639,7 @@ bool ChatHandler::HandleTicketCommand(char* args)
{
bool accept = m_session->GetPlayer()->isAcceptTickets();
PSendSysMessage(LANG_COMMAND_TICKETCOUNT, count, accept ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
PSendSysMessage(LANG_COMMAND_TICKETCOUNT, count, GetOnOffStr(accept));
}
else
PSendSysMessage(LANG_COMMAND_TICKETCOUNT_CONSOLE, count);

View file

@ -514,7 +514,7 @@ bool ChatHandler::HandleServerLogFilterCommand(char* args)
SendSysMessage(LANG_LOG_FILTERS_STATE_HEADER);
for(int i = 0; i < LOG_FILTER_COUNT; ++i)
if (*logFilterData[i].name)
PSendSysMessage(" %-20s = %s",logFilterData[i].name, sLog.HasLogFilter(1 << i) ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
PSendSysMessage(" %-20s = %s",logFilterData[i].name, GetOnOffStr(sLog.HasLogFilter(1 << i)));
return true;
}
@ -533,7 +533,7 @@ bool ChatHandler::HandleServerLogFilterCommand(char* args)
if (strncmp(filtername, "all", 4) == 0)
{
sLog.SetLogFilter(LogFilters(0xFFFFFFFF), value);
PSendSysMessage(LANG_ALL_LOG_FILTERS_SET_TO_S, value ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
PSendSysMessage(LANG_ALL_LOG_FILTERS_SET_TO_S, GetOnOffStr(value));
return true;
}
@ -545,7 +545,7 @@ bool ChatHandler::HandleServerLogFilterCommand(char* args)
if (!strncmp(filtername,logFilterData[i].name,strlen(filtername)))
{
sLog.SetLogFilter(LogFilters(1 << i),value);
PSendSysMessage(" %-20s = %s",logFilterData[i].name,value ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
PSendSysMessage(" %-20s = %s",logFilterData[i].name, GetOnOffStr(value));
return true;
}
}

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11522"
#define REVISION_NR "11523"
#endif // __REVISION_NR_H__

View file

@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_11436_01_characters_character_queststatus"
#define REVISION_DB_MANGOS "required_11521_01_mangos_command"
#define REVISION_DB_MANGOS "required_11523_02_mangos_mangos_string"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__