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

Luminous Lightyears #4

Open
wants to merge 141 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
41e75a1
Initial commit
krishnabhat3383 Jul 19, 2024
084c58e
Add interactions.py
hazyfossa Jul 20, 2024
62cf6f2
Basic joining and leaving of the game (#1)
Sapient44 Jul 22, 2024
78ccdda
Improve how we're starting our app (#2)
hazyfossa Jul 22, 2024
ccb771d
Templating (#3)
hazyfossa Jul 22, 2024
a8f6e7b
Basic game management draft
hazyfossa Jul 23, 2024
8edfdd7
Implement random game id's
hazyfossa Jul 23, 2024
0d8e896
Player registration UI prototype
hazyfossa Jul 23, 2024
9ae9f3c
Remove player
Sapient44 Jul 23, 2024
fa80ba4
Linting + Embedding of template Game UI (#4)
Sapient44 Jul 23, 2024
aa5f9a0
Get nation name from user for registration
Maheshkumar-novice Jul 23, 2024
5fd4421
Refactor how players are added to a game instance
hazyfossa Jul 23, 2024
741efec
Merge branch 'game_starting' of https://github.com/krishnabhat3383/co…
hazyfossa Jul 23, 2024
112521f
Remove message when registering
hazyfossa Jul 23, 2024
dacc852
Revert to sending reply for modal response
Maheshkumar-novice Jul 23, 2024
42a9d8d
Sample
Dhanvantg Jul 24, 2024
f11a75c
Sample
Dhanvantg Jul 24, 2024
3b8c897
Keeping up with starting
Sapient44 Jul 24, 2024
f77801f
Add more vairables as per the GDD
Sapient44 Jul 24, 2024
ae686f8
Game management logic (#5)
hazyfossa Jul 24, 2024
4d749f2
Merge branch 'main' into game_loop
hazyfossa Jul 24, 2024
a51e14c
move player registration to Player class
hazyfossa Jul 24, 2024
de090dc
hotfix: make condition optional
hazyfossa Jul 24, 2024
c7c8a22
add a common error message prototype
hazyfossa Jul 24, 2024
5fcb285
Merge branch 'templating_v2' into game_loop
hazyfossa Jul 24, 2024
817995f
formatting
hazyfossa Jul 24, 2024
bbda9df
move PlayerState to game.py
hazyfossa Jul 24, 2024
b59bd6f
Move Stage type to game.py
hazyfossa Jul 24, 2024
ce075aa
templating backend and different types of templates
hazyfossa Jul 24, 2024
15ee62e
Adding actor name in embed
Sapient44 Jul 24, 2024
903a1b6
simplify data layout
hazyfossa Jul 25, 2024
2cf4dab
simplify StageGroup casting
hazyfossa Jul 25, 2024
023c423
Templating v2 (#7)
hazyfossa Jul 25, 2024
f091beb
move weighted random to a separate file and add proper typing
hazyfossa Jul 25, 2024
edbcf9d
Add dynamic character import util function
Maheshkumar-novice Jul 25, 2024
ca6e843
add append to WeightedList
hazyfossa Jul 25, 2024
2df864f
make Actor a dataclass
hazyfossa Jul 25, 2024
f4d2b04
Merge branch 'game_loop' into character-import
hazyfossa Jul 25, 2024
acd9b71
move code to characters __init__.py
hazyfossa Jul 25, 2024
facbde4
move example to characters/
hazyfossa Jul 25, 2024
a000752
disable false-positive linting for custom character files
hazyfossa Jul 25, 2024
1d7c1b0
change imports from relative to parent-package
hazyfossa Jul 25, 2024
8ac4d71
hotfix: imports
hazyfossa Jul 25, 2024
57dcdbc
change character extension
hazyfossa Jul 25, 2024
fb199e8
basic tick prototype
hazyfossa Jul 25, 2024
8e8c013
Fix circular imports
Maheshkumar-novice Jul 25, 2024
7b9d2e8
Game loop (#6)
hazyfossa Jul 25, 2024
fac649a
Add dynamic character import util function (#9)
Maheshkumar-novice Jul 25, 2024
263ce66
Merge branch 'main' into fixes
Maheshkumar-novice Jul 25, 2024
e4ed78d
Fix template sending issues
Maheshkumar-novice Jul 25, 2024
cfcc24d
basic seperation of stages
Sapient44 Jul 26, 2024
e8316b5
Add some variablility in time of sending message
Sapient44 Jul 26, 2024
15d0597
Add way to move the stage forward
Sapient44 Jul 26, 2024
bd33337
Linting
Sapient44 Jul 26, 2024
23322d6
Fix error of wrong time declarations
Sapient44 Jul 26, 2024
9f635b3
change variable names
Sapient44 Jul 26, 2024
c45ad9d
check for negative values, before continuing with the game
Sapient44 Jul 26, 2024
5e99a3d
Disable false-positive warnings about random security
hazyfossa Jul 26, 2024
65edf32
fix matching stage to send delay
hazyfossa Jul 26, 2024
aaac0ea
Merge branch 'game_loop' of https://github.com/krishnabhat3383/code-j…
hazyfossa Jul 26, 2024
1fef384
Merge branch 'game_loop' into fixes
hazyfossa Jul 26, 2024
90bce52
make weighted random support condition
hazyfossa Jul 26, 2024
46ad3c3
Fixes (#11)
Maheshkumar-novice Jul 26, 2024
c63c15e
Merge branch 'main' into game_loop
hazyfossa Jul 26, 2024
7999ede
fix typing
hazyfossa Jul 26, 2024
7e78e95
rename utils.py to const.py
hazyfossa Jul 26, 2024
2084726
linting
hazyfossa Jul 26, 2024
ed35ff8
Merge pull request #13 from krishnabhat3383/game_loop
Maheshkumar-novice Jul 27, 2024
776707b
The player can now leave the game with subcommands (#12)
Sapient44 Jul 27, 2024
ec19253
Decrease the time of the message sending, to make it more choatic
Sapient44 Jul 27, 2024
f5e6e2a
Define some coloured accents
Sapient44 Jul 27, 2024
08eedb6
On death remove player
Sapient44 Jul 27, 2024
e22db7e
Add const colours
Sapient44 Jul 27, 2024
71f5113
Add start logic and fix few bugs
Maheshkumar-novice Jul 27, 2024
cb9c576
Merge branch 'main' into game_improvements
Sapient44 Jul 27, 2024
c030a45
Fix on mistake in merge conflict
Sapient44 Jul 27, 2024
6fa1ce4
Fix the issue with Embed object
Sapient44 Jul 27, 2024
df37628
changing datetime to time
Sapient44 Jul 27, 2024
7e02860
Skeleton of anti_afk
Sapient44 Jul 27, 2024
20ed0d6
Added reference of Game Factory in Game, for removing player
Sapient44 Jul 27, 2024
78802fa
Add button interaction callback
Maheshkumar-novice Jul 27, 2024
7ce36cc
Merge pull request #15 from krishnabhat3383/game_improvements
Maheshkumar-novice Jul 27, 2024
8a28ae9
Merge branch 'main' into button-interaction
Maheshkumar-novice Jul 27, 2024
d677689
Fix death player issues
Maheshkumar-novice Jul 27, 2024
19ec3fb
Merge pull request #16 from krishnabhat3383/button-interaction
Maheshkumar-novice Jul 27, 2024
98129fb
Fix game none issue
Maheshkumar-novice Jul 27, 2024
349293f
Added more actors
Dhanvantg Jul 27, 2024
dedf804
Add more Actors
Dhanvantg Jul 27, 2024
d2bf55e
Fix spacing and default values
Maheshkumar-novice Jul 27, 2024
3ed0158
Changed the format of Actors
Sapient44 Jul 28, 2024
00355cb
Some enhancements
Maheshkumar-novice Jul 28, 2024
547d442
Merge branch 'main' into anti_afk
Sapient44 Jul 28, 2024
6d83574
Fix the false start of AFK timer
Sapient44 Jul 28, 2024
0fee870
Updated afk timer, on every button interaction
Sapient44 Jul 28, 2024
7190ad8
Fix ruff issue and game ending scenarios
Maheshkumar-novice Jul 28, 2024
9a96f13
Merge pull request #18 from krishnabhat3383/enhancements
Maheshkumar-novice Jul 28, 2024
3e7917e
Added Character variable
Sapient44 Jul 28, 2024
0daa0c3
Merge branch 'main' into anti_afk
Sapient44 Jul 28, 2024
fb39337
Fixed the afk timer
Sapient44 Jul 28, 2024
285c2f6
Fix infinite loop afk issue
Maheshkumar-novice Jul 28, 2024
c870836
Add afk broadcast and embed
Maheshkumar-novice Jul 28, 2024
60bedd5
Merge branch 'main' into templating
Maheshkumar-novice Jul 28, 2024
e1e80d0
Remove the Current activity time, is outdated
Sapient44 Jul 28, 2024
63dd103
Increase min number of players
Sapient44 Jul 28, 2024
7ad875f
Merge pull request #19 from krishnabhat3383/anti_afk
Maheshkumar-novice Jul 28, 2024
87d46a1
Update gary the general
Maheshkumar-novice Jul 28, 2024
34abc09
Update sam the scientist
Maheshkumar-novice Jul 28, 2024
3e882a7
Update sandra the spy
Maheshkumar-novice Jul 28, 2024
d3c6425
Update sheela the singer
Maheshkumar-novice Jul 28, 2024
070147a
Update wong the worker
Maheshkumar-novice Jul 28, 2024
4ba2df1
update characters
Sapient44 Jul 28, 2024
2da859d
Merge branch 'templating' of https://github.com/krishnabhat3383/code-…
Sapient44 Jul 28, 2024
87cd8e1
Add alex the analyst
Maheshkumar-novice Jul 28, 2024
79d4441
Merge branch 'my-updates' into templating
Maheshkumar-novice Jul 28, 2024
5f0b4a4
Update formatting
Maheshkumar-novice Jul 28, 2024
840bc56
Update andy the athlete
Maheshkumar-novice Jul 28, 2024
7e42235
Updat aura the activist
Maheshkumar-novice Jul 28, 2024
93cb902
Update craig the contractor
Maheshkumar-novice Jul 28, 2024
d661d9f
Update dave the doctor
Maheshkumar-novice Jul 28, 2024
b075883
Add images
Sapient44 Jul 28, 2024
0725ed6
Merge branch 'templating' of https://github.com/krishnabhat3383/code-…
Sapient44 Jul 28, 2024
bc2e2dd
Update fred the farmer
Maheshkumar-novice Jul 28, 2024
30c9519
Add national media
Maheshkumar-novice Jul 28, 2024
e6e8839
Update weights
Maheshkumar-novice Jul 28, 2024
1045fc5
Picturess are here
Sapient44 Jul 28, 2024
12c8bfb
Merge branch 'templating' of https://github.com/krishnabhat3383/code-…
Sapient44 Jul 28, 2024
4e87c76
Rename to national media
Maheshkumar-novice Jul 28, 2024
48b73a6
Add thumbnail fail safe
Maheshkumar-novice Jul 28, 2024
56fae51
Merge pull request #17 from krishnabhat3383/templating
Maheshkumar-novice Jul 28, 2024
72fc545
Basic stats announce
Sapient44 Jul 28, 2024
bef58f5
Stats announce (#20)
Maheshkumar-novice Jul 28, 2024
4d93cb3
Add embeds to interaction.py (#21)
Sapient44 Jul 28, 2024
cbac17a
fixing ephemeral bug
Sapient44 Jul 28, 2024
54302af
fixing ephemeral bug
Sapient44 Jul 28, 2024
62fd7ae
Update reqs and embed issue
Maheshkumar-novice Jul 28, 2024
084c7a7
Fix embeds
Maheshkumar-novice Jul 28, 2024
743d342
Create Documentation (#22)
Maheshkumar-novice Aug 1, 2024
f85f557
Add game flow gif (#24)
Maheshkumar-novice Aug 1, 2024
a02079f
Add YT video (#25)
Maheshkumar-novice Aug 1, 2024
61d6412
Fix cases
Maheshkumar-novice Aug 1, 2024
72a1ca7
Add 'luminous-lightyears/' from commit '61d6412a8623e37500271355c80a8…
janine9vn Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions luminous-lightyears/.github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# GitHub Action workflow enforcing our code style.

name: Lint

# Trigger the workflow on both push (to the main repository, on the main branch)
# and pull requests (against the main repository, but from any repo, from any branch).
on:
push:
branches:
- main
pull_request:

# Brand new concurrency setting! This ensures that not more than one run can be triggered for the same commit.
# It is useful for pull requests coming from the main repository since both triggers will match.
concurrency: lint-${{ github.sha }}

jobs:
lint:
runs-on: ubuntu-latest

env:
# The Python version your project uses. Feel free to change this if required.
PYTHON_VERSION: "3.12"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.1
31 changes: 31 additions & 0 deletions luminous-lightyears/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Files generated by the interpreter
__pycache__/
*.py[cod]

# Environment specific
.venv
venv
.env
env

# Unittest reports
.coverage*

# Logs
*.log

# PyEnv version selector
.python-version

# Built objects
*.so
dist/
build/

# IDEs
# PyCharm
.idea/
# VSCode
.vscode/
# MacOS
.DS_Store
18 changes: 18 additions & 0 deletions luminous-lightyears/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Pre-commit configuration.
# See https://github.com/python-discord/code-jam-template/tree/main#pre-commit-run-linting-before-committing

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff
- id: ruff-format
7 changes: 7 additions & 0 deletions luminous-lightyears/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 Python Discord

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
262 changes: 262 additions & 0 deletions luminous-lightyears/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
<p align="center" id="defcord">
<img src="https://github.com/user-attachments/assets/97a9a8f3-9749-4a47-91d8-7bafe9071199" alt="Game Logo" width="200" height="200">
</p>

<h1 align="center">Defcord</h1>

<p align="center"><i>Lead Nations. Compete. Outsmart.</i></p>

<details open="open">
<summary>Table Of Contents</summary>
<ol>
<li>
<a href="#about">About</a>
</li>
<li>
<a href="#vital-attributes">Vital Attributes</a>
</li>
<li>
<a href="#game-model">Game Model</a>
</li>
<li>
<a href="#available-commands">Available Commands</a>
</li>
<li>
<a href="#theme-relativity">How the bot relate to the theme `Information Overload`</a>
</li>
<li>
<a href="#known-issues">Known Issues</a>
</li>
<li>
<a href="#enhancements">Enhancements</a>
</li>
<li>
<a href="#contributions">Contributions</a>
</li>
<li>
<a href="#running-the-app">Running the App</a>
</li>
<li>
<a href="#demo">Demo of the game</a>
</li>
<li>
<a href="#video-showcase">A Video of the Gameplay</a>
</li>
</ol>
</details>

## About

Defcord is a multiplayer, discord application based game.

You play as a leader of a nation and it is your responsibility to make good decisions based on the information given to you.

You should make sure all of your vital attributes stay positive.

You can't know what vital attributes increase/decrease for the given information for the decision you make because you know, people are complex.

Whoever stays alive till the end of the game is the survivor of the game. If multiple people survive they are also survivors.

The main goal is to make sure you won't run out of your vital attributes in order to survive.

## Vital Attributes

| Attribute | Default Value |
|---------------|---------------|
| Money | 100 |
| Loyalty | 50 |
| Security | 50 |
| World Opinion | 50 |

## Game Model

One player is mapped with only one game. So at a time, a player can game participate in only one game.

The game time will be a random time between `12.5` and `16` minutes.

We have `3` stages, each stage will make the information flow faster.

If the player is AFK or non-responsive to the information for `60` seconds, they're disqualified automatically.

## Available Commands


### `/defcord create`

We use this command to create a defcord game. Whoever creates will be part of the game by default and they'll be the only one who can start the game.

User needs to enter the number of players they want in the game and the nation name they want to be the leader of.

Once the game is created, a message will be posted with the invite code. Other players need to use the invite code to join the game.

A player can join from a different channel or even a different server. Only requirement is in that server `defcord` should be installed.


### `/defcord join`

Other payers need to use this command with the given/taken invite code from the game creator in order to join a `defcord` game.

They also need to enter their nation name, via a modal prompt.


### `/defcord start`

Once the required number of players join, the game creator can start the game. Once invoked, the command will automatically start the game that the current player created and part of.

After that, stage `1` begins. Players will receive information at a slow rate first, as the game progresses it'll get faster.

Now the players should start respond to the information by making a good decision in order to survive.


### `/defcord leave`

If the player wants to leave in the middle of the game or before the game start, they can do. But if they leave in the middle of the game, they cannot rejoin. They can join another game.

If you are the last member to quit, you are the survivor of the game as you have no one to compete. But you can play till the game time and see what the game brings you. If you run out of an attribute than you are done.


## Theme Relativity

Given theme is `Information Overload`. Here we try to make the player overwhelmed by giving them information continuously.

They need to keep making good decisions in order to survive. Because they can't give `yes` to all the requests i.e. army tool requests, it'll cost their money. This is also applicable to the reverse situation where the player denies all requests.

After every stage we show the player's attributes so they need to make a quick play to proceed with the next stage. We have AFK mechanism in place so they can't sit idle, information flow till the game end.

## Known Issues

- `/defcord start` will show as `Application did not respond` in the invalid use case scenarios instead of showing a relevant message to the user. This is due to a fact that we missed to `await` that message call during a code refactor. Invalid use case scenarios,
* Trying to start the game without being in one
* When in a game, trying to start it (only creator can)
* Trying to start a game is already running
* Trying to start the game before all the players join
- We have an image embedded in each message to represent the actor of the message. But sometimes the service that we used to host the images goes down. So sometimes the images won't appear. If you receive any error due to this in the console or bot crashes due to this, you can set this env variable `WITHOUT_ACTOR_THUMBNAIL` to `True` to disable thumbnail functionality.

## Enhancements

- Include attribute sabotage and request mechanism so that it'll be more PvP instead of PvE.
- Game time can be configurable by the creator.
- Include encryption like mechanism to make it harder for the user.
- Option to stop the game by the creator (current work around is to make all players leave / die).
- Enhance random information picking logic to make it more relevant to the players context and reduce repetitiveness of information.
- Option to pause the game.
- Option to start the game if everyone has not joined.

## Contributions

- **Clueless_conoisseur** (krishnabhat): Checking PRs, structuring the project
- **Automafun** (Dhanvantg): Basic game character formation, logo creation
- **Diverman** (hazyfossa): Coding game factory, player classes, implementing character templates, weighted randomness logic
- **Maheshkumar**: Coding button interactions, defcord start command, advanced UI components
- **Sapient**: Basic UI elements, PlayerState class default values, Game class creation, game flow, Anti-AFK mechanism, character images

## Running The App

We require you to have `python 3.12`.

### Clone

```sh
git clone https://github.com/krishnabhat3383/code-jam-24-luminous-lightyears.git
```

if you prefer ssh way,

```sh
git clone git@github.com:krishnabhat3383/code-jam-24-luminous-lightyears.git
```

### Move To Directory

```sh
cd code-jam-24-luminous-lightyears
```

### Create Virtual Environment

```sh
python3 -m venv .venv
```

### Activate Virtual Environment

```sh
source .venv/bin/activate
```

### Install Requirements

```sh
pip install -r requirements.txt
```

### Setup Bot Token

```sh
export DEFCON_BOT_TOKEN=<token>
```

for a persistent way,

```sh
touch .env
```

```sh
echo "DEFCON_BOT_TOKEN=<token>" >> .env
```

### Run The Application

```sh
python main.py
```

## Demo

After the starting of the bot, following would need to be done to start the game.

1) To initiate the game the player (further referred as 'creator' of the game) need to use `/defcord create` and add the max number of players in the game.

<img src="https://github.com/user-attachments/assets/82d6042f-d112-4099-bec1-97625d47e16a" alt="Game" width="400" height="auto">

2) The creator will receive a modal, which will ask for their nation name.

<img src="https://github.com/user-attachments/assets/7e306a06-5d21-4a1f-972d-d47db06924e3" alt="Game" width="300" height="auto">

3) After entering the nation name the creator will receive 3 messages.

1st message referring to them as a player and their nation name.

2nd message is a game code, for anyone joining the game (visible to everyone in chat)

3rd message is the standard joining message, indicating how many players are left to join and who has last joined (here the game created if of 2 players)

</br>

<img src="https://github.com/user-attachments/assets/c1e1b135-9d97-44a8-b31b-6e078c04dfeb" alt="Game" width="300" height="auto">

4) Other wannabe players would need to use `/defcord join` with the invite code to join the game

<img src="https://github.com/user-attachments/assets/045061b9-46f6-45fe-a42c-ca3770548236" alt="Game" width="300" height="auto">

5) After everyone joining the game, everyone in the game will receive this message

<img src="https://github.com/user-attachments/assets/6d3756e8-6f8e-4c3c-83cc-9d4a8ef1f19d" alt="Game" width="300" height="auto">

(Here `Thonk` being the last player joined)

6) After this the creator is able to use the command `/defcord start` to start the game, and then everyone will receive 3 messages (3rd one being part of the main game, hence covered below)

<img src="https://github.com/user-attachments/assets/3da4659d-5671-480b-87ea-da0202571112" alt="Game" width="300" height="auto">

7) Game flow - example

![flow](https://github.com/user-attachments/assets/df7e944a-a361-47c5-862a-34a4b44f0bf0)


## Video Showcase
https://youtube.com/shorts/Aox39yoCAXY


[Move To Top](#defcord)
Loading