Skip to content

Commit

Permalink
Merge pull request #7 from andygarcha/coop-roll
Browse files Browse the repository at this point in the history
Coop roll
  • Loading branch information
andygarcha authored Oct 30, 2024
2 parents 4d69698 + 637d92c commit e940758
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Classes/CE_Roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ def rolled_categories(self, database_name : list) -> list[str] :
return list(set([hm.get_item_from_list(game, database_name).category for game in self.games]))

def get_win_message(self, database_name : list, database_user : list) -> str :
"""Returns a string to send to #casino-log if this roll is won."""
"""Returns a string to send to #casino-log if this roll is won.
This also sets the winner property if the roll is co-op."""
import Modules.Mongo_Reader as Mongo_Reader
from Classes.CE_User import CEUser
from Classes.CE_Game import CEGame
Expand Down
23 changes: 23 additions & 0 deletions Classes/CE_User.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ def get_rank(self) -> str :
elif total_points >= 50 : return "D Rank"
else : return "E Rank"

def rank_num(self) -> int :
"Returns the rank as a user. E Rank is 0, D Rank is 1, etc."
match(self.get_rank()) :
case "E Rank" : return 0
case "D Rank" : return 1
case "C Rank" : return 2
case "B Rank" : return 3
case "A Rank" : return 4
case "S Rank" : return 5
case "SS Rank" : return 6
case "SSS Rank" : return 7
case "EX Rank" : return 8
return None

@property
def owned_games(self):
"""Returns a list of :class:`CEUserGame`s that this user owns."""
Expand All @@ -107,6 +121,15 @@ def get_owned_game(self, ce_id : str) -> CEUserGame | None :
if game.ce_id == ce_id : return game
return None

def owned_games_as_cegames(self, database_name : list[CEGame]) -> list[CEGame] :
"Returns a list of this user's owned games as `CEGame`s."
o : list[CEGame] = []
for game in database_name :
for owned_game in self.owned_games :
if game.ce_id == owned_game.ce_id :
o.append(game)
return o

def get_completed_games(self) -> list[CEUserGame] :
"""Returns a list of :class:`CEUserGame`'s that this user has completed.
This is so fucking inefficient. Please don't use this."""
Expand Down
10 changes: 10 additions & 0 deletions Modules/WebInteractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,21 @@ def user_update(user : CEUser, site_data : CEUser, old_database_name : list[CEGa
del user.current_rolls[index]

if roll.is_co_op() :
# get the partner and their roll
partner = hm.get_item_from_list(roll.partner_ce_id, database_user)
partner_roll = partner.get_current_roll(roll.roll_name)

# set the partner roll's winner tag
if roll.is_pvp() : partner_roll.winner = not roll.winner

# remove their current roll
partner.remove_current_roll(partner_roll.roll_name)

# set the completion time and add it to the completed rolls
partner_roll.completed_time = hm.get_unix('now')
partner.add_completed_roll(partner_roll)

# and append it to partners
partners.append(partner)


Expand Down Expand Up @@ -570,6 +579,7 @@ async def master_loop(client : discord.Client, guild_id : int) :
database_user = await Mongo_Reader.get_mongo_users()
try :
new_users = await CEAPIReader.get_api_users_all(database_user=database_user)
database_user = await Mongo_Reader.get_mongo_users()

# guild
guild = await client.fetch_guild(guild_id)
Expand Down
30 changes: 22 additions & 8 deletions Modules/hm.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,20 @@ def get_rollable_game(
continue
"""

if game.get_tier() != f"Tier {tier_number}" :
if tier_number != None and game.get_tier() != f"Tier {tier_number}" :
"Incorrect tier."
continue

if (type(user) is list) :
"If there's more than one user..."
for u in user :
"...one of them has completed the game."
if u.has_completed_game(game.ce_id, database_name) : continue
else :
"User has completed the game already."
if user.has_completed_game(game.ce_id, database_name) :
continue

if (user.has_completed_game(game.ce_id, database_name)) :
"User has completed game already."
continue

if game.ce_id in already_rolled_games :
"This game has already been rolled."
Expand All @@ -359,10 +366,17 @@ def get_rollable_game(
if game.ce_id in banned_games :
"This game is in the Banned Games section."
continue

if has_points_restriction and user.has_points(game.ce_id) :
"This user is not allowed to have points in this game."
continue

if has_points_restriction :
"If the user isn't allowed to have points in the game..."
if type(user) is list :
"One of the users passed has points in the game."
for u in user :
u : CEUser = u
if u.has_points(game.ce_id) : continue
else :
"The user passed has points in the game."
if user.has_points(game.ce_id) : continue

return game.ce_id

Expand Down
Loading

0 comments on commit e940758

Please sign in to comment.