9
3

Sign.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 "Sign.h"
  17. #include "../common/ConfigReader.h"
  18. #include "WorldDatabase.h"
  19. #include "World.h"
  20. #include "../common/Log.h"
  21. extern World world;
  22. extern ConfigReader configReader;
  23. extern WorldDatabase database;
  24. extern ZoneList zone_list;
  25. extern MasterSpellList master_spell_list;
  26. Sign::Sign(){
  27. widget_id = 0;
  28. widget_x = 0;
  29. widget_y = 0;
  30. widget_z = 0;
  31. appearance.pos.state = 1;
  32. appearance.encounter_level = 0;
  33. spawn_type = 2;
  34. appearance.activity_status = 64;
  35. sign_type = 0;
  36. zone_x = 0;
  37. zone_y = 0;
  38. zone_z = 0;
  39. zone_heading = 0;
  40. sign_distance = 0;
  41. include_location = false;
  42. include_heading = false;
  43. zone_id = 0;
  44. language = 0;
  45. }
  46. Sign::~Sign(){
  47. }
  48. int32 Sign::GetWidgetID(){
  49. return widget_id;
  50. }
  51. EQ2Packet* Sign::serialize(Player* player, int16 version){
  52. return spawn_serialize(player, version);
  53. }
  54. void Sign::SetWidgetID(int32 val){
  55. widget_id = val;
  56. }
  57. void Sign::SetWidgetX(float val){
  58. widget_x = val;
  59. }
  60. float Sign::GetWidgetX(){
  61. return widget_x;
  62. }
  63. void Sign::SetWidgetY(float val){
  64. widget_y = val;
  65. }
  66. float Sign::GetWidgetY(){
  67. return widget_y;
  68. }
  69. void Sign::SetWidgetZ(float val){
  70. widget_z = val;
  71. }
  72. float Sign::GetWidgetZ(){
  73. return widget_z;
  74. }
  75. void Sign::SetSignIcon(int8 val){
  76. appearance.icon = val;
  77. }
  78. void Sign::SetIncludeLocation(bool val){
  79. include_location = val;
  80. }
  81. bool Sign::GetIncludeLocation(){
  82. return include_location;
  83. }
  84. void Sign::SetIncludeHeading(bool val){
  85. include_heading = val;
  86. }
  87. bool Sign::GetIncludeHeading(){
  88. return include_heading;
  89. }
  90. Sign* Sign::Copy(){
  91. Sign* new_spawn = new Sign();
  92. if(GetSizeOffset() > 0){
  93. int8 offset = GetSizeOffset()+1;
  94. sint32 tmp_size = size + (rand()%offset - rand()%offset);
  95. if(tmp_size < 0)
  96. tmp_size = 1;
  97. else if(tmp_size >= 0xFFFF)
  98. tmp_size = 0xFFFF;
  99. new_spawn->size = (int16)tmp_size;
  100. }
  101. else
  102. new_spawn->size = size;
  103. new_spawn->SetCollector(IsCollector());
  104. new_spawn->SetMerchantID(merchant_id);
  105. new_spawn->SetMerchantType(merchant_type);
  106. new_spawn->SetMerchantLevelRange(GetMerchantMinLevel(), GetMerchantMaxLevel());
  107. new_spawn->SetPrimaryCommands(&primary_command_list);
  108. new_spawn->primary_command_list_id = primary_command_list_id;
  109. new_spawn->SetSecondaryCommands(&secondary_command_list);
  110. new_spawn->secondary_command_list_id = secondary_command_list_id;
  111. new_spawn->database_id = database_id;
  112. memcpy(&new_spawn->appearance, &appearance, sizeof(AppearanceData));
  113. new_spawn->SetWidgetID(widget_id);
  114. new_spawn->SetWidgetX(widget_x);
  115. new_spawn->SetWidgetY(widget_y);
  116. new_spawn->SetWidgetZ(widget_z);
  117. new_spawn->SetSignType(sign_type);
  118. new_spawn->SetSignZoneX(zone_x);
  119. new_spawn->SetSignZoneY(zone_y);
  120. new_spawn->SetSignZoneZ(zone_z);
  121. new_spawn->SetSignZoneHeading(zone_heading);
  122. new_spawn->SetSignZoneID(GetSignZoneID());
  123. new_spawn->SetSignTitle(GetSignTitle());
  124. new_spawn->SetSignDescription(GetSignDescription());
  125. new_spawn->SetSignDistance(sign_distance);
  126. new_spawn->SetIncludeHeading(include_heading);
  127. new_spawn->SetIncludeLocation(include_location);
  128. new_spawn->SetTransporterID(GetTransporterID());
  129. new_spawn->SetSoundsDisabled(IsSoundsDisabled());
  130. new_spawn->SetOmittedByDBFlag(IsOmittedByDBFlag());
  131. new_spawn->SetLootTier(GetLootTier());
  132. new_spawn->SetLootDropType(GetLootDropType());
  133. new_spawn->SetLanguage(GetLanguage());
  134. return new_spawn;
  135. }
  136. int32 Sign::GetSignZoneID(){
  137. return zone_id;
  138. }
  139. void Sign::SetSignZoneID(int32 val){
  140. zone_id = val;
  141. }
  142. const char* Sign::GetSignTitle(){
  143. if(title.length() > 0)
  144. return title.c_str();
  145. else
  146. return 0;
  147. }
  148. void Sign::SetSignTitle(const char* val){
  149. if(val)
  150. title = string(val);
  151. }
  152. const char* Sign::GetSignDescription(){
  153. if(description.length() > 0)
  154. return description.c_str();
  155. else
  156. return 0;
  157. }
  158. void Sign::SetSignDescription(const char* val){
  159. if(val)
  160. description = string(val);
  161. }
  162. int8 Sign::GetSignType(){
  163. return sign_type;
  164. }
  165. void Sign::SetSignType(int8 val){
  166. sign_type = val;
  167. }
  168. float Sign::GetSignZoneX(){
  169. return zone_x;
  170. }
  171. void Sign::SetSignZoneX(float val){
  172. zone_x = val;
  173. }
  174. float Sign::GetSignZoneY(){
  175. return zone_y;
  176. }
  177. void Sign::SetSignZoneY(float val){
  178. zone_y = val;
  179. }
  180. float Sign::GetSignZoneZ(){
  181. return zone_z;
  182. }
  183. void Sign::SetSignZoneZ(float val){
  184. zone_z = val;
  185. }
  186. float Sign::GetSignZoneHeading(){
  187. return zone_heading;
  188. }
  189. void Sign::SetSignZoneHeading(float val){
  190. zone_heading = val;
  191. }
  192. float Sign::GetSignDistance(){
  193. return sign_distance;
  194. }
  195. void Sign::SetSignDistance(float val){
  196. sign_distance = val;
  197. }
  198. void Sign::HandleUse(Client* client, string command)
  199. {
  200. vector<TransportDestination*> destinations;
  201. //The following check disables the use of doors and other widgets if the player does not meet the quest requirements
  202. //If this is from a script ignore this check (client will be null)
  203. if (client) {
  204. bool meets_quest_reqs = MeetsSpawnAccessRequirements(client->GetPlayer());
  205. if (!meets_quest_reqs && (GetQuestsRequiredOverride() & 2) == 0)
  206. return;
  207. else if (meets_quest_reqs && appearance.show_command_icon != 1)
  208. return;
  209. }
  210. if( GetTransporterID() > 0 )
  211. GetZone()->GetTransporters(&destinations, client, GetTransporterID());
  212. if( destinations.size() )
  213. {
  214. client->SetTemporaryTransportID(0);
  215. client->ProcessTeleport(this, &destinations, GetTransporterID());
  216. }
  217. else if( sign_type == SIGN_TYPE_ZONE && GetSignZoneID() > 0 )
  218. {
  219. if( GetSignDistance() == 0 || client->GetPlayer()->GetDistance(this) <= GetSignDistance() )
  220. {
  221. string name = database.GetZoneName(GetSignZoneID());
  222. if( name.length() >0 )
  223. {
  224. if( !client->CheckZoneAccess(name.c_str()) )
  225. return;
  226. // determine if the coordinates should be set (returns false if they should)
  227. // clearer, if the sign has x,y,z,heading coordinates, use them otherwise I assume we use the zones safe coords(?)
  228. bool zone_coords_invalid = ( zone_x == 0 && zone_y == 0 && zone_z == 0 && zone_heading == 0 );
  229. // I really hate double-negatives. Seriously?
  230. if ( !zone_coords_invalid )
  231. {
  232. LogWrite(SIGN__DEBUG, 0, "Sign", "Sign has valid zone-to coordinates (%.2f, %.2f, %.2f, %.2f)", zone_x, zone_y, zone_z, zone_heading);
  233. client->GetPlayer()->SetX(zone_x);
  234. client->GetPlayer()->SetY(zone_y);
  235. client->GetPlayer()->SetZ(zone_z);
  236. client->GetPlayer()->SetHeading(zone_heading);
  237. }
  238. else // alert client we couldnt set the coordinates
  239. {
  240. LogWrite(SIGN__WARNING, 0, "Sign", "Sign has no zone-to coordinates set, using zones safe coords.");
  241. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Invalid zone in coords, taking you to a safe point.");
  242. }
  243. // Test if where we're going is an Instanced zone
  244. if ( !client->TryZoneInstance(GetSignZoneID(), zone_coords_invalid) )
  245. {
  246. LogWrite(SIGN__DEBUG, 0, "Sign", "Sending client to instance of zone_id: %u", GetSignZoneID());
  247. client->Zone(name.c_str(), zone_coords_invalid);
  248. }
  249. }
  250. else
  251. {
  252. LogWrite(SIGN__WARNING, 0, "Sign", "Unable to find zone with ID: %u", GetSignZoneID());
  253. client->Message(CHANNEL_COLOR_YELLOW, "Unable to find zone with ID: %u", GetSignZoneID());
  254. }
  255. }
  256. else
  257. {
  258. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You are too far away!");
  259. }
  260. }
  261. else if (client && command.length() > 0)
  262. {
  263. EntityCommand* entity_command = FindEntityCommand(command);
  264. if (entity_command)
  265. {
  266. LogWrite(SIGN__DEBUG, 0, "Sign", "ActivateQuestRequired Sign - Command: '%s'", entity_command->command.c_str());
  267. client->GetCurrentZone()->ProcessEntityCommand(entity_command, client->GetPlayer(), client->GetPlayer()->GetTarget());
  268. }
  269. }
  270. }