### # Copyright (c) 2007, Divad Ssilb # 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.dbi as dbi import supybot.conf as conf import supybot.utils as utils from supybot.commands import * import supybot.ircmsgs as ircmsgs import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks import random, threading class RaptorsEng(object): """The engine behind the raptors plugin. Channel-specific.""" threaded = True def __init__(self, channel): super(Raptors, self).__init__(irc) self.raptorMode = False self.peopleAttacked = 0 self.damageDone = 0 self.raptorsUponChannel = False self.isHidden = False self.irc = None self.messagesSinceCheck = False self.channel = None def doPrivmsg(self, irc, msg): irc = callbacks.SimpleProxy(irc, msg) if irc.isChannel(msg.args[0]) and self.raptorMode: if not self.raptorsUponChannel: #determine whether the raptors set upon the channel if random.randint(0, 100) <= 30: self.raptorsUponChannel = True irc.reply("The raptors have set upon the channel.") t = threading.Timer(3.0, lambda: self.doRaptorAttackCheck(irc)) else: #Do some fighting if random.randint(0, 100) <= 25: #Attack if random.randint(0,100) <= 60: #attack the person who spoke. self.__Attack(irc, msg.nick, msg.args[0]) else: #attack some random shmoe self.peopleAttacked += 1 irc.reply("The raptors attack someone else") if random.randint(5, 9) < self.peopleAttacked: self.__FinishRaptorsAttack(irc) def doInitialRaptorCheck(self, irc): """Internal function; after a certain amount of time, this function is called. If the raptors haven't set upon the channel, they move on.""" if not self.raptorsUponChannel: self.__FinishRaptorAttack(irc) def doRaptorAttackCheck(self, irc): """Internal function; continues raptor activity in silence""" if random.randint(0,100)<=13: #Attack random nick pass def doNoActivityCheck(self, irc): pass def __StartRaptorAttack(self, irc): """Starts a raptor attack, with the raptors at a distance.""" self.raptorMode = True self.peopleAttacked = 0 self.damageDone = 0 self.raptorsUponChannel = False self.isHidden = False timeDelay = random.randint(15, 45) t = threading.Timer(float(timeDelay), lambda: self.doInitialRaptorCheck(irc)) t.start() def __Attack(self, irc, nick, channel, reason="The raptors got you"): """Attacks the given nick""" if self.raptorMode and self.raptorsUponChannel: irc.queueMsg(ircmsgs.kick(channel, nick, reason)) self.peopleAttacked += 1 if random.randint(5, 9) < self.peopleAttacked: self.__FinishRaptorsAttack def __FinishRaptorAttack(self, irc): self.raptorsMode = False self.raptorsUponChannel = False irc.queueMsg(ircmsgs.privmsg(channel, "The raptors have left...")) def raptors(self, irc, msg, args): """takes no arguments Tells the bot you saw some velociraptors""" self.irc = irc if not self.raptorMode: self.__StartRaptorAttack(irc) irc.reply("sees the raptors as well", action=True) elif not self.raptorsUponChannel and not self.isHidden: irc.reply('whispers "I saw them the first time they were mentioned"', action=True) else: irc.reply('glares at %s for the idiocy' % msg.nick, action=True) raptors = wrap(raptors) def throwrocks(self, irc, msg, args): """takes no arguments throws rocks at the raptors, if any are seen""" self.irc = irc if random.randint(0, 100) <= 25: #Hit if random.randint(0,100) <= 80: self.peopleAttacked += 1 irc.reply("You hit a raptor and took it down.") if random.randint(5, 9) < self.peopleAttacked: self.__FinishRaptorsAttack(irc) else: self.__Attack(irc, msg.nick, msg.args[0], "You hit the raptor, but it attacked back") else: irc.reply("You missed.") throwrocks = wrap(throwrocks) class Raptors(callbacks.Plugin): engines = None def __init__(self, irc): callbacks.Plugin.__init__(self, irc) self.engines = {} def doPrivmsg(self, irc, msg): self.engines[msg.args[0]].doPrivmsg(self, irc, msg) def raptors(self, irc, msg, args): """takes no arguments Tells the bot you saw some velociraptors""" self.engines[msg.args[0]] = RaptorsEng(msg.args[0]) self.engines[msg.args[0]].raptors(irc, msg, args) raptors = wrap(raptors) def throwrocks(self, irc, msg, args): """takes no arguments throws rocks at the raptors, if any are seen""" self.engines[msg.args[0]].throwrocks(irc, msg, args) throwrocks = wrap(throwrocks) def abortraptors(self, irc, msg, args): del self.engines[msg.args[0]] #--- def testfunc(self, irc, msg, args): """takes no arguments provides some debugging feedback""" irc.reply("irc: %s" % str(dir(irc))) irc.reply("msg: %s" % str(dir(msg))) irc.reply("args: %s" % str(dir(args))) irc.reply("sender: %s" % msg.nick) testfunc = wrap(testfunc) Class = Raptors # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: