NPC.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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 "NPC.h"
  17. #include "WorldDatabase.h"
  18. #include <math.h>
  19. #include "client.h"
  20. #include "World.h"
  21. #include "races.h"
  22. #include "../common/Log.h"
  23. #include "NPC_AI.h"
  24. #include "Appearances.h"
  25. #include "SpellProcess.h"
  26. #include "Skills.h"
  27. #include "Rules/Rules.h"
  28. extern MasterSpellList master_spell_list;
  29. extern ConfigReader configReader;
  30. extern WorldDatabase database;
  31. extern World world;
  32. extern Races races;
  33. extern Appearance master_appearance_list;
  34. extern MasterSkillList master_skill_list;
  35. extern RuleManager rule_manager;
  36. NPC::NPC(){
  37. Initialize();
  38. if (GetMaxSpeed() > 0)
  39. SetSpeed(GetMaxSpeed());
  40. }
  41. NPC::NPC(NPC* old_npc){
  42. Initialize();
  43. if(old_npc){
  44. if(old_npc->GetSizeOffset() > 0){
  45. int8 offset = old_npc->GetSizeOffset()+1;
  46. sint32 tmp_size = old_npc->size + (rand()%offset - rand()%offset);
  47. if(tmp_size < 0)
  48. tmp_size = 1;
  49. else if(tmp_size >= 0xFFFF)
  50. tmp_size = 0xFFFF;
  51. size = (int16)tmp_size;
  52. }
  53. else
  54. size = old_npc->size;
  55. SetCollector(old_npc->IsCollector());
  56. SetMerchantID(old_npc->GetMerchantID());
  57. SetMerchantType(old_npc->GetMerchantType());
  58. SetMerchantLevelRange(old_npc->GetMerchantMinLevel(), old_npc->GetMerchantMaxLevel());
  59. SetPrimaryCommands(&old_npc->primary_command_list);
  60. SetSecondaryCommands(&old_npc->secondary_command_list);
  61. appearance_id = old_npc->appearance_id;
  62. database_id = old_npc->database_id;
  63. primary_command_list_id = old_npc->primary_command_list_id;
  64. secondary_command_list_id = old_npc->secondary_command_list_id;
  65. this->SetInfoStruct(old_npc->GetInfoStruct());
  66. //memcpy(GetInfoStruct(), old_npc->GetInfoStruct(), sizeof(InfoStruct));
  67. memcpy(&appearance, &old_npc->appearance, sizeof(AppearanceData));
  68. memcpy(&features, &old_npc->features, sizeof(CharFeatures));
  69. memcpy(&equipment, &old_npc->equipment, sizeof(EQ2_Equipment));
  70. if(appearance.min_level < appearance.max_level)
  71. SetLevel(appearance.min_level + rand()%((appearance.max_level - appearance.min_level)+1));
  72. target = 0;
  73. SetTotalHPBase(old_npc->GetTotalHPBase());
  74. SetTotalPowerBase(old_npc->GetTotalPowerBase());
  75. faction_id = old_npc->faction_id;
  76. movement_interrupted = false;
  77. old_npc->SetQuestsRequired(this);
  78. SetTransporterID(old_npc->GetTransporterID());
  79. SetAIStrategy(old_npc->GetAIStrategy());
  80. SetPrimarySpellList(old_npc->GetPrimarySpellList());
  81. SetSecondarySpellList(old_npc->GetSecondarySpellList());
  82. SetPrimarySkillList(old_npc->GetPrimarySkillList());
  83. SetSecondarySkillList(old_npc->GetSecondarySkillList());
  84. SetEquipmentListID(old_npc->GetEquipmentListID());
  85. SetAggroRadius(old_npc->GetBaseAggroRadius());
  86. SetCastPercentage(old_npc->GetCastPercentage());
  87. SetRandomize(old_npc->GetRandomize());
  88. if(appearance.randomize > 0)
  89. Randomize(this, appearance.randomize);
  90. CalculateBonuses();
  91. SetHP(GetTotalHP());
  92. SetPower(GetTotalPower());
  93. UpdateWeapons();
  94. SetSoundsDisabled(old_npc->IsSoundsDisabled());
  95. SetFlyingCreature();
  96. SetWaterCreature();
  97. SetOmittedByDBFlag(old_npc->IsOmittedByDBFlag());
  98. SetLootTier(old_npc->GetLootTier());
  99. SetLootDropType(old_npc->GetLootDropType());
  100. has_spells = old_npc->HasSpells();
  101. SetScaredByStrongPlayers(old_npc->IsScaredByStrongPlayers());
  102. }
  103. }
  104. NPC::~NPC(){
  105. ResetMovement();
  106. if(skills){
  107. map<string, Skill*>::iterator skill_itr;
  108. for(skill_itr = skills->begin(); skill_itr != skills->end(); skill_itr++){
  109. safe_delete(skill_itr->second);
  110. }
  111. safe_delete(skills);
  112. }
  113. if(spells) {
  114. vector<NPCSpell*>::iterator itr;
  115. for(itr = spells->begin(); itr != spells->end(); itr++){
  116. safe_delete((*itr));
  117. }
  118. spells->clear();
  119. }
  120. safe_delete(spells);
  121. MutexMap<int32, SkillBonus*>::iterator sb_itr = skill_bonus_list.begin();
  122. while (sb_itr.Next())
  123. RemoveSkillBonus(sb_itr.first);
  124. safe_delete(runback);
  125. safe_delete(m_brain);
  126. }
  127. void NPC::Initialize(){
  128. ai_strategy = 0;
  129. attack_type = 0;
  130. movement_index = 0;
  131. resume_movement = true;
  132. movement_start_time = 0;
  133. spawn_type = 2;
  134. movement_interrupted = false;
  135. attack_resume_needed = false;
  136. MMovementLoop.SetName("NPC::MMovementLoop");
  137. last_movement_update = Timer::GetCurrentTime2();
  138. aggro_radius = 0.0f;
  139. base_aggro_radius = 0.0f;
  140. skills = 0;
  141. spells = 0;
  142. runback = 0;
  143. m_brain = new ::Brain(this);
  144. MBrain.SetName("NPC::m_brain");
  145. m_runningBack = false;
  146. m_runbackHeadingDir1 = m_runbackHeadingDir2 = 0;
  147. following = false;
  148. SetFollowTarget(0);
  149. m_petDismissing = false;
  150. m_ShardID = 0;
  151. m_ShardCharID = 0;
  152. m_ShardCreatedTimestamp = 0;
  153. m_call_runback = false;
  154. has_spells = false;
  155. cast_on_aggro_completed = false;
  156. }
  157. EQ2Packet* NPC::serialize(Player* player, int16 version){
  158. return spawn_serialize(player, version);
  159. }
  160. void NPC::SetSkills(map<string, Skill*>* in_skills){
  161. if (skills) {
  162. map<string, Skill*>::iterator skill_itr;
  163. for(skill_itr = skills->begin(); skill_itr != skills->end(); skill_itr++){
  164. safe_delete(skill_itr->second);
  165. }
  166. safe_delete(skills);
  167. }
  168. skills = in_skills;
  169. }
  170. void NPC::SetSpells(vector<NPCSpell*>* in_spells){
  171. for(int i=0;i<CAST_TYPE::MAX_CAST_TYPES;i++) {
  172. cast_on_spells[i].clear();
  173. }
  174. if(spells) {
  175. vector<NPCSpell*>::iterator itr;
  176. for(itr = spells->begin(); itr != spells->end(); itr++){
  177. safe_delete((*itr));
  178. }
  179. }
  180. safe_delete(spells);
  181. spells = in_spells;
  182. if(spells && spells->size() > 0) {
  183. has_spells = true;
  184. vector<NPCSpell*>::iterator itr;
  185. for(itr = spells->begin(); itr != spells->end();){
  186. if((*itr)->cast_on_spawn) {
  187. cast_on_spells[CAST_TYPE::CAST_ON_SPAWN].push_back((*itr));
  188. itr = spells->erase(itr); // we don't keep on the master list
  189. continue;
  190. }
  191. if((*itr)->cast_on_initial_aggro) {
  192. cast_on_spells[CAST_TYPE::CAST_ON_AGGRO].push_back((*itr));
  193. itr = spells->erase(itr); // we don't keep on the master list
  194. continue;
  195. }
  196. // didn't hit a continue case, iterate
  197. itr++;
  198. }
  199. }
  200. else {
  201. has_spells = false;
  202. }
  203. }
  204. void NPC::SetRunbackLocation(float x, float y, float z, int32 gridid, bool set_hp_runback){
  205. safe_delete(runback);
  206. runback = new MovementLocation;
  207. runback->x = x;
  208. runback->y = y;
  209. runback->z = z;
  210. runback->gridid = gridid;
  211. runback->stage = 0;
  212. runback->reset_hp_on_runback = set_hp_runback;
  213. }
  214. MovementLocation* NPC::GetRunbackLocation(){
  215. return runback;
  216. }
  217. float NPC::GetRunbackDistance(){
  218. if(!runback)
  219. return 0;
  220. return GetDistance(runback->x, runback->y, runback->z);
  221. }
  222. void NPC::Runback(float distance, bool stopFollowing){
  223. if(!runback)
  224. return;
  225. if ( distance == 0.0f )
  226. distance = GetRunbackDistance(); // gotta make sure its true, lua doesn't send the distance
  227. if(stopFollowing)
  228. following = false;
  229. if (!m_runningBack)
  230. {
  231. ClearRunningLocations();
  232. GetZone()->movementMgr->StopNavigation((Entity*)this);
  233. }
  234. m_runningBack = true;
  235. SetSpeed(GetMaxSpeed()*2);
  236. if (CheckLoS(glm::vec3(runback->x, runback->z, runback->y + 1.0f), glm::vec3(GetX(), GetZ(), GetY() + 1.0f)))
  237. {
  238. FaceTarget(runback->x, runback->z);
  239. ClearRunningLocations();
  240. GetZone()->movementMgr->DisruptNavigation((Entity*)this);
  241. if (GetRunbackLocation()->gridid > 0)
  242. SetLocation(GetRunbackLocation()->gridid);
  243. AddRunningLocation(runback->x, runback->y, runback->z, GetSpeed(), 0, true, true, "", true);
  244. }
  245. else
  246. GetZone()->movementMgr->NavigateTo((Entity*)this, runback->x, runback->y, runback->z);
  247. //AddRunningLocation(runback->x, runback->y, runback->z, GetSpeed(), 0, false);
  248. last_movement_update = Timer::GetCurrentTime2();
  249. }
  250. void NPC::ClearRunback(){
  251. safe_delete(runback);
  252. m_runningBack = false;
  253. m_runbackHeadingDir1 = m_runbackHeadingDir2 = 0;
  254. resume_movement = true;
  255. NeedsToResumeMovement(false);
  256. }
  257. void NPC::StartRunback(bool reset_hp_on_runback)
  258. {
  259. if(GetRunbackLocation())
  260. return;
  261. SetRunbackLocation(GetX(), GetY(), GetZ(), GetLocation(), reset_hp_on_runback);
  262. m_runbackHeadingDir1 = appearance.pos.Dir1;
  263. m_runbackHeadingDir2 = appearance.pos.Dir2;
  264. }
  265. bool NPC::PauseMovement(int32 period_of_time_ms)
  266. {
  267. if(period_of_time_ms < 1)
  268. period_of_time_ms = 1;
  269. if(HasMovementLoop() || HasMovementLocations())
  270. StartRunback();
  271. RunToLocation(GetX(),GetY(),GetZ());
  272. pause_timer.Start(period_of_time_ms, true);
  273. return true;
  274. }
  275. bool NPC::IsPauseMovementTimerActive()
  276. {
  277. if(pause_timer.Check())
  278. {
  279. pause_timer.Disable();
  280. m_call_runback = true;
  281. }
  282. return pause_timer.Enabled();
  283. }
  284. void NPC::InCombat(bool val){
  285. if (in_combat == val)
  286. return;
  287. if(in_combat == false && val && GetZone()){
  288. LogWrite(NPC__DEBUG, 3, "NPC", "'%s' engaged in combat with '%s'", this->GetName(), ( GetTarget() ) ? GetTarget()->GetName() : "Unknown" );
  289. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_ATTACKED, GetTarget());
  290. SetTempActionState(0); // disable action states in combat
  291. }
  292. if(!in_combat && val){
  293. // if not a pet and no current run back location set then set one to the current location
  294. bool hadRunback = (GetRunbackLocation() != nullptr);
  295. if(hadRunback) {
  296. pause_timer.Disable();
  297. if(!GetRunbackLocation()->reset_hp_on_runback) // if we aren't resetting hp it isn't a real reset point, just face target swings
  298. ClearRunback();
  299. }
  300. if(!IsPet()) {
  301. StartRunback(true);
  302. }
  303. }
  304. int8 ruleAutoLockEncounter = rule_manager.GetGlobalRule(R_World, AutoLockEncounter)->GetInt8();
  305. in_combat = val;
  306. if(val){
  307. LogWrite(NPC__DEBUG, 3, "NPC", "'%s' engaged in combat with '%s'", this->GetName(), ( GetTarget() ) ? GetTarget()->GetName() : "Unknown" );
  308. if(ruleAutoLockEncounter) {
  309. SetLockedNoLoot(ENCOUNTER_STATE_LOCKED);
  310. }
  311. AddIconValue(64);
  312. // In combat so lets set the NPC's speed to its max speed
  313. if (GetMaxSpeed() > 0)
  314. SetSpeed(GetMaxSpeed());
  315. }
  316. else{
  317. SetLockedNoLoot(ENCOUNTER_STATE_AVAILABLE);
  318. RemoveIconValue(64);
  319. if (GetHP() > 0){
  320. SetTempActionState(-1); //re-enable action states on exiting combat
  321. GetZone()->CallSpawnScript(this, SPAWN_SCRIPT_COMBAT_RESET);
  322. // Stop all HO's attached to this NPC
  323. GetZone()->GetSpellProcess()->KillHOBySpawnID(GetID());
  324. }
  325. }
  326. if(!MovementInterrupted() && val && GetSpeed() > 0 && movement_loop.size() > 0){
  327. CalculateRunningLocation(true);
  328. }
  329. MovementInterrupted(val);
  330. }
  331. bool NPC::HandleUse(Client* client, string type){
  332. if(!client || type.length() == 0 || (appearance.show_command_icon == 0 && appearance.display_hand_icon == 0))
  333. return false;
  334. EntityCommand* entity_command = FindEntityCommand(type);
  335. if (entity_command) {
  336. client->GetCurrentZone()->ProcessEntityCommand(entity_command, client->GetPlayer(), client->GetPlayer()->GetTarget());
  337. return true;
  338. }
  339. return false;
  340. /*Spell* spell = master_spell_list.GetSpellByName((char*)type.c_str());
  341. if(spell)
  342. client->GetCurrentZone()->ProcessSpell(spell, client->GetPlayer(), client->GetPlayer()->GetTarget());
  343. else if(GetSpawnScript())
  344. client->GetCurrentZone()->CallSpawnScript(this, SPAWN_SCRIPT_CUSTOM, client->GetPlayer(), (char*)type.c_str());
  345. else
  346. return false;
  347. return true;*/
  348. }
  349. bool NPC::CheckSameAppearance(string name, int16 id)
  350. {
  351. // need to iterate through master_appearance_list finding if id contains name
  352. return true;
  353. }
  354. void NPC::Randomize(NPC* npc, int32 flags)
  355. {
  356. int8 random = 0;
  357. int8 min_val = 0;
  358. int8 max_val = 255;
  359. /* We need to check if gender is going to be randomized first because if the race is going to be
  360. * randomized, we need to know its gender so we can choose the proper model.
  361. * We also need to make sure the model gets set properly if the player chooses to randomize the gender
  362. * and not the race. */
  363. int8 old_gender = npc->GetGender();
  364. if (flags & RANDOMIZE_GENDER)
  365. {
  366. random = MakeRandomInt(1, 2);
  367. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Gender: %i", random);
  368. npc->SetGender(random);
  369. }
  370. if ((flags & RANDOMIZE_RACE) || (flags & RANDOMIZE_GENDER && old_gender != npc->GetGender()) || (flags & RANDOMIZE_MODEL_TYPE))
  371. {
  372. string race_string = "";
  373. int8 gender = npc->GetGender();
  374. if (gender == 1 || gender == 2)
  375. {
  376. if (flags & RANDOMIZE_RACE)
  377. {
  378. if(npc->GetAlignment() == 1) // Good
  379. random = races.GetRaceNameGood();
  380. else if(npc->GetAlignment() < 0) // Evil
  381. random = races.GetRaceNameEvil();
  382. else // All
  383. random = MakeRandomInt(0, 20);
  384. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Race: %s (%i)", races.GetRaceNameCase(random), random);
  385. npc->SetRace(random);
  386. }
  387. switch (npc->GetRace())
  388. {
  389. case BARBARIAN:
  390. // JA: If randomize has "4" (model) and race=0, barbarians show up in place of the real models.
  391. // Started working on a solution (CheckSameAppearance) but cannot get it to work yet.
  392. // Solution for now is to not randomize models for race=0. Set to race=255, or turn off model randomize
  393. race_string = "/barbarian/barbarian";
  394. break;
  395. case DARK_ELF:
  396. race_string = "/darkelf/darkelf";
  397. break;
  398. case DWARF:
  399. race_string = "/dwarf/dwarf";
  400. break;
  401. case ERUDITE:
  402. race_string = "/erudite/erudite";
  403. break;
  404. case FROGLOK:
  405. race_string = "/froglok/froglok";
  406. break;
  407. case GNOME:
  408. race_string = "/gnome/gnome";
  409. break;
  410. case HALF_ELF:
  411. race_string = "/halfelf/halfelf";
  412. break;
  413. case HALFLING:
  414. race_string = "/halfling/halfling";
  415. break;
  416. case HIGH_ELF:
  417. race_string = "/highelf/highelf";
  418. break;
  419. case HUMAN:
  420. race_string = "/human/human";
  421. break;
  422. case IKSAR:
  423. race_string = "/iksar/iksar";
  424. break;
  425. case KERRA:
  426. race_string = "/kerra/kerra";
  427. break;
  428. case OGRE:
  429. race_string = "/ogre/ogre";
  430. break;
  431. case RATONGA:
  432. race_string = "/ratonga/ratonga";
  433. break;
  434. case TROLL:
  435. race_string = "/troll/troll";
  436. break;
  437. case WOOD_ELF:
  438. race_string = "/woodelf/woodelf";
  439. break;
  440. case FAE:
  441. race_string = "/fae/fae_light";
  442. break;
  443. case ARASAI:
  444. race_string = "/fae/fae_dark";
  445. break;
  446. case SARNAK:
  447. gender == 1 ? race_string = "01/sarnak_male/sarnak" : race_string = "01/sarnak_female/sarnak";
  448. break;
  449. case VAMPIRE:
  450. race_string = "/vampire/vampire";
  451. break;
  452. case AERAKYN:
  453. race_string = "/aerakyn/aerakyn";
  454. break;
  455. }
  456. if (race_string.length() > 0)
  457. {
  458. string gender_string;
  459. gender == 1 ? gender_string = "male" : gender_string = "female";
  460. vector<int16>* id_list = database.GetAppearanceIDsLikeName("ec/pc" + race_string + "_" + gender_string);
  461. if (id_list)
  462. {
  463. int32 index = MakeRandomInt(0, id_list->size() - 1);
  464. npc->SetModelType(id_list->at(index));
  465. npc->SetSogaModelType(id_list->at(index));
  466. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Model Type: %i", npc->GetModelType());
  467. int16 wing_type = 0;
  468. if (npc->GetRace() == FAE)
  469. {
  470. vector<int16>* id_list_wings = database.GetAppearanceIDsLikeName("ec/pc/fae_wings/fae_wing");
  471. if (id_list_wings) {
  472. wing_type = id_list_wings->at(MakeRandomInt(0, id_list_wings->size() - 1));
  473. safe_delete(id_list_wings);
  474. }
  475. }
  476. else if (npc->GetRace() == ARASAI)
  477. {
  478. vector<int16>* id_list_wings = database.GetAppearanceIDsLikeName("ec/pc/fae_wings/fae_d_wing");
  479. if (id_list_wings) {
  480. wing_type = id_list_wings->at(MakeRandomInt(0, id_list_wings->size() - 1));
  481. safe_delete(id_list_wings);
  482. }
  483. }
  484. else if (npc->GetRace() == AERAKYN)
  485. {
  486. vector<int16>* id_list_wings = database.GetAppearanceIDsLikeName("ec/pc/aerakyn/aerakyn_male_wings");
  487. if (id_list_wings) {
  488. wing_type = id_list_wings->at(MakeRandomInt(0, id_list_wings->size() - 1));
  489. safe_delete(id_list_wings);
  490. }
  491. }
  492. if (wing_type > 0)
  493. {
  494. EQ2_Color color1;
  495. EQ2_Color color2;
  496. color1.red = MakeRandomInt(0, 255);
  497. color1.green = MakeRandomInt(0, 255);
  498. color1.blue = MakeRandomInt(0, 255);
  499. color2.red = MakeRandomInt(0, 255);
  500. color2.green = MakeRandomInt(0, 255);
  501. color2.blue = MakeRandomInt(0, 255);
  502. npc->SetWingColor1(color1);
  503. npc->SetWingColor2(color2);
  504. }
  505. npc->SetWingType(wing_type);
  506. safe_delete(id_list);
  507. }
  508. }
  509. }
  510. }
  511. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE) {
  512. vector<int16>* id_list = database.GetAppearanceIDsLikeName("accessories/hair/face");
  513. if (id_list) {
  514. int32 index = MakeRandomInt(0, id_list->size() - 1);
  515. npc->SetFacialHairType(id_list->at(index));
  516. npc->SetSogaFacialHairType(id_list->at(index));
  517. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Facial Hair: %i", npc->GetFacialHairType());
  518. safe_delete(id_list);
  519. }
  520. }
  521. if (flags & RANDOMIZE_HAIR_TYPE) {
  522. vector<int16>* id_list = database.GetAppearanceIDsLikeName("accessories/hair/hair");
  523. if (id_list) {
  524. int32 index = MakeRandomInt(0, id_list->size() - 1);
  525. npc->SetHairType(id_list->at(index));
  526. npc->SetSogaHairType(id_list->at(index));
  527. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Hair: %i", npc->GetHairType());
  528. safe_delete(id_list);
  529. }
  530. }
  531. if (flags & RANDOMIZE_WING_TYPE) {
  532. int16 wing_type = 0;
  533. if (npc->GetRace() == FAE) {
  534. vector<int16>* id_list_wings = database.GetAppearanceIDsLikeName("ec/pc/fae_wings/fae_wing");
  535. if (id_list_wings) {
  536. wing_type = id_list_wings->at(MakeRandomInt(0, id_list_wings->size() - 1));
  537. safe_delete(id_list_wings);
  538. }
  539. }
  540. else if (npc->GetRace() == ARASAI) {
  541. vector<int16>* id_list_wings = database.GetAppearanceIDsLikeName("ec/pc/fae_wings/fae_d_wing");
  542. if (id_list_wings) {
  543. wing_type = id_list_wings->at(MakeRandomInt(0, id_list_wings->size() - 1));
  544. safe_delete(id_list_wings);
  545. }
  546. }
  547. else if (npc->GetRace() == AERAKYN)
  548. {
  549. vector<int16>* id_list_wings = database.GetAppearanceIDsLikeName("ec/pc/aerakyn/aerakyn_male_wings");
  550. if (id_list_wings) {
  551. wing_type = id_list_wings->at(MakeRandomInt(0, id_list_wings->size() - 1));
  552. safe_delete(id_list_wings);
  553. }
  554. }
  555. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Wing Type: %i", wing_type);
  556. npc->SetWingType(wing_type);
  557. }
  558. if (flags & RANDOMIZE_CHEEK_TYPE) {
  559. for(int i=0;i<3;i++) {
  560. random = MakeRandomFloat(-100, 100);
  561. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Cheek[%i]: %i", i, random);
  562. npc->features.cheek_type[i] = random;
  563. }
  564. }
  565. if (flags & RANDOMIZE_CHIN_TYPE) {
  566. for(int i=0;i<3;i++) {
  567. random = MakeRandomFloat(-100, 100);
  568. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Chin[%i]: %i", i, random);
  569. npc->features.chin_type[i] = MakeRandomFloat(-100, 100);
  570. }
  571. }
  572. if (flags & RANDOMIZE_EAR_TYPE) {
  573. for(int i=0;i<3;i++) {
  574. random = MakeRandomFloat(-100, 100);
  575. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Ear[%i]: %i", i, random);
  576. npc->features.ear_type[i] = MakeRandomFloat(-100, 100);
  577. }
  578. }
  579. if (flags & RANDOMIZE_EYE_BROW_TYPE) {
  580. for(int i=0;i<3;i++) {
  581. random = MakeRandomFloat(-100, 100);
  582. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Eyebrow[%i]: %i", i, random);
  583. npc->features.eye_brow_type[i] = MakeRandomFloat(-100, 100);
  584. }
  585. }
  586. if (flags & RANDOMIZE_EYE_TYPE) {
  587. for(int i=0;i<3;i++) {
  588. random = MakeRandomFloat(-100, 100);
  589. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Eye[%i]: %i", i, random);
  590. npc->features.eye_type[i] = MakeRandomFloat(-100, 100);
  591. }
  592. }
  593. if (flags & RANDOMIZE_LIP_TYPE) {
  594. for(int i=0;i<3;i++) {
  595. random = MakeRandomFloat(-100, 100);
  596. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Lip[%i]: %i", i, random);
  597. npc->features.lip_type[i] = MakeRandomFloat(-100, 100);
  598. }
  599. }
  600. if (flags & RANDOMIZE_NOSE_TYPE) {
  601. for(int i=0;i<3;i++) {
  602. random = MakeRandomFloat(-100, 100);
  603. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Nose[%i]: %i", i, random);
  604. npc->features.nose_type[i] = MakeRandomFloat(-100, 100);
  605. }
  606. }
  607. /* Randomize Colors */
  608. random = MakeRandomInt(0, 255);
  609. if(random > 30) {
  610. min_val = random - MakeRandomInt(0, 30);
  611. max_val = random + MakeRandomInt(0, 30);
  612. }
  613. if(max_val > 255)
  614. max_val = 255;
  615. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Color Ranges, random: %i, min: %i, max: %i", random, min_val, max_val);
  616. if (flags & RANDOMIZE_EYE_COLOR) {
  617. npc->features.eye_color.red = MakeRandomInt(min_val, max_val);
  618. npc->features.eye_color.green = MakeRandomInt(min_val, max_val);
  619. npc->features.eye_color.blue = MakeRandomInt(min_val, max_val);
  620. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Eye Color - R: %i, G: %i, B: %i", npc->features.eye_color.red, npc->features.eye_color.green, npc->features.eye_color.blue);
  621. }
  622. if (flags & RANDOMIZE_HAIR_COLOR1) {
  623. npc->features.hair_color1.red = MakeRandomInt(min_val, max_val);
  624. npc->features.hair_color1.green = MakeRandomInt(min_val, max_val);
  625. npc->features.hair_color1.blue = MakeRandomInt(min_val, max_val);
  626. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Hair Color 1 - R: %i, G: %i, B: %i", npc->features.hair_color1.red, npc->features.hair_color1.green, npc->features.hair_color1.blue);
  627. }
  628. if (flags & RANDOMIZE_HAIR_COLOR2) {
  629. npc->features.hair_color2.red = MakeRandomInt(min_val, max_val);
  630. npc->features.hair_color2.green = MakeRandomInt(min_val, max_val);
  631. npc->features.hair_color2.blue = MakeRandomInt(min_val, max_val);
  632. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Hair Color 2 - R: %i, G: %i, B: %i", npc->features.hair_color2.red, npc->features.hair_color2.green, npc->features.hair_color2.blue);
  633. }
  634. if (flags & RANDOMIZE_HAIR_HIGHLIGHT) {
  635. npc->features.hair_highlight_color.red = MakeRandomInt(min_val, max_val);
  636. npc->features.hair_highlight_color.green = MakeRandomInt(min_val, max_val);
  637. npc->features.hair_highlight_color.blue = MakeRandomInt(min_val, max_val);
  638. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Hair Highlight - R: %i, G: %i, B: %i", npc->features.hair_highlight_color.red, npc->features.hair_highlight_color.green, npc->features.hair_highlight_color.blue);
  639. }
  640. if (flags & RANDOMIZE_HAIR_FACE_COLOR) {
  641. EQ2_Color color1;
  642. color1.red = MakeRandomInt(min_val, max_val);
  643. color1.green = MakeRandomInt(min_val, max_val);
  644. color1.blue = MakeRandomInt(min_val, max_val);
  645. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Facial Hair Color - R: %i, G: %i, B: %i", color1.red, color1.green, color1.blue);
  646. npc->SetFacialHairColor(color1);
  647. }
  648. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR) {
  649. EQ2_Color color1;
  650. color1.red = MakeRandomInt(min_val, max_val);
  651. color1.green = MakeRandomInt(min_val, max_val);
  652. color1.blue = MakeRandomInt(min_val, max_val);
  653. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Facial Hair Highlight - R: %i, G: %i, B: %i", color1.red, color1.green, color1.blue);
  654. npc->SetFacialHairHighlightColor(color1);
  655. }
  656. if (flags & RANDOMIZE_HAIR_TYPE_COLOR) {
  657. EQ2_Color color1;
  658. color1.red = MakeRandomInt(min_val, max_val);
  659. color1.green = MakeRandomInt(min_val, max_val);
  660. color1.blue = MakeRandomInt(min_val, max_val);
  661. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Hair Type Color - R: %i, G: %i, B: %i", color1.red, color1.green, color1.blue);
  662. npc->SetHairColor(color1);
  663. }
  664. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR) {
  665. EQ2_Color color1;
  666. color1.red = MakeRandomInt(min_val, max_val);
  667. color1.green = MakeRandomInt(min_val, max_val);
  668. color1.blue = MakeRandomInt(min_val, max_val);
  669. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Hair Type Highlight - R: %i, G: %i, B: %i", color1.red, color1.green, color1.blue);
  670. npc->SetHairTypeHighlightColor(color1);
  671. }
  672. if (flags & RANDOMIZE_SKIN_COLOR) {
  673. npc->features.skin_color.red = MakeRandomInt(min_val, max_val);
  674. npc->features.skin_color.green = MakeRandomInt(min_val, max_val);
  675. npc->features.skin_color.blue = MakeRandomInt(min_val, max_val);
  676. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Skin Color - R: %i, G: %i, B: %i", npc->features.eye_color.red, npc->features.eye_color.green, npc->features.eye_color.blue);
  677. }
  678. if (flags & RANDOMIZE_WING_COLOR1) {
  679. EQ2_Color color1;
  680. color1.red = MakeRandomInt(min_val, max_val);
  681. color1.green = MakeRandomInt(min_val, max_val);
  682. color1.blue = MakeRandomInt(min_val, max_val);
  683. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Wing Color 1 - R: %i, G: %i, B: %i", color1.red, color1.green, color1.blue);
  684. npc->SetWingColor1(color1);
  685. }
  686. if (flags & RANDOMIZE_WING_COLOR2) {
  687. EQ2_Color color1;
  688. color1.red = MakeRandomInt(min_val, max_val);
  689. color1.green = MakeRandomInt(min_val, max_val);
  690. color1.blue = MakeRandomInt(min_val, max_val);
  691. LogWrite(NPC__DEBUG, 5, "NPCs", "Randomizing Wing Color 2 - R: %i, G: %i, B: %i", color1.red, color1.green, color1.blue);
  692. npc->SetWingColor2(color1);
  693. }
  694. }
  695. Skill* NPC::GetSkillByName(const char* name, bool check_update){
  696. if(skills && skills->count(name) > 0){
  697. Skill* ret = (*skills)[name];
  698. if(ret && check_update && ret->current_val < ret->max_val && (rand()%100) >= 90)
  699. ret->current_val++;
  700. return ret;
  701. }
  702. return 0;
  703. }
  704. Skill* NPC::GetSkillByID(int32 id, bool check_update){
  705. Skill* skill = master_skill_list.GetSkill(id);
  706. if(skill && skills && skills->count(skill->name.data) > 0){
  707. Skill* ret = (*skills)[skill->name.data];
  708. if(ret && check_update && ret->current_val < ret->max_val && (rand()%100) >= 90)
  709. ret->current_val++;
  710. return ret;
  711. }
  712. return 0;
  713. }
  714. int8 NPC::GetAttackType(){
  715. return attack_type;
  716. }
  717. void NPC::SetAIStrategy(int8 strategy){
  718. ai_strategy = strategy;
  719. }
  720. int8 NPC::GetAIStrategy(){
  721. return ai_strategy;
  722. }
  723. void NPC::SetPrimarySpellList(int32 id){
  724. primary_spell_list = id;
  725. }
  726. int32 NPC::GetPrimarySpellList(){
  727. return primary_spell_list;
  728. }
  729. void NPC::SetSecondarySpellList(int32 id){
  730. secondary_spell_list = id;
  731. }
  732. int32 NPC::GetSecondarySpellList(){
  733. return secondary_spell_list;
  734. }
  735. void NPC::SetPrimarySkillList(int32 id){
  736. primary_skill_list = id;
  737. }
  738. int32 NPC::GetPrimarySkillList(){
  739. return primary_skill_list;
  740. }
  741. void NPC::SetSecondarySkillList(int32 id){
  742. secondary_skill_list = id;
  743. }
  744. int32 NPC::GetSecondarySkillList(){
  745. return secondary_skill_list;
  746. }
  747. void NPC::SetEquipmentListID(int32 id){
  748. equipment_list_id = id;
  749. }
  750. int32 NPC::GetEquipmentListID(){
  751. return equipment_list_id;
  752. }
  753. Spell* NPC::GetNextSpell(Spawn* target, float distance){
  754. if(!cast_on_aggro_completed) {
  755. Spell* ret = nullptr;
  756. Spell* tmpSpell = nullptr;
  757. vector<NPCSpell*>::iterator itr;
  758. Spawn* tmpTarget = target;
  759. for (itr = cast_on_spells[CAST_ON_AGGRO].begin(); itr != cast_on_spells[CAST_ON_AGGRO].end(); itr++) {
  760. tmpSpell = master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier);
  761. if(!tmpSpell)
  762. continue;
  763. if (tmpSpell->GetSpellData()->friendly_spell > 0) {
  764. tmpTarget = (Spawn*)this;
  765. }
  766. if (tmpSpell->GetSpellData()) {
  767. SpellEffects* effect = ((Entity*)tmpTarget)->GetSpellEffect(tmpSpell->GetSpellID());
  768. if (!effect) {
  769. ret = tmpSpell;
  770. if (tmpSpell->GetSpellData()->friendly_spell > 0) {
  771. tmpTarget = target;
  772. }
  773. break;
  774. }
  775. }
  776. if (tmpSpell->GetSpellData()->friendly_spell > 0) {
  777. tmpTarget = target;
  778. }
  779. }
  780. if(ret) {
  781. return ret;
  782. }
  783. else {
  784. cast_on_aggro_completed = true;
  785. }
  786. }
  787. int8 val = rand()%100;
  788. if(ai_strategy == AI_STRATEGY_OFFENSIVE){
  789. if(val >= 20)//80% chance to cast offensive spell if Offensive AI
  790. return GetNextSpell(distance, AI_STRATEGY_OFFENSIVE);
  791. return GetNextSpell(distance, AI_STRATEGY_DEFENSIVE);
  792. }
  793. else if(ai_strategy == AI_STRATEGY_DEFENSIVE){
  794. if(val >= 20)//80% chance to cast defensive spell if Defensive AI
  795. return GetNextSpell(distance, AI_STRATEGY_DEFENSIVE);
  796. return GetNextSpell(distance, AI_STRATEGY_OFFENSIVE);
  797. }
  798. return GetNextSpell(distance, AI_STRATEGY_BALANCED);
  799. }
  800. Spell* NPC::GetNextSpell(float distance, int8 type){
  801. Spell* ret = 0;
  802. if(spells){
  803. if(distance < 0)
  804. distance = 0;
  805. Spell* tmpSpell = 0;
  806. vector<NPCSpell*>::iterator itr;
  807. for(itr = spells->begin(); itr != spells->end(); itr++){
  808. // if positive, then say the hp ratio must be GREATER than OR EQUAL TO
  809. if((*itr)->required_hp_ratio > 0 && (*itr)->required_hp_ratio < 101 && GetIntHPRatio() >= (*itr)->required_hp_ratio)
  810. continue;
  811. // if negative, then say the hp ratio must be LESS than OR EQUAL TO
  812. if((*itr)->required_hp_ratio < 0 && (*itr)->required_hp_ratio > -101 && (-(*itr)->required_hp_ratio) >= GetIntHPRatio())
  813. continue;
  814. tmpSpell = master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier);
  815. if(!tmpSpell || (type == AI_STRATEGY_OFFENSIVE && tmpSpell->GetSpellData()->friendly_spell > 0))
  816. continue;
  817. if (tmpSpell->GetSpellData()->cast_type == SPELL_CAST_TYPE_TOGGLE)
  818. continue;
  819. if(type == AI_STRATEGY_DEFENSIVE && tmpSpell->GetSpellData()->friendly_spell == 0)
  820. continue;
  821. if(distance <= tmpSpell->GetSpellData()->range && distance >= tmpSpell->GetSpellData()->min_range && GetPower() >= tmpSpell->GetPowerRequired(this)){
  822. ret = tmpSpell;
  823. if((rand()%100) >= 70) //30% chance to stop after finding the first match, this will give the appearance of the NPC randomly choosing a spell to cast
  824. break;
  825. }
  826. }
  827. if(!ret && type != AI_STRATEGY_BALANCED)
  828. ret = GetNextSpell(distance, AI_STRATEGY_BALANCED); //wasnt able to find a valid match, so find any spell that the NPC has
  829. }
  830. return ret;
  831. }
  832. Spell* NPC::GetNextBuffSpell(Spawn* target) {
  833. if(!target) {
  834. target = (Spawn*)this;
  835. }
  836. Spell* ret = 0;
  837. if(!target->IsEntity()) {
  838. return ret;
  839. }
  840. if (spells && GetZone()->GetSpellProcess()) {
  841. Spell* tmpSpell = 0;
  842. vector<NPCSpell*>::iterator itr;
  843. for (itr = cast_on_spells[CAST_ON_SPAWN].begin(); itr != cast_on_spells[CAST_ON_SPAWN].end(); itr++) {
  844. tmpSpell = master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier);
  845. if (tmpSpell && tmpSpell->GetSpellData()) {
  846. SpellEffects* effect = ((Entity*)target)->GetSpellEffect(tmpSpell->GetSpellID());
  847. if (effect) {
  848. if (effect->tier < tmpSpell->GetSpellTier()) {
  849. ret = tmpSpell;
  850. break;
  851. }
  852. }
  853. else {
  854. ret = tmpSpell;
  855. break;
  856. }
  857. }
  858. }
  859. for (itr = spells->begin(); itr != spells->end(); itr++) {
  860. // if positive, then say the hp ratio must be GREATER than OR EQUAL TO
  861. if((*itr)->required_hp_ratio > 0 && (*itr)->required_hp_ratio < 101 && GetIntHPRatio() >= (*itr)->required_hp_ratio)
  862. continue;
  863. // if negative, then say the hp ratio must be LESS than OR EQUAL TO
  864. if((*itr)->required_hp_ratio < 0 && (*itr)->required_hp_ratio > -101 && (-(*itr)->required_hp_ratio) >= GetIntHPRatio())
  865. continue;
  866. tmpSpell = master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier);
  867. if (tmpSpell && tmpSpell->GetSpellData() && tmpSpell->GetSpellData()->cast_type == SPELL_CAST_TYPE_TOGGLE) {
  868. SpellEffects* effect = ((Entity*)target)->GetSpellEffect(tmpSpell->GetSpellID());
  869. if (effect) {
  870. if (effect->tier < tmpSpell->GetSpellTier()) {
  871. ret = tmpSpell;
  872. break;
  873. }
  874. }
  875. else {
  876. ret = tmpSpell;
  877. break;
  878. }
  879. }
  880. }
  881. }
  882. return ret;
  883. }
  884. void NPC::SetAggroRadius(float radius, bool overrideBaseValue){
  885. if (base_aggro_radius == 0.0f || overrideBaseValue)
  886. base_aggro_radius = radius;
  887. aggro_radius = radius;
  888. }
  889. float NPC::GetAggroRadius(){
  890. return aggro_radius;
  891. }
  892. void NPC::SetCastPercentage(int8 percentage){
  893. cast_percentage = percentage;
  894. }
  895. int8 NPC::GetCastPercentage(){
  896. return cast_percentage;
  897. }
  898. void NPC::AddSkillBonus(int32 spell_id, int32 skill_id, float value) {
  899. if (value != 0) {
  900. SkillBonus* sb;
  901. if (skill_bonus_list.count(spell_id) == 0) {
  902. sb = new SkillBonus;
  903. sb->spell_id = spell_id;
  904. skill_bonus_list.Put(spell_id, sb);
  905. }
  906. else
  907. sb = skill_bonus_list.Get(spell_id);
  908. if (sb->skills[skill_id] == 0) {
  909. SkillBonusValue* sbv = new SkillBonusValue;
  910. sbv->skill_id = skill_id;
  911. sbv->value = value;
  912. sb->skills[skill_id] = sbv;
  913. if (skills) {
  914. map<string, Skill*>::iterator itr;
  915. for (itr = skills->begin(); itr != skills->end(); itr++) {
  916. Skill* skill = itr->second;
  917. if (skill->skill_id == sbv->skill_id) {
  918. skill->current_val += (int16)sbv->value;
  919. skill->max_val += (int16)sbv->value;
  920. }
  921. }
  922. }
  923. }
  924. }
  925. }
  926. void NPC::RemoveSkillBonus(int32 spell_id) {
  927. if (skill_bonus_list.count(spell_id) > 0) {
  928. SkillBonus* sb = skill_bonus_list.Get(spell_id);
  929. skill_bonus_list.erase(spell_id);
  930. map<int32, SkillBonusValue*>::iterator itr;
  931. for (itr = sb->skills.begin(); itr != sb->skills.end(); itr++) {
  932. SkillBonusValue* sbv = itr->second;
  933. if (skills) {
  934. map<string, Skill*>::iterator skill_itr;
  935. for (skill_itr = skills->begin(); skill_itr != skills->end(); skill_itr++) {
  936. Skill* skill = skill_itr->second;
  937. if (sbv->skill_id == skill->skill_id) {
  938. skill->current_val -= (int16)sbv->value;
  939. skill->max_val -= (int16)sbv->value;
  940. }
  941. }
  942. }
  943. safe_delete(sbv);
  944. }
  945. safe_delete(sb);
  946. }
  947. }
  948. void NPC::SetBrain(::Brain* brain) {
  949. // Again, had to use the '::' to refer to the Brain class and not the function defined in the NPC class
  950. MBrain.writelock(__FUNCTION__, __LINE__);
  951. // Check to make sure the NPC the brain controls matches this npc
  952. if (brain && brain->GetBody() != this) {
  953. LogWrite(NPC_AI__ERROR, 0, "NPC_AI", "Brain body does not match the npc we tried to assign the brain to.");
  954. MBrain.releasewritelock(__FUNCTION__, __LINE__);
  955. return;
  956. }
  957. // Store the old brain in a temp pointer so we can delete it later
  958. ::Brain* old_brain = m_brain;
  959. // Set the brain for this NPC to the new brain
  960. m_brain = brain;
  961. // Release the lock
  962. MBrain.releasewritelock(__FUNCTION__, __LINE__);
  963. // Delete the old brain
  964. safe_delete(old_brain);
  965. }
  966. void NPC::SetZone(ZoneServer* in_zone, int32 version) {
  967. Spawn::SetZone(in_zone, version);
  968. if (in_zone){
  969. GetZone()->SetNPCEquipment(this);
  970. SetSkills(GetZone()->GetNPCSkills(primary_skill_list, secondary_skill_list));
  971. SetSpells(world.GetNPCSpells(primary_spell_list, secondary_spell_list));
  972. }
  973. }