diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-11-29 17:57:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-11-29 17:57:23 +0300 |
commit | f518402fc06a3bc4824af47e6c979ce649326cf4 (patch) | |
tree | ad85be5ef125756946229694ead74091c44bdb80 /src | |
parent | f013f783501bb92d88133d7ac9a7be6501d0dd8e (diff) | |
download | evol-hercules-f518402fc06a3bc4824af47e6c979ce649326cf4.tar.gz evol-hercules-f518402fc06a3bc4824af47e6c979ce649326cf4.tar.bz2 evol-hercules-f518402fc06a3bc4824af47e6c979ce649326cf4.tar.xz evol-hercules-f518402fc06a3bc4824af47e6c979ce649326cf4.zip |
Add checking for npc activate distance.
Diffstat (limited to 'src')
-rw-r--r-- | src/map/data/npcd.c | 2 | ||||
-rw-r--r-- | src/map/npc.c | 24 | ||||
-rw-r--r-- | src/map/struct/npcdext.h | 1 |
3 files changed, 24 insertions, 3 deletions
diff --git a/src/map/data/npcd.c b/src/map/data/npcd.c index 29e48a7..535c953 100644 --- a/src/map/data/npcd.c +++ b/src/map/data/npcd.c @@ -10,6 +10,7 @@ #include "../../../common/mmo.h" #include "../../../common/socket.h" #include "../../../common/strlib.h" +#include "../../../map/battle.h" #include "../../../map/npc.h" #include "map/data/npcd.h" @@ -33,5 +34,6 @@ struct NpcdExt *npcd_create(void) if (!data) return NULL; data->init = false; + data->areaSize = AREA_SIZE; return data; } diff --git a/src/map/npc.c b/src/map/npc.c index 3eabaa9..62dccfe 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -15,7 +15,9 @@ #include "../../../map/pc.h" #include "map/data/mapd.h" +#include "map/data/npcd.h" #include "map/struct/mapdext.h" +#include "map/struct/npcdext.h" #include "map/npc.h" struct npc_data* enpc_checknear(struct map_session_data* sd, struct block_list* bl) @@ -39,13 +41,29 @@ struct npc_data* enpc_checknear(struct map_session_data* sd, struct block_list* 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) + const int npcX = bl->x; + const int npcY = bl->y; + const int x = sd->bl.x; + const int y = sd->bl.y; + + if (bl->m != sd->bl.m + || npcX < x - AREA_SIZE - 1 || npcX > x + AREA_SIZE + 1 + || npcY < y - AREA_SIZE - 1 || npcY > y + AREA_SIZE + 1) { return NULL; } + struct NpcdExt *data = npcd_get(nd); + if (data) + { + const int size = data->areaSize; + if (npcX < x - size || npcX > x + size + || npcY < y - size || npcY > y + size) + { + return NULL; + } + } + return nd; } diff --git a/src/map/struct/npcdext.h b/src/map/struct/npcdext.h index 2158f2c..2ba1b72 100644 --- a/src/map/struct/npcdext.h +++ b/src/map/struct/npcdext.h @@ -6,6 +6,7 @@ struct NpcdExt { + int areaSize; bool init; }; |