forked from orangevirus/scriptdev2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsc_instance.cpp
More file actions
125 lines (106 loc) · 4.27 KB
/
sc_instance.cpp
File metadata and controls
125 lines (106 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Copyright (C) 2006 - 2011 ScriptDev2 <http://www.scriptdev2.com/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#include "precompiled.h"
//Optional uiWithRestoreTime. If not defined, autoCloseTime will be used (if not 0 by default in *_template)
void ScriptedInstance::DoUseDoorOrButton(ObjectGuid guid, uint32 uiWithRestoreTime, bool bUseAlternativeState)
{
if (guid.IsEmpty())
return;
if (GameObject* pGo = instance->GetGameObject(guid))
{
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
error_log("SD2: Script call DoUseDoorOrButton, but gameobject entry %u is type %u.", pGo->GetEntry(), pGo->GetGoType());
}
}
void ScriptedInstance::DoRespawnGameObject(ObjectGuid guid, uint32 uiTimeToDespawn)
{
if (guid.IsEmpty())
return;
if (GameObject* pGo = instance->GetGameObject(guid))
{
//not expect any of these should ever be handled
if (pGo->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE || pGo->GetGoType() == GAMEOBJECT_TYPE_DOOR ||
pGo->GetGoType() == GAMEOBJECT_TYPE_BUTTON || pGo->GetGoType() == GAMEOBJECT_TYPE_TRAP)
return;
if (pGo->isSpawned())
return;
pGo->SetRespawnTime(uiTimeToDespawn);
pGo->Refresh();
}
}
void ScriptedInstance::DoUpdateWorldState(uint32 uiStateId, uint32 uiStateData)
{
Map::PlayerList const& lPlayers = instance->GetPlayers();
if (!lPlayers.isEmpty())
{
for(Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr)
{
if (Player* pPlayer = itr->getSource())
pPlayer->SendUpdateWorldState(uiStateId, uiStateData);
}
}
else
debug_log("SD2: DoUpdateWorldState attempt send data but no players in map.");
}
void ScriptedInstance::DestroyItemFromAllPlayers(uint32 uiItemId)
{
Map::PlayerList const& lPlayers = instance->GetPlayers();
if (!lPlayers.isEmpty())
{
for(Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr)
{
if (Player* pPlayer = itr->getSource())
if (pPlayer->GetItemCount(uiItemId,true) > 0)
pPlayer->DestroyItemCount(uiItemId,pPlayer->GetItemCount(uiItemId),true);
}
}
else
error_log("SD2: DestroyItemFromAllPlayers attempt to remove item: %u but no players in map.", uiItemId);
}
void ScriptedInstance::DoCompleteAchievement(uint32 uiAchievmentId)
{
Map::PlayerList const& lPlayers = instance->GetPlayers();
if (!lPlayers.isEmpty())
{
for(Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr)
{
if (Player* pPlayer = itr->getSource())
pPlayer->CompletedAchievement(uiAchievmentId);
}
}
else
debug_log("SD2: DoCompleteAchievement attempt set data but no players in map.");
}
Player* ScriptedInstance::GetPlayerInMap(bool bOnlyAlive /*=false*/, bool bCanBeGamemaster /*=true*/)
{
Map::PlayerList const& lPlayers = instance->GetPlayers();
for(Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr)
{
Player* pPlayer = itr->getSource();
if (pPlayer && (!bOnlyAlive || pPlayer->isAlive()) && (bCanBeGamemaster || !pPlayer->isGameMaster()))
return pPlayer;
}
return NULL;
}
void ScriptedInstance::DoStartTimedAchievement(AchievementCriteriaTypes tCriteriaType, uint32 uiTimedCriteriaMiscId)
{
Map::PlayerList const& lPlayers = instance->GetPlayers();
if (!lPlayers.isEmpty())
{
for(Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr)
{
if (Player* pPlayer = itr->getSource())
pPlayer->StartTimedAchievementCriteria(tCriteriaType, uiTimedCriteriaMiscId);
}
}
else
debug_log("SD2: DoStartTimedAchievement attempt start achievements but no players in map.");
}