From 9c02f476ec97ac898778e39e40f74dedab01a15d Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Fri, 20 Aug 2010 20:25:02 +0200 Subject: [PATCH] [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 --- src/game/InstanceData.h | 12 ++++++++++++ src/game/Map.cpp | 6 ++++++ src/game/Unit.cpp | 14 ++++++++++++++ src/shared/revision_nr.h | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/game/InstanceData.h b/src/game/InstanceData.h index 3eaf1d881..d45f8c99c 100644 --- a/src/game/InstanceData.h +++ b/src/game/InstanceData.h @@ -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*/) { } diff --git a/src/game/Map.cpp b/src/game/Map.cpp index c682d6785..19c8424b3 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -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); } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index fa88df47c..607709d5e 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -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; } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 8e7c1dda6..9a5d71da5 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10389" + #define REVISION_NR "10390" #endif // __REVISION_NR_H__