diff --git a/bot.py b/bot.py index 9bbb1835bc1e64af21818311177d5b8bfd62b143..2664277fa51a102073fe7cecb9ee3dd96794b3f9 100644 --- a/bot.py +++ b/bot.py @@ -47,7 +47,6 @@ class Attribute: class Character: def checkSystemAttributes(self, systemName, attributeName): - print(systemName) system = getSystemByName(systemName) return attributeName in system.attributes; @@ -58,12 +57,14 @@ class Character: saveCharacters() - def __init__(self, systemName, name,owner,main=True): + def __init__(self, systemName, name,owner,xp = 0,notes="",main=True): self.attributes=[] self.competences=[] self.system = systemName self.name = name self.owner = owner + self.xp = xp + self.notes = notes self.setMain(main) def addAttribute(self, attributeName, attributeValue): for attr in self.attributes: @@ -90,7 +91,21 @@ class Character: saveCharacters() else: raise AttributeNotReconized(attributeName,self.system) + + def setxp(self, newxp): + self.xp = newxp + saveCharacters() + def setnotes(self, newnotes): + self.notes = newnotes + saveCharacters() + def getAttribute(attrName): + for attr in self.attributes: + if attributeName==attr.name: + return attr.level + return 0 + + def addSystem(name, attributes): global systems for system in systems: @@ -299,6 +314,62 @@ async def addcompetence(ctx , compName, attrName, value,characterName = None ): except Exception as e: await ctx.send('Exception : {}'.format(e)) + +@bot.command(name='addxp', help='Ajoute de l\'expérience au personnage') +async def addxp(ctx , value,characterName = None ): + author = '{}'.format(ctx.message.author) + try: + if characterName is None: + char= getMainCharactersByOwner(author) + else: + char = getCharacterByName(name) + newxp = char.xp+int(value) + char.setxp(newxp) + await ctx.send('{0} experience added for {1}, total : {2}'.format(value, char.name, newxp)) + except Exception as e: + await ctx.send('Exception : {}'.format(e)) + +@bot.command(name='setnotes', help='Modifie la note de personnage') +async def setnotes(ctx , value,characterName = None ): + author = '{}'.format(ctx.message.author) + try: + if characterName is None: + char= getMainCharactersByOwner(author) + else: + char = getCharacterByName(name) + char.setnotes(value) + await ctx.send('Note modified for {}'.format(char.name)) + except Exception as e: + await ctx.send('Exception : {}'.format(e)) + +@bot.command(name='addnotes', help='Ajoute des notes de personnage', aliases=['addnote']) +async def addnotes(ctx , value,characterName = None ): + author = '{}'.format(ctx.message.author) + try: + if characterName is None: + char= getMainCharactersByOwner(author) + else: + char = getCharacterByName(name) + newnotes = char.notes + "\n"+value + char.setnotes(newnotes) + await ctx.send('Notes added for {}'.format(char.name)) + except Exception as e: + await ctx.send('Exception : {}'.format(e)) + +@bot.command(name='getnotes', help='Affiche la note de personnage', aliases=['notes']) +async def getnotes(ctx, characterName = None ): + author = '{}'.format(ctx.message.author) + try: + if characterName is None: + char= getMainCharactersByOwner(author) + else: + char = getCharacterByName(name) + await ctx.send('Notes for {0}:\n{1}'.format(char.name,char.notes)) + except Exception as e: + await ctx.send('Exception : {}'.format(e)) + + + @bot.command(name='setmain', help='Redéfinit votre personnage principal') async def setmain(ctx, name): author = '{}'.format(ctx.message.author) @@ -335,7 +406,7 @@ async def getsys(ctx, name): attrs = "\n-".join(attr for attr in sys.attributes) await ctx.send('The system {0} have the following attributes :\n-{1}'.format(name,attrs)) -@bot.command(name='addsys', help='Ajoute un systeme addsys nom <attributs séparés par espace>') +@bot.command(name='addsys', help='Ajoute un systeme : addsys nom <attributs séparés par espace>') @has_permissions(administrator=True) async def addsys(ctx, name, *,attributes): try : @@ -360,8 +431,20 @@ async def r(ctx, what, characterName = None): char = getCharacterByName(characterName) for comp in char.competences: if what==comp.name: - await ctx.send("Competences not implemented yet") - return + if char.system=="Milipi": + roll = [] + for i in range(comp.level): + roll.append(random.choice(range(1, 10 + 1))) + noduplicates = set(roll) + dicebonus = roll.length - noduplicates.length + attrbonus = char.getAttribute(comp.attribute) + maxdice = max(roll) + res = maxdice + dicebonus + attr.level + await ctx.send('The result for the {0} check is : {1} ({2} + {3} + {4})'.format(what, res,maxdice,dicebonus,attrbonus)) + return + else: + await ctx.send("Competences not implemented yet") + return for attr in char.attributes: if what==attr.name: if char.system=="Maxence": @@ -370,6 +453,16 @@ async def r(ctx, what, characterName = None): res = randompart - custom await ctx.send('The result for the {0} check is : {1} ({2} - {3})'.format(what, res,randompart,custom)) return + elif char.system=="Milipi": + roll = [] + for i in range(attr.level): + roll.append(random.choice(range(1, 10 + 1))) + noduplicates = set(roll) + dicebonus = roll.length - noduplicates.length + maxdice = max(roll) + res = maxdice + dicebonus + attr.level + await ctx.send('The result for the {0} check is : {1} ({2} + {3} + {4})'.format(what, res,maxdice,dicebonus,attr.level)) + return else: await ctx.send('Character system {} not supported yet'.format(char.system)) return @@ -377,7 +470,7 @@ async def r(ctx, what, characterName = None): await ctx.send('You must specify as argument an attribute or a competence for your character : {}.'.format(char.name)) except Exception as e: await ctx.send('Exception found : {0}'.format(e)) - + @bot.event async def on_command_error(ctx, error): if isinstance(error, commands.errors.CheckFailure): @@ -385,4 +478,7 @@ async def on_command_error(ctx, error): loadAll() +#for char in characters: +# setattr(char, "notes", "") +# setattr(char, "xp", 0) bot.run(TOKEN) \ No newline at end of file