forked from mangosR2/scriptdev2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBSW_instance.cpp
More file actions
166 lines (139 loc) · 4.75 KB
/
BSW_instance.cpp
File metadata and controls
166 lines (139 loc) · 4.75 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* Copyright (C) 2009 - 2011 by /dev/rsa for ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#include "precompiled.h"
#include "BSW_instance.h"
BSWScriptedInstance::BSWScriptedInstance(Map* pMap) : ScriptedInstance(pMap)
{
debug_log("BSW: Initialized BSWScriptedInstance structure for map %u difficulty %u",pMap->GetId(),pMap->GetDifficulty());
m_auiEvent = 0;
m_auiEventTimer = 0;
m_auiCreatureID = 0;
m_auiEventLock = false;
m_pMap = pMap;
};
BSWScriptedInstance::~BSWScriptedInstance()
{
debug_log("BSW: Removing BSWScriptedInstance structure for map %u",m_pMap->GetId());
};
void BSWScriptedInstance::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("BSW: DoCompleteAchievement attempt set data, but no players in map.");
}
void BSWScriptedInstance::DoOpenDoor(ObjectGuid guid)
{
if (guid.IsEmpty())
return;
GameObject* pGo = instance->GetGameObject(guid);
if (pGo)
pGo->SetGoState(GO_STATE_ACTIVE);
else
debug_log("BSW: DoOpenDoor attempt set data to object %u, but no this object", guid.GetCounter());
}
void BSWScriptedInstance::DoCloseDoor(ObjectGuid guid)
{
if (guid.IsEmpty())
return;
GameObject* pGo = instance->GetGameObject(guid);
if (pGo)
pGo->SetGoState(GO_STATE_READY);
else
debug_log("BSW: DoCloseDoor attempt set data to object %u, but no this object", guid.GetCounter());
}
void BSWScriptedInstance::DoOpenDoor(uint32 entry)
{
EntryGuidMap::iterator find = m_mGoEntryGuidStore.find(entry);
if (find != m_mGoEntryGuidStore.end())
{
ObjectGuid guid = find->second;
DoOpenDoor(guid);
}
else
debug_log("BSW: Script call DoOpenDoor (by Entry), but no gameobject of entry %u was created yet, or it was not stored by script for map %u.", entry, instance->GetId());
}
void BSWScriptedInstance::DoCloseDoor(uint32 entry)
{
EntryGuidMap::iterator find = m_mGoEntryGuidStore.find(entry);
if (find != m_mGoEntryGuidStore.end())
{
ObjectGuid guid = find->second;
DoCloseDoor(guid);
}
else
debug_log("BSW: Script call DoCloseDoor (by Entry), but no gameobject of entry %u was created yet, or it was not stored by script for map %u.", entry, instance->GetId());
}
uint32 BSWScriptedInstance::GetEvent(uint32 creatureID)
{
if (m_auiEventLock || m_auiCreatureID != creatureID)
{
return 0;
}
else
{
debug_log("BSW: GetEvent: send event %u to creature %u",m_auiEvent, creatureID);
m_auiEventLock = true;
return m_auiEvent;
}
}
void BSWScriptedInstance::SetNextEvent(uint32 EventNum, uint32 creatureID, uint32 timer)
{
m_auiEvent = EventNum;
m_auiCreatureID = creatureID;
m_auiEventTimer = timer;
m_auiEventLock = false;
debug_log("BSW: SetNextEvent: setted event %u to creature %u, timer %u",m_auiEvent, creatureID, timer);
}
bool BSWScriptedInstance::GetEventTimer(uint32 creatureID, const uint32 diff)
{
if (m_auiEvent == 0 || m_auiCreatureID != creatureID)
return false;
if (m_auiEventTimer <= diff)
{
m_auiEventTimer = 0;
return true;
}
else
{
m_auiEventTimer -= diff;
return false;
}
}
void BSWScriptedInstance::SetCriteriaState(uint32 criteria_id, bool state, Player* player)
{
if (!criteria_id)
return;
if (player && state)
m_personalCriteriaMap.insert(std::make_pair(criteria_id, player->GetObjectGuid()));
else
m_groupCriteriaMap.insert(std::make_pair(criteria_id, state));
}
bool BSWScriptedInstance::GetCriteriaState(uint32 criteria_id, Player const* player)
{
if (!criteria_id)
return false;
std::map<uint32, bool>::const_iterator itr = m_groupCriteriaMap.find(criteria_id);
if (itr != m_groupCriteriaMap.end())
if (itr->second)
return true;
if (player)
{
std::pair<std::multimap<uint32, ObjectGuid>::const_iterator, std::multimap<uint32, ObjectGuid>::const_iterator> bounds =
m_personalCriteriaMap.equal_range(criteria_id);
for(std::multimap<uint32, ObjectGuid>::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
if (itr->second == player->GetObjectGuid())
return true;
}
}
return false;
}