Skip to content

Commit

Permalink
Auto pair additions (#161)
Browse files Browse the repository at this point in the history
Multi pair, max pair partners area prefs
  • Loading branch information
UnDeviato authored Aug 10, 2024
1 parent c6e8847 commit a55a9f1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
- Players will also be unable to see area movement messages or use `/chardesc`.
- You can change `/bg`, `/desc` and `/pos_lock` of the area when its dark and it will remember it next time you turn the lights off.
- tog can be `on`, `off` or empty.
* **auto\_pair** `<double/triple>`
- Set the max of players displayed on the screen.
- Depends on the /area_pref auto_pair setting
## Casing
* **doc** `[url]`
- Show or change the link for the current case document.
Expand Down
8 changes: 7 additions & 1 deletion docs/prefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,11 @@ If you're looking for the list of commands, it can be found [here](commands.md).
- When True, this area is currently recording testimony. This happens when you use /testimony_start or when the Witness Testimony WTCE is played by the CM.
- Do not change this directly!
- Default: *False*
* **auto\_pair**
- When True allows clients to pair directly if they are in the same pos without using commands.
- Default: *False*
* **auto\_pair\_cycle**
- When True and when auto_pair is on, it shows always the player who is speaking in the center.
- Default: *False*
### Mods Only
* Nothing here yet!
* Nothing here yet!
8 changes: 8 additions & 0 deletions server/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ def __init__(self, area_manager, name):

# multiple pair
self.auto_pair = False
self.auto_pair_max = "triple"
self.auto_pair_cycle = False

@property
def name(self):
Expand Down Expand Up @@ -594,6 +596,10 @@ def load(self, area):

if "auto_pair" in area:
self.auto_pair = area["auto_pair"]
if "auto_pair_max" in area:
self.auto_pair_max = area["auto_pair_max"]
if "auto_pair_cycle" in area:
self.auto_pair_cycle = area["auto_pair_cycle"]

def save(self):
area = OrderedDict()
Expand Down Expand Up @@ -670,6 +676,8 @@ def save(self):
area["links"] = self.links
area["can_battle"] = self.can_battle
area["auto_pair"] = self.auto_pair
area["auto_pair_max"] = self.auto_pair_max
area["auto_pair_cycle"] = self.auto_pair_cycle
return area

def new_client(self, client):
Expand Down
16 changes: 16 additions & 0 deletions server/commands/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"ooc_cmd_desc",
"ooc_cmd_edit_ambience",
"ooc_cmd_lights",
"ooc_cmd_auto_pair",
]

def ooc_cmd_overlay(client, arg):
Expand Down Expand Up @@ -841,3 +842,18 @@ def ooc_cmd_lights(client, arg):
pos = client.area.pos_dark
c.send_command("BN", bg, pos)
client.send_ooc(f"This area is {stat} dark.")


def ooc_cmd_auto_pair(client, arg):
"""
Set the max of players displayed on the screen.
Usage: /auto_pair <double/triple>
"""
if arg.lower() not in ["double", "triple"]:
client.send_ooc("Argument Error!\nUsage: /auto_pair <double/triple>")
return
client.area.auto_pair_max = arg.lower()
if arg.lower() == "triple":
client.send_ooc("Pairing will show a maximum of 3 characters on screen now")
else:
client.send_ooc("Pairing will show a maximum of 2 characters on screen now")
44 changes: 31 additions & 13 deletions server/network/aoprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ def net_cmd_ms(self, args):
if self.client.area.auto_pair:
clients_pos = [c for c in self.client.area.clients if c.pos == self.client.pos]
clients_pos.sort(key=lambda x: x.id)
if len(clients_pos) >= 3:
if len(clients_pos) >= 3 and self.client.area.auto_pair_max == "triple":
position = clients_pos.index(self.client)
if len(clients_pos) >= position+2:
if position > 0:
Expand All @@ -1014,34 +1014,52 @@ def net_cmd_ms(self, args):
client_pair = clients_pos[position-1]
third_client = clients_pos[position-2]

offset_pair = 0
charid_pair = f"{client_pair.id}^0"
other_offset = -33

charid_pair = f"{client_pair.char_id}^0"
other_emote = client_pair.last_sprite
other_flip = client_pair.flip
other_folder = client_pair.claimed_folder
third_charid = third_client.id
third_offset = 33
third_charid = f"{third_client.char_id}^0"
third_emote = third_client.last_sprite
third_flip = f"{third_client.id}^0"
third_flip = third_client.flip
third_folder = third_client.claimed_folder

if (
self.client.last_offset in [-33, 33, 0]
and client_pair.last_offset in [-33, 33, 0]
and third_client.last_offset in [-33, 33, 0]
and self.client.last_offset != client_pair.last_offset
and self.client.last_offset != third_client.last_offset
and client_pair.last_offset != third_client.last_offset
and not self.client.area.auto_pair_cycle
):
offset_pair = self.client.last_offset
other_offset = client_pair.last_offset
third_offset = third_client.last_offset
else:
offset_pair = 0
other_offset = -33
third_offset = 33
self.client.last_offset = 0
client_pair.last_offset = -33
third_client.last_offset = 33

else:
offset_pair = 0
if len(clients_pos) == 2:
clients_pos.remove(self.client)
client_pair = clients_pos[0]
if len(clients_pos) >= 2:
if clients_pos.index(self.client) == 0:
client_pair = clients_pos[1]
else:
client_pair = clients_pos[clients_pos.index(self.client) - 1]
if self.client.last_offset == -25 or client_pair.last_offset == 25:
offset_pair = -25
other_offset = 25
self.client.last_offset = -25
client_pair.last_offset = 25
else:
offset_pair = 25
other_offset = -25
self.client.last_offset = 25
client_pair.last_offset = -25
charid_pair = client_pair.id
charid_pair = client_pair.char_id
other_emote = client_pair.last_sprite
other_flip = client_pair.flip
other_folder = client_pair.claimed_folder
Expand Down

0 comments on commit a55a9f1

Please sign in to comment.