--HG--
branch : trunk
This commit is contained in:
megamage
2009-02-24 21:14:00 -06:00
10 changed files with 244 additions and 379 deletions

View File

@@ -1670,6 +1670,8 @@ void Creature::setDeathState(DeathState s)
}
if(s == JUST_ALIVED)
{
if(isPet())
setActive(true);
SetHealth(GetMaxHealth());
SetLootRecipient(NULL);
Unit::setDeathState(ALIVE);

View File

@@ -195,13 +195,21 @@ bool ChatHandler::HandleSendOpcodeCommand(const char* /*args*/)
data.append(unit->GetPackGUID());
}
else if(type == "myguid")
{
data.append(player->GetPackGUID());
}
else if(type == "pos")
{
data << unit->GetPositionX();
data << unit->GetPositionY();
data << unit->GetPositionZ();
}
else if(type == "mypos")
{
data << player->GetPositionX();
data << player->GetPositionY();
data << player->GetPositionZ();
}
else
{
sLog.outDebug("Sending opcode: unknown type '%s'", type.c_str());

View File

@@ -96,24 +96,32 @@ struct TRINITY_DLL_DECL CoordPair
{
if( x_coord >= val )
x_coord -= val;
else
x_coord = 0;
}
void operator>>(const uint32 val)
{
if( x_coord+val < LIMIT )
x_coord += val;
else
x_coord = LIMIT - 1;
}
void operator-=(const uint32 val)
{
if( y_coord >= val )
y_coord -= val;
else
y_coord = 0;
}
void operator+=(const uint32 val)
{
if( y_coord+val < LIMIT )
y_coord += val;
else
y_coord = LIMIT - 1;
}
uint32 x_coord;

View File

@@ -6502,21 +6502,21 @@ when attempting to use the PointMovementGenerator
*/
bool ChatHandler::HandleComeToMeCommand(const char *args)
{
Creature* caster = getSelectedCreature();
if(!caster)
{
SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
char* newFlagStr = strtok((char*)args, " ");
if(!newFlagStr)
return false;
uint32 newFlags = atoi(newFlagStr);
uint32 newFlags = (uint32)strtoul(newFlagStr, NULL, 0);
Creature* caster = getSelectedCreature();
if(!caster)
{
m_session->GetPlayer()->SetUnitMovementFlags(newFlags);
SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
caster->SetUnitMovementFlags(newFlags);

View File

@@ -474,6 +474,8 @@ Map::Add(T *obj)
AddToGrid(obj,grid,cell);
obj->AddToWorld();
if(obj->isActive())
AddActiveObject(obj);
DEBUG_LOG("Object %u enters grid[%u,%u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());
@@ -799,6 +801,8 @@ Map::Remove(T *obj, bool remove)
assert( grid != NULL );
obj->RemoveFromWorld();
if(obj->isActive())
RemoveActiveObject(obj);
RemoveFromGrid(obj,grid,cell);
UpdateObjectVisibility(obj,cell,p);

View File

@@ -1103,12 +1103,6 @@ WorldObject::WorldObject()
m_isActive = false;
}
WorldObject::~WorldObject()
{
if(m_isActive && !isType(TYPEMASK_PLAYER) && IsInWorld())
GetMap()->RemoveActiveObject(this);
}
void WorldObject::setActive(bool isActive)
{
// if already in the same activity state as we try to set, do nothing
@@ -1125,20 +1119,6 @@ void WorldObject::setActive(bool isActive)
}
}
void WorldObject::AddToWorld()
{
Object::AddToWorld();
if(m_isActive && !isType(TYPEMASK_PLAYER))
GetMap()->AddActiveObject(this);
}
void WorldObject::RemoveFromWorld()
{
if(m_isActive && IsInWorld() && !isType(TYPEMASK_PLAYER))
GetMap()->RemoveActiveObject(this);
Object::RemoveFromWorld();
}
void WorldObject::_Create( uint32 guidlow, HighGuid guidhigh, uint32 mapid, uint32 phaseMask )
{
Object::_Create(guidlow, 0, guidhigh);
@@ -1615,42 +1595,110 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, uint32 duration)
{
Pet* pCreature = new Pet(petType);
Pet* pet = new Pet(petType);
if(petType == SUMMON_PET && pet->LoadPetFromDB(this, entry))
{
// Remove Demonic Sacrifice auras (known pet)
Unit::AuraList const& auraClassScripts = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
{
if((*itr)->GetModifier()->m_miscvalue==2228)
{
RemoveAurasDueToSpell((*itr)->GetId());
itr = auraClassScripts.begin();
}
else
++itr;
}
if(duration > 0)
pet->SetDuration(duration);
return NULL;
}
// petentry==0 for hunter "call pet" (current pet summoned if any)
if(!entry)
{
delete pet;
return NULL;
}
Map *map = GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();
if(!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, GetPhaseMask(), entry, pet_number))
if(!pet->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, GetPhaseMask(), entry, pet_number))
{
sLog.outError("no such creature entry %u", entry);
delete pCreature;
delete pet;
return NULL;
}
pCreature->Relocate(x, y, z, ang);
pet->Relocate(x, y, z, ang);
if(!pCreature->IsPositionValid())
if(!pet->IsPositionValid())
{
sLog.outError("ERROR: Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY());
delete pCreature;
sLog.outError("ERROR: Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",pet->GetGUIDLow(),pet->GetEntry(),pet->GetPositionX(),pet->GetPositionY());
delete pet;
return NULL;
}
pet->SetOwnerGUID(GetGUID());
pet->SetCreatorGUID(GetGUID());
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction());
// this enables pet details window (Shift+P)
pet->GetCharmInfo()->SetPetNumber(pet_number, false);
pet->AIM_Initialize();
map->Add((Creature*)pet);
pet->setPowerType(POWER_MANA);
pet->SetUInt32Value(UNIT_NPC_FLAGS , 0);
pet->SetUInt32Value(UNIT_FIELD_BYTES_1,0);
pet->InitStatsForLevel(getLevel());
switch(petType)
{
case GUARDIAN_PET:
case POSSESSED_PET:
pet->SetUInt32Value(UNIT_FIELD_FLAGS,0);
AddGuardian(pet);
break;
case SUMMON_PET:
pet->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
pet->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
pet->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
pet->SetHealth(pet->GetMaxHealth());
pet->SetPower(POWER_MANA, pet->GetMaxPower(POWER_MANA));
pet->InitPetCreateSpells();
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
SetPet(pet);
PetSpellInitialize();
break;
}
if(petType == SUMMON_PET)
{
// Remove Demonic Sacrifice auras (known pet)
Unit::AuraList const& auraClassScripts = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
{
if((*itr)->GetModifier()->m_miscvalue==2228)
{
RemoveAurasDueToSpell((*itr)->GetId());
itr = auraClassScripts.begin();
}
else
++itr;
}
}
if(duration > 0)
pCreature->SetDuration(duration);
pet->SetDuration(duration);
pCreature->SetOwnerGUID(GetGUID());
pCreature->SetCreatorGUID(GetGUID());
pCreature->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction());
pCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
pCreature->AIM_Initialize();
map->Add((Creature*)pCreature);
AddGuardian(pCreature);
return pCreature;
return pet;
}
GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime)

View File

@@ -358,11 +358,7 @@ class TRINITY_DLL_SPEC Object
class TRINITY_DLL_SPEC WorldObject : public Object
{
public:
virtual ~WorldObject ( );
virtual void AddToWorld();
virtual void RemoveFromWorld();
virtual ~WorldObject ( ) {}
virtual void Update ( uint32 /*time_diff*/ ) { }

View File

@@ -22,7 +22,10 @@
#include "MapManager.h"
#include "RandomMovementGenerator.h"
#include "Traveller.h"
#include "ObjectAccessor.h"
#include "DestinationHolderImp.h"
#include "Map.h"
#include "Util.h"
#define RUNNING_CHANCE_RANDOMMV 20 //will be "1 / RUNNING_CHANCE_RANDOMMV"
@@ -31,9 +34,9 @@ bool
RandomMovementGenerator<Creature>::GetDestination(float &x, float &y, float &z) const
{
if(i_destinationHolder.HasArrived())
return false;
i_destinationHolder.GetDestination(x, y, z);
return false;
i_destinationHolder.GetDestination(x, y, z);
return true;
}
@@ -41,96 +44,76 @@ template<>
void
RandomMovementGenerator<Creature>::_setRandomLocation(Creature &creature)
{
float i_x,i_y,i_z,n_x,n_y,n_z,ori,dist;
creature.GetHomePosition(i_x,i_y,i_z,ori);
float X,Y,Z,z,nx,ny,nz,ori,dist;
const float angle = 2*M_PI*rand_norm();
const float range = rand_norm()*wander_dist;
const float distX = range*cos(angle);
const float distY = range*sin(angle);
creature.GetHomePosition(X, Y, Z, ori);
n_x = i_x + distX;
n_y = i_y + distY;
z = creature.GetPositionZ();
uint32 mapid=creature.GetMapId();
Map const* map = MapManager::Instance().GetBaseMap(mapid);
Trinity::NormalizeMapCoord(n_x);
Trinity::NormalizeMapCoord(n_y);
// For 2D/3D system selection
bool is_land_ok = creature.canWalk();
bool is_water_ok = creature.canSwim();
bool is_air_ok = creature.canFly();
Map const* map = MapManager::Instance().GetBaseMap(creature.GetMapId());
const float angle = rand_norm()*(M_PI*2);
const float range = rand_norm()*wander_distance;
const float distanceX = range * cos(angle);
const float distanceY = range * sin(angle);
switch(_InhabitType)
nx = X + distanceX;
ny = Y + distanceY;
// prevent invalid coordinates generation
Trinity::NormalizeMapCoord(nx);
Trinity::NormalizeMapCoord(ny);
dist = (nx - X)*(nx - X) + (ny - Y)*(ny - Y);
if (is_air_ok) // 3D system above ground and above water (flying mode)
{
case INHABIT_AIR:
{
//don't use normalized n_x, n_y because difference is too small.. and this is random movement
dist = sqrtf(distX*distX + distY*distY);
const float distanceZ = rand_norm() * dist/2; // Limit height change
n_z = i_z + distanceZ;
float tz = map->GetHeight(n_x,n_y,n_z - 2.0f,false);
if (tz >= n_z || ground >= n_z)
return;
//creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
break;
const float distanceZ = rand_norm() * sqrtf(dist)/2; // Limit height change
nz = Z + distanceZ;
float tz = map->GetHeight(nx, ny, nz-2.0f, false); // Map check only, vmap needed here but need to alter vmaps checks for height.
float wz = map->GetWaterLevel(nx, ny);
if (tz >= nz || wz >= nz)
return; // Problem here, we must fly above the ground and water, not under. Let's try on next tick
}
case INHABIT_WATER:
//else if (is_water_ok) // 3D system under water and above ground (swimming mode)
else // 2D only
{
//some small creatures can swim above water level
float water = map->GetWaterLevel(n_x,n_y) - 1.8f;
float floor = map->GetHeight(n_x,n_y,i_z,false) + 0.2f;
if (water - floor < 0)
return;
float z_diff = 2 * 1.192*creature.GetDistance2d(n_x,n_y); //1.192 = tan(50)
//if(water - floor > z_diff){
n_z = z_diff*(1 - 2*rand_norm()) + creature.GetPositionZ();
n_z = n_z > water ? water : n_z;
n_z = n_z < floor ? floor : n_z;
//}else
//n_z = floor + rand_norm()*(water - floor);
//creature.AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
break;
}
case INHABIT_GROUND:
{
dist = (distX*distX + distY*distY);
dist = dist>=100.0f ? 10.0f : sqrtf(dist); // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
n_z = map->GetHeight(n_x,n_y,i_z,false);
if (fabs(n_z - i_z) > dist)
// The fastest way to get an accurate result 90% of the time.
// Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
nz = map->GetHeight(nx,ny,Z+dist-2.0f,false); // Map check
if (fabs(nz-Z)>dist)
{
n_z = map->GetHeight(n_x,n_y,i_z,true); // Vmap Horizontal or above
if (fabs(n_z - i_z) > dist)
nz = map->GetHeight(nx,ny,Z-2.0f,true); // Vmap Horizontal or above
if (fabs(nz-Z)>dist)
{
n_z = map->GetHeight(n_x,n_y,i_z + 8.0f,true); // Vmap Higher
if (fabs(n_z - i_z) > dist)
return;
nz = map->GetHeight(nx,ny,Z+dist-2.0f,true); // Vmap Higher
if (fabs(nz-Z)>dist)
return; // let's forget this bad coords where a z cannot be find and retry at next tick
}
}
if (!irand(0,RUNNING_CHANCE_RANDOMMV))
creature.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
else
creature.AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
break;
}
default:
n_z = i_z;
break;
}
Traveller<Creature> traveller(creature);
creature.SetOrientation(creature.GetAngle(n_x,n_y));
i_destinationHolder.SetDestination(traveller,n_x,n_y,n_z);
creature.SetOrientation(creature.GetAngle(nx,ny));
i_destinationHolder.SetDestination(traveller, nx, ny, nz);
creature.addUnitState(UNIT_STAT_ROAMING);
switch(_InhabitType)
{
case INHABIT_AIR:
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
break;
case INHABIT_WATER:
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime() + urand(500,3000));
break;
default:
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime() + urand(500,5000));
break;
}
if (is_air_ok)
{
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
}
//else if (is_water_ok) // Swimming mode to be done with more than this check
else
{
i_nextMoveTime.Reset(urand(500+i_destinationHolder.GetTotalTravelTime(),5000+i_destinationHolder.GetTotalTravelTime()));
creature.SetUnitMovementFlags(MOVEMENTFLAG_WALK_MODE);
}
}
template<>
@@ -140,47 +123,13 @@ RandomMovementGenerator<Creature>::Initialize(Creature &creature)
if(!creature.isAlive())
return;
wander_dist = creature.GetRespawnRadius();
Map const* map = MapManager::Instance().GetBaseMap(creature.GetMapId());
wander_distance = creature.GetRespawnRadius();
_InhabitType = creature.GetCreatureInfo()->InhabitType;
// Let's select only one movement type
// TODO: make this check more correct
float water;
if(_InhabitType & (INHABIT_WATER | INHABIT_AIR))
water = map->GetWaterLevel(creature.GetPositionX(),creature.GetPositionY());
if(_InhabitType & INHABIT_AIR)
{
float floor = map->GetHeight(creature.GetPositionX(),creature.GetPositionY(),creature.GetPositionZ(),true);
ground = floor > water ? floor : water;
if(ground + 2.0f < creature.GetPositionZ())
{
_InhabitType = INHABIT_AIR;
creature.addUnitState(UNIT_STAT_IN_FLIGHT);
creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
i_nextMoveTime.Reset(urand(0,1000)); //to make them call _setRandomLocation not in one time
//_setRandomLocation(creature);
return;
}else
_InhabitType &= ~INHABIT_AIR;
}
if(_InhabitType & INHABIT_WATER)
{
if (water > creature.GetPositionZ()) //don't use "+2.0f" because under-water creatures already has height <= -1.9(if water level is 0)
{
_InhabitType = INHABIT_WATER;
creature.addUnitState(UNIT_STAT_IN_FLIGHT);
creature.AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
i_nextMoveTime.Reset(urand(0,1000));
//_setRandomLocation(creature);
return;
}else
_InhabitType &= ~INHABIT_WATER;
}
if(_InhabitType & INHABIT_GROUND)
i_nextMoveTime.Reset(urand(0,1000));
//_setRandomLocation(creature);
if (creature.canFly())
creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
else
creature.SetUnitMovementFlags(irand(0,RUNNING_CHANCE_RANDOMMV) > 0 ? MOVEMENTFLAG_WALK_MODE : MOVEMENTFLAG_NONE );
_setRandomLocation(creature);
}
template<>
@@ -207,7 +156,7 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
i_nextMoveTime.Update(diff);
if(i_destinationHolder.HasArrived() && !creature.IsStopped() && !(_InhabitType & (INHABIT_WATER | INHABIT_AIR)))
if(i_destinationHolder.HasArrived() && !creature.IsStopped() && !creature.canFly())
creature.clearUnitState(UNIT_STAT_ROAMING);
if(!i_destinationHolder.HasArrived() && creature.IsStopped())
@@ -217,8 +166,14 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
if( i_destinationHolder.UpdateTraveller(traveller, diff, false, true) )
{
if(i_nextMoveTime.Passed())
if(i_nextMoveTime.Passed())
{
if (creature.canFly())
creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
else
creature.SetUnitMovementFlags(irand(0,RUNNING_CHANCE_RANDOMMV) > 0 ? MOVEMENTFLAG_WALK_MODE : MOVEMENTFLAG_NONE);
_setRandomLocation(creature);
}
else if(creature.isPet() && creature.GetOwner() && creature.GetDistance(creature.GetOwner()) > PET_FOLLOW_DIST+2.5f)
{
creature.SetUnitMovementFlags(MOVEMENTFLAG_NONE);
@@ -227,3 +182,4 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
}
return true;
}

View File

@@ -30,8 +30,8 @@ class TRINITY_DLL_SPEC RandomMovementGenerator
: public MovementGeneratorMedium< T, RandomMovementGenerator<T> >
{
public:
// Wander dist is related on db spawn dist. So what if we wanna set random movement on summoned creature?!
RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_dist(spawn_dist) {}
// Wander dist is related on db spawn dist. So what if we wanna set eandom movement on summoned creature?!
RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_distance(spawn_dist) {}
void _setRandomLocation(T &);
void Initialize(T &);
@@ -48,7 +48,8 @@ class TRINITY_DLL_SPEC RandomMovementGenerator
TimeTrackerSmall i_nextMoveTime;
DestinationHolder< Traveller<T> > i_destinationHolder;
float wander_dist, ground;
uint32 _InhabitType;
float wander_distance;
uint32 i_nextMove;
};
#endif

View File

@@ -3308,37 +3308,20 @@ void Spell::EffectSummonType(uint32 i)
void Spell::EffectSummon(uint32 i)
{
if(m_caster->GetPetGUID())
return;
if(!unitTarget)
return;
uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
if(!pet_entry)
return;
uint32 level = m_caster->getLevel();
Pet* spawnCreature = new Pet(SUMMON_PET);
spawnCreature->setActive(m_caster->isActive());
if(m_caster->GetTypeId()==TYPEID_PLAYER && spawnCreature->LoadPetFromDB((Player*)m_caster,pet_entry))
if(!m_originalCaster || m_originalCaster->GetTypeId() != TYPEID_PLAYER)
{
// set timer for unsummon
int32 duration = GetSpellDuration(m_spellInfo);
if(duration > 0)
spawnCreature->SetDuration(duration);
EffectSummonWild(i);
return;
}
Map *map = m_caster->GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();
if(!spawnCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_PET),map,m_caster->GetPhaseMask(),
m_spellInfo->EffectMiscValue[i], pet_number))
{
sLog.outErrorDb("Spell::EffectSummon: no such creature entry %u",m_spellInfo->EffectMiscValue[i]);
delete spawnCreature;
Player *owner = (Player*)m_originalCaster;
if(owner->GetPetGUID())
return;
}
// Summon in dest location
float x,y,z;
@@ -3349,58 +3332,21 @@ void Spell::EffectSummon(uint32 i)
z = m_targets.m_destZ;
}
else
m_caster->GetClosePoint(x,y,z,spawnCreature->GetObjectSize());
m_caster->GetClosePoint(x,y,z,owner->GetObjectSize());
spawnCreature->Relocate(x,y,z,-m_caster->GetOrientation());
if(!spawnCreature->IsPositionValid())
{
sLog.outError("ERROR: Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
delete spawnCreature;
Pet *spawnCreature = owner->SummonPet(pet_entry, x, y, z, m_caster->GetOrientation(), SUMMON_PET, GetSpellDuration(m_spellInfo));
if(!spawnCreature)
return;
}
// set timer for unsummon
int32 duration = GetSpellDuration(m_spellInfo);
if(duration > 0)
spawnCreature->SetDuration(duration);
spawnCreature->SetOwnerGUID(m_caster->GetGUID());
spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, 0);
spawnCreature->setPowerType(POWER_MANA);
spawnCreature->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, m_caster->getFaction());
spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
spawnCreature->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
spawnCreature->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
spawnCreature->SetCreatorGUID(m_caster->GetGUID());
spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
spawnCreature->InitStatsForLevel(level);
spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
spawnCreature->AIM_Initialize();
spawnCreature->InitPetCreateSpells();
spawnCreature->SetHealth(spawnCreature->GetMaxHealth());
spawnCreature->SetPower(POWER_MANA, spawnCreature->GetMaxPower(POWER_MANA));
std::string name = m_caster->GetName();
std::string name = owner->GetName();
name.append(petTypeSuffix[spawnCreature->getPetType()]);
spawnCreature->SetName( name );
map->Add((Creature*)spawnCreature);
if(m_caster->GetTypeId() == TYPEID_PLAYER)
{
m_caster->SetPet(spawnCreature);
spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
spawnCreature->SavePetToDB(PET_SAVE_AS_CURRENT);
((Player*)m_caster)->PetSpellInitialize();
}
spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
}
void Spell::EffectLearnSpell(uint32 i)
@@ -3809,14 +3755,8 @@ void Spell::EffectSummonGuardian(uint32 i)
if(!spawnCreature)
return;
spawnCreature->setPowerType(POWER_MANA);
spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS , 0);
spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS,0);
spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1,0);
spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,0);
spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
spawnCreature->InitStatsForLevel(level);
}
}
@@ -4184,7 +4124,16 @@ void Spell::EffectTameCreature(uint32 /*i*/)
void Spell::EffectSummonPet(uint32 i)
{
if(!m_originalCaster || m_originalCaster->GetTypeId() != TYPEID_PLAYER)
Player *owner = NULL;
if(m_originalCaster)
{
if(m_originalCaster->GetTypeId() == TYPEID_PLAYER)
owner = (Player*)m_originalCaster;
else if(((Creature*)m_originalCaster)->isTotem())
owner = m_originalCaster->GetCharmerOrOwnerPlayerOrPlayerItself();
}
if(!owner)
{
EffectSummonWild(i);
return;
@@ -4192,7 +4141,7 @@ void Spell::EffectSummonPet(uint32 i)
uint32 petentry = m_spellInfo->EffectMiscValue[i];
Pet *OldSummon = m_caster->GetPet();
Pet *OldSummon = owner->GetPet();
// if pet requested type already exist
if( OldSummon )
@@ -4204,161 +4153,55 @@ void Spell::EffectSummonPet(uint32 i)
return;
OldSummon->GetMap()->Remove((Creature*)OldSummon,false);
OldSummon->SetMapId(m_caster->GetMapId());
OldSummon->SetMapId(owner->GetMapId());
float px, py, pz;
m_caster->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
owner->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation());
m_caster->GetMap()->Add((Creature*)OldSummon);
owner->GetMap()->Add((Creature*)OldSummon);
if(m_caster->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() )
if(owner->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() )
{
((Player*)m_caster)->PetSpellInitialize();
((Player*)owner)->PetSpellInitialize();
}
return;
}
if(m_caster->GetTypeId() == TYPEID_PLAYER)
((Player*)m_caster)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false);
if(owner->GetTypeId() == TYPEID_PLAYER)
((Player*)owner)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false);
else
return;
}
Pet* NewSummon = new Pet;
NewSummon->setActive(m_caster->isActive());
// petentry==0 for hunter "call pet" (current pet summoned if any)
if(m_caster->GetTypeId() == TYPEID_PLAYER && NewSummon->LoadPetFromDB((Player*)m_caster,petentry))
{
if(NewSummon->getPetType()==SUMMON_PET)
{
// Remove Demonic Sacrifice auras (known pet)
Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
{
if((*itr)->GetModifier()->m_miscvalue==2228)
{
m_caster->RemoveAurasDueToSpell((*itr)->GetId());
itr = auraClassScripts.begin();
}
else
++itr;
}
}
float x, y, z;
owner->GetClosePoint(x, y, z, owner->GetObjectSize());
Pet* pet = owner->SummonPet(petentry, x, y, z, owner->GetOrientation(), SUMMON_PET, 0);
if(!pet)
return;
}
// not error in case fail hunter call pet
if(!petentry)
{
delete NewSummon;
return;
}
CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(petentry);
if(!cInfo)
{
sLog.outError("EffectSummonPet: creature entry %u not found.",petentry);
delete NewSummon;
return;
}
Map *map = m_caster->GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();
if(!NewSummon->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
petentry, pet_number))
{
delete NewSummon;
return;
}
float px, py, pz;
m_caster->GetClosePoint(px, py, pz, NewSummon->GetObjectSize());
NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
if(!NewSummon->IsPositionValid())
{
sLog.outError("ERROR: Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
NewSummon->GetGUIDLow(), NewSummon->GetEntry(), NewSummon->GetPositionX(), NewSummon->GetPositionY());
delete NewSummon;
return;
}
uint32 petlevel = m_caster->getLevel();
NewSummon->setPetType(SUMMON_PET);
uint32 faction = m_caster->getFaction();
if(m_caster->GetTypeId() == TYPEID_UNIT)
{
if ( ((Creature*)m_caster)->isTotem() )
NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
pet->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
else
NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
}
NewSummon->SetOwnerGUID(m_caster->GetGUID());
NewSummon->SetCreatorGUID(m_caster->GetGUID());
NewSummon->SetUInt32Value(UNIT_NPC_FLAGS, 0);
NewSummon->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction);
NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
// this enables pet details window (Shift+P)
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
// this enables popup window (pet dismiss, cancel), hunter pet additional flags set later
if(m_caster->GetTypeId() == TYPEID_PLAYER)
NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
pet->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
NewSummon->InitStatsForLevel(petlevel);
NewSummon->InitPetCreateSpells();
NewSummon->InitTalentForLevel();
pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
if(NewSummon->getPetType()==SUMMON_PET)
{
// Remove Demonic Sacrifice auras (new pet)
Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
{
if((*itr)->GetModifier()->m_miscvalue==2228)
{
m_caster->RemoveAurasDueToSpell((*itr)->GetId());
itr = auraClassScripts.begin();
}
else
++itr;
}
// generate new name for summon pet
std::string new_name=objmgr.GeneratePetName(petentry);
if(!new_name.empty())
NewSummon->SetName(new_name);
}
else if(NewSummon->getPetType()==HUNTER_PET)
NewSummon->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED);
NewSummon->AIM_Initialize();
NewSummon->SetHealth(NewSummon->GetMaxHealth());
NewSummon->SetPower(POWER_MANA, NewSummon->GetMaxPower(POWER_MANA));
map->Add((Creature*)NewSummon);
m_caster->SetPet(NewSummon);
sLog.outDebug("New Pet has guid %u", NewSummon->GetGUIDLow());
if(m_caster->GetTypeId() == TYPEID_PLAYER)
{
NewSummon->SavePetToDB(PET_SAVE_AS_CURRENT);
((Player*)m_caster)->PetSpellInitialize();
}
pet->InitTalentForLevel();
// generate new name for summon pet
std::string new_name=objmgr.GeneratePetName(petentry);
if(!new_name.empty())
pet->SetName(new_name);
}
void Spell::EffectLearnPetSpell(uint32 i)
@@ -6158,7 +6001,6 @@ void Spell::EffectSummonCritter(uint32 i)
// summon new pet
Pet* critter = new Pet(MINI_PET);
critter->setActive(m_caster->isActive());
Map *map = m_caster->GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();