Spawn.cpp 98 KB

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