2010-11-09 10:15:35 -05:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2010-11-09 10:15:35 -05:00
*
* 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/>.
*/
/* ScriptData
Name: npc_commandscript
%Complete: 100
Comment: All npc related commands
Category: commandscripts
EndScriptData */
2017-05-20 00:09:37 +02:00
#include "ScriptMgr.h"
2010-11-13 22:29:46 +01:00
#include "Chat.h"
2022-02-11 21:57:45 +01:00
#include "ChatCommand.h"
2017-05-18 23:52:58 +02:00
#include "CreatureAI.h"
2010-11-09 10:15:35 -05:00
#include "CreatureGroups.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
2021-10-02 19:59:56 +02:00
#include "DB2Stores.h"
2018-04-06 18:09:55 +02:00
#include "FollowMovementGenerator.h"
2017-12-10 12:39:37 +01:00
#include "GameTime.h"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2022-09-01 20:07:58 +02:00
#include "Loot.h"
2017-06-04 01:00:45 +02:00
#include "Map.h"
2018-04-19 13:31:39 +02:00
#include "MotionMaster.h"
#include "MovementDefines.h"
2017-06-04 01:00:45 +02:00
#include "ObjectAccessor.h"
2017-05-18 23:52:58 +02:00
#include "ObjectMgr.h"
2012-11-20 12:30:30 +01:00
#include "Pet.h"
2018-01-28 11:37:20 +01:00
#include "PhasingHandler.h"
2017-05-18 23:52:58 +02:00
#include "Player.h"
2017-05-20 00:09:37 +02:00
#include "RBAC.h"
2018-10-26 14:43:22 +02:00
#include "SmartEnum.h"
2017-05-18 23:52:58 +02:00
#include "Transport.h"
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
using namespace Trinity :: ChatCommands ;
2020-09-20 02:50:38 +02:00
2020-09-04 00:58:23 +02:00
using CreatureSpawnId = Variant < Hyperlink < creature > , ObjectGuid :: LowType > ;
using CreatureEntry = Variant < Hyperlink < creature_entry > , uint32 > ;
2017-05-07 21:48:41 +01:00
2020-09-04 00:58:23 +02:00
// shared with cs_gobject.cpp, definitions are at the bottom of this file
2020-09-10 15:19:17 +02:00
bool HandleNpcSpawnGroup ( ChatHandler * handler , std :: vector < Variant < uint32 , EXACT_SEQUENCE ( "force" ), EXACT_SEQUENCE ( "ignorerespawn" ) >> const & opts );
bool HandleNpcDespawnGroup ( ChatHandler * handler , std :: vector < Variant < uint32 , EXACT_SEQUENCE ( "removerespawntime" ) >> const & opts );
2017-05-07 21:48:41 +01:00
2010-11-09 10:15:35 -05:00
class npc_commandscript : public CommandScript
{
2010-11-19 14:04:21 +01:00
public :
npc_commandscript () : CommandScript ( "npc_commandscript" ) { }
2010-11-09 10:15:35 -05:00
2020-09-20 02:50:38 +02:00
ChatCommandTable GetCommands () const override
2010-11-19 14:04:21 +01:00
{
2020-09-20 02:50:38 +02:00
static ChatCommandTable npcAddCommandTable =
2010-11-19 14:04:21 +01:00
{
2020-09-20 02:50:38 +02:00
{ "formation" , HandleNpcAddFormationCommand , rbac :: RBAC_PERM_COMMAND_NPC_ADD_FORMATION , Console :: No },
{ "item" , HandleNpcAddVendorItemCommand , rbac :: RBAC_PERM_COMMAND_NPC_ADD_ITEM , Console :: No },
{ "move" , HandleNpcAddMoveCommand , rbac :: RBAC_PERM_COMMAND_NPC_ADD_MOVE , Console :: No },
{ "temp" , HandleNpcAddTempSpawnCommand , rbac :: RBAC_PERM_COMMAND_NPC_ADD_TEMP , Console :: No },
// { "weapon", HandleNpcAddWeaponCommand, rbac::RBAC_PERM_COMMAND_NPC_ADD_WEAPON, Console::No },
{ "" , HandleNpcAddCommand , rbac :: RBAC_PERM_COMMAND_NPC_ADD , Console :: No },
2010-11-19 14:04:21 +01:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable npcSetCommandTable =
2015-10-22 20:26:56 +02:00
{
2020-09-20 02:50:38 +02:00
{ "allowmove" , HandleNpcSetAllowMovementCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_ALLOWMOVE , Console :: No },
{ "entry" , HandleNpcSetEntryCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_ENTRY , Console :: No },
{ "factionid" , HandleNpcSetFactionIdCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_FACTIONID , Console :: No },
{ "flag" , HandleNpcSetFlagCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_FLAG , Console :: No },
{ "level" , HandleNpcSetLevelCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_LEVEL , Console :: No },
{ "link" , HandleNpcSetLinkCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_LINK , Console :: No },
{ "model" , HandleNpcSetModelCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_MODEL , Console :: No },
{ "movetype" , HandleNpcSetMoveTypeCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_MOVETYPE , Console :: No },
{ "phase" , HandleNpcSetPhaseCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_PHASE , Console :: No },
{ "wanderdistance" , HandleNpcSetWanderDistanceCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_SPAWNDIST , Console :: No },
{ "spawntime" , HandleNpcSetSpawnTimeCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_SPAWNTIME , Console :: No },
{ "data" , HandleNpcSetDataCommand , rbac :: RBAC_PERM_COMMAND_NPC_SET_DATA , Console :: No },
2010-11-19 14:04:21 +01:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable npcCommandTable =
2015-10-22 20:26:56 +02:00
{
2020-09-20 02:50:38 +02:00
{ "add" , npcAddCommandTable },
{ "set" , npcSetCommandTable },
{ "info" , HandleNpcInfoCommand , rbac :: RBAC_PERM_COMMAND_NPC_INFO , Console :: No },
{ "near" , HandleNpcNearCommand , rbac :: RBAC_PERM_COMMAND_NPC_NEAR , Console :: No },
{ "move" , HandleNpcMoveCommand , rbac :: RBAC_PERM_COMMAND_NPC_MOVE , Console :: No },
{ "playemote" , HandleNpcPlayEmoteCommand , rbac :: RBAC_PERM_COMMAND_NPC_PLAYEMOTE , Console :: No },
{ "say" , HandleNpcSayCommand , rbac :: RBAC_PERM_COMMAND_NPC_SAY , Console :: No },
{ "textemote" , HandleNpcTextEmoteCommand , rbac :: RBAC_PERM_COMMAND_NPC_TEXTEMOTE , Console :: No },
{ "whisper" , HandleNpcWhisperCommand , rbac :: RBAC_PERM_COMMAND_NPC_WHISPER , Console :: No },
{ "yell" , HandleNpcYellCommand , rbac :: RBAC_PERM_COMMAND_NPC_YELL , Console :: No },
{ "tame" , HandleNpcTameCommand , rbac :: RBAC_PERM_COMMAND_NPC_TAME , Console :: No },
{ "spawngroup" , HandleNpcSpawnGroup , rbac :: RBAC_PERM_COMMAND_NPC_SPAWNGROUP , Console :: No },
{ "despawngroup" , HandleNpcDespawnGroup , rbac :: RBAC_PERM_COMMAND_NPC_DESPAWNGROUP , Console :: No },
{ "delete" , HandleNpcDeleteCommand , rbac :: RBAC_PERM_COMMAND_NPC_DELETE , Console :: No },
{ "delete item" , HandleNpcDeleteVendorItemCommand , rbac :: RBAC_PERM_COMMAND_NPC_DELETE_ITEM , Console :: No },
{ "follow" , HandleNpcFollowCommand , rbac :: RBAC_PERM_COMMAND_NPC_FOLLOW , Console :: No },
{ "follow stop" , HandleNpcUnFollowCommand , rbac :: RBAC_PERM_COMMAND_NPC_FOLLOW , Console :: No },
{ "evade" , HandleNpcEvadeCommand , rbac :: RBAC_PERM_COMMAND_NPC_EVADE , Console :: No },
{ "showloot" , HandleNpcShowLootCommand , rbac :: RBAC_PERM_COMMAND_NPC_SHOWLOOT , Console :: No },
2010-11-19 14:04:21 +01:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable commandTable =
2010-11-19 14:04:21 +01:00
{
2020-09-20 02:50:38 +02:00
{ "npc" , npcCommandTable },
2010-11-19 14:04:21 +01:00
};
return commandTable ;
}
//add spawn of creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcAddCommand ( ChatHandler * handler , CreatureEntry id )
2010-11-19 14:04:21 +01:00
{
2013-09-06 14:31:41 +02:00
if ( ! sObjectMgr -> GetCreatureTemplate ( id ))
return false ;
2010-11-19 14:04:21 +01:00
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2011-09-15 14:08:17 +02:00
Map * map = chr -> GetMap ();
2010-11-19 14:04:21 +01:00
2022-05-25 22:14:32 +02:00
if ( Transport * trans = dynamic_cast < Transport *> ( chr -> GetTransport ()))
2010-11-19 14:04:21 +01:00
{
2020-05-16 11:23:34 +02:00
ObjectGuid :: LowType guid = sObjectMgr -> GenerateCreatureSpawnId ();
2013-10-16 18:37:29 +02:00
CreatureData & data = sObjectMgr -> NewOrExistCreatureData ( guid );
2017-05-07 21:48:41 +01:00
data . spawnId = guid ;
2020-05-16 11:23:34 +02:00
data . spawnGroupData = sObjectMgr -> GetDefaultSpawnGroup ();
2013-10-16 18:37:29 +02:00
data . id = id ;
2017-05-07 21:48:41 +01:00
data . spawnPoint . Relocate ( chr -> GetTransOffsetX (), chr -> GetTransOffsetY (), chr -> GetTransOffsetZ (), chr -> GetTransOffsetO ());
2018-04-19 23:37:41 +02:00
if ( Creature * creature = trans -> CreateNPCPassenger ( guid , & data ))
{
creature -> SaveToDB ( trans -> GetGOInfo () -> moTransport . SpawnMap , { map -> GetDifficultyID () });
2021-12-28 14:24:10 +02:00
sObjectMgr -> AddCreatureToGrid ( & data );
2018-04-19 23:37:41 +02:00
}
2010-11-19 14:04:21 +01:00
return true ;
2010-11-09 10:15:35 -05:00
}
2018-01-27 21:47:37 +01:00
Creature * creature = Creature :: CreateCreature ( id , map , chr -> GetPosition ());
if ( ! creature )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2018-01-28 11:37:20 +01:00
PhasingHandler :: InheritPhaseShift ( creature , chr );
2018-09-15 17:55:26 +02:00
creature -> SaveToDB ( map -> GetId (), { map -> GetDifficultyID () });
2010-11-09 10:15:35 -05:00
2015-02-25 00:13:14 +01:00
ObjectGuid :: LowType db_guid = creature -> GetSpawnId ();
2010-11-09 10:15:35 -05:00
2013-12-29 19:37:20 +01:00
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
creature -> CleanupsBeforeDelete ();
delete creature ;
2018-01-27 21:47:37 +01:00
2017-05-07 21:48:41 +01:00
creature = Creature :: CreateCreatureFromDB ( db_guid , map , true , true );
2018-01-27 21:47:37 +01:00
if ( ! creature )
2011-11-28 14:05:25 -05:00
return false ;
2010-11-09 10:15:35 -05:00
2021-12-28 14:24:10 +02:00
sObjectMgr -> AddCreatureToGrid ( sObjectMgr -> GetCreatureData ( db_guid ));
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//add item in vendorlist
2020-09-04 00:58:23 +02:00
static bool HandleNpcAddVendorItemCommand ( ChatHandler * handler , ItemTemplate const * item , Optional < uint32 > mc , Optional < uint32 > it , Optional < uint32 > ec , Optional < std :: string_view > bonusListIDs )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
if ( ! item )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_COMMAND_NEEDITEMSEND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
Creature * vendor = handler -> getSelectedCreature ();
if ( ! vendor )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2020-09-04 00:58:23 +02:00
uint32 itemId = item -> GetId ();
uint32 maxcount = mc . value_or ( 0 );
uint32 incrtime = it . value_or ( 0 );
uint32 extendedcost = ec . value_or ( 0 );
2013-05-19 11:15:54 +02:00
uint32 vendor_entry = vendor -> GetEntry ();
2010-11-19 14:04:21 +01:00
2017-10-09 20:03:25 +01:00
VendorItem vItem ;
vItem . item = itemId ;
vItem . maxcount = maxcount ;
vItem . incrtime = incrtime ;
vItem . ExtendedCost = extendedcost ;
2020-09-04 00:58:23 +02:00
vItem . Type = ITEM_VENDOR_TYPE_ITEM ;
2017-10-09 20:03:25 +01:00
2020-09-04 00:58:23 +02:00
if ( bonusListIDs )
for ( std :: string_view token : Trinity :: Tokenize ( * bonusListIDs , ';' , false ))
2020-08-28 00:11:16 +02:00
if ( Optional < int32 > bonusListID = Trinity :: StringTo < int32 > ( token ))
vItem . BonusListIDs . push_back ( * bonusListID );
2017-10-09 20:03:25 +01:00
if ( ! sObjectMgr -> IsVendorItemValid ( vendor_entry , vItem , handler -> GetSession () -> GetPlayer ()))
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2017-10-09 20:03:25 +01:00
sObjectMgr -> AddVendorItem ( vendor_entry , vItem );
2010-11-09 10:15:35 -05:00
2021-06-20 13:11:53 +02:00
handler -> PSendSysMessage ( LANG_ITEM_ADDED_TO_LIST , itemId , item -> GetDefaultLocaleName (), maxcount , incrtime , extendedcost );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//add move for creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcAddMoveCommand ( ChatHandler * handler , CreatureSpawnId lowGuid )
2010-11-19 14:04:21 +01:00
{
// attempt check creature existence by DB data
2015-05-31 00:01:31 +02:00
CreatureData const * data = sObjectMgr -> GetCreatureData ( lowGuid );
if ( ! data )
2010-11-09 10:15:35 -05:00
{
2022-03-12 18:35:59 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , std :: to_string ( * lowGuid ). c_str ());
2015-05-31 00:01:31 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
// Update movement type
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_MOVEMENT_TYPE );
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
stmt -> setUInt8 ( 0 , uint8 ( WAYPOINT_MOTION_TYPE ));
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 1 , lowGuid );
2011-12-31 00:32:05 +01:00
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_WAYPOINT_ADDED );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetAllowMovementCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2010-12-23 23:25:44 +01:00
if ( sWorld -> getAllowMovement ())
2010-11-19 14:04:21 +01:00
{
2010-12-23 23:25:44 +01:00
sWorld -> SetAllowMovement ( false );
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_CREATURE_MOVE_DISABLED );
}
else
{
2010-12-23 23:25:44 +01:00
sWorld -> SetAllowMovement ( true );
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_CREATURE_MOVE_ENABLED );
}
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetEntryCommand ( ChatHandler * handler , CreatureEntry newEntryNum )
2010-11-19 14:04:21 +01:00
{
if ( ! newEntryNum )
return false ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
Unit * unit = handler -> getSelectedUnit ();
if ( ! unit || unit -> GetTypeId () != TYPEID_UNIT )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
Creature * creature = unit -> ToCreature ();
if ( creature -> UpdateEntry ( newEntryNum ))
handler -> SendSysMessage ( LANG_DONE );
else
handler -> SendSysMessage ( LANG_ERROR );
return true ;
}
//change level of creature or pet
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetLevelCommand ( ChatHandler * handler , uint8 lvl )
2010-11-19 14:04:21 +01:00
{
2010-12-23 23:25:44 +01:00
if ( lvl < 1 || lvl > sWorld -> getIntConfig ( CONFIG_MAX_PLAYER_LEVEL ) + 3 )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_BAD_VALUE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2016-01-20 23:43:13 +01:00
if ( ! creature || creature -> IsPet ())
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2016-01-20 23:43:13 +01:00
creature -> SetMaxHealth ( 100 + 30 * lvl );
creature -> SetHealth ( 100 + 30 * lvl );
creature -> SetLevel ( lvl );
creature -> SaveToDB ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcDeleteCommand ( ChatHandler * handler , Optional < CreatureSpawnId > spawnIdArg )
2010-11-19 14:04:21 +01:00
{
2019-07-08 11:33:09 +02:00
ObjectGuid :: LowType spawnId ;
if ( spawnIdArg )
spawnId = * spawnIdArg ;
else
2010-11-19 14:04:21 +01:00
{
2019-07-08 11:33:09 +02:00
Creature * creature = handler -> getSelectedCreature ();
if ( ! creature || creature -> IsPet () || creature -> IsTotem ())
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
2010-11-19 14:04:21 +01:00
return false ;
2019-07-08 11:33:09 +02:00
}
if ( TempSummon * summon = creature -> ToTempSummon ())
{
summon -> UnSummon ();
handler -> SendSysMessage ( LANG_COMMAND_DELCREATMESSAGE );
return true ;
}
spawnId = creature -> GetSpawnId ();
2010-11-09 10:15:35 -05:00
}
2019-07-08 11:33:09 +02:00
if ( Creature :: DeleteFromDB ( spawnId ))
2010-11-09 10:15:35 -05:00
{
2019-07-08 11:33:09 +02:00
handler -> SendSysMessage ( LANG_COMMAND_DELCREATMESSAGE );
return true ;
2010-11-19 14:04:21 +01:00
}
2017-05-07 21:48:41 +01:00
else
{
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , std :: to_string ( spawnId ). c_str ());
2019-07-08 11:33:09 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
2017-05-07 21:48:41 +01:00
}
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//del item from vendor list
2020-09-04 00:58:23 +02:00
static bool HandleNpcDeleteVendorItemCommand ( ChatHandler * handler , ItemTemplate const * item )
2010-11-19 14:04:21 +01:00
{
Creature * vendor = handler -> getSelectedCreature ();
2013-06-11 19:54:27 -02:30
if ( ! vendor || ! vendor -> IsVendor ())
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_COMMAND_VENDORSELECTION );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
if ( ! item )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_COMMAND_NEEDITEMSEND );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2012-08-14 18:11:06 +01:00
2020-09-04 00:58:23 +02:00
uint32 itemId = item -> GetId ();
if ( ! sObjectMgr -> RemoveVendorItem ( vendor -> GetEntry (), ITEM_VENDOR_TYPE_ITEM , itemId ))
2010-11-09 10:15:35 -05:00
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_ITEM_NOT_IN_LIST , itemId );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2021-06-20 13:11:53 +02:00
handler -> PSendSysMessage ( LANG_ITEM_DELETED_FROM_LIST , itemId , item -> GetDefaultLocaleName ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//set faction of creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetFactionIdCommand ( ChatHandler * handler , uint32 factionId )
2010-11-19 14:04:21 +01:00
{
if ( ! sFactionTemplateStore . LookupEntry ( factionId ))
{
handler -> PSendSysMessage ( LANG_WRONG_FACTION , factionId );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2017-04-28 02:24:04 -03:00
creature -> SetFaction ( factionId );
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
// Faction is set in creature_template - not inside creature
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
// Update in memory..
2012-02-27 14:58:47 +01:00
if ( CreatureTemplate const * cinfo = creature -> GetCreatureTemplate ())
2014-04-27 18:13:55 -04:00
const_cast < CreatureTemplate *> ( cinfo ) -> faction = factionId ;
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
// ..and DB
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_FACTION );
2011-12-31 00:32:05 +01:00
stmt -> setUInt16 ( 0 , uint16 ( factionId ));
2014-04-28 09:19:37 +02:00
stmt -> setUInt32 ( 1 , creature -> GetEntry ());
2011-12-31 00:32:05 +01:00
WorldDatabase . Execute ( stmt );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//set npcflag of creature
2020-08-16 14:11:21 +02:00
static bool HandleNpcSetFlagCommand ( ChatHandler * handler , NPCFlags npcFlags , NPCFlags2 npcFlags2 )
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2022-03-26 18:59:44 +01:00
creature -> ReplaceAllNpcFlags ( npcFlags );
creature -> ReplaceAllNpcFlags2 ( npcFlags2 );
2010-11-09 10:15:35 -05:00
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_NPCFLAG );
2011-12-31 19:06:24 +01:00
2020-08-16 14:11:21 +02:00
stmt -> setUInt64 ( 0 , uint64 ( npcFlags ) | ( uint64 ( npcFlags2 ) << 32 ));
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 1 , creature -> GetEntry ());
WorldDatabase . Execute ( stmt );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_VALUE_SAVED_REJOIN );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2012-05-09 10:07:18 -04:00
//set data of creature for testing scripting
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetDataCommand ( ChatHandler * handler , uint32 data_1 , uint32 data_2 )
2012-05-09 10:07:18 -04:00
{
Creature * creature = handler -> getSelectedCreature ();
if ( ! creature )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
creature -> AI () -> SetData ( data_1 , data_2 );
2014-09-19 03:30:02 +01:00
std :: string AIorScript = ! creature -> GetAIName (). empty () ? "AI type: " + creature -> GetAIName () : ( ! creature -> GetScriptName (). empty () ? "Script Name: " + creature -> GetScriptName () : "No AI or Script Name Set" );
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_NPC_SETDATA , creature -> GetGUID (). ToString (). c_str (), creature -> GetName (). c_str (), data_1 , data_2 , AIorScript . c_str ());
2012-05-09 10:07:18 -04:00
return true ;
}
2010-11-19 14:04:21 +01:00
//npc follow handling
2020-09-04 00:58:23 +02:00
static bool HandleNpcFollowCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2011-06-12 01:47:45 +02:00
Player * player = handler -> GetSession () -> GetPlayer ();
2011-06-30 14:24:56 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! creature )
{
handler -> PSendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
// Follow player - Using pet's default dist and angle
creature -> GetMotionMaster () -> MoveFollow ( player , PET_FOLLOW_DIST , creature -> GetFollowAngle ());
2010-11-09 10:15:35 -05:00
2012-10-24 13:29:34 +02:00
handler -> PSendSysMessage ( LANG_CREATURE_FOLLOW_YOU_NOW , creature -> GetName (). c_str ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcInfoCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
Creature * target = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! target )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2013-08-04 19:33:42 +02:00
CreatureTemplate const * cInfo = target -> GetCreatureTemplate ();
2017-04-28 02:24:04 -03:00
uint32 faction = target -> GetFaction ();
2019-06-03 20:40:34 +02:00
uint64 npcflags ;
memcpy ( & npcflags , target -> m_unitData -> NpcFlags . begin (), sizeof ( npcflags ));
2013-08-04 19:33:42 +02:00
uint32 mechanicImmuneMask = cInfo -> MechanicImmuneMask ;
2010-11-19 14:04:21 +01:00
uint32 displayid = target -> GetDisplayId ();
uint32 nativeid = target -> GetNativeDisplayId ();
2018-01-07 19:47:13 +01:00
uint32 entry = target -> GetEntry ();
2010-11-19 14:04:21 +01:00
2017-12-10 12:39:37 +01:00
int64 curRespawnDelay = target -> GetRespawnCompatibilityMode () ? target -> GetRespawnTimeEx () - GameTime :: GetGameTime () : target -> GetMap () -> GetCreatureRespawnTime ( target -> GetSpawnId ()) - GameTime :: GetGameTime ();
2017-05-07 21:48:41 +01:00
2010-11-19 14:04:21 +01:00
if ( curRespawnDelay < 0 )
curRespawnDelay = 0 ;
2020-02-23 00:31:37 +04:00
std :: string curRespawnDelayStr = secsToTimeString ( uint64 ( curRespawnDelay ), TimeFormat :: ShortText );
std :: string defRespawnDelayStr = secsToTimeString ( target -> GetRespawnDelay (), TimeFormat :: ShortText );
2010-11-19 14:04:21 +01:00
2018-01-07 19:47:13 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_CHAR , target -> GetName (). c_str (), std :: to_string ( target -> GetSpawnId ()). c_str (), target -> GetGUID (). ToString (). c_str (), entry , faction , std :: to_string ( npcflags ). c_str (), displayid , nativeid );
2017-05-07 21:48:41 +01:00
if ( target -> GetCreatureData () && target -> GetCreatureData () -> spawnGroupData -> groupId )
{
2017-08-26 13:14:25 +02:00
SpawnGroupTemplateData const * const groupData = target -> GetCreatureData () -> spawnGroupData ;
handler -> PSendSysMessage ( LANG_SPAWNINFO_GROUP_ID , groupData -> name . c_str (), groupData -> groupId , groupData -> flags , target -> GetMap () -> IsSpawnGroupActive ( groupData -> groupId ));
2017-05-07 21:48:41 +01:00
}
handler -> PSendSysMessage ( LANG_SPAWNINFO_COMPATIBILITY_MODE , target -> GetRespawnCompatibilityMode ());
2019-07-01 21:36:32 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_LEVEL , target -> GetLevel ());
2013-02-18 12:24:18 +00:00
handler -> PSendSysMessage ( LANG_NPCINFO_EQUIPMENT , target -> GetCurrentEquipmentId (), target -> GetOriginalEquipmentId ());
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_NPCINFO_HEALTH , target -> GetCreateHealth (), std :: to_string ( target -> GetMaxHealth ()). c_str (), std :: to_string ( target -> GetHealth ()). c_str ());
2017-11-26 16:37:51 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_MOVEMENT_DATA , target -> GetMovementTemplate (). ToString (). c_str ());
2013-08-05 14:51:42 +02:00
2019-06-03 20:40:34 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_UNIT_FIELD_FLAGS , * target -> m_unitData -> Flags );
2018-10-26 14:43:22 +02:00
for ( UnitFlags flag : EnumUtils :: Iterate < UnitFlags > ())
if ( target -> HasUnitFlag ( flag ))
handler -> PSendSysMessage ( "%s (0x%X)" , EnumUtils :: ToTitle ( flag ), flag );
2013-08-05 14:51:42 +02:00
2019-06-03 20:40:34 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_UNIT_FIELD_FLAGS_2 , * target -> m_unitData -> Flags2 );
2018-10-26 14:43:22 +02:00
for ( UnitFlags2 flag : EnumUtils :: Iterate < UnitFlags2 > ())
if ( target -> HasUnitFlag2 ( flag ))
handler -> PSendSysMessage ( "%s (0x%X)" , EnumUtils :: ToTitle ( flag ), flag );
2017-05-21 14:15:04 +02:00
2019-06-03 20:40:34 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_UNIT_FIELD_FLAGS_3 , * target -> m_unitData -> Flags3 );
2018-10-26 14:43:22 +02:00
for ( UnitFlags3 flag : EnumUtils :: Iterate < UnitFlags3 > ())
if ( target -> HasUnitFlag3 ( flag ))
handler -> PSendSysMessage ( "%s (0x%X)" , EnumUtils :: ToTitle ( flag ), flag );
2017-05-21 14:15:04 +02:00
2019-06-03 20:40:34 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_DYNAMIC_FLAGS , target -> GetDynamicFlags ());
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_RAWPAWNTIMES , defRespawnDelayStr . c_str (), curRespawnDelayStr . c_str ());
2023-05-29 00:01:23 +02:00
CreatureDifficulty const * creatureDifficulty = target -> GetCreatureDifficulty ();
handler -> PSendSysMessage ( LANG_NPCINFO_LOOT , creatureDifficulty -> LootID , creatureDifficulty -> PickPocketLootID , creatureDifficulty -> SkinLootID );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_DUNGEON_ID , target -> GetInstanceId ());
2015-11-20 20:28:21 +01:00
if ( CreatureData const * data = sObjectMgr -> GetCreatureData ( target -> GetSpawnId ()))
{
2018-01-06 19:56:11 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_PHASES , data -> phaseId , data -> phaseGroup );
2021-12-28 14:24:10 +02:00
PhasingHandler :: PrintToChat ( handler , target );
2015-11-20 20:28:21 +01:00
}
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_ARMOR , target -> GetArmor ());
2013-02-19 01:16:24 +00:00
handler -> PSendSysMessage ( LANG_NPCINFO_POSITION , target -> GetPositionX (), target -> GetPositionY (), target -> GetPositionZ ());
2018-02-15 09:11:28 -06:00
handler -> PSendSysMessage ( LANG_OBJECTINFO_AIINFO , target -> GetAIName (). c_str (), target -> GetScriptName (). c_str ());
2022-12-27 16:39:05 +01:00
handler -> PSendSysMessage ( LANG_OBJECTINFO_STRINGIDS , STRING_VIEW_FMT_ARG ( target -> GetStringIds ()[ 0 ]),
STRING_VIEW_FMT_ARG ( target -> GetStringIds ()[ 1 ]), STRING_VIEW_FMT_ARG ( target -> GetStringIds ()[ 2 ]));
2018-08-28 11:50:02 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_REACTSTATE , DescribeReactState ( target -> GetReactState ()));
2018-07-18 14:19:24 +02:00
if ( CreatureAI const * ai = target -> AI ())
2023-01-07 22:38:21 +01:00
handler -> PSendSysMessage ( LANG_OBJECTINFO_AITYPE , Trinity :: GetTypeName ( * ai ). c_str ());
2014-06-14 21:41:54 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_FLAGS_EXTRA , cInfo -> flags_extra );
2018-10-26 14:43:22 +02:00
for ( CreatureFlagsExtra flag : EnumUtils :: Iterate < CreatureFlagsExtra > ())
if ( cInfo -> flags_extra & flag )
handler -> PSendSysMessage ( "%s (0x%X)" , EnumUtils :: ToTitle ( flag ), flag );
2010-11-19 14:04:21 +01:00
2018-01-07 19:47:13 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_NPC_FLAGS , target -> m_unitData -> NpcFlags [ 0 ]);
2018-10-26 14:43:22 +02:00
for ( NPCFlags flag : EnumUtils :: Iterate < NPCFlags > ())
if ( target -> HasNpcFlag ( flag ))
handler -> PSendSysMessage ( "* %s (0x%X)" , EnumUtils :: ToTitle ( flag ), flag );
for ( NPCFlags2 flag : EnumUtils :: Iterate < NPCFlags2 > ())
if ( target -> HasNpcFlag2 ( flag ))
handler -> PSendSysMessage ( "* %s (0x%X)" , EnumUtils :: ToTitle ( flag ), flag );
2010-11-09 10:15:35 -05:00
2013-08-04 19:33:42 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_MECHANIC_IMMUNE , mechanicImmuneMask );
2018-10-26 14:43:22 +02:00
for ( Mechanics m : EnumUtils :: Iterate < Mechanics > ())
if ( m && ( mechanicImmuneMask & ( 1 << ( m - 1 ))))
handler -> PSendSysMessage ( "%s (0x%X)" , EnumUtils :: ToTitle ( m ), m );
2013-08-04 19:33:42 +02:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcNearCommand ( ChatHandler * handler , Optional < float > dist )
2012-12-30 17:09:55 +01:00
{
2020-09-04 00:58:23 +02:00
float distance = dist . value_or ( 10.0f );
2012-12-30 17:09:55 +01:00
uint32 count = 0 ;
Player * player = handler -> GetSession () -> GetPlayer ();
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_CREATURE_NEAREST );
2012-12-30 17:09:55 +01:00
stmt -> setFloat ( 0 , player -> GetPositionX ());
stmt -> setFloat ( 1 , player -> GetPositionY ());
stmt -> setFloat ( 2 , player -> GetPositionZ ());
stmt -> setUInt32 ( 3 , player -> GetMapId ());
stmt -> setFloat ( 4 , player -> GetPositionX ());
stmt -> setFloat ( 5 , player -> GetPositionY ());
stmt -> setFloat ( 6 , player -> GetPositionZ ());
stmt -> setFloat ( 7 , distance * distance );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
if ( result )
{
do
{
Field * fields = result -> Fetch ();
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType guid = fields [ 0 ]. GetUInt64 ();
2012-12-30 17:09:55 +01:00
uint32 entry = fields [ 1 ]. GetUInt32 ();
float x = fields [ 2 ]. GetFloat ();
float y = fields [ 3 ]. GetFloat ();
float z = fields [ 4 ]. GetFloat ();
uint16 mapId = fields [ 5 ]. GetUInt16 ();
CreatureTemplate const * creatureTemplate = sObjectMgr -> GetCreatureTemplate ( entry );
if ( ! creatureTemplate )
continue ;
2017-05-07 21:48:41 +01:00
handler -> PSendSysMessage ( LANG_CREATURE_LIST_CHAT , std :: to_string ( guid ). c_str (), std :: to_string ( guid ). c_str (), creatureTemplate -> Name . c_str (), x , y , z , mapId , "" , "" );
2012-12-30 17:09:55 +01:00
++ count ;
}
while ( result -> NextRow ());
}
handler -> PSendSysMessage ( LANG_COMMAND_NEAR_NPC_MESSAGE , distance , count );
return true ;
}
2010-11-19 14:04:21 +01:00
//move selected creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcMoveCommand ( ChatHandler * handler , Optional < CreatureSpawnId > spawnid )
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2017-05-07 21:48:41 +01:00
Player const * player = handler -> GetSession () -> GetPlayer ();
if ( ! player )
return false ;
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
if ( ! spawnid && ! creature )
return false ;
2010-11-19 14:04:21 +01:00
2020-09-04 00:58:23 +02:00
ObjectGuid :: LowType lowguid = spawnid ? * spawnid : creature -> GetSpawnId ();
2017-08-02 22:05:40 +02:00
// Attempting creature load from DB data
CreatureData const * data = sObjectMgr -> GetCreatureData ( lowguid );
if ( ! data )
{
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , std :: to_string ( lowguid ). c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2020-02-08 20:22:37 +01:00
if ( player -> GetMapId () != data -> mapId )
2010-11-19 14:04:21 +01:00
{
2017-08-02 22:05:40 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATUREATSAMEMAP , std :: to_string ( lowguid ). c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2017-08-02 22:05:40 +02:00
// update position in memory
2021-12-28 14:24:10 +02:00
sObjectMgr -> RemoveCreatureFromGrid ( data );
2017-08-02 22:05:40 +02:00
const_cast < CreatureData *> ( data ) -> spawnPoint . Relocate ( * player );
2021-12-28 14:24:10 +02:00
sObjectMgr -> AddCreatureToGrid ( data );
2011-12-31 19:06:24 +01:00
2017-08-02 22:05:40 +02:00
// update position in DB
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_POSITION );
2017-05-07 21:48:41 +01:00
stmt -> setFloat ( 0 , player -> GetPositionX ());
stmt -> setFloat ( 1 , player -> GetPositionY ());
stmt -> setFloat ( 2 , player -> GetPositionZ ());
stmt -> setFloat ( 3 , player -> GetOrientation ());
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 4 , lowguid );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2017-08-02 22:05:40 +02:00
// respawn selected creature at the new location
if ( creature )
2020-09-04 00:58:23 +02:00
creature -> DespawnOrUnsummon ( 0 s , 1 s );
2017-08-02 22:05:40 +02:00
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATUREMOVED );
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//play npc emote
2020-09-04 00:58:23 +02:00
static bool HandleNpcPlayEmoteCommand ( ChatHandler * handler , uint32 emote )
2010-11-19 14:04:21 +01:00
{
Creature * target = handler -> getSelectedCreature ();
if ( ! target )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2019-06-03 20:40:34 +02:00
target -> SetEmoteState ( Emote ( emote ));
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//set model of creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetModelCommand ( ChatHandler * handler , uint32 displayId )
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2013-06-11 18:39:51 -02:30
if ( ! creature || creature -> IsPet ())
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2019-01-01 15:00:27 +01:00
}
if ( ! sCreatureDisplayInfoStore . LookupEntry ( displayId ))
{
2020-09-04 00:58:23 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_INVALID_PARAM , Trinity :: ToString ( displayId ). c_str ());
2019-01-01 15:00:27 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2023-03-30 18:54:27 +02:00
creature -> SetDisplayId ( displayId , true );
2010-11-19 14:04:21 +01:00
2011-07-02 22:18:03 +02:00
creature -> SaveToDB ();
2010-11-19 14:04:21 +01:00
return true ;
}
/**HandleNpcSetMoveTypeCommand
* Set the movement type for an NPC.<br/>
* <br/>
* Valid movement types are:
* <ul>
* <li> stay - NPC wont move </li>
2021-12-21 19:50:12 +01:00
* <li> random - NPC will move randomly according to the wander_distance </li>
2010-11-19 14:04:21 +01:00
* <li> way - NPC will move with given waypoints set </li>
* </ul>
* additional parameter: NODEL - so no waypoints are deleted, if you
* change the movement type
*/
2020-09-10 15:19:17 +02:00
static bool HandleNpcSetMoveTypeCommand ( ChatHandler * handler , Optional < CreatureSpawnId > lowGuid , Variant < EXACT_SEQUENCE ( "stay" ), EXACT_SEQUENCE ( "random" ), EXACT_SEQUENCE ( "way" ) > type , Optional < EXACT_SEQUENCE ( "nodel" ) > nodel )
2010-11-19 14:04:21 +01:00
{
// 3 arguments:
// GUID (optional - you can also select the creature)
// stay|random|way (determines the kind of movement)
// NODEL (optional - tells the system NOT to delete any waypoints)
// this is very handy if you want to do waypoints, that are
// later switched on/off according to special events (like escort
// quests, etc)
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
bool doNotDelete = nodel . has_value ();
2010-11-09 10:15:35 -05:00
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType lowguid = UI64LIT ( 0 );
2016-01-20 23:43:13 +01:00
Creature * creature = nullptr ;
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
if ( ! lowGuid ) // case .setmovetype $move_type (with selected creature)
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
creature = handler -> getSelectedCreature ();
2013-06-11 18:39:51 -02:30
if ( ! creature || creature -> IsPet ())
2010-11-09 10:15:35 -05:00
return false ;
2015-02-25 00:13:14 +01:00
lowguid = creature -> GetSpawnId ();
2010-11-19 14:04:21 +01:00
}
else // case .setmovetype #creature_guid $move_type (with selected creature)
{
2020-09-04 00:58:23 +02:00
lowguid = * lowGuid ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( lowguid )
2017-03-11 12:29:37 +01:00
creature = handler -> GetCreatureFromPlayerMapByDbGuid ( lowguid );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// attempt check creature existence by DB data
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-09 10:15:35 -05:00
{
2010-12-22 21:25:23 +01:00
CreatureData const * data = sObjectMgr -> GetCreatureData ( lowguid );
2010-11-19 14:04:21 +01:00
if ( ! data )
2010-11-09 10:15:35 -05:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , std :: to_string ( lowguid ). c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
}
else
{
2015-02-25 00:13:14 +01:00
lowguid = creature -> GetSpawnId ();
2010-11-09 10:15:35 -05:00
}
}
2010-11-19 14:04:21 +01:00
// now lowguid is low guid really existed creature
2016-01-20 23:43:13 +01:00
// and creature point (maybe) to this creature or nullptr
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
MovementGeneratorType move_type ;
2020-09-04 00:58:23 +02:00
switch ( type . index ())
{
case 0 :
move_type = IDLE_MOTION_TYPE ;
break ;
case 1 :
move_type = RANDOM_MOTION_TYPE ;
break ;
case 2 :
move_type = WAYPOINT_MOTION_TYPE ;
break ;
default :
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// update movement type
//if (doNotDelete == false)
// WaypointMgr.DeletePath(lowguid);
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
if ( creature )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
// update movement type
if ( doNotDelete == false )
2011-07-02 22:18:03 +02:00
creature -> LoadPath ( 0 );
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
creature -> SetDefaultMovementType ( move_type );
creature -> GetMotionMaster () -> Initialize ();
2013-06-11 19:54:27 -02:30
if ( creature -> IsAlive ()) // dead creature will reset movement generator at respawn
2010-11-09 10:15:35 -05:00
{
2011-07-02 22:18:03 +02:00
creature -> setDeathState ( JUST_DIED );
creature -> Respawn ();
2010-11-09 10:15:35 -05:00
}
2011-07-02 22:18:03 +02:00
creature -> SaveToDB ();
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
if ( doNotDelete == false )
2010-11-09 10:15:35 -05:00
{
2020-09-04 00:58:23 +02:00
handler -> PSendSysMessage ( LANG_MOVE_TYPE_SET , EnumUtils :: ToTitle ( move_type ));
2010-11-19 14:04:21 +01:00
}
else
{
2020-09-04 00:58:23 +02:00
handler -> PSendSysMessage ( LANG_MOVE_TYPE_SET_NODEL , EnumUtils :: ToTitle ( move_type ));
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2014-06-05 13:05:29 -05:00
//npc phase handling
2015-03-16 07:28:49 +01:00
//change phase of creature
static bool HandleNpcSetPhaseGroup ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
2017-07-22 10:22:17 +03:00
int32 phaseGroupId = atoi ( args );
2015-03-16 07:28:49 +01:00
Creature * creature = handler -> getSelectedCreature ();
if ( ! creature || creature -> IsPet ())
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2018-01-28 11:37:20 +01:00
PhasingHandler :: ResetPhaseShift ( creature );
PhasingHandler :: AddPhaseGroup ( creature , phaseGroupId , true );
2017-07-22 10:22:17 +03:00
creature -> SetDBPhase ( - phaseGroupId );
2015-03-16 07:28:49 +01:00
creature -> SaveToDB ();
return true ;
}
//npc phase handling
//change phase of creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetPhaseCommand ( ChatHandler * handler , uint32 phaseID )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
if ( phaseID == 0 )
2016-06-05 16:43:41 +02:00
{
handler -> SendSysMessage ( LANG_PHASE_NOTFOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2015-03-16 07:28:49 +01:00
if ( ! creature || creature -> IsPet ())
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2018-01-28 11:37:20 +01:00
PhasingHandler :: ResetPhaseShift ( creature );
PhasingHandler :: AddPhase ( creature , phaseID , true );
2016-06-05 16:43:41 +02:00
creature -> SetDBPhase ( phaseID );
2010-11-09 10:15:35 -05:00
2015-03-16 07:28:49 +01:00
creature -> SaveToDB ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//set spawn dist of creature
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetWanderDistanceCommand ( ChatHandler * handler , float option )
2010-11-19 14:04:21 +01:00
{
if ( option < 0.0f )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_BAD_VALUE );
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
MovementGeneratorType mtype = IDLE_MOTION_TYPE ;
2020-09-04 00:58:23 +02:00
if ( option > 0.0f )
2010-11-19 14:04:21 +01:00
mtype = RANDOM_MOTION_TYPE ;
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType guidLow = UI64LIT ( 0 );
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
if ( creature )
2015-02-25 00:13:14 +01:00
guidLow = creature -> GetSpawnId ();
2010-11-19 14:04:21 +01:00
else
return false ;
2010-11-09 10:15:35 -05:00
2021-12-21 19:50:12 +01:00
creature -> SetWanderDistance (( float ) option );
2011-07-02 22:18:03 +02:00
creature -> SetDefaultMovementType ( mtype );
creature -> GetMotionMaster () -> Initialize ();
2013-06-11 19:54:27 -02:30
if ( creature -> IsAlive ()) // dead creature will reset movement generator at respawn
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
creature -> setDeathState ( JUST_DIED );
creature -> Respawn ();
2010-11-09 10:15:35 -05:00
}
2021-12-21 19:50:12 +01:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_WANDER_DISTANCE );
2011-12-31 19:06:24 +01:00
stmt -> setFloat ( 0 , option );
stmt -> setUInt8 ( 1 , uint8 ( mtype ));
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 2 , guidLow );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2021-12-21 19:50:12 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_WANDER_DISTANCE , option );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//spawn time handling
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetSpawnTimeCommand ( ChatHandler * handler , uint32 spawnTime )
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2017-07-22 10:22:17 +03:00
if ( ! creature )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_SPAWN_TIME_SECS );
2017-07-22 10:22:17 +03:00
stmt -> setUInt32 ( 0 , spawnTime );
2020-09-04 00:58:23 +02:00
stmt -> setUInt64 ( 1 , creature -> GetSpawnId ());
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2017-07-22 10:22:17 +03:00
creature -> SetRespawnDelay ( spawnTime );
2011-12-31 19:06:24 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_SPAWNTIME , spawnTime );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcSayCommand ( ChatHandler * handler , Tail text )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
if ( text . empty ())
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2020-09-04 00:58:23 +02:00
creature -> Say ( text , LANG_UNIVERSAL );
2010-11-19 14:04:21 +01:00
// make some emotes
2020-09-04 00:58:23 +02:00
switch ( text . back ())
2010-11-09 10:15:35 -05:00
{
2020-09-04 00:58:23 +02:00
case '?' : creature -> HandleEmoteCommand ( EMOTE_ONESHOT_QUESTION ); break ;
case '!' : creature -> HandleEmoteCommand ( EMOTE_ONESHOT_EXCLAMATION ); break ;
default : creature -> HandleEmoteCommand ( EMOTE_ONESHOT_TALK ); break ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//show text emote by creature in chat
2020-09-04 00:58:23 +02:00
static bool HandleNpcTextEmoteCommand ( ChatHandler * handler , Tail text )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
if ( text . empty ())
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
creature -> TextEmote ( text );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2018-06-03 10:06:57 -07:00
// npc unfollow handling
2020-09-04 00:58:23 +02:00
static bool HandleNpcUnFollowCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2011-06-12 01:47:45 +02:00
Player * player = handler -> GetSession () -> GetPlayer ();
2011-06-30 14:24:56 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! creature )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2018-06-03 10:06:57 -07:00
MovementGenerator * movement = creature -> GetMotionMaster () -> GetMovementGenerator ([ player ]( MovementGenerator const * a ) -> bool
2010-11-19 14:04:21 +01:00
{
2018-06-03 10:06:57 -07:00
if ( a -> GetMovementGeneratorType () == FOLLOW_MOTION_TYPE )
{
FollowMovementGenerator const * followMovement = dynamic_cast < FollowMovementGenerator const *> ( a );
return followMovement && followMovement -> GetTarget () == player ;
}
2010-11-19 14:04:21 +01:00
return false ;
2018-06-03 10:06:57 -07:00
});
2010-11-09 10:15:35 -05:00
2018-06-03 10:06:57 -07:00
if ( ! movement )
2010-11-19 14:04:21 +01:00
{
2012-10-24 13:29:34 +02:00
handler -> PSendSysMessage ( LANG_CREATURE_NOT_FOLLOW_YOU , creature -> GetName (). c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2018-06-03 10:06:57 -07:00
creature -> GetMotionMaster () -> Remove ( movement );
2012-10-24 13:29:34 +02:00
handler -> PSendSysMessage ( LANG_CREATURE_NOT_FOLLOW_YOU_NOW , creature -> GetName (). c_str ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// make npc whisper to player
2020-09-04 00:58:23 +02:00
static bool HandleNpcWhisperCommand ( ChatHandler * handler , Variant < Hyperlink < player > , std :: string_view > recv , Tail text )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
if ( text . empty ())
2010-11-19 14:04:21 +01:00
return false ;
2014-09-13 02:45:51 +01:00
2013-10-03 17:07:25 +02:00
Creature * creature = handler -> getSelectedCreature ();
2014-09-13 02:45:51 +01:00
if ( ! creature )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
2010-11-19 14:04:21 +01:00
return false ;
2014-09-13 02:45:51 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// check online security
2020-09-04 00:58:23 +02:00
Player * receiver = ObjectAccessor :: FindPlayerByName ( recv );
2014-09-14 16:54:21 +02:00
if ( handler -> HasLowerSecurity ( receiver , ObjectGuid :: Empty ))
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2014-09-13 20:41:31 +02:00
creature -> Whisper ( text , LANG_UNIVERSAL , receiver );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcYellCommand ( ChatHandler * handler , Tail text )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
if ( text . empty ())
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
creature -> Yell ( text , LANG_UNIVERSAL );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// make an emote
2011-07-02 22:18:03 +02:00
creature -> HandleEmoteCommand ( EMOTE_ONESHOT_SHOUT );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// add creature, temp only
2020-09-04 00:58:23 +02:00
static bool HandleNpcAddTempSpawnCommand ( ChatHandler * handler , Optional < std :: string_view > lootStr , CreatureEntry id )
2010-11-19 14:04:21 +01:00
{
2016-01-20 23:43:13 +01:00
bool loot = false ;
2020-09-04 00:58:23 +02:00
if ( lootStr )
{
if ( StringEqualI ( * lootStr , "loot" ))
loot = true ;
else if ( StringEqualI ( * lootStr , "noloot" ))
loot = false ;
else
return false ;
}
2010-11-09 10:15:35 -05:00
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2013-09-06 14:31:41 +02:00
if ( ! sObjectMgr -> GetCreatureTemplate ( id ))
return false ;
2020-09-04 00:58:23 +02:00
chr -> SummonCreature ( id , chr -> GetPosition (), loot ? TEMPSUMMON_CORPSE_TIMED_DESPAWN : TEMPSUMMON_CORPSE_DESPAWN , 30 s );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
//npc tame handling
2020-09-04 00:58:23 +02:00
static bool HandleNpcTameCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2012-03-16 19:40:57 +08:00
Creature * creatureTarget = handler -> getSelectedCreature ();
2013-06-11 18:39:51 -02:30
if ( ! creatureTarget || creatureTarget -> IsPet ())
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2012-03-16 19:40:57 +08:00
Player * player = handler -> GetSession () -> GetPlayer ();
2010-11-09 10:15:35 -05:00
2014-10-21 19:23:32 +02:00
if ( ! player -> GetPetGUID (). IsEmpty ())
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_YOU_ALREADY_HAVE_PET );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2012-02-27 14:58:47 +01:00
CreatureTemplate const * cInfo = creatureTarget -> GetCreatureTemplate ();
2010-11-09 10:15:35 -05:00
2023-05-29 00:01:23 +02:00
if ( ! cInfo -> IsTameable ( player -> CanTameExoticPets (), creatureTarget -> GetCreatureDifficulty ()))
2010-11-19 14:04:21 +01:00
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_CREATURE_NON_TAMEABLE , cInfo -> Entry );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
// Everything looks OK, create new pet
2011-11-28 14:34:30 -05:00
Pet * pet = player -> CreateTamedPetFrom ( creatureTarget );
2010-11-19 14:04:21 +01:00
if ( ! pet )
2010-11-09 10:15:35 -05:00
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_CREATURE_NON_TAMEABLE , cInfo -> Entry );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// place pet before player
2011-04-29 20:47:02 +02:00
float x , y , z ;
2017-03-23 00:43:04 +01:00
player -> GetClosePoint ( x , y , z , creatureTarget -> GetCombatReach (), CONTACT_DISTANCE );
2014-08-21 16:56:11 +02:00
pet -> Relocate ( x , y , z , float ( M_PI ) - player -> GetOrientation ());
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// set pet to defensive mode by default (some classes can't control controlled pets in fact).
pet -> SetReactState ( REACT_DEFENSIVE );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// calculate proper level
2019-07-01 21:36:32 +02:00
uint8 level = std :: max < uint8 > ( player -> GetLevel () - 5 , creatureTarget -> GetLevel ());
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// prepare visual effect for levelup
2019-06-03 20:40:34 +02:00
pet -> SetLevel ( level - 1 );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// add to world
2011-10-10 17:39:34 -04:00
pet -> GetMap () -> AddToMap ( pet -> ToCreature ());
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// visual effect for levelup
2019-06-03 20:40:34 +02:00
pet -> SetLevel ( level );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// caster have pet now
player -> SetMinion ( pet , true );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
pet -> SavePetToDB ( PET_SAVE_AS_CURRENT );
player -> PetSpellInitialize ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2023-01-19 21:23:06 +01:00
static bool HandleNpcEvadeCommand ( ChatHandler * handler , Optional < EvadeReason > why , Optional < EXACT_SEQUENCE ( "force" ) > force )
2016-01-20 23:43:13 +01:00
{
Creature * creatureTarget = handler -> getSelectedCreature ();
if ( ! creatureTarget || creatureTarget -> IsPet ())
{
handler -> PSendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2018-08-23 14:33:28 +02:00
if ( ! creatureTarget -> IsAIEnabled ())
2016-01-20 23:43:13 +01:00
{
handler -> PSendSysMessage ( LANG_CREATURE_NOT_AI_ENABLED );
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( force )
creatureTarget -> ClearUnitState ( UNIT_STATE_EVADE );
2023-01-19 21:23:06 +01:00
creatureTarget -> AI () -> EnterEvadeMode ( why . value_or ( EvadeReason :: Other ));
2016-01-20 23:43:13 +01:00
return true ;
}
2017-06-12 19:10:41 +02:00
static void _ShowLootEntry ( ChatHandler * handler , uint32 itemId , uint8 itemCount , bool alternateString = false )
{
ItemTemplate const * itemTemplate = sObjectMgr -> GetItemTemplate ( itemId );
char const * name = nullptr ;
2021-12-12 19:19:29 +01:00
if ( itemTemplate )
2017-06-12 19:10:41 +02:00
name = itemTemplate -> GetName ( handler -> GetSessionDbcLocale ());
if ( ! name )
name = "Unknown item" ;
handler -> PSendSysMessage ( alternateString ? LANG_COMMAND_NPC_SHOWLOOT_ENTRY_2 : LANG_COMMAND_NPC_SHOWLOOT_ENTRY ,
itemCount , ItemQualityColors [ itemTemplate ? static_cast < ItemQualities > ( itemTemplate -> GetQuality ()) : ITEM_QUALITY_POOR ], itemId , name , itemId );
}
2021-12-12 19:19:29 +01:00
2017-06-12 19:10:41 +02:00
static void _IterateNotNormalLootMap ( ChatHandler * handler , NotNormalLootItemMap const & map , std :: vector < LootItem > const & items )
{
for ( NotNormalLootItemMap :: value_type const & pair : map )
{
if ( ! pair . second )
continue ;
Player const * player = ObjectAccessor :: FindConnectedPlayer ( pair . first );
2023-01-08 21:16:53 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_NPC_SHOWLOOT_SUBLABEL , player ? player -> GetName () : Trinity :: StringFormat ( "Offline player (GUID {})" , pair . first . ToString ()), pair . second -> size ());
2017-06-12 19:10:41 +02:00
for ( auto it = pair . second -> cbegin (); it != pair . second -> cend (); ++ it )
{
2022-09-17 20:58:24 +02:00
LootItem const & item = items [ it -> LootListId ];
2017-06-12 19:10:41 +02:00
if ( ! ( it -> is_looted ) && ! item . is_looted )
_ShowLootEntry ( handler , item . itemid , item . count , true );
}
}
}
2020-09-10 15:19:17 +02:00
static bool HandleNpcShowLootCommand ( ChatHandler * handler , Optional < EXACT_SEQUENCE ( "all" ) > all )
2017-06-12 19:10:41 +02:00
{
Creature * creatureTarget = handler -> getSelectedCreature ();
if ( ! creatureTarget || creatureTarget -> IsPet ())
{
handler -> PSendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2022-09-01 20:07:58 +02:00
Loot const * loot = creatureTarget -> m_loot . get ();
2022-10-17 23:11:46 +02:00
if ( ! creatureTarget -> isDead () || ! loot || loot -> isLooted ())
2017-06-12 19:10:41 +02:00
{
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_NOT_DEAD_OR_NO_LOOT , creatureTarget -> GetName (). c_str ());
2017-06-12 19:10:41 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_NPC_SHOWLOOT_HEADER , creatureTarget -> GetName (). c_str (), creatureTarget -> GetEntry ());
2022-09-01 20:07:58 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_NPC_SHOWLOOT_MONEY , loot -> gold / GOLD , ( loot -> gold % GOLD ) / SILVER , loot -> gold % SILVER );
2017-06-12 19:10:41 +02:00
2020-09-04 00:58:23 +02:00
if ( ! all )
2017-06-12 19:10:41 +02:00
{
2022-09-01 20:07:58 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_NPC_SHOWLOOT_LABEL , "Standard items" , loot -> items . size ());
for ( LootItem const & item : loot -> items )
2017-06-12 19:10:41 +02:00
if ( ! item . is_looted )
_ShowLootEntry ( handler , item . itemid , item . count );
}
else
{
2022-09-01 20:07:58 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_NPC_SHOWLOOT_LABEL , "Standard items" , loot -> items . size ());
for ( LootItem const & item : loot -> items )
2017-06-12 19:10:41 +02:00
if ( ! item . is_looted && ! item . freeforall && item . conditions . empty ())
_ShowLootEntry ( handler , item . itemid , item . count );
2022-09-01 20:07:58 +02:00
if ( ! loot -> GetPlayerFFAItems (). empty ())
2017-06-12 19:10:41 +02:00
{
handler -> PSendSysMessage ( LANG_COMMAND_NPC_SHOWLOOT_LABEL_2 , "FFA items per allowed player" );
2022-09-01 20:07:58 +02:00
_IterateNotNormalLootMap ( handler , loot -> GetPlayerFFAItems (), loot -> items );
2017-06-12 19:10:41 +02:00
}
}
return true ;
}
2020-09-04 00:58:23 +02:00
static bool HandleNpcAddFormationCommand ( ChatHandler * handler , ObjectGuid :: LowType leaderGUID )
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2015-02-25 00:13:14 +01:00
if ( ! creature || ! creature -> GetSpawnId ())
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2015-02-25 00:13:14 +01:00
ObjectGuid :: LowType lowguid = creature -> GetSpawnId ();
2011-07-02 22:18:03 +02:00
if ( creature -> GetFormation ())
2010-11-09 10:15:35 -05:00
{
2018-01-22 01:54:15 -03:00
handler -> PSendSysMessage ( "Selected creature is already member of group " UI64FMTD , creature -> GetFormation () -> GetLeaderSpawnId ());
2010-11-09 10:15:35 -05:00
return false ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! lowguid )
return false ;
2010-11-09 10:15:35 -05:00
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2010-11-09 10:15:35 -05:00
2018-04-01 13:52:36 +02:00
float followAngle = ( creature -> GetAbsoluteAngle ( chr ) - chr -> GetOrientation ()) * 180.0f / float ( M_PI );
2018-01-22 01:54:15 -03:00
float followDist = std :: sqrt ( std :: pow ( chr -> GetPositionX () - creature -> GetPositionX (), 2.f ) + std :: pow ( chr -> GetPositionY () - creature -> GetPositionY (), 2.f ));
uint32 groupAI = 0 ;
sFormationMgr -> AddFormationMember ( lowguid , followAngle , followDist , leaderGUID , groupAI );
2011-07-02 22:18:03 +02:00
creature -> SearchFormation ();
2010-11-09 10:15:35 -05:00
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_CREATURE_FORMATION );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 0 , leaderGUID );
stmt -> setUInt64 ( 1 , lowguid );
2018-01-22 01:54:15 -03:00
stmt -> setFloat ( 2 , followAngle );
stmt -> setFloat ( 3 , followDist );
stmt -> setUInt32 ( 4 , groupAI );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2010-11-09 10:15:35 -05:00
2014-10-27 21:56:12 +00:00
handler -> PSendSysMessage ( "Creature " UI64FMTD " added to formation with leader " UI64FMTD , lowguid , leaderGUID );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-04 00:58:23 +02:00
static bool HandleNpcSetLinkCommand ( ChatHandler * handler , ObjectGuid :: LowType linkguid )
2010-11-19 14:04:21 +01:00
{
2011-07-02 22:18:03 +02:00
Creature * creature = handler -> getSelectedCreature ();
2010-11-19 14:04:21 +01:00
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2015-02-25 00:13:14 +01:00
if ( ! creature -> GetSpawnId ())
2010-11-19 14:04:21 +01:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "Selected %s isn't in creature table" , creature -> GetGUID (). ToString (). c_str ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2015-02-25 00:13:14 +01:00
if ( ! sObjectMgr -> SetCreatureLinkedRespawn ( creature -> GetSpawnId (), linkguid ))
2010-11-19 14:04:21 +01:00
{
2014-10-27 21:56:12 +00:00
handler -> PSendSysMessage ( "Selected creature can't link with guid '" UI64FMTD "'" , linkguid );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2015-02-25 00:13:14 +01:00
handler -> PSendSysMessage ( "LinkGUID '" UI64FMTD "' added to creature with DBTableGUID: '" UI64FMTD "'" , linkguid , creature -> GetSpawnId ());
2010-11-19 14:04:21 +01:00
return true ;
}
2013-03-08 21:41:30 +01:00
/// @todo NpcCommands that need to be fixed :
2020-09-04 00:58:23 +02:00
static bool HandleNpcAddWeaponCommand ( [[maybe_unused]] ChatHandler* handler, [[maybe_unused]] uint32 SlotID, [[maybe_unused]] ItemTemplate const * tmpItem )
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
/*
if (!tmpItem)
return;
2010-11-19 14:04:21 +01:00
uint64 guid = handler->GetSession()->GetPlayer()->GetSelection();
if (guid == 0)
{
handler->SendSysMessage(LANG_NO_SELECTION);
2020-09-04 00:58:23 +02:00
handler->SetSentErrorMessage(true);
return false;
2010-11-09 10:15:35 -05:00
}
2011-07-02 22:18:03 +02:00
Creature* creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), guid);
2010-11-19 14:04:21 +01:00
2011-07-02 22:18:03 +02:00
if (!creature)
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler->SendSysMessage(LANG_SELECT_CREATURE);
2020-09-04 00:58:23 +02:00
handler->SetSentErrorMessage(true);
2010-11-19 14:04:21 +01:00
return false;
}
2020-09-04 00:58:23 +02:00
switch (SlotID)
2010-11-19 14:04:21 +01:00
{
2020-09-04 00:58:23 +02:00
case 1:
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, tmpItem->ItemId);
break;
case 2:
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, tmpItem->ItemId);
break;
case 3:
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, tmpItem->ItemId);
break;
default:
handler->PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST, SlotID);
handler->SetSentErrorMessage(true);
return false;
2010-11-19 14:04:21 +01:00
}
2020-09-04 00:58:23 +02:00
handler->PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT, tmpItem->ItemID, tmpItem->Name1, SlotID);
2010-11-19 14:04:21 +01:00
*/
return true ;
}
2010-11-09 10:15:35 -05:00
};
void AddSC_npc_commandscript ()
{
new npc_commandscript ();
}
2020-09-04 00:58:23 +02:00
2020-09-10 15:19:17 +02:00
bool HandleNpcSpawnGroup ( ChatHandler * handler , std :: vector < Variant < uint32 , EXACT_SEQUENCE ( "force" ), EXACT_SEQUENCE ( "ignorerespawn" ) >> const & opts )
2020-09-04 00:58:23 +02:00
{
if ( opts . empty ())
return false ;
bool ignoreRespawn = false ;
bool force = false ;
uint32 groupId = 0 ;
// Decode arguments
for ( auto const & variant : opts )
{
switch ( variant . index ())
{
case 0 :
groupId = variant . get < uint32 > ();
break ;
case 1 :
force = true ;
break ;
case 2 :
ignoreRespawn = true ;
break ;
}
}
Player * player = handler -> GetSession () -> GetPlayer ();
std :: vector < WorldObject *> creatureList ;
if ( ! player -> GetMap () -> SpawnGroupSpawn ( groupId , ignoreRespawn , force , & creatureList ))
{
handler -> PSendSysMessage ( LANG_SPAWNGROUP_BADGROUP , groupId );
handler -> SetSentErrorMessage ( true );
return false ;
}
handler -> PSendSysMessage ( LANG_SPAWNGROUP_SPAWNCOUNT , creatureList . size ());
return true ;
}
2020-09-10 15:19:17 +02:00
bool HandleNpcDespawnGroup ( ChatHandler * handler , std :: vector < Variant < uint32 , EXACT_SEQUENCE ( "removerespawntime" ) >> const & opts )
2020-09-04 00:58:23 +02:00
{
if ( opts . empty ())
return false ;
bool deleteRespawnTimes = false ;
uint32 groupId = 0 ;
// Decode arguments
for ( auto const & variant : opts )
{
if ( variant . holds_alternative < uint32 > ())
groupId = variant . get < uint32 > ();
else
deleteRespawnTimes = true ;
}
Player * player = handler -> GetSession () -> GetPlayer ();
size_t n = 0 ;
if ( ! player -> GetMap () -> SpawnGroupDespawn ( groupId , deleteRespawnTimes , & n ))
{
handler -> PSendSysMessage ( LANG_SPAWNGROUP_BADGROUP , groupId );
handler -> SetSentErrorMessage ( true );
return false ;
}
handler -> PSendSysMessage ( "Despawned a total of %zu objects." , n );
return true ;
}