unitwarp npc - issue #4087 (#4104)

* Fixed issue #4087 
* Added an extra map check in npc_touch_areanpc
* Move the npc warped by unitwarp to the new map.

Thanks to @aleos89 for the review and @Litro for testing !
This commit is contained in:
Atemo 2019-04-25 15:07:20 +02:00 committed by GitHub
parent 53cedb72af
commit 3d8c20f6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View File

@ -1016,7 +1016,7 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
struct npc_data *nd = map_id2nd(sd->areanpc[i]); struct npc_data *nd = map_id2nd(sd->areanpc[i]);
if (!nd || nd->subtype != NPCTYPE_SCRIPT || if (!nd || nd->subtype != NPCTYPE_SCRIPT ||
!(x >= nd->bl.x - nd->u.scr.xs && x <= nd->bl.x + nd->u.scr.xs && y >= nd->bl.y - nd->u.scr.ys && y <= nd->bl.y + nd->u.scr.ys)) !(nd->bl.m == m && x >= nd->bl.x - nd->u.scr.xs && x <= nd->bl.x + nd->u.scr.xs && y >= nd->bl.y - nd->u.scr.ys && y <= nd->bl.y + nd->u.scr.ys))
sd->areanpc.erase(sd->areanpc.begin() + i); sd->areanpc.erase(sd->areanpc.begin() + i);
} }

View File

@ -1243,6 +1243,12 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type)
bl->y = ud->to_y = y; bl->y = ud->to_y = y;
bl->m = m; bl->m = m;
if (bl->type == BL_NPC) {
TBL_NPC *nd = (TBL_NPC*)bl;
map_addnpc(m, nd);
npc_setcells(nd);
}
if(map_addblock(bl)) if(map_addblock(bl))
return 4; //error on adding bl to map return 4; //error on adding bl to map
@ -3093,6 +3099,10 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
} }
break; break;
} }
case BL_NPC:
if (npc_remove_map( (TBL_NPC*)bl ) != 0)
return 0;
break;
default: default:
break;// do nothing break;// do nothing
} }
@ -3101,11 +3111,24 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
skill_unit_move(bl,gettick(),4); skill_unit_move(bl,gettick(),4);
skill_cleartimerskill(bl); skill_cleartimerskill(bl);
} }
// /BL_MOB is handled by mob_dead unless the monster is not dead.
if( bl->type != BL_MOB || !status_isdead(bl) )
clif_clearunit_area(bl,clrtype);
switch (bl->type) {
case BL_NPC:
// already handled by npc_remove_map
break;
case BL_MOB:
// /BL_MOB is handled by mob_dead unless the monster is not dead.
if (status_isdead(bl)) {
map_delblock(bl); map_delblock(bl);
break;
}
// Fall through
default:
clif_clearunit_area(bl, clrtype);
map_delblock(bl);
break;
}
map_freeblock_unlock(); map_freeblock_unlock();
return 1; return 1;