Pārlūkot izejas kodu

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 !
Atemo 6 gadi atpakaļ
vecāks
revīzija
3d8c20f6b9
2 mainītis faili ar 28 papildinājumiem un 5 dzēšanām
  1. 1 1
      src/map/npc.cpp
  2. 27 4
      src/map/unit.cpp

+ 1 - 1
src/map/npc.cpp

@@ -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]);
 
 		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);
 	}
 

+ 27 - 4
src/map/unit.cpp

@@ -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->m = m;
 
+	if (bl->type == BL_NPC) {
+		TBL_NPC *nd = (TBL_NPC*)bl;
+		map_addnpc(m, nd);
+		npc_setcells(nd);
+	}
+
 	if(map_addblock(bl))
 		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;
 		}
+		case BL_NPC:
+			if (npc_remove_map( (TBL_NPC*)bl ) != 0)
+				return 0;
+			break;
 		default:
 			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_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);
 
-	map_delblock(bl);
+	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);
+				break;
+			}
+			// Fall through
+		default:
+			clif_clearunit_area(bl, clrtype);
+			map_delblock(bl);
+			break;
+	}
+
 	map_freeblock_unlock();
 
 	return 1;