From a718115fd28fa91b82b6da055ecf60de02ec298d Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sun, 3 Feb 2019 16:22:17 +0200 Subject: [PATCH] Update a few npc commands. --- sql/migrations/20190203133019_world.sql | 21 ++++++ src/game/AI/CreatureEventAI.cpp | 2 - src/game/Chat/Chat.cpp | 3 +- src/game/Chat/Chat.h | 3 +- src/game/Commands/Level2.cpp | 10 +-- src/game/Commands/Level3.cpp | 94 +++++++++++-------------- src/game/Language.h | 7 +- src/game/Objects/Unit.cpp | 16 ++--- 8 files changed, 84 insertions(+), 72 deletions(-) create mode 100644 sql/migrations/20190203133019_world.sql diff --git a/sql/migrations/20190203133019_world.sql b/sql/migrations/20190203133019_world.sql new file mode 100644 index 000000000..06f8a1ea9 --- /dev/null +++ b/sql/migrations/20190203133019_world.sql @@ -0,0 +1,21 @@ +DROP PROCEDURE IF EXISTS add_migration; +delimiter ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20190203133019'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20190203133019'); +-- Add your query below. + + +UPDATE `mangos_string` SET `content_default`='Invalid virtual item slot (%u)' WHERE `entry`=505; +INSERT INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (1509, 'Motion type = %u', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/AI/CreatureEventAI.cpp b/src/game/AI/CreatureEventAI.cpp index 130240b2c..cdb178aac 100644 --- a/src/game/AI/CreatureEventAI.cpp +++ b/src/game/AI/CreatureEventAI.cpp @@ -62,8 +62,6 @@ int CreatureEventAI::Permissible(const Creature *creature) void CreatureEventAI::GetAIInformation(ChatHandler& reader) { reader.PSendSysMessage(LANG_NPC_EVENTAI_PHASE, (uint32)m_Phase); - reader.PSendSysMessage(LANG_NPC_EVENTAI_MOVE, reader.GetOnOffStr(m_bCombatMovement)); - reader.PSendSysMessage(LANG_NPC_EVENTAI_COMBAT, reader.GetOnOffStr(m_bMeleeAttack)); } CreatureEventAI::CreatureEventAI(Creature *c) : CreatureAI(c) diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp index 1f6349170..9582ca877 100644 --- a/src/game/Chat/Chat.cpp +++ b/src/game/Chat/Chat.cpp @@ -509,12 +509,14 @@ ChatCommand * ChatHandler::getCommandTable() { { NODE, "add", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddCommand, "", nullptr }, { NODE, "additem", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddVendorItemCommand, "", nullptr }, + { NODE, "addweapon", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddWeaponCommand, "", nullptr }, { NODE, "aiinfo", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAIInfoCommand, "", nullptr }, { NODE, "allowmove", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcAllowMovementCommand, "", nullptr }, { NODE, "changeentry", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcChangeEntryCommand, "", nullptr }, { NODE, "changelevel", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcChangeLevelCommand, "", nullptr }, { NODE, "delete", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcDeleteCommand, "", nullptr }, { NODE, "delitem", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcDelVendorItemCommand, "", nullptr }, + { NODE, "evade", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcEvadeCommand, "", nullptr }, { NODE, "factionid", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcFactionIdCommand, "", nullptr }, { NODE, "flag", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcFlagCommand, "", nullptr }, { NODE, "follow", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcFollowCommand, "", nullptr }, @@ -537,7 +539,6 @@ ChatCommand * ChatHandler::getCommandTable() //{ TODO: fix or remove this commands - { NODE, "addweapon", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcAddWeaponCommand, "", nullptr }, { NODE, "name", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcNameCommand, "", nullptr }, { NODE, "subname", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcSubNameCommand, "", nullptr }, //} diff --git a/src/game/Chat/Chat.h b/src/game/Chat/Chat.h index d7a6fba66..69f554f08 100644 --- a/src/game/Chat/Chat.h +++ b/src/game/Chat/Chat.h @@ -609,6 +609,7 @@ class MANGOS_DLL_SPEC ChatHandler //-----------------------Npc Commands----------------------- bool HandleNpcAddCommand(char* args); + bool HandleNpcAddWeaponCommand(char* args); bool HandleNpcSummonCommand(char* args); bool HandleNpcAddVendorItemCommand(char* args); bool HandleNpcAIInfoCommand(char* args); @@ -617,6 +618,7 @@ class MANGOS_DLL_SPEC ChatHandler bool HandleNpcChangeLevelCommand(char* args); bool HandleNpcDeleteCommand(char* args); bool HandleNpcDelVendorItemCommand(char* args); + bool HandleNpcEvadeCommand(char* args); bool HandleNpcFactionIdCommand(char* args); bool HandleNpcFlagCommand(char* args); bool HandleNpcFollowCommand(char* args); @@ -636,7 +638,6 @@ class MANGOS_DLL_SPEC ChatHandler bool HandleNpcYellCommand(char* args); //TODO: NpcCommands that needs to be fixed : - bool HandleNpcAddWeaponCommand(char* args); bool HandleNpcNameCommand(char* args); bool HandleNpcSubNameCommand(char* args); //---------------------------------------------------------- diff --git a/src/game/Commands/Level2.cpp b/src/game/Commands/Level2.cpp index 26f62b687..ab311e7dc 100644 --- a/src/game/Commands/Level2.cpp +++ b/src/game/Commands/Level2.cpp @@ -1722,7 +1722,7 @@ bool ChatHandler::HandleNpcAIInfoCommand(char* /*args*/) { Creature* pTarget = GetSelectedCreature(); - if (!pTarget) + if (!pTarget || !pTarget->AI()) { SendSysMessage(LANG_SELECT_CREATURE); SetSentErrorMessage(true); @@ -1739,9 +1739,10 @@ bool ChatHandler::HandleNpcAIInfoCommand(char* /*args*/) strAI.empty() ? " - " : strAI.c_str(), cstrAIClass ? cstrAIClass : " - ", strScript.empty() ? " - " : strScript.c_str()); - - if (pTarget->AI()) - pTarget->AI()->GetAIInformation(*this); + PSendSysMessage(LANG_NPC_AI_MOVE, GetOnOffStr(pTarget->AI()->IsCombatMovementEnabled())); + PSendSysMessage(LANG_NPC_AI_ATTACK, GetOnOffStr(pTarget->AI()->IsMeleeAttackEnabled())); + PSendSysMessage(LANG_NPC_MOTION_TYPE, pTarget->GetMotionMaster()->GetCurrentMovementGeneratorType()); + pTarget->AI()->GetAIInformation(*this); return true; } @@ -2054,6 +2055,7 @@ bool ChatHandler::HandleNpcSetModelCommand(char* args) return true; } + //set faction of creature bool ChatHandler::HandleNpcFactionIdCommand(char* args) { diff --git a/src/game/Commands/Level3.cpp b/src/game/Commands/Level3.cpp index a7911aaaa..e33b11349 100644 --- a/src/game/Commands/Level3.cpp +++ b/src/game/Commands/Level3.cpp @@ -4261,6 +4261,7 @@ bool ChatHandler::HandleNearGraveCommand(char* args) } //-----------------------Npc Commands----------------------- + bool ChatHandler::HandleNpcAllowMovementCommand(char* /*args*/) { if (sWorld.getAllowMovement()) @@ -4300,6 +4301,23 @@ bool ChatHandler::HandleNpcChangeEntryCommand(char *args) return true; } +bool ChatHandler::HandleNpcEvadeCommand(char* /*args*/) +{ + Creature* pTarget = GetSelectedCreature(); + + if (!pTarget) + { + SendSysMessage(LANG_SELECT_CREATURE); + SetSentErrorMessage(true); + return false; + } + + if (pTarget->AI()) + pTarget->AI()->EnterEvadeMode(); + + return true; +} + bool ChatHandler::HandleNpcInfoCommand(char* /*args*/) { Creature* target = GetSelectedCreature(); @@ -4368,73 +4386,43 @@ bool ChatHandler::HandleNpcPlayEmoteCommand(char* args) return true; } -//TODO: NpcCommands that needs to be fixed : - -bool ChatHandler::HandleNpcAddWeaponCommand(char* /*args*/) +bool ChatHandler::HandleNpcAddWeaponCommand(char* args) { - /*if (!*args) - return false; + Creature* pCreature = GetSelectedCreature(); - ObjectGuid guid = m_session->GetPlayer()->GetSelectionGuid(); - if (guid.IsEmpty()) - { - SendSysMessage(LANG_NO_SELECTION); - return true; - } - - Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid); - - if(!pCreature) + if (!pCreature) { SendSysMessage(LANG_SELECT_CREATURE); return true; } - char* pSlotID = strtok((char*)args, " "); - if (!pSlotID) + uint32 uiItemId = 0; + + if (!ExtractUInt32(&args, uiItemId)) return false; - char* pItemID = strtok(NULL, " "); - if (!pItemID) + uint32 uiSlotId = 0; + + if (!ExtractUInt32(&args, uiSlotId)) return false; + + ItemPrototype const* pItemProto = ObjectMgr::GetItemPrototype(uiItemId); - uint32 ItemID = atoi(pItemID); - uint32 SlotID = atoi(pSlotID); - - ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID); - - bool added = false; - if(tmpItem) + if (!pItemProto) { - switch(SlotID) - { - case 1: - pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID); - added = true; - break; - case 2: - pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID); - added = true; - break; - case 3: - pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID); - added = true; - break; - default: - PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID); - added = false; - break; - } - - if(added) - PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID); - } - else - { - PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID); + PSendSysMessage(LANG_ITEM_NOT_FOUND, uiItemId); return true; } - */ + + if (uiSlotId > VIRTUAL_ITEM_SLOT_2) + { + PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST, uiSlotId); + return true; + } + + pCreature->SetVirtualItem(VirtualItemSlot(uiSlotId), uiItemId); + PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT, uiItemId, pItemProto->Name1, uiSlotId); + return true; } //---------------------------------------------------------- diff --git a/src/game/Language.h b/src/game/Language.h index 0ef18b736..c95279485 100644 --- a/src/game/Language.h +++ b/src/game/Language.h @@ -1058,9 +1058,10 @@ enum MangosStrings 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 + LANG_NPC_AI_MOVE = 1507, + LANG_NPC_AI_ATTACK = 1508, + LANG_NPC_MOTION_TYPE = 1509, + // Room for more Level 2 1510-1599 not used // Ticket entries LANG_COMMAND_TICKETPLAYERABANDON = 2002, diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp index 3a5d14229..e69e4bad8 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -5931,15 +5931,15 @@ void Unit::CombatStop(bool includingCast) if (AI() && isInCombat()) AI()->OnCombatStop(); - if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel - else if (GetTypeId() == TYPEID_UNIT) + if (Player* pPlayer = ToPlayer()) + pPlayer->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel + else if (Creature* pCreature = ToCreature()) { - ((Creature*)this)->UpdateCombatState(false); - ((Creature*)this)->UpdateCombatWithZoneState(false); - ((Creature*)this)->m_TargetNotReachableTimer = 0; - if (((Creature*)this)->GetTemporaryFactionFlags() & TEMPFACTION_RESTORE_COMBAT_STOP) - ((Creature*)this)->ClearTemporaryFaction(); + pCreature->UpdateCombatState(false); + pCreature->UpdateCombatWithZoneState(false); + pCreature->m_TargetNotReachableTimer = 0; + if (pCreature->GetTemporaryFactionFlags() & TEMPFACTION_RESTORE_COMBAT_STOP) + pCreature->ClearTemporaryFaction(); } ClearInCombat();