From eb97c9e717622c8240a9b20a05fd63ed15dfb690 Mon Sep 17 00:00:00 2001 From: dythzer Date: Mon, 27 Oct 2008 00:25:00 +0100 Subject: [PATCH] [2008_10_31_02_mangos_mangos_string.sql 2008_10_31_03_mangos_command.sql] Added new command: .npc tame - Creates a pet of the selected creature. Works for all classes, not only hunter. Pet also saved in DB. Signed-off-by: dythzer Command renamed to .npc tame and code updated to use common function with spell effect. Targeted creature not killed and tamed pet show up before player. Signed-off-by: VladimirMangos --- sql/mangos.sql | 3 + .../2008_10_31_02_mangos_mangos_string.sql | 7 ++ sql/updates/2008_10_31_03_mangos_command.sql | 6 ++ sql/updates/Makefile.am | 4 ++ src/game/Chat.cpp | 1 + src/game/Chat.h | 1 + src/game/Language.h | 4 +- src/game/Level2.cpp | 64 +++++++++++++++++++ 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 sql/updates/2008_10_31_02_mangos_mangos_string.sql create mode 100644 sql/updates/2008_10_31_03_mangos_command.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 96ccd89de..e9996524a 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -340,6 +340,7 @@ INSERT INTO `command` VALUES ('npc spawndist',2,'Syntax: .npc spawndist #dist\r\n\r\nAdjust spawndistance of selected creature to dist.'), ('npc spawntime',2,'Syntax: .npc spawntime #time \r\n\r\nAdjust spawntime of selected creature to time.'), ('npc subname',2,'Syntax: .npc subname $Name\r\n\r\nChange the subname of the selected creature or player to $Name.\r\n\r\nCommand disabled.'), +('npc tame',2,'Syntax: .npc tame\r\n\r\nTame selected creature (tameable non pet creature). You don''t must have pet.'), ('npc textemote',3,'Syntax: .npc textemote #emoteid\r\n\r\nMake the selected creature to do textemote with an emote of id #emoteid.'), ('npc whisper',1,'Syntax: .npc whisper #playerguid #text\r\nMake the selected npc whisper #text to #playerguid.'), ('npc unfollow',2,'Syntax: .npc unfollow\r\n\r\nSelected creature (non pet) stop follow you.'), @@ -2415,6 +2416,8 @@ INSERT INTO `mangos_string` VALUES (340,'%s is now following you.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (341,'%s is not following you.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (342,'%s is now not following you.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(343,'Creature (Entry: %u) cannot be tamed.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(344,'You already have pet.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (400,'|cffff0000[System Message]:|rScripts reloaded',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (401,'You change security level of account %s to %i.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (402,'%s changed your security level to %i.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), diff --git a/sql/updates/2008_10_31_02_mangos_mangos_string.sql b/sql/updates/2008_10_31_02_mangos_mangos_string.sql new file mode 100644 index 000000000..a9752a113 --- /dev/null +++ b/sql/updates/2008_10_31_02_mangos_mangos_string.sql @@ -0,0 +1,7 @@ +ALTER TABLE db_version CHANGE COLUMN required_2008_10_31_01_mangos_creature_template required_2008_10_31_02_mangos_mangos_string bit; + +DELETE FROM mangos_string WHERE entry IN (343,344); + +INSERT INTO mangos_string VALUES +(343,'Creature (Entry: %u) cannot be tamed.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(344,'You already have pet.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); diff --git a/sql/updates/2008_10_31_03_mangos_command.sql b/sql/updates/2008_10_31_03_mangos_command.sql new file mode 100644 index 000000000..65bb15597 --- /dev/null +++ b/sql/updates/2008_10_31_03_mangos_command.sql @@ -0,0 +1,6 @@ +ALTER TABLE db_version CHANGE COLUMN required_2008_10_31_02_mangos_mangos_string required_2008_10_31_03_mangos_command bit; + +DELETE FROM command WHERE name IN ('npc tame'); + +INSERT INTO command VALUES +('npc tame',2,'Syntax: .npc tame\r\n\r\nTame selected creature (tameable non pet creature). You don''t must have pet.'); diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index 55dec2ca2..710f81c3d 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -119,6 +119,8 @@ pkgdata_DATA = \ 2008_10_29_04_mangos_mangos_string.sql \ 2008_10_29_05_mangos_command.sql \ 2008_10_31_01_mangos_creature_template.sql \ + 2008_10_31_02_mangos_mangos_string.sql \ + 2008_10_31_03_mangos_command.sql \ README ## Additional files to include when running 'make dist' @@ -219,4 +221,6 @@ EXTRA_DIST = \ 2008_10_29_04_mangos_mangos_string.sql \ 2008_10_29_05_mangos_command.sql \ 2008_10_31_01_mangos_creature_template.sql \ + 2008_10_31_02_mangos_mangos_string.sql \ + 2008_10_31_03_mangos_command.sql \ README diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index 2bceb2d0d..0a9097f43 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -379,6 +379,7 @@ ChatCommand * ChatHandler::getCommandTable() { "unfollow", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcUnFollowCommand, "", NULL }, { "whisper", SEC_MODERATOR, false, &ChatHandler::HandleNpcWhisperCommand, "", NULL }, { "yell", SEC_MODERATOR, false, &ChatHandler::HandleNpcYellCommand, "", NULL }, + { "tame", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcTameCommand, "", NULL }, //{ TODO: fix or remove this commands { "name", SEC_GAMEMASTER, false, &ChatHandler::HandleNameCommand, "", NULL }, diff --git a/src/game/Chat.h b/src/game/Chat.h index 4ddf2d92f..1319f30be 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -186,6 +186,7 @@ class ChatHandler bool HandleNpcSetMoveTypeCommand(const char* args); bool HandleNpcSpawnDistCommand(const char* args); bool HandleNpcSpawnTimeCommand(const char* args); + bool HandleNpcTameCommand(const char* args); bool HandleNpcTextEmoteCommand(const char* args); bool HandleNpcUnFollowCommand(const char* args); bool HandleNpcWhisperCommand(const char* args); diff --git a/src/game/Language.h b/src/game/Language.h index 974b94ee0..ad4137197 100644 --- a/src/game/Language.h +++ b/src/game/Language.h @@ -324,7 +324,9 @@ enum MangosStrings LANG_CREATURE_FOLLOW_YOU_NOW = 340, LANG_CREATURE_NOT_FOLLOW_YOU = 341, LANG_CREATURE_NOT_FOLLOW_YOU_NOW = 342, - // Room for more level 2 343-399 not used + LANG_CREATURE_NON_TAMEABLE = 343, + LANG_YOU_ALREADY_HAVE_PET = 344, + // Room for more level 2 345-399 not used // level 3 chat LANG_SCRIPTS_RELOADED = 400, diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index fa2dbae50..bd0f350cf 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -4156,3 +4156,67 @@ bool ChatHandler::HandleNpcUnFollowCommand(const char* /*args*/) PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU_NOW, creature->GetName()); return true; } + +bool ChatHandler::HandleNpcTameCommand(const char* args) +{ + Creature *creatureTarget = getSelectedCreature (); + if (!creatureTarget || creatureTarget->isPet ()) + { + PSendSysMessage (LANG_SELECT_CREATURE); + SetSentErrorMessage (true); + return false; + } + + Player *player = m_session->GetPlayer (); + + if(player->GetPetGUID ()) + { + SendSysMessage (LANG_YOU_ALREADY_HAVE_PET); + SetSentErrorMessage (true); + return false; + } + + CreatureInfo const* cInfo = creatureTarget->GetCreatureInfo(); + + if (!cInfo->isTameable ()) + { + PSendSysMessage (LANG_CREATURE_NON_TAMEABLE,cInfo->Entry); + SetSentErrorMessage (true); + return false; + } + + // Everything looks OK, create new pet + Pet* pet = player->CreateTamedPetFrom (creatureTarget); + if (!pet) + { + PSendSysMessage (LANG_CREATURE_NON_TAMEABLE,cInfo->Entry); + SetSentErrorMessage (true); + return false; + } + + // place pet before player + float x,y,z; + player->GetClosePoint (x,y,z,creatureTarget->GetObjectSize (),CONTACT_DISTANCE); + pet->Relocate (x,y,z,M_PI-player->GetOrientation ()); + + // set pet to defensive mode by default (some classes can't control contolled pets in fact). + pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE); + + + // prepare visual effect for levelup + pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1); + + // add to world + MapManager::Instance().GetMap(pet->GetMapId(), pet)->Add((Creature*)pet); + + // visual effect for levelup + pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()); + + // caster have pet now + player->SetPet(pet); + + pet->SavePetToDB(PET_SAVE_AS_CURRENT); + player->PetSpellInitialize(); + + return true; +}