summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-23 00:16:51 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-23 00:16:51 +0300
commitab9362782312ad81ef1c1d47dcac464607a710a2 (patch)
treec0ae55743e75a614718f3dd8fef1df7e23644336 /src/map
parent1b827f192497a2b57150df9f56d0fa82df890b0b (diff)
downloadevol-hercules-ab9362782312ad81ef1c1d47dcac464607a710a2.tar.gz
evol-hercules-ab9362782312ad81ef1c1d47dcac464607a710a2.tar.bz2
evol-hercules-ab9362782312ad81ef1c1d47dcac464607a710a2.tar.xz
evol-hercules-ab9362782312ad81ef1c1d47dcac464607a710a2.zip
map: if got buy command for market npc, show market instead of buy shop.
Diffstat (limited to 'src/map')
-rw-r--r--src/map/init.c1
-rw-r--r--src/map/npc.c59
-rw-r--r--src/map/npc.h2
3 files changed, 62 insertions, 0 deletions
diff --git a/src/map/init.c b/src/map/init.c
index 6a025a8..2757aeb 100644
--- a/src/map/init.c
+++ b/src/map/init.c
@@ -104,6 +104,7 @@ HPExport void plugin_init (void)
addHookPre("pc->unequipitem_pos", epc_unequipitem_pos);
addHookPre("pc->can_attack", epc_can_attack);
addHookPre("npc->parse_unknown_mapflag", enpc_parse_unknown_mapflag);
+ addHookPre("npc->buysellsel", enpc_buysellsel);
addHookPre("clif->quest_send_list", eclif_quest_send_list);
addHookPre("clif->quest_add", eclif_quest_add);
addHookPre("clif->charnameack", eclif_charnameack);
diff --git a/src/map/npc.c b/src/map/npc.c
index 7b15491..74ec586 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -52,3 +52,62 @@ void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char
*retval = EXIT_FAILURE;
}
}
+
+int enpc_buysellsel(struct map_session_data* sd, int *id, int *type)
+{
+ struct npc_data *nd;
+
+ if (!sd)
+ return 1;
+
+ if ((nd = npc->checknear(sd, map->id2bl(*id))) == NULL)
+ {
+ hookStop();
+ return 1;
+ }
+
+ if (nd->option & OPTION_INVISIBLE) // can't buy if npc is not visible (hack?)
+ {
+ hookStop();
+ return 1;
+ }
+
+ if (*type == 0 && nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type == NST_MARKET)
+ {
+ clif->npc_market_open(sd, nd);
+ hookStop();
+ return 0;
+ }
+
+ if (nd->subtype != SHOP && !(nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->items))
+ {
+ if (nd->subtype == SCRIPT)
+ ShowError("npc_buysellsel: trader '%s' has no shop list!\n", nd->exname);
+ else
+ ShowError("npc_buysellsel: no such shop npc %d (%s)\n", *id, nd->exname);
+
+ if (sd->npc_id == *id)
+ sd->npc_id = 0;
+ hookStop();
+ return 1;
+ }
+
+ if (nd->class_ < 0 && !sd->state.callshop)
+ { // not called through a script and is not a visible NPC so an invalid call
+ hookStop();
+ return 1;
+ }
+
+ // reset the callshop state for future calls
+ sd->state.callshop = 0;
+ sd->npc_shopid = *id;
+
+ if (*type == 0)
+ clif->buylist(sd, nd);
+ else
+ clif->selllist(sd);
+
+ hookStop();
+ return 0;
+}
+
diff --git a/src/map/npc.h b/src/map/npc.h
index 54685b2..f4ca1b9 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -7,4 +7,6 @@
void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start,
const char* buffer, const char* filepath, int *retval);
+int enpc_buysellsel(struct map_session_data* sd, int *id, int *type);
+
#endif // EVOL_MAP_NPC