Esempio n. 1
0
 def at_script_creation(self):
     # Called when script is first created
     random_key = "combat_handler_%i" % random.randint(1, 1000)
     while search_script(random_key):
         random_key = "combat_handler_%i" % random.randint(1, 1000)
     self.key = random_key
     self.desc = "handles combat"
     self.interval = COMBAT_ROUND_TIMEOUT
     self.start_delay = True
     self.persistent = True
     self.db.origin_location = None
     self.db.rooms = []
     self.db.exits = []
     # store all combatants - {dbref1:character}
     self.db.characters = {}
     # store all combat pairs - {attacker1:victim1, attacker2:victim2}
     self.db.pairs = {}
     # store all moves for each turn
     # character.id:{move:char_move, previous_move:prev_move}
     self.db.turn_actions = {}
     # stores all combos for each character - character.id:combo
     self.db.turn_combos = {}
     # stores any flee attempts for each character - character.id:count
     self.db.flee_count = {}
     # shifting targets - character.id:desired new target
     self.db.shifting = {}
     # rescuing targets - character.id:desired rescuee
     self.db.rescuing = {}
     # characters that are requesting a stop - character:target
     self.db.stop_requests = {}
     # add status effects for the turn -
     # character.id: {effect1:eff1_duration, effect2:eff2_duration}
     self.db.turn_effects = {}
Esempio n. 2
0
 def func(self):
     if self.args:
         self.msg("{R[Invalid '{r%s{R' command.  See '{rhelp %s{R' for usage]" % (self.cmdstring, self.key))
         return
     game_time = search_script('game_time')
     if not game_time:
         self.msg('{RThe game time system is not configured on this server.')
         return
     game_time = game_time[0]
     # Get the current time details
     game_time_now = game_time.localtime()
     type_daytime = game_time.type_daytime()
     type_season = game_time.type_season()
     type_moon = game_time.type_moon()
     # Output the time information
     self.msg('{n/================---------------------')
     self.msg('{n| It is %s, in %s.' % (self.daytime_names[type_daytime], self.season_names[type_season]))
     if type_daytime != 'day':
         self.msg('{n| It\'s a %s moon tonight.' % (self.moon_names[type_moon]))
     self.msg('{n|')
     self.msg('{n| {bCurrent date:{n Day %d, of year %d' % (game_time_now.tm_yday, game_time_now.tm_year))
     self.msg('{n| {bCurrent time:{n %02d:%02d:%02d' % (game_time_now.tm_hour, game_time_now.tm_min, game_time_now.tm_sec))
     self.msg('{n|')
     self.msg('{n| {bGame Time:{n')
     self.msg('{n|   %d seconds per minute.' % (game_time.db.secondsperminute))
     self.msg('{n|   %d minutes per hour.' % (game_time.db.minutesperhour))
     self.msg('{n|   %d hours per day.' % (game_time.db.hoursperday))
     self.msg('{n|   %d days per year.' % (game_time.db.daysperyear))
     self.msg('\:::::::::::...........')
Esempio n. 3
0
 def at_script_creation(self):
     # Called when script is first created
     random_key = "combat_handler_%i" % random.randint(1, 1000)
     while search_script(random_key):
         random_key = "combat_handler_%i" % random.randint(1, 1000)
     self.key = random_key
     self.desc = "handles combat"
     self.interval = COMBAT_ROUND_TIMEOUT
     self.start_delay = True
     self.persistent = True   
     self.db.origin_location = None
     self.db.rooms = []
     self.db.exits = []
     # store all combatants - {dbref1:character}
     self.db.characters = {}
     # store all combat pairs - {attacker1:victim1, attacker2:victim2}
     self.db.pairs = {}
     # store all moves for each turn
     # character.id:{move:char_move, previous_move:prev_move}
     self.db.turn_actions = {}
     # stores all combos for each character - character.id:combo
     self.db.turn_combos = {}
     # stores any flee attempts for each character - character.id:count
     self.db.flee_count = {}
     # shifting targets - character.id:desired new target
     self.db.shifting = {}
     # rescuing targets - character.id:desired rescuee
     self.db.rescuing = {}
     # characters that are requesting a stop - character:target
     self.db.stop_requests = {}
     # add status effects for the turn - 
     # character.id: {effect1:eff1_duration, effect2:eff2_duration}
     self.db.turn_effects = {}
Esempio n. 4
0
    def func(self):
        
        # Find global script
        script_key = "GlobalDatabase"
        script = ev.search_script(script_key)
        if not script:
            self.caller.msg("Global script by name '%s' could not be found." % script_key)
            return
        script = script[0] # all ev.search_* methods always return lists
        
        # Make sure the dictionary already exists in the global database script.
        if "areas" not in script.db.database:
            script.db.database["areas"] = {}
        
        # Parse input
        self.lhs = self.lhs.lower()
        command = ""
        target = ""
        if self.lhs:
            command = self.lhs.split(' ', 1)[0]
            if len(self.lhs.split(' ', 1)) > 1:
                target = self.lhs.split(' ', 1)[1]
        
        

        
        if command == "":
            # View all areas
        
            table = prettytable.PrettyTable(["Name", "Max rooms"])
            table.header = True
            table.border = False
            for key, area in script.db.database["areas"].iteritems():
                if "maxrooms" in area:
                    maxrooms = area["maxrooms"]
                else:
                    maxrooms = ""
                table.add_row([key, maxrooms])
            
            self.caller.msg("Areas:\n\n%s" % unicode(table))
        elif command == "delete":
            if not target:
                self.caller.msg("Which area do you wish to delete?")
                return
            
            if not target in script.db.database["areas"]:
                self.caller.msg("Cannot find area '%s'." % target)
                return
            
            script.db.database["areas"].pop(target, None)
            
            self.caller.msg("Area '%s' was deleted." % target)
        
        elif command == "add":
            if not target:
                self.caller.msg("You must specify an area key to add.")
                return

            if target in script.db.database["areas"]:
                self.caller.msg("There's already an area with key '%s'." % target)
                return

            area = {}
            
            script.db.database["areas"][target] = area
            
            self.caller.msg("Area '%s' was added." % target)
        
        else:
            lhs_split = self.lhs.split('/')
            areakey = lhs_split[0]
            attr = ""
            if len(lhs_split) > 1:
                attr = lhs_split[1]
            new_value = self.rhs
            
            if not areakey in script.db.database["areas"]:
                self.caller.msg("Cannot find area '%s'." % target)
                return
            
            if attr == "":
                # Attribute not included. List all attributes on area.
                string = ""
                for key, value in script.db.database["areas"][areakey].iteritems():
                    string += "Attribute %s/%s = %s\n" % (areakey, key, value)
                
                self.caller.msg(string, raw=True)
                return
            else:
                if not new_value and not attr in script.db.database["areas"][areakey]:
                    self.caller.msg("No such attribute has been set.")
                    return
                
                if new_value == None:
                    # No right hand side at all. Just display attribute.
                    self.caller.msg("Attribute %s/%s = %s" % (areakey, attr, script.db.database["areas"][areakey][attr]), raw=True)
                    return
                elif new_value == "":
                    # Right hand side included but empty. Delete attribute.
                    script.db.database["areas"][areakey].pop(attr, None)
                    self.caller.msg("Attribute %s/%s was deleted." % (areakey, attr))
                    return
                else:
                    # Right hand side is set. Set attribute value.
                    
                    # TODO: Validation of specific attributes
                    
                    script.db.database["areas"][areakey][attr] = self.convert_from_string(new_value)
                    self.caller.msg("Attribute %s/%s was set." % (areakey, attr))
                    return
Esempio n. 5
0
    def func(self):
        script_key = "GlobalTime"
        caller = self.caller

        script = ev.search_script(script_key)      
        if not script:
            self.caller.msg("Global script by name '%s' could not be found." % script_key)
            return
        script = script[0] # all ev.search_* methods always return lists
        
        time = script.db.time
        day = script.db.day
        week = script.db.week
        year = script.db.year
        year_name = script.db.year_name
        weeks_per_year = script.db.weeks_per_year

        time_string = ""
        if not caller.location.tags.get("outdoors"):
            time_string = "You cannot see the sky from here."
        else:
        
            if datetime.time(4, 0) <= time < datetime.time(5, 0):
                time_string = "The first light of dawn is hanging in the air."
            elif datetime.time(5, 0) <= time < datetime.time(6, 0):
                time_string = "The twilight of dawn lights up the sky. The sun will soon rise."
            elif datetime.time(6, 0) <= time < datetime.time(6, 30):
                time_string = "The sun has just appeared above the horizon. The sky is red."
            elif datetime.time(6, 30) <= time < datetime.time(7, 00):
                time_string = "The sun is rising. The sky is sparkling with colors."
            elif datetime.time(7, 00) <= time < datetime.time(8, 00):
                time_string = "It's early morning. The sun is still low."
            elif datetime.time(8, 00) <= time < datetime.time(9, 00):
                time_string = "It's morning."
            elif datetime.time(9, 00) <= time < datetime.time(10, 00):
                time_string = "It's late morning. The brightness of day is taking over."
            elif datetime.time(10, 00) <= time < datetime.time(12, 00):
                time_string = "It's forenoon, approaching midday. The sun is climbing high."
            elif datetime.time(12, 00) <= time < datetime.time(13, 00):
                time_string = "It's midday. The sun is right above you."
            elif datetime.time(13, 00) <= time < datetime.time(14, 00):
                time_string = "It's early afternoon. The sun is leaving zenith."
            elif datetime.time(14, 00) <= time < datetime.time(15, 00):
                time_string = "It's late afternoon. The sun is half-way to the horizon."
            elif datetime.time(15, 00) <= time < datetime.time(16, 00):
                time_string = "It's early evening. The sun is approaching the horizon."
            elif datetime.time(16, 00) <= time < datetime.time(17, 00):
                time_string = "It's late evening. The sun is soon setting."
            elif datetime.time(17, 00) <= time < datetime.time(17, 30):
                time_string = "Sunset has begun. Orange colors are lighting up the sky."
            elif datetime.time(17, 30) <= time < datetime.time(18, 00):
                time_string = "The sun has almost disappeared. The sky is burning red."
            elif datetime.time(18, 00) <= time < datetime.time(19, 00):
                time_string = "The sun has just set. Purple colors of dusk are glowing in the sky."
            elif datetime.time(19, 00) <= time < datetime.time(20, 00):
                time_string = "The last light is leaving the sky, giving way to night."
            elif datetime.time(20, 00) <= time < datetime.time(21, 00):
                time_string = "The night has just begun."
            elif datetime.time(21, 00) <= time < datetime.time(23, 00):
                time_string = "The night is growing darker."
            elif datetime.time(23, 00) <= time <= datetime.time(23, 59):
                time_string = "It's right before midnight. The darkness is reaching its peak"
            elif datetime.time(00, 00) <= time < datetime.time(01, 00):
                time_string = "It's the middle of the night. The darkness is overwhelming."
            elif datetime.time(01, 00) <= time < datetime.time(02, 00):
                time_string = "It's past midnight."
Esempio n. 6
0
    def func(self):
        caller = self.caller

        # Get weather data
        script_key = "GlobalWeather"
        script = ev.search_script(script_key)      
        if not script:
            self.caller.msg("Global script by name '%s' could not be found." % script_key)
            return
        script = script[0] # all ev.search_* methods always return lists
        
        if not caller.location.tags.get("outdoors"):
            self.caller.msg("You cannot see the weather from here.")
            return
        
        cloud_density = script.db.cloud_density
        wind_speed = script.db.wind_speed
        precipitation_level = script.db.precipitation_level
        precipitation_type = script.db.precipitation_type
        
        # Get time data
        script_key = "GlobalTime"
        script = ev.search_script(script_key)      
        if not script:
            self.caller.msg("Global script by name '%s' could not be found." % script_key)
            return
        script = script[0] # all ev.search_* methods always return lists
        
        time = script.db.time
        
        # Generate weather string
        if cloud_density == 0:
            cloud_string = "The sky is clear."
        elif cloud_density == 1:
            cloud_string = "A few small clouds are hanging in the sky."
        elif cloud_density == 2:
            cloud_string = "Light clouds are scattered across the sky."
        elif cloud_density == 3:
            cloud_string = "The sky is partly cloudy."
        elif cloud_density == 4:
            cloud_string = "The sky is covered with clouds."
        elif cloud_density == 5:
            cloud_string = "Dark clouds cover the sky."
        elif cloud_density == 6:
            cloud_string = "Black clouds stretches across the sky."
        elif cloud_density == 7:
            cloud_string = "Huge, black pillars of cloud reaches high up in the atmosphere."
        
        if wind_speed == 0:
            wind_string = "It's nearly windless."
        elif wind_speed == 1:
            wind_string = "The wind is calm."
        elif wind_speed == 2:
            wind_string = "A gentle breeze is stirring the air."
        elif wind_speed == 3:
            wind_string = "There's a strong breeze in the air."
        elif wind_speed == 4:
            wind_string = "A gale is blowing, wind speeds are strong."
        elif wind_speed == 5:
            wind_string = "Storm winds are raging."
        elif wind_speed == 6:
            wind_string = "Violent storm winds are howling in the air."
        elif wind_speed == 7:
            wind_string = "A hurricane is raging. The wind strength is incredible."
        
        string = "%s %s" % (cloud_string, wind_string)

        msg = ""
        if precipitation_level == 1:
            if precipitation_type == "rain":
                msg = "It's raining a little."
                if cloud_density < 4 and datetime.time(6, 30) <= time < datetime.time(9, 0):
                    msg += " A beautiful rainbow arcs across the sky."
                if cloud_density < 4 and datetime.time(14, 00) <= time < datetime.time(17, 30):
                    msg += " A beautiful rainbow arcs across the sky."
            elif precipitation_type == "snow":
                msg = "It's snowing a little."
            elif precipitation_type == "hail":
                msg = "It's hailing a little."
        
        if precipitation_level == 2:
            if precipitation_type == "rain":
                msg = "It's raining."
            elif precipitation_type == "snow":
                msg = "It's snowing."
            elif precipitation_type == "hail":
                msg = "It's hailing."
        
        if precipitation_level == 3:
            if precipitation_type == "rain":
                msg = "It's raining a lot."
            elif precipitation_type == "snow":
                msg = "It's snowing a lot."
            elif precipitation_type == "hail":
                msg = "It's hailing a lot."
        
        if precipitation_level == 4:
            if precipitation_type == "rain":
                msg = "Rain is pouring down."
            elif precipitation_type == "snow":
                msg = "Massive amounts of snow are falling."
            elif precipitation_type == "hail":
                msg = "Massive amounts of hail are falling."
        
        if msg:
            string += "\n%s" % msg

        caller.msg(string)
        
Esempio n. 7
0
from ev import create_script
from ev import search_script
from ev import Script
from ev import logger
from game.gamesrc.combat import move
from game.gamesrc.combat import resolve_combat
from game.gamesrc.combat import combo
import random

COMBAT_ROUND_TIMEOUT = 40
ROOM_DEPTH = 3
STATUS_STORAGE = search_script("StatusStorage")
STATUS_STORAGE = STATUS_STORAGE[0]


class CombatHandler(Script):
    """
    This implements the combat handler.
    """

    # standard Script hooks
    def at_script_creation(self):
        # Called when script is first created
        random_key = "combat_handler_%i" % random.randint(1, 1000)
        while search_script(random_key):
            random_key = "combat_handler_%i" % random.randint(1, 1000)
        self.key = random_key
        self.desc = "handles combat"
        self.interval = COMBAT_ROUND_TIMEOUT
        self.start_delay = True
        self.persistent = True
Esempio n. 8
0
    def func(self):
        caller = self.caller
        location = caller.location
        
        if not location:
            location = caller
            
        # Parse input
        target = None
        name = None
        if self.lhs:
            target = self.lhs.split(' ', 1)[0]
            if len(self.lhs.split(' ', 1)) > 1:
                name = self.lhs.split(' ', 1)[1]
        
        if not target:
            caller.msg("Which object do you wish create?")
            return
        
        # Find global script
        script_key = "GlobalDatabase"
        script = ev.search_script(script_key)
        if not script:
            caller.msg("Global script by name '%s' could not be found." % script_key)
            return
        script = script[0] # all ev.search_* methods always return lists
        
        # Make sure the "template_objects" dictionary already exists in the global database script.
        if "template_objects" not in script.db.database:
            script.db.database["template_objects"] = {}

        lockstring = "control:id(%s);examine:perm(Builders);delete:id(%s) or perm(Wizards)" % (caller.id, caller.id)



        # Create blank object
        if target == "object" or target == "obj":
            typeclass = settings.BASE_OBJECT_TYPECLASS
        
            new_obj = create.create_object(typeclass, "untitled object", location, home=location, locks=lockstring, report_to=caller)
            new_obj.db.desc = ''
        
        # Create blank character
        elif target == "character" or target == "char":
            typeclass = settings.BASE_CHARACTER_TYPECLASS

            new_obj = create.create_object(typeclass, "untitled character", location, home=location, locks=lockstring, report_to=caller)
            new_obj.db.desc = ''
        
        # Create object/character from template
        else:
            target = self.lhs
            name = self.rhs
            
            # Search for target in template database
            if not target in script.db.database["template_objects"]:
                caller.msg("Cannot find template '%s'." % target)
                return
            
            old_obj = script.db.database["template_objects"][target]["object"]
            
            from game.gamesrc.utils.copy_object_recursive import copy_object_recursive
            
            new_obj = copy_object_recursive(old_obj)
            
            # Set object location
            new_obj.home = location
            new_obj.move_to(location, quiet=True)
            
            new_obj.start_scripts()
            if new_obj.db.is_template:
                del new_obj.db.is_template
        
        
        # Set object name if supplied
        if name:
            new_obj.key = name
            
        caller.msg("Created %s." % new_obj.name)
        location.msg_contents("%s creates %s." % (caller.name, new_obj.name), exclude=caller)




        #if not self.args:
        #    string = "Usage: @create[/drop] <newname>[;alias;alias...] [:typeclass_path]"
        #    caller.msg(string)
        #    return
        #
        ## create the objects
        #for objdef in self.lhs_objs:
        #    string = ""
        #    name = objdef['name']
        #    aliases = objdef['aliases']
        #    typeclass = objdef['option']
        #
        #    # create object (if not a valid typeclass, the default
        #    # object typeclass will automatically be used)
        #    lockstring = "control:id(%s);examine:perm(Builders);delete:id(%s) or perm(Wizards)" % (caller.id, caller.id)
        #    obj = create.create_object(typeclass, name, caller,
        #                               home=caller, aliases=aliases,
        #                               locks=lockstring, report_to=caller)
        #    if not obj:
        #        continue
        #    if aliases:
        #        string = "You create a new %s: %s (aliases: %s)."
        #        string = string % (obj.typeclass.typename, obj.name, ", ".join(aliases))
        #    else:
        #        string = "You create a new %s: %s."
        #        string = string % (obj.typeclass.typename, obj.name)
        #    
        #    # set a default desc
        #    if not obj.db.desc:
        #        obj.db.desc = "You see nothing special."
        #
        #    # Set object location
        #    if caller.location:
        #        obj.home = caller.location
        #        obj.move_to(caller.location, quiet=True)
        #    
        #if string:
        #    self.caller.msg(string)
Esempio n. 9
0
from ev import create_script
from ev import search_script
from ev import Script
from ev import logger
from game.gamesrc.combat import move
from game.gamesrc.combat import resolve_combat
from game.gamesrc.combat import combo
import random

COMBAT_ROUND_TIMEOUT = 40
ROOM_DEPTH = 3
STATUS_STORAGE = search_script("StatusStorage")
STATUS_STORAGE = STATUS_STORAGE[0]

class CombatHandler(Script):
    """
    This implements the combat handler.
    """
    # standard Script hooks 
    def at_script_creation(self):
        # Called when script is first created
        random_key = "combat_handler_%i" % random.randint(1, 1000)
        while search_script(random_key):
            random_key = "combat_handler_%i" % random.randint(1, 1000)
        self.key = random_key
        self.desc = "handles combat"
        self.interval = COMBAT_ROUND_TIMEOUT
        self.start_delay = True
        self.persistent = True   
        self.db.origin_location = None
        self.db.rooms = []