Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique Universes #10

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Unique Universes #10

wants to merge 35 commits into from

Conversation

janine9vn
Copy link
Contributor

No description provided.

Snipy7374 and others added 30 commits July 15, 2024 23:15
* Add docker setup & instructions

Signed-off-by: Mmesek <[email protected]>

* Add docker build workflow

Signed-off-by: Mmesek <[email protected]>

* Improve image size & build by leveraging multi-stage build

Signed-off-by: Mmesek <[email protected]>

---------

Signed-off-by: Mmesek <[email protected]>
* Update README to include how to run project without docker

Signed-off-by: Mmesek <[email protected]>

* Remove samples folder

Signed-off-by: Mmesek <[email protected]>

* Reorganize installation steps

Signed-off-by: Mmesek <[email protected]>

---------

Signed-off-by: Mmesek <[email protected]>
feat: load exts at startup
This reverts commit 47c243c, reversing
changes made to e1a8c37.
* added database

* safety

* Update src/database.py

* Update src/database.py

* Update src/database.py

* Update src/database.py

* lint and format

* added type hinting for player obj

* changed where db connection is made

* implement custom run flow for db closure

---------

Co-authored-by: Snipy7374 <[email protected]>
* implement the base for shoot minigame

* Add sample statisic fields

Signed-off-by: Mmesek <[email protected]>

* Add aim buttons

Signed-off-by: Mmesek <[email protected]>

* Add embed attributes to ShootMenu

Added embed attributes, did ammunition check in shoot_callback

* Add values to fields

Add values to fields from ShootMenu

* implement shoot minigame logic

* Add Ad embed (part 1)

* Add Ad embed (part 2) (test)

* Use a json of ads instead of random Wikipedia articles

* Revert "Merge branch 'main' into main"

This reverts commit 47c243c, reversing
changes made to e1a8c37.

* new: database (#9)

* added database

* safety

* Update src/database.py

* Update src/database.py

* Update src/database.py

* Update src/database.py

* lint and format

* added type hinting for player obj

* changed where db connection is made

* implement custom run flow for db closure

---------

Co-authored-by: Snipy7374 <[email protected]>

* finalize shoot minigame adding database stats

---------

Signed-off-by: Mmesek <[email protected]>
Co-authored-by: Mmesek <[email protected]>
Co-authored-by: stroh13 <[email protected]>
Co-authored-by: EarthKiii <[email protected]>
Co-authored-by: Astroyo <[email protected]>
* Added about command with bot instantiat

Instantiated the bot, and added bot.run() and implemented the /about command

* Updated .gitignore

Includes .history

* Added about command with bot instantiat

Instantiated the bot, and added bot.run() and implemented the /about command

* Updated .gitignore

Includes .history

* fix about command

* remove version field

* Add Ad embed (part 1)

* Add Ad embed (part 2) (test)

* Use a json of ads instead of random Wikipedia articles

* Revert "Merge branch 'main' into main"

This reverts commit 47c243c, reversing
changes made to e1a8c37.

* new: database (#9)

* added database

* safety

* Update src/database.py

* Update src/database.py

* Update src/database.py

* Update src/database.py

* lint and format

* added type hinting for player obj

* changed where db connection is made

* implement custom run flow for db closure

---------

Co-authored-by: Snipy7374 <[email protected]>

* Added about command with bot instantiat

Instantiated the bot, and added bot.run() and implemented the /about command

* fix about command

* add shoot command mention in about command response

---------

Co-authored-by: stroh13 <[email protected]>
Co-authored-by: EarthKiii <[email protected]>
Co-authored-by: Astroyo <[email protected]>
Copy link
Member

@mbaruh mbaruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fun game, I liked the humor :)

You should invest more in comments and docstrings, but I think you knew that already.

Looks like you didn't manage to implement everything you had in mind, hopefully you enjoyed working on the project

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have dev-dependencies in your pyproject.toml, so this seems redundant.

Comment on lines +38 to +39
@tasks.loop(seconds=1, count=1)
async def fetch_cmd(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's a loop that repeats once? Why not await it normally then?

Comment on lines +22 to +41
class FetchTasks:
def __init__(self, bot: Universe) -> None:
self.bot = bot

async def _fetch_shoot_cmd(self) -> None:
_log.info("Fetching shoot cmd")
cmds = await self.bot.fetch_global_commands()
for cmd in cmds:
if cmd.name != "shoot":
continue
if isinstance(cmd, disnake.APISlashCommand):
self.bot.shoot_cmd = cmd

if self.bot.shoot_cmd is not None:
_log.info("Shoot command fetched")

@tasks.loop(seconds=1, count=1)
async def fetch_cmd(self) -> None:
await self.bot.wait_until_ready()
await self._fetch_shoot_cmd()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why this is all needed and can't be part of the bot class.

from src.views.shoot import ShootStats


__all__: tuple[str, ...] = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to type-hint this

Comment on lines +23 to +24
seq = random.choices(tokens, k=16) # noqa: S311
return ":".join([f"{seq[i]}{seq[i+1]}" for i in range(0, len(seq), 2)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could instead do random.choices with k=2 8 times and join that. Seems more readable that way

Comment on lines +55 to +94
embed = disnake.Embed(title="Shoot minigame", description="\n".join(["." * 10] * 5))
embed.add_field("Planet acceleration", f"{round(view.stats.g_acc, 2)} m/s^2")
embed.add_field("Position", f"{view.stats.position}")
embed.add_field("Angle", f"{view.stats.angle}")
embed.add_field("Ammunition (Shots left)", f"{view.stats.ammunition}")
embed.add_field("Energy (Moves left)", f"{view.stats.energy}")
embed.add_field("Ship Speed", f"{view.stats.ship_speed}")
embed.add_field("Bullet Velocity", f"{view.stats.bullet_velocity}")
embed.add_field("Bullet Type", f"{view.stats.bullet_type}")

embed.add_field("Obstacles in range", f"{view.stats.obstacles_in_range}")
embed.add_field("Outer Space Pression", "1.32 x 10^-11 Pa")

embed.add_field("Enemy Position", f"{view.stats.enemy_position}")
embed.add_field("Enemy Health", f"{view.stats.enemy_health}")
embed.add_field("Enemy Energy", f"{view.stats.enemy_energy}")

embed.add_field("Enemy has VIP Pass (+100 to Pay 2 Win)", f"{view.stats.enemy_has_vip_pass}")
embed.add_field("Enemy logins in a row", f"{view.stats.enemy_logins_in_a_row}")

embed.add_field("Ship insured", "Only below 0-e2 of skin damage")
embed.add_field("Gun cleaned", f"{random.randint(1, 10_000)} days ago") # noqa: S311
embed.add_field("Engines checked", f"{random.randint(1, 100)} years ago") # noqa: S311

embed.add_field("Serial Number", f"10-{str(inter.user.id).replace('4', 'A').replace('3', 'E')}-A")
# yeah you're basically fighting against yourself, enjoy it
embed.add_field("Enemy Serial Number", f"10-{str(inter.user.id*3).replace('4', 'A').replace('3', 'E')}-A")
embed.add_field("Manufacturer", "Legit Stuff™")
embed.add_field("MAC address", _generate_fake_mac())
embed.add_field(
"Your stats",
(
f"Wins: {player.wins}\n"
f"Losses: {player.loses}\n"
f"Total Shots: {player.shots_fired}\n"
f"Total Hits: {player.hits}\n"
f"Total Shots Missed: {player.misses}\n"
),
)
embed.set_footer(text=f"Total shots: {view.stats.total_shots}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating the embed could also have been a method of ShootStats.

I'm wondering how all of these add_fields could be avoided. You could store those extra values in ShootStats, and then most of the work could be done with a for loop on the fields.

generate_random_stats(view.stats)
embed = disnake.Embed(title="Shoot minigame", description="\n".join(["." * 10] * 5))
embed.add_field("Planet acceleration", f"{round(view.stats.g_acc, 2)} m/s^2")
embed.add_field("Position", f"{view.stats.position}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
embed.add_field("Position", f"{view.stats.position}")
embed.add_field("Position", str(view.stats.position))

Here and everywhere else f-strings are used only for casting to string

Comment on lines +20 to +22
# acceleration directed to the center of Earth
# measured in m/s^2
EARTH_ACCELERATION = 9.81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of too much information, could account for the gravity in various points on Earth ;)


async def callback(self, interaction: disnake.ModalInteraction) -> None:
angle = interaction.text_values["angle_deg"]
if not angle.isdigit():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.isdigit accepts a lot more than simple numbers. The most sure-fire way to check if a string represents a number is to try casting it to int and catch the error if it's not.

Comment on lines +85 to +109
@property
def misses(self) -> int:
return self.total_shots - self.hits

@property
def angle_as_radians(self) -> float:
return math.radians(self.angle)

@property
def get_enemy_distance(self) -> int:
return abs(self.enemy_position - self.position)

def calculate_shot_range(self) -> float:
return (
2 * self.bullet_velocity * math.cos(self.angle_as_radians) * math.sin(self.angle_as_radians)
) / self.g_acc

def calculate_max_possible_range(self) -> float:
return (self.bullet_velocity**2) / self.g_acc

def calculate_flight_time(self) -> float:
return (2 * self.bullet_velocity * math.sin(self.angle_as_radians)) / self.g_acc

def calculate_max_height(self) -> float:
return ((self.bullet_velocity**2) * (math.sin(self.angle_as_radians) ** 2)) / (2 * self.g_acc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you decide what should be a property and what shouldn't? Could all be properties if you removed calculate from the names. If the calculate methods were meant to be helper methods for other calculations, you could indicate that by starting their names with a _.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants