from game.gamesrc.parents.base.basicobject import BasicObject #you have to import the event definition(s) from somewhere covered by @reload, # - this is as good a place as any. import game.gamesrc.events.rhns.mobThink from game.gamesrc.parents.rhns.shellgame.Combatant import PrimitiveCombatant from game.gamesrc.parents.rhns.shellgame.abilities import Melee #from game.gamesrc.parents.rhns.shellgame import ent #from game.gamesrc.parents.rhns.shellgame.ent import Ent #ent.OBJECT_PARENT = BasicObject #from Test import Combatant from src.events import IntervalEvent from src.scheduler import add_event # #commands on the button object # def descStat(command, stat, level=0, seen_stats = []): spacer = "---" * level command.source_object.emit_to("%s %s %s" % (spacer, stat.__class__, stat.value)) for nstat in stat._updated_by: descStat(command, nstat, level + 1, seen_stats) def cmd_mobstats(command): command.source_object.emit_to("-----------------------------") command.source_object.emit_to(command.source_object.name) command.source_object.emit_to("-----------------------------") seen_stats = [] for pseudoID in command.source_object.scriptlink.stats: descStat(command, command.source_object.scriptlink.stats[pseudoID]) command.source_object.emit_to("-----------------------------") def cmd_push_button(command): """ This is a simple command that handles a user pressing the button by returning a message. """ retval = "There is a loud bang: BOOOM!" command.source_object.emit_to(retval) def cmd_pull_button(command): """ An example of a second defined command (for those who don't know how a button works ... ;) ) """ retval = "A button is meant to be pushed, not pulled!" command.source_object.emit_to(retval) class EventMobThink(IntervalEvent): def __init__(self, obj): super(EventMobThink, self).__init__() self.name = 'event_mob_think' #how often to blink, in seconds self.interval = 1 #the description is seen when you run @ps in-game. self.description = "mob thinking" self.obj = obj def event_function(self): self.obj.scriptlink.think() # #The object itself # class Mob(BasicObject, PrimitiveCombatant): def __init__(self, scripted_obj, *args, **kwargs): """ This is called when class_factory() instantiates a temporary instance of the script parent. This is typically not something you want to mess with much. """ # Calling the super class' __init__ is critical! Never forget to do # this or everything else from here on out will fail. super(Mob, self).__init__(scripted_obj, args, kwargs) # Add the commands to the object's command table (this is about #the only thing you should use the __init__ for). self.command_table.add_command("pushbutton", cmd_push_button) self.command_table.add_command("pullbutton", cmd_pull_button) self.command_table.add_command("mobstats", cmd_mobstats) def at_object_creation(self): self._setup() obj = self.scripted_obj obj.set_attribute('desc', "This is your standard big red button.") obj.set_attribute("breakpoint", 11) obj.set_attribute("count", 0) for ability in [Melee]: self.abilities.append(ability(self)) def think(self): """ called by mobThink every half second """ self.scripted_obj.get_location().emit_to_contents("WHEE\r") for x in self.abilities: try: print self.scripted_obj.get_location() self.scripted_obj.get_location().emit_to_contents("DOH\r") except: print "hrmm no2" #obj = self.scripted_obj #if obj.get_location(): # obj.get_location().emit_to_contents("WHEE %s\r" % ("F")) #for thing in obj.get_location().get_contents(): # if hasattr(thing.scriptlink, "die"): # for ability in self.abilities: # obj.get_location().emit_to_contents(str(ability) + "\r") ##obj.get_location().emit_to_contents(str(dir(obj.get_location().get_contents()))) #for player in obj.get_location() def class_factory(source_obj): """ This method is called by any script you retrieve (via the scripthandler). It creates an instance of the class and returns it transparently. source_obj: (Object) A reference to the object being scripted (the child). """ add_event(EventMobThink(source_obj)) return Mob(source_obj)