-
Notifications
You must be signed in to change notification settings - Fork 0
/
Party.js
75 lines (64 loc) · 1.74 KB
/
Party.js
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
setupParty = () => {
if (isInParty()) {
game_log("Already in a Party. Leaving to join group.")
leaveParty();
}
game_log("Searching for existing group party.");
let partyLeader = findPartyLeader();
if (partyLeader != null) {
game_log(`Requesting to join ${partyLeader}s party`);
joinParty(partyLeader);
} else {
game_log("No party leader found. Starting new party.");
initiateParty();
}
}
leaveParty = () => {
safeSay('/leave');
}
isInParty = () => {
return character.party !== undefined;
}
isPartyLeader = () => {
return isInParty && character.party == character.name;
}
findPartyLeader = () => {
for (var partyMember in PARTY_MEMBERS) {
let player = get_player(getPartyMemberName(partyMember));
if (player && player.party !== undefined) {
return player.party;
}
}
return null;
}
joinParty = (partyLeaderName) => {
send_party_request(partyLeaderName);
}
initiateParty = () => {
for (var partyMember in PARTY_MEMBERS) {
if (getPartyMemberName(partyMember) != character.name) {
game_log(`Inviting ${partyMember} to join party.`);
send_party_invite(getPartyMemberName(partyMember));
}
}
}
function on_party_invite(name) {
for (var partyMember in PARTY_MEMBERS) {
if (getPartyMemberName(partyMember) == name) {
accept_party_invite(name);
return;
}
}
}
function on_party_request(name) {
for (var partyMember in PARTY_MEMBERS) {
if (getPartyMemberName(partyMember) == name) {
accept_party_request(name);
return;
}
}
}
getPartyMemberName = (key) => {
return PARTY_MEMBERS[key];
}
setupParty();