OregonCore  revision fb2a440-git
Your Favourite TBC server
ScriptSystem.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "ScriptSystem.h"
19 #include "ObjectMgr.h"
20 #include "Database/DatabaseEnv.h"
21 #include "ScriptMgr.h"
22 
24 {
25 }
26 
28 {
29  static SystemMgr pSysMgr;
30  return pSysMgr;
31 }
32 
34 {
35  //Get Version information
36  QueryResult_AutoPtr Result = WorldDatabase.Query("SELECT script_version FROM version LIMIT 1");
37 
38  if (Result)
39  {
40  Field* pFields = Result->Fetch();
41 
42  outstring_log("OSCR: Database version is: %s\n", pFields[0].GetString());
43  }
44  else
45  error_log("OSCR: Missing version.script_version information.\n");
46 }
47 
49 {
51 
52  QueryResult_AutoPtr Result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM script_texts");
53 
54  if (Result)
55  {
56  uint32 uiCount = 0;
57 
58  do
59  {
60  Field* pFields = Result->Fetch();
61  StringTextData pTemp;
62 
63  int32 iId = pFields[0].GetInt32();
64  pTemp.uiSoundId = pFields[1].GetUInt32();
65  pTemp.uiType = pFields[2].GetUInt32();
66  pTemp.uiLanguage = pFields[3].GetUInt32();
67  pTemp.uiEmote = pFields[4].GetUInt32();
68 
69  if (iId >= 0)
70  {
71  error_db_log("OSCR: Entry %i in table script_texts is not a negative value.", iId);
72  continue;
73  }
74 
75  if (iId > TEXT_SOURCE_RANGE || iId <= TEXT_SOURCE_RANGE * 2)
76  {
77  error_db_log("OSCR: Entry %i in table script_texts is out of accepted entry range for table.", iId);
78  continue;
79  }
80 
81  if (pTemp.uiSoundId)
82  {
83  if (!GetSoundEntriesStore()->LookupEntry(pTemp.uiSoundId))
84  error_db_log("OSCR: Entry %i in table script_texts has soundId %u but sound does not exist.", iId, pTemp.uiSoundId);
85  }
86 
87  if (!GetLanguageDescByID(pTemp.uiLanguage))
88  error_db_log("OSCR: Entry %i in table script_texts using Language %u but Language does not exist.", iId, pTemp.uiLanguage);
89 
90  if (pTemp.uiType > CHAT_TYPE_ZONE_YELL)
91  error_db_log("OSCR: Entry %i in table script_texts has Type %u but this Chat Type does not exist.", iId, pTemp.uiType);
92 
93  m_mTextDataMap[iId] = pTemp;
94  ++uiCount;
95  }
96  while (Result->NextRow());
97 
98  outstring_log(">> Loaded %u additional Script Texts data.", uiCount);
99  }
100  else
101  outstring_log(">> Loaded 0 additional Script Texts data. DB table script_texts is empty.");
102 }
103 
105 {
106  LoadOregonStrings(WorldDatabase, "custom_texts", TEXT_SOURCE_RANGE * 2, 1 + (TEXT_SOURCE_RANGE * 3));
107 
108  QueryResult_AutoPtr Result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM custom_texts");
109 
110  if (Result)
111  {
112  uint32 uiCount = 0;
113 
114  do
115  {
116  Field* pFields = Result->Fetch();
117  StringTextData pTemp;
118 
119  int32 iId = pFields[0].GetInt32();
120  pTemp.uiSoundId = pFields[1].GetUInt32();
121  pTemp.uiType = pFields[2].GetUInt32();
122  pTemp.uiLanguage = pFields[3].GetUInt32();
123  pTemp.uiEmote = pFields[4].GetUInt32();
124 
125  if (iId >= 0)
126  {
127  error_db_log("OSCR: Entry %i in table custom_texts is not a negative value.", iId);
128  continue;
129  }
130 
131  if (iId > TEXT_SOURCE_RANGE * 2 || iId <= TEXT_SOURCE_RANGE * 3)
132  {
133  error_db_log("OSCR: Entry %i in table custom_texts is out of accepted entry range for table.", iId);
134  continue;
135  }
136 
137  if (pTemp.uiSoundId)
138  {
139  if (!GetSoundEntriesStore()->LookupEntry(pTemp.uiSoundId))
140  error_db_log("OSCR: Entry %i in table custom_texts has soundId %u but sound does not exist.", iId, pTemp.uiSoundId);
141  }
142 
143  if (!GetLanguageDescByID(pTemp.uiLanguage))
144  error_db_log("OSCR: Entry %i in table custom_texts using Language %u but Language does not exist.", iId, pTemp.uiLanguage);
145 
146  if (pTemp.uiType > CHAT_TYPE_ZONE_YELL)
147  error_db_log("OSCR: Entry %i in table custom_texts has Type %u but this Chat Type does not exist.", iId, pTemp.uiType);
148 
149  m_mTextDataMap[iId] = pTemp;
150  ++uiCount;
151  }
152  while (Result->NextRow());
153 
154  outstring_log(">> Loaded %u additional Custom Texts data.", uiCount);
155  }
156  else
157  outstring_log(">> Loaded 0 additional Custom Texts data. DB table custom_texts is empty.");
158 }
159 
161 {
162  // Drop Existing Waypoint list
163  m_mPointMoveMap.clear();
164 
165  uint64 uiCreatureCount = 0;
166 
167  // Load Waypoints
168  QueryResult_AutoPtr Result = WorldDatabase.Query("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry");
169  if (Result)
170  uiCreatureCount = Result->GetRowCount();
171 
172  Result = WorldDatabase.Query("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid");
173 
174  if (Result)
175  {
176  uint32 uiNodeCount = 0;
177 
178  do
179  {
180  Field* pFields = Result->Fetch();
181  ScriptPointMove pTemp;
182 
183  pTemp.uiCreatureEntry = pFields[0].GetUInt32();
184  uint32 uiEntry = pTemp.uiCreatureEntry;
185  pTemp.uiPointId = pFields[1].GetUInt32();
186  pTemp.fX = pFields[2].GetFloat();
187  pTemp.fY = pFields[3].GetFloat();
188  pTemp.fZ = pFields[4].GetFloat();
189  pTemp.uiWaitTime = pFields[5].GetUInt32();
190 
192 
193  if (!pCInfo)
194  {
195  error_db_log("OSCR: DB table script_waypoint has waypoint for non-existant creature entry %u", pTemp.uiCreatureEntry);
196  continue;
197  }
198 
199  if (!pCInfo->ScriptID)
200  error_db_log("OSCR: DB table script_waypoint has waypoint for creature entry %u, but creature does not have ScriptName defined and then useless.", pTemp.uiCreatureEntry);
201 
202  m_mPointMoveMap[uiEntry].push_back(pTemp);
203  ++uiNodeCount;
204  }
205  while (Result->NextRow());
206 
207  outstring_log(">> Loaded %u Script Waypoint nodes.", uiNodeCount);
208  }
209  else
210  outstring_log(">> Loaded 0 Script Waypoints. DB table script_waypoint is empty.");
211 }
212 
void LoadScriptTexts()
bool LoadOregonStrings(DatabaseType &db, char const *table, int32 start_value, int32 end_value)
Definition: ObjectMgr.cpp:7635
TextDataMap m_mTextDataMap
Definition: ScriptSystem.h:111
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
#define TEXT_SOURCE_RANGE
Definition: ScriptSystem.h:23
uint32 uiLanguage
Definition: ScriptSystem.h:63
Definition: Field.h:24
PointMoveMap m_mPointMoveMap
Definition: ScriptSystem.h:112
ACE_INT32 int32
Definition: Define.h:67
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
void LoadScriptTextsCustom()
void LoadScriptWaypoints()
DBCStorage< SoundEntriesEntry > const * GetSoundEntriesStore()
Definition: DBCStores.cpp:772
LanguageDesc const * GetLanguageDescByID(uint32 lang)
Definition: ObjectMgr.cpp:269
ACE_UINT64 uint64
Definition: Define.h:70
#define error_db_log
Definition: Log.h:203
#define error_log
Definition: Log.h:202
CreatureInfo const * GetCreatureTemplateStore(uint32 entry)
Definition: ObjectMgr.cpp:7668
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
uint32 uiCreatureEntry
Definition: ScriptSystem.h:51
void LoadVersion()
uint32 uiSoundId
Definition: ScriptSystem.h:61
#define outstring_log
Macros meant to be used by scripts.
Definition: Log.h:199
uint32 ScriptID
Definition: Creature.h:196
ACE_UINT32 uint32
Definition: Define.h:71
static SystemMgr & Instance()