252 lines
9.1 KiB
Python
252 lines
9.1 KiB
Python
from irc_api import commands
|
|
from irc_api.commands import auto_help
|
|
|
|
from random import randint, choice
|
|
import sqlite3
|
|
|
|
|
|
GAME_CHANNEL = "#glados"
|
|
|
|
|
|
def get_hunter(name: str):
|
|
def get():
|
|
table = sqlite3.connect("duck_hunting.db")
|
|
c = table.cursor()
|
|
data = c.execute(f"""
|
|
SELECT * FROM hunter
|
|
WHERE name="{name}"
|
|
""").fetchall()
|
|
table.close()
|
|
return data
|
|
|
|
data = get()
|
|
if not data:
|
|
add_hunter(name)
|
|
data = get()
|
|
|
|
return list(data[0][1:])
|
|
|
|
|
|
def add_hunter(name: str):
|
|
table = sqlite3.connect("duck_hunting.db")
|
|
c = table.cursor()
|
|
c.execute(f"""
|
|
INSERT INTO hunter (name)
|
|
VALUES ("{name}")
|
|
""")
|
|
table.commit()
|
|
table.close()
|
|
|
|
|
|
def del_hunter(name: str):
|
|
table = sqlite3.connect("duck_hunting.db")
|
|
c = table.cursor()
|
|
c.execute(f"""
|
|
DELETE FROM hunter
|
|
WHERE name="{name}"
|
|
""")
|
|
table.commit()
|
|
table.close()
|
|
|
|
|
|
def modify_hunter(name: str, **kwargs):
|
|
args = ""
|
|
for var, value in kwargs.items():
|
|
args += f"{var}={value}, "
|
|
|
|
table = sqlite3.connect("duck_hunting.db")
|
|
c = table.cursor()
|
|
c.execute(f"""
|
|
UPDATE hunter
|
|
SET {args[:-2]}
|
|
WHERE name="{name}"
|
|
""")
|
|
table.commit()
|
|
table.close()
|
|
|
|
|
|
|
|
@commands.every(30, desc="Fait apparaître un canard de manière aléatoire.")
|
|
def pop_duck(bot):
|
|
if randint(1, 100) <= 20:
|
|
if bot.troll_duck > 0 and randint(1, 4) <= 3:
|
|
bot.troll_duck -= 1
|
|
bot.ducks_history.append(2)
|
|
ducks = ("crr… Coin coin ! 🦆", "Couac crr… ! 🦆")
|
|
elif randint(1, 10) == 1:
|
|
ducks = ("COIN COIN ! 🦆", "COUAC ! 🦆")
|
|
bot.ducks_history.append(1)
|
|
else:
|
|
ducks = ("Coin coin ! 🦆", "Couac ! 🦆")
|
|
bot.ducks_history.append(0)
|
|
|
|
bot.send(GAME_CHANNEL, choice(ducks))
|
|
if randint(1, 100) <= 15 and len(bot.ducks_history) > 1:
|
|
ducks = ("Le canard est parti…", "Le canard s'est envolé…")
|
|
bot.send(GAME_CHANNEL, "Le canard est parti…")
|
|
bot.ducks_history.pop(0)
|
|
|
|
|
|
@commands.channel(GAME_CHANNEL)
|
|
@commands.command("pan", desc="Tirer sur un canard.")
|
|
def fire(bot, msg):
|
|
money, ammo, ammo_in_chamber, _, has_scope, grease, is_jammed = get_hunter(msg.author)
|
|
|
|
if ammo_in_chamber <= 0:
|
|
bot.send(GAME_CHANNEL, "Chambre vide ! Il faut recharger. 😉")
|
|
return
|
|
|
|
if is_jammed:
|
|
bot.send(GAME_CHANNEL, "Votre fusil est enrayé !")
|
|
return
|
|
|
|
if grease > 0:
|
|
grease -= 1
|
|
elif grease == 0 and randint(1, 100) < 33:
|
|
is_jammed = 1
|
|
|
|
if len(bot.ducks_history) > 0:
|
|
is_hit = randint(1, 100)
|
|
if has_scope:
|
|
has_scope -= 1
|
|
is_hit = randint(1, 15)
|
|
|
|
if is_hit <= 80:
|
|
duck_type = bot.ducks_history.pop(-1)
|
|
money += 2
|
|
if duck_type == 2:
|
|
hit = ("Oh un canard en plastique", "Peeww… CLONG")
|
|
bot.send(GAME_CHANNEL, "Canard mécanique ! [munition -1]\n" + choice(hit))
|
|
elif duck_type == 1 or is_hit < 10:
|
|
money += 2
|
|
hit = ("C'était un super canard !", "Ouh la belle bête !", "ÇA c'est du canard.")
|
|
bot.send(GAME_CHANNEL, "Super canard touché ! [argent +4, munition -1]\n" + choice(hit))
|
|
elif duck_type == 0:
|
|
hit = ("Touché !", "Et un canard en moins !", "You dit it bro!", "Joli tir !", "Peeww !")
|
|
bot.send(GAME_CHANNEL, "Canard touché ! [argent +2, munition -1]\n" + choice(hit))
|
|
|
|
|
|
else:
|
|
fail = ("Et le canard est toujours vivant…", "Mais… Pourquoi tu tires à côté ?", "Il est pas passé loin de la vieille celui-là !")
|
|
bot.send(GAME_CHANNEL, "Tir raté… [munition -1]\n" + choice(fail))
|
|
|
|
else:
|
|
no_ducks = ("Euh, va faire vérifier ta vue s'il-te-plaît.", "Il est où le canard ? Il est bien caché ?", "Et une grand mère en moins ! Une ! Wait…", "Un canard ne hurle pas comme ça.", "Joli tir… Mais ce n'était pas un canard…")
|
|
bot.send(GAME_CHANNEL, "Aucun canard en vue. [munition -1]\n" + choice(no_ducks))
|
|
|
|
modify_hunter(msg.author, money=money, ammo=ammo, ammo_in_chamber=ammo_in_chamber - 1, has_scope=has_scope, grease=grease, is_jammed=is_jammed)
|
|
|
|
|
|
@commands.channel(GAME_CHANNEL)
|
|
@commands.command("recharge", alias=("reload",), desc="Fait monter une balle du chargeur dans la chambre")
|
|
def reload(bot, msg):
|
|
ammo, ammo_in_chamber, max_ammo = get_hunter(msg.author)[1: 4]
|
|
ammo_to_fill = max_ammo - ammo_in_chamber
|
|
|
|
if ammo_to_fill == 0:
|
|
bot.send(GAME_CHANNEL, "Ton arme est déjà chargée.")
|
|
elif ammo > 0:
|
|
if ammo >= ammo_to_fill:
|
|
ammo_filled = ammo_to_fill
|
|
else:
|
|
ammo_filled = ammo
|
|
modify_hunter(msg.author, ammo=ammo - ammo_filled, ammo_in_chamber=ammo_in_chamber + ammo_filled)
|
|
bot.send(GAME_CHANNEL, f"{msg.author} a rechargé son arme.")
|
|
else:
|
|
bot.send(GAME_CHANNEL, f"Plus de munitions ! Va voir le magasin pour en acheter. 😉")
|
|
|
|
|
|
@commands.channel(GAME_CHANNEL)
|
|
@commands.command("stat", alias=("info",), desc="Affiche les statistiques du joueur.")
|
|
def stat(bot, msg):
|
|
money, ammo, ammo_in_chamber, max_ammo, has_scope, grease, is_jammed = get_hunter(msg.author)
|
|
|
|
additionnal_infos = ""
|
|
if has_scope:
|
|
additionnal_infos += "[lunette installée] "
|
|
if is_jammed:
|
|
additionnal_infos += "[fusil enrayé] "
|
|
|
|
text = f"Statistiques de {msg.author} {additionnal_infos[:-1]}\n"
|
|
text += f" │ argent : {money}\n"
|
|
text += f" │ chargeur : {ammo_in_chamber} / {max_ammo}\n"
|
|
text += f" │ munitions : {ammo}\n"
|
|
text += f" │ graisse : {grease}"
|
|
|
|
bot.send(GAME_CHANNEL, text)
|
|
|
|
|
|
@commands.channel(GAME_CHANNEL)
|
|
@commands.command("nettoyer", alias=("clean",), desc="Nettoie le fusil.")
|
|
def clear(bot, msg):
|
|
grease, is_jammed = get_hunter(msg.author)[5: 7]
|
|
|
|
if is_jammed:
|
|
if grease:
|
|
bot.send(GAME_CHANNEL, f"{msg.author} a nettoyé son fusil !")
|
|
grease -= 1
|
|
is_jammed = 0
|
|
else:
|
|
bot.send(GAME_CHANNEL, "Vous devez acheter de la graisse pour pouvoir nettoyer votre fusil.")
|
|
else:
|
|
bot.send(GAME_CHANNEL, "Votre fusil est déjà en bon état.")
|
|
|
|
modify_hunter(msg.author, grease=grease, is_jammed=is_jammed)
|
|
|
|
@commands.channel("Duck")
|
|
@commands.command("duck", desc="Fait apparaître un canard mécanique.")
|
|
def fake_duck(bot, msg):
|
|
bot.troll_duck += 1
|
|
bot.send(msg.author, "Un canard mécanique apparaîtra… ou pas !")
|
|
|
|
|
|
@commands.channel(GAME_CHANNEL)
|
|
@commands.command("reset", desc="Réinitialise le profil du joueur")
|
|
def reset(bot, msg):
|
|
hunter = get_hunter(msg.author)[:3]
|
|
bot.send(GAME_CHANNEL, f"Le profil de {msg.author} a été réinitialisé.")
|
|
del_hunter(msg.author)
|
|
|
|
|
|
@commands.channel(GAME_CHANNEL)
|
|
@commands.command("achat", alias=("magasin", "shop"), desc="Acheter des munitions et accessoires.\nLancer la commande sans arguments pour voir le magasin.")
|
|
def achat(bot, msg, article: str=""):
|
|
def get_spec(spec):
|
|
fields = ("argent", "munition", "munition dans la chambre", "capacité chargeur", "lunette de visée", "graisse")
|
|
text = "["
|
|
for field_index, value in spec.items():
|
|
text += f"{fields[field_index]} {('-', '+')[abs(value) == value]}{abs(value)}, "
|
|
return text[:-2] + "]"
|
|
|
|
hunter = get_hunter(msg.author)
|
|
db_fields = ("money", "ammo", "ammo_in_chamber", "max_ammo", "has_scope", "grease")
|
|
|
|
availables_articles = {
|
|
"chargeur": ("Ajoute cinq balles à ton inventaire", "un chargeur", {0: -4, 1: 5}),
|
|
"balle": ("Ajoute une balle à ton inventaire", "une balle", {0: -1, 1: 1}),
|
|
"capacité": ("Augmente la capacité du chargeur d'une balle", "un chargeur haute capacité", {0: -5, 3: 1}),
|
|
"viseur": ("Votre prochain tir touchera forcément un canard.", "une lunette de visée", {0: -3, 4: 1}),
|
|
"graisse": ("Permet de nettoyer son arme et de limiter le risque d'enrayement.", "une boîte de graisse pour fusil", {0: -3, 5: 5})
|
|
}
|
|
|
|
if article:
|
|
article = article.lower()
|
|
if article in availables_articles.keys():
|
|
args = availables_articles[article]
|
|
|
|
# not enough money
|
|
if hunter[0] < abs(args[2][0]):
|
|
bot.send(GAME_CHANNEL, f"Vous n'avez pas assez d'argent pour acheter {args[1]} {get_spec(args[2])}.")
|
|
else:
|
|
bot.send(GAME_CHANNEL, f"Vous avez acheté {args[1]} {get_spec(args[2])}.")
|
|
for index, value in args[2].items():
|
|
hunter[index] += value
|
|
modify_hunter(msg.author, **{field: hunter[i] for i, field in enumerate(db_fields)})
|
|
else:
|
|
msg = "Liste des articles disponibles :\n"
|
|
msg += "".join([
|
|
f" | {article} : {args[0]} {get_spec(args[2])}\n"
|
|
for article, args in availables_articles.items()
|
|
])
|
|
bot.send(GAME_CHANNEL, msg)
|