9
3

NPC.cpp 34 KB

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