Guest User

Untitled

a guest
Mar 13th, 2010
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.19 KB | None | 0 0
  1. /* Pridefire Gaming > All others. This is our legal statement. FUCK YALL!*/
  2. #include "World.h"
  3. #include "WorldPacket.h"
  4. #include "ObjectMgr.h"
  5. #include "BattleGroundMgr.h"
  6. #include "BattleGround.h"
  7. #include "BattleGroundIC.h"
  8. #include "Creature.h"
  9. #include "Language.h"
  10. #include "Object.h"
  11. #include "Player.h"
  12. #include "Util.h"
  13. #include "Unit.h"
  14. #include "stdafx.h
  15.  
  16. // these variables aren't used outside of this file, so declare them only here
  17. uint32 BG_IC_HonorScoreTicks[BG_HONOR_MODE_NUM] = {
  18. 330, // normal honor
  19. 200 // holiday
  20. };
  21.  
  22. BattleGroundIC::BattleGroundIC()
  23. {
  24. m_BuffChange = true;
  25. m_BgObjects.resize(BG_IC_OBJECT_MAX);
  26. m_BgCreatures.resize(BG_IC_ALL_NODES_COUNT);
  27.  
  28. m_StartMessageIds[BG_STARTING_EVENT_FIRST] = LANG_BG_IC_START_TWO_MINUTES;
  29. m_StartMessageIds[BG_STARTING_EVENT_SECOND] = LANG_BG_IC_START_ONE_MINUTE;
  30. m_StartMessageIds[BG_STARTING_EVENT_THIRD] = LANG_BG_IC_START_HALF_MINUTE;
  31. m_StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_IC_HAS_BEGUN;
  32. }
  33.  
  34. BattleGroundIC::~BattleGroundIC()
  35. {
  36. }
  37.  
  38. void BattleGroundIC::Update(uint32 diff)
  39. {
  40. BattleGround::Update(diff);
  41.  
  42. if (GetStatus() == STATUS_IN_PROGRESS)
  43. {
  44. int team_points[BG_TEAMS_COUNT] = { 0, 0 };
  45.  
  46. for (int node = 0; node < BG_IC_DYNAMIC_NODES_COUNT; ++node)
  47. {
  48. if (m_BannerTimers[node].timer)
  49. {
  50. if (m_BannerTimers[node].timer > diff)
  51. m_BannerTimers[node].timer -= diff;
  52. else
  53. {
  54. m_BannerTimers[node].timer = 0;
  55. _CreateBanner(node, m_BannerTimers[node].type, m_BannerTimers[node].teamIndex, false);
  56. }
  57. }
  58. if (m_NodeTimers[node])
  59. {
  60. if (m_NodeTimers[node] > diff)
  61. m_NodeTimers[node] -= diff;
  62. else
  63. {
  64. m_NodeTimers[node] = 0;
  65. uint8 teamIndex = m_Nodes[node]-1;
  66. m_prevNodes[node] = m_Nodes[node];
  67. m_Nodes[node] += 2;
  68. _DelBanner(node, BG_IC_NODE_TYPE_CONTESTED, teamIndex);
  69. _CreateBanner(node, BG_IC_NODE_TYPE_OCCUPIED, teamIndex, true);
  70. _SendNodeUpdate(node);
  71. _NodeOccupied(node,(teamIndex == 0) ? ALLIANCE:HORDE);
  72.  
  73. if (teamIndex == 0)
  74. {
  75. SendMessage2ToAll(LANG_BG_IC_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_ALLIANCE,NULL,LANG_BG_IC_ALLY,_GetNodeNameId(node));
  76. PlaySoundToAll(BG_IC_SOUND_NODE_CAPTURED_ALLIANCE);
  77. }
  78. else
  79. {
  80. SendMessage2ToAll(LANG_BG_IC_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_HORDE,NULL,LANG_BG_IC_HORDE,_GetNodeNameId(node));
  81. PlaySoundToAll(BG_IC_SOUND_NODE_CAPTURED_HORDE);
  82. }
  83. }
  84. }
  85.  
  86. for (int team = 0; team < BG_TEAMS_COUNT; ++team)
  87. if (m_Nodes[node] == team + BG_IC_NODE_TYPE_OCCUPIED)
  88. ++team_points[team];
  89. }
  90. }
  91. }
  92.  
  93. void BattleGroundIC::HandleKillUnit(Creature *unit, Player *killer)
  94. {
  95. sLog.outDebug("bg_ic HandleKillUnit %i",unit->GetEntry());
  96. if(GetStatus() != STATUS_IN_PROGRESS)
  97. return;
  98. uint32 entry = unit->GetEntry();
  99.  
  100. if(entry == BG_IC_StaticCreatureInfo[IC_NPC_A_BOSS][0])
  101. {
  102. RewardHonorToTeam(GetBonusHonor(BG_IC_KILL_BOSS),HORDE);
  103. EndBattleGround(HORDE);
  104. }
  105. else if ( entry == BG_IC_StaticCreatureInfo[IC_NPC_H_BOSS][0] )
  106. {
  107. RewardHonorToTeam(GetBonusHonor(BG_IC_KILL_BOSS),ALLIANCE);
  108. EndBattleGround(ALLIANCE);
  109. }
  110. }
  111.  
  112. const uint16 BattleGroundIC::GetBonusHonor(uint8 kills)
  113. {
  114. return Trinity::Honor::hk_honor_at_level(m_MaxLevel, kills);
  115. }
  116.  
  117. void BattleGroundIC::StartingEventCloseDoors()
  118. {
  119.  
  120. uint16 i;
  121.  
  122. for (int obj = BG_IC_OBJECT_BANNER_NEUTRAL; obj < BG_IC_DYNAMIC_NODES_COUNT * 8; ++obj)
  123. SpawnBGObject(obj, RESPAWN_ONE_DAY);
  124.  
  125. for (i = BG_IC_OBJECT_HORDE_PORTCULLIS; i <= BG_IC_OBJECT_SEAFOAM_BOMB_3 ; i++)
  126. SpawnBGObject(i, RESPAWN_IMMEDIATELY);
  127.  
  128. // Starting doors
  129. DoorClose(BG_IC_OBJECT_GATE_H_1);
  130. DoorClose(BG_IC_OBJECT_GATE_A_1);
  131. DoorClose(BG_IC_OBJECT_GATE_H_2);
  132. DoorClose(BG_IC_OBJECT_GATE_A_2);
  133. DoorClose(BG_IC_OBJECT_GATE_H_3);
  134. DoorClose(BG_IC_OBJECT_GATE_A_3);
  135. SpawnBGObject(BG_IC_OBJECT_GATE_H_1, RESPAWN_IMMEDIATELY);
  136. SpawnBGObject(BG_IC_OBJECT_GATE_A_1, RESPAWN_IMMEDIATELY);
  137. SpawnBGObject(BG_IC_OBJECT_GATE_H_2, RESPAWN_IMMEDIATELY);
  138. SpawnBGObject(BG_IC_OBJECT_GATE_A_2, RESPAWN_IMMEDIATELY);
  139. SpawnBGObject(BG_IC_OBJECT_GATE_H_3, RESPAWN_IMMEDIATELY);
  140. SpawnBGObject(BG_IC_OBJECT_GATE_A_3, RESPAWN_IMMEDIATELY);
  141.  
  142. _NodeOccupied(BG_IC_SPIRIT_ALIANCE,ALLIANCE);
  143. _NodeOccupied(BG_IC_SPIRIT_HORDE,HORDE);
  144. }
  145.  
  146. void BattleGroundIC::StartingEventOpenDoors()
  147. {
  148. for (int banner = BG_IC_OBJECT_BANNER_NEUTRAL, i = 0; i < 5; banner += 8, ++i)
  149. SpawnBGObject(banner, RESPAWN_IMMEDIATELY);
  150. DoorOpen(BG_IC_OBJECT_GATE_H_1);
  151. DoorOpen(BG_IC_OBJECT_GATE_A_1);
  152. DoorOpen(BG_IC_OBJECT_GATE_H_2);
  153. DoorOpen(BG_IC_OBJECT_GATE_A_2);
  154. DoorOpen(BG_IC_OBJECT_GATE_H_3);
  155. DoorOpen(BG_IC_OBJECT_GATE_A_3);
  156. }
  157.  
  158. void BattleGroundIC::AddPlayer(Player *plr)
  159. {
  160. BattleGround::AddPlayer(plr);
  161. BattleGroundICScore* sc = new BattleGroundICScore;
  162.  
  163. m_PlayerScores[plr->GetGUID()] = sc;
  164. }
  165.  
  166. void BattleGroundIC::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
  167. {
  168.  
  169. }
  170.  
  171. void BattleGroundIC::HandleAreaTrigger(Player *Source, uint32 Trigger)
  172. {
  173. if (GetStatus() != STATUS_IN_PROGRESS)
  174. return;
  175. }
  176.  
  177. Creature* BattleGroundIC::AddICCreature(uint16 cinfoid, uint16 type)
  178. {
  179. // In retail these only spawn if you've destroyed a gate, but who cares right now. We'll fix it l8r
  180. // Which also techincally makes them not static, ill fix that later to.
  181. uint8 level;
  182. bool isStatic = false;
  183. Creature* creature = NULL;
  184. if (type >= IC_STATICCPLACE_MAX)
  185. {
  186. type -= IC_STATICCPLACE_MAX;
  187. cinfoid=uint16(BG_IC_StaticCreaturePos[type][4]);
  188. creature = AddCreature(BG_IC_StaticCreatureInfo[cinfoid][0],(type+IC_STATICCPLACE_MAX),BG_IC_StaticCreatureInfo[cinfoid][1],BG_IC_StaticCreaturePos[type][0],BG_IC_StaticCreaturePos[type][1],BG_IC_StaticCreaturePos[type][2],BG_IC_StaticCreaturePos[type][3]);
  189. level = (BG_IC_StaticCreatureInfo[cinfoid][2] == BG_IC_StaticCreatureInfo[cinfoid][3]) ? BG_IC_StaticCreatureInfo[cinfoid][2] : urand(BG_IC_StaticCreatureInfo[cinfoid][2],BG_IC_StaticCreatureInfo[cinfoid][3]);
  190. isStatic = true;
  191. }
  192. if (!creature)
  193. return NULL;
  194. creature->GetMotionMaster()->Initialize();
  195. creature->setDeathState(JUST_DIED);
  196. creature->Respawn();
  197.  
  198. return creature;
  199. }
  200.  
  201. void BattleGroundIC::_CreateBanner(uint8 node, uint8 type, uint8 teamIndex, bool delay)
  202. {
  203. if (delay)
  204. {
  205. m_BannerTimers[node].timer = 2000;
  206. m_BannerTimers[node].type = type;
  207. m_BannerTimers[node].teamIndex = teamIndex;
  208. return;
  209. }
  210.  
  211. uint8 obj = node*8 + type + teamIndex;
  212.  
  213. SpawnBGObject(obj, RESPAWN_IMMEDIATELY);
  214.  
  215. if (!type)
  216. return;
  217. obj = node * 8 + ((type == BG_IC_NODE_TYPE_OCCUPIED) ? (5 + teamIndex) : 7);
  218. SpawnBGObject(obj, RESPAWN_IMMEDIATELY);
  219. }
  220.  
  221. void BattleGroundIC::_DelBanner(uint8 node, uint8 type, uint8 teamIndex)
  222. {
  223. uint8 obj = node*8 + type + teamIndex;
  224. SpawnBGObject(obj, RESPAWN_ONE_DAY);
  225.  
  226. if (!type)
  227. return;
  228. obj = node * 8 + ((type == BG_IC_NODE_TYPE_OCCUPIED) ? (5 + teamIndex) : 7);
  229. SpawnBGObject(obj, RESPAWN_ONE_DAY);
  230. }
  231.  
  232. int32 BattleGroundIC::_GetNodeNameId(uint8 node)
  233. {
  234. switch (node)
  235. {
  236. case BG_IC_NODE_WORKSHOP: return LANG_BG_IC_NODE_WORKSHOP;
  237. case BG_IC_NODE_QUARRY: return LANG_BG_IC_NODE_QUARRY;
  238. case BG_IC_NODE_REFINERY: return LANG_BG_IC_NODE_REFINERY;
  239. case BG_IC_NODE_DOCKS:return LANG_BG_IC_NODE_DOCKS;
  240. case BG_IC_NODE_HANGAR: return LANG_BG_IC_NODE_HANGAR;
  241. default:
  242. ASSERT(0);
  243. }
  244. return 0;
  245. }
  246.  
  247. void BattleGroundIC::FillInitialWorldStates(WorldPacket& data)
  248. {
  249. data << uint32(IC_Alliance_Score) << uint32(m_Team_Scores[0]);
  250. data << uint32(IC_Horde_Score) << uint32(m_Team_Scores[1]);
  251. if(GetStatus() == STATUS_IN_PROGRESS){
  252. data << uint32(IC_SHOW_A_SCORE) << uint32(1);
  253. data << uint32(IC_SHOW_H_SCORE) << uint32(1);
  254. }
  255. else
  256. {
  257. data << uint32(IC_SHOW_A_SCORE) << uint32(0);
  258. data << uint32(IC_SHOW_H_SCORE) << uint32(0);
  259. }
  260. }
  261.  
  262. void BattleGroundIC::_SendNodeUpdate(uint8 node)
  263. {
  264. const uint8 plusArray[] = {0, 2, 3, 0, 1};
  265.  
  266. if (m_prevNodes[node])
  267. UpdateWorldState(BG_IC_OP_NODESTATES[node] + plusArray[m_prevNodes[node]], 0);
  268. else
  269. UpdateWorldState(BG_IC_OP_NODEICONS[node], 0);
  270.  
  271. UpdateWorldState(BG_IC_OP_NODESTATES[node] + plusArray[m_Nodes[node]], 1);
  272.  
  273. uint8 ally = 0, horde = 0;
  274. for (uint8 i = 0; i < BG_IC_DYNAMIC_NODES_COUNT; ++i)
  275. if (m_Nodes[i] == BG_IC_NODE_STATUS_ALLY_OCCUPIED)
  276. ++ally;
  277. else if (m_Nodes[i] == BG_IC_NODE_STATUS_HORDE_OCCUPIED)
  278. ++horde;
  279. }
  280.  
  281. void BattleGroundIC::_NodeOccupied(uint8 node,Team team)
  282. {
  283. if (!AddSpiritGuide(node, BG_IC_SpiritGuidePos[node][0], BG_IC_SpiritGuidePos[node][1], BG_IC_SpiritGuidePos[node][2], BG_IC_SpiritGuidePos[node][3], team))
  284. sLog.outError("Failed to spawn spirit guide! point: %u, team: %u,", node, team);
  285. // SpawnBGCreature(node,RESPAWN_IMMEDIATELY);
  286.  
  287. uint8 capturedNodes = 0;
  288. for (uint8 i = 0; i < BG_IC_DYNAMIC_NODES_COUNT; ++i)
  289. {
  290. if (m_Nodes[node] == GetTeamIndexByTeamId(team) + BG_IC_NODE_TYPE_OCCUPIED && !m_NodeTimers[i])
  291. ++capturedNodes;
  292. }
  293. }
  294.  
  295. void BattleGroundIC::_NodeDeOccupied(uint8 node)
  296. {
  297. if (node >= BG_IC_DYNAMIC_NODES_COUNT)
  298. return;
  299.  
  300. std::vector<uint64> ghost_list = m_ReviveQueue[m_BgCreatures[node]];
  301. if (!ghost_list.empty())
  302. {
  303. WorldSafeLocsEntry const *ClosestGrave = NULL;
  304. for (std::vector<uint64>::const_iterator itr = ghost_list.begin(); itr != ghost_list.end(); ++itr)
  305. {
  306. Player* plr = objmgr.GetPlayer(*itr);
  307. if (!plr)
  308. continue;
  309.  
  310. if (!ClosestGrave)
  311. ClosestGrave = GetClosestGraveYard(plr);
  312.  
  313. if (ClosestGrave)
  314. plr->TeleportTo(GetMapId(), ClosestGrave->x, ClosestGrave->y, ClosestGrave->z, plr->GetOrientation());
  315. }
  316. }
  317.  
  318. if (m_BgCreatures[node])
  319. DelCreature(node);
  320. }
  321.  
  322. void BattleGroundIC::EventPlayerClickedOnFlag(Player *source, GameObject* /*target_obj*/)
  323. {
  324. if (GetStatus() != STATUS_IN_PROGRESS)
  325. return;
  326.  
  327. uint8 node = BG_IC_NODE_WORKSHOP;
  328. GameObject* obj=GetBgMap()->GetGameObject(m_BgObjects[node*8+7]);
  329. while ( (node < BG_IC_DYNAMIC_NODES_COUNT) && ((!obj) || (!source->IsWithinDistInMap(obj,10))))
  330. {
  331. ++node;
  332. obj=GetBgMap()->GetGameObject(m_BgObjects[node*8+BG_IC_OBJECT_AURA_CONTESTED]);
  333. }
  334.  
  335. if (node == BG_IC_DYNAMIC_NODES_COUNT)
  336. {
  337. return;
  338. }
  339.  
  340. BattleGroundTeamId teamIndex = GetTeamIndexByTeamId(source->GetTeam());
  341.  
  342. if (!(m_Nodes[node] == 0 || teamIndex == m_Nodes[node]%2))
  343. return;
  344.  
  345. source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
  346. uint32 sound = 0;
  347. if (m_Nodes[node] == BG_IC_NODE_TYPE_NEUTRAL)
  348. {
  349. UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
  350. m_prevNodes[node] = m_Nodes[node];
  351. m_Nodes[node] = teamIndex + 1;
  352. _DelBanner(node, BG_IC_NODE_TYPE_NEUTRAL, 0);
  353. _CreateBanner(node, BG_IC_NODE_TYPE_CONTESTED, teamIndex, true);
  354. _SendNodeUpdate(node);
  355. m_NodeTimers[node] = BG_IC_FLAG_CAPTURING_TIME;
  356.  
  357. if (teamIndex == 0)
  358. SendMessage2ToAll(LANG_BG_IC_NODE_CLAIMED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node), LANG_BG_IC_ALLY);
  359. else
  360. SendMessage2ToAll(LANG_BG_IC_NODE_CLAIMED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node), LANG_BG_IC_HORDE);
  361.  
  362. sound = BG_IC_SOUND_NODE_CLAIMED;
  363. }
  364. else if ((m_Nodes[node] == BG_IC_NODE_STATUS_ALLY_CONTESTED) || (m_Nodes[node] == BG_IC_NODE_STATUS_HORDE_CONTESTED))
  365. {
  366. if (m_prevNodes[node] < BG_IC_NODE_TYPE_OCCUPIED)
  367. {
  368. UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
  369. m_prevNodes[node] = m_Nodes[node];
  370. m_Nodes[node] = teamIndex + BG_IC_NODE_TYPE_CONTESTED;
  371. _DelBanner(node, BG_IC_NODE_TYPE_CONTESTED, !teamIndex);
  372. _CreateBanner(node, BG_IC_NODE_TYPE_CONTESTED, teamIndex, true);
  373. _SendNodeUpdate(node);
  374. m_NodeTimers[node] = BG_IC_FLAG_CAPTURING_TIME;
  375.  
  376. if (teamIndex == BG_TEAM_ALLIANCE)
  377. SendMessage2ToAll(LANG_BG_IC_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node));
  378. else
  379. SendMessage2ToAll(LANG_BG_IC_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node));
  380. }
  381. else
  382. {
  383. UpdatePlayerScore(source, SCORE_BASES_DEFENDED, 1);
  384. m_prevNodes[node] = m_Nodes[node];
  385. m_Nodes[node] = teamIndex + BG_IC_NODE_TYPE_OCCUPIED;
  386. _DelBanner(node, BG_IC_NODE_TYPE_CONTESTED, !teamIndex);
  387. _CreateBanner(node, BG_IC_NODE_TYPE_OCCUPIED, teamIndex, true);
  388. _SendNodeUpdate(node);
  389. m_NodeTimers[node] = 0;
  390. _NodeOccupied(node,(teamIndex == BG_TEAM_ALLIANCE) ? ALLIANCE:HORDE);
  391.  
  392. if (teamIndex == BG_TEAM_ALLIANCE)
  393. SendMessage2ToAll(LANG_BG_IC_NODE_DEFENDED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node));
  394. else
  395. SendMessage2ToAll(LANG_BG_IC_NODE_DEFENDED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node));
  396. }
  397. sound = (teamIndex == BG_TEAM_ALLIANCE) ? BG_IC_SOUND_NODE_ASSAULTED_ALLIANCE : BG_IC_SOUND_NODE_ASSAULTED_HORDE;
  398. }
  399. else
  400. {
  401. UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
  402. m_prevNodes[node] = m_Nodes[node];
  403. m_Nodes[node] = teamIndex + BG_IC_NODE_TYPE_CONTESTED;
  404. _DelBanner(node, BG_IC_NODE_TYPE_OCCUPIED, !teamIndex);
  405. _CreateBanner(node, BG_IC_NODE_TYPE_CONTESTED, teamIndex, true);
  406. _SendNodeUpdate(node);
  407. _NodeDeOccupied(node);
  408. m_NodeTimers[node] = BG_IC_FLAG_CAPTURING_TIME;
  409.  
  410. if (teamIndex == BG_TEAM_ALLIANCE)
  411. SendMessage2ToAll(LANG_BG_IC_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node));
  412. else
  413. SendMessage2ToAll(LANG_BG_IC_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node));
  414.  
  415. sound = (teamIndex == BG_TEAM_ALLIANCE) ? BG_IC_SOUND_NODE_ASSAULTED_ALLIANCE : BG_IC_SOUND_NODE_ASSAULTED_HORDE;
  416. }
  417.  
  418. if (m_Nodes[node] >= BG_IC_NODE_TYPE_OCCUPIED)
  419. {
  420. if (teamIndex == BG_TEAM_ALLIANCE)
  421. SendMessage2ToAll(LANG_BG_IC_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_ALLIANCE, NULL, LANG_BG_IC_ALLY, _GetNodeNameId(node));
  422. else
  423. SendMessage2ToAll(LANG_BG_IC_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_HORDE, NULL, LANG_BG_IC_HORDE, _GetNodeNameId(node));
  424. }
  425. PlaySoundToAll(sound);
  426. }
  427.  
  428. bool BattleGroundIC::SetupBattleGround()
  429. {
  430. uint16 i;
  431.  
  432. sLog.outDebug("BG_IC: start spawning static creatures");
  433. for (i=0; i < IC_STATICCPLACE_MAX; i++ )
  434. AddICCreature(0,i+IC_STATICCPLACE_MAX);
  435.  
  436. for (int i = 0 ; i < BG_IC_DYNAMIC_NODES_COUNT; ++i)
  437. {
  438. if (!AddObject(BG_IC_OBJECT_BANNER_NEUTRAL + 8*i,BG_IC_OBJECTID_NODE_BANNER_0 + i,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  439. || !AddObject(BG_IC_OBJECT_BANNER_CONT_A + 8*i,BG_IC_OBJECTID_BANNER_CONT_A,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  440. || !AddObject(BG_IC_OBJECT_BANNER_CONT_H + 8*i,BG_IC_OBJECTID_BANNER_CONT_H,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  441. || !AddObject(BG_IC_OBJECT_BANNER_ALLY + 8*i,BG_IC_OBJECTID_BANNER_A,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  442. || !AddObject(BG_IC_OBJECT_BANNER_HORDE + 8*i,BG_IC_OBJECTID_BANNER_H,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  443. || !AddObject(BG_IC_OBJECT_AURA_ALLY + 8*i,BG_IC_OBJECTID_AURA_A,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  444. || !AddObject(BG_IC_OBJECT_AURA_HORDE + 8*i,BG_IC_OBJECTID_AURA_H,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  445. || !AddObject(BG_IC_OBJECT_AURA_CONTESTED + 8*i,BG_IC_OBJECTID_AURA_C,BG_IC_NodePositions[i][0],BG_IC_NodePositions[i][1],BG_IC_NodePositions[i][2],BG_IC_NodePositions[i][3], 0, 0, sin(BG_IC_NodePositions[i][3]/2), cos(BG_IC_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
  446. )
  447. {
  448. sLog.outErrorDb("BatteGroundIC: Failed to spawn some object BattleGround not created!");
  449. return false;
  450. }
  451. }
  452. if (!AddObject(BG_IC_OBJECT_GATE_H_1,BG_IC_OBJECTID_GATE_H_1,BG_IC_DoorPositions[0][0],BG_IC_DoorPositions[0][1],BG_IC_DoorPositions[0][2],BG_IC_DoorPositions[0][3],BG_IC_DoorPositions[0][4],BG_IC_DoorPositions[0][5],BG_IC_DoorPositions[0][6],BG_IC_DoorPositions[0][7],RESPAWN_ONE_DAY)
  453. || !AddObject(BG_IC_OBJECT_GATE_A_1,BG_IC_OBJECTID_GATE_A_1,BG_IC_DoorPositions[1][0],BG_IC_DoorPositions[1][1],BG_IC_DoorPositions[1][2],BG_IC_DoorPositions[1][3],BG_IC_DoorPositions[1][4],BG_IC_DoorPositions[1][5],BG_IC_DoorPositions[1][6],BG_IC_DoorPositions[1][7],RESPAWN_ONE_DAY)
  454. || !AddObject(BG_IC_OBJECT_GATE_H_2,BG_IC_OBJECTID_GATE_H_2,BG_IC_DoorPositions[2][0],BG_IC_DoorPositions[2][1],BG_IC_DoorPositions[2][2],BG_IC_DoorPositions[2][3],BG_IC_DoorPositions[2][4],BG_IC_DoorPositions[2][5],BG_IC_DoorPositions[2][6],BG_IC_DoorPositions[2][7],RESPAWN_ONE_DAY)
  455. || !AddObject(BG_IC_OBJECT_GATE_A_2,BG_IC_OBJECTID_GATE_A_2,BG_IC_DoorPositions[3][0],BG_IC_DoorPositions[3][1],BG_IC_DoorPositions[3][2],BG_IC_DoorPositions[3][3],BG_IC_DoorPositions[3][4],BG_IC_DoorPositions[3][5],BG_IC_DoorPositions[3][6],BG_IC_DoorPositions[3][7],RESPAWN_ONE_DAY)
  456. || !AddObject(BG_IC_OBJECT_GATE_H_3,BG_IC_OBJECTID_GATE_H_3,BG_IC_DoorPositions[4][0],BG_IC_DoorPositions[4][1],BG_IC_DoorPositions[4][2],BG_IC_DoorPositions[4][3],BG_IC_DoorPositions[4][4],BG_IC_DoorPositions[4][5],BG_IC_DoorPositions[4][6],BG_IC_DoorPositions[4][7],RESPAWN_ONE_DAY)
  457. || !AddObject(BG_IC_OBJECT_GATE_A_3,BG_IC_OBJECTID_GATE_A_3,BG_IC_DoorPositions[5][0],BG_IC_DoorPositions[5][1],BG_IC_DoorPositions[5][2],BG_IC_DoorPositions[5][3],BG_IC_DoorPositions[5][4],BG_IC_DoorPositions[5][5],BG_IC_DoorPositions[5][6],BG_IC_DoorPositions[5][7],RESPAWN_ONE_DAY)
  458. || !AddObject(BG_IC_OBJECT_DESTRUCT_GATE_H_1,BG_IC_OBJECTID_DESTRUCT_GATE_H_1,BG_IC_DestructDoorPositions[0][0],BG_IC_DestructDoorPositions[0][1],BG_IC_DestructDoorPositions[0][2],BG_IC_DestructDoorPositions[0][3],BG_IC_DestructDoorPositions[0][4],BG_IC_DestructDoorPositions[0][5],BG_IC_DestructDoorPositions[0][6],BG_IC_DestructDoorPositions[0][7],RESPAWN_ONE_DAY)
  459. || !AddObject(BG_IC_OBJECT_DESTRUCT_GATE_A_1,BG_IC_OBJECTID_DESTRUCT_GATE_A_1,BG_IC_DestructDoorPositions[1][0],BG_IC_DestructDoorPositions[1][1],BG_IC_DestructDoorPositions[1][2],BG_IC_DestructDoorPositions[1][3],BG_IC_DestructDoorPositions[1][4],BG_IC_DestructDoorPositions[1][5],BG_IC_DestructDoorPositions[1][6],BG_IC_DestructDoorPositions[1][7],RESPAWN_ONE_DAY)
  460. || !AddObject(BG_IC_OBJECT_DESTRUCT_GATE_H_2,BG_IC_OBJECTID_DESTRUCT_GATE_H_2,BG_IC_DestructDoorPositions[2][0],BG_IC_DestructDoorPositions[2][1],BG_IC_DestructDoorPositions[2][2],BG_IC_DestructDoorPositions[2][3],BG_IC_DestructDoorPositions[2][4],BG_IC_DestructDoorPositions[2][5],BG_IC_DestructDoorPositions[2][6],BG_IC_DestructDoorPositions[2][7],RESPAWN_ONE_DAY)
  461. || !AddObject(BG_IC_OBJECT_DESTRUCT_GATE_A_2,BG_IC_OBJECTID_DESTRUCT_GATE_A_2,BG_IC_DestructDoorPositions[3][0],BG_IC_DestructDoorPositions[3][1],BG_IC_DestructDoorPositions[3][2],BG_IC_DestructDoorPositions[3][3],BG_IC_DestructDoorPositions[3][4],BG_IC_DestructDoorPositions[3][5],BG_IC_DestructDoorPositions[3][6],BG_IC_DestructDoorPositions[3][7],RESPAWN_ONE_DAY)
  462. || !AddObject(BG_IC_OBJECT_DESTRUCT_GATE_H_3,BG_IC_OBJECTID_DESTRUCT_GATE_H_3,BG_IC_DestructDoorPositions[4][0],BG_IC_DestructDoorPositions[4][1],BG_IC_DestructDoorPositions[4][2],BG_IC_DestructDoorPositions[4][3],BG_IC_DestructDoorPositions[4][4],BG_IC_DestructDoorPositions[4][5],BG_IC_DestructDoorPositions[4][6],BG_IC_DestructDoorPositions[4][7],RESPAWN_ONE_DAY)
  463. || !AddObject(BG_IC_OBJECT_DESTRUCT_GATE_A_3,BG_IC_OBJECTID_DESTRUCT_GATE_A_3,BG_IC_DestructDoorPositions[5][0],BG_IC_DestructDoorPositions[5][1],BG_IC_DestructDoorPositions[5][2],BG_IC_DestructDoorPositions[5][3],BG_IC_DestructDoorPositions[5][4],BG_IC_DestructDoorPositions[5][5],BG_IC_DestructDoorPositions[5][6],BG_IC_DestructDoorPositions[5][7],RESPAWN_ONE_DAY)
  464. )
  465. {
  466. sLog.outErrorDb("BatteGroundIC: Failed to spawn door object BattleGround not created!");
  467. return false;
  468. }
  469. return true;
  470. }
  471.  
  472. void BattleGroundIC::Reset()
  473. {
  474. BattleGround::Reset();
  475.  
  476. m_TeamScores[BG_TEAM_ALLIANCE] = 0;
  477. m_TeamScores[BG_TEAM_HORDE] = 0;
  478. m_lastTick[BG_TEAM_ALLIANCE] = 0;
  479. m_lastTick[BG_TEAM_HORDE] = 0;
  480. m_HonorScoreTics[BG_TEAM_ALLIANCE] = 0;
  481. m_HonorScoreTics[BG_TEAM_HORDE] = 0;
  482. m_IsInformedNearVictory = false;
  483. bool isBGWeekend = sBattleGroundMgr.IsBGWeekend(GetTypeID());
  484. m_HonorTics = (isBGWeekend) ? BG_IC_ICBGWeekendHonorTicks : BG_IC_NotICBGWeekendHonorTicks;
  485.  
  486. for (uint8 i = 0; i < BG_IC_DYNAMIC_NODES_COUNT; ++i)
  487. {
  488. m_Nodes[i] = 0;
  489. m_prevNodes[i] = 0;
  490. m_NodeTimers[i] = 0;
  491. m_BannerTimers[i].timer = 0;
  492. }
  493.  
  494. for (uint8 i = 0; i < BG_IC_ALL_NODES_COUNT; ++i)
  495. if (m_BgCreatures[i])
  496. DelCreature(i);
  497. }
  498.  
  499. void BattleGroundIC::EndBattleGround(uint32 winner)
  500. {
  501. if (winner == ALLIANCE)
  502. RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
  503. if (winner == HORDE)
  504. RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
  505. RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
  506. RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
  507.  
  508. BattleGround::EndBattleGround(winner);
  509. }
  510.  
  511. WorldSafeLocsEntry const* BattleGroundIC::GetClosestGraveYard(Player* player)
  512. {
  513. BattleGroundTeamId teamIndex = GetTeamIndexByTeamId(player->GetTeam());
  514.  
  515. std::vector<uint8> nodes;
  516. for (uint8 i = 0; i < BG_IC_DYNAMIC_NODES_COUNT; ++i)
  517. if (m_Nodes[i] == teamIndex + 3)
  518. nodes.push_back(i);
  519.  
  520. WorldSafeLocsEntry const* good_entry = NULL;
  521. if (!nodes.empty())
  522. {
  523. float plr_x = player->GetPositionX();
  524. float plr_y = player->GetPositionY();
  525.  
  526. float mindist = 999999.0f;
  527. for (uint8 i = 0; i < nodes.size(); ++i)
  528. {
  529. WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry( BG_IC_GraveyardIds[nodes[i]] );
  530. if (!entry)
  531. continue;
  532. float dist = (entry->x - plr_x)*(entry->x - plr_x)+(entry->y - plr_y)*(entry->y - plr_y);
  533. if (mindist > dist)
  534. {
  535. mindist = dist;
  536. good_entry = entry;
  537. }
  538. }
  539. nodes.clear();
  540. }
  541. if (!good_entry)
  542. good_entry = sWorldSafeLocsStore.LookupEntry( BG_IC_GraveyardIds[teamIndex+5] );
  543.  
  544. return good_entry;
  545. }
  546.  
  547. void BattleGroundIC::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
  548. {
  549. BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetGUID());
  550. if( itr == m_PlayerScores.end() )
  551. return;
  552.  
  553. switch(type)
  554. {
  555. case SCORE_BASES_ASSAULTED:
  556. ((BattleGroundICScore*)itr->second)->BasesAssaulted += value;
  557. break;
  558. case SCORE_BASES_DEFENDED:
  559. ((BattleGroundICScore*)itr->second)->BasesDefended += value;
  560. break;
  561. default:
  562. BattleGround::UpdatePlayerScore(Source,type,value);
  563. break;
  564. }
  565. }
Advertisement
Add Comment
Please, Sign In to add comment