HeroicOpPackets.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../ClientPacketFunctions.h"
  17. #include "../../common/Log.h"
  18. #include "HeroicOp.h"
  19. #include "../Spells.h"
  20. extern ConfigReader configReader;
  21. extern MasterSpellList master_spell_list;
  22. void ClientPacketFunctions::SendHeroicOPUpdate(Client* client, HeroicOP* ho) {
  23. if (!client) {
  24. LogWrite(PACKET__ERROR, 0, "Packets", "SendHeroicOPUpdate() called without a valid client");
  25. return;
  26. }
  27. if (!ho) {
  28. LogWrite(PACKET__ERROR, 0, "Packets", "SendHeroicOPUpdate() called without a valid HO");
  29. return;
  30. }
  31. PacketStruct* packet = configReader.getStruct("WS_HeroicOpportunity", client->GetVersion());
  32. Spell* spell = 0;
  33. if (packet) {
  34. packet->setDataByName("id", client->GetPlayer()->player_spawn_reverse_id_map[client->GetPlayer()]);
  35. if (ho->GetWheel()) {
  36. spell = master_spell_list.GetSpell(ho->GetWheel()->spell_id, 1);
  37. if (!spell) {
  38. LogWrite(SPELL__ERROR, 0, "HO", "Unable to get the spell (%u)", ho->GetWheel()->spell_id);
  39. return;
  40. }
  41. packet->setDataByName("name", spell->GetName());
  42. packet->setDataByName("description", spell->GetDescription());
  43. packet->setDataByName("order", ho->GetWheel()->order);
  44. packet->setDataByName("time_total", ho->GetTotalTime());
  45. packet->setDataByName("time_left", max(0.0f, (float)(((ho->GetStartTime() + (ho->GetTotalTime() * 1000)) - Timer::GetCurrentTime2()) / 1000)));
  46. // This is not displayed in the wheel so set it to 0xFFFF
  47. packet->setDataByName("starter_icon", 0xFFFF);
  48. if (ho->HasShifted())
  49. packet->setDataByName("shift_icon", 0xFFFF);
  50. else
  51. packet->setDataByName("shift_icon", ho->GetWheel()->shift_icon);
  52. // If completed set special values
  53. if (ho->GetComplete() > 0) {
  54. packet->setDataByName("wheel_type", 2);
  55. packet->setDataByName("unknown", ho->GetComplete());
  56. }
  57. char temp[20];
  58. char ability[20];
  59. // Set the icons for the whee;
  60. for (int8 i = 1; i < 7; i++) {
  61. strcpy(ability, "icon");
  62. itoa(i, temp, 10);
  63. strcat(ability, temp);
  64. packet->setDataByName(ability, ho->GetWheel()->abilities[i-1]);
  65. }
  66. // Flag the icons that are completed
  67. for (int8 i = 1; i < 7; i++) {
  68. strcpy(ability, "countered");
  69. itoa(i, temp, 10);
  70. strcat(ability, temp);
  71. packet->setDataByName(ability, ho->countered[i-1]);
  72. }
  73. }
  74. else {
  75. if (ho->GetComplete() > 0) {
  76. // This will make the ui element vanish
  77. packet->setDataByName("wheel_type", 5);
  78. packet->setDataByName("unknown", 8);
  79. }
  80. else {
  81. packet->setDataByName("wheel_type", 4);
  82. }
  83. packet->setDataByName("icon1", 0xFFFF);
  84. packet->setDataByName("icon2", 0xFFFF);
  85. packet->setDataByName("icon3", 0xFFFF);
  86. packet->setDataByName("icon4", 0xFFFF);
  87. packet->setDataByName("icon5", 0xFFFF);
  88. packet->setDataByName("icon6", 0xFFFF);
  89. packet->setDataByName("shift_icon", 0xFFFF);
  90. int8 index = 1;
  91. char temp[20];
  92. char ability[20];
  93. vector<HeroicOPStarter*>::iterator itr;
  94. for (itr = ho->GetStarterChains()->begin(); itr != ho->GetStarterChains()->end(); itr++, index++) {
  95. if (index > 6 )
  96. break;
  97. strcpy(ability, "icon");
  98. itoa(index, temp, 10);
  99. strcat(ability, temp);
  100. packet->setDataByName(ability, (*itr)->abilities[ho->GetStage()]);
  101. // Only set this once
  102. if (index == 1)
  103. packet->setDataByName("starter_icon", (*itr)->starter_icon);
  104. }
  105. }
  106. client->QueuePacket(packet->serialize());
  107. }
  108. safe_delete(packet);
  109. }
  110. /*
  111. <Struct Name="WS_HeroicOpportunity" ClientVersion="1" OpcodeName="OP_UpdateOpportunityMsg">
  112. <Data ElementName="name" Type="EQ2_16Bit_String" />
  113. <Data ElementName="description" Type="EQ2_16Bit_String" />
  114. <Data ElementName="id" Type="int32" />
  115. <Data ElementName="wheel_type" Type="int8" />
  116. <Data ElementName="unknown" Type="int8" />
  117. <Data ElementName="order" Type="int8" />
  118. <Data ElementName="shift_icon" Type="int16" />
  119. <Data ElementName="starter_icon" Type="int16" />
  120. <Data ElementName="time_total" Type="float" />
  121. <Data ElementName="time_left" Type="float" />
  122. <Data ElementName="icon1" Type="int16" />
  123. <Data ElementName="icon2" Type="int16" />
  124. <Data ElementName="icon3" Type="int16" />
  125. <Data ElementName="icon4" Type="int16" />
  126. <Data ElementName="icon5" Type="int16" />
  127. <Data ElementName="icon6" Type="int16" />
  128. <Data ElementName="countered1" Type="int16" />
  129. <Data ElementName="countered2" Type="int16" />
  130. <Data ElementName="countered3" Type="int16" />
  131. <Data ElementName="countered4" Type="int16" />
  132. <Data ElementName="countered5" Type="int16" />
  133. <Data ElementName="countered6" Type="int16" />
  134. </Struct>
  135. */