[11222] Move possition setup for Creature and subclases before Create call.

Some called from Create code can req. proper pos setup for creature.
Bad side: But in way how currently code orginized impossible setup excetly position for most
Creature sublasses. So in this part need more work.
This commit is contained in:
VladimirMangos 2011-03-06 12:08:55 +03:00
parent c132e54f73
commit 51b4556c4b
7 changed files with 171 additions and 105 deletions

View file

@ -1230,17 +1230,18 @@ bool Creature::LoadFromDB(uint32 guidlow, Map *map)
if (map->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, guidlow)))
return false;
if (!Create(guidlow, map, data->phaseMask, data->id, TEAM_NONE, data, eventData))
return false;
// set coordinates before call Create because some code can be depend from correct coordinates values.
Relocate(data->posX, data->posY, data->posZ, data->orientation);
if(!IsPositionValid())
if (!IsPositionValid())
{
sLog.outError("Creature (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY());
return false;
}
if (!Create(guidlow, map, data->phaseMask, data->id, TEAM_NONE, data, eventData))
return false;
m_respawnradius = data->spawndist;
m_respawnDelay = data->spawntimesecs;

View file

@ -1558,11 +1558,6 @@ bool ChatHandler::HandleNpcAddCommand(char* args)
Map *map = chr->GetMap();
Creature* pCreature = new Creature;
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id))
{
delete pCreature;
return false;
}
pCreature->Relocate(x,y,z,o);
@ -1573,6 +1568,12 @@ bool ChatHandler::HandleNpcAddCommand(char* args)
return false;
}
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id))
{
delete pCreature;
return false;
}
pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
uint32 db_guid = pCreature->GetGUIDLow();
@ -3139,29 +3140,28 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
// create the waypoint creature
wpGuid = 0;
Creature* wpCreature = new Creature;
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature;
}
else
{
wpCreature->Relocate(chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation());
if (!wpCreature->IsPositionValid())
{
sLog.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature->GetGUIDLow(),wpCreature->GetEntry(),wpCreature->GetPositionX(),wpCreature->GetPositionY());
delete wpCreature;
return false;
}
else
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature;
return false;
}
wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
wpCreature->LoadFromDB(wpCreature->GetGUIDLow(), map);
map->Add(wpCreature);
wpGuid = wpCreature->GetGUIDLow();
}
}
sWaypointMgr.AddAfterNode(lowguid, point, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), 0, 0, wpGuid);
@ -3259,12 +3259,6 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
wpCreature->AddObjectToRemoveList();
// re-create
Creature* wpCreature2 = new Creature;
if (!wpCreature2->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
wpCreature2->Relocate(chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation());
@ -3275,6 +3269,13 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
return false;
}
if (!wpCreature2->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
wpCreature2->LoadFromDB(wpCreature2->GetGUIDLow(), map);
@ -3563,13 +3564,6 @@ bool ChatHandler::HandleWpShowCommand(char* args)
float o = chr->GetOrientation();
Creature* wpCreature = new Creature;
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete wpCreature;
delete result;
return false;
}
wpCreature->Relocate(x, y, z, o);
@ -3581,6 +3575,14 @@ bool ChatHandler::HandleWpShowCommand(char* args)
return false;
}
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete wpCreature;
delete result;
return false;
}
wpCreature->SetVisibility(VISIBILITY_OFF);
DEBUG_LOG("DEBUG: UPDATE creature_movement SET wpguid = '%u", wpCreature->GetGUIDLow());
// set "wpguid" column to the visual waypoint
@ -3621,13 +3623,6 @@ bool ChatHandler::HandleWpShowCommand(char* args)
Map *map = chr->GetMap();
Creature* pCreature = new Creature;
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT),map, chr->GetPhaseMaskForSpawn(), id))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete pCreature;
delete result;
return false;
}
pCreature->Relocate(x, y, z, o);
@ -3639,6 +3634,14 @@ bool ChatHandler::HandleWpShowCommand(char* args)
return false;
}
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT),map, chr->GetPhaseMaskForSpawn(), id))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete pCreature;
delete result;
return false;
}
pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
pCreature->LoadFromDB(pCreature->GetGUIDLow(), map);
map->Add(pCreature);
@ -3681,13 +3684,6 @@ bool ChatHandler::HandleWpShowCommand(char* args)
Map *map = chr->GetMap();
Creature* pCreature = new Creature;
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id))
{
PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id);
delete pCreature;
delete result;
return false;
}
pCreature->Relocate(x, y, z, o);
@ -3699,6 +3695,14 @@ bool ChatHandler::HandleWpShowCommand(char* args)
return false;
}
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id))
{
PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id);
delete pCreature;
delete result;
return false;
}
pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
pCreature->LoadFromDB(pCreature->GetGUIDLow(), map);
map->Add(pCreature);

View file

@ -1653,6 +1653,13 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
if (GetTypeId()==TYPEID_PLAYER)
team = ((Player*)this)->GetTeam();
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if creature have creature_template_addon.auras with persistent point for example or script call
if (x == 0.0f && y == 0.0f && z == 0.0f)
GetClosePoint(x, y, z, 0);
pCreature->Relocate(x, y, z, ang);
if (!pCreature->Create(GetMap()->GenerateLocalLowGuid(HIGHGUID_UNIT), GetMap(), GetPhaseMask(), id, team))
{
delete pCreature;
@ -1660,9 +1667,11 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
}
if (x == 0.0f && y == 0.0f && z == 0.0f)
{
GetClosePoint(x, y, z, pCreature->GetObjectBoundingRadius());
pCreature->Relocate(x, y, z, ang);
}
pCreature->SetSummonPoint(x, y, z, ang);
if(!pCreature->IsPositionValid())

View file

@ -149,6 +149,13 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
return false;
}
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if pet have creature_template_addon.auras with persistent point for example or script call
float px, py, pz;
owner->GetClosePoint(px, py, pz, 0, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE, this);
Relocate(px, py, pz, owner->GetOrientation());
Map *map = owner->GetMap();
uint32 guid = map->GenerateLocalLowGuid(HIGHGUID_PET);
if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number))
@ -157,7 +164,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
return false;
}
float px, py, pz;
owner->GetClosePoint(px, py, pz, GetObjectBoundingRadius(), PET_FOLLOW_DIST, PET_FOLLOW_ANGLE, this);
Relocate(px, py, pz, owner->GetOrientation());
@ -803,17 +809,10 @@ bool Pet::CreateBaseAtCreature(Creature* creature)
{
if(!creature)
{
sLog.outError("CRITICAL: NULL pointer parsed into CreateBaseAtCreature()");
sLog.outError("CRITICAL: NULL pointer passed into CreateBaseAtCreature()");
return false;
}
uint32 guid = creature->GetMap()->GenerateLocalLowGuid(HIGHGUID_PET);
BASIC_LOG("Create pet");
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if(!Create(guid, creature->GetMap(), creature->GetPhaseMask(), creature->GetEntry(), pet_number))
return false;
Relocate(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation());
if(!IsPositionValid())
@ -823,6 +822,13 @@ bool Pet::CreateBaseAtCreature(Creature* creature)
return false;
}
uint32 guid = creature->GetMap()->GenerateLocalLowGuid(HIGHGUID_PET);
BASIC_LOG("Create pet");
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if(!Create(guid, creature->GetMap(), creature->GetPhaseMask(), creature->GetEntry(), pet_number))
return false;
CreatureInfo const *cinfo = GetCreatureInfo();
if(!cinfo)
{

View file

@ -4479,6 +4479,21 @@ void Spell::DoSummon(SpellEffectIndex eff_idx)
return;
}
// Summon in dest location
float x, y, z;
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
x = m_targets.m_destX;
y = m_targets.m_destY;
z = m_targets.m_destZ;
}
else
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if totem have creature_template_addon.auras with persistent point for example or script call
m_caster->GetClosePoint(x, y, z, 0);
spawnCreature->Relocate(x, y, z, -m_caster->GetOrientation());
Map *map = m_caster->GetMap();
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
@ -4489,18 +4504,12 @@ void Spell::DoSummon(SpellEffectIndex eff_idx)
return;
}
// Summon in dest location
float x, y, z;
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
if (!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
{
x = m_targets.m_destX;
y = m_targets.m_destY;
z = m_targets.m_destZ;
}
else
m_caster->GetClosePoint(x, y, z, spawnCreature->GetObjectBoundingRadius());
spawnCreature->Relocate(x, y, z, -m_caster->GetOrientation());
}
spawnCreature->SetSummonPoint(x, y, z, -m_caster->GetOrientation());
if (!spawnCreature->IsPositionValid())
@ -4940,16 +4949,6 @@ void Spell::DoSummonGuardian(SpellEffectIndex eff_idx, uint32 forceFaction)
{
Pet* spawnCreature = new Pet(petType);
Map *map = m_caster->GetMap();
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map,m_caster->GetPhaseMask(),
m_spellInfo->EffectMiscValue[eff_idx], pet_number))
{
sLog.outError("no such creature entry %u", m_spellInfo->EffectMiscValue[eff_idx]);
delete spawnCreature;
return;
}
float px, py, pz;
// If dest location if present
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
@ -4967,9 +4966,29 @@ void Spell::DoSummonGuardian(SpellEffectIndex eff_idx, uint32 forceFaction)
}
// Summon if dest location not present near caster
else
m_caster->GetClosePoint(px, py, pz,spawnCreature->GetObjectBoundingRadius());
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if totem have creature_template_addon.auras with persistent point for example or script call
m_caster->GetClosePoint(px, py, pz, 0);
spawnCreature->Relocate(px, py, pz, m_caster->GetOrientation());
Map *map = m_caster->GetMap();
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map,m_caster->GetPhaseMask(),
m_spellInfo->EffectMiscValue[eff_idx], pet_number))
{
sLog.outError("no such creature entry %u", m_spellInfo->EffectMiscValue[eff_idx]);
delete spawnCreature;
return;
}
// Summon if dest location not present near caster
if (!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
{
m_caster->GetClosePoint(px, py, pz,spawnCreature->GetObjectBoundingRadius());
spawnCreature->Relocate(px, py, pz, m_caster->GetOrientation());
}
spawnCreature->SetSummonPoint(px, py, pz, m_caster->GetOrientation());
if (!spawnCreature->IsPositionValid())
@ -5427,6 +5446,14 @@ void Spell::EffectSummonPet(SpellEffectIndex eff_idx)
return;
}
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if totem have creature_template_addon.auras with persistent point for example or script call
float px, py, pz;
m_caster->GetClosePoint(px, py, pz, 0);
NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
Map *map = m_caster->GetMap();
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if(!NewSummon->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
@ -5436,7 +5463,6 @@ void Spell::EffectSummonPet(SpellEffectIndex eff_idx)
return;
}
float px, py, pz;
m_caster->GetClosePoint(px, py, pz, NewSummon->GetObjectBoundingRadius());
NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
@ -7578,6 +7604,19 @@ void Spell::DoSummonTotem(SpellEffectIndex eff_idx, uint8 slot_dbc)
Totem* pTotem = new Totem;
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if totem have creature_template_addon.auras with persistent point for example or script call
float angle = slot < MAX_TOTEM_SLOT ? M_PI_F/MAX_TOTEM_SLOT - (slot*2*M_PI_F/MAX_TOTEM_SLOT) : 0;
float x, y, z;
m_caster->GetClosePoint(x, y, z, 0, 2.0f, angle);
// totem must be at same Z in case swimming caster and etc.
if (fabs( z - m_caster->GetPositionZ() ) > 5)
z = m_caster->GetPositionZ();
pTotem->Relocate(x, y, z, m_caster->GetOrientation());
if (!pTotem->Create(m_caster->GetMap()->GenerateLocalLowGuid(HIGHGUID_UNIT), m_caster->GetMap(), m_caster->GetPhaseMask(),
m_spellInfo->EffectMiscValue[eff_idx], team))
{
@ -7592,9 +7631,6 @@ void Spell::DoSummonTotem(SpellEffectIndex eff_idx, uint8 slot_dbc)
pTotem->SetDisplayId(modelid_race);
}
float angle = slot < MAX_TOTEM_SLOT ? M_PI_F/MAX_TOTEM_SLOT - (slot*2*M_PI_F/MAX_TOTEM_SLOT) : 0;
float x, y, z;
m_caster->GetClosePoint(x, y, z, pTotem->GetObjectBoundingRadius(), 2.0f, angle);
// totem must be at same Z in case swimming caster and etc.
@ -8081,6 +8117,21 @@ void Spell::DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction)
// summon new pet
Pet* critter = new Pet(MINI_PET);
float x, y, z;
// If dest location if present
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
x = m_targets.m_destX;
y = m_targets.m_destY;
z = m_targets.m_destZ;
}
else
// FIXME: Setup near to finish point because GetObjectBoundingRadius set in Create but some Create calls can be dependent from proper position
// if pet have creature_template_addon.auras with persistent point for example or script call
m_caster->GetClosePoint(x, y, z, 0);
critter->Relocate(x, y, z, m_caster->GetOrientation());
Map *map = m_caster->GetMap();
uint32 pet_number = sObjectMgr.GeneratePetNumber();
if(!critter->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
@ -8091,19 +8142,12 @@ void Spell::DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction)
return;
}
float x, y, z;
// If dest location if present
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
x = m_targets.m_destX;
y = m_targets.m_destY;
z = m_targets.m_destZ;
}
// Summon if dest location not present near caster
else
if (!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
{
m_caster->GetClosePoint(x, y, z, critter->GetObjectBoundingRadius());
critter->Relocate(x, y, z, m_caster->GetOrientation());
}
critter->SetSummonPoint(x, y, z, m_caster->GetOrientation());
if(!critter->IsPositionValid())

View file

@ -664,12 +664,6 @@ bool ChatHandler::HandleDebugSpawnVehicleCommand(char* args)
return false;
Vehicle *v = new Vehicle;
Map *map = m_session->GetPlayer()->GetMap();
if (!v->Create(map->GenerateLocalLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
{
delete v;
return false;
}
float px, py, pz;
m_session->GetPlayer()->GetClosePoint(px, py, pz, m_session->GetPlayer()->GetObjectBoundingRadius());
@ -684,6 +678,14 @@ bool ChatHandler::HandleDebugSpawnVehicleCommand(char* args)
return false;
}
Map *map = m_session->GetPlayer()->GetMap();
if (!v->Create(map->GenerateLocalLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
{
delete v;
return false;
}
map->Add((Creature*)v);
return true;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11221"
#define REVISION_NR "11222"
#endif // __REVISION_NR_H__