Adjusted OnTouch overlap behavior (#2382)
* Fixes #1939 and fixes #2274. * OnTouch NPC are now able to overlap one another and properly trigger as they do on official servers. * When entering an overlap area it should trigger both NPC. * Walking from overlap area to either NPC should trigger neither. * Walking from one NPC to the other (skipping the overlap area) should trigger the NPC area you enter. * Entering an OnTouch area will no longer stop the player from walking unless a message or menu window opens (or other events that should stop the player). * Resolves OnTouch_ overlapping issues. * Dead players don't trigger OnTouch_ anymore. * Hidden players don't trigger NPC clicks when OnTouch_ label is defined. Thanks to @Tokeiburu, @Lemongrass3110, @Atemo, and @Normynator!
This commit is contained in:
parent
98a685d706
commit
c977558cfd
@ -10655,7 +10655,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
|
|||||||
if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
|
if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
|
||||||
npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
|
npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
|
||||||
else
|
else
|
||||||
sd->areanpc_id = 0;
|
sd->areanpc.clear();
|
||||||
|
|
||||||
/* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
|
/* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
|
||||||
if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
|
if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
|
||||||
|
@ -2642,7 +2642,43 @@ bool map_addnpc(int16 m,struct npc_data *nd)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xs = -1, ys = -1;
|
||||||
|
|
||||||
|
switch (nd->subtype) {
|
||||||
|
case NPCTYPE_WARP:
|
||||||
|
xs = nd->u.warp.xs;
|
||||||
|
ys = nd->u.warp.ys;
|
||||||
|
break;
|
||||||
|
case NPCTYPE_SCRIPT:
|
||||||
|
xs = nd->u.scr.xs;
|
||||||
|
ys = nd->u.scr.ys;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// npcs with trigger area are grouped
|
||||||
|
// 0 < npc_num_warp < npc_num_area < npc_num
|
||||||
|
if (xs < 0 && ys < 0)
|
||||||
mapdata->npc[ mapdata->npc_num ] = nd;
|
mapdata->npc[ mapdata->npc_num ] = nd;
|
||||||
|
else {
|
||||||
|
switch (nd->subtype) {
|
||||||
|
case NPCTYPE_WARP:
|
||||||
|
mapdata->npc[ mapdata->npc_num ] = mapdata->npc[ mapdata->npc_num_area ];
|
||||||
|
mapdata->npc[ mapdata->npc_num_area ] = mapdata->npc[ mapdata->npc_num_warp ];
|
||||||
|
mapdata->npc[ mapdata->npc_num_warp ] = nd;
|
||||||
|
mapdata->npc_num_warp++;
|
||||||
|
mapdata->npc_num_area++;
|
||||||
|
break;
|
||||||
|
case NPCTYPE_SCRIPT:
|
||||||
|
mapdata->npc[ mapdata->npc_num ] = mapdata->npc[ mapdata->npc_num_area ];
|
||||||
|
mapdata->npc[ mapdata->npc_num_area ] = nd;
|
||||||
|
mapdata->npc_num_area++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mapdata->npc[ mapdata->npc_num ] = nd;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
mapdata->npc_num++;
|
mapdata->npc_num++;
|
||||||
idb_put(id_db,nd->bl.id,nd);
|
idb_put(id_db,nd->bl.id,nd);
|
||||||
return true;
|
return true;
|
||||||
@ -2709,6 +2745,8 @@ int map_addinstancemap(const char *name, unsigned short instance_id)
|
|||||||
|
|
||||||
memset(dst_map->npc, 0, sizeof(dst_map->npc));
|
memset(dst_map->npc, 0, sizeof(dst_map->npc));
|
||||||
dst_map->npc_num = 0;
|
dst_map->npc_num = 0;
|
||||||
|
dst_map->npc_num_area = 0;
|
||||||
|
dst_map->npc_num_warp = 0;
|
||||||
|
|
||||||
// Reallocate cells
|
// Reallocate cells
|
||||||
num_cell = dst_map->xs * dst_map->ys;
|
num_cell = dst_map->xs * dst_map->ys;
|
||||||
|
@ -726,7 +726,9 @@ struct map_data {
|
|||||||
int16 xs,ys; // map dimensions (in cells)
|
int16 xs,ys; // map dimensions (in cells)
|
||||||
int16 bxs,bys; // map dimensions (in blocks)
|
int16 bxs,bys; // map dimensions (in blocks)
|
||||||
int16 bgscore_lion, bgscore_eagle; // Battleground ScoreBoard
|
int16 bgscore_lion, bgscore_eagle; // Battleground ScoreBoard
|
||||||
int npc_num;
|
int npc_num; // number total of npc on the map
|
||||||
|
int npc_num_area; // number of npc with a trigger area on the map
|
||||||
|
int npc_num_warp; // number of warp npc on the map
|
||||||
int users;
|
int users;
|
||||||
int users_pvp;
|
int users_pvp;
|
||||||
int iwall_num; // Total of invisible walls in this map
|
int iwall_num; // Total of invisible walls in this map
|
||||||
|
183
src/map/npc.cpp
183
src/map/npc.cpp
@ -169,11 +169,21 @@ int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd)
|
|||||||
{
|
{
|
||||||
char name[EVENT_NAME_LENGTH];
|
char name[EVENT_NAME_LENGTH];
|
||||||
|
|
||||||
|
if (pc_isdead(sd)) // Dead player don't trigger 'OnTouch_'
|
||||||
|
return 0;
|
||||||
|
|
||||||
if( nd->touching_id )
|
if( nd->touching_id )
|
||||||
return 0; // Attached a player already. Can't trigger on anyone else.
|
return 0; // Attached a player already. Can't trigger on anyone else.
|
||||||
|
|
||||||
if( pc_ishiding(sd) )
|
// pc_ishiding moved in npc_event for now.
|
||||||
return 1; // Can't trigger 'OnTouch_'. try 'OnTouch' later.
|
// If OnTouch_ event exists hiding player doesn't click the npc.
|
||||||
|
// if( pc_ishiding(sd) )
|
||||||
|
// return 1; // Can't trigger 'OnTouch_'.
|
||||||
|
|
||||||
|
auto it = std::find(sd->npc_ontouch_.begin(), sd->npc_ontouch_.end(), nd->bl.id);
|
||||||
|
|
||||||
|
if (it != sd->npc_ontouch_.end())
|
||||||
|
return 0;
|
||||||
|
|
||||||
safesnprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_event_name);
|
safesnprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_event_name);
|
||||||
return npc_event(sd,name,1);
|
return npc_event(sd,name,1);
|
||||||
@ -182,8 +192,9 @@ int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd)
|
|||||||
int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd)
|
int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd)
|
||||||
{
|
{
|
||||||
char name[EVENT_NAME_LENGTH];
|
char name[EVENT_NAME_LENGTH];
|
||||||
|
auto it = std::find(sd->areanpc.begin(), sd->areanpc.end(), nd->bl.id);
|
||||||
|
|
||||||
if( sd->areanpc_id == nd->bl.id )
|
if (it != sd->areanpc.end())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
safesnprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch2_event_name);
|
safesnprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch2_event_name);
|
||||||
@ -206,6 +217,7 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
|
|||||||
if (nd->sc.option&OPTION_INVISIBLE)
|
if (nd->sc.option&OPTION_INVISIBLE)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// note : disablenpc doesn't reset the previous trigger status on official
|
||||||
if( npc_ontouch_event(sd,nd) > 0 && npc_ontouch2_event(sd,nd) > 0 )
|
if( npc_ontouch_event(sd,nd) > 0 && npc_ontouch2_event(sd,nd) > 0 )
|
||||||
{ // failed to run OnTouch event, so just click the npc
|
{ // failed to run OnTouch event, so just click the npc
|
||||||
if (sd->npc_id != 0)
|
if (sd->npc_id != 0)
|
||||||
@ -898,18 +910,25 @@ int npc_event(struct map_session_data* sd, const char* eventname, int ontouch)
|
|||||||
return ontouch;
|
return ontouch;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ontouch)
|
if (ontouch == 1) { // OnTouch_
|
||||||
{
|
if (pc_ishiding(sd))
|
||||||
case 1:
|
return 0;
|
||||||
|
|
||||||
nd->touching_id = sd->bl.id;
|
nd->touching_id = sd->bl.id;
|
||||||
sd->touching_id = nd->bl.id;
|
|
||||||
break;
|
auto it = std::find(sd->npc_ontouch_.begin(), sd->npc_ontouch_.end(), nd->bl.id);
|
||||||
case 2:
|
|
||||||
sd->areanpc_id = nd->bl.id;
|
if (it == sd->npc_ontouch_.end())
|
||||||
break;
|
sd->npc_ontouch_.push_back(nd->bl.id);
|
||||||
|
} else if (ontouch == 2) { // OnTouch
|
||||||
|
auto it = std::find(sd->areanpc.begin(), sd->areanpc.end(), nd->bl.id);
|
||||||
|
|
||||||
|
if (it == sd->areanpc.end())
|
||||||
|
sd->areanpc.push_back(nd->bl.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return npc_event_sub(sd,ev,eventname);
|
npc_event_sub(sd,ev,eventname); // Don't return this value so npc_enable_sub doesn't attempt to "click" the NPC if OnTouch fails.
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
@ -931,6 +950,8 @@ int npc_touch_areanpc_sub(struct block_list *bl, va_list ap)
|
|||||||
return 0;
|
return 0;
|
||||||
if( pc_ishiding(sd) )
|
if( pc_ishiding(sd) )
|
||||||
return 0;
|
return 0;
|
||||||
|
if( pc_isdead(sd) )
|
||||||
|
return 0;
|
||||||
if( pc_id == sd->bl.id )
|
if( pc_id == sd->bl.id )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -945,27 +966,40 @@ int npc_touch_areanpc_sub(struct block_list *bl, va_list ap)
|
|||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap)
|
int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap)
|
||||||
{
|
{
|
||||||
struct npc_data *nd = map_id2nd(sd->touching_id);
|
if (sd->npc_ontouch_.empty())
|
||||||
short xs, ys;
|
return 0;
|
||||||
|
|
||||||
if( !nd || nd->touching_id != sd->bl.id )
|
bool found = false;
|
||||||
return 1;
|
|
||||||
|
|
||||||
xs = nd->u.scr.xs;
|
sd->npc_ontouch_.erase(std::remove_if(sd->npc_ontouch_.begin(), sd->npc_ontouch_.end(), [&] (const int ¤t_npc_id) {
|
||||||
ys = nd->u.scr.ys;
|
struct npc_data *nd = map_id2nd(current_npc_id);
|
||||||
|
|
||||||
if( sd->bl.m != nd->bl.m ||
|
if (!nd) {
|
||||||
sd->bl.x < nd->bl.x - xs || sd->bl.x > nd->bl.x + xs ||
|
return true;
|
||||||
sd->bl.y < nd->bl.y - ys || sd->bl.y > nd->bl.y + ys ||
|
} else {
|
||||||
pc_ishiding(sd) || leavemap )
|
int16 xs = nd->u.scr.xs;
|
||||||
{
|
int16 ys = nd->u.scr.ys;
|
||||||
|
|
||||||
|
// note : hiding doesn't reset the previous trigger status
|
||||||
|
// player must leave the area to reset nd->touching_id on official
|
||||||
|
if (sd->bl.m != nd->bl.m || sd->bl.x < nd->bl.x - xs || sd->bl.x > nd->bl.x + xs || sd->bl.y < nd->bl.y - ys || sd->bl.y > nd->bl.y + ys || leavemap) {
|
||||||
char name[EVENT_NAME_LENGTH];
|
char name[EVENT_NAME_LENGTH];
|
||||||
|
|
||||||
nd->touching_id = sd->touching_id = 0;
|
if (nd->touching_id && nd->touching_id == sd->bl.id) {// empty when reload script
|
||||||
|
found = true;
|
||||||
|
nd->touching_id = 0;
|
||||||
safesnprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_event_name);
|
safesnprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_event_name);
|
||||||
map_forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,name);
|
map_forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,name);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}), sd->npc_ontouch_.end());
|
||||||
|
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
@ -973,24 +1007,25 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap)
|
|||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
|
int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
|
||||||
{
|
{
|
||||||
int xs,ys;
|
int xs, ys, i, f = 1;
|
||||||
int f = 1;
|
|
||||||
int i;
|
|
||||||
int j, found_warp = 0;
|
|
||||||
|
|
||||||
nullpo_retr(1, sd);
|
nullpo_retr(1, sd);
|
||||||
|
|
||||||
// Why not enqueue it? [Inkfish]
|
// Remove NPCs that are no longer within the OnTouch area
|
||||||
//if(sd->npc_id)
|
for (i = 0; i < sd->areanpc.size(); i++) {
|
||||||
// return 1;
|
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))
|
||||||
|
sd->areanpc.erase(sd->areanpc.begin() + i);
|
||||||
|
}
|
||||||
|
|
||||||
if (sd->state.block_action & PCBLOCK_NPCCLICK)
|
if (sd->state.block_action & PCBLOCK_NPCCLICK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
struct map_data *mapdata = map_getmapdata(m);
|
struct map_data *mapdata = map_getmapdata(m);
|
||||||
|
|
||||||
for(i=0;i<mapdata->npc_num;i++)
|
for (i = 0; i < mapdata->npc_num_area; i++) {
|
||||||
{
|
|
||||||
if (mapdata->npc[i]->sc.option&OPTION_INVISIBLE) {
|
if (mapdata->npc[i]->sc.option&OPTION_INVISIBLE) {
|
||||||
f = 0; // a npc was found, but it is disabled; don't print warning
|
f = 0; // a npc was found, but it is disabled; don't print warning
|
||||||
continue;
|
continue;
|
||||||
@ -1008,16 +1043,10 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
|
|||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if( x >= mapdata->npc[i]->bl.x-xs && x <= mapdata->npc[i]->bl.x+xs
|
|
||||||
&& y >= mapdata->npc[i]->bl.y-ys && y <= mapdata->npc[i]->bl.y+ys )
|
if (x >= mapdata->npc[i]->bl.x - xs && x <= mapdata->npc[i]->bl.x + xs && y >= mapdata->npc[i]->bl.y - ys && y <= mapdata->npc[i]->bl.y + ys) {
|
||||||
break;
|
f = 0;
|
||||||
}
|
|
||||||
if( i == mapdata->npc_num )
|
|
||||||
{
|
|
||||||
if( f == 1 ) // no npc found
|
|
||||||
ShowError("npc_touch_areanpc : stray NPC cell/NPC not found in the block on coordinates '%s',%d,%d\n", mapdata->name, x, y);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
switch (mapdata->npc[i]->subtype) {
|
switch (mapdata->npc[i]->subtype) {
|
||||||
case NPCTYPE_WARP:
|
case NPCTYPE_WARP:
|
||||||
if ((!mapdata->npc[i]->trigger_on_hidden && (pc_ishiding(sd) || (sd->sc.count && sd->sc.data[SC_CAMOUFLAGE]))) || pc_isdead(sd))
|
if ((!mapdata->npc[i]->trigger_on_hidden && (pc_ishiding(sd) || (sd->sc.count && sd->sc.data[SC_CAMOUFLAGE]))) || pc_isdead(sd))
|
||||||
@ -1030,40 +1059,29 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pc_setpos(sd, mapdata->npc[i]->u.warp.mapindex, mapdata->npc[i]->u.warp.x, mapdata->npc[i]->u.warp.y, CLR_OUTSIGHT);
|
pc_setpos(sd, mapdata->npc[i]->u.warp.mapindex, mapdata->npc[i]->u.warp.x, mapdata->npc[i]->u.warp.y, CLR_OUTSIGHT);
|
||||||
break;
|
return 0;
|
||||||
case NPCTYPE_SCRIPT:
|
case NPCTYPE_SCRIPT:
|
||||||
for (j = i; j < mapdata->npc_num; j++) {
|
// warp type sorted first, no need to check if they override any other OnTouch areas.
|
||||||
if (mapdata->npc[j]->subtype != NPCTYPE_WARP) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((sd->bl.x >= (mapdata->npc[j]->bl.x - mapdata->npc[j]->u.warp.xs) && sd->bl.x <= (mapdata->npc[j]->bl.x + mapdata->npc[j]->u.warp.xs)) &&
|
if (npc_ontouch_event(sd, mapdata->npc[i]) > 0 && npc_ontouch2_event(sd, mapdata->npc[i]) > 0) { // failed to run OnTouch event, so just click the npc
|
||||||
(sd->bl.y >= (mapdata->npc[j]->bl.y - mapdata->npc[j]->u.warp.ys) && sd->bl.y <= (mapdata->npc[j]->bl.y + mapdata->npc[j]->u.warp.ys))) {
|
auto it = std::find(sd->areanpc.begin(), sd->areanpc.end(), mapdata->npc[i]->bl.id);
|
||||||
if ((!mapdata->npc[i]->trigger_on_hidden && (pc_ishiding(sd) || (sd->sc.count && sd->sc.data[SC_CAMOUFLAGE]))) || pc_isdead(sd))
|
|
||||||
break; // hidden or dead chars cannot use warps
|
|
||||||
pc_setpos(sd,mapdata->npc[j]->u.warp.mapindex,mapdata->npc[j]->u.warp.x,mapdata->npc[j]->u.warp.y,CLR_OUTSIGHT);
|
|
||||||
found_warp = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found_warp > 0) {
|
if (it == sd->areanpc.end())
|
||||||
break;
|
sd->areanpc.push_back(mapdata->npc[i]->bl.id);
|
||||||
}
|
|
||||||
|
|
||||||
if( npc_ontouch_event(sd,mapdata->npc[i]) > 0 && npc_ontouch2_event(sd,mapdata->npc[i]) > 0 )
|
|
||||||
{ // failed to run OnTouch event, so just click the npc
|
|
||||||
struct unit_data *ud = unit_bl2ud(&sd->bl);
|
|
||||||
if( ud && ud->walkpath.path_pos < ud->walkpath.path_len )
|
|
||||||
{ // Since walktimer always == INVALID_TIMER at this time, we stop walking manually. [Inkfish]
|
|
||||||
clif_fixpos(&sd->bl);
|
|
||||||
ud->walkpath.path_pos = ud->walkpath.path_len;
|
|
||||||
}
|
|
||||||
sd->areanpc_id = mapdata->npc[i]->bl.id;
|
|
||||||
npc_click(sd, mapdata->npc[i]);
|
npc_click(sd, mapdata->npc[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f == 1) {
|
||||||
|
ShowError("npc_touch_areanpc : stray NPC cell/NPC not found in the block on coordinates '%s',%d,%d\n", mapdata->name, x, y);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1077,7 +1095,7 @@ int npc_touch_areanpc2(struct mob_data *md)
|
|||||||
int xs, ys;
|
int xs, ys;
|
||||||
struct map_data *mapdata = map_getmapdata(md->bl.m);
|
struct map_data *mapdata = map_getmapdata(md->bl.m);
|
||||||
|
|
||||||
for( i = 0; i < mapdata->npc_num; i++ )
|
for( i = 0; i < mapdata->npc_num_area; i++ )
|
||||||
{
|
{
|
||||||
if( mapdata->npc[i]->sc.option&OPTION_INVISIBLE )
|
if( mapdata->npc[i]->sc.option&OPTION_INVISIBLE )
|
||||||
continue;
|
continue;
|
||||||
@ -1166,7 +1184,7 @@ int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range)
|
|||||||
if (!i) return 0; //No NPC_CELLs.
|
if (!i) return 0; //No NPC_CELLs.
|
||||||
|
|
||||||
//Now check for the actual NPC on said range.
|
//Now check for the actual NPC on said range.
|
||||||
for(i=0;i<mapdata->npc_num;i++)
|
for (i = 0; i < mapdata->npc_num_area; i++)
|
||||||
{
|
{
|
||||||
if (mapdata->npc[i]->sc.option&OPTION_INVISIBLE)
|
if (mapdata->npc[i]->sc.option&OPTION_INVISIBLE)
|
||||||
continue;
|
continue;
|
||||||
@ -1193,7 +1211,7 @@ int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range)
|
|||||||
&& y1 >= mapdata->npc[i]->bl.y-ys && y0 <= mapdata->npc[i]->bl.y+ys )
|
&& y1 >= mapdata->npc[i]->bl.y-ys && y0 <= mapdata->npc[i]->bl.y+ys )
|
||||||
break; // found a npc
|
break; // found a npc
|
||||||
}
|
}
|
||||||
if (i==mapdata->npc_num)
|
if (i == mapdata->npc_num_area)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (mapdata->npc[i]->bl.id);
|
return (mapdata->npc[i]->bl.id);
|
||||||
@ -2164,7 +2182,20 @@ int npc_remove_map(struct npc_data* nd)
|
|||||||
if( i == mapdata->npc_num ) return 2; //failed to find it?
|
if( i == mapdata->npc_num ) return 2; //failed to find it?
|
||||||
|
|
||||||
mapdata->npc_num--;
|
mapdata->npc_num--;
|
||||||
|
if (i >= mapdata->npc_num_area)
|
||||||
mapdata->npc[i] = mapdata->npc[ mapdata->npc_num ];
|
mapdata->npc[i] = mapdata->npc[ mapdata->npc_num ];
|
||||||
|
else if (i >= mapdata->npc_num_warp) {
|
||||||
|
mapdata->npc_num_area--;
|
||||||
|
mapdata->npc[i] = mapdata->npc[ mapdata->npc_num_area ];
|
||||||
|
mapdata->npc[ mapdata->npc_num_area ] = mapdata->npc[ mapdata->npc_num ];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mapdata->npc_num_warp--;
|
||||||
|
mapdata->npc_num_area--;
|
||||||
|
mapdata->npc[i] = mapdata->npc[ mapdata->npc_num_warp ];
|
||||||
|
mapdata->npc[ mapdata->npc_num_warp ] = mapdata->npc[ mapdata->npc_num_area ];
|
||||||
|
mapdata->npc[ mapdata->npc_num_area ] = mapdata->npc[ mapdata->npc_num ];
|
||||||
|
}
|
||||||
mapdata->npc[ mapdata->npc_num ] = NULL;
|
mapdata->npc[ mapdata->npc_num ] = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2570,7 +2601,6 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
|
|||||||
struct npc_data *nd;
|
struct npc_data *nd;
|
||||||
|
|
||||||
nd = npc_create_npc(from_mapid, from_x, from_y);
|
nd = npc_create_npc(from_mapid, from_x, from_y);
|
||||||
map_addnpc(from_mapid, nd);
|
|
||||||
|
|
||||||
safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname));
|
safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname));
|
||||||
if (npc_name2id(nd->exname) != NULL)
|
if (npc_name2id(nd->exname) != NULL)
|
||||||
@ -2597,6 +2627,7 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
|
|||||||
nd->bl.type = BL_NPC;
|
nd->bl.type = BL_NPC;
|
||||||
nd->subtype = NPCTYPE_WARP;
|
nd->subtype = NPCTYPE_WARP;
|
||||||
nd->trigger_on_hidden = false;
|
nd->trigger_on_hidden = false;
|
||||||
|
map_addnpc(from_mapid, nd);
|
||||||
npc_setcells(nd);
|
npc_setcells(nd);
|
||||||
if(map_addblock(&nd->bl))
|
if(map_addblock(&nd->bl))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2654,7 +2685,6 @@ static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
nd = npc_create_npc(m, x, y);
|
nd = npc_create_npc(m, x, y);
|
||||||
map_addnpc(m, nd);
|
|
||||||
npc_parsename(nd, w3, start, buffer, filepath);
|
npc_parsename(nd, w3, start, buffer, filepath);
|
||||||
|
|
||||||
if (!battle_config.warp_point_debug)
|
if (!battle_config.warp_point_debug)
|
||||||
@ -2675,6 +2705,7 @@ static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const
|
|||||||
nd->trigger_on_hidden = true;
|
nd->trigger_on_hidden = true;
|
||||||
else
|
else
|
||||||
nd->trigger_on_hidden = false;
|
nd->trigger_on_hidden = false;
|
||||||
|
map_addnpc(m, nd);
|
||||||
npc_setcells(nd);
|
npc_setcells(nd);
|
||||||
if(map_addblock(&nd->bl)) //couldn't add on map
|
if(map_addblock(&nd->bl)) //couldn't add on map
|
||||||
return strchr(start,'\n');
|
return strchr(start,'\n');
|
||||||
@ -3376,7 +3407,6 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wnd = npc_create_npc(m, snd->bl.x, snd->bl.y);
|
wnd = npc_create_npc(m, snd->bl.x, snd->bl.y);
|
||||||
map_addnpc(m, wnd);
|
|
||||||
safestrncpy(wnd->name, "", ARRAYLENGTH(wnd->name));
|
safestrncpy(wnd->name, "", ARRAYLENGTH(wnd->name));
|
||||||
safestrncpy(wnd->exname, newname, ARRAYLENGTH(wnd->exname));
|
safestrncpy(wnd->exname, newname, ARRAYLENGTH(wnd->exname));
|
||||||
wnd->class_ = JT_WARPNPC;
|
wnd->class_ = JT_WARPNPC;
|
||||||
@ -3390,6 +3420,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
|
|||||||
wnd->subtype = NPCTYPE_WARP;
|
wnd->subtype = NPCTYPE_WARP;
|
||||||
wnd->trigger_on_hidden = snd->trigger_on_hidden;
|
wnd->trigger_on_hidden = snd->trigger_on_hidden;
|
||||||
wnd->src_id = snd->src_id ? snd->src_id : snd->bl.id;
|
wnd->src_id = snd->src_id ? snd->src_id : snd->bl.id;
|
||||||
|
map_addnpc(m, wnd);
|
||||||
npc_setcells(wnd);
|
npc_setcells(wnd);
|
||||||
if(map_addblock(&wnd->bl))
|
if(map_addblock(&wnd->bl))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -333,7 +333,8 @@ struct map_session_data {
|
|||||||
unsigned short mapindex;
|
unsigned short mapindex;
|
||||||
unsigned char head_dir; //0: Look forward. 1: Look right, 2: Look left.
|
unsigned char head_dir; //0: Look forward. 1: Look right, 2: Look left.
|
||||||
t_tick client_tick;
|
t_tick client_tick;
|
||||||
int npc_id,areanpc_id,npc_shopid,touching_id; //for script follow scriptoid; ,npcid
|
int npc_id,npc_shopid; //for script follow scriptoid; ,npcid
|
||||||
|
std::vector<int> areanpc, npc_ontouch_; ///< Array of OnTouch and OnTouch_ NPC ID
|
||||||
int npc_item_flag; //Marks the npc_id with which you can use items during interactions with said npc (see script command enable_itemuse)
|
int npc_item_flag; //Marks the npc_id with which you can use items during interactions with said npc (see script command enable_itemuse)
|
||||||
int npc_menu; // internal variable, used in npc menu handling
|
int npc_menu; // internal variable, used in npc menu handling
|
||||||
int npc_amount;
|
int npc_amount;
|
||||||
|
@ -11851,7 +11851,7 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( opt_flag&2 && sd && sd->touching_id )
|
if( opt_flag&2 && sd && !sd->npc_ontouch_.empty() )
|
||||||
npc_touchnext_areanpc(sd,false); // Run OnTouch_ on next char in range
|
npc_touchnext_areanpc(sd,false); // Run OnTouch_ on next char in range
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -444,14 +444,14 @@ static TIMER_FUNC(unit_walktoxy_timer){
|
|||||||
|
|
||||||
switch(bl->type) {
|
switch(bl->type) {
|
||||||
case BL_PC:
|
case BL_PC:
|
||||||
if( sd->touching_id )
|
if( !sd->npc_ontouch_.empty() )
|
||||||
npc_touchnext_areanpc(sd,false);
|
npc_touchnext_areanpc(sd,false);
|
||||||
if(map_getcell(bl->m,x,y,CELL_CHKNPC)) {
|
if(map_getcell(bl->m,x,y,CELL_CHKNPC)) {
|
||||||
npc_touch_areanpc(sd,bl->m,x,y);
|
npc_touch_areanpc(sd,bl->m,x,y);
|
||||||
if (bl->prev == NULL) // Script could have warped char, abort remaining of the function.
|
if (bl->prev == NULL) // Script could have warped char, abort remaining of the function.
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
sd->areanpc_id=0;
|
sd->areanpc.clear();
|
||||||
pc_cell_basilica(sd);
|
pc_cell_basilica(sd);
|
||||||
break;
|
break;
|
||||||
case BL_MOB:
|
case BL_MOB:
|
||||||
@ -971,7 +971,7 @@ bool unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, boo
|
|||||||
ud->walktimer = INVALID_TIMER;
|
ud->walktimer = INVALID_TIMER;
|
||||||
|
|
||||||
if(sd) {
|
if(sd) {
|
||||||
if( sd->touching_id )
|
if( !sd->npc_ontouch_.empty() )
|
||||||
npc_touchnext_areanpc(sd,false);
|
npc_touchnext_areanpc(sd,false);
|
||||||
|
|
||||||
if(map_getcell(bl->m,bl->x,bl->y,CELL_CHKNPC)) {
|
if(map_getcell(bl->m,bl->x,bl->y,CELL_CHKNPC)) {
|
||||||
@ -980,7 +980,7 @@ bool unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, boo
|
|||||||
if (bl->prev == NULL) // Script could have warped char, abort remaining of the function.
|
if (bl->prev == NULL) // Script could have warped char, abort remaining of the function.
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
sd->areanpc_id=0;
|
sd->areanpc.clear();
|
||||||
|
|
||||||
if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > PET_INTIMATE_NONE ) {
|
if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > PET_INTIMATE_NONE ) {
|
||||||
// Check if pet needs to be teleported. [Skotlex]
|
// Check if pet needs to be teleported. [Skotlex]
|
||||||
@ -1102,13 +1102,13 @@ int unit_blown(struct block_list* bl, int dx, int dy, int count, enum e_skill_bl
|
|||||||
clif_blown(bl);
|
clif_blown(bl);
|
||||||
|
|
||||||
if(sd) {
|
if(sd) {
|
||||||
if(sd->touching_id)
|
if(!sd->npc_ontouch_.empty())
|
||||||
npc_touchnext_areanpc(sd, false);
|
npc_touchnext_areanpc(sd, false);
|
||||||
|
|
||||||
if(map_getcell(bl->m, bl->x, bl->y, CELL_CHKNPC))
|
if(map_getcell(bl->m, bl->x, bl->y, CELL_CHKNPC))
|
||||||
npc_touch_areanpc(sd, bl->m, bl->x, bl->y);
|
npc_touch_areanpc(sd, bl->m, bl->x, bl->y);
|
||||||
else
|
else
|
||||||
sd->areanpc_id = 0;
|
sd->areanpc.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2955,7 +2955,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
|
|||||||
if(sd->menuskill_id)
|
if(sd->menuskill_id)
|
||||||
sd->menuskill_id = sd->menuskill_val = 0;
|
sd->menuskill_id = sd->menuskill_val = 0;
|
||||||
|
|
||||||
if( sd->touching_id )
|
if( !sd->npc_ontouch_.empty() )
|
||||||
npc_touchnext_areanpc(sd,true);
|
npc_touchnext_areanpc(sd,true);
|
||||||
|
|
||||||
// Check if warping and not changing the map.
|
// Check if warping and not changing the map.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user