Skip to content

Commit

Permalink
More party fixes (otland#3938)
Browse files Browse the repository at this point in the history
- pending invitation emblem no longer visible for players leaving the party
- fix party invitations occasionally getting stuck
- fix pending invitation party emblems not appearing occasionally
  • Loading branch information
EPuncker authored Feb 14, 2022
1 parent 22dd9ca commit efda5d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
43 changes: 33 additions & 10 deletions src/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ bool Party::leaveParty(Player* player)
player->sendCreatureSkull(player);
player->sendPlayerPartyIcons(leader);

// remove pending invitation icons from the screen
for (Player* invitee : inviteList) {
player->sendCreatureShield(invitee);
}

player->sendTextMessage(MESSAGE_INFO_DESCR, "You have left the party.");

updateSharedExperience();
Expand Down Expand Up @@ -177,35 +182,47 @@ bool Party::passPartyLeadership(Player* player)

bool Party::joinParty(Player& player)
{
// check if lua scripts allow the player to join
if (!g_events->eventPartyOnJoin(this, &player)) {
return false;
}

auto it = std::find(inviteList.begin(), inviteList.end(), &player);
if (it == inviteList.end()) {
return false;
// first player accepted the invitation
// the party gets officially formed
// the leader can no longer take invitations from others
if (memberList.empty()) {
leader->clearPartyInvitations();
}

inviteList.erase(it);

// add player to the party
memberList.push_back(&player);
player.setParty(this);
broadcastPartyMessage(MESSAGE_INFO_DESCR, fmt::format("{:s} has joined the party.", player.getName()));

player.setParty(this);
// remove player pending invitations to this and other parties
player.clearPartyInvitations();

// update player icon on the screen
g_game.updatePlayerShield(&player);

// update player-member party icons
for (Player* member : memberList) {
member->sendCreatureSkull(&player);
player.sendPlayerPartyIcons(member);
}

player.sendCreatureSkull(&player);
// update player-leader party icons
leader->sendCreatureSkull(&player);
player.sendPlayerPartyIcons(leader);
// update player own skull
player.sendCreatureSkull(&player);

memberList.push_back(&player);
// show the new member who else is invited
for (Player* invitee : inviteList) {
player.sendCreatureShield(invitee);
}

player.removePartyInvitation(this);
// check the party eligibility for shared experience
updateSharedExperience();

const std::string& leaderName = leader->getName();
Expand Down Expand Up @@ -257,12 +274,18 @@ bool Party::invitePlayer(Player& player)
leader->sendTextMessage(MESSAGE_INFO_DESCR, fmt::format("{:s} has been invited.", player.getName()));
}

// add player to invite lists
inviteList.push_back(&player);
player.addPartyInvitation(this);

// update leader-invitee party status
leader->sendCreatureShield(&player);
player.sendCreatureShield(leader);

player.addPartyInvitation(this);
// update the invitation status for other members
for (Player* member : memberList) {
member->sendCreatureShield(&player);
}

player.sendTextMessage(MESSAGE_INFO_DESCR, fmt::format("{:s} has invited you to {:s} party.", leader->getName(), leader->getSex() == PLAYERSEX_FEMALE ? "her" : "his"));
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4170,7 +4170,8 @@ PartyShields_t Player::getPartyShield(const Player* player) const
return SHIELD_BLUE;
}

if (isInviting(player)) {
// isInviting(player) if members aren't supposed to see the invited player emblem
if (party->isPlayerInvited(player)) {
return SHIELD_WHITEBLUE;
}
}
Expand Down

0 comments on commit efda5d9

Please sign in to comment.