From b6690d7bb05e75d28891f360f42e0dfe19ea0904 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 8 Sep 2016 21:04:27 +0300 Subject: Add script command navigateto. Add packet for this command. Based on rAthena commits: commit 4f13007fec7f08c265620a71c3bc4806d186c0f1 Author: Lemongrass3110 Date: Sun Mar 6 21:48:47 2016 +0100 commit 809f220b9f5ef70ee062ee56ae6e8d5f56cb5d32 Author: aleos89 Date: Sun Mar 6 16:15:54 2016 -0500 commit 179f73424934d528ebe494dfb66503c182eacb09 Author: aleos89 Date: Sun Mar 6 16:10:15 2016 -0500 --- doc/script_commands.txt | 33 +++++++++++++++++++++++++++++ src/map/clif.c | 42 +++++++++++++++++++++++++++++++++++++ src/map/clif.h | 1 + src/map/script.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ src/map/script.h | 11 ++++++++++ 5 files changed, 142 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 04d2c0c16..eb7e0cd9d 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7203,6 +7203,39 @@ Example: // coordinates are legit). movenpc("Bugga", 100, 20); +--------------------------------------- + +*navigateto(""{,,,,,,}); + +Generates a navigation for attached or specified character. Requires client +2011-10-10aRagEXE or newer. + +The flag specifies how the client will calculate the specific route. + +Valid flags are: + NAV_NONE - No services + NAV_AIRSHIP_ONLY - Airship only + NAV_SCROLL_ONLY - Scroll only + NAV_AIRSHIP_AND_SCROLL - Airship and Scroll + NAV_KAFRA_ONLY - Kafra only + NAV_KAFRA_AND_AIRSHIP - Kafra and Airship + NAV_KAFRA_AND_SCROLL - Kafra and Scroll + NAV_ALL - All services + +When flag is not specified, the default value is NAV_KAFRA_AND_AIRSHIP. + +The hide_window specifies whether to display (0) or hide (1) the navigation window. +By default the window is hidden. + +You can specify the monster_id in combination with a mapname to make the +navigation system tell you, that you have reached the desired mob. + +Note: +The client requires custom monster spawns be in the navigation file +for using the embedded client Navigation feature to work properly. In this +instance sending the player to the map where the monster spawns is a simpler +solution rather than sending the map and the monster_id. + --------------------------------------- //===================================== 6 - Other Commands diff --git a/src/map/clif.c b/src/map/clif.c index 7e4f6b825..749b3d068 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -18861,6 +18861,47 @@ void clif_selectcart(struct map_session_data *sd) #endif } +/// Starts navigation to the given target on client side +void clif_navigate_to(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id) +{ +#if PACKETVER >= 20111010 + int fd; + + nullpo_retv(sd); + nullpo_retv(mapname); + fd = sd->fd; + WFIFOHEAD(fd, 27); + WFIFOW(fd, 0) = 0x8e2; + + // How detailed will our navigation be? + if (mob_id > 0) { + x = 0; + y = 0; + WFIFOB(fd, 2) = 3; // monster with destination field + } else if (x > 0 && y > 0) { + WFIFOB(fd, 2) = 0; // with coordinates + } else { + x = 0; + y = 0; + WFIFOB(fd, 2) = 1; // without coordinates(will fail if you are already on the map) + } + + // Which services can be used for transportation? + WFIFOB(fd, 3) = flag; + // If this flag is set, the navigation window will not be opened up + WFIFOB(fd, 4) = hideWindow; + // Target map + safestrncpy((char*)WFIFOP(fd, 5), mapname, MAP_NAME_LENGTH_EXT); + // Target x + WFIFOW(fd, 21) = x; + // Target y + WFIFOW(fd, 23) = y; + // Target monster ID + WFIFOW(fd, 25) = mob_id; + WFIFOSET(fd, 27); +#endif +} + /** * Returns the name of the given bl, in a client-friendly format. * @@ -19704,6 +19745,7 @@ void clif_defaults(void) { clif->selectcart = clif_selectcart; /* */ clif->isdisguised = clif_isdisguised; + clif->navigate_to = clif_navigate_to; clif->bl_type = clif_bl_type; /*------------------------ diff --git a/src/map/clif.h b/src/map/clif.h index 8f6950666..3203a3e66 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1111,6 +1111,7 @@ struct clif_interface { void (*ackmergeitems) (int fd, struct map_session_data *sd); /* */ bool (*isdisguised) (struct block_list* bl); + void (*navigate_to) (struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id); unsigned char (*bl_type) (struct block_list *bl); /*------------------------ *- Parse Incoming Packet diff --git a/src/map/script.c b/src/map/script.c index 2633c1e5f..f8754660c 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -20506,6 +20506,48 @@ BUILDIN(pcre_match) return true; } +/** + * navigateto(""{,,,,,,}); + */ +BUILDIN(navigateto) +{ +#if PACKETVER >= 20111010 + struct map_session_data* sd; + const char *mapname; + uint16 x = 0; + uint16 y = 0; + uint16 monster_id = 0; + uint8 flag = NAV_KAFRA_AND_AIRSHIP; + bool hideWindow = true; + + mapname = script_getstr(st, 2); + + if (script_hasdata(st, 3)) + x = script_getnum(st, 3); + if (script_hasdata(st, 4)) + y = script_getnum(st, 4); + if (script_hasdata(st, 5)) + flag = (uint8)script_getnum(st, 5); + if (script_hasdata(st, 6)) + hideWindow = script_getnum(st, 6) ? true : false; + if (script_hasdata(st, 7)) + monster_id = script_getnum(st, 7); + + if (script_hasdata(st, 8)) { + sd = map->charid2sd(script_getnum(st, 8)); + } else { + sd = script->rid2sd(st); + } + + clif->navigate_to(sd, mapname, x, y, flag, hideWindow, monster_id); + + return true; +#else + ShowError("Navigation system works only with packet version >= 20111010"); + return false; +#endif +} + /** * Adds a built-in script function. * @@ -21175,6 +21217,9 @@ void script_parse_builtin(void) { BUILDIN_DEF(purchaseok,""), BUILDIN_DEF(shopcount, "i"), + /* Navigation */ + BUILDIN_DEF(navigateto, "s??????"), + BUILDIN_DEF(channelmes, "ss"), BUILDIN_DEF(showscript, "s?"), BUILDIN_DEF(mergeitem,""), @@ -21329,6 +21374,16 @@ void script_hardcoded_constants(void) script->set_constant("EQP_SHADOW_ACC_R", EQP_SHADOW_ACC_R, false, false); script->set_constant("EQP_SHADOW_ACC_L", EQP_SHADOW_ACC_L, false, false); + script->constdb_comment("Navigation constants, use with *navigateto*"); + script->set_constant("NAV_NONE", NAV_NONE, false, false); + script->set_constant("NAV_AIRSHIP_ONLY", NAV_AIRSHIP_ONLY, false, false); + script->set_constant("NAV_SCROLL_ONLY", NAV_SCROLL_ONLY, false, false); + script->set_constant("NAV_AIRSHIP_AND_SCROLL", NAV_AIRSHIP_AND_SCROLL, false, false); + script->set_constant("NAV_KAFRA_ONLY", NAV_KAFRA_ONLY, false, false); + script->set_constant("NAV_KAFRA_AND_AIRSHIP", NAV_KAFRA_AND_AIRSHIP, false, false); + script->set_constant("NAV_KAFRA_AND_SCROLL", NAV_KAFRA_AND_SCROLL, false, false); + script->set_constant("NAV_ALL", NAV_ALL, false, false); + script->constdb_comment("Renewal"); #ifdef RENEWAL script->set_constant("RENEWAL", 1, false, false); diff --git a/src/map/script.h b/src/map/script.h index c4c082263..a69000991 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -338,6 +338,17 @@ enum { MF_NOVIEWID }; +enum navigation_service { + NAV_NONE = 0, + NAV_AIRSHIP_ONLY = 1, + NAV_SCROLL_ONLY = 10, + NAV_AIRSHIP_AND_SCROLL = NAV_AIRSHIP_ONLY + NAV_SCROLL_ONLY, //11 + NAV_KAFRA_ONLY = 100, + NAV_KAFRA_AND_AIRSHIP = NAV_KAFRA_ONLY + NAV_AIRSHIP_ONLY, // 101 + NAV_KAFRA_AND_SCROLL = NAV_KAFRA_ONLY + NAV_SCROLL_ONLY, // 110 + NAV_ALL = NAV_AIRSHIP_ONLY + NAV_SCROLL_ONLY + NAV_KAFRA_ONLY // 111-255 +}; + /** * Structures **/ -- cgit v1.2.3-60-g2f50