[28] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 4 | * This program is free software; you can redistribute it and/or modify |
---|
| 5 | * it under the terms of the GNU General Public License as published by |
---|
| 6 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | * (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include "Common.h" |
---|
| 20 | #include "WorldPacket.h" |
---|
| 21 | #include "WorldSession.h" |
---|
| 22 | #include "World.h" |
---|
| 23 | #include "ObjectMgr.h" |
---|
| 24 | #include "SpellMgr.h" |
---|
| 25 | #include "Log.h" |
---|
| 26 | #include "Opcodes.h" |
---|
| 27 | #include "Spell.h" |
---|
| 28 | #include "ObjectAccessor.h" |
---|
| 29 | #include "MapManager.h" |
---|
| 30 | #include "CreatureAI.h" |
---|
| 31 | #include "Util.h" |
---|
| 32 | #include "Pet.h" |
---|
| 33 | #include "Language.h" |
---|
| 34 | |
---|
| 35 | void WorldSession::HandlePetAction( WorldPacket & recv_data ) |
---|
| 36 | { |
---|
| 37 | CHECK_PACKET_SIZE(recv_data,8+2+2+8); |
---|
| 38 | |
---|
| 39 | uint64 guid1; |
---|
| 40 | uint16 spellid; |
---|
| 41 | uint16 flag; |
---|
| 42 | uint64 guid2; |
---|
| 43 | recv_data >> guid1; //pet guid |
---|
| 44 | recv_data >> spellid; |
---|
| 45 | recv_data >> flag; //delete = 0x0700 CastSpell = C100 |
---|
| 46 | recv_data >> guid2; //tag guid |
---|
| 47 | |
---|
| 48 | // used also for charmed creature |
---|
| 49 | Unit* pet= ObjectAccessor::GetUnit(*_player,guid1); |
---|
| 50 | sLog.outDetail( "HandlePetAction.Pet %u flag is %u, spellid is %u, target %u.\n", uint32(GUID_LOPART(guid1)), flag, spellid, uint32(GUID_LOPART(guid2)) ); |
---|
| 51 | if(!pet) |
---|
| 52 | { |
---|
| 53 | sLog.outError( "Pet %u not exist.\n", uint32(GUID_LOPART(guid1)) ); |
---|
| 54 | return; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | if(pet != GetPlayer()->GetPet() && pet != GetPlayer()->GetCharm()) |
---|
| 58 | { |
---|
| 59 | sLog.outError( "HandlePetAction.Pet %u isn't pet of player %s .\n", uint32(GUID_LOPART(guid1)),GetPlayer()->GetName() ); |
---|
| 60 | return; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if(!pet->isAlive()) |
---|
| 64 | return; |
---|
| 65 | |
---|
| 66 | if(pet->GetTypeId() == TYPEID_PLAYER && !(flag == ACT_COMMAND && spellid == COMMAND_ATTACK)) |
---|
| 67 | return; |
---|
| 68 | |
---|
| 69 | CharmInfo *charmInfo = pet->GetCharmInfo(); |
---|
| 70 | if(!charmInfo) |
---|
| 71 | { |
---|
| 72 | sLog.outError("WorldSession::HandlePetAction: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID()); |
---|
| 73 | return; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | switch(flag) |
---|
| 77 | { |
---|
| 78 | case ACT_COMMAND: //0x0700 |
---|
| 79 | switch(spellid) |
---|
| 80 | { |
---|
| 81 | case COMMAND_STAY: //flat=1792 //STAY |
---|
| 82 | pet->StopMoving(); |
---|
| 83 | pet->GetMotionMaster()->Clear(); |
---|
| 84 | pet->GetMotionMaster()->MoveIdle(); |
---|
| 85 | charmInfo->SetCommandState( COMMAND_STAY ); |
---|
| 86 | break; |
---|
| 87 | case COMMAND_FOLLOW: //spellid=1792 //FOLLOW |
---|
| 88 | pet->AttackStop(); |
---|
| 89 | pet->GetMotionMaster()->MoveFollow(_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); |
---|
| 90 | charmInfo->SetCommandState( COMMAND_FOLLOW ); |
---|
| 91 | break; |
---|
| 92 | case COMMAND_ATTACK: //spellid=1792 //ATTACK |
---|
| 93 | { |
---|
| 94 | // only place where pet can be player |
---|
| 95 | pet->clearUnitState(UNIT_STAT_FOLLOW); |
---|
| 96 | uint64 selguid = _player->GetSelection(); |
---|
| 97 | Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid); |
---|
| 98 | if(!TargetUnit) |
---|
| 99 | return; |
---|
| 100 | |
---|
| 101 | // not let attack friendly units. |
---|
| 102 | if( GetPlayer()->IsFriendlyTo(TargetUnit)) |
---|
| 103 | return; |
---|
| 104 | |
---|
| 105 | if(pet->getVictim()) |
---|
| 106 | pet->AttackStop(); |
---|
| 107 | |
---|
| 108 | if(pet->GetTypeId() != TYPEID_PLAYER) |
---|
| 109 | { |
---|
| 110 | pet->GetMotionMaster()->Clear(); |
---|
| 111 | if (((Creature*)pet)->AI()) |
---|
| 112 | ((Creature*)pet)->AI()->AttackStart(TargetUnit); |
---|
| 113 | |
---|
| 114 | //10% chance to play special pet attack talk, else growl |
---|
| 115 | if(((Creature*)pet)->isPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10) |
---|
| 116 | pet->SendPetTalk((uint32)PET_TALK_ATTACK); |
---|
| 117 | else |
---|
| 118 | { |
---|
| 119 | // 90% chance for pet and 100% chance for charmed creature |
---|
| 120 | pet->SendPetAIReaction(guid1); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | else // charmed player |
---|
| 124 | { |
---|
| 125 | pet->Attack(TargetUnit,true); |
---|
| 126 | pet->SendPetAIReaction(guid1); |
---|
| 127 | } |
---|
| 128 | break; |
---|
| 129 | } |
---|
| 130 | case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet) |
---|
| 131 | if(((Creature*)pet)->isPet()) |
---|
| 132 | { |
---|
| 133 | Pet* p = (Pet*)pet; |
---|
| 134 | if(p->getPetType() == HUNTER_PET) |
---|
| 135 | _player->RemovePet(p,PET_SAVE_AS_DELETED); |
---|
| 136 | else |
---|
| 137 | //dismissing a summoned pet is like killing them (this prevents returning a soulshard...) |
---|
| 138 | p->setDeathState(CORPSE); |
---|
| 139 | } |
---|
| 140 | else // charmed |
---|
| 141 | _player->Uncharm(); |
---|
| 142 | break; |
---|
| 143 | default: |
---|
| 144 | sLog.outError("WORLD: unknown PET flag Action %i and spellid %i.\n", flag, spellid); |
---|
| 145 | } |
---|
| 146 | break; |
---|
| 147 | case ACT_REACTION: // 0x600 |
---|
| 148 | switch(spellid) |
---|
| 149 | { |
---|
| 150 | case REACT_PASSIVE: //passive |
---|
| 151 | case REACT_DEFENSIVE: //recovery |
---|
| 152 | case REACT_AGGRESSIVE: //activete |
---|
| 153 | charmInfo->SetReactState( ReactStates(spellid) ); |
---|
| 154 | break; |
---|
| 155 | } |
---|
| 156 | break; |
---|
| 157 | case ACT_DISABLED: //0x8100 spell (disabled), ignore |
---|
| 158 | case ACT_CAST: //0x0100 |
---|
| 159 | case ACT_ENABLED: //0xc100 spell |
---|
| 160 | { |
---|
| 161 | Unit* unit_target; |
---|
| 162 | if(guid2) |
---|
| 163 | unit_target = ObjectAccessor::GetUnit(*_player,guid2); |
---|
| 164 | else |
---|
| 165 | unit_target = NULL; |
---|
| 166 | |
---|
| 167 | // do not cast unknown spells |
---|
| 168 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid ); |
---|
| 169 | if(!spellInfo) |
---|
| 170 | { |
---|
| 171 | sLog.outError("WORLD: unknown PET spell id %i\n", spellid); |
---|
| 172 | return; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | for(uint32 i = 0; i < 3;i++) |
---|
| 176 | { |
---|
| 177 | if(spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_INSTANT || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED) |
---|
| 178 | return; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | // do not cast not learned spells |
---|
| 182 | if(!pet->HasSpell(spellid) || IsPassiveSpell(spellid)) |
---|
| 183 | return; |
---|
| 184 | |
---|
| 185 | pet->clearUnitState(UNIT_STAT_FOLLOW); |
---|
| 186 | |
---|
| 187 | Spell *spell = new Spell(pet, spellInfo, false); |
---|
| 188 | |
---|
| 189 | int16 result = spell->PetCanCast(unit_target); |
---|
| 190 | |
---|
| 191 | //auto turn to target unless possessed |
---|
| 192 | if(result == SPELL_FAILED_UNIT_NOT_INFRONT && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) |
---|
| 193 | { |
---|
| 194 | pet->SetInFront(unit_target); |
---|
| 195 | if( unit_target->GetTypeId() == TYPEID_PLAYER ) |
---|
| 196 | pet->SendUpdateToPlayer( (Player*)unit_target ); |
---|
| 197 | if(Unit* powner = pet->GetCharmerOrOwner()) |
---|
| 198 | if(powner->GetTypeId() == TYPEID_PLAYER) |
---|
| 199 | pet->SendUpdateToPlayer((Player*)powner); |
---|
| 200 | result = -1; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | if(result == -1) |
---|
| 204 | { |
---|
| 205 | ((Creature*)pet)->AddCreatureSpellCooldown(spellid); |
---|
| 206 | if (((Creature*)pet)->isPet()) |
---|
| 207 | ((Pet*)pet)->CheckLearning(spellid); |
---|
| 208 | |
---|
| 209 | unit_target = spell->m_targets.getUnitTarget(); |
---|
| 210 | |
---|
| 211 | //10% chance to play special pet attack talk, else growl |
---|
| 212 | //actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell |
---|
| 213 | if(((Creature*)pet)->isPet() && (((Pet*)pet)->getPetType() == SUMMON_PET) && (pet != unit_target) && (urand(0, 100) < 10)) |
---|
| 214 | pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); |
---|
| 215 | else |
---|
| 216 | { |
---|
| 217 | pet->SendPetAIReaction(guid1); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | if( unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) |
---|
| 221 | { |
---|
| 222 | pet->clearUnitState(UNIT_STAT_FOLLOW); |
---|
| 223 | if(pet->getVictim()) |
---|
| 224 | pet->AttackStop(); |
---|
| 225 | pet->GetMotionMaster()->Clear(); |
---|
| 226 | if (((Creature*)pet)->AI()) |
---|
| 227 | ((Creature*)pet)->AI()->AttackStart(unit_target); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | spell->prepare(&(spell->m_targets)); |
---|
| 231 | } |
---|
| 232 | else |
---|
| 233 | { |
---|
| 234 | if(pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) |
---|
| 235 | { |
---|
| 236 | WorldPacket data(SMSG_CAST_FAILED, (4+1+1)); |
---|
| 237 | data << uint32(spellid) << uint8(2) << uint8(result); |
---|
| 238 | switch (result) |
---|
| 239 | { |
---|
| 240 | case SPELL_FAILED_REQUIRES_SPELL_FOCUS: |
---|
| 241 | data << uint32(spellInfo->RequiresSpellFocus); |
---|
| 242 | break; |
---|
| 243 | case SPELL_FAILED_REQUIRES_AREA: |
---|
| 244 | data << uint32(spellInfo->AreaId); |
---|
| 245 | break; |
---|
| 246 | } |
---|
| 247 | SendPacket(&data); |
---|
| 248 | } |
---|
| 249 | else |
---|
| 250 | pet->SendPetCastFail(spellid, result); |
---|
| 251 | |
---|
| 252 | if(!((Creature*)pet)->HasSpellCooldown(spellid)) |
---|
| 253 | pet->SendPetClearCooldown(spellid); |
---|
| 254 | |
---|
| 255 | spell->finish(false); |
---|
| 256 | delete spell; |
---|
| 257 | } |
---|
| 258 | break; |
---|
| 259 | } |
---|
| 260 | default: |
---|
| 261 | sLog.outError("WORLD: unknown PET flag Action %i and spellid %i.\n", flag, spellid); |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | void WorldSession::HandlePetNameQuery( WorldPacket & recv_data ) |
---|
| 266 | { |
---|
| 267 | CHECK_PACKET_SIZE(recv_data,4+8); |
---|
| 268 | |
---|
| 269 | sLog.outDetail( "HandlePetNameQuery. CMSG_PET_NAME_QUERY\n" ); |
---|
| 270 | |
---|
| 271 | uint32 petnumber; |
---|
| 272 | uint64 petguid; |
---|
| 273 | |
---|
| 274 | recv_data >> petnumber; |
---|
| 275 | recv_data >> petguid; |
---|
| 276 | |
---|
| 277 | SendPetNameQuery(petguid,petnumber); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | void WorldSession::SendPetNameQuery( uint64 petguid, uint32 petnumber) |
---|
| 281 | { |
---|
| 282 | Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player, petguid); |
---|
| 283 | if(!pet || !pet->GetCharmInfo() || pet->GetCharmInfo()->GetPetNumber() != petnumber) |
---|
| 284 | return; |
---|
| 285 | |
---|
| 286 | std::string name = pet->GetName(); |
---|
| 287 | |
---|
| 288 | WorldPacket data(SMSG_PET_NAME_QUERY_RESPONSE, (4+4+name.size()+1)); |
---|
| 289 | data << uint32(petnumber); |
---|
| 290 | data << name.c_str(); |
---|
| 291 | data << uint32(pet->GetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP)); |
---|
| 292 | |
---|
| 293 | if( pet->isPet() && ((Pet*)pet)->GetDeclinedNames() ) |
---|
| 294 | { |
---|
| 295 | data << uint8(1); |
---|
| 296 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
| 297 | data << ((Pet*)pet)->GetDeclinedNames()->name[i]; |
---|
| 298 | } |
---|
| 299 | else |
---|
| 300 | data << uint8(0); |
---|
| 301 | |
---|
| 302 | _player->GetSession()->SendPacket(&data); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | void WorldSession::HandlePetSetAction( WorldPacket & recv_data ) |
---|
| 306 | { |
---|
| 307 | CHECK_PACKET_SIZE(recv_data,8+4+2+2); |
---|
| 308 | |
---|
| 309 | sLog.outDetail( "HandlePetSetAction. CMSG_PET_SET_ACTION\n" ); |
---|
| 310 | |
---|
| 311 | uint64 petguid; |
---|
| 312 | uint32 position; |
---|
| 313 | uint16 spell_id; |
---|
| 314 | uint16 act_state; |
---|
| 315 | uint8 count; |
---|
| 316 | |
---|
| 317 | recv_data >> petguid; |
---|
| 318 | |
---|
| 319 | // FIXME: charmed case |
---|
| 320 | //Pet* pet = ObjectAccessor::Instance().GetPet(petguid); |
---|
| 321 | if(ObjectAccessor::FindPlayer(petguid)) |
---|
| 322 | return; |
---|
| 323 | |
---|
| 324 | Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player, petguid); |
---|
| 325 | |
---|
| 326 | if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm())) |
---|
| 327 | { |
---|
| 328 | sLog.outError( "HandlePetSetAction: Unknown pet or pet owner.\n" ); |
---|
| 329 | return; |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | CharmInfo *charmInfo = pet->GetCharmInfo(); |
---|
| 333 | if(!charmInfo) |
---|
| 334 | { |
---|
| 335 | sLog.outError("WorldSession::HandlePetSetAction: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID()); |
---|
| 336 | return; |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | count = (recv_data.size() == 24) ? 2 : 1; |
---|
| 340 | for(uint8 i = 0; i < count; i++) |
---|
| 341 | { |
---|
| 342 | recv_data >> position; |
---|
| 343 | recv_data >> spell_id; |
---|
| 344 | recv_data >> act_state; |
---|
| 345 | |
---|
| 346 | sLog.outDetail( "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X\n", _player->GetName(), position, spell_id, act_state); |
---|
| 347 | |
---|
| 348 | //if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add |
---|
| 349 | if(!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_CAST) && spell_id && !pet->HasSpell(spell_id))) |
---|
| 350 | { |
---|
| 351 | //sign for autocast |
---|
| 352 | if(act_state == ACT_ENABLED && spell_id) |
---|
| 353 | { |
---|
| 354 | if(pet->isCharmed()) |
---|
| 355 | charmInfo->ToggleCreatureAutocast(spell_id, true); |
---|
| 356 | else |
---|
| 357 | ((Pet*)pet)->ToggleAutocast(spell_id, true); |
---|
| 358 | } |
---|
| 359 | //sign for no/turn off autocast |
---|
| 360 | else if(act_state == ACT_DISABLED && spell_id) |
---|
| 361 | { |
---|
| 362 | if(pet->isCharmed()) |
---|
| 363 | charmInfo->ToggleCreatureAutocast(spell_id, false); |
---|
| 364 | else |
---|
| 365 | ((Pet*)pet)->ToggleAutocast(spell_id, false); |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | charmInfo->GetActionBarEntry(position)->Type = act_state; |
---|
| 369 | charmInfo->GetActionBarEntry(position)->SpellOrAction = spell_id; |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | void WorldSession::HandlePetRename( WorldPacket & recv_data ) |
---|
| 375 | { |
---|
| 376 | CHECK_PACKET_SIZE(recv_data,8+1+1+1+1+1+1+1); |
---|
| 377 | |
---|
| 378 | sLog.outDetail( "HandlePetRename. CMSG_PET_RENAME\n" ); |
---|
| 379 | |
---|
| 380 | uint64 petguid; |
---|
| 381 | uint8 isdeclined; |
---|
| 382 | |
---|
| 383 | std::string name; |
---|
| 384 | DeclinedName declinedname; |
---|
| 385 | |
---|
| 386 | recv_data >> petguid; |
---|
| 387 | recv_data >> name; |
---|
| 388 | recv_data >> isdeclined; |
---|
| 389 | |
---|
| 390 | Pet* pet = ObjectAccessor::GetPet(petguid); |
---|
| 391 | // check it! |
---|
| 392 | if( !pet || !pet->isPet() || ((Pet*)pet)->getPetType()!= HUNTER_PET || |
---|
| 393 | pet->GetByteValue(UNIT_FIELD_BYTES_2, 2) != UNIT_RENAME_ALLOWED || |
---|
| 394 | pet->GetOwnerGUID() != _player->GetGUID() || !pet->GetCharmInfo() ) |
---|
| 395 | return; |
---|
| 396 | |
---|
| 397 | if((!ObjectMgr::IsValidPetName(name)) || (objmgr.IsReservedName(name))) |
---|
| 398 | { |
---|
| 399 | SendNotification(LANG_PET_INVALID_NAME); |
---|
| 400 | return; |
---|
| 401 | } |
---|
| 402 | pet->SetName(name); |
---|
| 403 | |
---|
| 404 | Unit *owner = pet->GetOwner(); |
---|
| 405 | if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) |
---|
| 406 | ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME); |
---|
| 407 | |
---|
| 408 | pet->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED); |
---|
| 409 | |
---|
| 410 | if(isdeclined) |
---|
| 411 | { |
---|
| 412 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
| 413 | recv_data >> declinedname.name[i]; |
---|
| 414 | |
---|
| 415 | std::wstring wname; |
---|
| 416 | Utf8toWStr(name,wname); |
---|
| 417 | if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname)) |
---|
| 418 | { |
---|
| 419 | SendNotification(LANG_PET_INVALID_NAME); |
---|
| 420 | return; |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | CharacterDatabase.BeginTransaction(); |
---|
| 425 | if(isdeclined) |
---|
| 426 | { |
---|
| 427 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
| 428 | CharacterDatabase.escape_string(declinedname.name[i]); |
---|
| 429 | CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber()); |
---|
| 430 | CharacterDatabase.PExecute("INSERT INTO character_pet_declinedname (id, owner, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%u','%s','%s','%s','%s','%s')", |
---|
| 431 | pet->GetCharmInfo()->GetPetNumber(), _player->GetGUIDLow(), declinedname.name[0].c_str(),declinedname.name[1].c_str(),declinedname.name[2].c_str(),declinedname.name[3].c_str(),declinedname.name[4].c_str()); |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | CharacterDatabase.escape_string(name); |
---|
| 435 | CharacterDatabase.PExecute("UPDATE character_pet SET name = '%s', renamed = '1' WHERE owner = '%u' AND id = '%u'", name.c_str(),_player->GetGUIDLow(),pet->GetCharmInfo()->GetPetNumber() ); |
---|
| 436 | CharacterDatabase.CommitTransaction(); |
---|
| 437 | |
---|
| 438 | pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | void WorldSession::HandlePetAbandon( WorldPacket & recv_data ) |
---|
| 442 | { |
---|
| 443 | CHECK_PACKET_SIZE(recv_data,8); |
---|
| 444 | |
---|
| 445 | uint64 guid; |
---|
| 446 | recv_data >> guid; //pet guid |
---|
| 447 | sLog.outDetail( "HandlePetAbandon. CMSG_PET_ABANDON pet guid is %u", GUID_LOPART(guid) ); |
---|
| 448 | |
---|
| 449 | // pet/charmed |
---|
| 450 | Creature* pet=ObjectAccessor::GetCreatureOrPet(*_player, guid); |
---|
| 451 | if(pet) |
---|
| 452 | { |
---|
| 453 | if(pet->isPet()) |
---|
| 454 | { |
---|
| 455 | if(pet->GetGUID() == _player->GetPetGUID()) |
---|
| 456 | { |
---|
| 457 | uint32 feelty = pet->GetPower(POWER_HAPPINESS); |
---|
| 458 | pet->SetPower(POWER_HAPPINESS ,(feelty-50000) > 0 ?(feelty-50000) : 0); |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | _player->RemovePet((Pet*)pet,PET_SAVE_AS_DELETED); |
---|
| 462 | } |
---|
| 463 | else if(pet->GetGUID() == _player->GetCharmGUID()) |
---|
| 464 | { |
---|
| 465 | _player->Uncharm(); |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | void WorldSession::HandlePetUnlearnOpcode(WorldPacket& recvPacket) |
---|
| 471 | { |
---|
| 472 | CHECK_PACKET_SIZE(recvPacket,8); |
---|
| 473 | |
---|
| 474 | sLog.outDetail("CMSG_PET_UNLEARN"); |
---|
| 475 | uint64 guid; |
---|
| 476 | recvPacket >> guid; |
---|
| 477 | |
---|
| 478 | Pet* pet = _player->GetPet(); |
---|
| 479 | |
---|
| 480 | if(!pet || pet->getPetType() != HUNTER_PET || pet->m_spells.size() <= 1) |
---|
| 481 | return; |
---|
| 482 | |
---|
| 483 | if(guid != pet->GetGUID()) |
---|
| 484 | { |
---|
| 485 | sLog.outError( "HandlePetUnlearnOpcode.Pet %u isn't pet of player %s .\n", uint32(GUID_LOPART(guid)),GetPlayer()->GetName() ); |
---|
| 486 | return; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | CharmInfo *charmInfo = pet->GetCharmInfo(); |
---|
| 490 | if(!charmInfo) |
---|
| 491 | { |
---|
| 492 | sLog.outError("WorldSession::HandlePetUnlearnOpcode: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID()); |
---|
| 493 | return; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | uint32 cost = pet->resetTalentsCost(); |
---|
| 497 | |
---|
| 498 | if (GetPlayer()->GetMoney() < cost) |
---|
| 499 | { |
---|
| 500 | GetPlayer()->SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY, 0, 0, 0); |
---|
| 501 | return; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | for(PetSpellMap::iterator itr = pet->m_spells.begin(); itr != pet->m_spells.end();) |
---|
| 505 | { |
---|
| 506 | uint32 spell_id = itr->first; // Pet::removeSpell can invalidate iterator at erase NEW spell |
---|
| 507 | ++itr; |
---|
| 508 | pet->removeSpell(spell_id); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | pet->SetTP(pet->getLevel() * (pet->GetLoyaltyLevel() - 1)); |
---|
| 512 | |
---|
| 513 | for(uint8 i = 0; i < 10; i++) |
---|
| 514 | { |
---|
| 515 | if(charmInfo->GetActionBarEntry(i)->SpellOrAction && charmInfo->GetActionBarEntry(i)->Type == ACT_ENABLED || charmInfo->GetActionBarEntry(i)->Type == ACT_DISABLED) |
---|
| 516 | charmInfo->GetActionBarEntry(i)->SpellOrAction = 0; |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | // relearn pet passives |
---|
| 520 | pet->LearnPetPassives(); |
---|
| 521 | |
---|
| 522 | pet->m_resetTalentsTime = time(NULL); |
---|
| 523 | pet->m_resetTalentsCost = cost; |
---|
| 524 | GetPlayer()->ModifyMoney(-(int32)cost); |
---|
| 525 | |
---|
| 526 | GetPlayer()->PetSpellInitialize(); |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | void WorldSession::HandlePetSpellAutocastOpcode( WorldPacket& recvPacket ) |
---|
| 530 | { |
---|
| 531 | CHECK_PACKET_SIZE(recvPacket,8+2+2+1); |
---|
| 532 | |
---|
| 533 | sLog.outDetail("CMSG_PET_SPELL_AUTOCAST"); |
---|
| 534 | uint64 guid; |
---|
| 535 | uint16 spellid; |
---|
| 536 | uint16 spellid2; //maybe second spell, automatically toggled off when first toggled on? |
---|
| 537 | uint8 state; //1 for on, 0 for off |
---|
| 538 | recvPacket >> guid >> spellid >> spellid2 >> state; |
---|
| 539 | |
---|
| 540 | if(!_player->GetPet() && !_player->GetCharm()) |
---|
| 541 | return; |
---|
| 542 | |
---|
| 543 | if(ObjectAccessor::FindPlayer(guid)) |
---|
| 544 | return; |
---|
| 545 | |
---|
| 546 | Creature* pet=ObjectAccessor::GetCreatureOrPet(*_player,guid); |
---|
| 547 | |
---|
| 548 | if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm())) |
---|
| 549 | { |
---|
| 550 | sLog.outError( "HandlePetSpellAutocastOpcode.Pet %u isn't pet of player %s .\n", uint32(GUID_LOPART(guid)),GetPlayer()->GetName() ); |
---|
| 551 | return; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | // do not add not learned spells/ passive spells |
---|
| 555 | if(!pet->HasSpell(spellid) || IsPassiveSpell(spellid)) |
---|
| 556 | return; |
---|
| 557 | |
---|
| 558 | CharmInfo *charmInfo = pet->GetCharmInfo(); |
---|
| 559 | if(!charmInfo) |
---|
| 560 | { |
---|
| 561 | sLog.outError("WorldSession::HandlePetSpellAutocastOpcod: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID()); |
---|
| 562 | return; |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | if(pet->isCharmed()) |
---|
| 566 | //state can be used as boolean |
---|
| 567 | pet->GetCharmInfo()->ToggleCreatureAutocast(spellid, state); |
---|
| 568 | else |
---|
| 569 | ((Pet*)pet)->ToggleAutocast(spellid, state); |
---|
| 570 | |
---|
| 571 | for(uint8 i = 0; i < 10; ++i) |
---|
| 572 | { |
---|
| 573 | if((charmInfo->GetActionBarEntry(i)->Type == ACT_ENABLED || charmInfo->GetActionBarEntry(i)->Type == ACT_DISABLED) && spellid == charmInfo->GetActionBarEntry(i)->SpellOrAction) |
---|
| 574 | charmInfo->GetActionBarEntry(i)->Type = state ? ACT_ENABLED : ACT_DISABLED; |
---|
| 575 | } |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | void WorldSession::HandleAddDynamicTargetObsoleteOpcode( WorldPacket& recvPacket ) |
---|
| 579 | { |
---|
| 580 | sLog.outDetail("WORLD: CMSG_PET_CAST_SPELL"); |
---|
| 581 | |
---|
| 582 | CHECK_PACKET_SIZE(recvPacket,8+4); |
---|
| 583 | uint64 guid; |
---|
| 584 | uint32 spellid; |
---|
| 585 | |
---|
| 586 | recvPacket >> guid >> spellid; |
---|
| 587 | |
---|
| 588 | if(!_player->GetPet() && !_player->GetCharm()) |
---|
| 589 | return; |
---|
| 590 | |
---|
| 591 | if(ObjectAccessor::FindPlayer(guid)) |
---|
| 592 | return; |
---|
| 593 | |
---|
| 594 | Creature* pet=ObjectAccessor::GetCreatureOrPet(*_player,guid); |
---|
| 595 | |
---|
| 596 | if(!pet || (pet != _player->GetPet() && pet!= _player->GetCharm())) |
---|
| 597 | { |
---|
| 598 | sLog.outError( "HandleAddDynamicTargetObsoleteOpcode.Pet %u isn't pet of player %s .\n", uint32(GUID_LOPART(guid)),GetPlayer()->GetName() ); |
---|
| 599 | return; |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid); |
---|
| 603 | if(!spellInfo) |
---|
| 604 | { |
---|
| 605 | sLog.outError("WORLD: unknown PET spell id %i\n", spellid); |
---|
| 606 | return; |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | // do not cast not learned spells |
---|
| 610 | if(!pet->HasSpell(spellid) || IsPassiveSpell(spellid)) |
---|
| 611 | return; |
---|
| 612 | |
---|
| 613 | SpellCastTargets targets; |
---|
| 614 | if(!targets.read(&recvPacket,pet)) |
---|
| 615 | return; |
---|
| 616 | |
---|
| 617 | pet->clearUnitState(UNIT_STAT_FOLLOW); |
---|
| 618 | |
---|
| 619 | Spell *spell = new Spell(pet, spellInfo, false); |
---|
| 620 | spell->m_targets = targets; |
---|
| 621 | |
---|
| 622 | int16 result = spell->PetCanCast(NULL); |
---|
| 623 | if(result == -1) |
---|
| 624 | { |
---|
| 625 | pet->AddCreatureSpellCooldown(spellid); |
---|
| 626 | if(pet->isPet()) |
---|
| 627 | { |
---|
| 628 | Pet* p = (Pet*)pet; |
---|
| 629 | p->CheckLearning(spellid); |
---|
| 630 | //10% chance to play special pet attack talk, else growl |
---|
| 631 | //actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell |
---|
| 632 | if(p->getPetType() == SUMMON_PET && (urand(0, 100) < 10)) |
---|
| 633 | pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); |
---|
| 634 | else |
---|
| 635 | pet->SendPetAIReaction(guid); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | spell->prepare(&(spell->m_targets)); |
---|
| 639 | } |
---|
| 640 | else |
---|
| 641 | { |
---|
| 642 | pet->SendPetCastFail(spellid, result); |
---|
| 643 | if(!pet->HasSpellCooldown(spellid)) |
---|
| 644 | pet->SendPetClearCooldown(spellid); |
---|
| 645 | |
---|
| 646 | spell->finish(false); |
---|
| 647 | delete spell; |
---|
| 648 | } |
---|
| 649 | } |
---|