From e5d0f388bd40dbadebe1d18a4a6c2805648baa13 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Wed, 8 Apr 2020 07:43:05 +0200 Subject: Add pc_hide() function --- src/map/pc.c | 31 +++++++++++++++++++++++++++++++ src/map/pc.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/map/pc.c b/src/map/pc.c index 90282209b..194c2cbb1 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9288,6 +9288,36 @@ static int pc_changelook(struct map_session_data *sd, int type, int val) return 0; } +/** + * Hides a character. + * + * @param sd The character to hide. + * @param show_msg Whether to show message to the character or not. + * + **/ +static void pc_hide(struct map_session_data *sd, bool show_msg) +{ + nullpo_retv(sd); + + clif->clearunit_area(&sd->bl, CLR_OUTSIGHT); + sd->sc.option |= OPTION_INVISIBLE; + sd->vd.class = INVISIBLE_CLASS; + + if (show_msg) + clif->message(sd->fd, atcommand->msgsd(sd, 11)); // Invisible: On + + // Decrement the number of pvp players on the map. + map->list[sd->bl.m].users_pvp--; + + if (map->list[sd->bl.m].flag.pvp != 0 && map->list[sd->bl.m].flag.pvp_nocalcrank == 0 + && sd->pvp_timer != INVALID_TIMER) { // Unregister the player for ranking. + timer->delete(sd->pvp_timer, pc->calc_pvprank_timer); + sd->pvp_timer = INVALID_TIMER; + } + + clif->changeoption(&sd->bl); +} + /*========================================== * Give an option (type) to player (sd) and display it to client *------------------------------------------*/ @@ -12824,6 +12854,7 @@ void pc_defaults(void) pc->itemheal = pc_itemheal; pc->percentheal = pc_percentheal; pc->jobchange = pc_jobchange; + pc->hide = pc_hide; pc->setoption = pc_setoption; pc->setcart = pc_setcart; pc->setfalcon = pc_setfalcon; diff --git a/src/map/pc.h b/src/map/pc.h index 2699b7882..b895c75db 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -1044,6 +1044,7 @@ END_ZEROED_BLOCK; /* End */ int (*itemheal) (struct map_session_data *sd,int itemid, int hp,int sp); int (*percentheal) (struct map_session_data *sd,int hp,int sp); int (*jobchange) (struct map_session_data *sd, int class, int upper); + void (*hide) (struct map_session_data *sd, bool show_msg); int (*setoption) (struct map_session_data *sd,int type); int (*setcart) (struct map_session_data* sd, int type); void (*setfalcon) (struct map_session_data *sd, bool flag); -- cgit v1.2.3-70-g09d2 From 18c93185ecf6b150d027a070c49c46dbd2ec45c1 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Wed, 8 Apr 2020 07:48:30 +0200 Subject: Add pc_unhide() function --- src/map/pc.c | 37 +++++++++++++++++++++++++++++++++++++ src/map/pc.h | 1 + 2 files changed, 38 insertions(+) diff --git a/src/map/pc.c b/src/map/pc.c index 194c2cbb1..ded87f368 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9318,6 +9318,42 @@ static void pc_hide(struct map_session_data *sd, bool show_msg) clif->changeoption(&sd->bl); } +/** + * Unhides a character. + * + * @param sd The character to unhide. + * @param show_msg Whether to show message to the character or not. + * + **/ +static void pc_unhide(struct map_session_data *sd, bool show_msg) +{ + nullpo_retv(sd); + + sd->sc.option &= ~OPTION_INVISIBLE; + + if (sd->disguise != -1) + status->set_viewdata(&sd->bl, sd->disguise); + else + status->set_viewdata(&sd->bl, sd->status.class); + + if (show_msg) + clif->message(sd->fd, atcommand->msgsd(sd, 10)); // Invisible: Off + + // Increment the number of pvp players on the map. + map->list[sd->bl.m].users_pvp++; + + if (map->list[sd->bl.m].flag.pvp != 0 && map->list[sd->bl.m].flag.pvp_nocalcrank == 0) // Register the player for ranking. + sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0); + + // bugreport:2266 + map->foreachinmovearea(clif->insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl); + + if (sd->disguise != -1) + clif->spawn_unit(&sd->bl, AREA_WOS); + + clif->changeoption(&sd->bl); +} + /*========================================== * Give an option (type) to player (sd) and display it to client *------------------------------------------*/ @@ -12855,6 +12891,7 @@ void pc_defaults(void) pc->percentheal = pc_percentheal; pc->jobchange = pc_jobchange; pc->hide = pc_hide; + pc->unhide = pc_unhide; pc->setoption = pc_setoption; pc->setcart = pc_setcart; pc->setfalcon = pc_setfalcon; diff --git a/src/map/pc.h b/src/map/pc.h index b895c75db..6b2b44e2a 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -1045,6 +1045,7 @@ END_ZEROED_BLOCK; /* End */ int (*percentheal) (struct map_session_data *sd,int hp,int sp); int (*jobchange) (struct map_session_data *sd, int class, int upper); void (*hide) (struct map_session_data *sd, bool show_msg); + void (*unhide) (struct map_session_data *sd, bool show_msg); int (*setoption) (struct map_session_data *sd,int type); int (*setcart) (struct map_session_data* sd, int type); void (*setfalcon) (struct map_session_data *sd, bool flag); -- cgit v1.2.3-70-g09d2 From df6075407ae9434a2179d9d7bf75a9e341bcd595 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Wed, 8 Apr 2020 07:52:48 +0200 Subject: Use pc_(un)hide() in ACMD(hide) --- src/map/atcommand.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 91ddc3ef9..00073e544 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -962,39 +962,10 @@ ACMD(option) *------------------------------------------*/ ACMD(hide) { - if (pc_isinvisible(sd)) { - sd->sc.option &= ~OPTION_INVISIBLE; - if (sd->disguise != -1 ) - status->set_viewdata(&sd->bl, sd->disguise); - else - status->set_viewdata(&sd->bl, sd->status.class); - clif->message(fd, msg_fd(fd,10)); // Invisible: Off - - // increment the number of pvp players on the map - map->list[sd->bl.m].users_pvp++; - - if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank ) { - // register the player for ranking calculations - sd->pvp_timer = timer->add( timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0 ); - } - //bugreport:2266 - map->foreachinmovearea(clif->insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl); - } else { - clif->clearunit_area(&sd->bl, CLR_OUTSIGHT); - sd->sc.option |= OPTION_INVISIBLE; - sd->vd.class = INVISIBLE_CLASS; - clif->message(fd, msg_fd(fd,11)); // Invisible: On - - // decrement the number of pvp players on the map - map->list[sd->bl.m].users_pvp--; - - if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ) { - // unregister the player for ranking - timer->delete( sd->pvp_timer, pc->calc_pvprank_timer ); - sd->pvp_timer = INVALID_TIMER; - } - } - clif->changeoption(&sd->bl); + if (pc_isinvisible(sd)) + pc->unhide(sd, true); + else + pc->hide(sd, true); return true; } -- cgit v1.2.3-70-g09d2 From b7c6f652d37d1a5711dfa3b451731510a6cec5de Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Wed, 8 Apr 2020 07:57:27 +0200 Subject: Use pc_(un)hide() in pc_setoption() --- src/map/pc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/map/pc.c b/src/map/pc.c index ded87f368..d8bae7b87 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9365,7 +9365,13 @@ static int pc_setoption(struct map_session_data *sd, int type) //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex] sd->sc.option=type; - clif->changeoption(&sd->bl); + + if ((p_type & OPTION_INVISIBLE) != 0 && (type & OPTION_INVISIBLE) == 0) // Unhide character. + pc->unhide(sd, false); + else if ((p_type & OPTION_INVISIBLE) == 0 && (type & OPTION_INVISIBLE) != 0) // Hide character. + pc->hide(sd, false); + else + clif->changeoption(&sd->bl); if( (type&OPTION_RIDING && !(p_type&OPTION_RIDING)) || (type&OPTION_DRAGON && !(p_type&OPTION_DRAGON) && pc->checkskill(sd,RK_DRAGONTRAINING) > 0) ) { // Mounting -- cgit v1.2.3-70-g09d2