mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[11215] Replace direct code use in .npc tame by spell cast.
Only work different from old way: target creature despawned. So if this not expected use .respawn to it in gm mode or area respawn. Code simplification suggested originally by rsa.
This commit is contained in:
parent
9312ef7e78
commit
06fe777f82
6 changed files with 50 additions and 99 deletions
|
|
@ -2172,50 +2172,7 @@ bool ChatHandler::HandleNpcTameCommand(char* /*args*/)
|
|||
return false;
|
||||
}
|
||||
|
||||
CreatureInfo const* cInfo = creatureTarget->GetCreatureInfo();
|
||||
|
||||
if (!cInfo->isTameable(player->CanTameExoticPets()))
|
||||
{
|
||||
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->GetObjectBoundingRadius(), CONTACT_DISTANCE);
|
||||
pet->Relocate (x,y,z,M_PI_F-player->GetOrientation ());
|
||||
|
||||
// set pet to defensive mode by default (some classes can't control controlled pets in fact).
|
||||
pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
|
||||
|
||||
// calculate proper level
|
||||
uint32 level = (creatureTarget->getLevel() < (player->getLevel() - 5)) ? (player->getLevel() - 5) : creatureTarget->getLevel();
|
||||
|
||||
// prepare visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
|
||||
|
||||
// add to world
|
||||
pet->GetMap()->Add((Creature*)pet);
|
||||
|
||||
// visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
|
||||
|
||||
// caster have pet now
|
||||
player->SetPet(pet);
|
||||
|
||||
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
|
||||
player->PetSpellInitialize();
|
||||
|
||||
player->CastSpell(creatureTarget, 13481, true); // Tame Beast, triggered effect
|
||||
return true;
|
||||
}
|
||||
//npc phasemask handling
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include "VMapFactory.h"
|
||||
#include "BattleGround.h"
|
||||
#include "Util.h"
|
||||
#include "Chat.h"
|
||||
|
||||
#define SPELL_CHANNEL_UPDATE_INTERVAL (1 * IN_MILLISECONDS)
|
||||
|
||||
|
|
@ -5003,7 +5004,15 @@ SpellCastResult Spell::CheckCast(bool strict)
|
|||
|
||||
Player* plrCaster = (Player*)caster;
|
||||
|
||||
if(plrCaster->getClass() != CLASS_HUNTER)
|
||||
bool gmmode = m_triggeredBySpellInfo == NULL;
|
||||
|
||||
if (gmmode && !ChatHandler(plrCaster).FindCommand("npc tame"))
|
||||
{
|
||||
plrCaster->SendPetTameFailure(PETTAME_UNKNOWNERROR);
|
||||
return SPELL_FAILED_DONT_REPORT;
|
||||
}
|
||||
|
||||
if(plrCaster->getClass() != CLASS_HUNTER && !gmmode)
|
||||
{
|
||||
plrCaster->SendPetTameFailure(PETTAME_UNITSCANTTAME);
|
||||
return SPELL_FAILED_DONT_REPORT;
|
||||
|
|
@ -5017,13 +5026,13 @@ SpellCastResult Spell::CheckCast(bool strict)
|
|||
return SPELL_FAILED_DONT_REPORT;
|
||||
}
|
||||
|
||||
if (target->getLevel() > plrCaster->getLevel())
|
||||
if (target->getLevel() > plrCaster->getLevel() && !gmmode)
|
||||
{
|
||||
plrCaster->SendPetTameFailure(PETTAME_TOOHIGHLEVEL);
|
||||
return SPELL_FAILED_DONT_REPORT;
|
||||
}
|
||||
|
||||
if (target->GetCreatureInfo()->IsExotic() && !plrCaster->CanTameExoticPets())
|
||||
if (target->GetCreatureInfo()->IsExotic() && !plrCaster->CanTameExoticPets() && !gmmode)
|
||||
{
|
||||
plrCaster->SendPetTameFailure(PETTAME_CANTCONTROLEXOTIC);
|
||||
return SPELL_FAILED_DONT_REPORT;
|
||||
|
|
|
|||
|
|
@ -5312,15 +5312,47 @@ void Spell::EffectTameCreature(SpellEffectIndex /*eff_idx*/)
|
|||
//SendChannelUpdate(0);
|
||||
finish();
|
||||
|
||||
Pet* pet = plr->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
|
||||
if(!pet) // in versy specific state like near world end/etc.
|
||||
Pet* pet = new Pet(HUNTER_PET);
|
||||
|
||||
if(!pet->CreateBaseAtCreature(creatureTarget))
|
||||
{
|
||||
delete pet;
|
||||
return;
|
||||
}
|
||||
|
||||
pet->SetOwnerGuid(plr->GetObjectGuid());
|
||||
pet->SetCreatorGuid(plr->GetObjectGuid());
|
||||
pet->setFaction(plr->getFaction());
|
||||
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
|
||||
pet->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
|
||||
|
||||
if (pet->IsPvP())
|
||||
pet->SetPvP(true);
|
||||
|
||||
if (pet->IsFFAPvP())
|
||||
pet->SetFFAPvP(true);
|
||||
|
||||
// level of hunter pet can't be less owner level at 5 levels
|
||||
uint32 level = creatureTarget->getLevel() + 5 < plr->getLevel() ? (plr->getLevel() - 5) : creatureTarget->getLevel();
|
||||
|
||||
if (!pet->InitStatsForLevel(level))
|
||||
{
|
||||
sLog.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!", creatureTarget->GetEntry());
|
||||
delete pet;
|
||||
return;
|
||||
}
|
||||
|
||||
pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
|
||||
// this enables pet details window (Shift+P)
|
||||
pet->AIM_Initialize();
|
||||
pet->InitPetCreateSpells();
|
||||
pet->InitLevelupSpellsForLevel();
|
||||
pet->InitTalentForLevel();
|
||||
pet->SetHealth(pet->GetMaxHealth());
|
||||
|
||||
// "kill" original creature
|
||||
creatureTarget->ForcedDespawn();
|
||||
|
||||
uint32 level = (creatureTarget->getLevel() < (plr->getLevel() - 5)) ? (plr->getLevel() - 5) : creatureTarget->getLevel();
|
||||
|
||||
// prepare visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -10397,51 +10397,6 @@ void Unit::RemovePetAura(PetAura const* petSpell)
|
|||
pet->RemoveAurasDueToSpell(petSpell->GetAura(pet->GetEntry()));
|
||||
}
|
||||
|
||||
Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id)
|
||||
{
|
||||
Pet* pet = new Pet(HUNTER_PET);
|
||||
|
||||
if(!pet->CreateBaseAtCreature(creatureTarget))
|
||||
{
|
||||
delete pet;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pet->SetOwnerGuid(GetObjectGuid());
|
||||
pet->SetCreatorGuid(GetObjectGuid());
|
||||
pet->setFaction(getFaction());
|
||||
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id);
|
||||
|
||||
if(GetTypeId()==TYPEID_PLAYER)
|
||||
pet->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
|
||||
|
||||
if(IsPvP())
|
||||
pet->SetPvP(true);
|
||||
|
||||
if(IsFFAPvP())
|
||||
pet->SetFFAPvP(true);
|
||||
|
||||
// level of hunter pet can't be less owner level at 5 levels
|
||||
uint32 level = creatureTarget->getLevel() + 5 < getLevel() ? (getLevel() - 5) : creatureTarget->getLevel();
|
||||
|
||||
if(!pet->InitStatsForLevel(level))
|
||||
{
|
||||
sLog.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget->GetEntry());
|
||||
delete pet;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
|
||||
// this enables pet details window (Shift+P)
|
||||
pet->AIM_Initialize();
|
||||
pet->InitPetCreateSpells();
|
||||
pet->InitLevelupSpellsForLevel();
|
||||
pet->InitTalentForLevel();
|
||||
pet->SetHealth(pet->GetMaxHealth());
|
||||
|
||||
return pet;
|
||||
}
|
||||
|
||||
void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask, uint32 exceptSpellId, bool non_positive /*= false*/)
|
||||
{
|
||||
Unit::SpellAuraHolderMap& auras = GetSpellAuraHolderMap();
|
||||
|
|
|
|||
|
|
@ -1552,8 +1552,6 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
|
|||
CharmInfo* GetCharmInfo() { return m_charmInfo; }
|
||||
CharmInfo* InitCharmInfo(Unit* charm);
|
||||
|
||||
Pet* CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id = 0);
|
||||
|
||||
uint64 const& GetTotemGUID(TotemSlot slot) const { return m_TotemSlot[slot]; }
|
||||
Totem* GetTotem(TotemSlot slot) const;
|
||||
bool IsAllTotemSlotsUsed() const;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "11214"
|
||||
#define REVISION_NR "11215"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue