diff options
| author | megamage <none@none> | 2009-05-30 22:15:05 -0500 |
|---|---|---|
| committer | megamage <none@none> | 2009-05-30 22:15:05 -0500 |
| commit | 8d1f4f9ea0beb503e2a3014abb95263e501ef1c5 (patch) | |
| tree | 41d48951c315129dee817befa40d4dab90d3fd14 /src/game/Creature.cpp | |
| parent | b5778357d9d8c5fb10da5d99c46b48250578cb49 (diff) | |
*Provide another way to implement dynamic spawns. Now a creature will call its zonescript before spawn to determine the spawned entry. This can be used to implement zones such as wintergrasp with less data requirement (only need to know the entry of counterpart creatures, not require spawn points)
*Use zonescript as basic class of opvp script and dugeon script (can also be used for bg)
*Store zonescript in worldobject.
*Add door for sapphiron.
--HG--
branch : trunk
Diffstat (limited to 'src/game/Creature.cpp')
| -rw-r--r-- | src/game/Creature.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index fc5b0436867..01a3b057ce9 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -174,6 +174,8 @@ void Creature::AddToWorld() ///- Register the creature for guid lookup if(!IsInWorld()) { + if(m_zoneScript) + m_zoneScript->OnCreatureCreate(this, true); ObjectAccessor::Instance().AddObject(this); Unit::AddToWorld(); SearchFormationAndPath(); @@ -185,9 +187,8 @@ void Creature::RemoveFromWorld() { if(IsInWorld()) { - if(Map *map = FindMap()) - if(map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData()) - ((InstanceMap*)map)->GetInstanceData()->OnCreatureCreate(this, false); + if(m_zoneScript) + m_zoneScript->OnCreatureCreate(this, false); if(m_formation) formation_mgr.RemoveCreatureFromGroup(m_formation, this); Unit::RemoveFromWorld(); @@ -694,8 +695,15 @@ void Creature::Motion_Initialize() i_motionMaster.Initialize(); } -bool Creature::Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data) +bool Creature::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, float x, float y, float z, float ang, const CreatureData *data) { + Relocate(x, y, z, ang); + if(!IsPositionValid()) + { + sLog.outError("Creature (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",guidlow,Entry,x,y); + return false; + } + SetMapId(map->GetId()); SetInstanceId(map->GetInstanceId()); SetPhaseMask(phaseMask,false); @@ -1440,12 +1448,21 @@ float Creature::GetSpellDamageMod(int32 Rank) bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 team, const CreatureData *data) { + SetZoneScript(); + if(m_zoneScript) + { + Entry = m_zoneScript->GetCreatureEntry(guidlow, Entry); + if(!Entry) + return false; + } + CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(Entry); if(!cinfo) { sLog.outErrorDb("Creature entry %u does not exist.", Entry); return false; } + m_originalEntry = Entry; if(isVehicle()) @@ -1456,15 +1473,6 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 team, const if(!UpdateEntry(Entry, team, data)) return false; - //Notify the map's instance data. - //Only works if you create the object in it, not if it is moves to that map. - //Normally non-players do not teleport to other maps. - Map *map = FindMap(); - if(map && map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData()) - { - ((InstanceMap*)map)->GetInstanceData()->OnCreatureCreate(this, true); - } - return true; } @@ -1486,16 +1494,9 @@ bool Creature::LoadFromDB(uint32 guid, Map *map) if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT); uint16 team = 0; - if(!Create(guid,map,data->phaseMask,data->id,team,data)) + if(!Create(guid,map,data->phaseMask,data->id,team,data->posX,data->posY,data->posZ,data->orientation,data)) return false; - Relocate(data->posX,data->posY,data->posZ,data->orientation); - - 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; - } //We should set first home position, because then AI calls home movement SetHomePosition(data->posX,data->posY,data->posZ,data->orientation); |
