Multiple dynamic npc (#7486)

* Vectorize npc_id_dynamic to support multiple dynamic npc with different ids

Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>

Thanks to @dimasshotta and @eppc0330 !
This commit is contained in:
Atemo
2022-12-16 21:22:31 +01:00
committed by GitHub
parent 20dedc7918
commit ef602d98cb
3 changed files with 28 additions and 15 deletions

View File

@@ -3423,17 +3423,22 @@ int unit_free(struct block_list *bl, clr_type clrtype)
sd->npc_id = 0;
}
if( sd->npc_id_dynamic != 0 ){
struct npc_data* nd = map_id2nd( sd->npc_id_dynamic );
if( !sd->npc_id_dynamic.empty() ){
for (const auto &it : sd->npc_id_dynamic) {
struct npc_data* nd = map_id2nd( it );
if( nd != nullptr ){
// Delete the NPC
npc_unload( nd, true );
// Update NPC event database
npc_read_event_script();
if( nd != nullptr ){
// Erase the owner first to prevent loops from npc_unload
nd->dynamicnpc.owner_char_id = 0;
// Delete the NPC
npc_unload( nd, true );
}
}
// Update NPC event database
npc_read_event_script();
sd->npc_id_dynamic = 0;
sd->npc_id_dynamic.clear();
}
sd->combos.clear();