diff options
author | KirieZ <guilherme.menaldo@outlook.com> | 2017-02-12 12:08:49 -0200 |
---|---|---|
committer | KirieZ <guilherme.menaldo@outlook.com> | 2017-02-12 12:08:49 -0200 |
commit | 2ce4c3e261f59df22ff23259574b6bfccc11bf3b (patch) | |
tree | f8e849d766786cc5ac3a3796cc7af397bfdeefda /src/map/party.c | |
parent | 946b7f8490e952fbd90c6760f256ddfdd1e98137 (diff) | |
download | hercules-2ce4c3e261f59df22ff23259574b6bfccc11bf3b.tar.gz hercules-2ce4c3e261f59df22ff23259574b6bfccc11bf3b.tar.bz2 hercules-2ce4c3e261f59df22ff23259574b6bfccc11bf3b.tar.xz hercules-2ce4c3e261f59df22ff23259574b6bfccc11bf3b.zip |
Follow-up 946b7f8490e952fbd90c6760f256ddfdd1e98137
Diffstat (limited to 'src/map/party.c')
-rw-r--r-- | src/map/party.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/map/party.c b/src/map/party.c index 0a5b791fe..26b4bae8b 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -274,6 +274,7 @@ int party_recv_info(const struct party *sp, int char_id) int added_count = 0; int j; int member_id; + int leader_account_id = 0, leader_char_id = 0; nullpo_ret(sp); @@ -287,8 +288,12 @@ int party_recv_info(const struct party *sp, int char_id) ARR_FIND(0, MAX_PARTY, i, sp->member[i].account_id == member->account_id && sp->member[i].char_id == member->char_id); - if (i == MAX_PARTY) + if (i == MAX_PARTY) { removed[removed_count++] = member_id; + } else if (member->leader != 0) { + leader_account_id = member->account_id; + leader_char_id = member->char_id; + } } for (member_id = 0; member_id < MAX_PARTY; ++member_id) { member = &sp->member[member_id]; @@ -300,18 +305,6 @@ int party_recv_info(const struct party *sp, int char_id) if (i == MAX_PARTY) added[added_count++] = member_id; } - - ARR_FIND(0, MAX_PARTY, j, p->party.member[j].leader == 1); - if (j == MAX_PARTY) { - // Leader has changed - int k; - ARR_FIND(0, MAX_PARTY, k, sp->member[k].leader == 1); - if (k < MAX_PARTY) { - clif->PartyLeaderChanged(map->id2sd(sp->member[k].account_id), 0, sp->member[k].account_id); - } else { - party->broken(p->party.party_id); // Should not happen, Party is leaderless, disband - } - } } else { for( member_id = 0; member_id < MAX_PARTY; ++member_id ) if( sp->member[member_id].char_id != 0 ) @@ -328,6 +321,7 @@ int party_recv_info(const struct party *sp, int char_id) continue;// not online party->member_withdraw(sp->party_id, sd->status.account_id, sd->status.char_id); } + memcpy(&p->party, sp, sizeof(struct party)); memset(&p->state, 0, sizeof(p->state)); memset(&p->data, 0, sizeof(p->data)); @@ -336,6 +330,8 @@ int party_recv_info(const struct party *sp, int char_id) if ( member->char_id == 0 ) continue;// empty p->data[member_id].sd = party->sd_check(sp->party_id, member->account_id, member->char_id); + if (member->account_id == leader_account_id && member->char_id == leader_char_id) + p->party.member[member_id].leader = 1; } party->check_state(p); while( added_count > 0 ) { // new in party @@ -603,11 +599,43 @@ int party_member_withdraw(int party_id, int account_id, int char_id) int i; ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id ); if( i < MAX_PARTY ) { + bool was_leader = false; + int prev_leader_accountId = 0; + if (p->party.member[i].leader != 0) { + was_leader = true; + prev_leader_accountId = p->party.member[i].account_id; + } + clif->party_withdraw(p,sd,account_id,p->party.member[i].name,0x0); memset(&p->party.member[i], 0, sizeof(p->party.member[0])); memset(&p->data[i], 0, sizeof(p->data[0])); p->party.count--; party->check_state(p); + + if (was_leader) { + int k; + // Member was party leader, try to pick a new leader from online members + ARR_FIND(0, MAX_PARTY, k, p->party.member[k].account_id != 0 && p->party.member[k].online == 1); + + if (k == MAX_PARTY) { + // No online members, get an offline one + ARR_FIND(0, MAX_PARTY, k, p->party.member[k].account_id != 0); + } + + if (k < MAX_PARTY) { + // Update party's leader + p->party.member[k].leader = 1; + + if (p->data[k].sd != NULL) { + /** update members **/ + clif->PartyLeaderChanged(p->data[k].sd, prev_leader_accountId, p->data[k].sd->status.account_id); + } + + //Update info. + intif->party_leaderchange(p->party.party_id, p->party.member[k].account_id, p->party.member[k].char_id); + clif->party_info(p, NULL); + } + } } } |