From 4600844336c994dca9eb96abfcbc5891d13d57a9 Mon Sep 17 00:00:00 2001 From: regneq Date: Fri, 7 Apr 2017 19:45:26 -0700 Subject: [PATCH] Added ignore_despawn column to npc_types to have NPCs ignore the despawn column in spawngroup. --- utils/sql/db_update_manifest.txt | 1 + .../required/2017_04_07_ignore_despawn.sql | 1 + zone/npc.cpp | 1 + zone/npc.h | 3 +++ zone/spawn2.cpp | 26 ++++++++++++++++--- zone/zonedb.cpp | 4 ++- zone/zonedump.h | 1 + 7 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 utils/sql/git/required/2017_04_07_ignore_despawn.sql diff --git a/utils/sql/db_update_manifest.txt b/utils/sql/db_update_manifest.txt index 428fd52c8..ea176f1e0 100644 --- a/utils/sql/db_update_manifest.txt +++ b/utils/sql/db_update_manifest.txt @@ -361,6 +361,7 @@ 9105|2017_02_15_bot_spells_entries.sql|SELECT `id` FROM `npc_spells_entries` WHERE `npc_spells_id` >= 701 AND `npc_spells_id` <= 712|not_empty| 9106|2017_02_26_npc_spells_update_for_bots.sql|SELECT * FROM `npc_spells` WHERE `id` = '701' AND `name` = 'Cleric Bot'|not_empty| 9107|2017_03_09_inventory_version.sql|SHOW TABLES LIKE 'inventory_version'|empty| +9107|2017_04_07_ignore_despawn|SHOW COLUMNS FROM `npc_types` LIKE 'ignore_despawn'|empty| # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/required/2017_04_07_ignore_despawn.sql b/utils/sql/git/required/2017_04_07_ignore_despawn.sql new file mode 100644 index 000000000..0cf264d34 --- /dev/null +++ b/utils/sql/git/required/2017_04_07_ignore_despawn.sql @@ -0,0 +1 @@ +alter table npc_types add column `ignore_despawn` tinyint(2) not null default 0; \ No newline at end of file diff --git a/zone/npc.cpp b/zone/npc.cpp index e47ba402b..324bfe2e9 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -374,6 +374,7 @@ NPC::NPC(const NPCType* d, Spawn2* in_respawn, const glm::vec4& position, int if InitializeBuffSlots(); CalcBonuses(); raid_target = d->raid_target; + ignore_despawn = d->ignore_despawn; } NPC::~NPC() diff --git a/zone/npc.h b/zone/npc.h index 015128340..30e54da55 100644 --- a/zone/npc.h +++ b/zone/npc.h @@ -417,6 +417,8 @@ public: bool IsRaidTarget() const { return raid_target; }; void ResetHPUpdateTimer() { sendhpupdate_timer.Start(); } + bool IgnoreDespawn() { return ignore_despawn; } + protected: const NPCType* NPCTypedata; @@ -532,6 +534,7 @@ protected: bool raid_target; uint8 probability; + bool ignore_despawn; //NPCs with this set to 1 will ignore the despawn value in spawngroup private: uint32 loottable_id; diff --git a/zone/spawn2.cpp b/zone/spawn2.cpp index 291ee9bb7..654c5e836 100644 --- a/zone/spawn2.cpp +++ b/zone/spawn2.cpp @@ -208,11 +208,26 @@ bool Spawn2::Process() { } } - if(sg->despawn != 0 && condition_id == 0) - zone->Despawn(spawn2_id); - - if(IsDespawned) + bool ignore_despawn = false; + if (npcthis) + { + ignore_despawn = npcthis->IgnoreDespawn(); + } + + if (ignore_despawn) + { return true; + } + + if (sg->despawn != 0 && condition_id == 0 && !ignore_despawn) + { + zone->Despawn(spawn2_id); + } + + if (IsDespawned) + { + return true; + } currentnpcid = npcid; NPC* npc = new NPC(tmp, this, glm::vec4(x, y, z, heading), FlyMode3); @@ -295,6 +310,9 @@ void Spawn2::ForceDespawn() if(npcthis != nullptr) { + if (npcthis->IgnoreDespawn()) + return; + if(!npcthis->IsEngaged()) { if(sg->despawn == 3 || sg->despawn == 4) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index dae62340d..aa4cbc846 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1966,7 +1966,8 @@ const NPCType* ZoneDatabase::LoadNPCTypesData(uint32 npc_type_id, bool bulk_load "npc_types.bracertexture, " "npc_types.handtexture, " "npc_types.legtexture, " - "npc_types.feettexture " + "npc_types.feettexture, " + "npc_types.ignore_despawn " "FROM npc_types %s", where_condition.c_str() ); @@ -2141,6 +2142,7 @@ const NPCType* ZoneDatabase::LoadNPCTypesData(uint32 npc_type_id, bool bulk_load temp_npctype_data->handtexture = atoi(row[94]); temp_npctype_data->legtexture = atoi(row[95]); temp_npctype_data->feettexture = atoi(row[96]); + temp_npctype_data->ignore_despawn = atoi(row[97]) == 1 ? true : false; // If NPC with duplicate NPC id already in table, // free item we attempted to add. diff --git a/zone/zonedump.h b/zone/zonedump.h index ef8da2243..359c09ba8 100644 --- a/zone/zonedump.h +++ b/zone/zonedump.h @@ -132,6 +132,7 @@ struct NPCType uint8 handtexture; uint8 legtexture; uint8 feettexture; + bool ignore_despawn; }; namespace player_lootitem {