[10390] Add several new script calls for InstanceData

OnCreature Evade/Death/EnterCombat and in addition OnPlayerLeave
The functions are intended to help doing instance related tasks (in other words, not for the general AI of creatures).

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-08-20 20:25:02 +02:00
parent 1fd4ff3155
commit 9c02f476ec
4 changed files with 33 additions and 1 deletions

View file

@ -57,12 +57,24 @@ class MANGOS_DLL_SPEC InstanceData
//Called when a player successfully enters the instance (after really added to map)
virtual void OnPlayerEnter(Player *) {}
//Called when a player leaves the instance (before really removed from map (or possibly world))
virtual void OnPlayerLeave(Player *) {}
//Called when a gameobject is created
virtual void OnObjectCreate(GameObject *) {}
//called on creature creation
virtual void OnCreatureCreate(Creature * /*creature*/) {}
//called on creature enter combat
virtual void OnCreatureEnterCombat(Creature * /*creature*/) {}
//called on creature evade
virtual void OnCreatureEvade(Creature * /*creature*/) {}
//called on creature death
virtual void OnCreatureDeath(Creature * /*creature*/) {}
//All-purpose data storage 64 bit
virtual uint64 GetData64(uint32 /*Data*/) { return 0; }
virtual void SetData64(uint32 /*Data*/, uint64 /*Value*/) { }

View file

@ -1824,10 +1824,16 @@ void BattleGroundMap::Update(const uint32& diff)
void InstanceMap::Remove(Player *player, bool remove)
{
DETAIL_LOG("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName());
//if last player set unload timer
if(!m_unloadTimer && m_mapRefManager.getSize() == 1)
m_unloadTimer = m_unloadWhenEmpty ? MIN_UNLOAD_DELAY : std::max(sWorld.getConfig(CONFIG_UINT32_INSTANCE_UNLOAD_DELAY), (uint32)MIN_UNLOAD_DELAY);
if (i_data)
i_data->OnPlayerLeave(player);
Map::Remove(player, remove);
// for normal instances schedule the reset after all players have left
SetResetSchedule(true);
}

View file

@ -41,6 +41,7 @@
#include "Util.h"
#include "Totem.h"
#include "BattleGround.h"
#include "InstanceData.h"
#include "InstanceSaveMgr.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
@ -814,6 +815,9 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
((Creature*)pOwner)->AI()->SummonedCreatureJustDied(cVictim);
}
if (InstanceData* mapInstance = cVictim->GetInstanceData())
mapInstance->OnCreatureDeath(cVictim);
// Dungeon specific stuff, only applies to players killing creatures
if(cVictim->GetInstanceId())
{
@ -7470,6 +7474,9 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy)
if (((Creature*)this)->AI())
((Creature*)this)->AI()->EnterCombat(enemy);
if (InstanceData* mapInstance = this->GetInstanceData())
mapInstance->OnCreatureEnterCombat((Creature*)this);
}
}
@ -8329,6 +8336,10 @@ void Unit::TauntFadeOut(Unit *taunter)
{
if(((Creature*)this)->AI())
((Creature*)this)->AI()->EnterEvadeMode();
if (InstanceData* mapInstance = this->GetInstanceData())
mapInstance->OnCreatureEvade((Creature*)this);
return;
}
@ -8424,6 +8435,9 @@ bool Unit::SelectHostileTarget()
// enter in evade mode in other case
((Creature*)this)->AI()->EnterEvadeMode();
if (InstanceData* mapInstance = this->GetInstanceData())
mapInstance->OnCreatureEvade((Creature*)this);
return false;
}

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10389"
#define REVISION_NR "10390"
#endif // __REVISION_NR_H__