viewing paste topic/11349-p showbuff_0.4.c | C

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
//===== Hercules Plugin ======================================
//= @showbuff
//===== By: ==================================================
//= AnnieRuru
//===== Current Version: =====================================
//= 0.4
//===== Compatible With: ===================================== 
//= Hercules 2018-06-05
//===== Description: =========================================
//= @showbuff on the party screen Alt + Z
//===== Topic ================================================
//= http://herc.ws/board/topic/11349-partybuff-spb/
//===== Additional Comments: =================================  
//= testing ...
//= join party -> OK -> clif_party_member_info_overload
//= somebody leave party -> OK -> clif_party_withdraw_overload
//= disband party -> not yet ... I guess no need test this one
//= party member log in -> OK
//= party member log out -> OK
//= expel party -> BUG -> no choice but have to prevent them from doing so
//= you leave party -> party_leave_pre
//============================================================
 
#include "common/hercules.h"
#include "map/pc.h"
#include "map/clif.h"
#include "map/party.h"
#include "common/nullpo.h"
#include "common/socket.h"
#include "common/memmgr.h"
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
    "showbuff",
    SERVER_TYPE_MAP,
    "0.4",
    HPM_VERSION,
};
 
struct player_data {
    int buff;
    bool showbuff;
};
 
int status_change_start_post( int retVal, struct block_list *src, struct block_list *bl, enum sc_type type, int rate, int val1, int val2, int val3, int val4, int tick, int flag) {
    if ( bl->type == BL_PC && retVal > 0 ) {
        struct map_session_data *sd = BL_CAST( BL_PC, bl );
        struct party_data *p;
        if ( p = party->search(sd->status.party_id )) {
            struct player_data *ssd = getFromMSD( sd, 0 );
            int before_buff = ssd->buff;
            if ( type == SC_BLESSING )
                ssd->buff |= 0x1;
            if ( type == SC_INC_AGI )
                ssd->buff |= 0x2;
            if ( type == SC_PROTECTWEAPON || type == SC_PROTECTSHIELD || type == SC_PROTECTARMOR || type == SC_PROTECTHELM )
                if ( sd->sc.data[SC_PROTECTWEAPON] && sd->sc.data[SC_PROTECTSHIELD] && sd->sc.data[SC_PROTECTARMOR] && sd->sc.data[SC_PROTECTHELM] )
                    ssd->buff |= 0x4;
            if ( type == SC_SOULLINK )
                ssd->buff |= 0x8;
            if ( type == SC_DEVOTION )
                ssd->buff |= 0x10;
            if ( before_buff != ssd->buff ) // only send the packet if update the status is newly apply, no need to resend if just renew the status
                clif->party_info( p, NULL );
        }
    }
    return retVal;
}
 
int status_change_end_post( int retVal, struct block_list *bl, enum sc_type type, int tid, const char *file, int line ) {
    if ( bl->type == BL_PC && retVal > 0 ) {
        struct map_session_data *sd = BL_CAST( BL_PC, bl );
        struct party_data *p;
        if ( sd->state.active == 1 ) { // fix map-server crash when player logout
            if (( p = party->search(sd->status.party_id ))) {
                struct player_data *ssd = getFromMSD( sd, 0 );
                int before_buff = ssd->buff;
                if ( type == SC_BLESSING )
                    ssd->buff &= ~0x1;
                if ( type == SC_INC_AGI )
                    ssd->buff &= ~0x2;
                if ( type == SC_PROTECTWEAPON || type == SC_PROTECTSHIELD || type == SC_PROTECTARMOR || type == SC_PROTECTHELM )
                    if ( sd->sc.data[SC_PROTECTWEAPON] && sd->sc.data[SC_PROTECTSHIELD] && sd->sc.data[SC_PROTECTARMOR] && sd->sc.data[SC_PROTECTHELM] )
                        ssd->buff &= ~0x4;
                if ( type == SC_SOULLINK )
                    ssd->buff &= ~0x8;
                if ( type == SC_DEVOTION )
                    ssd->buff &= ~0x10;
                if ( before_buff != ssd->buff ) // only send the packet if update the status is newly apply, no need to resend if just renew the status
                    clif->party_info( p, NULL );
            }
        }
    }
    return retVal;
}
 
char *showing_buff( struct map_session_data *sd ) {
    struct player_data *ssd = getFromMSD( sd, 0 );
    char *temp = "\0";
    safesnprintf( temp, NAME_LENGTH, "[%s%s%s%s%s]%s",
        ( ssd->buff & 0x1 )? "B" : "_",
        ( ssd->buff & 0x2 )? "A" : "_",
        ( ssd->buff & 0x4 )? "F" : "_",
        ( ssd->buff & 0x8 )? "S" : "_",
        ( ssd->buff & 0x10 )? "+" : "_",
        sd->status.name );
    return temp;
}
 
void clif_party_info_overload( struct party_data *p, struct map_session_data *sd ) {
    struct PACKET_ZC_GROUP_LIST *packet;
    int i, c;
    unsigned char buf[sizeof(*packet) + sizeof(struct PACKET_ZC_GROUP_LIST_SUB) * MAX_PARTY];
    nullpo_retv(p);
 
    memset( buf, 0, sizeof(buf) );
    packet = (struct PACKET_ZC_GROUP_LIST *)buf;
    packet->packetType = partyinfo;
    memcpy( packet->partyName, p->party.name, NAME_LENGTH );
    for ( i = 0, c = 0; i < MAX_PARTY; ++i ) {
        struct party_member *m = &p->party.member[i];
        if ( !m->account_id )
            continue;
        packet->members[c].AID = m->account_id;
#if PACKETVER >= 20171207
        packet->members[c].GID = m->char_id;
#endif
        memcpy( packet->members[c].playerName, m->name, NAME_LENGTH );
        mapindex->getmapname_ext(mapindex_id2name(m->map), packet->members[c].mapName);
        packet->members[c].leader = (m->leader) ? 0 : 1;
        packet->members[c].offline = (m->online) ? 0 : 1;
#if PACKETVER >= 20170502
        packet->members[c].class = m->class;
        packet->members[c].baseLevel = m->lv;
#endif
        ++c;
    }
    packet->packetLen = sizeof(*packet) + c * sizeof( struct PACKET_ZC_GROUP_LIST_SUB );
    if ( sd ) {
        struct player_data *ssd = getFromMSD( sd, 0 );
        if ( ssd && ssd->showbuff ) {
            for ( i = 0, c = 0; i < MAX_PARTY; ++i ) {
                struct party_member *m = &p->party.member[i];
                if ( !m->account_id )
                    continue;
                if ( m->online && p->data[i].sd != NULL )
                    memcpy( packet->members[c].playerName, showing_buff( p->data[i].sd ), NAME_LENGTH );
                ++c;
            }
        }
        clif->send( buf, packet->packetLen, &sd->bl, SELF );
    }
    else {
        int j;
        for ( j = 0; j < MAX_PARTY; ++j ) {
            struct party_member *m1 = &p->party.member[j];
            if ( !m1 || !m1->account_id )
                continue;
            else {
                struct map_session_data *tsd = map->id2sd( m1->account_id );
                struct player_data *ssd = NULL;
                if ( !tsd )
                    continue;
                ssd = getFromMSD( tsd, 0 );
                if ( ssd && ssd->showbuff ) {
                    for ( i = 0, c = 0; i < MAX_PARTY; ++i ) {
                        struct party_member *m = &p->party.member[i];
                        if ( !m->account_id )
                            continue;
                        if ( m->online && p->data[i].sd != NULL ) {
                            memcpy( packet->members[c].playerName, showing_buff( p->data[i].sd ), NAME_LENGTH );
                        }
                        ++c;
                    }
                }
                else {
                    for ( i = 0, c = 0; i < MAX_PARTY; ++i ) {
                        struct party_member *m = &p->party.member[i];
                        if ( !m->account_id )
                            continue;
                        memcpy( packet->members[c].playerName, m->name, NAME_LENGTH );
                        ++c;
                    }
                }
                clif->send( buf, packet->packetLen, map->id2bl( m1->account_id ), SELF );
            }
        }
    }
}
 
bool pc_authok_pre( struct map_session_data **sd, int *login_id2, time_t *expiration_time, int *group_id, const struct mmo_charstatus **st, bool *changing_mapservers ) {
    struct player_data *ssd;
    CREATE( ssd, struct player_data, true );
    ssd->buff = 0;
    ssd->showbuff = 0;
    addToMSD( *sd, ssd, 0, true );
    return 0;
}
 
void clif_party_member_info_overload( struct party_data *p, struct map_session_data *sd ) {
    return;
}
 
void clif_party_withdraw_overload( struct party_data *p, struct map_session_data *sd, int account_id, const char *name, int flag ) {
    unsigned char buf[64];
    nullpo_retv(p);
    nullpo_retv(name);
    if ( !sd && !(flag & 0xf0) ) {
        int i;
        ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != NULL );
        if ( i != MAX_PARTY )
            sd = p->data[i].sd;
    }
    if ( !sd )
        return;
    WBUFW(buf,0) = 0x105;
    WBUFL(buf,2) = account_id;
    memcpy( WBUFP(buf,6), name, NAME_LENGTH );
    WBUFB(buf,30) = flag & 0x0f;
    if ( !(flag & 0xf0) ) {
        for ( int i = 0; i < MAX_PARTY; ++i ) {
            struct party_member *m = &p->party.member[i];
            if ( !m || !m->account_id )
                continue;
            else {
                struct map_session_data *tsd = map->id2sd( m->account_id );
                struct player_data *ssd = NULL;
                if ( !tsd )
                    continue;
                ssd = getFromMSD( tsd, 0 );
                if ( ssd && ssd->showbuff )
                    memcpy( WBUFP(buf,6), showing_buff( sd ), NAME_LENGTH );
                else
                    memcpy( WBUFP(buf,6), name, NAME_LENGTH );
                clif->send( buf, 31, map->id2bl( m->account_id ), SELF );
            }
        }
    }
    else
        clif->send( buf, 31, &sd->bl, SELF );
}
 
int party_removemember_pre( struct map_session_data **sd, int *account_id, const char **name ) {
    struct player_data *ssd = getFromMSD( *sd, 0 );
    if ( ssd->showbuff ) {      
        clif->message( (*sd)->fd, "You cannot expel a party member while @showbuff is turn ON." );
        hookStop();
    }
    return 0;
}
 
int party_leave_pre( struct map_session_data **sd ) {
    struct party_data *p;
    int i;
    nullpo_ret(*sd);
    p = party->search( (*sd)->status.party_id );
    if ( p == NULL )
        return 0;
    ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == (*sd)->status.account_id && p->party.member[i].char_id == (*sd)->status.char_id );
    if ( i == MAX_PARTY )
        return 0;
    else {
        struct player_data *ssd = getFromMSD( *sd, 0 );
        if ( ssd->showbuff )
            ssd->showbuff = 0;
    }
    return 0;
}
 
ACMD(showbuff) {
    struct player_data *ssd = getFromMSD( sd, 0 );
    struct party_data *p = party->search( sd->status.party_id );
    if ( !p ) {
        clif->message( sd->fd, "You don't have a Party." );
        return false;
    }
    else if ( ssd->showbuff ) {
        ssd->showbuff = 0;
        clif->message( sd->fd, "@showbuff is now turn OFF." );
    }
    else {
        ssd->showbuff = 1;
        clif->message( sd->fd, "@showbuff is now turn ON." );
    }
    clif->party_info( p, sd );
    return true;
}
 
HPExport void plugin_init (void) {
    addHookPost( status, change_start, status_change_start_post );
    addHookPost( status, change_end_, status_change_end_post );
    clif->party_info = &clif_party_info_overload;
    addHookPre( pc, authok, pc_authok_pre );
    clif->party_member_info = &clif_party_member_info_overload;
    clif->party_withdraw = &clif_party_withdraw_overload;
    addHookPre( party, removemember, party_removemember_pre );
    addHookPre( party, leave, party_leave_pre );
    addAtcommand( "showbuff", showbuff );
}
 
Viewed 2211 times, submitted by AnnieRuru.