PageRenderTime 2615ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/northrend/ruby_sanctum/instance_ruby_sanctum.cpp

https://github.com/vertrigo/scriptdev2
C++ | 376 lines | 306 code | 46 blank | 24 comment | 50 complexity | b38984fbe86e0f0f642466c8ab9aa80e MD5 | raw file
  1. /* Copyright (C) 2006 - 2012 ScriptDev2 <http://www.scriptdev2.com/>
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. /* ScriptData
  17. SDName: instance_ruby_sanctum
  18. SD%Complete: 50%
  19. SDComment: by notagain, corrected by /dev/rsa
  20. SDCategory: ruby_sanctum
  21. EndScriptData */
  22. //TODO: Trash mobs, spawn and removal of fire ring/walls, spawn of halion
  23. #include "precompiled.h"
  24. #include "ruby_sanctum.h"
  25. struct MANGOS_DLL_DECL instance_ruby_sanctum : public BSWScriptedInstance
  26. {
  27. instance_ruby_sanctum(Map* pMap) : BSWScriptedInstance(pMap)
  28. {
  29. Initialize();
  30. }
  31. bool needSave;
  32. std::string strSaveData;
  33. //Creatures GUID
  34. uint32 m_auiEncounter[MAX_ENCOUNTERS+1];
  35. uint32 m_auiEventTimer;
  36. uint32 m_auiHalionEvent;
  37. uint32 m_auiOrbDirection;
  38. uint32 m_auiOrbNState;
  39. uint32 m_auiOrbSState;
  40. uint64 m_uiHalion_pGUID;
  41. uint64 m_uiHalion_tGUID;
  42. uint64 m_uiHalionControlGUID;
  43. uint64 m_uiRagefireGUID;
  44. uint64 m_uiZarithrianGUID;
  45. uint64 m_uiBaltharusGUID;
  46. uint64 m_uiCloneGUID;
  47. uint64 m_uiXerestraszaGUID;
  48. uint64 m_uiOrbNGUID;
  49. uint64 m_uiOrbSGUID;
  50. uint64 m_uiOrbFocusGUID;
  51. uint64 m_uiOrbCarrierGUID;
  52. //object GUID
  53. uint64 m_uiHalionPortal1GUID;
  54. uint64 m_uiHalionPortal2GUID;
  55. uint64 m_uiHalionPortal3GUID;
  56. uint64 m_uiHalionFireWallSGUID;
  57. uint64 m_uiHalionFireWallMGUID;
  58. uint64 m_uiHalionFireWallLGUID;
  59. uint64 m_uiBaltharusTargetGUID;
  60. uint64 m_uiFireFieldGUID;
  61. uint64 m_uiFlameWallsGUID;
  62. uint64 m_uiFlameRingGUID;
  63. void Initialize()
  64. {
  65. for (uint8 i = 0; i < MAX_ENCOUNTERS; ++i)
  66. m_auiEncounter[i] = NOT_STARTED;
  67. m_auiEventTimer = 1000;
  68. m_uiHalion_pGUID = 0;
  69. m_uiHalion_tGUID = 0;
  70. m_uiRagefireGUID = 0;
  71. m_uiZarithrianGUID = 0;
  72. m_uiBaltharusGUID = 0;
  73. m_uiCloneGUID = 0;
  74. m_uiHalionPortal1GUID = 0;
  75. m_uiHalionPortal2GUID = 0;
  76. m_uiHalionPortal3GUID = 0;
  77. m_uiXerestraszaGUID = 0;
  78. m_uiHalionFireWallSGUID = 0;
  79. m_uiHalionFireWallMGUID = 0;
  80. m_uiHalionFireWallLGUID = 0;
  81. m_uiBaltharusTargetGUID = 0;
  82. m_auiOrbDirection = 0;
  83. m_uiOrbNGUID = 0;
  84. m_uiOrbSGUID = 0;
  85. m_uiOrbFocusGUID = 0;
  86. m_auiOrbNState = NOT_STARTED;
  87. m_auiOrbSState = NOT_STARTED;
  88. }
  89. bool IsEncounterInProgress() const
  90. {
  91. for(uint8 i = 1; i < MAX_ENCOUNTERS ; ++i)
  92. if (m_auiEncounter[i] == IN_PROGRESS)
  93. return true;
  94. return false;
  95. }
  96. void UpdateWorldState(bool command, uint32 value)
  97. {
  98. Map::PlayerList const &players = instance->GetPlayers();
  99. if (command)
  100. {
  101. for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
  102. {
  103. if(Player* pPlayer = i->getSource())
  104. {
  105. if(pPlayer->isAlive())
  106. {
  107. pPlayer->SendUpdateWorldState(UPDATE_STATE_UI_SHOW,0);
  108. if (pPlayer->HasAura(74807))
  109. {
  110. pPlayer->SendUpdateWorldState(UPDATE_STATE_UI_COUNT_T, 100 - value);
  111. }
  112. else
  113. {
  114. pPlayer->SendUpdateWorldState(UPDATE_STATE_UI_COUNT_R, value);
  115. }
  116. pPlayer->SendUpdateWorldState(UPDATE_STATE_UI_SHOW,1);
  117. }
  118. }
  119. }
  120. }
  121. else
  122. {
  123. for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
  124. {
  125. if(Player* pPlayer = i->getSource())
  126. {
  127. if(pPlayer->isAlive())
  128. {
  129. pPlayer->SendUpdateWorldState(UPDATE_STATE_UI_SHOW,0);
  130. }
  131. }
  132. }
  133. }
  134. }
  135. void OpenAllDoors()
  136. {
  137. if (m_auiEncounter[TYPE_RAGEFIRE] == DONE &&
  138. m_auiEncounter[TYPE_BALTHARUS] == DONE &&
  139. m_auiEncounter[TYPE_XERESTRASZA] == DONE)
  140. DoOpenDoor(GO_FLAME_WALLS);
  141. else
  142. DoCloseDoor(GO_FLAME_WALLS);
  143. }
  144. void OnCreatureCreate(Creature* pCreature)
  145. {
  146. switch(pCreature->GetEntry())
  147. {
  148. case NPC_HALION_REAL:
  149. case NPC_HALION_TWILIGHT:
  150. case NPC_HALION_CONTROL:
  151. case NPC_RAGEFIRE:
  152. case NPC_ZARITHRIAN:
  153. case NPC_BALTHARUS:
  154. case NPC_BALTHARUS_TARGET:
  155. case NPC_CLONE:
  156. case NPC_XERESTRASZA:
  157. case NPC_SHADOW_PULSAR_N:
  158. case NPC_SHADOW_PULSAR_S:
  159. case NPC_ORB_ROTATION_FOCUS:
  160. case NPC_ORB_CARRIER:
  161. m_mNpcEntryGuidStore[pCreature->GetEntry()] = pCreature->GetObjectGuid();
  162. break;
  163. }
  164. }
  165. void OnObjectCreate(GameObject* pGo)
  166. {
  167. switch(pGo->GetEntry())
  168. {
  169. case GO_HALION_PORTAL_1:
  170. case GO_HALION_PORTAL_2:
  171. case GO_HALION_PORTAL_3:
  172. case GO_FLAME_WALLS:
  173. case GO_FLAME_RING:
  174. case GO_FIRE_FIELD:
  175. m_mGoEntryGuidStore[pGo->GetEntry()] = pGo->GetObjectGuid();
  176. break;
  177. }
  178. OpenAllDoors();
  179. }
  180. void SetData(uint32 uiType, uint32 uiData)
  181. {
  182. switch(uiType)
  183. {
  184. case TYPE_EVENT: m_auiEncounter[uiType] = uiData; uiData = NOT_STARTED; break;
  185. case TYPE_RAGEFIRE: m_auiEncounter[uiType] = uiData;
  186. OpenAllDoors();
  187. break;
  188. case TYPE_BALTHARUS: m_auiEncounter[uiType] = uiData;
  189. OpenAllDoors();
  190. break;
  191. case TYPE_XERESTRASZA: m_auiEncounter[uiType] = uiData;
  192. if (uiData == IN_PROGRESS)
  193. DoOpenDoor(GO_FIRE_FIELD);
  194. else if (uiData == NOT_STARTED)
  195. {
  196. DoCloseDoor(GO_FIRE_FIELD);
  197. OpenAllDoors();
  198. }
  199. else if (uiData == DONE)
  200. {
  201. OpenAllDoors();
  202. if (m_auiEncounter[TYPE_ZARITHRIAN] == DONE)
  203. {
  204. m_auiEncounter[TYPE_EVENT] = 200;
  205. m_auiEventTimer = 30000;
  206. };
  207. }
  208. break;
  209. case TYPE_ZARITHRIAN: m_auiEncounter[uiType] = uiData;
  210. if (uiData == DONE)
  211. {
  212. DoOpenDoor(GO_FLAME_WALLS);
  213. m_auiEncounter[TYPE_EVENT] = 200;
  214. m_auiEventTimer = 30000;
  215. }
  216. else if (uiData == IN_PROGRESS)
  217. DoCloseDoor(GO_FLAME_WALLS);
  218. else if (uiData == FAIL)
  219. DoOpenDoor(GO_FLAME_WALLS);
  220. break;
  221. case TYPE_HALION: m_auiEncounter[uiType] = uiData;
  222. if (uiData == IN_PROGRESS)
  223. DoCloseDoor(GO_FLAME_RING);
  224. else
  225. DoOpenDoor(GO_FLAME_RING);
  226. break;
  227. case TYPE_HALION_EVENT: m_auiHalionEvent = uiData; uiData = NOT_STARTED; break;
  228. case TYPE_EVENT_TIMER: m_auiEventTimer = uiData; uiData = NOT_STARTED; break;
  229. case DATA_ORB_DIRECTION: m_auiOrbDirection = uiData; uiData = NOT_STARTED; break;
  230. case DATA_ORB_N: m_auiOrbNState = uiData; uiData = NOT_STARTED; break;
  231. case DATA_ORB_S: m_auiOrbSState = uiData; uiData = NOT_STARTED; break;
  232. case TYPE_COUNTER:
  233. if (uiData == COUNTER_OFF)
  234. {
  235. UpdateWorldState(false,0);
  236. }
  237. else
  238. {
  239. UpdateWorldState(true,uiData);
  240. }
  241. uiData = NOT_STARTED;
  242. break;
  243. }
  244. if (uiData == DONE)
  245. {
  246. OUT_SAVE_INST_DATA;
  247. std::ostringstream saveStream;
  248. for(uint8 i = 0; i < MAX_ENCOUNTERS; ++i)
  249. saveStream << m_auiEncounter[i] << " ";
  250. strSaveData = saveStream.str();
  251. SaveToDB();
  252. OUT_SAVE_INST_DATA_COMPLETE;
  253. }
  254. }
  255. const char* Save()
  256. {
  257. return strSaveData.c_str();
  258. }
  259. uint32 GetData(uint32 uiType)
  260. {
  261. switch(uiType)
  262. {
  263. case TYPE_RAGEFIRE: return m_auiEncounter[uiType];
  264. case TYPE_BALTHARUS: return m_auiEncounter[uiType];
  265. case TYPE_XERESTRASZA: return m_auiEncounter[uiType];
  266. case TYPE_ZARITHRIAN: return m_auiEncounter[uiType];
  267. case TYPE_HALION: return m_auiEncounter[uiType];
  268. case TYPE_EVENT: return m_auiEncounter[uiType];
  269. case TYPE_HALION_EVENT: return m_auiHalionEvent;
  270. case TYPE_EVENT_TIMER: return m_auiEventTimer;
  271. case TYPE_EVENT_NPC: switch (m_auiEncounter[TYPE_EVENT])
  272. {
  273. case 10:
  274. case 20:
  275. case 30:
  276. case 40:
  277. case 50:
  278. case 60:
  279. case 70:
  280. case 80:
  281. case 90:
  282. case 100:
  283. case 110:
  284. case 200:
  285. case 210:
  286. return NPC_XERESTRASZA;
  287. break;
  288. default:
  289. break;
  290. };
  291. return 0;
  292. case DATA_ORB_DIRECTION: return m_auiOrbDirection;
  293. case DATA_ORB_N: return m_auiOrbNState;
  294. case DATA_ORB_S: return m_auiOrbSState;
  295. }
  296. return 0;
  297. }
  298. void Load(const char* chrIn)
  299. {
  300. if (!chrIn)
  301. {
  302. OUT_LOAD_INST_DATA_FAIL;
  303. return;
  304. }
  305. OUT_LOAD_INST_DATA(chrIn);
  306. std::istringstream loadStream(chrIn);
  307. for(uint8 i = 0; i < MAX_ENCOUNTERS; ++i)
  308. {
  309. loadStream >> m_auiEncounter[i];
  310. if (m_auiEncounter[i] == IN_PROGRESS
  311. || m_auiEncounter[i] == FAIL)
  312. m_auiEncounter[i] = NOT_STARTED;
  313. }
  314. m_auiEncounter[TYPE_XERESTRASZA] = NOT_STARTED;
  315. OUT_LOAD_INST_DATA_COMPLETE;
  316. OpenAllDoors();
  317. }
  318. };
  319. InstanceData* GetInstanceData_instance_ruby_sanctum(Map* pMap)
  320. {
  321. return new instance_ruby_sanctum(pMap);
  322. }
  323. void AddSC_instance_ruby_sanctum()
  324. {
  325. Script* pNewScript;
  326. pNewScript = new Script;
  327. pNewScript->Name = "instance_ruby_sanctum";
  328. pNewScript->GetInstanceData = &GetInstanceData_instance_ruby_sanctum;
  329. pNewScript->RegisterSelf();
  330. }