2010-10-07 15:35:36 +02:00
/*
2012-12-31 23:15:50 +01:00
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2009-05-06 15:36:55 +02:00
#include "Creature.h"
2009-05-16 14:49:30 -05:00
#include "CreatureAI.h"
2012-11-20 12:30:30 +01:00
#include "DatabaseEnv.h"
#include "GameObject.h"
2013-01-09 15:15:42 +01:00
#include "Group.h"
2012-11-20 12:30:30 +01:00
#include "InstanceScript.h"
2011-02-03 22:20:40 +01:00
#include "LFGMgr.h"
2012-11-20 12:30:30 +01:00
#include "Log.h"
#include "Map.h"
#include "Player.h"
#include "Pet.h"
2012-11-20 14:54:33 +01:00
#include "WorldSession.h"
#include "Opcodes.h"
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
void InstanceScript :: SaveToDB ()
2008-10-02 16:23:55 -05:00
{
2009-05-11 03:17:13 -05:00
std :: string data = GetSaveData ();
2009-11-01 17:53:07 -08:00
if ( data . empty ())
2009-05-11 03:17:13 -05:00
return ;
2011-02-03 22:20:40 +01:00
2012-01-01 01:09:38 +01:00
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_INSTANCE_DATA );
2011-02-03 22:20:40 +01:00
stmt -> setUInt32 ( 0 , GetCompletedEncounterMask ());
stmt -> setString ( 1 , data );
stmt -> setUInt32 ( 2 , instance -> GetInstanceId ());
CharacterDatabase . Execute ( stmt );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: HandleGameObject ( uint64 GUID , bool open , GameObject * go )
2009-04-06 21:14:51 +02:00
{
2009-11-01 17:53:07 -08:00
if ( ! go )
2009-04-20 20:28:19 -05:00
go = instance -> GetGameObject ( GUID );
2009-11-01 17:53:07 -08:00
if ( go )
2009-04-27 18:36:10 -05:00
go -> SetGoState ( open ? GO_STATE_ACTIVE : GO_STATE_READY );
2009-04-04 18:07:05 +02:00
else
2012-08-03 14:20:18 +02:00
sLog -> outDebug ( LOG_FILTER_TSCR , "InstanceScript: HandleGameObject failed" );
2009-04-04 18:07:05 +02:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
bool InstanceScript :: IsEncounterInProgress () const
2009-05-01 18:24:12 -05:00
{
2009-10-17 16:20:24 -07:00
for ( std :: vector < BossInfo >:: const_iterator itr = bosses . begin (); itr != bosses . end (); ++ itr )
2009-11-01 17:53:07 -08:00
if ( itr -> state == IN_PROGRESS )
2009-05-01 18:24:12 -05:00
return true ;
2009-10-17 15:51:44 -07:00
2009-05-01 18:24:12 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: LoadMinionData ( const MinionData * data )
2009-05-16 14:49:30 -05:00
{
2010-04-07 19:13:19 +02:00
while ( data -> entry )
2009-05-16 14:49:30 -05:00
{
2009-11-01 17:53:07 -08:00
if ( data -> bossId < bosses . size ())
2009-05-16 14:49:30 -05:00
minions . insert ( std :: make_pair ( data -> entry , MinionInfo ( & bosses [ data -> bossId ])));
2009-10-17 15:51:44 -07:00
2009-05-16 14:49:30 -05:00
++ data ;
}
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_TSCR , "InstanceScript::LoadMinionData: " UI64FMTD " minions loaded." , uint64 ( minions . size ()));
2009-05-16 14:49:30 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: LoadDoorData ( const DoorData * data )
2009-05-01 18:24:12 -05:00
{
2010-04-07 19:13:19 +02:00
while ( data -> entry )
2009-05-01 18:24:12 -05:00
{
2009-11-01 17:53:07 -08:00
if ( data -> bossId < bosses . size ())
2009-05-17 16:37:03 -05:00
doors . insert ( std :: make_pair ( data -> entry , DoorInfo ( & bosses [ data -> bossId ], data -> type , BoundaryType ( data -> boundary ))));
2009-10-17 15:51:44 -07:00
2009-05-09 14:08:42 -05:00
++ data ;
}
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_TSCR , "InstanceScript::LoadDoorData: " UI64FMTD " doors loaded." , uint64 ( doors . size ()));
2009-05-09 14:08:42 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: UpdateMinionState ( Creature * minion , EncounterState state )
2009-05-16 14:49:30 -05:00
{
2009-11-01 17:53:07 -08:00
switch ( state )
2009-05-16 14:49:30 -05:00
{
case NOT_STARTED :
2009-11-01 17:53:07 -08:00
if ( ! minion -> isAlive ())
2009-05-16 14:49:30 -05:00
minion -> Respawn ();
2009-11-01 17:53:07 -08:00
else if ( minion -> isInCombat ())
2009-05-16 14:49:30 -05:00
minion -> AI () -> EnterEvadeMode ();
break ;
case IN_PROGRESS :
2009-11-01 17:53:07 -08:00
if ( ! minion -> isAlive ())
2009-05-16 14:49:30 -05:00
minion -> Respawn ();
2009-11-01 17:53:07 -08:00
else if ( ! minion -> getVictim ())
2009-05-16 14:49:30 -05:00
minion -> AI () -> DoZoneInCombat ();
break ;
2010-08-21 20:55:31 +02:00
default :
break ;
2009-05-16 14:49:30 -05:00
}
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: UpdateDoorState ( GameObject * door )
2009-05-09 14:08:42 -05:00
{
2013-01-02 09:53:43 +01:00
DoorInfoMapBounds range = doors . equal_range ( door -> GetEntry ());
if ( range . first == range . second )
2009-05-09 14:08:42 -05:00
return ;
2009-10-17 15:51:44 -07:00
2009-05-09 14:08:42 -05:00
bool open = true ;
2013-01-02 09:53:43 +01:00
for (; range . first != range . second && open ; ++ range . first )
2009-05-09 14:08:42 -05:00
{
2013-01-02 09:53:43 +01:00
DoorInfo const & info = range . first -> second ;
switch ( info . type )
2009-05-06 00:06:38 -05:00
{
2011-05-16 13:24:08 +02:00
case DOOR_TYPE_ROOM :
2013-01-02 09:53:43 +01:00
open = ( info . bossInfo -> state != IN_PROGRESS );
2009-05-09 14:08:42 -05:00
break ;
2011-05-16 13:24:08 +02:00
case DOOR_TYPE_PASSAGE :
2013-01-02 09:53:43 +01:00
open = ( info . bossInfo -> state == DONE );
2011-05-16 13:24:08 +02:00
break ;
case DOOR_TYPE_SPAWN_HOLE :
2013-01-02 09:53:43 +01:00
open = ( info . bossInfo -> state == IN_PROGRESS );
2011-05-16 13:24:08 +02:00
break ;
default :
2009-05-09 14:08:42 -05:00
break ;
2009-05-06 00:06:38 -05:00
}
2009-05-01 18:24:12 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-09 14:08:42 -05:00
door -> SetGoState ( open ? GO_STATE_ACTIVE : GO_STATE_READY );
2009-05-01 18:24:12 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: AddDoor ( GameObject * door , bool add )
2009-05-01 18:24:12 -05:00
{
2013-01-02 09:53:43 +01:00
DoorInfoMapBounds range = doors . equal_range ( door -> GetEntry ());
if ( range . first == range . second )
2009-05-09 14:08:42 -05:00
return ;
2009-10-17 15:51:44 -07:00
2013-01-02 09:53:43 +01:00
for (; range . first != range . second ; ++ range . first )
2009-05-01 18:24:12 -05:00
{
2013-01-02 09:53:43 +01:00
DoorInfo const & data = range . first -> second ;
2011-10-18 12:39:01 +02:00
2009-11-01 17:53:07 -08:00
if ( add )
2009-05-17 16:37:03 -05:00
{
2011-10-18 12:39:01 +02:00
data . bossInfo -> door [ data . type ]. insert ( door );
switch ( data . boundary )
2009-05-17 16:37:03 -05:00
{
default :
case BOUNDARY_NONE :
break ;
case BOUNDARY_N :
case BOUNDARY_S :
2011-10-18 12:39:01 +02:00
data . bossInfo -> boundary [ data . boundary ] = door -> GetPositionX ();
2009-05-17 16:37:03 -05:00
break ;
case BOUNDARY_E :
case BOUNDARY_W :
2011-10-18 12:39:01 +02:00
data . bossInfo -> boundary [ data . boundary ] = door -> GetPositionY ();
2009-05-17 16:37:03 -05:00
break ;
case BOUNDARY_NW :
case BOUNDARY_SE :
2011-10-18 12:39:01 +02:00
data . bossInfo -> boundary [ data . boundary ] = door -> GetPositionX () + door -> GetPositionY ();
2009-05-17 16:37:03 -05:00
break ;
case BOUNDARY_NE :
case BOUNDARY_SW :
2011-10-18 12:39:01 +02:00
data . bossInfo -> boundary [ data . boundary ] = door -> GetPositionX () - door -> GetPositionY ();
2009-05-17 16:37:03 -05:00
break ;
}
}
2009-05-06 00:06:38 -05:00
else
2011-10-18 12:39:01 +02:00
data . bossInfo -> door [ data . type ]. erase ( door );
2009-05-01 18:24:12 -05:00
}
2009-10-17 15:51:44 -07:00
2009-11-01 17:53:07 -08:00
if ( add )
2009-05-09 14:08:42 -05:00
UpdateDoorState ( door );
2009-05-01 18:24:12 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void InstanceScript :: AddMinion ( Creature * minion , bool add )
2009-05-16 14:49:30 -05:00
{
MinionInfoMap :: iterator itr = minions . find ( minion -> GetEntry ());
2009-11-01 17:53:07 -08:00
if ( itr == minions . end ())
2009-05-16 14:49:30 -05:00
return ;
2009-10-17 15:51:44 -07:00
2009-11-01 17:53:07 -08:00
if ( add )
2009-05-16 14:49:30 -05:00
itr -> second . bossInfo -> minion . insert ( minion );
else
itr -> second . bossInfo -> minion . erase ( minion );
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
bool InstanceScript :: SetBossState ( uint32 id , EncounterState state )
2009-05-01 18:24:12 -05:00
{
2009-11-01 17:53:07 -08:00
if ( id < bosses . size ())
2009-05-01 18:24:12 -05:00
{
2011-09-15 14:08:17 +02:00
BossInfo * bossInfo = & bosses [ id ];
2009-11-01 17:53:07 -08:00
if ( bossInfo -> state == TO_BE_DECIDED ) // loading
2009-05-20 11:44:38 -05:00
{
2009-05-11 03:17:13 -05:00
bossInfo -> state = state ;
2012-08-03 14:20:18 +02:00
//sLog->outError(LOG_FILTER_GENERAL, "Inialize boss %u state as %u.", id, (uint32)state);
2009-05-20 11:44:38 -05:00
return false ;
}
2009-05-11 03:17:13 -05:00
else
{
2009-11-01 17:53:07 -08:00
if ( bossInfo -> state == state )
2009-05-20 11:44:38 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-11-01 17:53:07 -08:00
if ( state == DONE )
2009-10-17 16:20:24 -07:00
for ( MinionSet :: iterator i = bossInfo -> minion . begin (); i != bossInfo -> minion . end (); ++ i )
2010-04-07 19:14:10 +02:00
if (( * i ) -> isWorldBoss () && ( * i ) -> isAlive ())
2009-05-20 11:44:38 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-05-11 03:17:13 -05:00
bossInfo -> state = state ;
SaveToDB ();
}
2009-10-17 16:20:24 -07:00
for ( uint32 type = 0 ; type < MAX_DOOR_TYPES ; ++ type )
for ( DoorSet :: iterator i = bossInfo -> door [ type ]. begin (); i != bossInfo -> door [ type ]. end (); ++ i )
2009-05-09 14:08:42 -05:00
UpdateDoorState ( * i );
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for ( MinionSet :: iterator i = bossInfo -> minion . begin (); i != bossInfo -> minion . end (); ++ i )
2009-05-16 14:49:30 -05:00
UpdateMinionState ( * i , state );
2009-10-17 15:51:44 -07:00
2009-05-20 11:44:38 -05:00
return true ;
2009-05-01 18:24:12 -05:00
}
2009-05-20 11:44:38 -05:00
return false ;
2009-05-01 18:24:12 -05:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
std :: string InstanceScript :: LoadBossState ( const char * data )
2009-05-11 03:17:13 -05:00
{
2010-04-07 19:14:10 +02:00
if ( ! data )
2009-11-01 17:53:07 -08:00
return NULL ;
2009-05-11 03:17:13 -05:00
std :: istringstream loadStream ( data );
uint32 buff ;
uint32 bossId = 0 ;
2009-10-17 16:20:24 -07:00
for ( std :: vector < BossInfo >:: iterator i = bosses . begin (); i != bosses . end (); ++ i , ++ bossId )
2009-05-11 03:17:13 -05:00
{
loadStream >> buff ;
2009-11-01 17:53:07 -08:00
if ( buff < TO_BE_DECIDED )
2009-05-11 03:17:13 -05:00
SetBossState ( bossId , ( EncounterState ) buff );
}
return loadStream . str ();
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
std :: string InstanceScript :: GetBossSaveData ()
2009-05-11 03:17:13 -05:00
{
std :: ostringstream saveStream ;
2009-10-17 16:20:24 -07:00
for ( std :: vector < BossInfo >:: iterator i = bosses . begin (); i != bosses . end (); ++ i )
2011-07-29 14:18:28 +02:00
saveStream << ( uint32 ) i -> state << ' ' ;
2009-05-11 03:17:13 -05:00
return saveStream . str ();
2009-10-17 16:20:24 -07:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoUseDoorOrButton ( uint64 uiGuid , uint32 uiWithRestoreTime , bool bUseAlternativeState )
2009-06-17 07:16:40 +02:00
{
if ( ! uiGuid )
return ;
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
GameObject * go = instance -> GetGameObject ( uiGuid );
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
if ( go )
2009-06-17 07:16:40 +02:00
{
2011-10-07 19:45:43 -05:00
if ( go -> GetGoType () == GAMEOBJECT_TYPE_DOOR || go -> GetGoType () == GAMEOBJECT_TYPE_BUTTON )
2009-06-17 07:16:40 +02:00
{
2011-10-07 19:45:43 -05:00
if ( go -> getLootState () == GO_READY )
go -> UseDoorOrButton ( uiWithRestoreTime , bUseAlternativeState );
else if ( go -> getLootState () == GO_ACTIVATED )
go -> ResetDoorOrButton ();
2009-06-17 07:16:40 +02:00
}
else
2012-08-03 14:20:18 +02:00
sLog -> outError ( LOG_FILTER_GENERAL , "SD2: Script call DoUseDoorOrButton, but gameobject entry %u is type %u." , go -> GetEntry (), go -> GetGoType ());
2009-06-17 07:16:40 +02:00
}
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoRespawnGameObject ( uint64 uiGuid , uint32 uiTimeToDespawn )
2009-06-17 07:16:40 +02:00
{
2011-10-07 19:45:43 -05:00
if ( GameObject * go = instance -> GetGameObject ( uiGuid ))
2009-06-17 07:16:40 +02:00
{
//not expect any of these should ever be handled
2011-10-07 19:45:43 -05:00
if ( go -> GetGoType () == GAMEOBJECT_TYPE_FISHINGNODE || go -> GetGoType () == GAMEOBJECT_TYPE_DOOR ||
go -> GetGoType () == GAMEOBJECT_TYPE_BUTTON || go -> GetGoType () == GAMEOBJECT_TYPE_TRAP )
2009-06-17 07:16:40 +02:00
return ;
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
if ( go -> isSpawned ())
2009-06-17 07:16:40 +02:00
return ;
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
go -> SetRespawnTime ( uiTimeToDespawn );
2009-06-17 07:16:40 +02:00
}
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoUpdateWorldState ( uint32 uiStateId , uint32 uiStateData )
2009-08-14 20:56:01 +02:00
{
Map :: PlayerList const & lPlayers = instance -> GetPlayers ();
2009-10-17 15:51:44 -07:00
2009-08-14 20:56:01 +02:00
if ( ! lPlayers . isEmpty ())
{
2009-10-17 16:20:24 -07:00
for ( Map :: PlayerList :: const_iterator itr = lPlayers . begin (); itr != lPlayers . end (); ++ itr )
2011-10-07 11:08:09 -05:00
if ( Player * player = itr -> getSource ())
player -> SendUpdateWorldState ( uiStateId , uiStateData );
2009-08-14 20:56:01 +02:00
}
else
2012-08-03 14:20:18 +02:00
sLog -> outDebug ( LOG_FILTER_TSCR , "DoUpdateWorldState attempt send data but no players in map." );
2009-08-14 20:56:01 +02:00
}
2009-10-17 15:51:44 -07:00
2009-10-16 16:45:01 -07:00
// Send Notify to all players in instance
2012-01-12 22:33:11 +01:00
void InstanceScript :: DoSendNotifyToInstance ( char const * format , ...)
2009-10-16 16:45:01 -07:00
{
2012-01-12 21:14:57 +01:00
InstanceMap :: PlayerList const & players = instance -> GetPlayers ();
2009-10-17 15:51:44 -07:00
2012-01-12 21:14:57 +01:00
if ( ! players . isEmpty ())
2010-08-30 15:25:15 +02:00
{
va_list ap ;
va_start ( ap , format );
2012-01-12 21:14:57 +01:00
char buff [ 1024 ];
vsnprintf ( buff , 1024 , format , ap );
2010-08-30 15:25:15 +02:00
va_end ( ap );
2012-01-12 21:14:57 +01:00
for ( Map :: PlayerList :: const_iterator i = players . begin (); i != players . end (); ++ i )
if ( Player * player = i -> getSource ())
if ( WorldSession * session = player -> GetSession ())
2012-02-16 13:56:08 +01:00
session -> SendNotification ( "%s" , buff );
2010-08-30 15:25:15 +02:00
}
2009-10-16 16:45:01 -07:00
}
2009-11-01 17:53:07 -08:00
2010-03-23 19:15:17 +01:00
// Update Achievement Criteria for all players in instance
2011-04-21 23:32:45 +02:00
void InstanceScript :: DoUpdateAchievementCriteria ( AchievementCriteriaTypes type , uint32 miscValue1 /*= 0*/ , uint32 miscValue2 /*= 0*/ , Unit * unit /*= NULL*/ )
2010-03-23 19:15:17 +01:00
{
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
if ( ! PlayerList . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
2011-10-07 11:08:09 -05:00
if ( Player * player = i -> getSource ())
player -> UpdateAchievementCriteria ( type , miscValue1 , miscValue2 , unit );
2010-03-23 19:15:17 +01:00
}
2010-04-27 22:26:30 +02:00
// Start timed achievement for all players in instance
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoStartTimedAchievement ( AchievementCriteriaTimedTypes type , uint32 entry )
2010-04-27 22:26:30 +02:00
{
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
if ( ! PlayerList . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
2011-10-07 11:08:09 -05:00
if ( Player * player = i -> getSource ())
2012-09-18 14:29:53 +02:00
player -> StartTimedAchievement ( type , entry );
2010-04-27 22:26:30 +02:00
}
// Stop timed achievement for all players in instance
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoStopTimedAchievement ( AchievementCriteriaTimedTypes type , uint32 entry )
2010-04-27 22:26:30 +02:00
{
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
if ( ! PlayerList . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
2011-10-07 11:08:09 -05:00
if ( Player * player = i -> getSource ())
2012-09-18 14:29:53 +02:00
player -> RemoveTimedAchievement ( type , entry );
2010-04-27 22:26:30 +02:00
}
2009-10-16 16:45:01 -07:00
// Remove Auras due to Spell on all players in instance
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoRemoveAurasDueToSpellOnPlayers ( uint32 spell )
2009-10-16 16:45:01 -07:00
{
2011-08-19 18:17:04 +02:00
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
2009-10-16 16:45:01 -07:00
if ( ! PlayerList . isEmpty ())
2011-08-19 18:17:04 +02:00
{
for ( Map :: PlayerList :: const_iterator itr = PlayerList . begin (); itr != PlayerList . end (); ++ itr )
{
if ( Player * player = itr -> getSource ())
{
player -> RemoveAurasDueToSpell ( spell );
if ( Pet * pet = player -> GetPet ())
pet -> RemoveAurasDueToSpell ( spell );
}
}
}
2009-10-16 16:45:01 -07:00
}
2009-12-25 15:53:37 +01:00
2011-01-01 23:37:35 +01:00
// Cast spell on all players in instance
void InstanceScript :: DoCastSpellOnPlayers ( uint32 spell )
{
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
if ( ! PlayerList . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
if ( Player * player = i -> getSource ())
player -> CastSpell ( player , spell , true );
}
2010-08-08 22:54:58 +06:00
bool InstanceScript :: CheckAchievementCriteriaMeet ( uint32 criteria_id , Player const * /*source*/ , Unit const * /*target*/ /*= NULL*/ , uint32 /*miscvalue1*/ /*= 0*/ )
2009-12-25 15:53:37 +01:00
{
2012-08-03 14:20:18 +02:00
sLog -> outError ( LOG_FILTER_GENERAL , "Achievement system call InstanceScript::CheckAchievementCriteriaMeet but instance script for map %u not have implementation for achievement criteria %u" ,
2011-04-29 20:47:02 +02:00
instance -> GetId (), criteria_id );
2009-12-25 15:53:37 +01:00
return false ;
}
2011-01-23 16:59:33 +01:00
2011-01-23 21:42:32 +01:00
void InstanceScript :: SendEncounterUnit ( uint32 type , Unit * unit /*= NULL*/ , uint8 param1 /*= 0*/ , uint8 param2 /*= 0*/ )
2011-01-23 16:59:33 +01:00
{
2011-01-23 21:42:32 +01:00
// size of this packet is at most 15 (usually less)
WorldPacket data ( SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT , 15 );
2011-01-23 16:59:33 +01:00
data << uint32 ( type );
switch ( type )
{
2012-03-16 23:16:22 +01:00
case ENCOUNTER_FRAME_ENGAGE :
case ENCOUNTER_FRAME_DISENGAGE :
case ENCOUNTER_FRAME_UPDATE_PRIORITY :
2013-03-25 13:26:48 +01:00
if ( ! unit )
return ;
2011-01-23 16:59:33 +01:00
data . append ( unit -> GetPackGUID ());
data << uint8 ( param1 );
break ;
2012-03-16 23:16:22 +01:00
case ENCOUNTER_FRAME_ADD_TIMER :
case ENCOUNTER_FRAME_ENABLE_OBJECTIVE :
case ENCOUNTER_FRAME_DISABLE_OBJECTIVE :
2011-01-23 16:59:33 +01:00
data << uint8 ( param1 );
break ;
2012-03-16 23:16:22 +01:00
case ENCOUNTER_FRAME_UPDATE_OBJECTIVE :
2011-01-23 16:59:33 +01:00
data << uint8 ( param1 );
2012-03-16 23:45:35 +01:00
data << uint8 ( param2 );
2011-01-23 16:59:33 +01:00
break ;
2012-03-16 23:16:22 +01:00
case ENCOUNTER_FRAME_UNK7 :
2011-01-23 16:59:33 +01:00
default :
break ;
}
instance -> SendToPlayers ( & data );
}
2011-02-03 22:20:40 +01:00
2013-01-09 15:15:42 +01:00
void InstanceScript :: UpdateEncounterState ( EncounterCreditType type , uint32 creditEntry , Unit * /*source*/ )
2011-02-03 22:20:40 +01:00
{
DungeonEncounterList const * encounters = sObjectMgr -> GetDungeonEncounterList ( instance -> GetId (), instance -> GetDifficulty ());
if ( ! encounters )
return ;
2013-01-09 15:15:42 +01:00
uint32 dungeonId = 0 ;
2011-02-03 22:20:40 +01:00
for ( DungeonEncounterList :: const_iterator itr = encounters -> begin (); itr != encounters -> end (); ++ itr )
{
2013-01-09 15:15:42 +01:00
DungeonEncounter const * encounter = * itr ;
if ( encounter -> creditType == type && encounter -> creditEntry == creditEntry )
2011-02-03 22:20:40 +01:00
{
2013-01-09 15:15:42 +01:00
completedEncounters |= 1 << encounter -> dbcEntry -> encounterIndex ;
if ( encounter -> lastEncounterDungeon )
2011-02-03 22:20:40 +01:00
{
2013-01-09 15:15:42 +01:00
dungeonId = encounter -> lastEncounterDungeon ;
sLog -> outDebug ( LOG_FILTER_LFG , "UpdateEncounterState: Instance %s (instanceId %u) completed encounter %s. Credit Dungeon: %u" , instance -> GetMapName (), instance -> GetInstanceId (), encounter -> dbcEntry -> encounterName [ 0 ], dungeonId );
break ;
2011-02-03 22:20:40 +01:00
}
2013-01-09 15:15:42 +01:00
}
}
if ( dungeonId )
{
Map :: PlayerList const & players = instance -> GetPlayers ();
for ( Map :: PlayerList :: const_iterator i = players . begin (); i != players . end (); ++ i )
{
if ( Player * player = i -> getSource ())
if ( Group * grp = player -> GetGroup ())
if ( grp -> isLFGGroup ())
{
sLFGMgr -> FinishDungeon ( grp -> GetGUID (), dungeonId );
return ;
}
2011-02-03 22:20:40 +01:00
}
}
}