diff --git a/HuntNFish/README.txt b/HuntNFish/README.txt new file mode 100644 index 0000000..b75c96f --- /dev/null +++ b/HuntNFish/README.txt @@ -0,0 +1,7 @@ +this is a basic hunting and fishing game for supybot + +chance of success is a % variable, 1 to 100. it is set with config plugins.HuntNFish.successRate + +the game can be turned off using config plugins.HuntNFish.enable + +type of weight used is also configurable, with config plugins.HuntNFish.weightType diff --git a/HuntNFish/__init__.py b/HuntNFish/__init__.py new file mode 100644 index 0000000..89f5c4f --- /dev/null +++ b/HuntNFish/__init__.py @@ -0,0 +1,68 @@ +### +# Copyright (c) 2012, resistivecorpse +# 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 +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.Author('resistivecorpse', 'resistivecorpse', + 'resistivecorpse@gmail.com') + +# 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/HuntNFish/download' + +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: + from . import test + +Class = plugin.Class +configure = config.configure + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/HuntNFish/config.py b/HuntNFish/config.py new file mode 100644 index 0000000..1027380 --- /dev/null +++ b/HuntNFish/config.py @@ -0,0 +1,56 @@ +### +# Copyright (c) 2012, resistivecorpse +# 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. + +### + +import supybot.conf as conf +import supybot.registry as registry +from supybot.i18n import PluginInternationalization, internationalizeDocstring + +_ = PluginInternationalization('HuntNFish') + +def configure(advanced): + # This will be called by supybot to configure this module. advanced is + # a bool that specifies whether the user identified himself as an 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('HuntNFish', True) + + +HuntNFish = conf.registerPlugin('HuntNFish') +# This is where your configuration variables (if any) should go. For example: +conf.registerChannelValue(HuntNFish, 'WeightType', + registry.String('lb', _("""Determines what form of weight, metric or imperial, is used by the plugin. options are lb and kg."""))) +conf.registerChannelValue(HuntNFish, 'enable', + registry.Boolean(True, _("""Turns on and off the hunt and fish commands."""))) +conf.registerChannelValue(HuntNFish, 'successRate', + registry.NonNegativeInteger(0, _("""Percent of chance of success"""))) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/HuntNFish/local/__init__.py b/HuntNFish/local/__init__.py new file mode 100644 index 0000000..e86e97b --- /dev/null +++ b/HuntNFish/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/HuntNFish/plugin.py b/HuntNFish/plugin.py new file mode 100644 index 0000000..d900eda --- /dev/null +++ b/HuntNFish/plugin.py @@ -0,0 +1,206 @@ +### +# Copyright (c) 2012, resistivecorpse +# 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. + +### + +import os +import re +import time +import string +import random as random +import supybot.conf as conf +import supybot.utils as utils +from supybot.commands import * +import supybot.plugins as plugins +import supybot.ircutils as ircutils +import supybot.callbacks as callbacks +from supybot.i18n import PluginInternationalization, internationalizeDocstring + +_ = PluginInternationalization('HuntNFish') + +@internationalizeDocstring +class HuntNFish(callbacks.Plugin): + """Adds hunt and fish commands for a basic hunting and fishing game.""" + threaded = True + + def hunt(self,irc,msg,args): + """takes no arguments + performs a random hunt + """ + channel = msg.args[0] + hunttrophy = conf.supybot.directories.data.dirize("hunttrophy_{0}.db".format(channel)) + if not os.path.isfile(hunttrophy): + with open(hunttrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + if(self.registryValue('enable', msg.args[0])): + animals = ['bear', 'gopher', 'rabbit', 'hunter', 'deer', 'fox', 'duck', 'moose', 'pokemon named Pikachu', 'park ranger', 'Yogi Bear', 'Boo Boo Bear', 'dog named Benji', 'cow', 'raccoon', 'koala bear', 'camper', 'channel lamer', 'your mom'] + places = ['in some bushes', 'in a hunting blind', 'in a hole', 'up in a tree', 'in a hiding place', 'out in the open', 'in the middle of a field', 'downtown', 'on a street corner', 'at the local mall'] + + with open(hunttrophy, 'r') as f: + data = f.readlines() + highScore = data[2].rstrip('\n') + huntrandom = random.getstate() + random.seed(time.time()) + currentWhat = random.choice(animals) + currentWhere = random.choice(places) + weightType = self.registryValue('weightType') + weight = (random.randint(int(highScore)/2,int(highScore)+10)) + thisHunt = '%s goes hunting %s for a %s%s %s' % (msg.nick, currentWhere, weight, weightType, currentWhat) + irc.reply(thisHunt) + irc.reply("aims....") + irc.reply("fires.....") + time.sleep(random.randint(4,8))#pauses the output between line 1 and 2 for 4-8 seconds + huntChance = random.randint(1,100) + successRate = self.registryValue('SuccessRate') + random.setstate(huntrandom) + + if huntChance < successRate: + win = 'way to go, %s. You killed the %s%s %s' % (msg.nick, weight, weightType, currentWhat) + irc.reply(win) + with open(hunttrophy, 'r') as f: + data = f.readlines() + bigHunt = data[2].rstrip('\n') + if weight > int(bigHunt): + with open(hunttrophy, 'w') as f: + data[0] = msg.nick + data[1] = currentWhat + data[2] = weight + f.write(str(data[0]) + '\n' + str(data[1]) + '\n' + str(data[2])) + irc.reply("you got a new highscore") + + else: + lose = ' '.join(["oops, you missed", msg.nick]) + irc.reply(lose) + + hunt = wrap(hunt) + + def fish(self,irc,msg,args): + """takes no arguments + performs a random fishing trip + """ + channel = msg.args[0] + fishtrophy = conf.supybot.directories.data.dirize("fishtrophy_{0}.db".format(channel)) + if not os.path.isfile(fishtrophy): + with open(fishtrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + if(self.registryValue('enable', msg.args[0])): + fishes = ('Salmon', 'Herring', 'Yellowfin Tuna', 'Pink Salmon', 'Chub', 'Barbel', 'Perch', 'Northern Pike', 'Brown Trout', 'Arctic Char', 'Roach', 'Brayling', 'Bleak', 'Cat Fish', 'Sun Fish', 'Old Tire', 'Rusty Tin Can', 'Genie Lamp', 'Love Message In A Bottle', 'Old Log', 'Rubber Boot' , 'Dead Body', 'Loch Ness Monster', 'Old Fishing Lure', 'Piece of the Titanic', 'Chunk of Atlantis', 'Squid', 'Whale', 'Dolphin', 'Porpoise' , 'Stingray', 'Submarine', 'Seal', 'Seahorse', 'Jellyfish', 'Starfish', 'Electric Eel', 'Great White Shark', 'Scuba Diver' , 'Lag Monster', 'Virus', 'Soggy Pack of Smokes', 'Bag of Weed', 'Boat Anchor', 'Pair Of Floaties', 'Mermaid', ' Merman', 'Halibut', 'Tiddler', 'Sock', 'Trout') + fishSpots = ('a Stream', 'a Lake', 'a River', 'a Pond', 'an Ocean', 'a Bathtub', 'a Kiddies Swimming Pool', 'a Toilet', 'a Pile of Vomit', 'a Pool of Urine', 'a Kitchen Sink', 'a Bathroom Sink', 'a Mud Puddle', 'a Pail of Water', 'a Bowl of Jell-O', 'a Wash Basin', 'a Rain Barrel', 'an Aquarium', 'a SnowBank', 'a WaterFall', 'a Cup of Coffee', 'a Glass of Milk') + + with open(fishtrophy, 'r') as f: + data = f.readlines() + highScore = data[2].rstrip('\n') + fishrandom = random.getstate() + random.seed(time.time()) + currentWhat = random.choice(fishes) + currentWhere = random.choice(fishSpots) + weight = random.randint(int(highScore)/2,int(highScore)+10) + weightType = self.registryValue('weightType') + thisFishing = '%s goes fishing in %s' % (msg.nick, currentWhere) + irc.reply(thisFishing) + irc.reply("casts in....") + irc.reply('a %s%s %s is biting...' % (str(weight), weightType, currentWhat)) + time.sleep(random.randint(4,8))#pauses the output between line 1 and 2 for 4-8 seconds + huntChance = random.randint(1,100) + successRate = self.registryValue('SuccessRate') + random.setstate(fishrandom) + + if huntChance < successRate: + win = 'way to go, %s. You caught the %s%s %s' % (msg.nick, str(weight), weightType, currentWhat) + irc.reply(win) + with open(fishtrophy, 'r') as f: + data = f.readlines() + bigFish = data[2].rstrip('\n') + if weight > int(bigFish): + with open(fishtrophy, 'w') as f: + data[0] = msg.nick + data[1] = currentWhat + data[2] = weight + f.writelines(str(data[0]) + '\n' + str(data[1]) + '\n' + str(data[2])) + irc.reply("you got a new highscore") + + else: + lose = ' '.join(["oops, it got away", msg.nick]) + irc.reply(lose) + + fish = wrap(fish) + + def trophy(self,irc,msg,args): + """takes no arguments + checks the current highscores for hunting and fishing + """ + channel = msg.args[0] + hunttrophy = conf.supybot.directories.data.dirize("hunttrophy_{0}.db".format(channel)) + fishtrophy = conf.supybot.directories.data.dirize("fishtrophy_{0}.db".format(channel)) + if not os.path.isfile(fishtrophy): + with open(fishtrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + if not os.path.isfile(hunttrophy): + with open(hunttrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + if(self.registryValue('enable', msg.args[0])): + weightType = self.registryValue('weightType') + with open(hunttrophy, 'r') as f: + data = f.readlines() + hunter = data[0].rstrip('\n') + hunted = data[1].rstrip('\n') + size = data[2].rstrip('\n') + irc.reply('hunting highscore held by: %s with a %s%s %s' % (hunter, size, weightType, hunted)) + with open(fishtrophy, 'r') as f: + data = f.readlines() + fisherman = data[0].rstrip('\n') + catch = data[1].rstrip('\n') + size = data[2].rstrip('\n') + irc.reply('fishing highscore held by: %s with a %s%s %s' % (fisherman, size, weightType, catch)) + + trophy = wrap(trophy) + + def resetscores(self,irc,msg,args): + """takes no arguments + resets the highscores for both hunting and fishing. this command is limited to the owner, to prevent just anyone from clearing the scores + """ + hunttrophy = conf.supybot.directories.data.dirize("hunttrophy_{0}.db".format(channel)) + fishtrophy = conf.supybot.directories.data.dirize("fishtrophy_{0}.db".format(channel)) + if not os.path.isfile(fishtrophy): + with open(fishtrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + if not os.path.isfile(hunttrophy): + with open(hunttrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + with open(hunttrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + with open(fishtrophy, 'w') as f: + f.write('Nobody\nnothing\n2') + irc.replySuccess() + + resetscores = wrap(resetscores, ['owner']) + +Class = HuntNFish + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/HuntNFish/test.py b/HuntNFish/test.py new file mode 100644 index 0000000..5ae054b --- /dev/null +++ b/HuntNFish/test.py @@ -0,0 +1,37 @@ +### +# Copyright (c) 2012, resistivecorpse +# 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. + +### + +from supybot.test import * + +class HuntNFishTestCase(PluginTestCase): + plugins = ('HuntNFish',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: