2010-10-07 15:35:36 +02:00
/*
2011-01-01 15:01:13 +01:00
* Copyright (C) 2008-2011 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
2010-08-08 22:54:58 +06:00
#include "InstanceScript.h"
2010-06-08 16:13:55 -06:00
#include "DatabaseEnv.h"
2008-10-02 16:23:55 -05:00
#include "Map.h"
2009-08-14 20:56:01 +02:00
#include "Player.h"
2009-05-06 15:36:55 +02:00
#include "GameObject.h"
#include "Creature.h"
2009-05-16 14:49:30 -05:00
#include "CreatureAI.h"
2009-12-25 15:53:37 +01:00
#include "Log.h"
2011-02-03 22:20:40 +01:00
#include "LFGMgr.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
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPDATE_INSTANCE_DATA );
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
2010-08-08 22:54:58 +06: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
2010-12-23 23:25:44 +01:00
sLog -> outDebug ( "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
2010-08-08 22:54:58 +06: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 ;
}
2010-12-23 23:25:44 +01:00
sLog -> outDebug ( "InstanceScript::LoadMinionData: " UI64FMTD " minions loaded." , uint64 ( minions . size ()));
2009-05-16 14:49:30 -05:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06: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 ;
}
2010-12-23 23:25:44 +01:00
sLog -> outDebug ( "InstanceScript::LoadDoorData: " UI64FMTD " doors loaded." , uint64 ( doors . size ()));
2009-05-09 14:08:42 -05:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06: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
2010-08-08 22:54:58 +06:00
void InstanceScript :: UpdateDoorState ( GameObject * door )
2009-05-09 14:08:42 -05:00
{
DoorInfoMap :: iterator lower = doors . lower_bound ( door -> GetEntry ());
DoorInfoMap :: iterator upper = doors . upper_bound ( door -> GetEntry ());
2009-11-01 17:53:07 -08:00
if ( lower == upper )
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 ;
2009-10-17 16:20:24 -07:00
for ( DoorInfoMap :: iterator itr = lower ; itr != upper ; ++ itr )
2009-05-09 14:08:42 -05:00
{
2009-11-01 17:53:07 -08:00
if ( itr -> second . type == DOOR_TYPE_ROOM )
2009-05-06 00:06:38 -05:00
{
2009-11-01 17:53:07 -08:00
if ( itr -> second . bossInfo -> state == IN_PROGRESS )
2009-05-09 14:08:42 -05:00
{
open = false ;
break ;
}
}
2009-11-01 17:53:07 -08:00
else if ( itr -> second . type == DOOR_TYPE_PASSAGE )
2009-05-09 14:08:42 -05:00
{
2009-11-01 17:53:07 -08:00
if ( itr -> second . bossInfo -> state != DONE )
2009-05-09 14:08:42 -05:00
{
open = false ;
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 );
2010-12-23 23:25:44 +01:00
//sLog->outError("Door %u is %s.", door->GetEntry(), open ? "opened" : "closed");
2009-05-01 18:24:12 -05:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
void InstanceScript :: AddDoor ( GameObject * door , bool add )
2009-05-01 18:24:12 -05:00
{
2009-05-09 14:08:42 -05:00
DoorInfoMap :: iterator lower = doors . lower_bound ( door -> GetEntry ());
DoorInfoMap :: iterator upper = doors . upper_bound ( door -> GetEntry ());
2009-11-01 17:53:07 -08:00
if ( lower == upper )
2009-05-09 14:08:42 -05:00
return ;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for ( DoorInfoMap :: iterator itr = lower ; itr != upper ; ++ itr )
2009-05-01 18:24:12 -05:00
{
2009-11-01 17:53:07 -08:00
if ( add )
2009-05-17 16:37:03 -05:00
{
2009-05-09 14:08:42 -05:00
itr -> second . bossInfo -> door [ itr -> second . type ]. insert ( door );
2009-11-01 17:53:07 -08:00
switch ( itr -> second . boundary )
2009-05-17 16:37:03 -05:00
{
default :
case BOUNDARY_NONE :
break ;
case BOUNDARY_N :
case BOUNDARY_S :
itr -> second . bossInfo -> boundary [ itr -> second . boundary ] = door -> GetPositionX ();
break ;
case BOUNDARY_E :
case BOUNDARY_W :
itr -> second . bossInfo -> boundary [ itr -> second . boundary ] = door -> GetPositionY ();
break ;
case BOUNDARY_NW :
case BOUNDARY_SE :
itr -> second . bossInfo -> boundary [ itr -> second . boundary ] = door -> GetPositionX () + door -> GetPositionY ();
break ;
case BOUNDARY_NE :
case BOUNDARY_SW :
itr -> second . bossInfo -> boundary [ itr -> second . boundary ] = door -> GetPositionX () - door -> GetPositionY ();
break ;
}
}
2009-05-06 00:06:38 -05:00
else
2009-05-09 14:08:42 -05:00
itr -> second . bossInfo -> door [ itr -> second . 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
2010-08-08 22:54:58 +06: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
{
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 ;
2010-12-23 23:25:44 +01:00
//sLog->outError("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 )
2009-05-11 03:17:13 -05:00
saveStream << ( uint32 ) i -> state << " " ;
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
2009-06-17 07:16:40 +02:00
GameObject * pGo = instance -> GetGameObject ( uiGuid );
2009-10-17 15:51:44 -07:00
2009-06-17 07:16:40 +02:00
if ( pGo )
{
if ( pGo -> GetGoType () == GAMEOBJECT_TYPE_DOOR || pGo -> GetGoType () == GAMEOBJECT_TYPE_BUTTON )
{
if ( pGo -> getLootState () == GO_READY )
pGo -> UseDoorOrButton ( uiWithRestoreTime , bUseAlternativeState );
else if ( pGo -> getLootState () == GO_ACTIVATED )
pGo -> ResetDoorOrButton ();
}
else
2010-12-23 23:25:44 +01:00
sLog -> outError ( "SD2: Script call DoUseDoorOrButton, but gameobject entry %u is type %u." , pGo -> GetEntry (), pGo -> 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
{
if ( GameObject * pGo = instance -> GetGameObject ( uiGuid ))
{
//not expect any of these should ever be handled
2010-04-07 23:25:02 +02:00
if ( pGo -> GetGoType () == GAMEOBJECT_TYPE_FISHINGNODE || pGo -> GetGoType () == GAMEOBJECT_TYPE_DOOR ||
pGo -> GetGoType () == GAMEOBJECT_TYPE_BUTTON || pGo -> GetGoType () == GAMEOBJECT_TYPE_TRAP )
2009-06-17 07:16:40 +02:00
return ;
2009-10-17 15:51:44 -07:00
2009-06-17 07:16:40 +02:00
if ( pGo -> isSpawned ())
return ;
2009-10-17 15:51:44 -07:00
2009-06-17 07:16:40 +02:00
pGo -> SetRespawnTime ( uiTimeToDespawn );
}
}
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 )
2009-11-01 17:53:07 -08:00
if ( Player * pPlayer = itr -> getSource ())
2009-08-14 20:56:01 +02:00
pPlayer -> SendUpdateWorldState ( uiStateId , uiStateData );
}
else
2010-12-23 23:25:44 +01:00
sLog -> outDebug ( "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
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoSendNotifyToInstance ( const char * format , ...)
2009-10-16 16:45:01 -07:00
{
InstanceMap :: PlayerList const & PlayerList = instance -> GetPlayers ();
InstanceMap :: PlayerList :: const_iterator i ;
2009-10-17 15:51:44 -07:00
2009-10-16 16:45:01 -07:00
if ( ! PlayerList . isEmpty ())
2010-08-30 15:25:15 +02:00
{
va_list ap ;
va_start ( ap , format );
2009-10-18 15:09:43 -07:00
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
2010-08-30 15:25:15 +02:00
{
2009-11-01 17:53:07 -08:00
if ( Player * pPlayer = i -> getSource ())
if ( WorldSession * pSession = pPlayer -> GetSession ())
2010-08-30 15:25:15 +02:00
pSession -> SendNotification ( format , ap );
}
va_end ( ap );
}
2009-10-16 16:45:01 -07:00
}
2009-11-01 17:53:07 -08:00
2009-10-16 16:45:01 -07:00
// Complete Achievement for all players in instance
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoCompleteAchievement ( uint32 achievement )
2009-10-16 16:45:01 -07:00
{
2010-03-27 13:45:39 +01:00
AchievementEntry const * pAE = GetAchievementStore () -> LookupEntry ( achievement );
2009-10-16 16:45:01 -07:00
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
2009-10-17 15:51:44 -07:00
2010-03-27 13:45:39 +01:00
if ( ! pAE )
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "TSCR: DoCompleteAchievement called for not existing achievement %u" , achievement );
2010-03-27 13:45:39 +01:00
return ;
}
2009-10-16 16:45:01 -07:00
if ( ! PlayerList . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
2009-11-01 17:53:07 -08:00
if ( Player * pPlayer = i -> getSource ())
2010-03-27 13:45:39 +01:00
pPlayer -> CompletedAchievement ( pAE );
2009-10-16 16:45:01 -07:00
}
2009-10-17 15:51:44 -07:00
2010-03-23 19:15:17 +01:00
// Update Achievement Criteria for all players in instance
2010-08-08 22:54:58 +06:00
void InstanceScript :: DoUpdateAchievementCriteria ( AchievementCriteriaTypes type , uint32 miscvalue1 , uint32 miscvalue2 , Unit * unit , uint32 time )
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 )
if ( Player * pPlayer = i -> getSource ())
pPlayer -> UpdateAchievementCriteria ( type , miscvalue1 , miscvalue2 , unit , time );
}
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 )
if ( Player * pPlayer = i -> getSource ())
pPlayer -> GetAchievementMgr (). StartTimedAchievement ( type , entry );
}
// 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 )
if ( Player * pPlayer = i -> getSource ())
pPlayer -> GetAchievementMgr (). RemoveTimedAchievement ( type , entry );
}
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
{
Map :: PlayerList const & PlayerList = instance -> GetPlayers ();
2009-10-17 15:51:44 -07:00
2009-10-16 16:45:01 -07:00
if ( ! PlayerList . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = PlayerList . begin (); i != PlayerList . end (); ++ i )
2009-11-01 17:53:07 -08:00
if ( Player * pPlayer = i -> getSource ())
pPlayer -> 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
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "Achievement system call InstanceScript::CheckAchievementCriteriaMeet but instance script for map %u not have implementation for achievement criteria %u" ,
2009-12-25 15:53:37 +01:00
instance -> GetId (), criteria_id );
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 )
{
2011-01-23 21:42:32 +01:00
case ENCOUNTER_FRAME_ADD :
case ENCOUNTER_FRAME_REMOVE :
2011-01-23 16:59:33 +01:00
case 2 :
data . append ( unit -> GetPackGUID ());
data << uint8 ( param1 );
break ;
case 3 :
case 4 :
case 6 :
data << uint8 ( param1 );
data << uint8 ( param2 );
break ;
case 5 :
data << uint8 ( param1 );
break ;
case 7 :
default :
break ;
}
instance -> SendToPlayers ( & data );
}
2011-02-03 22:20:40 +01:00
void InstanceScript :: UpdateEncounterState ( EncounterCreditType type , uint32 creditEntry , Unit * source )
{
DungeonEncounterList const * encounters = sObjectMgr -> GetDungeonEncounterList ( instance -> GetId (), instance -> GetDifficulty ());
if ( ! encounters )
return ;
for ( DungeonEncounterList :: const_iterator itr = encounters -> begin (); itr != encounters -> end (); ++ itr )
{
if (( * itr ) -> creditType == type && ( * itr ) -> creditEntry == creditEntry )
{
completedEncounters |= 1 << ( * itr ) -> dbcEntry -> encounterIndex ;
sLog -> outDebug ( "Instance %s (instanceId %u) completed encounter %s" , instance -> GetMapName (), instance -> GetInstanceId (), ( * itr ) -> dbcEntry -> encounterName [ 0 ]);
if ( uint32 dungeonId = ( * itr ) -> lastEncounterDungeon )
{
Map :: PlayerList const & players = instance -> GetPlayers ();
if ( ! players . isEmpty ())
for ( Map :: PlayerList :: const_iterator i = players . begin (); i != players . end (); ++ i )
if ( Player * player = i -> getSource ())
if ( ! source || player -> IsAtGroupRewardDistance ( source ))
sLFGMgr -> RewardDungeonDoneFor ( dungeonId , player );
}
return ;
}
}
}