Skip to content

Commit

Permalink
Added code to remove a player party search if the player leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon committed Aug 21, 2024
1 parent 7703b29 commit 366c217
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion GuildWarsPartySearch.Bot/Dependencies/Headquarter
13 changes: 13 additions & 0 deletions GuildWarsPartySearch.Bot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ static CallbackEntry EventType_PartySearchType_entry;
static CallbackEntry EventType_WorldMapEnter_entry;
static CallbackEntry EventType_PartyMembersChanged_entry;
static CallbackEntry EventType_PlayerPartySize_entry;
static CallbackEntry EventType_AgentDestroyPlayer_entry;

static bool party_advertisements_pending = true;
static bool maps_unlocked_pending = true;
Expand Down Expand Up @@ -441,6 +442,13 @@ static void add_party_search_advertisement(Event* event, void* params) {
party_advertisements_pending = true;
}

static void on_player_destroyed(Event* event, void* params) {
assert(event && event->type == EventType_AgentDestroyPlayer && event->AgentDestroyPlayer.player_id);
// NB: GW sends player_id as a 32 bit number here, even though its a u16 :/
assert(event->AgentDestroyPlayer.player_id < 0xffff);
uint32_t party_id = 0xfffe0000 | (uint16_t)event->AgentDestroyPlayer.player_id;
remove_party_search_advertisement(party_id);
}
static void on_player_party_size(Event* event, void* params) {
assert(event && event->type == EventType_PlayerPartySize);
clear_party_searches_if_map_changed();
Expand Down Expand Up @@ -792,6 +800,10 @@ static int main_bot(void* param)
CallbackEntry_Init(&EventType_PlayerPartySize_entry, on_player_party_size, NULL);
RegisterEvent(EventType_PlayerPartySize, &EventType_PlayerPartySize_entry);

CallbackEntry_Init(&EventType_AgentDestroyPlayer_entry, on_player_destroyed, NULL);
RegisterEvent(EventType_AgentDestroyPlayer, &EventType_AgentDestroyPlayer_entry);


load_configuration();

wait_until_ingame();
Expand Down Expand Up @@ -856,6 +868,7 @@ static int main_bot(void* param)
UnRegisterEvent(&EventType_PartySearchType_entry);
UnRegisterEvent(&EventType_WorldMapEnter_entry);
UnRegisterEvent(&EventType_PlayerPartySize_entry);
UnRegisterEvent(&EventType_AgentDestroyPlayer_entry);

clear_party_search_advertisements();

Expand Down

0 comments on commit 366c217

Please sign in to comment.