From 7966264fdf4271c8b247d572c2eadef88dcaf4b4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 17 Nov 2014 23:26:43 +0300 Subject: Allow continue npc script execution if distance to npc bigger than limit. --- src/Makefile.am | 2 ++ src/map/init.c | 2 ++ src/map/npc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/map/npc.h | 9 +++++++++ 4 files changed, 60 insertions(+) create mode 100644 src/map/npc.c create mode 100644 src/map/npc.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 51ef27a..c739693 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,8 @@ LOGIN_SRC = login/config.c \ MAP_SRC = map/dummy.c \ map/dummy.h \ map/init.c \ + map/npc.c \ + map/npc.h \ map/parse.c \ map/parse.h \ map/pc.c \ diff --git a/src/map/init.c b/src/map/init.c index 52c5f58..795a331 100644 --- a/src/map/init.c +++ b/src/map/init.c @@ -35,6 +35,7 @@ #include "common/interfaces.h" #include "map/dummy.h" +#include "map/npc.h" #include "map/parse.h" #include "map/script.h" #include "map/pc.h" @@ -121,6 +122,7 @@ HPExport void plugin_init (void) addPacket(0x7530, 22, map_parse_version, hpClif_Parse); addHookPre("pc->readparam", epc_readparam_pre); addHookPre("pc->setregistry", epc_setregistry); + addHookPre("npc->checknear", enpc_checknear); langScriptId = script->add_str("Lang"); } diff --git a/src/map/npc.c b/src/map/npc.c new file mode 100644 index 0000000..054505d --- /dev/null +++ b/src/map/npc.c @@ -0,0 +1,47 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "../../../common/HPMi.h" +#include "../../../common/malloc.h" +#include "../../../common/mmo.h" +#include "../../../common/socket.h" +#include "../../../common/strlib.h" +#include "../../../map/npc.h" +#include "../../../map/pc.h" + +#include "map/npc.h" + +struct npc_data* enpc_checknear(struct map_session_data* sd, struct block_list* bl) +{ + struct npc_data *nd; + + hookStop(); + + if (!sd) + return NULL; + + if (bl == NULL) + return NULL; + if (bl->type != BL_NPC) + return NULL; + nd = (TBL_NPC*)bl; + + if (sd->npc_id == bl->id) + return nd; + + if (nd->class_ < 0) //Class-less npc, enable click from anywhere. + return nd; + + if (bl->m != sd->bl.m || + bl->x < sd->bl.x - AREA_SIZE - 1 || bl->x > sd->bl.x + AREA_SIZE + 1 || + bl->y < sd->bl.y - AREA_SIZE - 1 || bl->y > sd->bl.y + AREA_SIZE + 1) + { + return NULL; + } + + return nd; +} diff --git a/src/map/npc.h b/src/map/npc.h new file mode 100644 index 0000000..8053352 --- /dev/null +++ b/src/map/npc.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_NPC +#define EVOL_MAP_NPC + +struct npc_data* enpc_checknear(struct map_session_data* sd, struct block_list* bl); + +#endif // EVOL_MAP_NPC -- cgit v1.2.3-60-g2f50