Spawn.cpp 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333
  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 "Spawn.h"
  17. #include <stdio.h>
  18. #include "../common/timer.h"
  19. #include <time.h>
  20. #include <math.h>
  21. #include "Entity.h"
  22. #include "Widget.h"
  23. #include "Sign.h"
  24. #include "../common/MiscFunctions.h"
  25. #include "../common/Log.h"
  26. #include "Rules/Rules.h"
  27. #include "World.h"
  28. #include "LuaInterface.h"
  29. #include "Zone/SPGrid.h"
  30. #include "Bots/Bot.h"
  31. #include "Zone/raycast_mesh.h"
  32. extern ConfigReader configReader;
  33. extern RuleManager rule_manager;
  34. extern World world;
  35. Spawn::Spawn(){
  36. group_id = 0;
  37. size_offset = 0;
  38. merchant_id = 0;
  39. memset(&appearance, 0, sizeof(AppearanceData));
  40. memset(&basic_info, 0, sizeof(BasicInfoStruct));
  41. appearance.encounter_level =6;
  42. size = 32;
  43. appearance.pos.collision_radius = 32;
  44. id = Spawn::NextID();
  45. oversized_packet = 0xFF;
  46. zone = 0;
  47. spawn_location_id = 0;
  48. spawn_entry_id = 0;
  49. spawn_location_spawns_id = 0;
  50. respawn = 0;
  51. expire_time = 0;
  52. expire_offset = 0;
  53. x_offset = 0;
  54. y_offset = 0;
  55. z_offset = 0;
  56. database_id = 0;
  57. packet_num = 1;
  58. changed = false;
  59. vis_changed = false;
  60. position_changed = false;
  61. send_spawn_changes = true;
  62. info_changed = false;
  63. appearance.pos.Speed1 = 0;
  64. last_attacker = 0;
  65. faction_id = 0;
  66. running_to = 0;
  67. tmp_visual_state = -1;
  68. tmp_action_state = -1;
  69. transporter_id = 0;
  70. invulnerable = false;
  71. spawn_group_list = 0;
  72. MSpawnGroup = 0;
  73. movement_locations = 0;
  74. MMovementLocations = 0;
  75. target = 0;
  76. primary_command_list_id = 0;
  77. secondary_command_list_id = 0;
  78. is_pet = false;
  79. m_followTarget = 0;
  80. following = false;
  81. req_quests_continued_access = false;
  82. req_quests_override = 0;
  83. req_quests_private = false;
  84. m_illusionModel = 0;
  85. Cell_Info.CurrentCell = nullptr;
  86. Cell_Info.CellListIndex = -1;
  87. m_addedToWorldTimestamp = 0;
  88. m_spawnAnim = 0;
  89. m_spawnAnimLeeway = 0;
  90. m_Update.SetName("Spawn::m_Update");
  91. m_requiredHistory.SetName("Spawn::m_requiredHistory");
  92. m_requiredQuests.SetName("Spawn::m_requiredQuests");
  93. last_heading_angle = 0.0;
  94. last_grid_update = 0;
  95. last_location_update = 0.0;
  96. last_movement_update = Timer::GetCurrentTime2();
  97. forceMapCheck = false;
  98. m_followDistance = 0;
  99. MCommandMutex.SetName("Entity::MCommandMutex");
  100. has_spawn_proximities = false;
  101. pickup_item_id = 0;
  102. pickup_unique_item_id = 0;
  103. disable_sounds = false;
  104. }
  105. Spawn::~Spawn(){
  106. RemovePrimaryCommands();
  107. for(int32 i=0;i<secondary_command_list.size();i++){
  108. safe_delete(secondary_command_list[i]);
  109. }
  110. RemoveSpawnFromGroup();
  111. if (MMovementLocations)
  112. MMovementLocations->writelock(__FUNCTION__, __LINE__);
  113. if(movement_locations){
  114. while(movement_locations->size()){
  115. safe_delete(movement_locations->front());
  116. movement_locations->pop_front();
  117. }
  118. safe_delete(movement_locations);
  119. }
  120. if (MMovementLocations)
  121. MMovementLocations->releasewritelock(__FUNCTION__, __LINE__);
  122. safe_delete(MMovementLocations);
  123. MMovementLoop.lock();
  124. for (int32 i = 0; i < movement_loop.size(); i++)
  125. safe_delete(movement_loop.at(i));
  126. MMovementLoop.unlock();
  127. map<int32, vector<int16>* >::iterator rq_itr;
  128. m_requiredQuests.writelock(__FUNCTION__, __LINE__);
  129. for (rq_itr = required_quests.begin(); rq_itr != required_quests.end(); rq_itr++){
  130. safe_delete(rq_itr->second);
  131. }
  132. m_requiredQuests.releasewritelock(__FUNCTION__, __LINE__);
  133. // just in case to make sure data is destroyed
  134. RemoveSpawnProximities();
  135. }
  136. void Spawn::RemovePrimaryCommands()
  137. {
  138. for (int32 i = 0; i < primary_command_list.size(); i++) {
  139. safe_delete(primary_command_list[i]);
  140. }
  141. primary_command_list.clear();
  142. }
  143. void Spawn::InitializeHeaderPacketData(Player* player, PacketStruct* header, int16 index) {
  144. header->setDataByName("index", index);
  145. if (GetSpawnAnim() > 0 && Timer::GetCurrentTime2() < (GetAddedToWorldTimestamp() + GetSpawnAnimLeeway())) {
  146. if (header->GetVersion() >= 57080)
  147. header->setDataByName("spawn_anim", GetSpawnAnim());
  148. else
  149. header->setDataByName("spawn_anim", (int16)GetSpawnAnim());
  150. }
  151. else {
  152. if (header->GetVersion() >= 57080)
  153. header->setDataByName("spawn_anim", 0xFFFFFFFF);
  154. else
  155. header->setDataByName("spawn_anim", 0xFFFF);
  156. }
  157. if (primary_command_list.size() > 0){
  158. if (primary_command_list.size() > 1) {
  159. header->setArrayLengthByName("command_list", primary_command_list.size());
  160. for (int32 i = 0; i < primary_command_list.size(); i++) {
  161. header->setArrayDataByName("command_list_name", primary_command_list[i]->name.c_str(), i);
  162. header->setArrayDataByName("command_list_max_distance", primary_command_list[i]->distance, i);
  163. header->setArrayDataByName("command_list_error", primary_command_list[i]->error_text.c_str(), i);
  164. header->setArrayDataByName("command_list_command", primary_command_list[i]->command.c_str(), i);
  165. }
  166. }
  167. header->setMediumStringByName("default_command", primary_command_list[0]->command.c_str());
  168. header->setDataByName("max_distance", primary_command_list[0]->distance);
  169. }
  170. if (spawn_group_list && MSpawnGroup){
  171. MSpawnGroup->readlock(__FUNCTION__, __LINE__);
  172. header->setArrayLengthByName("group_size", spawn_group_list->size());
  173. vector<Spawn*>::iterator itr;
  174. int i = 0;
  175. for (itr = spawn_group_list->begin(); itr != spawn_group_list->end(); itr++, i++){
  176. header->setArrayDataByName("group_spawn_id", player->GetIDWithPlayerSpawn((*itr)), i);
  177. }
  178. MSpawnGroup->releasereadlock(__FUNCTION__, __LINE__);
  179. }
  180. header->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(this));
  181. header->setDataByName("crc", 1);
  182. header->setDataByName("time_stamp", Timer::GetCurrentTime2());
  183. }
  184. void Spawn::InitializeVisPacketData(Player* player, PacketStruct* vis_packet) {
  185. int16 version = vis_packet->GetVersion();
  186. if (IsPlayer())
  187. appearance.pos.grid_id = 0xFFFFFFFF;
  188. if (appearance.targetable == 1 || appearance.show_level == 1 || appearance.display_name == 1){
  189. if (!IsGroundSpawn()){
  190. int8 arrow_color = ARROW_COLOR_WHITE;
  191. sint8 npc_con = player->GetFactions()->GetCon(faction_id);
  192. if (IsPlayer() && !((Player*)this)->CanSeeInvis(player))
  193. npc_con = 0;
  194. else if (!IsPlayer() && IsEntity() && !((Entity*)this)->CanSeeInvis(player))
  195. npc_con = 0;
  196. if (appearance.attackable == 1)
  197. arrow_color = player->GetArrowColor(GetLevel());
  198. vis_packet->setDataByName("arrow_color", arrow_color);
  199. vis_packet->setDataByName("locked_no_loot", appearance.locked_no_loot);
  200. if (player->GetArrowColor(GetLevel()) == ARROW_COLOR_GRAY)
  201. if (npc_con == -4)
  202. npc_con = -3;
  203. vis_packet->setDataByName("npc_con", npc_con);
  204. if (appearance.attackable == 1 && IsNPC() && (player->GetFactions()->GetCon(faction_id) <= -4 || ((NPC*)this)->Brain()->GetHate(player) > 1))
  205. vis_packet->setDataByName("npc_hate", ((NPC*)this)->Brain()->GetHatePercentage(player));
  206. int8 quest_flag = player->CheckQuestFlag(this);
  207. if (version < 1188 && quest_flag >= 16)
  208. quest_flag = 1;
  209. vis_packet->setDataByName("quest_flag",quest_flag);
  210. if( player->CheckQuestsKillUpdate(this, false)){
  211. vis_packet->setDataByName("name_quest_icon", 1);
  212. }
  213. }
  214. }
  215. int8 vis_flags = 0;
  216. if (MeetsSpawnAccessRequirements(player)) {
  217. if (appearance.attackable == 1)
  218. vis_flags += 64; //attackable icon
  219. if (appearance.show_level == 1)
  220. vis_flags += 32;
  221. if (appearance.display_name == 1)
  222. vis_flags += 16;
  223. if (IsPlayer() || appearance.targetable == 1)
  224. vis_flags += 4;
  225. if (appearance.show_command_icon == 1)
  226. vis_flags += 2;
  227. if (this == player) {
  228. vis_flags += 1;
  229. }
  230. }
  231. else if (req_quests_override > 0)
  232. {
  233. //Check to see if there's an override value set
  234. vis_flags = req_quests_override & 0xFF;
  235. }
  236. if (player->HasGMVision())
  237. {
  238. if ((vis_flags & 16) == 0 && appearance.display_name == 0)
  239. vis_flags += 16;
  240. if ((vis_flags & 4) == 0)
  241. vis_flags += 4;
  242. }
  243. vis_packet->setDataByName("vis_flags", vis_flags);
  244. if (MeetsSpawnAccessRequirements(player))
  245. vis_packet->setDataByName("hand_flag", appearance.display_hand_icon);
  246. else {
  247. if ((req_quests_override & 256) > 0)
  248. vis_packet->setDataByName("hand_flag", 1);
  249. }
  250. }
  251. void Spawn::InitializeFooterPacketData(Player* player, PacketStruct* footer) {
  252. if (IsWidget()){
  253. Widget* widget = (Widget*)this;
  254. if (widget->GetMultiFloorLift()) {
  255. footer->setDataByName("widget_x", widget->GetX());
  256. footer->setDataByName("widget_y", widget->GetY());
  257. footer->setDataByName("widget_z", widget->GetZ());
  258. }
  259. else {
  260. footer->setDataByName("widget_x", widget->GetWidgetX());
  261. footer->setDataByName("widget_y", widget->GetWidgetY());
  262. footer->setDataByName("widget_z", widget->GetWidgetZ());
  263. }
  264. footer->setDataByName("widget_id", widget->GetWidgetID());
  265. footer->setDataByName("unknown3c", 6);
  266. }
  267. else if (IsSign()){
  268. Sign* sign = (Sign*)this;
  269. footer->setDataByName("widget_id", sign->GetWidgetID());
  270. footer->setDataByName("widget_x", sign->GetWidgetX());
  271. footer->setDataByName("widget_y", sign->GetWidgetY());
  272. footer->setDataByName("widget_z", sign->GetWidgetZ());
  273. footer->setDataByName("unknown2b", 6);
  274. if (sign->GetSignTitle())
  275. footer->setMediumStringByName("title", sign->GetSignTitle());
  276. if (sign->GetSignDescription())
  277. footer->setMediumStringByName("description", sign->GetSignDescription());
  278. footer->setDataByName("sign_distance", sign->GetSignDistance());
  279. footer->setDataByName("show", 1);
  280. }
  281. if ( IsPlayer())
  282. footer->setDataByName("is_player", 1);
  283. if (strlen(appearance.name) < 1)
  284. strncpy(appearance.name,to_string(GetID()).c_str(),128);
  285. footer->setMediumStringByName("name", appearance.name);
  286. footer->setMediumStringByName("guild", appearance.sub_title);
  287. footer->setMediumStringByName("prefix", appearance.prefix_title);
  288. footer->setMediumStringByName("suffix", appearance.suffix_title);
  289. footer->setMediumStringByName("last_name", appearance.last_name);
  290. if (appearance.attackable == 0 && GetLevel() > 0)
  291. footer->setDataByName("spawn_type", 1);
  292. else if (appearance.attackable == 0)
  293. footer->setDataByName("spawn_type", 6);
  294. else
  295. footer->setDataByName("spawn_type", 3);
  296. }
  297. EQ2Packet* Spawn::spawn_serialize(Player* player, int16 version){
  298. // If spawn is NPC AND is pet && owner is a player && owner is the player passed to this function && player's char sheet pet id is 0
  299. if (IsNPC() && ((NPC*)this)->IsPet() && ((NPC*)this)->GetOwner()->IsPlayer() && player == ((NPC*)this)->GetOwner() && player->GetInfoStruct()->pet_id == 0) {
  300. ((Player*)((NPC*)this)->GetOwner())->GetInfoStruct()->pet_id = player->spawn_id;
  301. player->SetCharSheetChanged(true);
  302. }
  303. int16 index;
  304. if (player->player_spawn_index_map.count(this) > 0) {
  305. index = player->player_spawn_index_map[this];
  306. player->player_spawn_map[index] = this;
  307. }
  308. else {
  309. player->spawn_index++;
  310. if(player->spawn_index == 255)
  311. player->spawn_index++; //just so we dont have to worry about overloading
  312. index = player->spawn_index;
  313. player->player_spawn_index_map[this] = index;
  314. player->player_spawn_map[index] = this;
  315. }
  316. // Jabantiz - [Bug] Client Crash on Revive
  317. if (player->player_spawn_reverse_id_map.count(this) == 0) {
  318. int32 spawn_id = ++player->spawn_id;
  319. player->player_spawn_id_map[spawn_id] = this;
  320. player->player_spawn_reverse_id_map[this] = spawn_id;
  321. }
  322. m_Update.writelock(__FUNCTION__, __LINE__);
  323. PacketStruct* header = player->GetSpawnHeaderStruct();
  324. header->ResetData();
  325. InitializeHeaderPacketData(player, header, index);
  326. PacketStruct* footer;
  327. if(IsWidget())
  328. footer = player->GetWidgetFooterStruct();
  329. else if(IsSign())
  330. footer = player->GetSignFooterStruct();
  331. else
  332. footer = player->GetSpawnFooterStruct();
  333. footer->ResetData();
  334. InitializeFooterPacketData(player, footer);
  335. PacketStruct* vis_struct = player->GetSpawnVisStruct();
  336. PacketStruct* info_struct = player->GetSpawnInfoStruct();
  337. PacketStruct* pos_struct = player->GetSpawnPosStruct();
  338. player->vis_mutex.writelock(__FUNCTION__, __LINE__);
  339. vis_struct->ResetData();
  340. InitializeVisPacketData(player, vis_struct);
  341. player->info_mutex.writelock(__FUNCTION__, __LINE__);
  342. info_struct->ResetData();
  343. InitializeInfoPacketData(player, info_struct);
  344. player->pos_mutex.writelock(__FUNCTION__, __LINE__);
  345. pos_struct->ResetData();
  346. InitializePosPacketData(player, pos_struct);
  347. string* vis_data= vis_struct->serializeString();
  348. string* pos_data = pos_struct->serializeString();
  349. string* info_data = info_struct->serializeString();
  350. int16 part2_size = pos_data->length() + vis_data->length() + info_data->length();
  351. uchar* part2 = new uchar[part2_size];
  352. player->AddSpawnPosPacketForXOR(id, (uchar*)pos_data->c_str(), pos_data->length());
  353. player->AddSpawnVisPacketForXOR(id, (uchar*)vis_data->c_str(), vis_data->length());
  354. player->AddSpawnInfoPacketForXOR(id, (uchar*)info_data->c_str(), info_data->length());
  355. uchar* ptr = part2;
  356. memcpy(ptr, pos_data->c_str(), pos_data->length());
  357. ptr += pos_data->length();
  358. memcpy(ptr, vis_data->c_str(), vis_data->length());
  359. ptr += vis_data->length();
  360. memcpy(ptr, info_data->c_str(), info_data->length());
  361. player->pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  362. player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  363. player->vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  364. string* part1 = header->serializeString();
  365. string* part3 = footer->serializeString();
  366. uchar tmp[900];
  367. int32 origPart2Size = part2_size;
  368. part2_size = Pack(tmp, part2, part2_size, 900, version);
  369. int32 total_size = part1->length() + part2_size + part3->length() + 3;
  370. uchar* final_packet = new uchar[total_size + 4];
  371. ptr = final_packet;
  372. memcpy(ptr, &total_size, sizeof(total_size));
  373. ptr += sizeof(total_size);
  374. memcpy(ptr, &oversized_packet, sizeof(oversized_packet));
  375. ptr += sizeof(oversized_packet);
  376. memcpy(ptr, &opcode, sizeof(opcode));
  377. ptr += sizeof(opcode);
  378. memcpy(ptr, part1->c_str(), part1->length());
  379. ptr += part1->length();
  380. memcpy(ptr, tmp, part2_size);
  381. ptr += part2_size;
  382. memcpy(ptr, part3->c_str(), part3->length());
  383. delete[] part2;
  384. // printf("%s (%i): p1: %i, p2:% i (%i), p3:% i, ts: %i\n", GetName(), GetID(), part1->length(), part2_size, origPart2Size, part3->length(), total_size);
  385. EQ2Packet* ret = new EQ2Packet(OP_ClientCmdMsg, final_packet, total_size + 4);
  386. delete[] final_packet;
  387. m_Update.releasewritelock(__FUNCTION__, __LINE__);
  388. return ret;
  389. }
  390. uchar* Spawn::spawn_info_changes(Player* player, int16 version){
  391. int16 index = player->player_spawn_index_map[this];
  392. PacketStruct* packet = player->GetSpawnInfoStruct();
  393. player->info_mutex.writelock(__FUNCTION__, __LINE__);
  394. packet->ResetData();
  395. InitializeInfoPacketData(player, packet);
  396. string* data = packet->serializeString();
  397. int32 size = data->length();
  398. uchar* xor_info_packet = player->GetTempInfoPacketForXOR();
  399. if (!xor_info_packet || size != player->GetTempInfoXorSize())
  400. {
  401. LogWrite(ZONE__DEBUG, 0, "Zone", "InstantiateInfoPacket: %i, %i", size, player->GetTempInfoXorSize());
  402. safe_delete(xor_info_packet);
  403. xor_info_packet = player->SetTempInfoPacketForXOR(size);
  404. }
  405. uchar* orig_packet = player->GetSpawnInfoPacketForXOR(id);
  406. if(orig_packet){
  407. memcpy(xor_info_packet, (uchar*)data->c_str(), size);
  408. Encode(xor_info_packet, orig_packet, size);
  409. }
  410. bool changed = false;
  411. for (int i = 0; i < size; ++i) {
  412. if (xor_info_packet[i]) {
  413. changed = true;
  414. break;
  415. }
  416. }
  417. if (!changed) {
  418. player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  419. return nullptr;
  420. }
  421. uchar* tmp = new uchar[size + 10];
  422. size = Pack(tmp, xor_info_packet, size, size, version);
  423. player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  424. int32 orig_size = size;
  425. size-=sizeof(int32);
  426. size+=CheckOverLoadSize(index);
  427. info_packet_size = size + CheckOverLoadSize(size);
  428. uchar* tmp2 = new uchar[info_packet_size];
  429. uchar* ptr = tmp2;
  430. ptr += DoOverLoad(size, ptr);
  431. ptr += DoOverLoad(index, ptr);
  432. memcpy(ptr, tmp+sizeof(int32), orig_size - sizeof(int32));
  433. delete[] tmp;
  434. return tmp2;
  435. }
  436. uchar* Spawn::spawn_vis_changes(Player* player, int16 version){
  437. PacketStruct* vis_struct = player->GetSpawnVisStruct();
  438. int16 index = player->player_spawn_index_map[this];
  439. player->vis_mutex.writelock(__FUNCTION__, __LINE__);
  440. uchar* orig_packet = player->GetSpawnVisPacketForXOR(id);
  441. vis_struct->ResetData();
  442. InitializeVisPacketData(player, vis_struct);
  443. string* data = vis_struct->serializeString();
  444. int32 size = data->length();
  445. uchar* xor_vis_packet = player->GetTempVisPacketForXOR();
  446. if (!xor_vis_packet || size != player->GetTempVisXorSize())
  447. {
  448. LogWrite(ZONE__DEBUG, 0, "Zone", "InstantiateVisPacket: %i, %i", size, player->GetTempVisXorSize());
  449. safe_delete(xor_vis_packet);
  450. xor_vis_packet = player->SetTempVisPacketForXOR(size);
  451. }
  452. if(orig_packet){
  453. memcpy(xor_vis_packet, (uchar*)data->c_str(), size);
  454. Encode(xor_vis_packet, orig_packet, size);
  455. }
  456. bool changed = false;
  457. for (int i = 0; i < size; ++i) {
  458. if (xor_vis_packet[i]) {
  459. changed = true;
  460. break;
  461. }
  462. }
  463. if (!changed) {
  464. player->vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  465. return nullptr;
  466. }
  467. uchar* tmp = new uchar[size + 10];
  468. size = Pack(tmp, xor_vis_packet, size, size, version);
  469. player->vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  470. int32 orig_size = size;
  471. size-=sizeof(int32);
  472. size+=CheckOverLoadSize(index);
  473. vis_packet_size = size + CheckOverLoadSize(size);
  474. uchar* tmp2 = new uchar[vis_packet_size];
  475. uchar* ptr = tmp2;
  476. ptr += DoOverLoad(size, ptr);
  477. ptr += DoOverLoad(index, ptr);
  478. memcpy(ptr, tmp+sizeof(int32), orig_size - sizeof(int32));
  479. delete[] tmp;
  480. return tmp2;
  481. }
  482. uchar* Spawn::spawn_pos_changes(Player* player, int16 version) {
  483. int16 index = player->GetIndexForSpawn(this);
  484. PacketStruct* packet = player->GetSpawnPosStruct();
  485. player->pos_mutex.writelock(__FUNCTION__, __LINE__);
  486. uchar* orig_packet = player->GetSpawnPosPacketForXOR(id);
  487. packet->ResetData();
  488. InitializePosPacketData(player, packet, true);
  489. string* data = packet->serializeString();
  490. int32 size = data->length();
  491. uchar* xor_pos_packet = player->GetTempPosPacketForXOR();
  492. if (!xor_pos_packet || size != player->GetTempPosXorSize())
  493. {
  494. LogWrite(ZONE__DEBUG, 0, "Zone", "InstantiatePosPacket: %i, %i", size, player->GetTempPosXorSize());
  495. safe_delete(xor_pos_packet);
  496. xor_pos_packet = player->SetTempPosPacketForXOR(size);
  497. }
  498. if(orig_packet){
  499. memcpy(xor_pos_packet, (uchar*)data->c_str(), size);
  500. Encode(xor_pos_packet, orig_packet, size);
  501. }
  502. bool changed = false;
  503. for (int i = 0; i < size; ++i) {
  504. if (xor_pos_packet[i]) {
  505. changed = true;
  506. break;
  507. }
  508. }
  509. if (!changed) {
  510. player->pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  511. return nullptr;
  512. }
  513. uchar* tmp;
  514. if (IsPlayer())
  515. tmp = new uchar[size + 14];
  516. else
  517. tmp = new uchar[size + 10];
  518. size = Pack(tmp, xor_pos_packet, size, size, version);
  519. player->pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  520. int32 orig_size = size;
  521. // Needed for CoE+ clients
  522. if (version >= 1188)
  523. size += 1;
  524. if(IsPlayer())
  525. size += 4;
  526. size-=sizeof(int32);
  527. size+=CheckOverLoadSize(index);
  528. pos_packet_size = size + CheckOverLoadSize(size);
  529. uchar* tmp2 = new uchar[pos_packet_size];
  530. uchar* ptr = tmp2;
  531. ptr += DoOverLoad(size, ptr);
  532. ptr += DoOverLoad(index, ptr);
  533. // extra byte in coe+ clients, 0 for NPC's 1 for Players
  534. int8 x = 0;
  535. if(IsPlayer()){
  536. if (version >= 1188) {
  537. // set x to 1 and add it to the packet
  538. x = 1;
  539. memcpy(ptr, &x, sizeof(int8));
  540. ptr += sizeof(int8);
  541. }
  542. int32 now = Timer::GetCurrentTime2();
  543. memcpy(ptr, &now, sizeof(int32));
  544. ptr += sizeof(int32);
  545. }
  546. else if (version >= 1188) {
  547. // add x to packet
  548. memcpy(ptr, &x, sizeof(int8));
  549. ptr += sizeof(int8);
  550. }
  551. memcpy(ptr, tmp+sizeof(int32), orig_size - sizeof(int32));
  552. delete[] tmp;
  553. return tmp2;
  554. }
  555. EQ2Packet* Spawn::player_position_update_packet(Player* player, int16 version){
  556. if(!player || player->IsPlayer() == false){
  557. LogWrite(SPAWN__ERROR, 0, "Spawn", "Error: Called player_position_update_packet without player!");
  558. return 0;
  559. }
  560. else if(IsPlayer() == false){
  561. LogWrite(SPAWN__ERROR, 0, "Spawn", "Error: Called player_position_update_packet from spawn!");
  562. return 0;
  563. }
  564. static const int8 info_size = 1;
  565. static const int8 vis_size = 1;
  566. m_Update.writelock(__FUNCTION__, __LINE__);
  567. uchar* pos_changes = spawn_pos_changes(player, version);
  568. if (pos_changes == NULL )
  569. {
  570. m_Update.releasewritelock(__FUNCTION__, __LINE__);
  571. return NULL;
  572. }
  573. int32 tmp_pos_packet_size = pos_packet_size;
  574. m_Update.releasewritelock(__FUNCTION__, __LINE__);
  575. int32 size = info_size + tmp_pos_packet_size + vis_size + 11;
  576. static const int8 oversized = 255;
  577. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  578. uchar* tmp = new uchar[size];
  579. memset(tmp, 0, size);
  580. uchar* ptr = tmp;
  581. size -=4;
  582. memcpy(ptr, &size, sizeof(int32));
  583. size +=4;
  584. ptr += sizeof(int32);
  585. memcpy(ptr, &oversized, sizeof(int8));
  586. ptr += sizeof(int8);
  587. memcpy(ptr, &opcode_val, sizeof(int16));
  588. ptr += sizeof(int16);
  589. ptr += sizeof(int32);
  590. ptr += info_size;
  591. memcpy(ptr, pos_changes, tmp_pos_packet_size);
  592. EQ2Packet* ret_packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  593. delete[] tmp;
  594. delete[] pos_changes;
  595. return ret_packet;
  596. }
  597. EQ2Packet* Spawn::spawn_update_packet(Player* player, int16 version, bool override_changes, bool override_vis_changes){
  598. if(!player || player->IsPlayer() == false){
  599. LogWrite(SPAWN__ERROR, 0, "Spawn", "Error: Called spawn_update_packet without player!");
  600. return 0;
  601. }
  602. else if((IsPlayer() && info_changed == false && vis_changed == false) || (info_changed == false && vis_changed == false && position_changed == false)){
  603. if(!override_changes && !override_vis_changes)
  604. return 0;
  605. }
  606. static const uchar null_byte = 0;
  607. uchar* info_changes = 0;
  608. uchar* pos_changes = 0;
  609. uchar* vis_changes = 0;
  610. static const int8 oversized = 255;
  611. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  612. int16 tmp_info_packet_size;
  613. int16 tmp_vis_packet_size;
  614. int16 tmp_pos_packet_size;
  615. //We need to lock these variables up to make this thread safe
  616. m_Update.writelock(__FUNCTION__, __LINE__);
  617. //These variables are set in the spawn_info_changes, pos and vis changes functions
  618. info_packet_size = 1;
  619. pos_packet_size = 1;
  620. vis_packet_size = 1;
  621. if (info_changed || override_changes)
  622. info_changes = spawn_info_changes(player, version);
  623. if ((position_changed || override_changes) && IsPlayer() == false)
  624. pos_changes = spawn_pos_changes(player, version);
  625. if (vis_changed || override_changes || override_vis_changes)
  626. vis_changes = spawn_vis_changes(player, version);
  627. tmp_info_packet_size = info_packet_size;
  628. tmp_pos_packet_size = pos_packet_size;
  629. tmp_vis_packet_size = vis_packet_size;
  630. int32 size = info_packet_size + pos_packet_size + vis_packet_size + 11;
  631. uchar* tmp = new uchar[size];
  632. memset(tmp, 0, size);
  633. uchar* ptr = tmp;
  634. size -=4;
  635. memcpy(ptr, &size, sizeof(int32));
  636. size +=4;
  637. ptr += sizeof(int32);
  638. memcpy(ptr, &oversized, sizeof(int8));
  639. ptr += sizeof(int8);
  640. memcpy(ptr, &opcode_val, sizeof(int16));
  641. ptr += sizeof(int16);
  642. if (IsPlayer() == false){ //this isnt sent for player updates, it is sent on position update
  643. //int32 time = Timer::GetCurrentTime2();
  644. packet_num = Timer::GetCurrentTime2();
  645. memcpy(ptr, &packet_num, sizeof(int32));
  646. }
  647. ptr += sizeof(int32);
  648. memcpy(ptr, info_changes ? info_changes : &null_byte, tmp_info_packet_size);
  649. ptr += info_packet_size;
  650. memcpy(ptr, pos_changes ? pos_changes : &null_byte, tmp_pos_packet_size);
  651. ptr += pos_packet_size;
  652. memcpy(ptr, vis_changes ? vis_changes : &null_byte, tmp_vis_packet_size);
  653. EQ2Packet* ret_packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  654. delete[] tmp;
  655. safe_delete_array(info_changes);
  656. safe_delete_array(vis_changes);
  657. safe_delete_array(pos_changes);
  658. m_Update.releasewritelock(__FUNCTION__, __LINE__);
  659. return ret_packet;
  660. }
  661. uchar* Spawn::spawn_info_changes_ex(Player* player, int16 version) {
  662. int16 index = player->player_spawn_index_map[this];
  663. PacketStruct* packet = player->GetSpawnInfoStruct();
  664. player->info_mutex.writelock(__FUNCTION__, __LINE__);
  665. packet->ResetData();
  666. InitializeInfoPacketData(player, packet);
  667. string* data = packet->serializeString();
  668. int32 size = data->length();
  669. uchar* xor_info_packet = player->GetTempInfoPacketForXOR();
  670. if (!xor_info_packet || size != player->GetTempInfoXorSize()) {
  671. LogWrite(ZONE__DEBUG, 0, "Zone", "InstantiateInfoExPacket: %i, %i", size, player->GetTempInfoXorSize());
  672. safe_delete(xor_info_packet);
  673. xor_info_packet = player->SetTempInfoPacketForXOR(size);
  674. }
  675. uchar* orig_packet = player->GetSpawnInfoPacketForXOR(id);
  676. if (orig_packet) {
  677. memcpy(xor_info_packet, (uchar*)data->c_str(), size);
  678. Encode(xor_info_packet, orig_packet, size);
  679. }
  680. bool changed = false;
  681. for (int i = 0; i < size; ++i) {
  682. if (xor_info_packet[i]) {
  683. changed = true;
  684. break;
  685. }
  686. }
  687. if (!changed) {
  688. player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  689. return nullptr;
  690. }
  691. uchar* tmp = new uchar[size + 10];
  692. size = Pack(tmp, xor_info_packet, size, size, version);
  693. player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  694. int32 orig_size = size;
  695. size -= sizeof(int32);
  696. size += CheckOverLoadSize(index);
  697. info_packet_size = size;
  698. uchar* tmp2 = new uchar[size];
  699. uchar* ptr = tmp2;
  700. ptr += DoOverLoad(index, ptr);
  701. memcpy(ptr, tmp + sizeof(int32), orig_size - sizeof(int32));
  702. delete[] tmp;
  703. return move(tmp2);
  704. }
  705. uchar* Spawn::spawn_vis_changes_ex(Player* player, int16 version) {
  706. PacketStruct* vis_struct = player->GetSpawnVisStruct();
  707. int16 index = player->player_spawn_index_map[this];
  708. player->vis_mutex.writelock(__FUNCTION__, __LINE__);
  709. uchar* orig_packet = player->GetSpawnVisPacketForXOR(id);
  710. vis_struct->ResetData();
  711. InitializeVisPacketData(player, vis_struct);
  712. string* data = vis_struct->serializeString();
  713. int32 size = data->length();
  714. uchar* xor_vis_packet = player->GetTempVisPacketForXOR();
  715. if (!xor_vis_packet || size != player->GetTempVisXorSize()) {
  716. LogWrite(ZONE__DEBUG, 0, "Zone", "InstantiateVisExPacket: %i, %i", size, player->GetTempVisXorSize());
  717. safe_delete(xor_vis_packet);
  718. xor_vis_packet = player->SetTempVisPacketForXOR(size);
  719. }
  720. if (orig_packet) {
  721. memcpy(xor_vis_packet, (uchar*)data->c_str(), size);
  722. Encode(xor_vis_packet, orig_packet, size);
  723. }
  724. bool changed = false;
  725. for (int i = 0; i < size; ++i) {
  726. if (xor_vis_packet[i]) {
  727. changed = true;
  728. break;
  729. }
  730. }
  731. if (!changed) {
  732. player->vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  733. return nullptr;
  734. }
  735. uchar* tmp = new uchar[size + 10];
  736. size = Pack(tmp, xor_vis_packet, size, size, version);
  737. player->vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  738. int32 orig_size = size;
  739. size -= sizeof(int32);
  740. size += CheckOverLoadSize(index);
  741. vis_packet_size = size;
  742. uchar* tmp2 = new uchar[size];
  743. uchar* ptr = tmp2;
  744. ptr += DoOverLoad(index, ptr);
  745. memcpy(ptr, tmp + sizeof(int32), orig_size - sizeof(int32));
  746. delete[] tmp;
  747. return move(tmp2);
  748. }
  749. uchar* Spawn::spawn_pos_changes_ex(Player* player, int16 version) {
  750. int16 index = player->GetIndexForSpawn(this);
  751. PacketStruct* packet = player->GetSpawnPosStruct();
  752. player->pos_mutex.writelock(__FUNCTION__, __LINE__);
  753. uchar* orig_packet = player->GetSpawnPosPacketForXOR(id);
  754. packet->ResetData();
  755. InitializePosPacketData(player, packet);
  756. string* data = packet->serializeString();
  757. int32 size = data->length();
  758. uchar* xor_pos_packet = player->GetTempPosPacketForXOR();
  759. if (!xor_pos_packet || size != player->GetTempPosXorSize()) {
  760. LogWrite(ZONE__DEBUG, 0, "Zone", "InstantiatePosExPacket: %i, %i", size, player->GetTempPosXorSize());
  761. safe_delete(xor_pos_packet);
  762. xor_pos_packet = player->SetTempPosPacketForXOR(size);
  763. }
  764. if (orig_packet) {
  765. memcpy(xor_pos_packet, (uchar*)data->c_str(), size);
  766. Encode(xor_pos_packet, orig_packet, size);
  767. }
  768. bool changed = false;
  769. for (int i = 0; i < size; ++i) {
  770. if (xor_pos_packet[i]) {
  771. changed = true;
  772. break;
  773. }
  774. }
  775. if (!changed) {
  776. player->pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  777. return nullptr;
  778. }
  779. uchar* tmp = new uchar[size + 10];
  780. size = Pack(tmp, xor_pos_packet, size, size, version);
  781. player->pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  782. int32 orig_size = size;
  783. if (version >= 1188) {
  784. size += 1;
  785. }
  786. if (IsPlayer()) {
  787. size += 4;
  788. }
  789. size -= sizeof(int32);
  790. size += CheckOverLoadSize(index);
  791. pos_packet_size = size;
  792. uchar* tmp2 = new uchar[size];
  793. uchar* ptr = tmp2;
  794. ptr += DoOverLoad(index, ptr);
  795. // extra byte in coe+ clients, 0 for NPC's 1 for Players
  796. int8 x = 0;
  797. if (version >= 1188) {
  798. if (IsPlayer()) {
  799. x = 1;
  800. memcpy(ptr, &x, sizeof(int8));
  801. ptr += sizeof(int8);
  802. int32 now = Timer::GetCurrentTime2();
  803. memcpy(ptr, &now, sizeof(int32));
  804. ptr += sizeof(int32);
  805. }
  806. else {
  807. memcpy(ptr, &x, sizeof(int8));
  808. ptr += sizeof(int8);
  809. }
  810. }
  811. memcpy(ptr, tmp + sizeof(int32), orig_size - sizeof(int32));
  812. delete[] tmp;
  813. return move(tmp2);
  814. }
  815. EQ2Packet* Spawn::serialize(Player* player, int16 version){
  816. return 0;
  817. }
  818. Spawn* Spawn::GetTarget(){
  819. Spawn* ret = 0;
  820. // only attempt to get a spawn if we had a target stored
  821. if (target != 0)
  822. {
  823. ret = GetZone()->GetSpawnByID(target);
  824. if (!ret)
  825. target = 0;
  826. }
  827. return ret;
  828. }
  829. void Spawn::SetTarget(Spawn* spawn){
  830. SetInfo(&target, spawn ? spawn->GetID() : 0);
  831. }
  832. Spawn* Spawn::GetLastAttacker() {
  833. Spawn* ret = 0;
  834. ret = GetZone()->GetSpawnByID(last_attacker);
  835. if (!ret)
  836. last_attacker = 0;
  837. return ret;
  838. }
  839. void Spawn::SetLastAttacker(Spawn* spawn){
  840. last_attacker = spawn->GetID();
  841. }
  842. void Spawn::SetInvulnerable(bool val){
  843. invulnerable = val;
  844. }
  845. bool Spawn::GetInvulnerable(){
  846. return invulnerable;
  847. }
  848. bool Spawn::TakeDamage(int32 damage){
  849. if(invulnerable)
  850. return false;
  851. if (IsEntity()) {
  852. if (((Entity*)this)->IsMezzed())
  853. ((Entity*)this)->RemoveAllMezSpells();
  854. if (damage == 0)
  855. return true;
  856. }
  857. int32 hp = GetHP();
  858. if(damage >= hp) {
  859. SetHP(0);
  860. if (IsPlayer()) {
  861. ((Player*)this)->InCombat(false);
  862. ((Player*)this)->SetRangeAttack(false);
  863. GetZone()->TriggerCharSheetTimer(); // force char sheet updates now
  864. }
  865. }
  866. else {
  867. SetHP(hp - damage);
  868. // if player flag the char sheet as changed so the ui updates properly
  869. if (IsPlayer())
  870. ((Player*)this)->SetCharSheetChanged(true);
  871. }
  872. return true;
  873. }
  874. void Spawn::TakeDamage(Spawn* attacker, int32 damage){
  875. if (TakeDamage(damage))
  876. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_HEALTHCHANGED, attacker);
  877. SetLastAttacker(attacker);
  878. }
  879. ZoneServer* Spawn::GetZone(){
  880. return zone;
  881. }
  882. void Spawn::SetZone(ZoneServer* in_zone){
  883. zone = in_zone;
  884. }
  885. /*** HIT POINT ***/
  886. void Spawn::SetHP(sint32 new_val, bool setUpdateFlags){
  887. if(new_val == 0){
  888. ClearRunningLocations();
  889. CalculateRunningLocation(true);
  890. }
  891. if(new_val > basic_info.max_hp)
  892. SetInfo(&basic_info.max_hp, new_val, setUpdateFlags);
  893. SetInfo(&basic_info.cur_hp, new_val, setUpdateFlags);
  894. if(/*IsPlayer() &&*/ GetZone() && basic_info.cur_hp > 0 && basic_info.cur_hp < basic_info.max_hp)
  895. GetZone()->AddDamagedSpawn(this);
  896. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  897. ((Entity*)this)->UpdateGroupMemberInfo();
  898. if (IsPlayer())
  899. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  900. else
  901. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  902. }
  903. if (IsNPC() && ((NPC*)this)->IsPet() && ((NPC*)this)->GetOwner()->IsPlayer()) {
  904. Player* player = (Player*)((NPC*)this)->GetOwner();
  905. if (player->GetPet() && player->GetCharmedPet()) {
  906. if (this == player->GetPet()) {
  907. player->GetInfoStruct()->pet_health_pct = (float)basic_info.cur_hp / (float)basic_info.max_hp;
  908. player->SetCharSheetChanged(true);
  909. }
  910. }
  911. else {
  912. player->GetInfoStruct()->pet_health_pct = (float)basic_info.cur_hp / (float)basic_info.max_hp;
  913. player->SetCharSheetChanged(true);
  914. }
  915. }
  916. }
  917. void Spawn::SetTotalHP(sint32 new_val){
  918. if(basic_info.hp_base == 0)
  919. SetTotalHPBase(new_val);
  920. SetInfo(&basic_info.max_hp, new_val);
  921. if(GetZone() && basic_info.cur_hp > 0 && basic_info.cur_hp < basic_info.max_hp)
  922. GetZone()->AddDamagedSpawn(this);
  923. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  924. ((Entity*)this)->UpdateGroupMemberInfo();
  925. if (IsPlayer())
  926. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  927. else
  928. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  929. }
  930. if (IsNPC() && ((NPC*)this)->IsPet() && ((NPC*)this)->GetOwner()->IsPlayer()) {
  931. Player* player = (Player*)((NPC*)this)->GetOwner();
  932. if (player->GetPet() && player->GetCharmedPet()) {
  933. if (this == player->GetPet()) {
  934. player->GetInfoStruct()->pet_health_pct = (float)basic_info.cur_hp / (float)basic_info.max_hp;
  935. player->SetCharSheetChanged(true);
  936. }
  937. }
  938. else {
  939. player->GetInfoStruct()->pet_health_pct = (float)basic_info.cur_hp / (float)basic_info.max_hp;
  940. player->SetCharSheetChanged(true);
  941. }
  942. }
  943. }
  944. void Spawn::SetTotalHPBase(sint32 new_val)
  945. {
  946. SetInfo(&basic_info.hp_base, new_val);
  947. if(GetZone() && basic_info.cur_hp > 0 && basic_info.cur_hp < basic_info.max_hp)
  948. GetZone()->AddDamagedSpawn(this);
  949. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  950. ((Entity*)this)->UpdateGroupMemberInfo();
  951. if (IsPlayer())
  952. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  953. else
  954. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  955. }
  956. }
  957. sint32 Spawn::GetHP()
  958. {
  959. return basic_info.cur_hp;
  960. }
  961. sint32 Spawn::GetTotalHP()
  962. {
  963. return basic_info.max_hp;
  964. }
  965. sint32 Spawn::GetTotalHPBase()
  966. {
  967. return basic_info.hp_base;
  968. }
  969. /*** POWER ***/
  970. void Spawn::SetPower(sint32 power, bool setUpdateFlags){
  971. if(power > basic_info.max_power)
  972. SetInfo(&basic_info.max_power, power, setUpdateFlags);
  973. SetInfo(&basic_info.cur_power, power, setUpdateFlags);
  974. if(/*IsPlayer() &&*/ GetZone() && basic_info.cur_power < basic_info.max_power)
  975. GetZone()->AddDamagedSpawn(this);
  976. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  977. ((Entity*)this)->UpdateGroupMemberInfo();
  978. if (IsPlayer())
  979. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  980. else
  981. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  982. }
  983. if (IsNPC() && ((NPC*)this)->IsPet() && ((NPC*)this)->GetOwner()->IsPlayer()) {
  984. Player* player = (Player*)((NPC*)this)->GetOwner();
  985. if (player->GetPet() && player->GetCharmedPet()) {
  986. if (this == player->GetPet()) {
  987. player->GetInfoStruct()->pet_power_pct = (float)basic_info.cur_power / (float)basic_info.max_power;
  988. player->SetCharSheetChanged(true);
  989. }
  990. }
  991. else {
  992. player->GetInfoStruct()->pet_power_pct = (float)basic_info.cur_power / (float)basic_info.max_power;
  993. player->SetCharSheetChanged(true);
  994. }
  995. }
  996. }
  997. void Spawn::SetTotalPower(sint32 new_val)
  998. {
  999. if(basic_info.power_base == 0)
  1000. SetTotalPowerBase(new_val);
  1001. SetInfo(&basic_info.max_power, new_val);
  1002. if(GetZone() && basic_info.cur_power < basic_info.max_power)
  1003. GetZone()->AddDamagedSpawn(this);
  1004. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  1005. ((Entity*)this)->UpdateGroupMemberInfo();
  1006. if (IsPlayer())
  1007. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  1008. else
  1009. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  1010. }
  1011. if (IsNPC() && ((NPC*)this)->IsPet() && ((NPC*)this)->GetOwner()->IsPlayer()) {
  1012. Player* player = (Player*)((NPC*)this)->GetOwner();
  1013. if (player->GetPet() && player->GetCharmedPet()) {
  1014. if (this == player->GetPet()) {
  1015. player->GetInfoStruct()->pet_power_pct = (float)basic_info.cur_power / (float)basic_info.max_power;
  1016. player->SetCharSheetChanged(true);
  1017. }
  1018. }
  1019. else {
  1020. player->GetInfoStruct()->pet_power_pct = (float)basic_info.cur_power / (float)basic_info.max_power;
  1021. player->SetCharSheetChanged(true);
  1022. }
  1023. }
  1024. }
  1025. void Spawn::SetTotalPowerBase(sint32 new_val)
  1026. {
  1027. SetInfo(&basic_info.power_base, new_val);
  1028. if(GetZone() && basic_info.cur_power < basic_info.max_power)
  1029. GetZone()->AddDamagedSpawn(this);
  1030. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  1031. ((Entity*)this)->UpdateGroupMemberInfo();
  1032. if (IsPlayer())
  1033. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  1034. else
  1035. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  1036. }
  1037. }
  1038. sint32 Spawn::GetPower()
  1039. {
  1040. return basic_info.cur_power;
  1041. }
  1042. sint32 Spawn::GetTotalPower(){
  1043. return basic_info.max_power;
  1044. }
  1045. sint32 Spawn::GetTotalPowerBase()
  1046. {
  1047. return basic_info.power_base;
  1048. }
  1049. /*** SAVAGERY ***/
  1050. void Spawn::SetSavagery(sint32 savagery, bool setUpdateFlags)
  1051. {
  1052. /* JA: extremely limited functionality until we better understand Savagery */
  1053. if(savagery > basic_info.max_savagery)
  1054. SetInfo(&basic_info.max_savagery, savagery, setUpdateFlags);
  1055. SetInfo(&basic_info.cur_savagery, savagery, setUpdateFlags);
  1056. }
  1057. void Spawn::SetTotalSavagery(sint32 new_val)
  1058. {
  1059. /* JA: extremely limited functionality until we better understand Savagery */
  1060. if(basic_info.savagery_base == 0)
  1061. SetTotalSavageryBase(new_val);
  1062. SetInfo(&basic_info.max_savagery, new_val);
  1063. }
  1064. void Spawn::SetTotalSavageryBase(sint32 new_val){
  1065. SetInfo(&basic_info.savagery_base, new_val);
  1066. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  1067. ((Entity*)this)->UpdateGroupMemberInfo();
  1068. if (IsPlayer())
  1069. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  1070. else
  1071. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  1072. }
  1073. }
  1074. sint32 Spawn::GetTotalSavagery()
  1075. {
  1076. return basic_info.max_savagery;
  1077. }
  1078. sint32 Spawn::GetSavagery()
  1079. {
  1080. return basic_info.cur_savagery;
  1081. }
  1082. /*** DISSONANCE ***/
  1083. void Spawn::SetDissonance(sint32 dissonance, bool setUpdateFlags)
  1084. {
  1085. /* JA: extremely limited functionality until we better understand Dissonance */
  1086. if(dissonance > basic_info.max_dissonance)
  1087. SetInfo(&basic_info.max_dissonance, dissonance, setUpdateFlags);
  1088. SetInfo(&basic_info.cur_dissonance, dissonance, setUpdateFlags);
  1089. }
  1090. void Spawn::SetTotalDissonance(sint32 new_val)
  1091. {
  1092. /* JA: extremely limited functionality until we better understand Dissonance */
  1093. if(basic_info.dissonance_base == 0)
  1094. SetTotalDissonanceBase(new_val);
  1095. SetInfo(&basic_info.max_dissonance, new_val);
  1096. }
  1097. void Spawn::SetTotalDissonanceBase(sint32 new_val)
  1098. {
  1099. SetInfo(&basic_info.dissonance_base, new_val);
  1100. if (IsEntity() && ((Entity*)this)->GetGroupMemberInfo()) {
  1101. ((Entity*)this)->UpdateGroupMemberInfo();
  1102. if (IsPlayer())
  1103. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id, GetZone()->GetClientBySpawn(this));
  1104. else
  1105. world.GetGroupManager()->SendGroupUpdate(((Entity*)this)->GetGroupMemberInfo()->group_id);
  1106. }
  1107. }
  1108. sint32 Spawn::GetTotalDissonance()
  1109. {
  1110. return basic_info.max_dissonance;
  1111. }
  1112. sint32 Spawn::GetDissonance()
  1113. {
  1114. return basic_info.cur_dissonance;
  1115. }
  1116. /* --< Alternate Advancement Points >-- */
  1117. void Spawn::SetAssignedAA(sint16 new_val)
  1118. {
  1119. SetInfo(&basic_info.assigned_aa, new_val);
  1120. }
  1121. void Spawn::SetUnassignedAA(sint16 new_val)
  1122. {
  1123. SetInfo(&basic_info.unassigned_aa, new_val);
  1124. }
  1125. void Spawn::SetTradeskillAA(sint16 new_val)
  1126. {
  1127. SetInfo(&basic_info.tradeskill_aa, new_val);
  1128. }
  1129. void Spawn::SetUnassignedTradeskillAA(sint16 new_val)
  1130. {
  1131. SetInfo(&basic_info.unassigned_tradeskill_aa, new_val);
  1132. }
  1133. void Spawn::SetPrestigeAA(sint16 new_val)
  1134. {
  1135. SetInfo(&basic_info.prestige_aa, new_val);
  1136. }
  1137. void Spawn::SetUnassignedPrestigeAA(sint16 new_val)
  1138. {
  1139. SetInfo(&basic_info.unassigned_prestige_aa, new_val);
  1140. }
  1141. void Spawn::SetTradeskillPrestigeAA(sint16 new_val)
  1142. {
  1143. SetInfo(&basic_info.tradeskill_prestige_aa, new_val);
  1144. }
  1145. void Spawn::SetUnassignedTradeskillPrestigeAA(sint16 new_val)
  1146. {
  1147. SetInfo(&basic_info.unassigned_tradeskill_prestige_aa, new_val);
  1148. }
  1149. sint16 Spawn::GetAssignedAA()
  1150. {
  1151. return basic_info.assigned_aa;
  1152. }
  1153. sint16 Spawn::GetUnassignedAA()
  1154. {
  1155. return basic_info.unassigned_aa;
  1156. }
  1157. sint16 Spawn::GetTradeskillAA()
  1158. {
  1159. return basic_info.tradeskill_aa;
  1160. }
  1161. sint16 Spawn::GetUnassignedTradeskillAA()
  1162. {
  1163. return basic_info.unassigned_tradeskill_aa;
  1164. }
  1165. sint16 Spawn::GetPrestigeAA()
  1166. {
  1167. return basic_info.prestige_aa;
  1168. }
  1169. sint16 Spawn::GetUnassignedPretigeAA()
  1170. {
  1171. return basic_info.unassigned_prestige_aa;
  1172. }
  1173. sint16 Spawn::GetTradeskillPrestigeAA()
  1174. {
  1175. return basic_info.tradeskill_prestige_aa;
  1176. }
  1177. sint16 Spawn::GetUnassignedTradeskillPrestigeAA()
  1178. {
  1179. return basic_info.unassigned_tradeskill_prestige_aa;
  1180. }
  1181. float Spawn::GetDistance(float x1, float y1, float z1, float x2, float y2, float z2){
  1182. x1 = x1 - x2;
  1183. y1 = y1 - y2;
  1184. z1 = z1 - z2;
  1185. return sqrt(x1*x1 + y1*y1 + z1*z1);
  1186. }
  1187. float Spawn::GetDistance(float x, float y, float z, float radius, bool ignore_y) {
  1188. if (ignore_y)
  1189. return GetDistance(x, y, z, GetX(), y, GetZ()) - radius;
  1190. else
  1191. return GetDistance(x, y, z, GetX(), GetY(), GetZ()) - radius;
  1192. }
  1193. float Spawn::GetDistance(float x, float y, float z, bool ignore_y) {
  1194. return GetDistance(x, y, z, 0.0f, ignore_y);
  1195. }
  1196. float Spawn::GetDistance(Spawn* spawn, bool ignore_y, bool includeRadius){
  1197. float ret = 0;
  1198. if (spawn)
  1199. {
  1200. float radius = 0.0f;
  1201. if (includeRadius)
  1202. radius = CalculateRadius(spawn);
  1203. ret = GetDistance(spawn->GetX(), spawn->GetY(), spawn->GetZ(), radius, ignore_y);
  1204. }
  1205. // maybe distance against ourselves, in that case we want to nullify the radius check
  1206. if (ret < 0)
  1207. ret = 0.0f;
  1208. return ret;
  1209. }
  1210. float Spawn::GetDistance(Spawn* spawn, float x1, float y1, float z1, bool includeRadius) {
  1211. float ret = 0;
  1212. if (spawn)
  1213. {
  1214. float radius = 0.0f;
  1215. if (includeRadius)
  1216. radius = CalculateRadius(spawn);
  1217. ret = GetDistance(x1, y1, z1, spawn->GetX(), spawn->GetY(), spawn->GetZ()) - radius;
  1218. }
  1219. // maybe distance against ourselves, in that case we want to nullify the radius check
  1220. if (ret < 0)
  1221. ret = 0.0f;
  1222. return ret;
  1223. }
  1224. float Spawn::CalculateRadius(Spawn* target)
  1225. {
  1226. float srcRadius = short_to_float(appearance.pos.collision_radius);
  1227. if (target)
  1228. {
  1229. float targRadius = short_to_float(target->appearance.pos.collision_radius);
  1230. return (targRadius / 32.0f) + (srcRadius / 32.0f);
  1231. }
  1232. else
  1233. return (srcRadius / 32.0f);
  1234. }
  1235. int32 Spawn::GetRespawnTime(){
  1236. return respawn;
  1237. }
  1238. void Spawn::SetRespawnTime(int32 time){
  1239. respawn = time;
  1240. }
  1241. int32 Spawn::GetExpireOffsetTime(){
  1242. return expire_offset;
  1243. }
  1244. void Spawn::SetExpireOffsetTime(int32 time){
  1245. expire_offset = time;
  1246. }
  1247. int32 Spawn::GetSpawnLocationID(){
  1248. return spawn_location_id;
  1249. }
  1250. void Spawn::SetSpawnLocationID(int32 id){
  1251. spawn_location_id = id;
  1252. }
  1253. int32 Spawn::GetSpawnEntryID(){
  1254. return spawn_entry_id;
  1255. }
  1256. void Spawn::SetSpawnEntryID(int32 id){
  1257. spawn_entry_id = id;
  1258. }
  1259. int32 Spawn::GetSpawnLocationPlacementID(){
  1260. return spawn_location_spawns_id;
  1261. }
  1262. void Spawn::SetSpawnLocationPlacementID(int32 id){
  1263. spawn_location_spawns_id = id;
  1264. }
  1265. const char* Spawn::GetSpawnScript(){
  1266. if(spawn_script.length() > 0)
  1267. return spawn_script.c_str();
  1268. else
  1269. return 0;
  1270. }
  1271. void Spawn::SetSpawnScript(string name){
  1272. spawn_script = name;
  1273. }
  1274. void Spawn::SetPrimaryCommand(const char* name, const char* command, float distance){
  1275. EntityCommand* entity_command = CreateEntityCommand(name, distance, command, "", 0, 0);
  1276. if(primary_command_list.size() > 0 && primary_command_list[0]){
  1277. safe_delete(primary_command_list[0]);
  1278. primary_command_list[0] = entity_command;
  1279. }
  1280. else
  1281. primary_command_list.push_back(entity_command);
  1282. }
  1283. void Spawn::SetSecondaryCommands(vector<EntityCommand*>* commands){
  1284. if(commands && commands->size() > 0){
  1285. vector<EntityCommand*>::iterator itr;
  1286. if(secondary_command_list.size() > 0){
  1287. for(itr = secondary_command_list.begin(); itr != secondary_command_list.end(); itr++){
  1288. safe_delete(*itr);
  1289. }
  1290. secondary_command_list.clear();
  1291. }
  1292. EntityCommand* command = 0;
  1293. for(itr = commands->begin(); itr != commands->end(); itr++){
  1294. command = CreateEntityCommand(*itr);
  1295. secondary_command_list.push_back(command);
  1296. }
  1297. }
  1298. }
  1299. void Spawn::SetPrimaryCommands(vector<EntityCommand*>* commands){
  1300. if(commands && commands->size() > 0){
  1301. vector<EntityCommand*>::iterator itr;
  1302. if(primary_command_list.size() > 0){
  1303. for(itr = primary_command_list.begin(); itr != primary_command_list.end(); itr++){
  1304. safe_delete(*itr);
  1305. }
  1306. primary_command_list.clear();
  1307. }
  1308. EntityCommand* command = 0;
  1309. for(itr = commands->begin(); itr != commands->end(); itr++){
  1310. command = CreateEntityCommand(*itr);
  1311. primary_command_list.push_back(command);
  1312. }
  1313. }
  1314. }
  1315. EntityCommand* Spawn::FindEntityCommand(string command, bool primaryOnly) {
  1316. EntityCommand* entity_command = 0;
  1317. if (primary_command_list.size() > 0) {
  1318. vector<EntityCommand*>::iterator itr;
  1319. for (itr = primary_command_list.begin(); itr != primary_command_list.end(); itr++) {
  1320. if ((*itr)->command.compare(command) == 0) {
  1321. entity_command = *itr;
  1322. break;
  1323. }
  1324. }
  1325. }
  1326. if (primaryOnly)
  1327. return entity_command;
  1328. if (!entity_command && secondary_command_list.size() > 0) {
  1329. vector<EntityCommand*>::iterator itr;
  1330. for (itr = secondary_command_list.begin(); itr != secondary_command_list.end(); itr++) {
  1331. if ((*itr)->command == command) {
  1332. entity_command = *itr;
  1333. break;
  1334. }
  1335. }
  1336. }
  1337. return entity_command;
  1338. }
  1339. void Spawn::SetSizeOffset(int8 offset){
  1340. size_offset = offset;
  1341. }
  1342. int8 Spawn::GetSizeOffset(){
  1343. return size_offset;
  1344. }
  1345. void Spawn::SetMerchantID(int32 val){
  1346. merchant_id = val;
  1347. }
  1348. int32 Spawn::GetMerchantID(){
  1349. return merchant_id;
  1350. }
  1351. void Spawn::SetMerchantType(int8 val){
  1352. merchant_type = val;
  1353. }
  1354. int8 Spawn::GetMerchantType(){
  1355. return merchant_type;
  1356. }
  1357. void Spawn::SetQuestsRequired(map<int32, vector<int16>* >* quests){
  1358. if(quests){
  1359. map<int32, vector<int16>* >::iterator itr;
  1360. for(itr = quests->begin(); itr != quests->end(); itr++){
  1361. vector<int16>* quest_steps = itr->second;
  1362. for (int32 i = 0; i < quest_steps->size(); i++)
  1363. SetQuestsRequired(itr->first, quest_steps->at(i));
  1364. }
  1365. }
  1366. }
  1367. void Spawn::SetQuestsRequired(int32 quest_id, int16 quest_step){
  1368. m_requiredQuests.writelock(__FUNCTION__, __LINE__);
  1369. if (required_quests.count(quest_id) == 0)
  1370. required_quests[quest_id] = new vector<int16>;
  1371. else{
  1372. for (int32 i = 0; i < required_quests[quest_id]->size(); i++){
  1373. if (required_quests[quest_id]->at(i) == quest_step){
  1374. m_requiredQuests.releasewritelock(__FUNCTION__, __LINE__);
  1375. return;
  1376. }
  1377. }
  1378. }
  1379. required_quests[quest_id]->push_back(quest_step);
  1380. m_requiredQuests.releasewritelock(__FUNCTION__, __LINE__);
  1381. }
  1382. void Spawn::SetRequiredHistory(int32 event_id, int32 value1, int32 value2){
  1383. LUAHistory set_value;
  1384. set_value.Value = value1;
  1385. set_value.Value2 = value2;
  1386. set_value.SaveNeeded = false;
  1387. m_requiredHistory.writelock(__FUNCTION__, __LINE__);
  1388. required_history[event_id] = set_value;
  1389. m_requiredHistory.releasewritelock(__FUNCTION__, __LINE__);
  1390. }
  1391. map<int32, vector<int16>* >* Spawn::GetQuestsRequired(){
  1392. return &required_quests;
  1393. }
  1394. void Spawn::SetTransporterID(int32 id){
  1395. transporter_id = id;
  1396. }
  1397. int32 Spawn::GetTransporterID(){
  1398. return transporter_id;
  1399. }
  1400. void Spawn::InitializePosPacketData(Player* player, PacketStruct* packet, bool bSpawnUpdate) {
  1401. int16 version = packet->GetVersion();
  1402. packet->setDataByName("pos_grid_id", appearance.pos.grid_id);
  1403. bool include_heading = true;
  1404. if (IsWidget() && ((Widget*)this)->GetIncludeHeading() == false)
  1405. include_heading = false;
  1406. else if (IsSign() && ((Sign*)this)->GetIncludeHeading() == false)
  1407. include_heading = false;
  1408. else if (IsGroundSpawn())
  1409. include_heading = false;
  1410. if (include_heading){
  1411. packet->setDataByName("pos_heading1", appearance.pos.Dir1);
  1412. packet->setDataByName("pos_heading2", appearance.pos.Dir2);
  1413. }
  1414. if (version <= 910) {
  1415. packet->setDataByName("pos_collision_radius", appearance.pos.collision_radius > 0 ? appearance.pos.collision_radius : 32);
  1416. packet->setDataByName("pos_size", size > 0 ? size : 32);
  1417. packet->setDataByName("pos_size_multiplier", 32); //32 is normal
  1418. }
  1419. else {
  1420. if (size == 0)
  1421. size = 32;
  1422. packet->setDataByName("pos_collision_radius", appearance.pos.collision_radius > 0 ? appearance.pos.collision_radius : 32);
  1423. if (!IsPlayer())
  1424. packet->setDataByName("pos_size", size > 0 ? (((float)size) / 32.0f) : 1.0f);
  1425. else
  1426. packet->setDataByName("pos_size", 1.0f);
  1427. packet->setDataByName("pos_size_ratio", 1.0f);
  1428. }
  1429. packet->setDataByName("pos_state", appearance.pos.state);
  1430. bool include_location = true;
  1431. if (IsWidget() && ((Widget*)this)->GetIncludeLocation() == false)
  1432. include_location = false;
  1433. else if (IsSign() && ((Sign*)this)->GetIncludeLocation() == false)
  1434. include_location = false;
  1435. if (include_location){
  1436. if (IsWidget() && ((Widget*)this)->GetMultiFloorLift()) {
  1437. Widget* widget = (Widget*)this;
  1438. float x = appearance.pos.X - widget->GetWidgetX();
  1439. float y = appearance.pos.Y - widget->GetWidgetY();
  1440. float z = appearance.pos.Z - widget->GetWidgetZ();
  1441. packet->setDataByName("pos_x", x);
  1442. packet->setDataByName("pos_y", y);
  1443. packet->setDataByName("pos_z", z);
  1444. }
  1445. else {
  1446. packet->setDataByName("pos_x", appearance.pos.X);
  1447. packet->setDataByName("pos_y", appearance.pos.Y);
  1448. packet->setDataByName("pos_z", appearance.pos.Z);
  1449. }
  1450. if (IsSign())
  1451. packet->setDataByName("pos_unknown6", 3, 2);
  1452. }
  1453. if (IsPlayer()) {
  1454. packet->setDataByName("pos_x_velocity", static_cast<sint16>(GetSpeedX() * 32));
  1455. packet->setDataByName("pos_y_velocity", static_cast<sint16>(GetSpeedY() * 32));
  1456. packet->setDataByName("pos_z_velocity", static_cast<sint16>(GetSpeedZ() * 32));
  1457. }
  1458. bool bSendSpeed = true;
  1459. if (IsWidget() && ((Widget*)this)->GetMultiFloorLift()) {
  1460. Widget* widget = (Widget*)this;
  1461. float x;
  1462. float y;
  1463. float z;
  1464. if (IsRunning()){
  1465. x = appearance.pos.X2 - widget->GetWidgetX();
  1466. y = appearance.pos.Y2 - widget->GetWidgetY();
  1467. z = appearance.pos.Z2- widget->GetWidgetZ();
  1468. }
  1469. else {
  1470. x = appearance.pos.X - widget->GetWidgetX();
  1471. y = appearance.pos.Y - widget->GetWidgetY();
  1472. z = appearance.pos.Z - widget->GetWidgetZ();
  1473. }
  1474. packet->setDataByName("pos_next_x", x);
  1475. packet->setDataByName("pos_next_y", y);
  1476. packet->setDataByName("pos_next_z", z);
  1477. packet->setDataByName("pos_x3", x);
  1478. packet->setDataByName("pos_y3", y);
  1479. packet->setDataByName("pos_z3", z);
  1480. }
  1481. //If this is a spawn update or this spawn is currently moving we can send these values, otherwise set speed and next_xyz to 0
  1482. //This fixes the bug where spawns with movement scripts face south when initially spawning if they are at their target location.
  1483. else if (bSpawnUpdate || memcmp(&appearance.pos.X, &appearance.pos.X2, sizeof(float) * 3) != 0) {
  1484. packet->setDataByName("pos_next_x", appearance.pos.X2);
  1485. packet->setDataByName("pos_next_y", appearance.pos.Y2);
  1486. packet->setDataByName("pos_next_z", appearance.pos.Z2);
  1487. packet->setDataByName("pos_x3", appearance.pos.X3);
  1488. packet->setDataByName("pos_y3", appearance.pos.Y3);
  1489. packet->setDataByName("pos_z3", appearance.pos.Z3);
  1490. }
  1491. else
  1492. {
  1493. bSendSpeed = false;
  1494. }
  1495. //packet->setDataByName("pos_unknown2", 4, 2);
  1496. int16 speed_multiplier = rule_manager.GetGlobalRule(R_Spawn, SpeedMultiplier)->GetInt16(); // was 1280, 600 and now 300... investigating why
  1497. if (IsPlayer()) {
  1498. Player* player = static_cast<Player*>(this);
  1499. packet->setDataByName("pos_speed", player->GetPosPacketSpeed() * speed_multiplier);
  1500. packet->setDataByName("pos_side_speed", player->GetSideSpeed() * speed_multiplier);
  1501. }
  1502. else if (bSendSpeed) {
  1503. packet->setDataByName("pos_speed", GetSpeed() * speed_multiplier);
  1504. }
  1505. if (IsNPC() || IsPlayer()) {
  1506. packet->setDataByName("pos_move_type", 25);
  1507. }
  1508. else if (IsWidget() || IsSign()) {
  1509. packet->setDataByName("pos_move_type", 11);
  1510. }
  1511. else if(IsGroundSpawn()) {
  1512. packet->setDataByName("pos_move_type", 16);
  1513. }
  1514. if (!IsPlayer())
  1515. packet->setDataByName("pos_movement_mode", 2);
  1516. if(version <= 910)
  1517. packet->setDataByName("pos_unknown10", 0xFFFF, 1);
  1518. else if (version >= 1119)
  1519. packet->setDataByName("face_actor_id", 0xFFFFFFFF);
  1520. else
  1521. packet->setDataByName("pos_unknown10", 0xFFFF);
  1522. if(version <= 910)
  1523. packet->setDataByName("pos_unknown10", 0xFFFF, 2);
  1524. else if (version >= 1119)
  1525. packet->setDataByName("face_actor_id", 0xFFFFFFFF);
  1526. else
  1527. packet->setDataByName("pos_unknown10", 0XFFFF, 1);
  1528. packet->setDataByName("pos_pitch1", appearance.pos.Pitch1);
  1529. packet->setDataByName("pos_pitch2", appearance.pos.Pitch2);
  1530. packet->setDataByName("pos_roll", appearance.pos.Roll);
  1531. }
  1532. void Spawn::InitializeInfoPacketData(Player* spawn, PacketStruct* packet){
  1533. int16 version = packet->GetVersion();
  1534. bool spawnHiddenFromClient = false;
  1535. // radius of 0 is always seen, -1 is never seen (unless items/spells override), larger than 0 is a defined radius to restrict visibility
  1536. sint32 radius = rule_manager.GetGlobalRule(R_PVP, InvisPlayerDiscoveryRange)->GetSInt32();
  1537. if (radius != 0 && (Spawn*)spawn != this && this->IsPlayer() && !spawn->CanSeeInvis((Entity*)this))
  1538. spawnHiddenFromClient = true;
  1539. if(!spawnHiddenFromClient && (appearance.targetable == 1 || appearance.show_level == 1 || appearance.display_name == 1)){
  1540. appearance.locked_no_loot = 1; //for now
  1541. if(!IsObject() && !IsGroundSpawn() && !IsWidget() && !IsSign()){
  1542. int8 percent = 0;
  1543. if(GetHP() > 0)
  1544. percent = (int8)(((float)GetHP()/GetTotalHP()) * 100);
  1545. if(percent < 100){
  1546. packet->setDataByName("hp_remaining", 100 ^ percent);
  1547. }
  1548. else
  1549. packet->setDataByName("hp_remaining", 0);
  1550. if(GetTotalPower() > 0){
  1551. percent = (int8)(((float)GetPower()/GetTotalPower()) * 100);
  1552. if(percent > 0)
  1553. packet->setDataByName("power_percent", percent);
  1554. else
  1555. packet->setDataByName("power_percent", 0);
  1556. }
  1557. }
  1558. }
  1559. packet->setDataByName("level", (int8)GetLevel());
  1560. packet->setDataByName("unknown4", (int8)GetLevel());
  1561. packet->setDataByName("difficulty", appearance.encounter_level); //6);
  1562. packet->setDataByName("heroic_flag", appearance.heroic_flag);
  1563. if(!IsObject() && !IsGroundSpawn() && !IsWidget() && !IsSign())
  1564. packet->setDataByName("interaction_flag", 12); //this makes NPCs head turn to look at you
  1565. packet->setDataByName("class", appearance.adventure_class);
  1566. int16 model_type = appearance.model_type;
  1567. if (GetIllusionModel() != 0) {
  1568. if (IsPlayer()) {
  1569. if (((Player*)this)->get_character_flag(CF_SHOW_ILLUSION)) {
  1570. model_type = GetIllusionModel();
  1571. }
  1572. }
  1573. else
  1574. model_type = GetIllusionModel();
  1575. }
  1576. int16 sogaModelType = appearance.soga_model_type;
  1577. if (spawnHiddenFromClient)
  1578. {
  1579. model_type = 0;
  1580. sogaModelType = 0;
  1581. }
  1582. packet->setDataByName("model_type", model_type);
  1583. if(appearance.soga_model_type == 0)
  1584. packet->setDataByName("soga_model_type", model_type);
  1585. else
  1586. packet->setDataByName("soga_model_type", sogaModelType);
  1587. if(GetTempActionState() >= 0)
  1588. packet->setDataByName("action_state", GetTempActionState());
  1589. else
  1590. packet->setDataByName("action_state", appearance.action_state);
  1591. if(GetTempVisualState() >= 0)
  1592. packet->setDataByName("visual_state", GetTempVisualState());
  1593. else
  1594. packet->setDataByName("visual_state", appearance.visual_state);
  1595. packet->setDataByName("emote_state", appearance.emote_state);
  1596. packet->setDataByName("mood_state", appearance.mood_state);
  1597. packet->setDataByName("gender", appearance.gender);
  1598. packet->setDataByName("race", appearance.race);
  1599. packet->setDataByName("gender", appearance.gender);
  1600. if(IsEntity()){
  1601. Entity* entity = ((Entity*)this);
  1602. packet->setDataByName("combat_voice", entity->GetCombatVoice());
  1603. packet->setDataByName("emote_voice", entity->GetEmoteVoice());
  1604. for(int i=0;i<25;i++){
  1605. if(i == 2){ //don't send helm if hidden flag
  1606. if(IsPlayer()){
  1607. if(((Player*)this)->get_character_flag(CF_HIDE_HELM)){
  1608. packet->setDataByName("equipment_types", 0, i);
  1609. packet->setColorByName("equipment_colors", 0, i);
  1610. packet->setColorByName("equipment_highlights", 0, i);
  1611. continue;
  1612. }
  1613. }
  1614. if (IsBot()) {
  1615. if (!((Bot*)this)->ShowHelm) {
  1616. packet->setDataByName("equipment_types", 0, i);
  1617. packet->setColorByName("equipment_colors", 0, i);
  1618. packet->setColorByName("equipment_highlights", 0, i);
  1619. continue;
  1620. }
  1621. }
  1622. }
  1623. else if(i == 19){ //don't send cloak if hidden
  1624. if(IsPlayer()){
  1625. if(!((Player*)this)->get_character_flag(CF_SHOW_CLOAK)){
  1626. packet->setDataByName("equipment_types", 0, i);
  1627. packet->setColorByName("equipment_colors", 0, i);
  1628. packet->setColorByName("equipment_highlights", 0, i);
  1629. continue;
  1630. }
  1631. }
  1632. if (IsBot()) {
  1633. if (!((Bot*)this)->ShowCloak) {
  1634. packet->setDataByName("equipment_types", 0, i);
  1635. packet->setColorByName("equipment_colors", 0, i);
  1636. packet->setColorByName("equipment_highlights", 0, i);
  1637. continue;
  1638. }
  1639. }
  1640. }
  1641. packet->setDataByName("equipment_types", entity->equipment.equip_id[i], i);
  1642. packet->setColorByName("equipment_colors", entity->equipment.color[i], i);
  1643. packet->setColorByName("equipment_highlights", entity->equipment.highlight[i], i);
  1644. }
  1645. packet->setDataByName("mount_type", entity->GetMount());
  1646. // find the visual flags
  1647. int8 vis_flag = 0;
  1648. //Invis + crouch flag check
  1649. if (entity->IsStealthed())
  1650. vis_flag += (INFO_VIS_FLAG_INVIS + INFO_VIS_FLAG_CROUCH);
  1651. //Invis flag check
  1652. else if (entity->IsInvis())
  1653. vis_flag += INFO_VIS_FLAG_INVIS;
  1654. //Mount flag check
  1655. if (entity->GetMount() > 0)
  1656. vis_flag += INFO_VIS_FLAG_MOUNTED;
  1657. //Hide hood check
  1658. if ((IsPlayer() && ((Player*)this)->get_character_flag(CF_HIDE_HOOD)) || appearance.hide_hood)
  1659. vis_flag += INFO_VIS_FLAG_HIDE_HOOD;
  1660. packet->setDataByName("visual_flag", vis_flag);
  1661. packet->setColorByName("mount_saddle_color", entity->GetMountSaddleColor());
  1662. packet->setColorByName("mount_color", entity->GetMountColor());
  1663. packet->setDataByName("hair_type_id", entity->features.hair_type);
  1664. packet->setDataByName("chest_type_id", entity->features.chest_type);
  1665. packet->setDataByName("wing_type_id", entity->features.wing_type);
  1666. packet->setDataByName("legs_type_id", entity->features.legs_type);
  1667. packet->setDataByName("soga_hair_type_id", entity->features.soga_hair_type);
  1668. packet->setDataByName("facial_hair_type_id", entity->features.hair_face_type);
  1669. packet->setDataByName("soga_facial_hair_type_id", entity->features.soga_hair_face_type);
  1670. for(int i=0;i<3;i++){
  1671. packet->setDataByName("eye_type", entity->features.eye_type[i], i);
  1672. packet->setDataByName("ear_type", entity->features.ear_type[i], i);
  1673. packet->setDataByName("eye_brow_type", entity->features.eye_brow_type[i], i);
  1674. packet->setDataByName("cheek_type", entity->features.cheek_type[i], i);
  1675. packet->setDataByName("lip_type", entity->features.lip_type[i], i);
  1676. packet->setDataByName("chin_type", entity->features.chin_type[i], i);
  1677. packet->setDataByName("nose_type", entity->features.nose_type[i], i);
  1678. packet->setDataByName("soga_eye_type", entity->features.soga_eye_type[i], i);
  1679. packet->setDataByName("soga_ear_type", entity->features.soga_ear_type[i], i);
  1680. packet->setDataByName("soga_eye_brow_type", entity->features.soga_eye_brow_type[i], i);
  1681. packet->setDataByName("soga_cheek_type", entity->features.soga_cheek_type[i], i);
  1682. packet->setDataByName("soga_lip_type", entity->features.soga_lip_type[i], i);
  1683. packet->setDataByName("soga_chin_type", entity->features.soga_chin_type[i], i);
  1684. packet->setDataByName("soga_nose_type", entity->features.soga_nose_type[i], i);
  1685. }
  1686. packet->setColorByName("skin_color", entity->features.skin_color);
  1687. packet->setColorByName("eye_color", entity->features.eye_color);
  1688. packet->setColorByName("hair_type_color", entity->features.hair_type_color);
  1689. packet->setColorByName("hair_type_highlight_color", entity->features.hair_type_highlight_color);
  1690. packet->setColorByName("hair_face_color", entity->features.hair_face_color);
  1691. packet->setColorByName("hair_face_highlight_color", entity->features.hair_face_highlight_color);
  1692. packet->setColorByName("hair_highlight", entity->features.hair_highlight_color);
  1693. packet->setColorByName("wing_color1", entity->features.wing_color1);
  1694. packet->setColorByName("wing_color2", entity->features.wing_color2);
  1695. packet->setColorByName("hair_color1", entity->features.hair_color1);
  1696. packet->setColorByName("hair_color2", entity->features.hair_color2);
  1697. packet->setColorByName("soga_skin_color", entity->features.soga_skin_color);
  1698. packet->setColorByName("soga_eye_color", entity->features.soga_eye_color);
  1699. packet->setColorByName("soga_hair_color1", entity->features.soga_hair_color1);
  1700. packet->setColorByName("soga_hair_color2", entity->features.soga_hair_color2);
  1701. packet->setColorByName("soga_hair_type_color", entity->features.soga_hair_type_color);
  1702. packet->setColorByName("soga_hair_type_highlight_color", entity->features.soga_hair_type_highlight_color);
  1703. packet->setColorByName("soga_hair_face_color", entity->features.soga_hair_face_color);
  1704. packet->setColorByName("soga_hair_face_highlight_color", entity->features.soga_hair_face_highlight_color);
  1705. packet->setColorByName("soga_hair_highlight", entity->features.soga_hair_highlight_color);
  1706. packet->setDataByName("body_age", entity->features.body_age);
  1707. }
  1708. else{
  1709. EQ2_Color empty;
  1710. empty.red = 255;
  1711. empty.blue = 255;
  1712. empty.green = 255;
  1713. packet->setColorByName("skin_color", empty);
  1714. packet->setColorByName("eye_color", empty);
  1715. packet->setColorByName("soga_skin_color", empty);
  1716. packet->setColorByName("soga_eye_color", empty);
  1717. }
  1718. if(appearance.icon == 0){
  1719. if(appearance.attackable == 1)
  1720. appearance.icon = 0;
  1721. else if(appearance.encounter_level > 0)
  1722. appearance.icon = 4;
  1723. else
  1724. appearance.icon = 6;
  1725. }
  1726. // If Coe+ clients modify the values before we send
  1727. // if not then just send the value we have.
  1728. int8 temp_icon = appearance.icon;
  1729. //Check if we need to add the hand icon..
  1730. if ((temp_icon & 6) != 6 && appearance.display_hand_icon) {
  1731. temp_icon |= 6;
  1732. }
  1733. //Icon value 28 for boats, set this without modifying the value
  1734. if (version >= 1188 && temp_icon != 28) {
  1735. if ((temp_icon & 64) > 0) {
  1736. temp_icon -= 64; // remove the DoV value;
  1737. temp_icon += 128; // add the CoE value
  1738. }
  1739. if ((temp_icon & 32) > 0) {
  1740. temp_icon -= 32; // remove the DoV value;
  1741. temp_icon += 64; // add the CoE value
  1742. }
  1743. if ((temp_icon & 4) > 0) {
  1744. temp_icon -= 4; // remove DoV value
  1745. temp_icon += 8; // add the CoE icon
  1746. }
  1747. if ((temp_icon & 6) > 0) {
  1748. temp_icon -= 10; // remove DoV value
  1749. temp_icon += 12; // add the CoE icon
  1750. }
  1751. }
  1752. packet->setDataByName("icon", temp_icon);//appearance.icon);
  1753. int32 temp_activity_status = 0;
  1754. if (!Alive() && GetTotalHP() > 0 && !IsObject() && !IsGroundSpawn())
  1755. temp_activity_status = 1;
  1756. temp_activity_status += (IsNPC() || IsObject() || IsGroundSpawn()) ? 1 << 1 : 0;
  1757. if (version >= 1188) {
  1758. if (IsGroundSpawn() || GetShowHandIcon())
  1759. temp_activity_status += ACTIVITY_STATUS_INTERACTABLE_1188;
  1760. if ((appearance.activity_status & ACTIVITY_STATUS_ROLEPLAYING) > 0)
  1761. temp_activity_status += ACTIVITY_STATUS_ROLEPLAYING_1188;
  1762. if ((appearance.activity_status & ACTIVITY_STATUS_ANONYMOUS) > 0)
  1763. temp_activity_status += ACTIVITY_STATUS_ANONYMOUS_1188;
  1764. if ((appearance.activity_status & ACTIVITY_STATUS_LINKDEAD) > 0)
  1765. temp_activity_status += ACTIVITY_STATUS_LINKDEAD_1188;
  1766. if ((appearance.activity_status & ACTIVITY_STATUS_CAMPING) > 0)
  1767. temp_activity_status += ACTIVITY_STATUS_CAMPING_1188;
  1768. if ((appearance.activity_status & ACTIVITY_STATUS_LFG) > 0)
  1769. temp_activity_status += ACTIVITY_STATUS_LFG_1188;
  1770. if ((appearance.activity_status & ACTIVITY_STATUS_LFW) > 0)
  1771. temp_activity_status += ACTIVITY_STATUS_LFW_1188;
  1772. if ((appearance.activity_status & ACTIVITY_STATUS_SOLID) > 0)
  1773. temp_activity_status += ACTIVITY_STATUS_SOLID_1188;
  1774. if ((appearance.activity_status & ACTIVITY_STATUS_IMMUNITY_GAINED) > 0)
  1775. temp_activity_status += ACTIVITY_STATUS_IMMUNITY_GAINED_1188;
  1776. if ((appearance.activity_status & ACTIVITY_STATUS_IMMUNITY_REMAINING) > 0)
  1777. temp_activity_status += ACTIVITY_STATUS_IMMUNITY_REMAINING_1188;
  1778. if ((appearance.activity_status & ACTIVITY_STATUS_AFK) > 0)
  1779. temp_activity_status += ACTIVITY_STATUS_AFK_1188;
  1780. if (EngagedInCombat())
  1781. temp_activity_status += ACTIVITY_STATUS_INCOMBAT_1188;
  1782. // if this is either a boat or lift let the client be manipulated by the object
  1783. if (appearance.icon == 28 || appearance.icon == 12)
  1784. temp_activity_status += ACTIVITY_STATUS_ISTRANSPORT_1188;
  1785. }
  1786. else
  1787. {
  1788. temp_activity_status = appearance.activity_status;
  1789. // WE ARE UNSURE OF THESE OLD CLIENT VALUES USED AS TEMP PLACEHOLDERS FOR NEWER CLIENTS
  1790. if ((appearance.activity_status & ACTIVITY_STATUS_AFK) > 0)
  1791. temp_activity_status -= ACTIVITY_STATUS_AFK;
  1792. }
  1793. packet->setDataByName("activity_status", temp_activity_status); //appearance.activity_status);
  1794. // If player and player has a follow target
  1795. if (IsPlayer()) {
  1796. if (((Player*)this)->GetFollowTarget())
  1797. packet->setDataByName("follow_target", ((((Player*)this)->GetIDWithPlayerSpawn(((Player*)this)->GetFollowTarget()) * -1) - 1));
  1798. else
  1799. packet->setDataByName("follow_target", 0);
  1800. }
  1801. if (GetTarget() && GetTarget()->GetTargetable())
  1802. packet->setDataByName("target_id", ((spawn->GetIDWithPlayerSpawn(GetTarget()) * -1) - 1));
  1803. else
  1804. packet->setDataByName("target_id", 0);
  1805. //Send spell effects for target window
  1806. if(IsEntity()){
  1807. InfoStruct* info = ((Entity*)this)->GetInfoStruct();
  1808. int8 i = 0;
  1809. int16 backdrop = 0;
  1810. int16 spell_icon = 0;
  1811. int32 spell_id = 0;
  1812. LuaSpell* spell = 0;
  1813. ((Entity*)this)->GetSpellEffectMutex()->readlock(__FUNCTION__, __LINE__);
  1814. while(i < 30){
  1815. //Change value of spell id for this packet if spell exists
  1816. spell_id = info->spell_effects[i].spell_id;
  1817. if(spell_id > 0)
  1818. spell_id = 0xFFFFFFFF - spell_id;
  1819. else
  1820. spell_id = 0;
  1821. packet->setSubstructDataByName("spell_effects", "spell_id", spell_id, i);
  1822. //Change value of spell icon for this packet if spell exists
  1823. spell_icon = info->spell_effects[i].icon;
  1824. if(spell_icon > 0){
  1825. if(!(spell_icon == 0xFFFF))
  1826. spell_icon = 0xFFFF - spell_icon;
  1827. }
  1828. else
  1829. spell_icon = 0;
  1830. packet->setSubstructDataByName("spell_effects", "spell_icon", spell_icon, i);
  1831. //Change backdrop values to match values in this packet
  1832. backdrop = info->spell_effects[i].icon_backdrop;
  1833. switch(backdrop){
  1834. case 312:
  1835. backdrop = 33080;
  1836. break;
  1837. case 313:
  1838. backdrop = 33081;
  1839. break;
  1840. case 314:
  1841. backdrop = 33082;
  1842. break;
  1843. case 315:
  1844. backdrop = 33083;
  1845. break;
  1846. case 316:
  1847. backdrop = 33084;
  1848. break;
  1849. case 317:
  1850. backdrop = 33085;
  1851. break;
  1852. case (318 || 319):
  1853. backdrop = 33086;
  1854. break;
  1855. default:
  1856. break;
  1857. }
  1858. packet->setSubstructDataByName("spell_effects", "spell_icon_backdrop", backdrop, i);
  1859. spell = info->spell_effects[i].spell;
  1860. if (spell)
  1861. packet->setSubstructDataByName("spell_effects", "spell_triggercount", spell->num_triggers, i);
  1862. i++;
  1863. }
  1864. ((Entity*)this)->GetSpellEffectMutex()->releasereadlock(__FUNCTION__, __LINE__);
  1865. }
  1866. }
  1867. void Spawn::MoveToLocation(Spawn* spawn, float distance, bool immediate, bool mapped){
  1868. if(!spawn)
  1869. return;
  1870. SetRunningTo(spawn);
  1871. FaceTarget(spawn);
  1872. if (!IsPlayer() && distance > 0.0f)
  1873. {
  1874. if (IsFlying() && CheckLoS(spawn))
  1875. {
  1876. if (immediate)
  1877. ClearRunningLocations();
  1878. AddRunningLocation(spawn->GetX(), spawn->GetY(), spawn->GetZ(), GetSpeed(), distance, true, true, "", true);
  1879. }
  1880. else if (/*!mapped && */GetZone())
  1881. {
  1882. GetZone()->movementMgr->NavigateTo((Entity*)this, spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1883. last_grid_update = Timer::GetCurrentTime2();
  1884. }
  1885. else
  1886. {
  1887. if (immediate)
  1888. ClearRunningLocations();
  1889. AddRunningLocation(spawn->GetX(), spawn->GetY(), spawn->GetZ(), GetSpeed(), distance, true, true, "", mapped);
  1890. }
  1891. }
  1892. }
  1893. void Spawn::ProcessMovement(bool isSpawnListLocked){
  1894. CheckProximities();
  1895. if(IsPlayer()){
  1896. //Check if player is riding a boat, if so update pos (boat's current location + XYZ offsets)
  1897. Player* player = ((Player*)this);
  1898. int32 boat_id = player->GetBoatSpawn();
  1899. Spawn* boat = 0;
  1900. if(boat_id > 0)
  1901. boat = GetZone()->GetSpawnByID(boat_id, isSpawnListLocked);
  1902. if(boat){
  1903. SetX(boat->GetX() + player->GetBoatX());
  1904. SetY(boat->GetY() + player->GetBoatY());
  1905. SetZ(boat->GetZ() + player->GetBoatZ());
  1906. }
  1907. return;
  1908. }
  1909. if (forceMapCheck && GetZone() != nullptr && zone->zonemap != nullptr && zone->zonemap->IsMapLoaded())
  1910. {
  1911. FixZ(true);
  1912. int32 newGrid = GetZone()->Grid->GetGridID(this);
  1913. if (!IsFlying() && newGrid != 0 && newGrid != appearance.pos.grid_id)
  1914. SetPos(&(appearance.pos.grid_id), newGrid);
  1915. forceMapCheck = false;
  1916. }
  1917. if (GetHP() <= 0 && !IsWidget())
  1918. return;
  1919. if (EngagedInCombat())
  1920. {
  1921. int locations = 0;
  1922. if (movement_locations && MMovementLocations)
  1923. {
  1924. MMovementLocations->readlock(__FUNCTION__, __LINE__);
  1925. locations = movement_locations->size();
  1926. MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
  1927. }
  1928. if (locations < 1 && GetZone() && ((Entity*)this)->IsFeared())
  1929. {
  1930. CalculateNewFearpoint();
  1931. }
  1932. }
  1933. MMovementLoop.lock();
  1934. Spawn* followTarget = GetZone()->GetSpawnByID(m_followTarget, isSpawnListLocked);
  1935. if (!followTarget && m_followTarget > 0)
  1936. m_followTarget = 0;
  1937. if (following && followTarget && !((Entity*)this)->IsFeared()) {
  1938. // Need to clear m_followTarget before the zoneserver deletes it
  1939. if (followTarget->GetHP() <= 0) {
  1940. followTarget = 0;
  1941. MMovementLoop.unlock();
  1942. return;
  1943. }
  1944. if (!IsEntity() || (!((Entity*)this)->IsCasting() && !((Entity*)this)->IsMezzedOrStunned() && !((Entity*)this)->IsRooted())) {
  1945. if (GetBaseSpeed() > 0) {
  1946. CalculateRunningLocation();
  1947. }
  1948. else {
  1949. float speed = 4.0f;
  1950. if (IsEntity())
  1951. speed = ((Entity*)this)->GetMaxSpeed();
  1952. SetSpeed(speed);
  1953. }
  1954. MovementLocation* loc = GetCurrentRunningLocation();
  1955. float dist = GetDistance(followTarget, true);
  1956. if ((!EngagedInCombat() && m_followDistance > 0 && dist <= m_followDistance) ||
  1957. (dist <= rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())) {
  1958. ClearRunningLocations();
  1959. CalculateRunningLocation(true);
  1960. }
  1961. else if (loc) {
  1962. float distance = GetDistance(followTarget, loc->x, loc->y, loc->z);
  1963. if ( (!EngagedInCombat() && m_followDistance > 0 && distance > m_followDistance) ||
  1964. ( EngagedInCombat() && distance > rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())) {
  1965. MoveToLocation(followTarget, rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat(), true, loc->mapped);
  1966. CalculateRunningLocation();
  1967. }
  1968. }
  1969. else {
  1970. MoveToLocation(followTarget, rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat());
  1971. CalculateRunningLocation();
  1972. }
  1973. }
  1974. }
  1975. // Movement loop is only for scripted paths
  1976. else if(!EngagedInCombat() && !NeedsToResumeMovement() && movement_loop.size() > 0 && movement_index < movement_loop.size() && (!IsNPC() || !((NPC*)this)->m_runningBack)){
  1977. // Get the target location
  1978. MovementData* data = movement_loop[movement_index];
  1979. // need to resume our movement
  1980. if(resume_movement){
  1981. if (movement_locations){
  1982. while (movement_locations->size()){
  1983. safe_delete(movement_locations->front());
  1984. movement_locations->pop_front();
  1985. }
  1986. movement_locations->clear();
  1987. }
  1988. data = movement_loop[movement_index];
  1989. ((Entity*)this)->SetSpeed(data->speed);
  1990. SetSpeed(data->speed);
  1991. if(!IsWidget())
  1992. FaceTarget(data->x, data->z);
  1993. // 0 delay at target location, need to set multiple locations
  1994. if(data->delay == 0 && movement_loop.size() > 0) {
  1995. int16 tmp_index = movement_index+1;
  1996. MovementData* data2 = 0;
  1997. if(tmp_index < movement_loop.size())
  1998. data2 = movement_loop[tmp_index];
  1999. else
  2000. data2 = movement_loop[0];
  2001. AddRunningLocation(data->x, data->y, data->z, data->speed, 0, true, false, "", true);
  2002. AddRunningLocation(data2->x, data2->y, data2->z, data2->speed, 0, true, true, "", true);
  2003. }
  2004. // delay at target location, only need to set 1 location
  2005. else
  2006. AddRunningLocation(data->x, data->y, data->z, data->speed);
  2007. movement_start_time = 0;
  2008. resume_movement = false;
  2009. }
  2010. // If we are not moving or we have arrived at our destination
  2011. else if(!IsRunning() || (data && data->x == GetX() && data->y == GetY() && data->z == GetZ())){
  2012. // If we were moving remove the last running location (the point we just arrived at)
  2013. if(IsRunning())
  2014. RemoveRunningLocation();
  2015. // If this waypoint has a delay and we just arrived here (movement_start_time == 0)
  2016. if(data->delay > 0 && movement_start_time == 0){
  2017. // Set the current time
  2018. movement_start_time = Timer::GetCurrentTime2();
  2019. // If this waypoint had a lua function then call it
  2020. if(data->lua_function.length() > 0)
  2021. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_CUSTOM, 0, data->lua_function.c_str());
  2022. int16 nextMove;
  2023. if ((int16)(movement_index + 1) < movement_loop.size())
  2024. nextMove = movement_index + 1;
  2025. else
  2026. nextMove = 0;
  2027. // Get the next target location
  2028. data = movement_loop[nextMove];
  2029. //Go ahead and face the next location
  2030. FaceTarget(data->x, data->z);
  2031. }
  2032. // If this waypoint has no delay or we have waited the required time (current time >= delay + movement_start_time)
  2033. else if(data->delay == 0 || (data->delay > 0 && Timer::GetCurrentTime2() >= (data->delay+movement_start_time))) {
  2034. // if no delay at this waypoint but a lua function for it then call the function
  2035. if(data->delay == 0 && data->lua_function.length() > 0)
  2036. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_CUSTOM, 0, data->lua_function.c_str());
  2037. // Advance the current movement loop index
  2038. if((int16)(movement_index+1) < movement_loop.size())
  2039. movement_index++;
  2040. else
  2041. movement_index = 0;
  2042. // Get the next target location
  2043. data = movement_loop[movement_index];
  2044. // set the speed for that location
  2045. SetSpeed(data->speed);
  2046. if(!IsWidget())
  2047. // turn towards the location
  2048. FaceTarget(data->x, data->z);
  2049. // If 0 delay at location get and set data for the point after it
  2050. if(data->delay == 0 && movement_loop.size() > 0){
  2051. while (movement_locations->size()){
  2052. safe_delete(movement_locations->front());
  2053. movement_locations->pop_front();
  2054. }
  2055. // clear current target locations
  2056. movement_locations->clear();
  2057. // get the data for the location after out new location
  2058. int16 tmp_index = movement_index+1;
  2059. MovementData* data2 = 0;
  2060. if(tmp_index < movement_loop.size())
  2061. data2 = movement_loop[tmp_index];
  2062. else
  2063. data2 = movement_loop[0];
  2064. // set the first location (adds it to movement_locations that we just cleared)
  2065. AddRunningLocation(data->x, data->y, data->z, data->speed, 0, true, false, "", true);
  2066. // set the location after that
  2067. AddRunningLocation(data2->x, data2->y, data2->z, data2->speed, 0, true, true, "", true);
  2068. }
  2069. // there is a delay at the next location so we only need to set it
  2070. else
  2071. AddRunningLocation(data->x, data->y, data->z, data->speed);
  2072. // reset this timer to 0 now that we are moving again
  2073. movement_start_time = 0;
  2074. }
  2075. }
  2076. // moving and not at target location yet
  2077. else if(GetBaseSpeed() > 0)
  2078. CalculateRunningLocation();
  2079. // not moving, have a target location but not at it yet
  2080. else if (data) {
  2081. SetSpeed(data->speed);
  2082. AddRunningLocation(data->x, data->y, data->z, data->speed);
  2083. }
  2084. }
  2085. else if (IsRunning()) {
  2086. CalculateRunningLocation();
  2087. }
  2088. /*else if (IsNPC() && !IsRunning() && !EngagedInCombat() && ((NPC*)this)->GetRunbackLocation()) {
  2089. // Is an npc that is not moving and not engaged in combat but has a run back location set then clear the runback location
  2090. LogWrite(NPC_AI__DEBUG, 7, "NPC_AI", "Clear runback location for %s", GetName());
  2091. ((NPC*)this)->ClearRunback();
  2092. resume_movement = true;
  2093. NeedsToResumeMovement(false);
  2094. }*/
  2095. MMovementLoop.unlock();
  2096. }
  2097. void Spawn::ResetMovement(){
  2098. MMovementLoop.lock();
  2099. vector<MovementData*>::iterator itr;
  2100. for(itr = movement_loop.begin(); itr != movement_loop.end(); itr++){
  2101. safe_delete(*itr);
  2102. }
  2103. MMovementLoop.unlock();
  2104. resume_movement = true;
  2105. movement_index = 0;
  2106. }
  2107. void Spawn::AddMovementLocation(float x, float y, float z, float speed, int16 delay, const char* lua_function){
  2108. LogWrite(LUA__DEBUG, 5, "LUA", "AddMovementLocation: x: %.2f, y: %.2f, z: %.2f, speed: %.2f, delay: %i, lua: %s",
  2109. x, y, z, speed, delay, string(lua_function).c_str());
  2110. MovementData* data = new MovementData;
  2111. data->x = x;
  2112. data->y = y;
  2113. data->z = z;
  2114. data->speed = speed;
  2115. data->delay = delay*1000;
  2116. if(lua_function)
  2117. data->lua_function = string(lua_function);
  2118. MMovementLoop.lock();
  2119. movement_loop.push_back(data);
  2120. MMovementLoop.unlock();
  2121. }
  2122. bool Spawn::IsRunning(){
  2123. if(movement_locations && movement_locations->size() > 0)
  2124. return true;
  2125. else
  2126. return false;
  2127. }
  2128. void Spawn::RunToLocation(float x, float y, float z, float following_x, float following_y, float following_z){
  2129. if(!IsWidget())
  2130. FaceTarget(x, z);
  2131. SetPos(&appearance.pos.X2, x, false);
  2132. SetPos(&appearance.pos.Z2, z, false);
  2133. SetPos(&appearance.pos.Y2, y, false);
  2134. if(following_x == 0 && following_y == 0 && following_z == 0){
  2135. SetPos(&appearance.pos.X3, x, false);
  2136. SetPos(&appearance.pos.Z3, z, false);
  2137. SetPos(&appearance.pos.Y3, y, false);
  2138. }
  2139. else{
  2140. SetPos(&appearance.pos.X3, following_x, false);
  2141. SetPos(&appearance.pos.Y3, following_y, false);
  2142. SetPos(&appearance.pos.Z3, following_z, false);
  2143. }
  2144. position_changed = true;
  2145. changed = true;
  2146. GetZone()->AddChangedSpawn(this);
  2147. }
  2148. MovementLocation* Spawn::GetCurrentRunningLocation(){
  2149. MovementLocation* ret = 0;
  2150. if(movement_locations && movement_locations->size() > 0){
  2151. MMovementLocations->readlock(__FUNCTION__, __LINE__);
  2152. ret = movement_locations->front();
  2153. MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
  2154. }
  2155. return ret;
  2156. }
  2157. MovementLocation* Spawn::GetLastRunningLocation(){
  2158. MovementLocation* ret = 0;
  2159. if(movement_locations && movement_locations->size() > 0){
  2160. MMovementLocations->readlock(__FUNCTION__, __LINE__);
  2161. ret = movement_locations->back();
  2162. MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
  2163. }
  2164. return ret;
  2165. }
  2166. void Spawn::AddRunningLocation(float x, float y, float z, float speed, float distance_away, bool attackable, bool finished_adding_locations, string lua_function, bool isMapped){
  2167. if(speed == 0)
  2168. return;
  2169. ((Entity*)this)->SetSpeed(speed);
  2170. MovementLocation* current_location = 0;
  2171. float distance = GetDistance(x, y, z, distance_away != 0);
  2172. if(distance_away != 0){
  2173. distance -= distance_away;
  2174. x = x - (GetX() - x)*distance_away/distance;
  2175. z = z - (GetZ() - z)*distance_away/distance;
  2176. }
  2177. if(!movement_locations){
  2178. movement_locations = new deque<MovementLocation*>();
  2179. MMovementLocations = new Mutex();
  2180. }
  2181. MovementLocation* data = new MovementLocation;
  2182. data->mapped = isMapped;
  2183. data->x = x;
  2184. data->y = y;
  2185. data->z = z;
  2186. data->speed = speed;
  2187. data->attackable = attackable;
  2188. data->lua_function = lua_function;
  2189. data->gridid = 0; // used for runback defaults
  2190. MMovementLocations->writelock(__FUNCTION__, __LINE__);
  2191. if(movement_locations->size() > 0)
  2192. current_location = movement_locations->back();
  2193. if(!current_location){
  2194. SetSpawnOrigX(GetX());
  2195. SetSpawnOrigY(GetY());
  2196. SetSpawnOrigZ(GetZ());
  2197. SetSpawnOrigHeading(GetHeading());
  2198. }
  2199. movement_locations->push_back(data);
  2200. if(finished_adding_locations){
  2201. current_location = movement_locations->front();
  2202. SetSpeed(current_location->speed);
  2203. if(movement_locations->size() > 1){
  2204. data = movement_locations->at(1);
  2205. RunToLocation(current_location->x, current_location->y, current_location->z, data->x, data->y, data->z);
  2206. }
  2207. else
  2208. RunToLocation(current_location->x, current_location->y, current_location->z, 0, 0, 0);
  2209. }
  2210. MMovementLocations->releasewritelock(__FUNCTION__, __LINE__);
  2211. }
  2212. bool Spawn::RemoveRunningLocation(){
  2213. bool ret = false;
  2214. if(movement_locations){
  2215. MMovementLocations->writelock(__FUNCTION__, __LINE__);
  2216. if(movement_locations->size() > 0){
  2217. delete movement_locations->front();
  2218. movement_locations->pop_front();
  2219. ret = true;
  2220. }
  2221. MMovementLocations->releasewritelock(__FUNCTION__, __LINE__);
  2222. }
  2223. return ret;
  2224. }
  2225. void Spawn::ClearRunningLocations(){
  2226. while(RemoveRunningLocation()){}
  2227. }
  2228. bool Spawn::CalculateChange(){
  2229. bool remove_needed = false;
  2230. if(movement_locations && MMovementLocations){
  2231. MovementLocation* data = 0;
  2232. MMovementLocations->readlock(__FUNCTION__, __LINE__);
  2233. if(movement_locations->size() > 0){
  2234. // Target location
  2235. data = movement_locations->front();
  2236. // If no target or we are at the target location need to remove this point
  2237. if(!data || (data->x == GetX() && data->y == GetY() && data->z == GetZ()))
  2238. remove_needed = true;
  2239. if(data){
  2240. if(NeedsToResumeMovement()){
  2241. resume_movement = true;
  2242. NeedsToResumeMovement(false);
  2243. }
  2244. if(!data->attackable)
  2245. SetHeading(GetSpawnOrigHeading());
  2246. }
  2247. }
  2248. MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
  2249. if(remove_needed) {
  2250. if (data && data->lua_function.length() > 0)
  2251. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_CUSTOM, 0, data->lua_function.c_str());
  2252. RemoveRunningLocation();
  2253. //CalculateChange();
  2254. }
  2255. else if(data){
  2256. // Speed is per second so we need a time_step (amount of time since the last update) to modify movement by
  2257. float time_step = (Timer::GetCurrentTime2() - last_movement_update) * 0.001; // * 0.001 is the same as / 1000, float muliplications is suppose to be faster though
  2258. // Get current location
  2259. float nx = GetX();
  2260. float ny = GetY();
  2261. float nz = GetZ();
  2262. // Get Forward vecotr
  2263. float tar_vx = data->x - nx;
  2264. float tar_vy = data->y - ny;
  2265. float tar_vz = data->z - nz;
  2266. // Multiply speed by the time_step to get how much should have changed over the last tick
  2267. float speed = GetSpeed() * time_step;
  2268. // Normalize the forward vector and multiply by speed, this gives us our change in coords, just need to add them to our current coords
  2269. float len = sqrtf(tar_vx * tar_vx + tar_vy * tar_vy + tar_vz * tar_vz);
  2270. tar_vx = (tar_vx / len) * speed;
  2271. tar_vy = (tar_vy / len) * speed;
  2272. tar_vz = (tar_vz / len) * speed;
  2273. // Distance less then 0.5 just set the npc to the target location
  2274. if (GetDistance(data->x, data->y, data->z, IsWidget() ? false : true) <= 0.5f) {
  2275. SetX(data->x, false);
  2276. SetZ(data->z, false);
  2277. SetY(data->y, false, true);
  2278. }
  2279. else {
  2280. SetX(nx + tar_vx, false);
  2281. SetZ(nz + tar_vz, false);
  2282. if ( IsWidget() )
  2283. SetY(ny + tar_vy, false, true);
  2284. else
  2285. SetY(ny + tar_vy, false);
  2286. }
  2287. if (GetZone()->Grid != nullptr) {
  2288. Cell* newCell = GetZone()->Grid->GetCell(GetX(), GetZ());
  2289. if (newCell != Cell_Info.CurrentCell) {
  2290. GetZone()->Grid->RemoveSpawnFromCell(this);
  2291. GetZone()->Grid->AddSpawn(this, newCell);
  2292. }
  2293. int32 newGrid = GetZone()->Grid->GetGridID(this);
  2294. if (!IsFlying() && newGrid != 0 && newGrid != appearance.pos.grid_id)
  2295. SetPos(&(appearance.pos.grid_id), newGrid);
  2296. }
  2297. }
  2298. }
  2299. return remove_needed;
  2300. }
  2301. void Spawn::CalculateRunningLocation(bool stop){
  2302. if (!stop && (last_location_update + 100) > Timer::GetCurrentTime2())
  2303. return;
  2304. else if (!stop)
  2305. last_location_update = Timer::GetCurrentTime2();
  2306. bool removed = CalculateChange();
  2307. if (stop) {
  2308. //following = false;
  2309. SetPos(&appearance.pos.X2, GetX(), false);
  2310. SetPos(&appearance.pos.Y2, GetY(), false);
  2311. SetPos(&appearance.pos.Z2, GetZ(), false);
  2312. SetPos(&appearance.pos.X3, GetX(), false);
  2313. SetPos(&appearance.pos.Y3, GetY(), false);
  2314. SetPos(&appearance.pos.Z3, GetZ(), false);
  2315. }
  2316. else if (removed && movement_locations && movement_locations->size() > 0) {
  2317. MovementLocation* current_location = movement_locations->at(0);
  2318. if (movement_locations->size() > 1) {
  2319. MovementLocation* data = movement_locations->at(1);
  2320. RunToLocation(current_location->x, current_location->y, current_location->z, data->x, data->y, data->z);
  2321. }
  2322. else
  2323. RunToLocation(current_location->x, current_location->y, current_location->z, 0, 0, 0);
  2324. }
  2325. else if (GetZone() && GetTarget() != NULL && EngagedInCombat())
  2326. {
  2327. if (GetDistance(GetTarget()) > rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())
  2328. {
  2329. if (IsFlying() && CheckLoS(GetTarget()))
  2330. AddRunningLocation(GetTarget()->GetX(), GetTarget()->GetY(), GetTarget()->GetZ(), GetSpeed(), 0, false);
  2331. else
  2332. GetZone()->movementMgr->NavigateTo((Entity*)this, GetTarget()->GetX(), GetTarget()->GetY(), GetTarget()->GetZ());
  2333. }
  2334. else
  2335. ((Entity*)this)->HaltMovement();
  2336. }
  2337. }
  2338. float Spawn::GetFaceTarget(float x, float z) {
  2339. float angle;
  2340. double diff_x = x - GetX();
  2341. double diff_z = z - GetZ();
  2342. //If we're very close to the same spot don't bother changing heading
  2343. if (sqrt(diff_x * diff_x * diff_z * diff_z) < .1) {
  2344. return GetHeading();
  2345. }
  2346. if (diff_z == 0) {
  2347. if (diff_x > 0)
  2348. angle = 90;
  2349. else
  2350. angle = 270;
  2351. }
  2352. else
  2353. angle = ((atan(diff_x / diff_z)) * 180) / 3.14159265358979323846;
  2354. if (angle < 0)
  2355. angle = angle + 360;
  2356. else
  2357. angle = angle + 180;
  2358. if (diff_x < 0)
  2359. angle = angle + 180;
  2360. if (last_heading_angle == angle) return angle;
  2361. return angle;
  2362. }
  2363. void Spawn::FaceTarget(float x, float z){
  2364. float angle;
  2365. double diff_x = x - GetX();
  2366. double diff_z = z - GetZ();
  2367. //If we're very close to the same spot don't bother changing heading
  2368. if (sqrt(diff_x * diff_x * diff_z * diff_z) < .1) {
  2369. return;
  2370. }
  2371. if(diff_z==0){
  2372. if(diff_x > 0)
  2373. angle = 90;
  2374. else
  2375. angle = 270;
  2376. }
  2377. else
  2378. angle = ((atan(diff_x / diff_z)) * 180) / 3.14159265358979323846;
  2379. if(angle < 0)
  2380. angle = angle + 360;
  2381. else
  2382. angle = angle + 180;
  2383. if(diff_x < 0)
  2384. angle = angle + 180;
  2385. if (last_heading_angle == angle) return;
  2386. SetHeading(angle);
  2387. }
  2388. void Spawn::FaceTarget(Spawn* target){
  2389. if(!target)
  2390. return;
  2391. FaceTarget(target->GetX(), target->GetZ());
  2392. if(GetHP() > 0 && target->IsPlayer() && !EngagedInCombat()){
  2393. GetZone()->AddHeadingTimer(this);
  2394. SetTempActionState(0);
  2395. }
  2396. }
  2397. bool Spawn::MeetsSpawnAccessRequirements(Player* player){
  2398. bool ret = false;
  2399. Quest* quest = 0;
  2400. //Check if we meet all quest requirements first..
  2401. m_requiredQuests.readlock(__FUNCTION__, __LINE__);
  2402. if (player && required_quests.size() > 0) {
  2403. map<int32, vector<int16>* >::iterator itr;
  2404. for (itr = required_quests.begin(); itr != required_quests.end(); itr++) {
  2405. player->AddQuestRequiredSpawn(this, itr->first);
  2406. vector<int16>* quest_steps = itr->second;
  2407. for (int32 i = 0; i < quest_steps->size(); i++) {
  2408. quest = player->GetQuest(itr->first);
  2409. if (req_quests_continued_access) {
  2410. if (quest) {
  2411. if (quest->GetQuestStepCompleted(quest_steps->at(i))) {
  2412. ret = true;
  2413. break;
  2414. }
  2415. }
  2416. else if (player->GetCompletedQuest(itr->first)) {
  2417. ret = true;
  2418. break;
  2419. }
  2420. }
  2421. if (quest && quest->QuestStepIsActive(quest_steps->at(i))) {
  2422. ret = true;
  2423. break;
  2424. }
  2425. }
  2426. }
  2427. }
  2428. else
  2429. ret = true;
  2430. m_requiredQuests.releasereadlock(__FUNCTION__, __LINE__);
  2431. if (!ret)
  2432. return ret;
  2433. //Now check if the player meets all history requirements
  2434. m_requiredHistory.readlock(__FUNCTION__, __LINE__);
  2435. if (required_history.size() > 0){
  2436. map<int32, LUAHistory>::iterator itr;
  2437. for (itr = required_history.begin(); itr != required_history.end(); itr++){
  2438. player->AddHistoryRequiredSpawn(this, itr->first);
  2439. LUAHistory* player_history = player->GetLUAHistory(itr->first);
  2440. if (player_history){
  2441. if (player_history->Value != itr->second.Value || player_history->Value2 != itr->second.Value2)
  2442. ret = false;
  2443. }
  2444. else
  2445. ret = false;
  2446. if (!ret)
  2447. break;
  2448. }
  2449. }
  2450. m_requiredHistory.releasereadlock(__FUNCTION__, __LINE__);
  2451. return ret;
  2452. }
  2453. vector<Spawn*>* Spawn::GetSpawnGroup(){
  2454. vector<Spawn*>* ret_list = 0;
  2455. if(spawn_group_list){
  2456. ret_list = new vector<Spawn*>();
  2457. if(MSpawnGroup)
  2458. MSpawnGroup->readlock(__FUNCTION__, __LINE__);
  2459. ret_list->insert(ret_list->begin(), spawn_group_list->begin(), spawn_group_list->end());
  2460. if(MSpawnGroup)
  2461. MSpawnGroup->releasereadlock(__FUNCTION__, __LINE__);
  2462. }
  2463. return ret_list;
  2464. }
  2465. bool Spawn::HasSpawnGroup() {
  2466. return spawn_group_list && spawn_group_list->size() > 0;
  2467. }
  2468. bool Spawn::IsInSpawnGroup(Spawn* spawn) {
  2469. bool ret = false;
  2470. if (HasSpawnGroup() && spawn) {
  2471. vector<Spawn*>::iterator itr;
  2472. for (itr = spawn_group_list->begin(); itr != spawn_group_list->end(); itr++) {
  2473. if ((*itr) == spawn) {
  2474. ret = true;
  2475. break;
  2476. }
  2477. }
  2478. }
  2479. return ret;
  2480. }
  2481. void Spawn::AddSpawnToGroup(Spawn* spawn){
  2482. if(!spawn)
  2483. return;
  2484. if(!spawn_group_list){
  2485. spawn_group_list = new vector<Spawn*>();
  2486. spawn_group_list->push_back(this);
  2487. safe_delete(MSpawnGroup);
  2488. MSpawnGroup = new Mutex();
  2489. MSpawnGroup->SetName("Spawn::MSpawnGroup");
  2490. }
  2491. vector<Spawn*>::iterator itr;
  2492. MSpawnGroup->writelock(__FUNCTION__, __LINE__);
  2493. for(itr = spawn_group_list->begin(); itr != spawn_group_list->end(); itr++){
  2494. if((*itr) == spawn){
  2495. MSpawnGroup->releasewritelock(__FUNCTION__, __LINE__);
  2496. return;
  2497. }
  2498. }
  2499. spawn_group_list->push_back(spawn);
  2500. spawn->SetSpawnGroupList(spawn_group_list, MSpawnGroup);
  2501. MSpawnGroup->releasewritelock(__FUNCTION__, __LINE__);
  2502. }
  2503. void Spawn::SetSpawnGroupList(vector<Spawn*>* list, Mutex* mutex){
  2504. spawn_group_list = list;
  2505. MSpawnGroup = mutex;
  2506. }
  2507. void Spawn::RemoveSpawnFromGroup(bool erase_all){
  2508. SetSpawnGroupID(0);
  2509. bool del = false;
  2510. if(MSpawnGroup){
  2511. MSpawnGroup->writelock(__FUNCTION__, __LINE__);
  2512. if(spawn_group_list){
  2513. vector<Spawn*>::iterator itr;
  2514. Spawn* spawn = 0;
  2515. if(spawn_group_list->size() == 1)
  2516. erase_all = true;
  2517. for(itr = spawn_group_list->begin(); itr != spawn_group_list->end(); itr++){
  2518. spawn = *itr;
  2519. if (spawn) {
  2520. if(!erase_all){
  2521. if(spawn == this){
  2522. spawn_group_list->erase(itr);
  2523. MSpawnGroup->releasewritelock(__FUNCTION__, __LINE__);
  2524. spawn_group_list = 0;
  2525. MSpawnGroup = 0;
  2526. return;
  2527. }
  2528. }
  2529. else{
  2530. if (spawn != this)
  2531. spawn->SetSpawnGroupList(0, 0);
  2532. }
  2533. }
  2534. }
  2535. if (erase_all)
  2536. spawn_group_list->clear();
  2537. del = (spawn_group_list->size() == 0);
  2538. }
  2539. MSpawnGroup->releasewritelock(__FUNCTION__, __LINE__);
  2540. if (del){
  2541. safe_delete(MSpawnGroup);
  2542. safe_delete(spawn_group_list);
  2543. }
  2544. }
  2545. }
  2546. void Spawn::SetSpawnGroupID(int32 id){
  2547. group_id = id;
  2548. }
  2549. int32 Spawn::GetSpawnGroupID(){
  2550. return group_id;
  2551. }
  2552. void Spawn::AddChangedZoneSpawn(){
  2553. if(send_spawn_changes && GetZone())
  2554. GetZone()->AddChangedSpawn(this);
  2555. }
  2556. void Spawn::RemoveSpawnAccess(Spawn* spawn) {
  2557. if (allowed_access.count(spawn->GetID()) > 0) {
  2558. allowed_access.erase(spawn->GetID());
  2559. GetZone()->HidePrivateSpawn(this);
  2560. }
  2561. }
  2562. void Spawn::SetFollowTarget(Spawn* spawn, int32 follow_distance) {
  2563. if (spawn && spawn != this) {
  2564. m_followTarget = spawn->GetID();
  2565. m_followDistance = follow_distance;
  2566. }
  2567. else {
  2568. m_followTarget = 0;
  2569. if (following)
  2570. following = false;
  2571. m_followDistance = 0;
  2572. }
  2573. }
  2574. void Spawn::AddTempVariable(string var, string val) {
  2575. m_tempVariableTypes[var] = 5;
  2576. m_tempVariables[var] = val;
  2577. }
  2578. void Spawn::AddTempVariable(string var, Spawn* val) {
  2579. m_tempVariableTypes[var] = 1;
  2580. m_tempVariableSpawn[var] = val->GetID();
  2581. }
  2582. void Spawn::AddTempVariable(string var, ZoneServer* val) {
  2583. m_tempVariableTypes[var] = 2;
  2584. m_tempVariableZone[var] = val;
  2585. }
  2586. void Spawn::AddTempVariable(string var, Item* val) {
  2587. m_tempVariableTypes[var] = 3;
  2588. m_tempVariableItem[var] = val;
  2589. }
  2590. void Spawn::AddTempVariable(string var, Quest* val) {
  2591. m_tempVariableTypes[var] = 4;
  2592. m_tempVariableQuest[var] = val;
  2593. }
  2594. string Spawn::GetTempVariable(string var) {
  2595. string ret = "";
  2596. if (m_tempVariables.count(var) > 0)
  2597. ret = m_tempVariables[var];
  2598. return ret;
  2599. }
  2600. Spawn* Spawn::GetTempVariableSpawn(string var) {
  2601. Spawn* ret = 0;
  2602. if (m_tempVariableSpawn.count(var) > 0)
  2603. ret = GetZone()->GetSpawnByID(m_tempVariableSpawn[var]);
  2604. return ret;
  2605. }
  2606. ZoneServer* Spawn::GetTempVariableZone(string var) {
  2607. ZoneServer* ret = 0;
  2608. if (m_tempVariableZone.count(var) > 0)
  2609. ret = m_tempVariableZone[var];
  2610. return ret;
  2611. }
  2612. Item* Spawn::GetTempVariableItem(string var) {
  2613. Item* ret = 0;
  2614. if (m_tempVariableItem.count(var) > 0)
  2615. ret = m_tempVariableItem[var];
  2616. return ret;
  2617. }
  2618. Quest* Spawn::GetTempVariableQuest(string var) {
  2619. Quest* ret = 0;
  2620. if (m_tempVariableQuest.count(var) > 0)
  2621. ret = m_tempVariableQuest[var];
  2622. return ret;
  2623. }
  2624. int8 Spawn::GetTempVariableType(string var) {
  2625. int8 ret = 0;
  2626. if (m_tempVariableTypes.count(var) > 0)
  2627. ret = m_tempVariableTypes[var];
  2628. return ret;
  2629. }
  2630. void Spawn::DeleteTempVariable(string var) {
  2631. int8 type = GetTempVariableType(var);
  2632. switch (type) {
  2633. case 1:
  2634. m_tempVariableSpawn.erase(var);
  2635. break;
  2636. case 2:
  2637. m_tempVariableZone.erase(var);
  2638. break;
  2639. case 3:
  2640. m_tempVariableItem.erase(var);
  2641. break;
  2642. case 4:
  2643. m_tempVariableQuest.erase(var);
  2644. break;
  2645. case 5:
  2646. m_tempVariables.erase(var);
  2647. break;
  2648. }
  2649. m_tempVariableTypes.erase(var);
  2650. }
  2651. Spawn* Spawn::GetRunningTo() {
  2652. return GetZone()->GetSpawnByID(running_to);
  2653. }
  2654. Spawn* Spawn::GetFollowTarget() {
  2655. return GetZone()->GetSpawnByID(m_followTarget);
  2656. }
  2657. void Spawn::CopySpawnAppearance(Spawn* spawn){
  2658. if (!spawn)
  2659. return;
  2660. //This function copies the appearace of the provided spawn to this one
  2661. if (spawn->IsEntity() && IsEntity()){
  2662. memcpy(&((Entity*)this)->features, &((Entity*)spawn)->features, sizeof(CharFeatures));
  2663. memcpy(&((Entity*)this)->equipment, &((Entity*)spawn)->equipment, sizeof(EQ2_Equipment));
  2664. }
  2665. SetSize(spawn->GetSize());
  2666. SetModelType(spawn->GetModelType());
  2667. }
  2668. void Spawn::SetY(float y, bool updateFlags, bool disableYMapCheck)
  2669. {
  2670. SetPos(&appearance.pos.Y, y, updateFlags);
  2671. if (!disableYMapCheck)
  2672. FixZ();
  2673. }
  2674. float Spawn::FindDestGroundZ(glm::vec3 dest, float z_offset)
  2675. {
  2676. float best_z = BEST_Z_INVALID;
  2677. if (GetZone() != nullptr && GetZone()->zonemap != nullptr)
  2678. {
  2679. dest.z += z_offset;
  2680. best_z = zone->zonemap->FindBestZ(dest, nullptr);
  2681. }
  2682. return best_z;
  2683. }
  2684. float Spawn::GetFixedZ(const glm::vec3& destination, int32 z_find_offset) {
  2685. BenchTimer timer;
  2686. timer.reset();
  2687. float new_z = destination.z;
  2688. if (GetZone() != nullptr && zone->zonemap != nullptr) {
  2689. /* if (flymode == GravityBehavior::Flying)
  2690. return new_z;
  2691. */
  2692. /* if (zone->HasWaterMap() && zone->watermap->InLiquid(glm::vec3(m_Position)))
  2693. return new_z;
  2694. */
  2695. /*
  2696. * Any more than 5 in the offset makes NPC's hop/snap to ceiling in small corridors
  2697. */
  2698. new_z = this->FindDestGroundZ(destination, z_find_offset);
  2699. if (new_z != BEST_Z_INVALID) {
  2700. if (new_z < -2000) {
  2701. new_z = GetY();
  2702. }
  2703. }
  2704. auto duration = timer.elapsed();
  2705. LogWrite(MAP__DEBUG, 0, "Map", "Mob::GetFixedZ() ([{%s}]) returned [{%f}] at [{%f}], [{%f}], [{%f}] - Took [{%f}]",
  2706. this->GetName(),
  2707. new_z,
  2708. destination.x,
  2709. destination.y,
  2710. destination.z,
  2711. duration);
  2712. }
  2713. return new_z;
  2714. }
  2715. void Spawn::FixZ(bool forceUpdate) {
  2716. if (IsPlayer() || IsFlying() || !GetZone() || (IsObject() && GetZone()->GetInstanceType() == Instance_Type::PERSONAL_HOUSE_INSTANCE)) {
  2717. return;
  2718. }
  2719. /*
  2720. if (flymode == GravityBehavior::Flying) {
  2721. return;
  2722. }*/
  2723. /*
  2724. if (zone->watermap && zone->watermap->InLiquid(m_Position)) {
  2725. return;
  2726. }*/
  2727. glm::vec3 current_loc(GetX(), GetZ(), GetY());
  2728. float new_z = GetFixedZ(current_loc, 1);
  2729. if (new_z == GetY())
  2730. return;
  2731. if ((new_z > -2000) && new_z != BEST_Z_INVALID) {
  2732. SetY(new_z, forceUpdate, true);
  2733. }
  2734. else {
  2735. LogWrite(MAP__DEBUG, 0, "Map", "[{%s}] is failing to find Z [{%f}]", this->GetName(), std::abs(GetY() - new_z));
  2736. }
  2737. }
  2738. bool Spawn::CheckLoS(Spawn* target)
  2739. {
  2740. glm::vec3 targpos(target->GetX(), target->GetZ(), target->GetY()+1.0f);
  2741. glm::vec3 pos(GetX(), GetZ(), GetY()+1.0f);
  2742. return CheckLoS(pos, targpos);
  2743. }
  2744. bool Spawn::CheckLoS(glm::vec3 myloc, glm::vec3 oloc)
  2745. {
  2746. ZoneServer* zone = GetZone();
  2747. if (zone == NULL || zone->zonemap == NULL || !zone->zonemap->IsMapLoaded())
  2748. return true;
  2749. else
  2750. return zone->zonemap->CheckLoS(myloc, oloc);
  2751. return false;
  2752. }
  2753. void Spawn::CalculateNewFearpoint()
  2754. {
  2755. if (GetZone() && GetZone()->pathing) {
  2756. auto Node = zone->pathing->GetRandomLocation(glm::vec3(GetX(), GetZ(), GetY()));
  2757. if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) {
  2758. AddRunningLocation(Node.x, Node.y, Node.z, GetSpeed(), 0, true, true, "", true);
  2759. }
  2760. }
  2761. }
  2762. void Spawn::CheckProximities()
  2763. {
  2764. if (!has_spawn_proximities)
  2765. return;
  2766. if (spawn_proximities.size() > 0)
  2767. {
  2768. MutexList<SpawnProximity*>::iterator itr = spawn_proximities.begin();
  2769. while (itr.Next()) {
  2770. SpawnProximity* prox = itr.value;
  2771. map<int32, bool>::iterator spawnsItr;
  2772. for (spawnsItr = prox->spawns_in_proximity.begin(); spawnsItr != prox->spawns_in_proximity.end(); spawnsItr++) {
  2773. Spawn* tmpSpawn = 0;
  2774. if (spawnsItr->first &&
  2775. ((prox->spawn_type == SPAWNPROXIMITY_DATABASE_ID && (tmpSpawn = GetZone()->GetSpawnByDatabaseID(spawnsItr->first)) != 0) ||
  2776. (prox->spawn_type == SPAWNPROXIMITY_LOCATION_ID && (tmpSpawn = GetZone()->GetSpawnByLocationID(spawnsItr->first)) != 0)))
  2777. {
  2778. if (!spawnsItr->second && tmpSpawn->GetDistance(this) <= prox->distance)
  2779. {
  2780. if (prox->in_range_lua_function.size() > 0)
  2781. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_CUSTOM, tmpSpawn, prox->in_range_lua_function.c_str());
  2782. spawnsItr->second = true;
  2783. }
  2784. else if (spawnsItr->second && tmpSpawn->GetDistance(this) > prox->distance)
  2785. {
  2786. if (prox->leaving_range_lua_function.size() > 0)
  2787. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_CUSTOM, tmpSpawn, prox->leaving_range_lua_function.c_str());
  2788. spawnsItr->second = false;
  2789. }
  2790. }
  2791. }
  2792. }
  2793. }
  2794. }
  2795. void Spawn::AddSpawnToProximity(int32 spawnValue, SpawnProximityType type)
  2796. {
  2797. if (!has_spawn_proximities)
  2798. return;
  2799. if (spawn_proximities.size() > 0)
  2800. {
  2801. MutexList<SpawnProximity*>::iterator itr = spawn_proximities.begin();
  2802. while (itr.Next()) {
  2803. SpawnProximity* prox = itr->value;
  2804. if (prox->spawn_value == spawnValue && prox->spawn_type == type)
  2805. prox->spawns_in_proximity.insert(make_pair(spawnValue, false));
  2806. }
  2807. }
  2808. }
  2809. void Spawn::RemoveSpawnFromProximity(int32 spawnValue, SpawnProximityType type)
  2810. {
  2811. if (!has_spawn_proximities)
  2812. return;
  2813. if (spawn_proximities.size() > 0)
  2814. {
  2815. MutexList<SpawnProximity*>::iterator itr = spawn_proximities.begin();
  2816. while (itr.Next()) {
  2817. SpawnProximity* prox = itr->value;
  2818. if (prox->spawn_value == spawnValue && prox->spawn_type == type &&
  2819. prox->spawns_in_proximity.count(spawnValue) > 0)
  2820. prox->spawns_in_proximity.erase(spawnValue);
  2821. }
  2822. }
  2823. }
  2824. void Spawn::AddPrimaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual, bool defaultDenyList, Player* player) {
  2825. EntityCommand* cmd = FindEntityCommand(string(command), true);
  2826. bool newCommand = false;
  2827. if (!cmd)
  2828. {
  2829. newCommand = true;
  2830. cmd = CreateEntityCommand(name, distance, command, error_text, cast_time, spell_visual, !defaultDenyList);
  2831. }
  2832. if (defaultDenyList)
  2833. SetPermissionToEntityCommand(cmd, player, true);
  2834. if (newCommand)
  2835. primary_command_list.push_back(cmd);
  2836. }
  2837. void Spawn::RemovePrimaryEntityCommand(const char* command) {
  2838. vector<EntityCommand*>::iterator itr;
  2839. string tmpStr(command);
  2840. for (itr = primary_command_list.begin(); itr != primary_command_list.end(); itr++) {
  2841. EntityCommand* cmd = *itr;
  2842. if (cmd->command.compare(tmpStr) == 0)
  2843. {
  2844. primary_command_list.erase(itr);
  2845. delete cmd;
  2846. break;
  2847. }
  2848. }
  2849. }
  2850. bool Spawn::SetPermissionToEntityCommand(EntityCommand* command, Player* player, bool permissionValue)
  2851. {
  2852. if (player != NULL)
  2853. {
  2854. map<int32, bool>::iterator itr = command->allow_or_deny.find(player->GetCharacterID());
  2855. if (itr == command->allow_or_deny.end())
  2856. command->allow_or_deny.insert(make_pair(player->GetCharacterID(), permissionValue));
  2857. else if (itr->second != permissionValue)
  2858. itr->second = permissionValue;
  2859. return true;
  2860. }
  2861. return false;
  2862. }