diff --git a/RPG/__init__.py b/RPG/__init__.py index e274376..e5c086e 100644 --- a/RPG/__init__.py +++ b/RPG/__init__.py @@ -35,29 +35,32 @@ here. This should describe *what* the plugin does. import supybot import supybot.world as world +import importlib # Use this for the version of this plugin. You may wish to put a CVS keyword # in here if you're keeping the plugin in CVS or some similar system. __version__ = "" # XXX Replace this with an appropriate author or supybot.Author instance. -__author__ = supybot.authors.unknown +__author__ = supybot.Author('Anthiny Boot', 'antb', '') +__maintainer__ = getattr(supybot.authors, 'oddluck', + supybot.Author('oddluck', 'oddluck', 'oddluck@riseup.net')) # This is a dictionary mapping supybot.Author instances to lists of # contributions. __contributors__ = {} # This is a url where the most recent plugin package can be downloaded. -__url__ = '' # 'http://supybot.com/Members/yourname/Rpg/download' +__url__ = 'https://github.com/oddluck/limnoria-plugins/' -import config -import plugin -reload(plugin) # In case we're being reloaded. +from . import config +from . import plugin +importlib.reload(plugin) # In case we're being reloaded. # Add more reloads here if you add third-party modules and want them to be # reloaded when this plugin is reloaded. Don't forget to import them as well! if world.testing: - import test + from . import test Class = plugin.Class configure = config.configure diff --git a/RPG/__init__.py.bak b/RPG/__init__.py.bak new file mode 100644 index 0000000..e274376 --- /dev/null +++ b/RPG/__init__.py.bak @@ -0,0 +1,66 @@ +### +# Copyright (c) 2011, Anthony Boot +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +### + +""" +Add a description of the plugin (to be presented to the user inside the wizard) +here. This should describe *what* the plugin does. +""" + +import supybot +import supybot.world as world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "" + +# XXX Replace this with an appropriate author or supybot.Author instance. +__author__ = supybot.authors.unknown + +# This is a dictionary mapping supybot.Author instances to lists of +# contributions. +__contributors__ = {} + +# This is a url where the most recent plugin package can be downloaded. +__url__ = '' # 'http://supybot.com/Members/yourname/Rpg/download' + +import config +import plugin +reload(plugin) # In case we're being reloaded. +# Add more reloads here if you add third-party modules and want them to be +# reloaded when this plugin is reloaded. Don't forget to import them as well! + +if world.testing: + import test + +Class = plugin.Class +configure = config.configure + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/RPG/__pycache__/__init__.cpython-37.pyc b/RPG/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..76c913b Binary files /dev/null and b/RPG/__pycache__/__init__.cpython-37.pyc differ diff --git a/RPG/__pycache__/plugin.cpython-37.pyc b/RPG/__pycache__/plugin.cpython-37.pyc new file mode 100644 index 0000000..109e20e Binary files /dev/null and b/RPG/__pycache__/plugin.cpython-37.pyc differ diff --git a/RPG/config.py b/RPG/config.py index 06116df..80e2d9c 100644 --- a/RPG/config.py +++ b/RPG/config.py @@ -37,10 +37,10 @@ def configure(advanced): # user or not. You should effect your configuration by manipulating the # registry as appropriate. from supybot.questions import expect, anything, something, yn - conf.registerPlugin('Rpg', True) + conf.registerPlugin('RPG', True) -Rpg = conf.registerPlugin('Rpg') +Rpg = conf.registerPlugin('RPG') # This is where your configuration variables (if any) should go. For example: # conf.registerGlobalValue(Rpg, 'someConfigVariableName', # registry.Boolean(False, """Help for someConfigVariableName.""")) diff --git a/RPG/items.txt b/RPG/items.txt index 26cc2b1..22b195d 100644 --- a/RPG/items.txt +++ b/RPG/items.txt @@ -1 +1,2 @@ -{"modifiers": [["AntB", 150, 200, 2], ["Catelite", 75, 150, 5], ["Frankbro", 75, 150, 5], ["Simon", 100, 150, 2], ["cracker64", 64, 64, 15], ["RedFlash", 50, 70, 20], ["Magical", 50, 65, 22], ["QRTZ", 50, 60, 25], ["DMND", 45, 55, 30], ["CLNE", 40, 50, 40], ["INSL", 35, 45, 50], ["Fine", 5, 15, 60], ["Cold-proof", 5, 10, 65], ["Fire-proof", 5, 12, 65], ["Polished", 5, 7, 65], ["Azure", 2, 5, 70], [["Crude", 1, 3, 80]], [["Damaged", 1, 2, 90]], ["", 0, 0, 100], ["Doxin", 60, 80, 7]], "swords": [["Sharpened Wooden", 1, 5, 90], ["Short Sword", 1, 10, 80], ["Gladius", 4, 13, 70], ["Dagger", 7, 13, 60], ["", 6, 15, 50], ["Cutlass", 5, 15, 40], ["Katana", 8, 15, 30], ["Bastard", 10, 17, 20], ["Weighted", 15, 20, 10], ["Whip", 17, 30, 5]], "defence": [["Tin", 1, 5, 90], ["Aluminium", 3, 8, 80], ["Iron", 6, 11, 70], ["Bronze", 9, 14, 60], ["Steel", 12, 17, 50], ["Reinforced", 15, 40], ["Hoylian", 18, 23, 30], ["Mirrored", 21, 26, 20], ["Reforged Steel", 24, 29, 10], ["Tower", 27, 32, 5]]} +{"modifiers": [["Legendary", 150, 200, 2], ["Sensational", 75, 150, 5], ["Rare", 75, 150, 5], ["Lucky", 100, 150, 2], ["Diamond", 64, 64, 15], ["Magical", 50, 70, 20], ["Strengthened", 50, 65, 22], ["Quartz", 50, 60, 25], ["Diamond", 45, 55, 30], ["Enchanted", 40, 50, 40], ["Improved", 35, 45, 50], ["Fine", 5, 15, 60], ["Cold-proof", 5, 10, 65], ["Fire-proof", 5, 12, 65], ["Polished", 5, 7, 65], ["Makeshift", 2, 5, 70], [["Crude", 1, 3, 80]], [["Damaged", 1, 2, 90]], ["", 0, 0, 100]], "swords": [["Wooden Sword", 1, 5, 90], ["Short Sword", 1, 10, 80], ["Longsword", 4, 13, 70], ["Dagger", 7, 13, 60], ["Broadsword", 6, 15, 50], ["Cutlass", 5, 15, 40], ["Katana", 8, 15, 30], ["Bastard", 10, 17, 20], ["Weighted", 15, 20, 10], ["Samurai", 17, 30, 5]], "defence": [["Tin", 1, 5, 90], ["Aluminium", 3, 8, 80], ["Iron", 6, 11, 70], ["Bronze", 9, 14, 60], ["Iron", 12, 17, 50], ["Steel", 15, 40], ["Reinforced", 18, 23, 30], ["Mirrored", 21, 26, 20], ["Titanium", 24, 29, 10], ["Meteorite", 27, 32, 5]]} + diff --git a/RPG/map.txt b/RPG/map.txt index e7cc284..6d220b9 100644 --- a/RPG/map.txt +++ b/RPG/map.txt @@ -1,51 +1,53 @@ -################################################### -#.........#...##..#............#..................# -#.......~............~.......~...............#....# -#...................#..........#....#....##......## -#....#.#................#...........~....#.......## -#.............#....#.#.......#.......#..........~.# -#...........#.............#..~....................# -#...#...:.~......#.#.............#.....#.....#...## -#................#..#........:.#...:..#...~.:...#.# -#....................#.........................#.## -#............#..#........##.........:#..........#.# -#...#....#.......#.............#..................# -#............#.....................#........#.....# -#.~#.................~....~......:..........:.....# -#..........:..:.::.............#..............#...# -##.........:...#....#..#.#....#..#.....#..........# -#.#........................:....#....~....~.#~#...# -##..#.....................................#...#...# -###.......#...:.....~..............#.#.#..........# -#....:...#................:........:.........#....# -#..#.~.......#................#.........#..:......# -#...:.............~#.......##.........:..........## -#...~...#..#.##.#....#.............#......#.......# -#........:.#..##.....:..#.............:.....#.....# -#..#..#...:......#........:#.~....................# -#~.......#.....#~#.......@...:...........~........# -#...................#...:.....:.....#.....#.#..#..# -#...#.............#......#......................#.# -#.....#~......##.........................#........# -#....#....#.....................~:...#..~....#..#.# -#..#......#............#........#..#.~...........~# -#.........:......#.............~....#.............# -##~...:.........:#...#..#....:...............#....# -#...#..:.#..:.......~#................#~.........## -#...:...#..#....#..#..............:#..#...........# -#.....................~.:......#...~#....#........# -#.#.....~............#.................~..:.......# -##..........................:.......#.....#.......# -#............##.....#..#......#.........#........:# -#..#:..~....#.........#...~..#.#........#...~.....# -#.........:........#......:......:.........#...#.~# -#...............:......:...........~.....#..#.....# -#...~...#....................................#...:# -#..#:.................#...........................# -#....#...#................#.#.:........#.....#....# -#...~.......~......#........~....#~...............# -#.~....~.................:.........#...........#..# -#.........##.......#.............................## -###..#:................##....#.....#...#..........# -#.........#............~#..#......##:....:........# -################################################### +##################################################### +#......:...................~......#.....#...##......# +#.#......#....#..........~..............#~.......#..# +#...........#...........#.........................:.# +#.....##.....#........#..##.#..#..................### +#..#...#...#..........#.........#....~.~..#.........# +#...:.##....#....#...#..~.........:....#.#..........# +#...#.....#..#.....#........:.....#...............#.# +#.................#..........#....................#.# +#....................#....#.............#...........# +#..#...#...:.......................:.#....##........# +#........#...#..#:..........#...................#...# +#............................#.....:##:...#.#......## +#:..~...........................:......#....#......## +#....:...#...........#.:.....~.#....................# +#.....#....:..#....:......#.....#:......#.....#.....# +#....................##......##.#.....~..#..#.#...#.# +#.....#..........~.........##....#...##..........##.# +#.#......#...........#..........##..................# +#..............#........#...........#...............# +#.....###....#...~......#......:..##.#..............# +#..#.....:.............#...#.............#....:.....# +#..............#.:..#..#..~:....:.............:.#...# +#...................#.......................#.......# +#..........#.............................#..........# +#.............#...................#..#..:~.......:..# +#......:..#....#..##......@#...............#........# +#.#...##...#............##......#....#....#.........# +#.##...#.............~.##.~......#.#.........#......# +#........#............#......#........~..#.....##.#.# +#.#.#..........#........~.................:...#.:.#.# +#...........#.................................#.....# +#......#..:..................#.............~~.......# +#.................~......:.....#..#.....:...........# +#.....#...#........#......:.#.............:......:..# +#.......:#.........#..........:.~...#..~.#...#....#.# +#................................##..............#..# +#............#.....~..........#.......#...........#.# +#~#.........#..#...#.........##...........#....:.#..# +#...................:......##..........#............# +#...............#.....#............#........~.#:....# +#.........#...#.........#...:..#..#.....#.#......#..# +#.....##....#...............#..#..........~..##.....# +#..............#.........#..................#....##.# +#..................:#.#........................#....# +#..........#.........................#........###:..# +#..........#..:........##......#...........#.......## +#.......::.....................##~#.....~...........# +#:.......:.....##...........#......~...........#....# +#............~.:...#.#:.....................#.....#.# +##..#...#...#.......................................# +#........#..#...##.#...............:.......#........# +##################################################### diff --git a/RPG/mapData.txt b/RPG/mapData.txt index 8171889..5fc14e8 100644 --- a/RPG/mapData.txt +++ b/RPG/mapData.txt @@ -1 +1 @@ -{"homeX": 25, "homeY": 25, "height": 50, "width": 50, "homeLoc": 1325, "desc": "Random Generation."} \ No newline at end of file +{"width": 52, "height": 52, "homeY": 26.0, "homeX": 26, "homeLoc": 1430, "desc": "Random Generation."} \ No newline at end of file diff --git a/RPG/monsters.txt b/RPG/monsters.txt index e6ffac9..131cc07 100644 --- a/RPG/monsters.txt +++ b/RPG/monsters.txt @@ -1 +1 @@ -{"monsters": ["Photons", "Trolls", "Moderators", "Basement Cat", "Internet Explorers", "Fired Fox", "Cereal Guys", "Opera Singers", "Justin Beiber Impersonators", "Twilight Fans", "Harry Potter Fans", "The Invisible Man", "Swimming Trunks", "Guko", "Paranoid Parrots", "Stickmen", "8-Bit Shades", "Insanity Wolf", "Emo kids", "Psychosociables", "Guitar Heroes", "Balloon Bombers", "Mad Motorist", "Crazy Hobo", "Radioactive Aardvarks", "Rouge Banhammers"], "boss": {"pen": [{"luc": [50, 100]}, {"atk": [100, 10]}, {"def": [50, 5]}, {"atk": [5, 100]}], "names": ["Mortvert", "cctvdude99", "Nibble", "Stewie", "HK6", "Frankomisko"]}} \ No newline at end of file +{"monsters": ["Ruthless Doom Panther", "Primeval Frost Gorilla", "Elusive Corpse Leopard", "Blight Hog", "Electric Nether Wolf", "Savage Spite Owl", "Rabid Grief Frog", "Putrid Bulge Hound", "Howling Murder Yak", "Raging Ghost Spider"], "boss": {"pen": [{"luc": [50, 100]}, {"atk": [100, 10]}, {"def": [50, 5]}, {"atk": [5, 100]}], "names": ["Vexspawn", "Dreadtooth", "Thunderscream", "Doomfoot", "Germclaw", "Cinderface"]}} diff --git a/RPG/players.txt b/RPG/players.txt index bbac181..ac6605e 100644 --- a/RPG/players.txt +++ b/RPG/players.txt @@ -1 +1 @@ -{"AntB": {"Loc": 1277, "force": false, "Deaths": 0, "HP": 1500, "Atk": 144, "Item": {"rArm": {"Name": "AntB's BanBlade", "Power": 200}, "Head": {"Name": "AntB's Customised", "Power": 0}, "Torso": {"Name": "AntB's Anti-Troll", "Power": 200}, "lArm": {"Name": "AntB's Magnet", "Power": 90}}, "Luc": 91, "MHP": 1512, "Exp": 8231, "Lvl": 107, "Spd": 116, "Def": 231}, "desred3": {"Loc": 912, "force": false, "Deaths": 4, "HP": 30, "Atk": 4, "Item": {"rArm": {"Name": "Wooden", "Power": 1}, "Head": {"Name": "Cloth", "Power": 1}, "Torso": {"Name": "Cloth", "Power": 1}, "lArm": {"Name": "Wooden", "Power": 1}}, "Luc": 1, "MHP": 30, "Exp": 1, "Lvl": 1, "Spd": 4, "Def": 5}, "InsanityPrawnBoy": {"Loc": 1325, "force": false, "Deaths": 1, "HP": 22, "Atk": 4, "Item": {"Torso": {"Name": "Cloth", "Power": 2}, "Head": {"Name": "Cloth", "Power": 2}, "rArm": {"Name": "Wooden", "Power": 2}, "lArm": {"Name": "Wooden", "Power": 2}}, "Luc": 1, "Def": 4, "Exp": 0, "Lvl": 1, "Spd": 2, "MHP": 22}, "supertanno": {"Loc": 1167, "force": false, "Deaths": 0, "HP": 25, "Atk": 5, "Item": {"Torso": {"Name": "Cloth", "Power": 1}, "Head": {"Name": "Cloth", "Power": 2}, "rArm": {"Name": "Wooden", "Power": 1}, "lArm": {"Name": "Wooden", "Power": 2}}, "Luc": 1, "Def": 4, "Exp": 0, "Lvl": 1, "Spd": 2, "MHP": 25}} \ No newline at end of file +{"AntB": {"Loc": 1430.0, "force": false, "Deaths": 0, "HP": 1500, "Atk": 144, "Item": {"rArm": {"Name": "AntB's BanBlade", "Power": 200}, "Head": {"Name": "AntB's Customised", "Power": 0}, "Torso": {"Name": "AntB's Anti-Troll", "Power": 200}, "lArm": {"Name": "AntB's Magnet", "Power": 90}}, "Luc": 91, "MHP": 1512, "Exp": 8231, "Lvl": 107, "Spd": 116, "Def": 231}, "desred3": {"Loc": 1430.0, "force": false, "Deaths": 4, "HP": 30, "Atk": 4, "Item": {"rArm": {"Name": "Wooden", "Power": 1}, "Head": {"Name": "Cloth", "Power": 1}, "Torso": {"Name": "Cloth", "Power": 1}, "lArm": {"Name": "Wooden", "Power": 1}}, "Luc": 1, "MHP": 30, "Exp": 1, "Lvl": 1, "Spd": 4, "Def": 5}, "InsanityPrawnBoy": {"Loc": 1430.0, "force": false, "Deaths": 1, "HP": 22, "Atk": 4, "Item": {"Torso": {"Name": "Cloth", "Power": 2}, "Head": {"Name": "Cloth", "Power": 2}, "rArm": {"Name": "Wooden", "Power": 2}, "lArm": {"Name": "Wooden", "Power": 2}}, "Luc": 1, "Def": 4, "Exp": 0, "Lvl": 1, "Spd": 2, "MHP": 22}, "supertanno": {"Loc": 1430.0, "force": false, "Deaths": 0, "HP": 25, "Atk": 5, "Item": {"Torso": {"Name": "Cloth", "Power": 1}, "Head": {"Name": "Cloth", "Power": 2}, "rArm": {"Name": "Wooden", "Power": 1}, "lArm": {"Name": "Wooden", "Power": 2}}, "Luc": 1, "Def": 4, "Exp": 0, "Lvl": 1, "Spd": 2, "MHP": 25}, "oddluck": {"Lvl": 1, "Exp": 0, "MHP": 19, "HP": 19, "Atk": 1, "Def": 2, "Spd": 1, "Luc": 1, "Item": {"Head": {"Name": "Cloth", "Power": 0}, "Torso": {"Name": "Cloth", "Power": 0}, "lArm": {"Name": "Wooden", "Power": 0}, "rArm": {"Name": "Wooden", "Power": 0}}, "Deaths": 0, "Loc": 1430, "force": false}} \ No newline at end of file diff --git a/RPG/plugin.py b/RPG/plugin.py index dae2423..194b901 100644 --- a/RPG/plugin.py +++ b/RPG/plugin.py @@ -33,7 +33,7 @@ from supybot.commands import * import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks - +import os import supybot.ircmsgs as ircmsgs import supybot.ircdb as ircdb import random @@ -42,23 +42,20 @@ try: except: import json as simplejson -class Rpg(callbacks.Plugin): - '''A text based RPG for IRC channels. Requires the user to be registered - with supybot to use it. all commands are prefixed with rpg. Command list: - rpgmove rpgstats rpgrun rpgnew rpgloc rpgviewarea''' - threaded = True - - class rpg(callbacks.Commands): - - gameChannel='##TPTRPG' +class RPG(callbacks.Plugin): + '''A text based RPG for IRC channels. Requires the user to be registered + with supybot to use it. all commands are prefixed with rpg. Command list: + rpgmove rpgstats rpgrun rpgnew rpgloc rpgviewarea''' + threaded = True playerData=mapData=mapInfo=monsterData=itemData={} - consolechannel = '##sgoutput' - filepath = '/home/antb/StewieGriffin/plugins/Rpg/' + consolechannel = None + filepath = "{0}/".format(os.path.dirname(os.path.abspath(__file__))) ######################### ### Game Commands ### ######################### - def rpgReloadData(self,irc,msg,args): + def reloaddata(self,irc,msg,args): + """Reload RPG data. """ if not ircdb.users.getUser(msg.prefix)._checkCapability('admin'): irc.error('Only people with \'Admin\' can do that.') return @@ -70,9 +67,10 @@ class Rpg(callbacks.Plugin): self.monsterData = simplejson.load(f) self._getItemsFile() irc.replySuccess() - reloaddata = wrap(rpgReloadData) + reloaddata = wrap(reloaddata) - def rpgGenMap(self,irc,msg,args,width,height): + def genmap(self,irc,msg,args,width,height): + """Generate map.""" if not ircdb.users.getUser(msg.prefix)._checkCapability('owner'): irc.error('Only people with \'Admin\' can do that.') return @@ -86,7 +84,6 @@ class Rpg(callbacks.Plugin): except: irc.error('Invalid arguments given.') return - random.seed() seed=random.random() random.seed(seed) @@ -95,9 +92,7 @@ class Rpg(callbacks.Plugin): # # is wall : is boss ~ is item . is nothing. rand = {} terrainmap = '' - self._sendDbg(irc,'Generating new usermap..') - x = -1 while x < width: terrainline='' @@ -124,31 +119,24 @@ class Rpg(callbacks.Plugin): else: terrainline+=terrain[rand[4]] terrainmap+=terrainline+'\n' - data = {'width':width,'height':height,'homeY':(height/2),'homeX':int(width/2),'homeLoc':int((height/2)+((width/2)*(width+2))),'desc':'Random Generation.'} - with open(self.filepath+'mapData.txt','w') as f: simplejson.dump(data,f) self._saveMapData(terrainmap) irc.replySuccess('Map regeneration') self._sendDbg(irc,'Map created and saved to map.txt, info saved to mapData.txt') - playerData=self.playerData for player in playerData: playerData[player]['Loc']=(height/2)+((width/2)*(width+2)) self._savePlayerData(playerData) self._sendDbg(irc,'Players relocated successfully.') irc.replySuccess('Players Relocated to Home') + genmap = wrap(genmap,[optional('somethingWithoutSpaces'),optional('somethingWithoutSpaces')]) -# if (self.serverUrl) - # submit = utils.web.getUrl(self.serverUrl+"?m=%s&w=%i&h=%&hm=%i&hy=%i - - genmap = wrap(rpgGenMap,[optional('somethingWithoutSpaces'),optional('somethingWithoutSpaces')]) - - def rpgStats(self,irc,msg,args): + def stats(self,irc,msg,args): + """Get player stats.""" player = self._checkPlayer(irc,msg) playerData = self.playerData[player] - level = playerData['Lvl'] exp = playerData['Exp'] next = self._getNextLevelXp(player) @@ -161,23 +149,21 @@ class Rpg(callbacks.Plugin): deaths = playerData['Deaths'] hp = playerData['HP'] mhp = playerData['MHP'] - weapon = playerData['Item']['rArm']['Name'] helmet = playerData['Item']['Head']['Name'] shield = playerData['Item']['lArm']['Name'] armour = playerData['Item']['Torso']['Name'] - irc.reply('%s is at Level %i with %i experience; %i is \ needed for the next level. You have %i/%i HP. \ Your base attack is %i and is boosted to %i by your %s Sword. Your base \ defence is %i, boosted to %i with your %s Helmet and %s Armour. Your %s \ Shield gives you a %i%s chance to block attacks. Your Luck \ rating is %i. You have died %i times.\ -'%(player,level,exp,next,hp,mhp,baseAtk,totalAtk,weapon,baseDef,totalDef,helmet,armour,shield,block,'%',luck,deaths) - ) - stats = wrap(rpgStats) +'%(player,level,exp,next,hp,mhp,baseAtk,totalAtk,weapon,baseDef,totalDef,helmet,armour,shield,block,'%',luck,deaths) ) + stats = wrap(stats) - def rpgNew(self,irc,msg,args): + def newplayer(self,irc,msg,args): + """Create new RPG player.""" player = self._checkPlayer(irc,msg,1) playerData = self.playerData @@ -198,17 +184,16 @@ rating is %i. You have died %i times.\ playerData[player]['Deaths'] = 0 playerData[player]['Loc']=self.mapInfo['homeLoc'] playerData[player]['force']=False - self._sendDbg(irc,player+' has been reset/created') self._savePlayerData(playerData) - self.rpgStats(irc,msg,args) - new = wrap(rpgNew) + self.stats(irc,msg,args) + newplayer = wrap(newplayer) - def rpgLocation(self,irc,msg,args): + def location(self,irc,msg,args): + """Get player location""" player = self._checkPlayer(irc,msg) location = self.playerData[player]['Loc'] mapInfo = self.mapInfo - x=0 while True: if location > mapInfo['width']: @@ -218,14 +203,14 @@ rating is %i. You have died %i times.\ break y = location irc.reply('You are located at (%i,%i). Home is at (%i,%i)'%(x,y,self.mapInfo['homeX'],self.mapInfo['homeY'])) - loc = wrap(rpgLocation) + location = wrap(location) - def rpgViewArea(self,irc,msg,args): + def look(self,irc,msg,args): + """Look aroun.""" player = self._checkPlayer(irc,msg) location = self.playerData[player]['Loc'] mapData = self.mapData mapInfo = self.mapInfo - area = [] area += mapData[location-(mapInfo['width']+3)] area += mapData[location-(mapInfo['width']+2)] @@ -235,7 +220,6 @@ rating is %i. You have died %i times.\ area += mapData[location+(mapInfo['width']+1)] area += mapData[location+(mapInfo['width']+2)] area += mapData[location+(mapInfo['width']+3)] - for x in area: line = area.index(x) if x is '.': @@ -248,13 +232,13 @@ rating is %i. You have died %i times.\ area[line]='Boss' elif x is '@': area[line]='Home' - irc.reply('NW: %s - N: %s - NE: %s - W: %s - E: %s - SW: %s - S: %s - SE: %s\ '%(area[0],area[1],area[2],area[3],area[4],area[5],area[6],area[7]) ) - viewarea=wrap(rpgViewArea) + look=wrap(look) - def rpgforcebattle(self,irc,msg,args): + def forcebattle(self,irc,msg,args): + """Force battle nex turn.""" player=self._checkPlayer(irc,msg) if self.playerData[player]['force']: self.playerData[player]['force']=False @@ -262,19 +246,20 @@ rating is %i. You have died %i times.\ else: self.playerData[player]['force']=True irc.reply('%s will enter a monster battle on their next turn.'%player.capitalize(),prefixNick=False) - forcebattle=wrap(rpgforcebattle) + forcebattle=wrap(forcebattle) - def rpgmove(self,irc,msg,args,direction,number): + def move(self,irc,msg,args,direction,number): + """[direction] [number] + Move [direction] [number]. + """ player = self._checkPlayer(irc,msg) playerData = self.playerData mapData = self.mapData mapInfo = self.mapInfo direction = direction.upper() - try: number = int(number) except: number = 1 if number == 0: number=1 - x = 0 while x < number: if direction == 'NW': @@ -335,15 +320,12 @@ rating is %i. You have died %i times.\ self._savePlayerData(playerData) else: irc.error("Move failed. you gave %s as a direction. %s"%(direction,str(type(direction)))) - if mapData[playerData[player]['Loc']] is '~': self._genItem(player,2) # mapData[playerData[player]['Loc']]='.' self._saveMapData() - elif mapData[playerData[player]['Loc']] is ':': self._doBattle(irc,player,2,msg.nick) - elif mapData[playerData[player]['Loc']] is '.': if playerData[player]['force'] is True: self._sendDbg(irc,"Battle Forced") @@ -352,35 +334,23 @@ rating is %i. You have died %i times.\ self._savePlayerData(playerData) elif int(random.random()*100) < 5: self._doBattle(irc,player,1,msg.nick) - elif mapData[playerData[player]['Loc']] is '@': playerData[player]['HP']=playerData[player]['MHP'] # irc.reply("Your health has been restored.") irc.queueMsg(ircmsgs.IrcMsg('NOTICE {0} :Your health has been restored.'.format(msg.nick))) self._savePlayerData(playerData) x+=1 - - move = wrap(rpgmove,['somethingWithoutSpaces',optional('int')]) - + move = wrap(move,['somethingWithoutSpaces',optional('int')]) ############################ ### Engine functions ### ############################ def _checkPlayer(self,irc,msg,new=0): - if (msg.args[0] != self.gameChannel): - if msg.nick in irc.state.channels[self.gameChannel].users: - irc.error('That command cannot be sent in this channel. Please try again in %s'%self.gameChannel) - else: - irc.error('You need to join %s and use that command there.'%self.gameChannel) - irc.queueMsg(ircmsgs.invite(msg.nick, self.gameChannel)) - return None - try: player = str(ircdb.users.getUser(msg.prefix)) player = player.split('name=\"')[1].split('\",')[0] except KeyError: irc.errorNotRegistered() - try: test=self.playerData[player] except: @@ -410,7 +380,7 @@ rating is %i. You have died %i times.\ def _getMapInfo(self): with open(self.filepath+'mapData.txt','r') as f: self.mapInfo = simplejson.load(f) - + def _getItemsFile(self): with open(self.filepath+'items.txt','r') as f: self.itemData = simplejson.load(f) @@ -459,7 +429,6 @@ rating is %i. You have died %i times.\ monster['HP']-=playerAtk if monster['HP'] <=0: return player - winner = None while winner is None: battleData['rounds']+=1 @@ -471,20 +440,15 @@ rating is %i. You have died %i times.\ winner = _doPlayer() if winner is None: winner = _doMonster() - if winner is player: self._playerWin(irc,player,monster,playerData) else: self._playerDead(irc,player,monster,playerData) - - - bDataString='Battle lasted %i rounds, you scored %i hits, %i were critical and %i were evaded attacks. %s made %i attacks, %i were critical and %i were blocked.\ '%(battleData['rounds'],battleData['player']['atks'],battleData['player']['crits'],battleData['monster']['evades'],monster['Name'],battleData['monster']['atks'],battleData['monster']['crits'],battleData['player']['blocks']) irc.queueMsg(ircmsgs.IrcMsg('NOTICE {0} :{1}'.format(nick,bDataString))) # irc.reply(bDataString,prefixNick=False) - def _playerDead(self,irc,player,monster,playerData): #irc.reply('OOOOOOH YOU JUST GOT PWNT! - You\'ve been sent back home and fully healed. Luckily theres no penalties for dying.') irc.queueMsg(ircmsgs.IrcMsg('NOTICE {0}: OOOOOOH YOU JUST GOT PWNT! - You\'ve been sent back home and fully healed. Luckily theres no penalties for dying.'.format(msg.nick))) @@ -529,7 +493,6 @@ rating is %i. You have died %i times.\ playerData[player]['Torso']['Power']=itemWon['power'] playerData[player]['Torso']['Name']=itemWon['name'] better = True - if better: winString+=' its better than your old %s %s, so you discard it and equip the %s %s\ '%(oldEquip['Name'],itemWon['item'].capitalize(),itemWon['name'],itemWon['item'].capitalize()) @@ -539,17 +502,14 @@ rating is %i. You have died %i times.\ self._savePlayerData(playerData) irc.reply(winString,prefixNick=False) - def _genItem(self,player,level=1): playerData = self.playerData itemData = self.itemData genChance=(100-playerData[player]['Luc'])/(level+1) itemType=int(random.random()*3) itemToReturn = possibleItem = {} - if itemType is 0: #Sword possibleItem['item']='sword' - itemBase = False while itemBase is False: possibleItem=itemData['swords'][int(random.random()*len(itemData['swords']))] @@ -564,7 +524,6 @@ rating is %i. You have died %i times.\ possibleItem['item']='helmet' elif itemType is 3: #Torso possibleItem['item']='armour' - itemBase = False while itemBase is False: possibleItem=itemData['defence'][int(random.random()*len(itemData['defence']))] @@ -572,16 +531,14 @@ rating is %i. You have died %i times.\ itemBase=possibleItem itemToReturn['name']=possibleItem[0] itemToReturn['power']=int((random.random()*(possibleItem[2]-possibleItem[1]))+possibleItem[1]) - itemBoost = False while itemBoost is False: booster = itemData['modifiers'][random.randint(0,len(itemData['modifiers'])-1)] - print booster + print(booster) if genChance < booster: itemBoost = booster; itemToReturn['name']='%s %s'%(booster[0],itemToReturn['name']) itemToReturn['power']=itemToReturn['power']*(random.random()*(booster[2]-booster[1]))+booster[1] - return itemToReturn def _genMonster(self,player): @@ -629,6 +586,7 @@ rating is %i. You have died %i times.\ pLvl = self.playerData[player]['Lvl'] return (levelBaseXp*pLvl)+((levelBaseXp*pLvl)/2) -Class = Rpg +Class = RPG # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: + diff --git a/RPG/test.py b/RPG/test.py index c03de23..0d50942 100644 --- a/RPG/test.py +++ b/RPG/test.py @@ -31,7 +31,7 @@ from supybot.test import * class RpgTestCase(PluginTestCase): - plugins = ('Rpg',) + plugins = ('RPG',) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: