From 4ba5aa83e39a2449d659c84a9a25ea82e7c3973f Mon Sep 17 00:00:00 2001 From: Schmoozerd Date: Mon, 23 May 2011 03:01:43 +0400 Subject: [PATCH] [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 --- sql/mangos.sql | 11 +++++-- sql/updates/11523_01_mangos_command.sql | 6 ++++ sql/updates/11523_02_mangos_mangos_string.sql | 10 ++++++ src/game/Chat.cpp | 6 ++++ src/game/Chat.h | 3 ++ src/game/CreatureAI.h | 4 +++ src/game/CreatureEventAI.cpp | 9 +++++ src/game/CreatureEventAI.h | 4 ++- src/game/Language.h | 7 +++- src/game/Level1.cpp | 2 +- src/game/Level2.cpp | 33 ++++++++++++++++++- src/mangosd/CliRunnable.cpp | 6 ++-- src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 14 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 sql/updates/11523_01_mangos_command.sql create mode 100644 sql/updates/11523_02_mangos_mangos_string.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index c319f0b2f..97a833b90 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -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; diff --git a/sql/updates/11523_01_mangos_command.sql b/sql/updates/11523_01_mangos_command.sql new file mode 100644 index 000000000..ec91ae17e --- /dev/null +++ b/sql/updates/11523_01_mangos_command.sql @@ -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.'); diff --git a/sql/updates/11523_02_mangos_mangos_string.sql b/sql/updates/11523_02_mangos_mangos_string.sql new file mode 100644 index 000000000..f8d07aff7 --- /dev/null +++ b/sql/updates/11523_02_mangos_mangos_string.sql @@ -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); diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index 767e69a57..7b6421dca 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -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(); diff --git a/src/game/Chat.h b/src/game/Chat.h index 64030a938..253055fef 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -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); diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h index 10ea75c21..2a49d501d 100644 --- a/src/game/CreatureAI.h +++ b/src/game/CreatureAI.h @@ -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 diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 01659d1cb..f75a4ac18 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -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 diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index d1a33f4d3..70ea40b44 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -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(); diff --git a/src/game/Language.h b/src/game/Language.h index 52418ef56..8a9b3dfea 100644 --- a/src/game/Language.h +++ b/src/game/Language.h @@ -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 diff --git a/src/game/Level1.cpp b/src/game/Level1.cpp index f98105b5f..7aeab2579 100644 --- a/src/game/Level1.cpp +++ b/src/game/Level1.cpp @@ -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; } diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 64bd45775..ebdb4bc7f 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -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); diff --git a/src/mangosd/CliRunnable.cpp b/src/mangosd/CliRunnable.cpp index 7d75e133f..0b3f0daf6 100644 --- a/src/mangosd/CliRunnable.cpp +++ b/src/mangosd/CliRunnable.cpp @@ -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; } } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index e182c9071..6642d3fcb 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11522" + #define REVISION_NR "11523" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 2325164ce..5ab955a03 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -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__