From 629194c0e080e27dc24a6b66dc4e40671d5f5efd Mon Sep 17 00:00:00 2001 From: Blaymoira Date: Tue, 24 Feb 2009 14:50:27 +0100 Subject: Backed out changeset: aee1fec2cb04 --HG-- branch : trunk --- src/game/RandomMovementGenerator.cpp | 194 ++++++++++++++--------------------- src/game/RandomMovementGenerator.h | 9 +- 2 files changed, 80 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/game/RandomMovementGenerator.cpp b/src/game/RandomMovementGenerator.cpp index 14dae3c663f..cb748883772 100644 --- a/src/game/RandomMovementGenerator.cpp +++ b/src/game/RandomMovementGenerator.cpp @@ -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::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::_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) - { - case INHABIT_AIR: + 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) { - //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 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::Initialize(Creature &creature) if(!creature.isAlive()) return; - wander_dist = creature.GetRespawnRadius(); - Map const* map = MapManager::Instance().GetBaseMap(creature.GetMapId()); - - _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); + wander_distance = creature.GetRespawnRadius(); + + 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::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::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::Update(Creature &creature, const uint32 &diff } return true; } + diff --git a/src/game/RandomMovementGenerator.h b/src/game/RandomMovementGenerator.h index 9fba4d07326..a7105284ac6 100644 --- a/src/game/RandomMovementGenerator.h +++ b/src/game/RandomMovementGenerator.h @@ -30,8 +30,8 @@ class TRINITY_DLL_SPEC RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovementGenerator > { 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 > i_destinationHolder; - float wander_dist, ground; - uint32 _InhabitType; + float wander_distance; + uint32 i_nextMove; }; #endif + -- cgit v1.2.3 From fe5fa582752175e3e44f28416ed5e534fb11c2fb Mon Sep 17 00:00:00 2001 From: megamage Date: Tue, 24 Feb 2009 20:05:29 -0600 Subject: *Try to fix some crash bug related to grid. --HG-- branch : trunk --- src/game/Creature.cpp | 2 ++ src/game/GridDefines.h | 8 +++++++ src/game/Map.cpp | 4 ++++ src/game/Object.cpp | 65 ++++++++++++++++++++++---------------------------- src/game/Object.h | 6 +---- 5 files changed, 44 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 0e649c66c01..ece6ea3e527 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1675,6 +1675,8 @@ void Creature::setDeathState(DeathState s) } if(s == JUST_ALIVED) { + if(isPet()) + setActive(true); SetHealth(GetMaxHealth()); SetLootRecipient(NULL); Unit::setDeathState(ALIVE); diff --git a/src/game/GridDefines.h b/src/game/GridDefines.h index 9b39702d397..cb67897329f 100644 --- a/src/game/GridDefines.h +++ b/src/game/GridDefines.h @@ -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; diff --git a/src/game/Map.cpp b/src/game/Map.cpp index cb072d93e8d..33b35c0db38 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -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); diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 6c65667c9aa..a6a4866917e 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1070,12 +1070,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 @@ -1092,20 +1086,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 ) { Object::_Create(guidlow, 0, guidhigh); @@ -1613,42 +1593,55 @@ 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)) + { + if(duration > 0) + pet->SetDuration(duration); + return NULL; + } Map *map = GetMap(); uint32 pet_number = objmgr.GeneratePetNumber(); - if(!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, entry, pet_number)) + if(!pet->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, 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; } if(duration > 0) - pCreature->SetDuration(duration); + pet->SetDuration(duration); - pCreature->SetOwnerGUID(GetGUID()); - pCreature->SetCreatorGUID(GetGUID()); - pCreature->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction()); + pet->SetOwnerGUID(GetGUID()); + pet->SetCreatorGUID(GetGUID()); + pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction()); - pCreature->GetCharmInfo()->SetPetNumber(pet_number, false); + pet->GetCharmInfo()->SetPetNumber(pet_number, false); - pCreature->AIM_Initialize(); + pet->AIM_Initialize(); - map->Add((Creature*)pCreature); + map->Add((Creature*)pet); - AddGuardian(pCreature); + switch(petType) + { + case GUARDIAN_PET: + case POSSESSED_PET: + AddGuardian(pet); + break; + } - 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) diff --git a/src/game/Object.h b/src/game/Object.h index a485f117938..0dfb63e5997 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -350,11 +350,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*/ ) { } -- cgit v1.2.3 From 0f9afd76a1308635d0dfbcffe054bf0224324251 Mon Sep 17 00:00:00 2001 From: megamage Date: Tue, 24 Feb 2009 20:52:55 -0600 Subject: *Clean up of summoning pet spells. --HG-- branch : trunk --- src/game/Object.cpp | 61 +++++++++++- src/game/SpellEffects.cpp | 242 ++++++++-------------------------------------- 2 files changed, 100 insertions(+), 203 deletions(-) (limited to 'src') diff --git a/src/game/Object.cpp b/src/game/Object.cpp index a6a4866917e..0c8d12d132a 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1597,8 +1597,29 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy 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; } @@ -1620,27 +1641,61 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy return NULL; } - if(duration > 0) - pet->SetDuration(duration); - 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) + pet->SetDuration(duration); + return pet; } diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index ac5beb11343..066252c6de8 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -3209,36 +3209,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(spawnCreature->LoadPetFromDB(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_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; @@ -3249,58 +3233,21 @@ void Spell::EffectSummon(uint32 i) z = m_targets.m_destZ; } else - m_caster->GetClosePoint(x,y,z,spawnCreature->GetObjectSize()); - - spawnCreature->Relocate(x,y,z,-m_caster->GetOrientation()); + m_caster->GetClosePoint(x,y,z,owner->GetObjectSize()); - 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) @@ -3713,14 +3660,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); } } @@ -4028,7 +3969,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; @@ -4036,7 +3986,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 ) @@ -4048,158 +3998,51 @@ 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(NewSummon->LoadPetFromDB(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; - } - } - - return; - } - - // not error in case fail hunter call pet - if(!petentry) - { - delete NewSummon; - return; - } - - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(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, 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; + 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; - } - - 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 - NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE); - - NewSummon->InitStatsForLevel(petlevel); - NewSummon->InitPetCreateSpells(); - - 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)); + pet->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE); + pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); - 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(); - } + // 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) @@ -5844,7 +5687,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(); -- cgit v1.2.3 From 8770a90bc6389d123a2716079bde40f43fc26357 Mon Sep 17 00:00:00 2001 From: megamage Date: Tue, 24 Feb 2009 21:06:12 -0600 Subject: *Update of some debug command. --HG-- branch : trunk --- src/game/Debugcmds.cpp | 22 +++++++++++++++++++++- src/game/Level3.cpp | 16 ++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/game/Debugcmds.cpp b/src/game/Debugcmds.cpp index c0f673a539a..3bf64188e34 100644 --- a/src/game/Debugcmds.cpp +++ b/src/game/Debugcmds.cpp @@ -132,8 +132,12 @@ bool ChatHandler::HandleBuyErrorCommand(const char* args) bool ChatHandler::HandleSendOpcodeCommand(const char* /*args*/) { Unit *unit = getSelectedUnit(); + Player *player = NULL; if (!unit || (unit->GetTypeId() != TYPEID_PLAYER)) - unit = m_session->GetPlayer(); + player = m_session->GetPlayer(); + else + player = (Player*)unit; + if(!unit) unit = player; std::ifstream ifs("opcode.txt"); if(ifs.bad()) @@ -192,6 +196,22 @@ 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()); diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 6a909d447ba..0dd5c7a176d 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -6433,22 +6433,22 @@ when attempting to use the PointMovementGenerator */ bool ChatHandler::HandleComeToMeCommand(const char *args) { - Creature* caster = getSelectedCreature(); + char* newFlagStr = strtok((char*)args, " "); + if(!newFlagStr) + return false; + + 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; } - char* newFlagStr = strtok((char*)args, " "); - - if(!newFlagStr) - return false; - - uint32 newFlags = atoi(newFlagStr); - caster->SetUnitMovementFlags(newFlags); Player* pl = m_session->GetPlayer(); -- cgit v1.2.3