PageRenderTime 311ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ArkCORE-master/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp

https://bitbucket.org/nfeldkamp/lfgfixing
C++ | 328 lines | 254 code | 41 blank | 33 comment | 34 complexity | efb972446d9568c89b30e3d4c4e46f4a MD5 | raw file
  1. /*
  2. * Copyright (C) 2008 - 2013 TrinityCore <http://www.trinitycore.org/>
  3. * Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
  4. *
  5. * Copyright (C) 2011 - 2013 ArkCORE <http://www.arkania.net/>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /* ScriptData
  21. SDName: Instance_Mount_Hyjal
  22. SD%Complete: 100
  23. SDComment: Instance Data Scripts and functions to acquire mobs and set encounter status for use in various Hyjal Scripts
  24. SDCategory: Caverns of Time, Mount Hyjal
  25. EndScriptData */
  26. #include "ScriptPCH.h"
  27. #include "hyjal.h"
  28. #include "hyjal_trash.h"
  29. enum eEnums
  30. {
  31. MAX_ENCOUNTER = 5,
  32. GO_ANCIENT_GEM = 185557
  33. };
  34. /* Battle of Mount Hyjal encounters:
  35. 0 - Rage Winterchill event
  36. 1 - Anetheron event
  37. 2 - Kaz'rogal event
  38. 3 - Azgalor event
  39. 4 - Archimonde event
  40. */
  41. class instance_hyjal : public InstanceMapScript
  42. {
  43. public:
  44. instance_hyjal() : InstanceMapScript("instance_hyjal", 534) { }
  45. InstanceScript* GetInstanceScript(InstanceMap* map) const
  46. {
  47. return new instance_mount_hyjal_InstanceMapScript(map);
  48. }
  49. struct instance_mount_hyjal_InstanceMapScript : public InstanceScript
  50. {
  51. instance_mount_hyjal_InstanceMapScript(Map* map) : InstanceScript(map) {}
  52. uint32 m_auiEncounter[MAX_ENCOUNTER];
  53. std::string str_data;
  54. std::list<uint64> m_uiAncientGemGUID;
  55. uint64 RageWinterchill;
  56. uint64 Anetheron;
  57. uint64 Kazrogal;
  58. uint64 Azgalor;
  59. uint64 Archimonde;
  60. uint64 JainaProudmoore;
  61. uint64 Thrall;
  62. uint64 TyrandeWhisperwind;
  63. uint64 HordeGate;
  64. uint64 ElfGate;
  65. uint32 Trash;
  66. uint32 hordeRetreat;
  67. uint32 allianceRetreat;
  68. bool ArchiYell;
  69. uint32 RaidDamage;
  70. #define YELL_EFFORTS "All of your efforts have been in vain, for the draining of the World Tree has already begun. Soon the heart of your world will beat no more."
  71. #define YELL_EFFORTS_NAME "Archimonde"
  72. void Initialize()
  73. {
  74. memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
  75. m_uiAncientGemGUID.clear();
  76. RageWinterchill = 0;
  77. Anetheron = 0;
  78. Kazrogal = 0;
  79. Azgalor = 0;
  80. Archimonde = 0;
  81. JainaProudmoore = 0;
  82. Thrall = 0;
  83. TyrandeWhisperwind = 0;
  84. HordeGate = 0;
  85. ElfGate = 0;
  86. ArchiYell = false;
  87. RaidDamage = 0;
  88. Trash = 0;
  89. hordeRetreat = 0;
  90. allianceRetreat = 0;
  91. }
  92. bool IsEncounterInProgress() const
  93. {
  94. for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
  95. if (m_auiEncounter[i] == IN_PROGRESS) return true;
  96. return false;
  97. }
  98. void OnGameObjectCreate(GameObject* go, bool /*add*/)
  99. {
  100. switch (go->GetEntry())
  101. {
  102. case 182060:
  103. HordeGate = go->GetGUID();
  104. if (allianceRetreat)
  105. HandleGameObject(0, true, go);
  106. else
  107. HandleGameObject(0, false, go);
  108. break;
  109. case 182061:
  110. ElfGate = go->GetGUID();
  111. if (hordeRetreat)
  112. HandleGameObject(0, true, go);
  113. else
  114. HandleGameObject(0, false, go);
  115. break;
  116. case GO_ANCIENT_GEM:
  117. m_uiAncientGemGUID.push_back(go->GetGUID());
  118. break;
  119. }
  120. }
  121. void OnCreatureCreate(Creature* creature, bool /*add*/)
  122. {
  123. switch (creature->GetEntry())
  124. {
  125. case 17767: RageWinterchill = creature->GetGUID(); break;
  126. case 17808: Anetheron = creature->GetGUID(); break;
  127. case 17888: Kazrogal = creature->GetGUID(); break;
  128. case 17842: Azgalor = creature->GetGUID(); break;
  129. case 17968: Archimonde = creature->GetGUID(); break;
  130. case 17772: JainaProudmoore = creature->GetGUID(); break;
  131. case 17852: Thrall = creature->GetGUID(); break;
  132. case 17948: TyrandeWhisperwind = creature->GetGUID(); break;
  133. }
  134. }
  135. uint64 GetData64(uint32 identifier)
  136. {
  137. switch (identifier)
  138. {
  139. case DATA_RAGEWINTERCHILL: return RageWinterchill;
  140. case DATA_ANETHERON: return Anetheron;
  141. case DATA_KAZROGAL: return Kazrogal;
  142. case DATA_AZGALOR: return Azgalor;
  143. case DATA_ARCHIMONDE: return Archimonde;
  144. case DATA_JAINAPROUDMOORE: return JainaProudmoore;
  145. case DATA_THRALL: return Thrall;
  146. case DATA_TYRANDEWHISPERWIND: return TyrandeWhisperwind;
  147. }
  148. return 0;
  149. }
  150. void SetData(uint32 type, uint32 data)
  151. {
  152. switch (type)
  153. {
  154. case DATA_RAGEWINTERCHILLEVENT: m_auiEncounter[0] = data; break;
  155. case DATA_ANETHERONEVENT:
  156. m_auiEncounter[1] = data;
  157. break;
  158. case DATA_KAZROGALEVENT: m_auiEncounter[2] = data; break;
  159. case DATA_AZGALOREVENT:
  160. {
  161. m_auiEncounter[3] = data;
  162. if (data == DONE)
  163. {
  164. if (ArchiYell)break;
  165. ArchiYell = true;
  166. Creature* creature = instance->GetCreature(Azgalor);
  167. if (creature)
  168. {
  169. Creature* unit = creature->SummonCreature(21987, creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 10000);
  170. Map* map = creature->GetMap();
  171. if (map->IsDungeon() && unit)
  172. {
  173. unit->SetVisible(false);
  174. Map::PlayerList const &PlayerList = map->GetPlayers();
  175. if (PlayerList.isEmpty())
  176. return;
  177. for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
  178. {
  179. if (i->getSource())
  180. {
  181. WorldPacket data(SMSG_MESSAGECHAT, 200);
  182. unit->BuildMonsterChat(&data, CHAT_MSG_MONSTER_YELL, YELL_EFFORTS, 0, YELL_EFFORTS_NAME, i->getSource()->GetGUID());
  183. i->getSource()->GetSession()->SendPacket(&data);
  184. WorldPacket data2(SMSG_PLAY_SOUND, 4);
  185. data2 << 10986;
  186. i->getSource()->GetSession()->SendPacket(&data2);
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. break;
  194. case DATA_ARCHIMONDEEVENT: m_auiEncounter[4] = data; break;
  195. case DATA_RESET_TRASH_COUNT: Trash = 0; break;
  196. case DATA_TRASH:
  197. if (data) Trash = data;
  198. else Trash--;
  199. DoUpdateWorldState(WORLD_STATE_ENEMYCOUNT, Trash);
  200. break;
  201. case TYPE_RETREAT:
  202. if (data == SPECIAL)
  203. {
  204. if (!m_uiAncientGemGUID.empty())
  205. {
  206. for (std::list<uint64>::const_iterator itr = m_uiAncientGemGUID.begin(); itr != m_uiAncientGemGUID.end(); ++itr)
  207. {
  208. //don't know how long it expected
  209. DoRespawnGameObject(*itr, DAY);
  210. }
  211. }
  212. }
  213. break;
  214. case DATA_ALLIANCE_RETREAT:
  215. allianceRetreat = data;
  216. HandleGameObject(HordeGate, true);
  217. SaveToDB();
  218. break;
  219. case DATA_HORDE_RETREAT:
  220. hordeRetreat = data;
  221. HandleGameObject(ElfGate, true);
  222. SaveToDB();
  223. break;
  224. case DATA_RAIDDAMAGE:
  225. RaidDamage += data;
  226. if (RaidDamage >= MINRAIDDAMAGE)
  227. RaidDamage = MINRAIDDAMAGE;
  228. break;
  229. case DATA_RESET_RAIDDAMAGE:
  230. RaidDamage = 0;
  231. break;
  232. }
  233. sLog->outDebug(LOG_FILTER_TSCR, "TSCR: Instance Hyjal: Instance data updated for event %u (Data=%u)", type, data);
  234. if (data == DONE)
  235. {
  236. OUT_SAVE_INST_DATA;
  237. std::ostringstream saveStream;
  238. saveStream << m_auiEncounter[0] << ' ' << m_auiEncounter[1] << ' ' << m_auiEncounter[2] << ' '
  239. << m_auiEncounter[3] << ' ' << m_auiEncounter[4]
  240. << ' ' << allianceRetreat << ' ' << hordeRetreat
  241. << ' ' << RaidDamage;
  242. str_data = saveStream.str();
  243. SaveToDB();
  244. OUT_SAVE_INST_DATA_COMPLETE;
  245. }
  246. }
  247. uint32 GetData(uint32 type)
  248. {
  249. switch (type)
  250. {
  251. case DATA_RAGEWINTERCHILLEVENT: return m_auiEncounter[0];
  252. case DATA_ANETHERONEVENT: return m_auiEncounter[1];
  253. case DATA_KAZROGALEVENT: return m_auiEncounter[2];
  254. case DATA_AZGALOREVENT: return m_auiEncounter[3];
  255. case DATA_ARCHIMONDEEVENT: return m_auiEncounter[4];
  256. case DATA_TRASH: return Trash;
  257. case DATA_ALLIANCE_RETREAT: return allianceRetreat;
  258. case DATA_HORDE_RETREAT: return hordeRetreat;
  259. case DATA_RAIDDAMAGE: return RaidDamage;
  260. }
  261. return 0;
  262. }
  263. std::string GetSaveData()
  264. {
  265. return str_data;
  266. }
  267. void Load(const char* in)
  268. {
  269. if (!in)
  270. {
  271. OUT_LOAD_INST_DATA_FAIL;
  272. return;
  273. }
  274. OUT_LOAD_INST_DATA(in);
  275. std::istringstream loadStream(in);
  276. loadStream >> m_auiEncounter[0] >> m_auiEncounter[1] >> m_auiEncounter[2] >> m_auiEncounter[3] >> m_auiEncounter[4] >> allianceRetreat >> hordeRetreat >> RaidDamage;
  277. for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
  278. if (m_auiEncounter[i] == IN_PROGRESS) // Do not load an encounter as IN_PROGRESS - reset it instead.
  279. m_auiEncounter[i] = NOT_STARTED;
  280. OUT_LOAD_INST_DATA_COMPLETE;
  281. }
  282. };
  283. };
  284. void AddSC_instance_mount_hyjal()
  285. {
  286. new instance_hyjal();
  287. }