Skip to content

Commit

Permalink
Finish cupid implementation and fix witch send dead packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Solirs committed Jul 15, 2023
1 parent a1283f4 commit 6f53de1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
10 changes: 8 additions & 2 deletions freefang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ def kill_player(self, player, reason=None):
self.up = Hunter
self.eventloop()
if player.lover:
player.lover.lover = None
self.kill_player(player.lover)
player.lover = None

# Add player to list of dead players
self.dead.append(player)

Expand Down Expand Up @@ -297,9 +300,11 @@ def gameloop(self):
# Game should go on as long as there are villagers and werewolves, keeping the day night cycle
self.sendall(utils.obj_to_json(packets.Time_change(time="night"))) # Notify everyone night has fallen
for i in self.nightroles:
if self.roles[i] > 0:
# This is to make sure a player who was killed during the night does not wake up
playerwithrole = [x for x in self.players if x.role == i][0]
if self.roles[i] > 0 and not playerwithrole in self.nightdeaths:
# If the role is a first night role and its not the first night, we skip it.
if self.roles[i].firstnightrole and not self.firstnight:
if i.firstnightrole and not self.firstnight:
continue

self.queueall(utils.obj_to_json(packets.Role_wakeup(role=i.__name__))) # Notify everyone role has woken up
Expand All @@ -308,6 +313,7 @@ def gameloop(self):
try:
i.onwakeup(self)
except:
traceback.print_exc()
pass
self.eventloop()
self.firstnight = False
Expand Down
37 changes: 23 additions & 14 deletions freefang/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ def __init__(self, outcome):
}

class ChatMessage:
def __init__(self, sender, message, timestamp):
self.action = "chat_message"
self.headers = {
"sender": sender,
"message": message,
"timestamp": timestamp
}
def __init__(self, sender, message, timestamp):
self.action = "chat_message"
self.headers = {
"sender": sender,
"message": message,
"timestamp": timestamp
}

class SeerReveal:
def __init__(self, role, name):
self.action = "seer_role_reveal"
self.headers = {
def __init__(self, role, name):
self.action = "seer_role_reveal"
self.headers = {
"role": role,
"name": name
}
}
class Town_Vote_Begin:
def __init__(self):
self.action = "town_vote_begin"
Expand All @@ -133,5 +133,14 @@ def __init__(self):
class Witch_send_dead:
def __init__(self, players):
self.action = "witch_send_dead"
self.dead = players

self.headers = {
"dead": players
}

# Sent to players who are coupled with eachother by the Cupid role
class Player_coupled:
def __init__(self, player):
self.action = "player_coupled"
self.headers = {
"lover": player
}
19 changes: 15 additions & 4 deletions freefang/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def vote(headers, game, connection):
class Werewolf(Role):
nightrole = 1
order = 4
firstnightrole = 0
def __init__(self):
super(Werewolf, self).__init__()
pass
Expand Down Expand Up @@ -110,6 +111,8 @@ def vote(headers, game, connection):
class Seer:
nightrole = 1
order = 3
firstnightrole = 0

@staticmethod
def reveal(headers, game, connection):
target = game.getplayerbyname(headers.target)
Expand All @@ -135,6 +138,8 @@ def kill(headers, game, connection):

# can prevent one person of his choosing from dying at each night
class Protector(Role):
firstnightrole = 0

nightrole = 1
order = 2
def __init__(self):
Expand All @@ -155,22 +160,28 @@ def protect(headers, game, connection):

class Cupid(Role):
firstnightrole = 1
nightrole = 1
order = 1
@staticmethod
def infatuate(headers, game, connection){
target1 = game.getplayerbyname(headers.sender.target1)
target2 = game.getplayerbyname(headers.sender.target2)
def infatuate(headers, game, connection):
target1 = game.getplayerbyname(headers.target1)
target2 = game.getplayerbyname(headers.target2)

if game.up == Cupid and headers.sender.role == Cupid:
target1.lover = target2
target2.lover = target1

game.send_packet(utils.obj_to_json(packets.Player_coupled(target1.name)), target2.connection)
game.send_packet(utils.obj_to_json(packets.Player_coupled(target2.name)), target1.connection)

return 2
else:
return 1
}



class Witch(Role):
firstnightrole = 0
nightrole = 1
order = 5
@staticmethod
Expand Down

0 comments on commit 6f53de1

Please sign in to comment.