HousingPackets.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "../ClientPacketFunctions.h"
  2. #include "../World.h"
  3. #include "../client.h"
  4. extern ConfigReader configReader;
  5. extern World world;
  6. void ClientPacketFunctions::SendHousePurchace(Client* client, HouseZone* hz, int32 spawnID) {
  7. PacketStruct* packet = configReader.getStruct("WS_PlayerHousePurchase", client->GetVersion());
  8. if (packet) {
  9. packet->setDataByName("house_name", hz->name.c_str());
  10. packet->setDataByName("house_id", hz->id);
  11. packet->setDataByName("spawn_id", spawnID);
  12. packet->setDataByName("purchase_coins", hz->cost_coin);
  13. packet->setDataByName("purchace_status", hz->cost_status);
  14. packet->setDataByName("upkeep_coins", hz->upkeep_coin);
  15. packet->setDataByName("upkeep_status", hz->upkeep_status);
  16. packet->setDataByName("vendor_vault_slots", hz->vault_slots);
  17. string req;
  18. if (hz->alignment > 0) {
  19. req = "You must be of ";
  20. if (hz->alignment == 1)
  21. req.append("Good");
  22. else
  23. req.append("Evil");
  24. req.append(" alignment");
  25. }
  26. if (hz->guild_level > 0) {
  27. if (req.length() > 0) {
  28. req.append(", and a guild level of ");
  29. char temp[5];
  30. sprintf(temp, "%i", hz->guild_level);
  31. req.append(temp);
  32. //req.append(std::to_string(static_cast<long long>(hz->guild_level)));
  33. }
  34. else {
  35. req.append("Requires a guild of level ");
  36. char temp[5];
  37. sprintf(temp, "%i", hz->guild_level);
  38. req.append(temp);
  39. //req.append(std::to_string(static_cast<long long>(hz->guild_level)))
  40. req.append(" or above");
  41. }
  42. }
  43. if (req.length() > 0) {
  44. req.append(" in order to purchase a home within the ");
  45. req.append(hz->name);
  46. req.append(".");
  47. }
  48. packet->setDataByName("additional_reqs", req.c_str());
  49. bool enable_buy = true;
  50. if (hz->alignment > 0 && client->GetPlayer()->GetAlignment() != hz->alignment)
  51. enable_buy = false;
  52. if (hz->guild_level > 0 && (!client->GetPlayer()->GetGuild() || (client->GetPlayer()->GetGuild() && client->GetPlayer()->GetGuild()->GetLevel() < hz->guild_level)))
  53. enable_buy = false;
  54. packet->setDataByName("enable_buy", enable_buy ? 1 : 0);
  55. client->QueuePacket(packet->serialize());
  56. }
  57. safe_delete(packet);
  58. }
  59. void ClientPacketFunctions::SendBaseHouseWindow(Client* client, HouseZone* hz, PlayerHouse* ph, int32 spawnID) {
  60. PacketStruct* packet = configReader.getStruct("WS_PlayerHouseBaseScreen", client->GetVersion());
  61. if (packet) {
  62. packet->setDataByName("house_id", ph->unique_id);
  63. packet->setDataByName("spawn_id", spawnID);
  64. string name;
  65. name = ph->player_name;
  66. name.append("'s ");
  67. name.append(hz->name);
  68. packet->setDataByName("house_name", name.c_str());
  69. packet->setDataByName("zone_name", hz->name.c_str());
  70. packet->setDataByName("upkeep_cost_coins", hz->upkeep_coin);
  71. packet->setDataByName("upkeep_cost_status", hz->upkeep_status);
  72. int32 upkeep_due = ph->upkeep_due - Timer::GetUnixTimeStamp();
  73. packet->setDataByName("upkeep_due", upkeep_due);
  74. packet->setDataByName("escrow_balance_coins", ph->escrow_coins);
  75. packet->setDataByName("escrow_balance_status", ph->escrow_status);
  76. // temp - set priv level to owner for now
  77. packet->setDataByName("privlage_level", 4);
  78. // temp - set house type to personal house for now
  79. packet->setDataByName("house_type", 0);
  80. if (client->GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE
  81. || client->GetCurrentZone()->GetInstanceType() == GUILD_HOUSE_INSTANCE) {
  82. // Inside a house need to set a flag and set the history for the tabs
  83. packet->setDataByName("inside_house", 1);
  84. packet->setDataByName("num_access", 0);
  85. packet->setDataByName("public_access_level", 1);
  86. packet->setDataByName("num_history", 0);
  87. }
  88. client->QueuePacket(packet->serialize());
  89. }
  90. safe_delete(packet);
  91. }
  92. void ClientPacketFunctions::SendHouseVisitWindow(Client* client, vector<PlayerHouse*> houses) {
  93. PacketStruct* packet = configReader.getStruct("WS_DisplayVisitScreen", client->GetVersion());
  94. if (packet) {
  95. vector<PlayerHouse*>::iterator itr;
  96. packet->setArrayLengthByName("num_houses", houses.size());
  97. int16 i = 0;
  98. for (itr = houses.begin(); itr != houses.end(); itr++) {
  99. PlayerHouse* ph = *itr;
  100. if (ph) {
  101. HouseZone* hz = world.GetHouseZone(ph->house_id);
  102. if (hz) {
  103. packet->setArrayDataByName("house_id", ph->unique_id, i);
  104. packet->setArrayDataByName("house_owner", ph->player_name.c_str(), i);
  105. packet->setArrayDataByName("house_location", hz->name.c_str(), i);
  106. packet->setArrayDataByName("house_zone", client->GetCurrentZone()->GetZoneName(), i);
  107. packet->setArrayDataByName("access_level", 1, i);
  108. packet->setArrayDataByName("visit_flag", 0, i); // 0 = allowed to visit, 1 = owner hasn't paid upkeep
  109. i++;
  110. }
  111. }
  112. }
  113. client->QueuePacket(packet->serialize());
  114. }
  115. safe_delete(packet);
  116. }
  117. /*
  118. <Struct Name="WS_DisplayVisitScreen" ClientVersion="1193" OpcodeName="OP_DisplayInnVisitScreenMsg">
  119. <Data ElementName="num_houses" Type="int16" Size="1" />
  120. <Data ElementName="visithouse_array" Type="Array" ArraySizeVariable="num_houses">
  121. <Data ElementName="house_id" Type="int64" />
  122. <Data ElementName="house_owner" Type="EQ2_16Bit_String" />
  123. <Data ElementName="house_location" Type="EQ2_16Bit_string" />
  124. <Data ElementName="house_zone" Type="EQ2_16Bit_String" />
  125. <Data ElementName="access_level" Type="int8" Size="1" />
  126. <Data ElementName="unknown3" Type="int8" Size="3" />
  127. <Data ElementName="visit_flag" Type="int8" Size="1" />
  128. </Data>
  129. <Data ElementName="unknown4" Type="int32" Size="1" />
  130. <Data ElementName="unknown5" Type="int8" Size="1" />
  131. </Struct>
  132. */