From 9350c8966a641bfa4bcfb66dee5630188012407d Mon Sep 17 00:00:00 2001 From: Samuele Lorefice Date: Sun, 5 Nov 2023 16:24:31 +0100 Subject: [PATCH] proof of concept made --- .gitignore | 192 +++++++++ .idea/.gitignore | 8 + .idea/IsleBot.iml | 10 + .idea/dbnavigator.xml | 403 ++++++++++++++++++ .idea/inspectionProfiles/Project_Default.xml | 54 +++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + Card.py | 25 ++ Player.py | 24 ++ main.py | 95 +++++ start.ps1 | 0 13 files changed, 838 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/IsleBot.iml create mode 100644 .idea/dbnavigator.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Card.py create mode 100644 Player.py create mode 100644 main.py create mode 100644 start.ps1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2452a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,192 @@ +### PythonVanilla template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + + +### Python template +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +#ignore .env +.env \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/IsleBot.iml b/.idea/IsleBot.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/.idea/IsleBot.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..6fc0e30 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..ee80c28 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,54 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4073b5e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..832b3e4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Card.py b/Card.py new file mode 100644 index 0000000..76ae43b --- /dev/null +++ b/Card.py @@ -0,0 +1,25 @@ +import string + + +class Card: + id: int = 0 + name: string = "" + attack: int = 0 + defence: int = 0 + currHp: int = 0 + maxHp: int = 0 + + def __init__(self, id: int, name: string, attack: int, defense: int): + self.id = id + self.name = name + self.attack = attack + self.defense = defense + + def __str__(self): + return f"Card: {self.name} - Attack: {self.attack} - Defense: {self.defense}" + + def Attack(self, card): + # current formula being sustained damage = attack - own card defence + card.currHp -= (self.attack-card.defense) + # might want to expand with crits and dice rolls to make it more fun + diff --git a/Player.py b/Player.py new file mode 100644 index 0000000..bb59b2d --- /dev/null +++ b/Player.py @@ -0,0 +1,24 @@ +import string + +from Card import Card + + +class Player: + id: string = "" + name: string = "" + activeCard: Card = None + + + def __init__(self, id: string, name: string): + self.id = id + self.Name = name + + def __str__(self): + return f"Player: {self.Name} - ID: {self.id}" + + def setActiveCard(self, card: Card): + self.activeCard = card + + def getActiveCard(self): + return self.activeCard + diff --git a/main.py b/main.py new file mode 100644 index 0000000..56ea30d --- /dev/null +++ b/main.py @@ -0,0 +1,95 @@ +import os +import random +import dotenv +import discord + +from Card import Card +from Player import Player + + +dotenv.load_dotenv() +token = os.getenv("TOKEN") +#intents: discord.Intents = discord.Intents.default() +#intents.guilds = True +#intents.members = True +#intents.messages = True +#intents.message_content = True + +bot = discord.Bot() +rng = random.Random() +players = [] + +@bot.event +async def on_ready(): + print("Bot loaded") + +@bot.event +async def on_message(message): + # Prevents bot from responding to itself + if message.author == bot.user: + return + + if message.content.startswith("!hello"): + await message.channel.send("Hello!") + return + +@bot.slash_command(name="get-card", description="Get a random card") +async def getCard(ctx: discord.ApplicationContext): + sender = ctx.author + player = Player(sender.id, sender.name) + player.activeCard = Card(1, f"TestCard {rng.randint(0, 1999)}", rng.randint(2,20), rng.randint(0,5)) + + for p in players: + if p.id == player.id: + p.activeCard = player.activeCard + await ctx.respond(f"You already have a card, swapping it...\nYour new card is: \n {p.activeCard}") + return + players.append(player) + await ctx.respond(f"Your card is: \n {player.activeCard}") + return + +@bot.slash_command(name="attack", description="Attack another player") +async def attackPlayer(ctx: discord.ApplicationContext, target: discord.Member): + attacker: Player = None + defender: Player = None + + if target == ctx.author: + await ctx.respond("You can't attack yourself!") + return + + if target.bot: + await ctx.respond("You can't attack a bot!") + return + + for p in players: + if p.id == ctx.author.id: + attacker = p + if p.activeCard == None: + await ctx.respond("You don't have a card! Generate one first!") + return + break + + for p in players: + if p.id == target.id: + defender = p + if p.activeCard == None: + await ctx.respond("That player doesn't have a card! Tell him to generate one first!") + return + break + + if attacker is None or defender is None: + await ctx.respond(f"can't find a match... attacker: {attacker} defender: {defender}") + return + + attacker.activeCard.Attack(defender.activeCard) + + if defender.activeCard.currHp <= 0: + await ctx.respond(f"{attacker.Name} attacked {defender.Name} and killed his card!") + players.remove(defender) + return + else: + await ctx.respond(f"{attacker.Name} attacked {defender.Name}! {defender.Name}'s card has {defender.activeCard.currHp} hp left!") + await ctx.send(f"Battle Status:\n{attacker.Name}'s card: {attacker.activeCard.currHp} hp left\n{defender.Name}'s card: {defender.activeCard.currHp} hp left") + return + +bot.run(token) \ No newline at end of file diff --git a/start.ps1 b/start.ps1 new file mode 100644 index 0000000..e69de29