Continued progress (keeping votegroup)
This commit is contained in:
parent
e586fa6faa
commit
df28c4215f
@ -28,9 +28,11 @@ class Game:
|
|||||||
|
|
||||||
self.started = False
|
self.started = False
|
||||||
self.game_over = False
|
self.game_over = False
|
||||||
|
self.can_vote = False
|
||||||
|
|
||||||
self.village_channel = None
|
self.village_channel = None
|
||||||
self.secret_channels = {}
|
self.secret_channels = {}
|
||||||
|
self.vote_groups = []
|
||||||
|
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
@ -82,6 +84,8 @@ class Game:
|
|||||||
return
|
return
|
||||||
await self._notify(1)
|
await self._notify(1)
|
||||||
|
|
||||||
|
self.can_vote = True
|
||||||
|
|
||||||
asyncio.sleep(240) # 4 minute days
|
asyncio.sleep(240) # 4 minute days
|
||||||
await self._at_day_end()
|
await self._at_day_end()
|
||||||
|
|
||||||
@ -105,7 +109,9 @@ class Game:
|
|||||||
return
|
return
|
||||||
await self._notify(5)
|
await self._notify(5)
|
||||||
|
|
||||||
asyncio.sleep(60)
|
self.can_vote = False
|
||||||
|
|
||||||
|
asyncio.sleep(30)
|
||||||
await self._at_night_start()
|
await self._at_night_start()
|
||||||
|
|
||||||
async def _at_night_start(self): # ID 6
|
async def _at_night_start(self): # ID 6
|
||||||
@ -132,16 +138,33 @@ class Game:
|
|||||||
async def _notify(self, event, data=None):
|
async def _notify(self, event, data=None):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
|
# Role priorities
|
||||||
role_order = [role for role in self.roles if role.action_list[event][1]==i]
|
role_order = [role for role in self.roles if role.action_list[event][1]==i]
|
||||||
for role in role_order:
|
for role in role_order:
|
||||||
tasks.append(asyncio.ensure_future(role.on_event(event, data))
|
tasks.append(asyncio.ensure_future(role.on_event(event, data))
|
||||||
|
# VoteGroup priorities
|
||||||
|
vote_order = [votes for votes in self.vote_groups if votes.action_list[event][1]==i]
|
||||||
|
for vote_group in vote_order:
|
||||||
|
tasks.append(asyncio.ensure_future(vote_group.on_event(event, data))
|
||||||
|
|
||||||
# self.loop.create_task(role.on_event(event))
|
# self.loop.create_task(role.on_event(event))
|
||||||
self.loop.run_until_complete(asyncio.gather(*tasks))
|
self.loop.run_until_complete(asyncio.gather(*tasks))
|
||||||
# Run same-priority task simultaneously
|
# Run same-priority task simultaneously
|
||||||
|
|
||||||
async def _generate_targets(self):
|
async def generate_targets(self, channel):
|
||||||
|
embed=discord.Embed(title="Remaining Players")
|
||||||
|
for i in range(len(self.players)):
|
||||||
|
player = self.players[i]
|
||||||
|
if player.alive:
|
||||||
|
status=""
|
||||||
|
else:
|
||||||
|
status="*Dead*"
|
||||||
|
embed.add_field(name="ID# **{}**".format(i), value="{} {}".format(status, player.member.display_name, inline=True)
|
||||||
|
|
||||||
async def register_channel(self, channel_id):
|
return await channel.send(embed=embed)
|
||||||
|
|
||||||
|
async def register_channel(self, channel_id, votegroup = None):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -186,13 +209,29 @@ class Game:
|
|||||||
|
|
||||||
if player is None:
|
if player is None:
|
||||||
channel.send("You're not in this game!")
|
channel.send("You're not in this game!")
|
||||||
|
return
|
||||||
|
|
||||||
if not player.alive:
|
if not player.alive:
|
||||||
channel.send("Corpses can't vote")
|
channel.send("Corpses can't vote")
|
||||||
|
return
|
||||||
|
|
||||||
|
if channel in self.secret_channels.values():
|
||||||
|
|
||||||
|
if channel == self.village_channel:
|
||||||
|
if not self.can_vote:
|
||||||
|
channel.send("Voting is not allowed right now")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
target = self.players[id]
|
target = self.players[id]
|
||||||
except IndexError
|
except IndexError:
|
||||||
|
target = None
|
||||||
|
|
||||||
|
if target is None:
|
||||||
|
channel.send("Not a valid target")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_roles(self, game_code=None):
|
async def get_roles(self, game_code=None):
|
||||||
|
@ -13,7 +13,7 @@ class DefaultWerewolf(Role):
|
|||||||
rand_choice = True
|
rand_choice = True
|
||||||
category = [11, 15]
|
category = [11, 15]
|
||||||
allignment = 2 # 1: Town, 2: Werewolf, 3: Neutral
|
allignment = 2 # 1: Town, 2: Werewolf, 3: Neutral
|
||||||
channel_id = "werewolf"
|
channel_id = "werewolves"
|
||||||
unique = False
|
unique = False
|
||||||
action_list = [
|
action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 0), # (Action, Priority)
|
||||||
@ -67,22 +67,7 @@ class DefaultWerewolf(Role):
|
|||||||
super()._at_day_end(data)
|
super()._at_day_end(data)
|
||||||
|
|
||||||
async def _at_night_start(self, data=None):
|
async def _at_night_start(self, data=None):
|
||||||
channel = self.game.channel_lock(self.channel_id, False)
|
|
||||||
# channel = await self.game.get_channel(self.channel_id)
|
|
||||||
|
|
||||||
await self.game._generate_targets(channel)
|
|
||||||
super()._at_night_start(data)
|
super()._at_night_start(data)
|
||||||
|
|
||||||
async def _at_night_end(self, data=None):
|
async def _at_night_end(self, data=None):
|
||||||
await self.game.channel_lock(self.channel_id, True)
|
|
||||||
|
|
||||||
try:
|
|
||||||
target = data["target"]
|
|
||||||
except:
|
|
||||||
# No target chosen, no kill
|
|
||||||
target = None
|
|
||||||
|
|
||||||
if target:
|
|
||||||
await self.game.kill(target)
|
|
||||||
|
|
||||||
super()._at_night_end(data)
|
super()._at_night_end(data)
|
@ -3,15 +3,15 @@ import asyncio
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
|
||||||
class SecretGroup:
|
class VoteGroup:
|
||||||
"""
|
"""
|
||||||
Base SecretGroup class for werewolf game
|
Base VoteGroup class for werewolf game
|
||||||
Handles secret channels and group decisions
|
Handles secret channels and group decisions
|
||||||
Default handles Town lynch votes
|
Default handles wolf kill vote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allignment = 1 # 1: Town, 2: Werewolf, 3: Neutral
|
allignment = 2 # 1: Town, 2: Werewolf, 3: Neutral
|
||||||
channel_id = "Town Square"
|
channel_id = "werewolves"
|
||||||
|
|
||||||
action_list = [
|
action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 0), # (Action, Priority)
|
||||||
@ -20,14 +20,17 @@ class SecretGroup:
|
|||||||
(self._at_kill, 0),
|
(self._at_kill, 0),
|
||||||
(self._at_hang, 0),
|
(self._at_hang, 0),
|
||||||
(self._at_day_end, 0),
|
(self._at_day_end, 0),
|
||||||
(self._at_night_start, 0),
|
(self._at_night_start, 2),
|
||||||
(self._at_night_end, 0)
|
(self._at_night_end, 5)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
vote_emojis =
|
||||||
|
|
||||||
def __init__(self, game):
|
def __init__(self, game):
|
||||||
self.game = game
|
self.game = game
|
||||||
self.channel = None
|
self.channel = None
|
||||||
self.properties = {} # Extra data for other options
|
self.properties = {} # Extra data for other options
|
||||||
|
self.vote_message = None
|
||||||
|
|
||||||
async def on_event(self, event, data):
|
async def on_event(self, event, data):
|
||||||
"""
|
"""
|
||||||
@ -56,7 +59,13 @@ class SecretGroup:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
async def _at_night_start(self, data=None):
|
async def _at_night_start(self, data=None):
|
||||||
pass
|
if self.channel is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.vote_message = await self.game.generate_targets(self.channel)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def _at_night_end(self, data=None):
|
async def _at_night_end(self, data=None):
|
||||||
pass
|
if self.channel is None:
|
||||||
|
return
|
Loading…
x
Reference in New Issue
Block a user