2010-11-09 10:15:35 -05:00
/*
2017-01-01 16:21:30 +01:00
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
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"
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"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2017-05-18 23:52:58 +02:00
#include "Log.h"
2017-06-04 01:00:45 +02:00
#include "Map.h"
#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"
2017-05-18 23:52:58 +02:00
#include "Player.h"
2017-05-20 00:09:37 +02:00
#include "RBAC.h"
2017-05-18 23:52:58 +02:00
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
#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
2013-09-06 14:31:41 +02:00
template < typename E , typename T = char const *>
struct EnumName
2013-01-19 19:17:31 +01:00
{
2013-09-06 14:31:41 +02:00
E Value ;
T Name ;
2013-01-19 19:17:31 +01:00
};
2013-09-06 14:31:41 +02:00
#define CREATE_NAMED_ENUM(VALUE) { VALUE, STRINGIZE(VALUE) }
2017-05-21 14:15:04 +02:00
#define NPC_FLAG_COUNT 24
2016-02-04 15:46:23 +01:00
#define FLAGS_EXTRA_COUNT 19
2013-01-19 19:17:31 +01:00
2017-05-21 14:15:04 +02:00
EnumName < NPCFlags , uint32 > const npcFlagTexts [ NPC_FLAG_COUNT ] =
2013-01-19 19:17:31 +01:00
{
{ UNIT_NPC_FLAG_AUCTIONEER , LANG_NPCINFO_AUCTIONEER },
{ UNIT_NPC_FLAG_BANKER , LANG_NPCINFO_BANKER },
{ UNIT_NPC_FLAG_BATTLEMASTER , LANG_NPCINFO_BATTLEMASTER },
{ UNIT_NPC_FLAG_FLIGHTMASTER , LANG_NPCINFO_FLIGHTMASTER },
{ UNIT_NPC_FLAG_GOSSIP , LANG_NPCINFO_GOSSIP },
{ UNIT_NPC_FLAG_GUILD_BANKER , LANG_NPCINFO_GUILD_BANKER },
{ UNIT_NPC_FLAG_INNKEEPER , LANG_NPCINFO_INNKEEPER },
{ UNIT_NPC_FLAG_PETITIONER , LANG_NPCINFO_PETITIONER },
{ UNIT_NPC_FLAG_PLAYER_VEHICLE , LANG_NPCINFO_PLAYER_VEHICLE },
{ UNIT_NPC_FLAG_QUESTGIVER , LANG_NPCINFO_QUESTGIVER },
{ UNIT_NPC_FLAG_REPAIR , LANG_NPCINFO_REPAIR },
{ UNIT_NPC_FLAG_SPELLCLICK , LANG_NPCINFO_SPELLCLICK },
{ UNIT_NPC_FLAG_SPIRITGUIDE , LANG_NPCINFO_SPIRITGUIDE },
{ UNIT_NPC_FLAG_SPIRITHEALER , LANG_NPCINFO_SPIRITHEALER },
{ UNIT_NPC_FLAG_STABLEMASTER , LANG_NPCINFO_STABLEMASTER },
{ UNIT_NPC_FLAG_TABARDDESIGNER , LANG_NPCINFO_TABARDDESIGNER },
{ UNIT_NPC_FLAG_TRAINER , LANG_NPCINFO_TRAINER },
{ UNIT_NPC_FLAG_TRAINER_CLASS , LANG_NPCINFO_TRAINER_CLASS },
{ UNIT_NPC_FLAG_TRAINER_PROFESSION , LANG_NPCINFO_TRAINER_PROFESSION },
{ UNIT_NPC_FLAG_VENDOR , LANG_NPCINFO_VENDOR },
{ UNIT_NPC_FLAG_VENDOR_AMMO , LANG_NPCINFO_VENDOR_AMMO },
{ UNIT_NPC_FLAG_VENDOR_FOOD , LANG_NPCINFO_VENDOR_FOOD },
{ UNIT_NPC_FLAG_VENDOR_POISON , LANG_NPCINFO_VENDOR_POISON },
{ UNIT_NPC_FLAG_VENDOR_REAGENT , LANG_NPCINFO_VENDOR_REAGENT }
};
2013-09-06 14:31:41 +02:00
EnumName < Mechanics > const mechanicImmunes [ MAX_MECHANIC ] =
2013-08-05 14:51:42 +02:00
{
2013-09-06 14:31:41 +02:00
CREATE_NAMED_ENUM ( MECHANIC_NONE ),
CREATE_NAMED_ENUM ( MECHANIC_CHARM ),
CREATE_NAMED_ENUM ( MECHANIC_DISORIENTED ),
CREATE_NAMED_ENUM ( MECHANIC_DISARM ),
CREATE_NAMED_ENUM ( MECHANIC_DISTRACT ),
CREATE_NAMED_ENUM ( MECHANIC_FEAR ),
CREATE_NAMED_ENUM ( MECHANIC_GRIP ),
CREATE_NAMED_ENUM ( MECHANIC_ROOT ),
CREATE_NAMED_ENUM ( MECHANIC_SLOW_ATTACK ),
CREATE_NAMED_ENUM ( MECHANIC_SILENCE ),
CREATE_NAMED_ENUM ( MECHANIC_SLEEP ),
CREATE_NAMED_ENUM ( MECHANIC_SNARE ),
CREATE_NAMED_ENUM ( MECHANIC_STUN ),
CREATE_NAMED_ENUM ( MECHANIC_FREEZE ),
CREATE_NAMED_ENUM ( MECHANIC_KNOCKOUT ),
CREATE_NAMED_ENUM ( MECHANIC_BLEED ),
CREATE_NAMED_ENUM ( MECHANIC_BANDAGE ),
CREATE_NAMED_ENUM ( MECHANIC_POLYMORPH ),
CREATE_NAMED_ENUM ( MECHANIC_BANISH ),
CREATE_NAMED_ENUM ( MECHANIC_SHIELD ),
CREATE_NAMED_ENUM ( MECHANIC_SHACKLE ),
CREATE_NAMED_ENUM ( MECHANIC_MOUNT ),
CREATE_NAMED_ENUM ( MECHANIC_INFECTED ),
CREATE_NAMED_ENUM ( MECHANIC_TURN ),
CREATE_NAMED_ENUM ( MECHANIC_HORROR ),
CREATE_NAMED_ENUM ( MECHANIC_INVULNERABILITY ),
CREATE_NAMED_ENUM ( MECHANIC_INTERRUPT ),
CREATE_NAMED_ENUM ( MECHANIC_DAZE ),
CREATE_NAMED_ENUM ( MECHANIC_DISCOVERY ),
CREATE_NAMED_ENUM ( MECHANIC_IMMUNE_SHIELD ),
CREATE_NAMED_ENUM ( MECHANIC_SAPPED ),
2013-09-06 21:55:19 +02:00
CREATE_NAMED_ENUM ( MECHANIC_ENRAGED ),
CREATE_NAMED_ENUM ( MECHANIC_WOUNDED )
2013-08-05 14:51:42 +02:00
};
2013-09-06 14:31:41 +02:00
EnumName < UnitFlags > const unitFlags [ MAX_UNIT_FLAGS ] =
2013-08-05 14:51:42 +02:00
{
2013-09-06 14:31:41 +02:00
CREATE_NAMED_ENUM ( UNIT_FLAG_SERVER_CONTROLLED ),
CREATE_NAMED_ENUM ( UNIT_FLAG_NON_ATTACKABLE ),
2016-05-27 14:45:06 +02:00
CREATE_NAMED_ENUM ( UNIT_FLAG_REMOVE_CLIENT_CONTROL ),
2013-09-06 14:31:41 +02:00
CREATE_NAMED_ENUM ( UNIT_FLAG_PVP_ATTACKABLE ),
CREATE_NAMED_ENUM ( UNIT_FLAG_RENAME ),
CREATE_NAMED_ENUM ( UNIT_FLAG_PREPARATION ),
CREATE_NAMED_ENUM ( UNIT_FLAG_UNK_6 ),
CREATE_NAMED_ENUM ( UNIT_FLAG_NOT_ATTACKABLE_1 ),
CREATE_NAMED_ENUM ( UNIT_FLAG_IMMUNE_TO_PC ),
CREATE_NAMED_ENUM ( UNIT_FLAG_IMMUNE_TO_NPC ),
CREATE_NAMED_ENUM ( UNIT_FLAG_LOOTING ),
CREATE_NAMED_ENUM ( UNIT_FLAG_PET_IN_COMBAT ),
CREATE_NAMED_ENUM ( UNIT_FLAG_PVP ),
CREATE_NAMED_ENUM ( UNIT_FLAG_SILENCED ),
2016-05-27 14:45:06 +02:00
CREATE_NAMED_ENUM ( UNIT_FLAG_CANNOT_SWIM ),
2013-09-06 14:31:41 +02:00
CREATE_NAMED_ENUM ( UNIT_FLAG_UNK_15 ),
CREATE_NAMED_ENUM ( UNIT_FLAG_UNK_16 ),
CREATE_NAMED_ENUM ( UNIT_FLAG_PACIFIED ),
CREATE_NAMED_ENUM ( UNIT_FLAG_STUNNED ),
CREATE_NAMED_ENUM ( UNIT_FLAG_IN_COMBAT ),
CREATE_NAMED_ENUM ( UNIT_FLAG_TAXI_FLIGHT ),
CREATE_NAMED_ENUM ( UNIT_FLAG_DISARMED ),
CREATE_NAMED_ENUM ( UNIT_FLAG_CONFUSED ),
CREATE_NAMED_ENUM ( UNIT_FLAG_FLEEING ),
CREATE_NAMED_ENUM ( UNIT_FLAG_PLAYER_CONTROLLED ),
CREATE_NAMED_ENUM ( UNIT_FLAG_NOT_SELECTABLE ),
CREATE_NAMED_ENUM ( UNIT_FLAG_SKINNABLE ),
CREATE_NAMED_ENUM ( UNIT_FLAG_MOUNT ),
CREATE_NAMED_ENUM ( UNIT_FLAG_UNK_28 ),
CREATE_NAMED_ENUM ( UNIT_FLAG_UNK_29 ),
CREATE_NAMED_ENUM ( UNIT_FLAG_SHEATHE ),
CREATE_NAMED_ENUM ( UNIT_FLAG_UNK_31 )
2013-08-05 14:51:42 +02:00
};
2017-05-21 14:15:04 +02:00
EnumName < UnitFlags2 > const unitFlags2 [ MAX_UNIT_FLAGS_2 ] =
{
CREATE_NAMED_ENUM ( UNIT_FLAG2_FEIGN_DEATH ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_UNK1 ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_IGNORE_REPUTATION ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_COMPREHEND_LANG ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_MIRROR_IMAGE ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_INSTANTLY_APPEAR_MODEL ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_FORCE_MOVEMENT ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_DISARM_OFFHAND ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_DISABLE_PRED_STATS ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_DISARM_RANGED ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_REGENERATE_POWER ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_RESTRICT_PARTY_INTERACTION ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_PREVENT_SPELL_CLICK ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_ALLOW_ENEMY_INTERACT ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_DISABLE_TURN ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_UNK2 ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_PLAY_DEATH_ANIM ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_ALLOW_CHEAT_SPELLS ),
CREATE_NAMED_ENUM ( UNIT_FLAG2_NO_ACTIONS )
};
EnumName < UnitFlags3 > const unitFlags3 [ MAX_UNIT_FLAGS_3 ] =
{
CREATE_NAMED_ENUM ( UNIT_FLAG3_UNK1 )
};
2014-06-14 21:41:54 +02:00
EnumName < CreatureFlagsExtra > const flagsExtra [ FLAGS_EXTRA_COUNT ] =
{
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_INSTANCE_BIND ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_CIVILIAN ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_PARRY ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_BLOCK ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_CRUSH ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_XP_AT_KILL ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_TRIGGER ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_TAUNT ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_WORLDEVENT ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_GUARD ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_CRIT ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_SKILLGAIN ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_TAUNT_DIMINISH ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_ALL_DIMINISH ),
2016-01-13 20:03:17 +01:00
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_NO_PLAYER_DAMAGE_REQ ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_DUNGEON_BOSS ),
2016-02-04 15:46:23 +01:00
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_IGNORE_PATHFINDING ),
CREATE_NAMED_ENUM ( CREATURE_FLAG_EXTRA_IMMUNITY_KNOCKBACK )
2014-06-14 21:41:54 +02: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
2015-10-22 20:26:56 +02:00
std :: vector < ChatCommand > GetCommands () const override
2010-11-19 14:04:21 +01:00
{
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > npcAddCommandTable =
{
{ "formation" , rbac :: RBAC_PERM_COMMAND_NPC_ADD_FORMATION , false , & HandleNpcAddFormationCommand , "" },
{ "item" , rbac :: RBAC_PERM_COMMAND_NPC_ADD_ITEM , false , & HandleNpcAddVendorItemCommand , "" },
{ "move" , rbac :: RBAC_PERM_COMMAND_NPC_ADD_MOVE , false , & HandleNpcAddMoveCommand , "" },
{ "temp" , rbac :: RBAC_PERM_COMMAND_NPC_ADD_TEMP , false , & HandleNpcAddTempSpawnCommand , "" },
//{ "weapon", rbac::RBAC_PERM_COMMAND_NPC_ADD_WEAPON, false, &HandleNpcAddWeaponCommand, "" },
{ "" , rbac :: RBAC_PERM_COMMAND_NPC_ADD , false , & HandleNpcAddCommand , "" },
2010-11-19 14:04:21 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > npcDeleteCommandTable =
2010-11-19 14:04:21 +01:00
{
2015-10-22 20:26:56 +02:00
{ "item" , rbac :: RBAC_PERM_COMMAND_NPC_DELETE_ITEM , false , & HandleNpcDeleteVendorItemCommand , "" },
{ "" , rbac :: RBAC_PERM_COMMAND_NPC_DELETE , false , & HandleNpcDeleteCommand , "" },
2010-11-19 14:04:21 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > npcFollowCommandTable =
2010-11-19 14:04:21 +01:00
{
2015-10-22 20:26:56 +02:00
{ "stop" , rbac :: RBAC_PERM_COMMAND_NPC_FOLLOW_STOP , false , & HandleNpcUnFollowCommand , "" },
{ "" , rbac :: RBAC_PERM_COMMAND_NPC_FOLLOW , false , & HandleNpcFollowCommand , "" },
2010-11-19 14:04:21 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > npcSetCommandTable =
{
{ "allowmove" , rbac :: RBAC_PERM_COMMAND_NPC_SET_ALLOWMOVE , false , & HandleNpcSetAllowMovementCommand , "" },
{ "entry" , rbac :: RBAC_PERM_COMMAND_NPC_SET_ENTRY , false , & HandleNpcSetEntryCommand , "" },
{ "factionid" , rbac :: RBAC_PERM_COMMAND_NPC_SET_FACTIONID , false , & HandleNpcSetFactionIdCommand , "" },
{ "flag" , rbac :: RBAC_PERM_COMMAND_NPC_SET_FLAG , false , & HandleNpcSetFlagCommand , "" },
{ "level" , rbac :: RBAC_PERM_COMMAND_NPC_SET_LEVEL , false , & HandleNpcSetLevelCommand , "" },
{ "link" , rbac :: RBAC_PERM_COMMAND_NPC_SET_LINK , false , & HandleNpcSetLinkCommand , "" },
{ "model" , rbac :: RBAC_PERM_COMMAND_NPC_SET_MODEL , false , & HandleNpcSetModelCommand , "" },
{ "movetype" , rbac :: RBAC_PERM_COMMAND_NPC_SET_MOVETYPE , false , & HandleNpcSetMoveTypeCommand , "" },
{ "phase" , rbac :: RBAC_PERM_COMMAND_NPC_SET_PHASE , false , & HandleNpcSetPhaseCommand , "" },
{ "phasegroup" , rbac :: RBAC_PERM_COMMAND_NPC_SET_PHASE , false , & HandleNpcSetPhaseGroup , "" },
{ "spawndist" , rbac :: RBAC_PERM_COMMAND_NPC_SET_SPAWNDIST , false , & HandleNpcSetSpawnDistCommand , "" },
{ "spawntime" , rbac :: RBAC_PERM_COMMAND_NPC_SET_SPAWNTIME , false , & HandleNpcSetSpawnTimeCommand , "" },
{ "data" , rbac :: RBAC_PERM_COMMAND_NPC_SET_DATA , false , & HandleNpcSetDataCommand , "" },
2010-11-19 14:04:21 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > npcCommandTable =
{
{ "info" , rbac :: RBAC_PERM_COMMAND_NPC_INFO , false , & HandleNpcInfoCommand , "" },
{ "near" , rbac :: RBAC_PERM_COMMAND_NPC_NEAR , false , & HandleNpcNearCommand , "" },
{ "move" , rbac :: RBAC_PERM_COMMAND_NPC_MOVE , false , & HandleNpcMoveCommand , "" },
{ "playemote" , rbac :: RBAC_PERM_COMMAND_NPC_PLAYEMOTE , false , & HandleNpcPlayEmoteCommand , "" },
{ "say" , rbac :: RBAC_PERM_COMMAND_NPC_SAY , false , & HandleNpcSayCommand , "" },
{ "textemote" , rbac :: RBAC_PERM_COMMAND_NPC_TEXTEMOTE , false , & HandleNpcTextEmoteCommand , "" },
{ "whisper" , rbac :: RBAC_PERM_COMMAND_NPC_WHISPER , false , & HandleNpcWhisperCommand , "" },
{ "yell" , rbac :: RBAC_PERM_COMMAND_NPC_YELL , false , & HandleNpcYellCommand , "" },
{ "tame" , rbac :: RBAC_PERM_COMMAND_NPC_TAME , false , & HandleNpcTameCommand , "" },
2016-01-20 23:43:13 +01:00
{ "add" , rbac :: RBAC_PERM_COMMAND_NPC_ADD , false , nullptr , "" , npcAddCommandTable },
{ "delete" , rbac :: RBAC_PERM_COMMAND_NPC_DELETE , false , nullptr , "" , npcDeleteCommandTable },
{ "follow" , rbac :: RBAC_PERM_COMMAND_NPC_FOLLOW , false , nullptr , "" , npcFollowCommandTable },
{ "set" , rbac :: RBAC_PERM_COMMAND_NPC_SET , false , nullptr , "" , npcSetCommandTable },
{ "evade" , rbac :: RBAC_PERM_COMMAND_NPC_EVADE , false , & HandleNpcEvadeCommand , "" },
2010-11-19 14:04:21 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > commandTable =
2010-11-19 14:04:21 +01:00
{
2016-01-20 23:43:13 +01:00
{ "npc" , rbac :: RBAC_PERM_COMMAND_NPC , false , nullptr , "" , npcCommandTable },
2010-11-19 14:04:21 +01:00
};
return commandTable ;
}
//add spawn of creature
2012-10-24 13:29:34 +02:00
static bool HandleNpcAddCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2012-03-16 19:40:57 +08:00
2011-04-29 20:47:02 +02:00
char * charID = handler -> extractKeyFromLink (( char * ) args , "Hcreature_entry" );
2010-11-19 14:04:21 +01:00
if ( ! charID )
return false ;
2017-03-11 12:29:37 +01:00
uint32 id = atoul ( charID );
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 ();
2010-11-19 14:04:21 +01:00
float x = chr -> GetPositionX ();
float y = chr -> GetPositionY ();
float z = chr -> GetPositionZ ();
float o = chr -> GetOrientation ();
2011-09-15 14:08:17 +02:00
Map * map = chr -> GetMap ();
2010-11-19 14:04:21 +01:00
2013-10-16 18:37:29 +02:00
if ( Transport * trans = chr -> GetTransport ())
2010-11-19 14:04:21 +01:00
{
2015-02-25 00:13:14 +01:00
ObjectGuid :: LowType guid = map -> GenerateLowGuid < HighGuid :: Creature > ();
2013-10-16 18:37:29 +02:00
CreatureData & data = sObjectMgr -> NewOrExistCreatureData ( guid );
data . id = id ;
2014-06-01 22:27:29 -05:00
data . phaseMask = chr -> GetPhaseMask ();
2013-10-16 18:37:29 +02:00
data . posX = chr -> GetTransOffsetX ();
data . posY = chr -> GetTransOffsetY ();
data . posZ = chr -> GetTransOffsetZ ();
data . orientation = chr -> GetTransOffsetO ();
2012-03-19 16:48:08 +01:00
2013-10-16 18:37:29 +02:00
Creature * creature = trans -> CreateNPCPassenger ( guid , & data );
2012-03-19 16:48:08 +01:00
2016-05-30 23:49:35 +02:00
creature -> SaveToDB ( trans -> GetGOInfo () -> moTransport . SpawnMap , 1 << map -> GetSpawnMode (), chr -> GetPhaseMask ());
2010-11-19 14:04:21 +01:00
2013-10-16 18:37:29 +02:00
sObjectMgr -> AddCreatureToGrid ( guid , & data );
2010-11-19 14:04:21 +01:00
return true ;
2010-11-09 10:15:35 -05:00
}
2012-03-16 19:40:57 +08:00
Creature * creature = new Creature ();
2015-02-25 00:13:14 +01:00
if ( ! creature -> Create ( map -> GenerateLowGuid < HighGuid :: Creature > (), map , chr -> GetPhaseMask (), id , x , y , z , o ))
2010-11-09 10:15:35 -05:00
{
2011-07-02 22:18:03 +02:00
delete creature ;
2010-11-19 14:04:21 +01:00
return false ;
}
2010-11-09 10:15:35 -05:00
2014-06-01 22:27:29 -05:00
creature -> SaveToDB ( map -> GetId (), ( 1 << map -> GetSpawnMode ()), chr -> GetPhaseMask ());
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 ;
creature = new Creature ();
2011-11-28 14:05:25 -05:00
if ( ! creature -> LoadCreatureFromDB ( db_guid , map ))
{
delete creature ;
return false ;
}
2010-11-09 10:15:35 -05:00
2010-12-22 21:25:23 +01:00
sObjectMgr -> AddCreatureToGrid ( db_guid , 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
2011-10-31 09:17:45 +01:00
static bool HandleNpcAddVendorItemCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2012-08-14 18:11:06 +01:00
const uint8 type = 1 ; // FIXME: make type (1 item, 2 currency) an argument
2012-03-14 18:51:51 +01:00
char * pitem = handler -> extractKeyFromLink (( char * ) args , "Hitem" );
if ( ! pitem )
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-03-14 18:51:51 +01:00
int32 item_int = atol ( pitem );
2011-10-31 00:02:32 +01:00
if ( item_int <= 0 )
2011-10-31 09:17:45 +01:00
return false ;
2011-10-31 00:02:32 +01:00
uint32 itemId = item_int ;
2010-11-09 10:15:35 -05:00
2016-01-20 23:43:13 +01:00
char * fmaxcount = strtok ( nullptr , " " ); //add maxcount, default: 0
2010-11-19 14:04:21 +01:00
uint32 maxcount = 0 ;
if ( fmaxcount )
2014-11-26 02:03:30 +00:00
maxcount = atoul ( fmaxcount );
2010-11-09 10:15:35 -05:00
2016-01-20 23:43:13 +01:00
char * fincrtime = strtok ( nullptr , " " ); //add incrtime, default: 0
2010-11-19 14:04:21 +01:00
uint32 incrtime = 0 ;
if ( fincrtime )
2014-11-26 02:03:30 +00:00
incrtime = atoul ( fincrtime );
2010-11-09 10:15:35 -05:00
2016-01-20 23:43:13 +01:00
char * fextendedcost = strtok ( nullptr , " " ); //add ExtendedCost, default: 0
2014-11-26 02:03:30 +00:00
uint32 extendedcost = fextendedcost ? atoul ( fextendedcost ) : 0 ;
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
}
2013-05-19 11:15:54 +02:00
uint32 vendor_entry = vendor -> GetEntry ();
2010-11-19 14:04:21 +01:00
2012-08-14 18:11:06 +01:00
if ( ! sObjectMgr -> IsVendorItemValid ( vendor_entry , itemId , maxcount , incrtime , extendedcost , type , 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
2012-11-16 23:23:38 +02:00
sObjectMgr -> AddVendorItem ( vendor_entry , itemId , maxcount , incrtime , extendedcost , type );
2010-11-09 10:15:35 -05:00
2011-04-28 22:42:33 +02:00
ItemTemplate const * itemTemplate = sObjectMgr -> GetItemTemplate ( itemId );
2010-11-09 10:15:35 -05:00
2014-12-21 13:35:43 +01:00
handler -> PSendSysMessage ( LANG_ITEM_ADDED_TO_LIST , itemId , itemTemplate -> 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcAddMoveCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
char * guidStr = strtok (( char * ) args , " " );
2016-01-20 23:43:13 +01:00
char * waitStr = strtok (( char * ) nullptr , " " );
2010-11-19 14:04:21 +01:00
2017-03-11 12:29:37 +01:00
ObjectGuid :: LowType lowGuid = atoull ( guidStr );
2010-11-09 10:15:35 -05:00
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
{
2015-05-31 00:01:31 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , lowGuid );
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
int wait = waitStr ? atoi ( waitStr ) : 0 ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( wait < 0 )
wait = 0 ;
2010-11-09 10:15:35 -05:00
2011-12-31 00:32:05 +01:00
// Update movement type
2011-12-31 19:06:24 +01:00
PreparedStatement * 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetAllowMovementCommand ( ChatHandler * handler , char const * /*args*/ )
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetEntryCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
uint32 newEntryNum = atoul ( args );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetLevelCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
uint8 lvl = ( uint8 ) atoi ( args );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcDeleteCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
2016-01-20 23:43:13 +01:00
Creature * unit = nullptr ;
2010-11-19 14:04:21 +01:00
if ( * args )
{
// number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
2011-04-29 20:47:02 +02:00
char * cId = handler -> extractKeyFromLink (( char * ) args , "Hcreature" );
2010-11-19 14:04:21 +01:00
if ( ! cId )
2010-11-09 10:15:35 -05:00
return false ;
2017-03-11 12:29:37 +01:00
ObjectGuid :: LowType lowguid = atoull ( cId );
2010-11-19 14:04:21 +01:00
if ( ! lowguid )
return false ;
2017-03-11 12:29:37 +01:00
unit = handler -> GetCreatureFromPlayerMapByDbGuid ( lowguid );
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
else
unit = handler -> getSelectedCreature ();
2010-11-09 10:15:35 -05:00
2013-06-11 19:54:27 -02:30
if ( ! unit || unit -> IsPet () || unit -> IsTotem ())
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
2010-11-19 14:04:21 +01:00
// Delete the creature
unit -> CombatStop ();
unit -> DeleteFromDB ();
unit -> AddObjectToRemoveList ();
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_COMMAND_DELCREATMESSAGE );
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
//del item from vendor list
2012-10-24 13:29:34 +02:00
static bool HandleNpcDeleteVendorItemCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
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
2012-03-14 18:51:51 +01:00
char * pitem = handler -> extractKeyFromLink (( char * ) args , "Hitem" );
if ( ! pitem )
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
}
2014-11-26 02:03:30 +00:00
uint32 itemId = atoul ( pitem );
2010-11-09 10:15:35 -05:00
2012-08-14 18:11:06 +01:00
const uint8 type = 1 ; // FIXME: make type (1 item, 2 currency) an argument
if ( ! sObjectMgr -> RemoveVendorItem ( vendor -> GetEntry (), itemId , type ))
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
2011-04-28 22:42:33 +02:00
ItemTemplate const * itemTemplate = sObjectMgr -> GetItemTemplate ( itemId );
2010-11-09 10:15:35 -05:00
2014-12-21 13:35:43 +01:00
handler -> PSendSysMessage ( LANG_ITEM_DELETED_FROM_LIST , itemId , itemTemplate -> 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetFactionIdCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
uint32 factionId = atoul ( args );
2010-11-09 10:15:35 -05:00
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
2011-07-02 22:18:03 +02: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
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_FACTION );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetFlagCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
uint64 npcFlags = atoull ( args );
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-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
2015-05-04 12:39:36 +02:00
creature -> SetUInt64Value ( UNIT_NPC_FLAGS , npcFlags );
2010-11-09 10:15:35 -05:00
2011-12-31 19:06:24 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_NPCFLAG );
2015-05-04 12:39:36 +02:00
stmt -> setUInt64 ( 0 , npcFlags );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetDataCommand ( ChatHandler * handler , char const * args )
2012-05-09 10:07:18 -04:00
{
if ( !* args )
return false ;
char * arg1 = strtok (( char * ) args , " " );
2016-01-20 23:43:13 +01:00
char * arg2 = strtok (( char * ) nullptr , "" );
2012-05-09 10:07:18 -04:00
if ( ! arg1 || ! arg2 )
return false ;
uint32 data_1 = ( uint32 ) atoi ( arg1 );
uint32 data_2 = ( uint32 ) atoi ( arg2 );
if ( ! data_1 || ! data_2 )
return false ;
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcFollowCommand ( ChatHandler * handler , char const * /*args*/ )
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcInfoCommand ( ChatHandler * handler , char const * /*args*/ )
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 ();
2010-11-19 14:04:21 +01:00
uint32 faction = target -> getFaction ();
2015-05-04 12:39:36 +02:00
uint64 npcflags = target -> GetUInt64Value ( UNIT_NPC_FLAGS );
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 ();
uint32 Entry = target -> GetEntry ();
int64 curRespawnDelay = target -> GetRespawnTimeEx () - time ( NULL );
if ( curRespawnDelay < 0 )
curRespawnDelay = 0 ;
2011-04-29 20:47:02 +02:00
std :: string curRespawnDelayStr = secsToTimeString ( uint64 ( curRespawnDelay ), true );
std :: string defRespawnDelayStr = secsToTimeString ( target -> GetRespawnDelay (), true );
2010-11-19 14:04:21 +01:00
2015-02-25 00:13:14 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_CHAR , target -> GetSpawnId (), target -> GetGUID (). ToString (). c_str (), faction , npcflags , Entry , displayid , nativeid );
2010-11-19 14:04:21 +01: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 ());
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_HEALTH , target -> GetCreateHealth (), target -> GetMaxHealth (), target -> GetHealth ());
2014-05-23 20:51:22 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_INHABIT_TYPE , cInfo -> InhabitType );
2013-08-05 14:51:42 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_UNIT_FIELD_FLAGS , target -> GetUInt32Value ( UNIT_FIELD_FLAGS ));
2013-08-06 00:40:14 +02:00
for ( uint8 i = 0 ; i < MAX_UNIT_FLAGS ; ++ i )
2013-09-06 14:31:41 +02:00
if ( target -> GetUInt32Value ( UNIT_FIELD_FLAGS ) & unitFlags [ i ]. Value )
handler -> PSendSysMessage ( "%s (0x%X)" , unitFlags [ i ]. Name , unitFlags [ i ]. Value );
2013-08-05 14:51:42 +02:00
2017-05-21 14:15:04 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_UNIT_FIELD_FLAGS_2 , target -> GetUInt32Value ( UNIT_FIELD_FLAGS_2 ));
for ( uint8 i = 0 ; i < MAX_UNIT_FLAGS_2 ; ++ i )
if ( target -> GetUInt32Value ( UNIT_FIELD_FLAGS_2 ) & unitFlags2 [ i ]. Value )
handler -> PSendSysMessage ( "%s (0x%X)" , unitFlags2 [ i ]. Name , unitFlags2 [ i ]. Value );
handler -> PSendSysMessage ( LANG_NPCINFO_UNIT_FIELD_FLAGS_3 , target -> GetUInt32Value ( UNIT_FIELD_FLAGS_3 ));
for ( uint8 i = 0 ; i < MAX_UNIT_FLAGS_3 ; ++ i )
if ( target -> GetUInt32Value ( UNIT_FIELD_FLAGS_3 ) & unitFlags3 [ i ]. Value )
handler -> PSendSysMessage ( "%s (0x%X)" , unitFlags3 [ i ]. Name , unitFlags3 [ i ]. Value );
handler -> PSendSysMessage ( LANG_NPCINFO_DYNAMIC_FLAGS , target -> GetUInt32Value ( OBJECT_DYNAMIC_FLAGS ));
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_RAWPAWNTIMES , defRespawnDelayStr . c_str (), curRespawnDelayStr . c_str ());
handler -> PSendSysMessage ( LANG_NPCINFO_LOOT , cInfo -> lootid , cInfo -> pickpocketLootId , cInfo -> 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 ()))
{
handler -> PSendSysMessage ( LANG_NPCINFO_PHASES , data -> phaseid , data -> phaseGroup );
if ( data -> phaseGroup )
{
std :: set < uint32 > _phases = target -> GetPhases ();
if ( ! _phases . empty ())
{
handler -> PSendSysMessage ( LANG_NPCINFO_PHASE_IDS );
for ( uint32 phaseId : _phases )
handler -> PSendSysMessage ( "%u" , phaseId );
}
}
}
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 ());
2011-12-18 22:45:23 +01:00
handler -> PSendSysMessage ( LANG_NPCINFO_AIINFO , target -> GetAIName (). c_str (), target -> GetScriptName (). c_str ());
2014-06-14 21:41:54 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_FLAGS_EXTRA , cInfo -> flags_extra );
for ( uint8 i = 0 ; i < FLAGS_EXTRA_COUNT ; ++ i )
if ( cInfo -> flags_extra & flagsExtra [ i ]. Value )
handler -> PSendSysMessage ( "%s (0x%X)" , flagsExtra [ i ]. Name , flagsExtra [ i ]. Value );
2010-11-19 14:04:21 +01:00
2017-05-21 14:15:04 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_NPC_FLAGS , npcflags );
for ( uint8 i = 0 ; i < NPC_FLAG_COUNT ; i ++ )
2013-09-06 14:31:41 +02:00
if ( npcflags & npcFlagTexts [ i ]. Value )
2014-01-06 13:53:29 +01:00
handler -> PSendSysMessage ( npcFlagTexts [ i ]. Name , npcFlagTexts [ i ]. Value );
2010-11-09 10:15:35 -05:00
2013-08-04 19:33:42 +02:00
handler -> PSendSysMessage ( LANG_NPCINFO_MECHANIC_IMMUNE , mechanicImmuneMask );
2014-09-14 20:58:05 +02:00
for ( uint8 i = 1 ; i < MAX_MECHANIC ; ++ i )
if ( mechanicImmuneMask & ( 1 << ( mechanicImmunes [ i ]. Value - 1 )))
2013-09-06 14:31:41 +02:00
handler -> PSendSysMessage ( "%s (0x%X)" , mechanicImmunes [ i ]. Name , mechanicImmunes [ i ]. Value );
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
2012-12-30 17:09:55 +01:00
static bool HandleNpcNearCommand ( ChatHandler * handler , char const * args )
{
float distance = ( !* args ) ? 10.0f : float (( atof ( args )));
uint32 count = 0 ;
Player * player = handler -> GetSession () -> GetPlayer ();
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_CREATURE_NEAREST );
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 ;
handler -> PSendSysMessage ( LANG_CREATURE_LIST_CHAT , guid , guid , creatureTemplate -> Name . c_str (), x , y , z , mapId );
++ 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcMoveCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType lowguid = UI64LIT ( 0 );
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-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
// number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
2011-04-29 20:47:02 +02:00
char * cId = handler -> extractKeyFromLink (( char * ) args , "Hcreature" );
2010-11-19 14:04:21 +01:00
if ( ! cId )
return false ;
2017-03-11 12:29:37 +01:00
lowguid = atoull ( cId );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// Attempting creature load from 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
{
2015-05-31 00:01:31 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , lowguid );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2015-05-31 00:01:31 +02:00
uint32 map_id = data -> mapid ;
if ( handler -> GetSession () -> GetPlayer () -> GetMapId () != map_id )
2010-11-09 10:15:35 -05:00
{
2015-05-31 00:01:31 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATUREATSAMEMAP , lowguid );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
}
else
{
2015-02-25 00:13:14 +01:00
lowguid = creature -> GetSpawnId ();
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
float x = handler -> GetSession () -> GetPlayer () -> GetPositionX ();
float y = handler -> GetSession () -> GetPlayer () -> GetPositionY ();
float z = handler -> GetSession () -> GetPlayer () -> GetPositionZ ();
float o = handler -> GetSession () -> GetPlayer () -> GetOrientation ();
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
{
2015-02-25 00:13:14 +01:00
if ( CreatureData const * data = sObjectMgr -> GetCreatureData ( creature -> GetSpawnId ()))
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
const_cast < CreatureData *> ( data ) -> posX = x ;
const_cast < CreatureData *> ( data ) -> posY = y ;
const_cast < CreatureData *> ( data ) -> posZ = z ;
const_cast < CreatureData *> ( data ) -> orientation = o ;
2010-11-09 10:15:35 -05:00
}
2011-10-10 17:08:01 -04:00
creature -> SetPosition ( x , y , z , o );
2011-07-02 22:18:03 +02:00
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
}
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-12-31 19:06:24 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_POSITION );
stmt -> setFloat ( 0 , x );
stmt -> setFloat ( 1 , y );
stmt -> setFloat ( 2 , z );
stmt -> setFloat ( 3 , o );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 4 , lowguid );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcPlayEmoteCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
uint32 emote = atoi (( char * ) args );
2010-11-09 10:15:35 -05:00
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
}
2011-04-29 20:47:02 +02:00
target -> SetUInt32Value ( UNIT_NPC_EMOTESTATE , 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetModelCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
uint32 displayId = atoul ( args );
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
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 ;
2010-11-09 10:15:35 -05:00
}
2011-07-02 22:18:03 +02:00
creature -> SetDisplayId ( displayId );
creature -> SetNativeDisplayId ( displayId );
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>
* <li> random - NPC will move randomly according to the spawndist </li>
* <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
*/
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetMoveTypeCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
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)
char * guid_str = strtok (( char * ) args , " " );
2016-01-20 23:43:13 +01:00
char * type_str = strtok (( char * ) nullptr , " " );
char * dontdel_str = strtok (( char * ) nullptr , " " );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
bool doNotDelete = false ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! guid_str )
return false ;
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
2010-11-19 14:04:21 +01:00
if ( dontdel_str )
{
2013-11-08 10:50:51 +01:00
//TC_LOG_ERROR("misc", "DEBUG: All 3 params are set");
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// All 3 params are set
// GUID
// type
// doNotDEL
if ( stricmp ( dontdel_str , "NODEL" ) == 0 )
2010-11-09 10:15:35 -05:00
{
2013-11-08 10:50:51 +01:00
//TC_LOG_ERROR("misc", "DEBUG: doNotDelete = true;");
2010-11-19 14:04:21 +01:00
doNotDelete = true ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
}
else
{
// Only 2 params - but maybe NODEL is set
if ( type_str )
2010-11-09 10:15:35 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "misc" , "DEBUG: Only 2 params " );
2010-11-19 14:04:21 +01:00
if ( stricmp ( type_str , "NODEL" ) == 0 )
2010-11-09 10:15:35 -05:00
{
2013-11-08 10:50:51 +01:00
//TC_LOG_ERROR("misc", "DEBUG: type_str, NODEL ");
2010-11-19 14:04:21 +01:00
doNotDelete = true ;
2016-01-20 23:43:13 +01:00
type_str = nullptr ;
2010-11-09 10:15:35 -05: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
if ( ! type_str ) // case .setmovetype $move_type (with selected creature)
{
type_str = guid_str ;
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)
{
2017-03-11 12:29:37 +01:00
lowguid = atoull ( guid_str );
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
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_COMMAND_CREATGUIDNOTFOUND , lowguid );
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 ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
std :: string type = type_str ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( type == "stay" )
move_type = IDLE_MOTION_TYPE ;
else if ( type == "random" )
move_type = RANDOM_MOTION_TYPE ;
else if ( type == "way" )
move_type = WAYPOINT_MOTION_TYPE ;
else
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
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_MOVE_TYPE_SET , type_str );
2010-11-19 14:04:21 +01:00
}
else
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_MOVE_TYPE_SET_NODEL , type_str );
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 ;
uint32 phaseGroupId = ( uint32 ) atoi (( char * ) args );
Creature * creature = handler -> getSelectedCreature ();
if ( ! creature || creature -> IsPet ())
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
creature -> ClearPhases ();
for ( uint32 id : sDB2Manager . GetPhasesForGroup ( phaseGroupId ))
creature -> SetInPhase ( id , false , true ); // don't send update here for multiple phases, only send it once after adding all phases
creature -> UpdateObjectVisibility ();
creature -> SetDBPhase ( - int ( phaseGroupId ));
creature -> SaveToDB ();
return true ;
}
//npc phase handling
//change phase of creature
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetPhaseCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
uint32 phaseID = atoul ( args );
2016-06-05 16:43:41 +02:00
if ( ! sPhaseStore . LookupEntry ( phaseID ))
{
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
2015-03-16 07:28:49 +01:00
creature -> ClearPhases ();
2016-06-05 16:43:41 +02:00
creature -> SetInPhase ( phaseID , true , true );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetSpawnDistCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
float option = ( float )( atof (( char * ) args ));
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 ;
if ( option > 0.0f )
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
2014-10-26 02:57:28 +02:00
creature -> SetRespawnRadius ( 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
}
2011-12-31 19:06:24 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_SPAWN_DISTANCE );
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 );
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_SPAWNDIST , 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetSpawnTimeCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
char * stime = strtok (( char * ) args , " " );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! stime )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
int spawnTime = atoi ( stime );
2010-11-09 10:15:35 -05:00
2011-12-31 19:06:24 +01:00
if ( spawnTime < 0 )
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 ();
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
2011-12-31 19:06:24 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_SPAWN_TIME_SECS );
stmt -> setUInt32 ( 0 , uint32 ( spawnTime ));
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 1 , guidLow );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
creature -> SetRespawnDelay (( uint32 ) spawnTime );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSayCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
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
}
2014-09-13 20:41:31 +02:00
creature -> Say ( args , LANG_UNIVERSAL );
2010-11-19 14:04:21 +01:00
// make some emotes
char lastchar = args [ strlen ( args ) - 1 ];
2011-09-29 12:43:05 +02:00
switch ( lastchar )
2010-11-09 10:15:35 -05:00
{
2011-07-02 22:18:03 +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
2012-10-24 13:29:34 +02:00
static bool HandleNpcTextEmoteCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
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
2014-09-13 20:41:31 +02:00
creature -> TextEmote ( args );
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 unfollow handling
2012-10-24 13:29:34 +02:00
static bool HandleNpcUnFollowCommand ( ChatHandler * handler , char const * /*args*/ )
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
2010-11-19 14:04:21 +01:00
if ( /*creature->GetMotionMaster()->empty() ||*/
2012-03-16 19:40:57 +08:00
creature -> GetMotionMaster () -> GetCurrentMovementGeneratorType () != FOLLOW_MOTION_TYPE )
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
2012-01-14 15:34:41 +01:00
FollowMovementGenerator < Creature > const * mgen = static_cast < FollowMovementGenerator < Creature > const *> (( creature -> GetMotionMaster () -> top ()));
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( mgen -> GetTarget () != player )
{
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
}
2010-11-19 14:04:21 +01:00
// reset movement
creature -> GetMotionMaster () -> MovementExpired ( true );
2010-11-09 10:15:35 -05:00
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcWhisperCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
2014-09-13 02:45:51 +01:00
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
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
char * receiver_str = strtok (( char * ) args , " " );
2016-01-20 23:43:13 +01:00
char * text = strtok ( nullptr , "" );
2010-11-09 10:15:35 -05:00
2014-09-13 02:45:51 +01:00
if ( ! receiver_str || ! text )
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
handler -> SetSentErrorMessage ( true );
return false ;
}
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
2014-10-29 21:13:21 +01:00
ObjectGuid receiver_guid = ObjectGuid :: Create < HighGuid :: Player > ( strtoull ( receiver_str , nullptr , 10 ));
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
// check online security
2013-12-23 14:23:49 +01:00
Player * receiver = ObjectAccessor :: FindPlayer ( receiver_guid );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcYellCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
2014-09-13 02:45:51 +01:00
{
handler -> SendSysMessage ( LANG_CMD_SYNTAX );
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
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
2014-09-13 20:41:31 +02:00
creature -> Yell ( args , 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
2012-10-24 13:29:34 +02:00
static bool HandleNpcAddTempSpawnCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2013-10-16 18:37:29 +02:00
2016-01-20 23:43:13 +01:00
bool loot = false ;
char const * spawntype_str = strtok (( char * ) args , " " );
char const * entry_str = strtok ( nullptr , "" );
if ( stricmp ( spawntype_str , "LOOT" ) == 0 )
loot = true ;
else if ( stricmp ( spawntype_str , "NOLOOT" ) == 0 )
loot = false ;
else
entry_str = args ;
char * charID = handler -> extractKeyFromLink (( char * ) entry_str , "Hcreature_entry" );
2010-11-19 14:04:21 +01:00
if ( ! charID )
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
2017-03-11 12:29:37 +01:00
uint32 id = atoul ( charID );
2010-11-19 14:04:21 +01:00
if ( ! id )
return false ;
2010-11-09 10:15:35 -05:00
2013-09-06 14:31:41 +02:00
if ( ! sObjectMgr -> GetCreatureTemplate ( id ))
return false ;
2016-01-20 23:43:13 +01:00
chr -> SummonCreature ( id , * chr , loot ? TEMPSUMMON_CORPSE_TIMED_DESPAWN : TEMPSUMMON_CORPSE_DESPAWN , 30 * IN_MILLISECONDS );
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcTameCommand ( ChatHandler * handler , char const * /*args*/ )
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
2013-06-11 21:25:12 -02:30
if ( ! cInfo -> IsTameable ( player -> CanTameExoticPets ()))
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 ;
2012-03-16 19:40:57 +08:00
player -> GetClosePoint ( x , y , z , creatureTarget -> GetObjectSize (), 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
uint8 level = ( creatureTarget -> getLevel () < ( player -> getLevel () - 5 )) ? ( 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
pet -> SetUInt32Value ( UNIT_FIELD_LEVEL , 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
pet -> SetUInt32Value ( UNIT_FIELD_LEVEL , 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
2016-01-20 23:43:13 +01:00
static bool HandleNpcEvadeCommand ( ChatHandler * handler , char const * args )
{
Creature * creatureTarget = handler -> getSelectedCreature ();
if ( ! creatureTarget || creatureTarget -> IsPet ())
{
handler -> PSendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( ! creatureTarget -> IsAIEnabled )
{
handler -> PSendSysMessage ( LANG_CREATURE_NOT_AI_ENABLED );
handler -> SetSentErrorMessage ( true );
return false ;
}
char * type_str = args ? strtok (( char * ) args , " " ) : nullptr ;
char * force_str = args ? strtok ( nullptr , " " ) : nullptr ;
CreatureAI :: EvadeReason why = CreatureAI :: EVADE_REASON_OTHER ;
bool force = false ;
if ( type_str )
{
if ( stricmp ( type_str , "NO_HOSTILES" ) == 0 || stricmp ( type_str , "EVADE_REASON_NO_HOSTILES" ) == 0 )
why = CreatureAI :: EVADE_REASON_NO_HOSTILES ;
else if ( stricmp ( type_str , "BOUNDARY" ) == 0 || stricmp ( type_str , "EVADE_REASON_BOUNDARY" ) == 0 )
why = CreatureAI :: EVADE_REASON_BOUNDARY ;
else if ( stricmp ( type_str , "SEQUENCE_BREAK" ) == 0 || stricmp ( type_str , "EVADE_REASON_SEQUENCE_BREAK" ) == 0 )
why = CreatureAI :: EVADE_REASON_SEQUENCE_BREAK ;
else if ( stricmp ( type_str , "FORCE" ) == 0 )
force = true ;
2016-09-22 21:59:12 +02:00
2016-01-20 23:43:13 +01:00
if ( ! force && force_str )
if ( stricmp ( force_str , "FORCE" ) == 0 )
force = true ;
}
if ( force )
creatureTarget -> ClearUnitState ( UNIT_STATE_EVADE );
creatureTarget -> AI () -> EnterEvadeMode ( why );
return true ;
}
2012-10-24 13:29:34 +02:00
static bool HandleNpcAddFormationCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
ObjectGuid :: LowType leaderGUID = atoull ( args );
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
{
2014-10-27 21:56:12 +00:00
handler -> PSendSysMessage ( "Selected creature is already member of group " UI64FMTD , creature -> GetFormation () -> GetId ());
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 ();
2011-09-15 14:08:17 +02:00
FormationInfo * group_member ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
group_member = new FormationInfo ;
2014-08-21 16:56:11 +02:00
group_member -> follow_angle = ( creature -> GetAngle ( chr ) - chr -> GetOrientation ()) * 180 / float ( M_PI );
group_member -> follow_dist = std :: sqrt ( std :: pow ( chr -> GetPositionX () - creature -> GetPositionX (), 2.f ) + std :: pow ( chr -> GetPositionY () - creature -> GetPositionY (), 2.f ));
2010-11-19 14:04:21 +01:00
group_member -> leaderGUID = leaderGUID ;
group_member -> groupAI = 0 ;
2010-11-09 10:15:35 -05:00
2012-03-25 09:25:28 -05:00
sFormationMgr -> CreatureGroupMap [ lowguid ] = group_member ;
2011-07-02 22:18:03 +02:00
creature -> SearchFormation ();
2010-11-09 10:15:35 -05:00
2011-12-31 19:06:24 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_CREATURE_FORMATION );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 0 , leaderGUID );
stmt -> setUInt64 ( 1 , lowguid );
2011-12-31 19:06:24 +01:00
stmt -> setFloat ( 2 , group_member -> follow_dist );
stmt -> setFloat ( 3 , group_member -> follow_angle );
stmt -> setUInt32 ( 4 , uint32 ( group_member -> groupAI ));
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
2012-10-24 13:29:34 +02:00
static bool HandleNpcSetLinkCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-09 10:15:35 -05:00
2017-03-11 12:29:37 +01:00
ObjectGuid :: LowType linkguid = atoull ( args );
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 :
2012-10-24 13:29:34 +02:00
static bool HandleNpcAddWeaponCommand ( ChatHandler * /*handler*/ , char const * /*args*/ )
2010-11-19 14:04:21 +01:00
{
/*if (!*args)
return false;
uint64 guid = handler->GetSession()->GetPlayer()->GetSelection();
if (guid == 0)
{
handler->SendSysMessage(LANG_NO_SELECTION);
2010-11-09 10:15:35 -05:00
return true;
}
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);
return true;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
char* pSlotID = strtok((char*)args, " ");
if (!pSlotID)
return false;
2010-11-09 10:15:35 -05:00
2016-01-20 23:43:13 +01:00
char* pItemID = strtok(nullptr, " ");
2010-11-19 14:04:21 +01:00
if (!pItemID)
return false;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
uint32 ItemID = atoi(pItemID);
uint32 SlotID = atoi(pSlotID);
2010-11-09 10:15:35 -05:00
2011-04-29 16:48:15 +06:00
ItemTemplate* tmpItem = sObjectMgr->GetItemTemplate(ItemID);
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
bool added = false;
if (tmpItem)
{
2011-09-29 12:43:05 +02:00
switch (SlotID)
2010-11-19 14:04:21 +01:00
{
case 1:
2011-07-02 22:18:03 +02:00
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
2010-11-19 14:04:21 +01:00
added = true;
break;
case 2:
2011-07-02 22:18:03 +02:00
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
2010-11-19 14:04:21 +01:00
added = true;
break;
case 3:
2011-07-02 22:18:03 +02:00
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
2010-11-19 14:04:21 +01:00
added = true;
break;
default:
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST, SlotID);
2010-11-19 14:04:21 +01:00
added = false;
break;
}
if (added)
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT, ItemID, tmpItem->Name1, SlotID);
2010-11-19 14:04:21 +01:00
}
else
{
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_ITEM_NOT_FOUND, ItemID);
2010-11-19 14:04:21 +01:00
return true;
}
*/
return true ;
}
2010-11-09 10:15:35 -05:00
};
void AddSC_npc_commandscript ()
{
new npc_commandscript ();
}