viewing paste topic/11349-p showbuff_0.2.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
// http://herc.ws/board/topic/11349-partybuff-spb/
 
#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.2",
    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 = "";
    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;
}
 
ACMD(showbuff) {
    struct player_data *ssd = getFromMSD( sd, 0 );
    struct party_data *p = party->search( sd->status.party_id );
    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 );
    addAtcommand( "showbuff", showbuff );
}
 
Viewed 1948 times, submitted by AnnieRuru.