Advertisement
Guest User

RPGBOT.py

a guest
Mar 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.73 KB | None | 0 0
  1. import discord
  2. import random
  3. import pickle
  4. import asyncio
  5. from random import shuffle
  6. from discord.ext import commands
  7. bot = commands.Bot(command_prefix='$$', description='RPG bot')
  8. bot.remove_command('help')
  9. @bot.event
  10. async def on_ready():
  11.     global plyChars
  12.     global helper
  13.  
  14.     print('Logged in as')
  15.     print(bot.user.name)
  16.     plyChars = {}
  17.     helper = False
  18.  
  19. @bot.command(pass_context=True)
  20. async def INFO(ctx):
  21.     global plyChars
  22.     usrName = str(ctx.message.author)
  23.     if plyChars[usrName] is None:
  24.         await bot.say('Load a :person_with_blond_hair::skin-tone-5: with $$PLAY')
  25.         return
  26.     fileN = plyChars[usrName] + '.' + usrName
  27.     charSh = pickle.load(open(fileN, "rb"))
  28.     plClass = charSh['Class']
  29.     plName = charSh['Name']
  30.     plAtk = charSh['Atk']
  31.     plDef = charSh['Def']
  32.     plLuk = charSh['Luk']
  33.     plHp = charSh['Hp']
  34.     plExp = charSh['Exp']
  35.     await bot.say('{} the {}\n{} :sparkling_heart:\n{} :crossed_swords:\n{} :shield:\n{} :moneybag:\n{} EXP'.format(plName, plClass, plHp, plAtk, plDef, plLuk, plExp))
  36.  
  37. @bot.group(pass_context=True)
  38. async def help(ctx):
  39.     if ctx.invoked_subcommand is None:
  40.         await bot.say('use $$help <command> \n create \n PLAY \n FGT \n LVL')
  41. @help.command()
  42. async def create():
  43.     helpC = open('help1.help', "r")
  44.     helpB = helpC.readlines()
  45.     for line in helpB:
  46.          await bot.say(line)
  47. @help.command()
  48. async def PLAY():
  49.     helpC = open('help3.help', "r")
  50.     helpB = helpC.readlines()
  51.     for line in helpB:
  52.          await bot.say(line)
  53.  
  54. @help.command()
  55. async def FGT():
  56.     helpC = open('help2.help', "r")
  57.     helpB = helpC.readlines()
  58.     for line in helpB:
  59.          await bot.say(line)
  60. @help.command()
  61. async def LVL():
  62.     helpC = open('help4.help', "r")
  63.     helpB = helpC.readlines()
  64.     for line in helpB:
  65.          await bot.say(line)
  66.  
  67.  
  68. @bot.command(pass_context=True)
  69. async def players(ctx):
  70.     global plyChars
  71.     plyCharsS = str(plyChars)
  72.     await bot.say('{}'.format(plyCharsS))
  73.    
  74. @bot.command(pass_context=True)
  75. async def hello(ctx, userName: discord.Member = None):
  76.     if userName is None:
  77.         userName = ctx.message.author
  78.     await bot.say('Hello, {0}!'.format(userName))
  79.  
  80. @bot.group(pass_context=True)
  81. async def create(ctx):
  82.     global usrName
  83.     if ctx.invoked_subcommand is None:
  84.         await bot.say('I KNOW ITS STUPID TO HAVE TO TYPE PC BUT THATS HOW IT IS! Type $$help for more info')
  85.     usrName = ctx.message.author
  86. @bot.group(pass_context=True)
  87. async def LVL(ctx):
  88.     global plyChars
  89.     global usrName
  90.     global charSh
  91.     usrName = str(ctx.message.author)
  92.     if ctx.invoked_subcommand is None:
  93.         await bot.say('Pick a stat! use $$help LVL')
  94.         return
  95.     fileN = plyChars[usrName] + '.' + usrName
  96.     charSh = pickle.load(open(fileN, "rb"))
  97.  
  98. @LVL.command()
  99. async def ATK():
  100.     global usrName
  101.     global plyChars
  102.     global charSh
  103.     fileN = plyChars[usrName] + '.' + usrName
  104.     if charSh['Exp'] < (charSh['Lvl']*1000):
  105.         await bot.say("you don't have enough EXP to level up, fight some shit")
  106.         pickle.dump(charSh, open(fileN, "wb"))
  107.         return
  108.     else:
  109.         charSh['Lvl'] = charSh['Lvl'] + 1
  110.         charSh['Atk'] = charSh['Atk'] + 2
  111.         charSh['Hp'] = charSh['Hp'] + 4
  112.         await bot.say("{}'s :crossed_swords: increased by 2! {} total :crossed_swords: \n Level is now {}".format(charSh['Name'], charSh['Atk'], charSh['Lvl']))
  113.         pickle.dump(charSh, open(fileN, "wb"))
  114.  
  115. @LVL.command()
  116. async def DEF():
  117.     global usrName
  118.     global plyChars
  119.     global charSh
  120.     fileN = plyChars[usrName] + '.' + usrName
  121.     if charSh['Exp'] < (charSh['Lvl']*1000):
  122.         await bot.say("you don't have enough EXP to level up, fight some shit")
  123.         pickle.dump(charSh, open(fileN, "wb"))
  124.         return
  125.     else:
  126.         charSh['Lvl'] = charSh['Lvl'] + 1
  127.         charSh['Def'] = charSh['Def'] + 2
  128.         charSh['Hp'] = charSh['Hp'] + 4
  129.         await bot.say("{}'s :shield: increased by 2! {} total :shield: \n Level is now {}".format(charSh['Name'], charSh['Def'], charSh['Lvl']))
  130.         pickle.dump(charSh, open(fileN, "wb"))
  131.  
  132. @LVL.command()
  133. async def LUK():
  134.     global usrName
  135.     global plyChars
  136.     global charSh
  137.     fileN = plyChars[usrName] + '.' + usrName
  138.     if charSh['Exp'] < (charSh['Lvl']*1000):
  139.         await bot.say("you don't have enough EXP to level up, fight some shit")
  140.         pickle.dump(charSh, open(fileN, "wb"))
  141.         return
  142.     else:
  143.         charSh['Lvl'] = charSh['Lvl'] + 1
  144.         charSh['Luk'] = charSh['Luk'] + 2
  145.         charSh['Hp'] = charSh['Hp'] + 4
  146.         await bot.say("{}'s :moneybag: increased by 2! {} total :moneybag: \n Level is now {}".format(charSh['Name'], charSh['Luk'], charSh['Lvl']))
  147.         pickle.dump(charSh, open(fileN, "wb"))
  148.  
  149. @LVL.command()
  150. async def HP():
  151.     global usrName
  152.     global plyChars
  153.     global charSh
  154.     fileN = plyChars[usrName] + '.' + usrName
  155.     if charSh['Exp'] < (charSh['Lvl']*1000):
  156.         await bot.say("you don't have enough EXP to level up, fight some shit")
  157.         pickle.dump(charSh, open(fileN, "wb"))
  158.         return
  159.     else:
  160.         charSh['Lvl'] = charSh['Lvl'] + 1
  161.         charSh['Hp'] = charSh['Hp'] + 10
  162.         await bot.say("{}'s :sparkling_heart: increased by 10! {} total :sparkling_heart: \n Level is now {}".format(charSh['Name'], charSh['Hp'], charSh['Lvl']))
  163.         pickle.dump(charSh, open(fileN, "wb"))
  164.  
  165. @bot.command(pass_context=True)
  166. async def PLAY(ctx, charName):
  167.     global usrName
  168.     global usrCharN
  169.     global pcChL
  170.     global plyChars
  171.     global npcE
  172.     global charSh
  173.     usrName = str(ctx.message.author)
  174.     if charName is None:
  175.         await bot.say('use $$PLAY <:person_with_blond_hair::skin-tone-5: name> or $$help')
  176.     usrCharN = charName + '.' + usrName
  177.     try:
  178.         pcChL = pickle.load(open(usrCharN, "rb"))
  179.     except FileNotFoundError:
  180.         await bot.say('Not a valid :person_with_blond_hair::skin-tone-5: name')
  181.         return
  182.     await bot.say(':person_with_blond_hair::skin-tone-5: loading...')
  183.     if pcChL['ID'] == usrName:
  184.         await bot.say('ID verified, this is your :person_with_blond_hair::skin-tone-5: \n :person_with_blond_hair::skin-tone-5: loaded')
  185.     else:
  186.         await bot.say('This :person_with_blond_hair::skin-tone-5: was not made by you, make your own')
  187.         return
  188.     pickle.dump(pcChL, open(usrCharN, "wb"))
  189.     plyChars[usrName] = charName
  190. @bot.command(pass_context=True)
  191. async def FGT(ctx):
  192.     global usrName
  193.     global plyChars
  194.     global charSh
  195.     usrName = str(ctx.message.author)
  196.     try:
  197.         if plyChars[usrName] is None:
  198.             await bot.say('you have not loaded a :person_with_blond_hair::skin-tone-5:, use $$PLAY or $$help')
  199.             return
  200.    
  201.  
  202.         else:
  203.             await bot.say('{} is going on an adventure'.format(plyChars[usrName]))
  204.             fileN = plyChars[usrName] + '.' + usrName
  205.             charSh = pickle.load(open(fileN, "rb"))
  206.             if charSh['Hp'] <= 0:
  207.                 await bot.say('The :person_with_blond_hair::skin-tone-5: you have loaded is dead. Not sure they can fight well')
  208.                 pickle.dump(charSh, open(fileN, "wb"))
  209.                 return
  210.             print(int(charSh['Lvl']/3))
  211.             difMod = int(charSh['Lvl']/2)
  212.             if difMod < 1:
  213.                 difMod = 1
  214.             await encountr(difMod)
  215.             fileE = plyChars[usrName] + '.enc'
  216.             npcE = pickle.load(open(fileE, "rb"))
  217.             await bot.say('You are facing a {} it looks {}'.format(npcE['Name'], npcE['DIF']))
  218.             if npcE['DIF'] == 'STRONG':
  219.                 xpMod = 3
  220.             if npcE['DIF'] == 'AVERAGE':
  221.                 xpMod = 2
  222.             if npcE['DIF'] == 'WEAK':
  223.                 xpMod = 1
  224.             print(npcE)
  225.             plrAtk = int(charSh['Atk'] / 2)
  226.             plrDef = int(charSh['Def'] / 2)
  227.             encAtk = int(npcE['ATK'] / 3)
  228.             encDef = int(npcE['DEF'] / 3)
  229.             while npcE['HP'] > 0:
  230.                 await bot.say('{} has {} :sparkling_heart:'.format(npcE['Name'], npcE['HP']))
  231.                 await bot.say('{} has {} :sparkling_heart:'.format(charSh['Name'], charSh['Hp']))
  232.                 if charSh['Hp'] <= 0:
  233.                     await bot.say('{} has died fighting a {}'.format(charSh['Name'], npcE['Name']))
  234.                     pickle.dump(charSh, open(fileN, "wb"))
  235.                     return
  236.                 pAt = (dicer(2, 8) + plrAtk) - encDef
  237.                 npcE['HP'] = npcE['HP'] - pAt
  238.                 await bot.say('{} hit the {} for {} damage. It has {} :sparkling_heart: left'.format(charSh['Name'], npcE['Name'], pAt, npcE['HP']))
  239.                 if npcE['HP'] > 0:
  240.                     eAt = (dicer(2, 8) + encAtk + 2) - plrDef
  241.                     charSh['Hp'] = charSh['Hp'] - eAt
  242.                     await bot.say('The {} hit {} for {} damage. You have {} :sparkling_heart: remaining!'.format(npcE['Name'], charSh['Name'], eAt, charSh['Hp']))
  243.             await bot.say('WINNER! gained {} EXP'.format(str(int(difMod*100*xpMod))))
  244.             charSh['Exp'] = charSh['Exp'] + (int(difMod * 100 * xpMod))
  245.             print(charSh['Exp'])
  246.             if charSh['Exp'] >= 1000 * charSh['Lvl']:
  247.                 await bot.say('Level up available!! Type $$LVL <stat> to level up! $$help LVL for details')
  248.                
  249.            
  250.             if charSh['Hp'] <= 0:
  251.                 await bot.say('{} has died fighting a {}'.format(charSh['Name'], npcE['Name']))
  252.                 pickle.dump(charSh, open(fileN, "wb"))
  253.             pickle.dump(charSh, open(fileN, "wb"))
  254.             pickle.dump(npcE, open(fileE, "wb"))
  255.    
  256.        
  257.     except KeyError:
  258.         await bot.say('you have not loaded a :person_with_blond_hair::skin-tone-5:, use $$PLAY or $$help')
  259.         return
  260.    
  261.                      
  262. @create.command()
  263. async def PC(pcClass: int, pcNamer: str):
  264.     global cmdLock
  265.     global pcChS
  266.     global pcCSt
  267.     global pcCi
  268.     global pcName
  269.     global usrName
  270.     pcCi = pcClass
  271.     pcName = pcNamer
  272.     pcChS = {}
  273.     cmdLock = False
  274.     print(pcName)
  275.     if pcClass == 1:
  276.         pcCSt = '::fist::skin-tone-5:'
  277.         print('good')
  278.         print('creating a character named:', pcName, 'the', pcCSt)
  279.         await bot.say('{} the {}'.format(pcName, pcCSt))
  280.         cmdLock = True
  281.     elif pcClass == 2:
  282.         pcCSt = ':dagger:'
  283.         print('good')
  284.         print('creating a character named:', pcName, 'the', pcCSt)
  285.         await bot.say('Creating :person_with_blond_hair::skin-tone-5: ... \n{} the {}'.format(pcName, pcCSt))
  286.         cmdLock = True
  287.     elif pcClass == 3:
  288.         pcCSt = ':fire:'
  289.         print('good')
  290.         print('creating a character named:', pcName, 'the', pcCSt)
  291.         await bot.say('{} the {}'.format(pcName, pcCSt))
  292.         cmdLock = True
  293.            
  294.  
  295.     else:
  296.         await bot.say('do it better that didnt work')
  297.         return
  298.     print('character accepted generating stats')
  299.     await bot.say('Rolling stats...')
  300.     await statser()
  301.     await bot.say(':sparkling_heart: = {}'.format(pcChS['Hp']))
  302.     await bot.say(':crossed_swords: = {}'.format(pcChS['Atk']))
  303.     await bot.say(':shield: = {}'.format(pcChS['Def']))
  304.     await bot.say(':moneybag: = {}'.format(pcChS['Luk']))
  305.     await bot.say('Rerolls are unavailable at this time!')
  306.     await packer()
  307.  
  308.    
  309. @asyncio.coroutine
  310. async def encountr(lvlMod):
  311.     global plyChars
  312.     global usrName
  313.     global npcDif
  314.     npcSh = {}
  315.     npcSh['HP'] = 5 + dicer(lvlMod, 8)
  316.     npcSh['ATK'] = 10 + dicer(lvlMod, 8)
  317.     npcSh['DEF'] = 6 + dicer(lvlMod, 8)
  318.     mNamer = open('monsterlist.RPG', "r")
  319.     mName = mNamer.readlines()
  320.     maxM = 0
  321.     for line in mName:
  322.         maxM = maxM + 1
  323.     print('number of monsters:', maxM)
  324.     npcSh['Name'] = str(mName[(dicer(1,maxM)-1)]).replace('\n','')
  325.     mNamer.close()
  326.     npcDif = npcSh['HP']+npcSh['ATK']+npcSh['DEF']
  327.     if npcDif >= 38:
  328.         npcSh['DIF'] = 'STRONG'
  329.     elif npcDif >= 28:
  330.         npcSh['DIF'] = 'AVERAGE'
  331.     else:
  332.         npcSh['DIF'] = 'WEAK'
  333.     fileN = plyChars[usrName] + '.enc'
  334.     pickle.dump(npcSh, open(fileN, "wb"))
  335.    
  336. @asyncio.coroutine
  337. async def statser():
  338.     global pcChS
  339.     global pcHp
  340.     global pcAtk
  341.     global pcDef
  342.     global pcLuk
  343.     global pcCi
  344.     global pcCSt
  345.     if pcCi == 1:
  346.         clHp = 5
  347.         clAtk = 2
  348.         clDef = 5
  349.         clLuk = 0
  350.     if pcCi == 2:
  351.         clHp = 3
  352.         clAtk = 6
  353.         clDef = 2
  354.         clLuk = 1
  355.     if pcCi == 3:
  356.         clHp = 2
  357.         clAtk = 2
  358.         clDef = 2
  359.         clLuk = 6
  360.     print('hp+{} atk+{} def+{} luk+{}'.format(clHp,clAtk,clDef,clLuk))
  361.     pcHp = 10 + int(dicer(2,4)+clHp)
  362.     pcAtk = 10 + int(dicer(2,4)+clAtk)
  363.     pcDef = 10 + int(dicer(2,4)+clDef)
  364.     pcLuk = 10 + int(dicer(2,4)+clLuk)
  365.     pcLvl = 1
  366.     pcExp = 0
  367.     pcChS['Hp'] = pcHp
  368.     pcChS['Atk'] = pcAtk
  369.     pcChS['Def'] = pcDef
  370.     pcChS['Luk'] = pcLuk
  371.     pcChS['Lvl'] = pcLvl
  372.     pcChS['Exp'] =  pcExp
  373.     pcChS['Class'] = pcCSt
  374.     print(pcChS)
  375. @asyncio.coroutine
  376. async def packer():
  377.     global pcChS
  378.     global pcName
  379.     global usrName
  380.     usrName = str(usrName)
  381.     pcNamez = pcName + '.' + usrName
  382.     pcChS['Name'] = pcName
  383.     pcChS['ID'] = usrName
  384.     print(pcChS)
  385.     pickle.dump(pcChS, open(pcNamez, "wb"))
  386.      
  387.  
  388. def dicer(diNum,diTy):
  389.     global roResult
  390.     global roTal
  391.     global rAc
  392.     rAc = 0
  393.     roResult = []
  394.     while(diNum > 0):
  395.         rAc = random.randint(1,diTy)
  396.         print(rAc)
  397.         roResult.append(rAc)
  398.         print(roResult)
  399.         diNum = diNum - 1
  400.     roTal = sum(roResult)
  401.     print(roTal)
  402.     return roTal
  403.  
  404. def itemz(difMod):
  405.     global npcE
  406.     global charSh
  407.    
  408.  
  409. bot.run('NDE0MzMzNDM1MzEwNzY4MTM4.DYeQdA.RF_uemJdVhR7eP4dlgTPnNhY5Tk')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement