Example #1
0
    def __init__(self, *args, **kwargs):
        super(FoodsForm, self).__init__(*args, **kwargs)

        self.fields['icon'] = ImageField(image_type="icon", required=False)

        localize_form_fields(self)
        FOOD_ATTRIBUTES_INFO.set_form_fields(self)
Example #2
0
    def __init__(self, *args, **kwargs):
        super(FoodsForm, self).__init__(*args, **kwargs)

        typeclasses = TYPECLASS_SET.get_group("FOOD")
        choices = [(key, cls.typeclass_name + " (" + key + ")")
                   for key, cls in typeclasses.items()]
        self.fields['typeclass'] = forms.ChoiceField(choices=choices)

        self.fields['icon'] = IconField(required=False)

        localize_form_fields(self)
        FOOD_ATTRIBUTES_INFO.set_form_fields(self)
Example #3
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    from muddery.utils.game_settings import GAME_SETTINGS
    GAME_SETTINGS.reset()

    # reload local strings
    from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER
    LOCALIZED_STRINGS_HANDLER.reload()

    # reload attributes
    from muddery.utils.attributes_info_handler import CHARACTER_ATTRIBUTES_INFO
    CHARACTER_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import EQUIPMENT_ATTRIBUTES_INFO
    EQUIPMENT_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import FOOD_ATTRIBUTES_INFO
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    from muddery.utils import builder
    builder.reset_default_locations()
    
    # clear dialogues
    from muddery.utils.dialogue_handler import DIALOGUE_HANDLER
    DIALOGUE_HANDLER.clear()
    
    # reload equipment types
    from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER
    EQUIP_TYPE_HANDLER.reload()

    # localize model fields
    from muddery.utils.localiztion_handler import localize_model_fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()
    
    # load condition descriptions
    from muddery.utils.desc_handler import DESC_HANDLER
    DESC_HANDLER.reload()
    
    # load honours
    from muddery.dao.honours_mapper import HONOURS_MAPPER
    HONOURS_MAPPER.reload()
Example #4
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    from muddery.utils.game_settings import GAME_SETTINGS
    GAME_SETTINGS.reset()

    # reload local strings
    from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER
    LOCALIZED_STRINGS_HANDLER.reload()

    # reload attributes
    from muddery.utils.attributes_info_handler import CHARACTER_ATTRIBUTES_INFO
    CHARACTER_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import EQUIPMENT_ATTRIBUTES_INFO
    EQUIPMENT_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import FOOD_ATTRIBUTES_INFO
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    from muddery.utils import builder
    builder.reset_default_locations()

    # clear dialogues
    from muddery.utils.dialogue_handler import DIALOGUE_HANDLER
    DIALOGUE_HANDLER.clear()

    # reload equipment types
    from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER
    EQUIP_TYPE_HANDLER.reload()

    # localize model fields
    from muddery.utils.localiztion_handler import localize_model_fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()

    # load condition descriptions
    from muddery.utils.desc_handler import DESC_HANDLER
    DESC_HANDLER.reload()

    # load honours
    from muddery.dao.honours_mapper import HONOURS_MAPPER
    HONOURS_MAPPER.reload()
Example #5
0
    def __init__(self, *args, **kwargs):
        super(FoodsForm, self).__init__(*args, **kwargs)
        
        objects = DATA_SETS.typeclasses.objects.filter(key="CLASS_FOOD")
        choices = [(obj.key, obj.name + " (" + obj.key + ")") for obj in objects]
        self.fields['typeclass'] = forms.ChoiceField(choices=choices)
        
        choices = [("", "---------")]
        objects = DATA_SETS.icon_resources.objects.all()
        choices.extend([(obj.key, obj.name + " (" + obj.key + ")") for obj in objects])
        self.fields['icon'] = forms.ChoiceField(choices=choices, required=False)

        localize_form_fields(self)
        FOOD_ATTRIBUTES_INFO.set_form_fields(self)
Example #6
0
    def __init__(self, *args, **kwargs):
        super(FoodsForm, self).__init__(*args, **kwargs)

        typeclasses = TYPECLASS_SET.get_group("FOOD")
        choices = [(key, cls.typeclass_name + " (" + key + ")")
                   for key, cls in typeclasses.items()]
        self.fields['typeclass'] = forms.ChoiceField(choices=choices)

        choices = [("", "---------")]
        objects = CM.ICON_RESOURCES.objects.all()
        choices.extend([(obj.key, obj.name + " (" + obj.key + ")")
                        for obj in objects])
        self.fields['icon'] = forms.ChoiceField(choices=choices,
                                                required=False)

        localize_form_fields(self)
        FOOD_ATTRIBUTES_INFO.set_form_fields(self)
Example #7
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reload attributes
    CHARACTER_ATTRIBUTES_INFO.reload()
    EQUIPMENT_ATTRIBUTES_INFO.reload()
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    builder.reset_default_locations()

    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()

    # load condition descriptions
    DESC_HANDLER.reload()

    # load honours
    HONOURS_MAPPER.reload()
Example #8
0
    def take_effect(self, user, number):
        """
        Use this object.

        Args:
            user: (object) the object who uses this
            number: (int) the number of the object to use

        Returns:
            (result, number):
                result: (string) a description of the result
                number: (int) actually used number
        """
        if not user:
            raise ValueError("User should not be None.")

        if number <= 0:
            raise ValueError("Number should be above zero.")

        used = number
        if used > self.db.number:
            used = self.db.number

        increments = {}
        for key in self.custom_attributes_handler.all():
            value = getattr(self.cattr, key)
            if not value:
                logger.log_errmsg("Can not apply custom attribute: %s to %s" %
                                  (key, self.get_data_key()))
                continue
            increments[key] = value * used

        changes = user.change_status(increments)
        user.show_status()

        result = ""
        for key in changes:
            # set result
            attribute_info = FOOD_ATTRIBUTES_INFO.for_key(key)

            if result:
                result += ", "

            if changes[key] >= 0:
                result += "%s +%s" % (attribute_info["name"], changes[key])
            else:
                result += "%s %s" % (attribute_info["name"], changes[key])

        return result, used
Example #9
0
    def take_effect(self, user, number):
        """
        Use this object.

        Args:
            user: (object) the object who uses this
            number: (int) the number of the object to use

        Returns:
            (result, number):
                result: (string) a description of the result
                number: (int) actually used number
        """
        if not user:
            raise ValueError("User should not be None.")

        if number <= 0:
            raise ValueError("Number should be above zero.")

        used = number
        if used > self.db.number:
            used = self.db.number

        increments = {}
        for key in self.custom_attributes_handler.all():
            value = getattr(self.cattr, key)
            if value:
                increments[key] = value * used

        changes = user.change_status(increments)
        user.show_status()
        
        result = ""
        for key in changes:
            # set result
            attribute_info = FOOD_ATTRIBUTES_INFO.for_key(key)
                
            if result:
                result += ", "

            if changes[key] >= 0:
                result += "%s +%s" % (attribute_info["name"], changes[key])
            else:
                result += "%s %s" % (attribute_info["name"], changes[key])

        return result, used
Example #10
0
    def take_effect(self, user, number):
        """
        Use this object.

        Args:
            user: (object) the object who uses this
            number: (int) the number of the object to use

        Returns:
            (result, number):
                result: (string) a description of the result
                number: (int) actually used number
        """
        if not user:
            raise ValueError("User should not be None.")

        if number <= 0:
            raise ValueError("Number should be above zero.")

        used = number
        if used > self.db.number:
            used = self.db.number

        increments = {}
        for key, value in self.custom_properties_handler.all(True):
            if value:
                increments[key] = value * used

        changes = user.change_properties(increments)
        user.show_status()

        result = ""
        for key in changes:
            # set result
            attribute_info = FOOD_ATTRIBUTES_INFO.for_key(key)

            if result:
                result += ", "

            if changes[key] >= 0:
                result += "%s +%s" % (attribute_info["name"], changes[key])
            else:
                result += "%s %s" % (attribute_info["name"], changes[key])

        return result, used
Example #11
0
    def __init__(self, *args, **kwargs):
        super(FoodsForm, self).__init__(*args, **kwargs)

        localize_form_fields(self)
        FOOD_ATTRIBUTES_INFO.set_form_fields(self)
Example #12
0
    def __init__(self, *args, **kwargs):
        super(FoodsForm, self).__init__(*args, **kwargs)

        localize_form_fields(self)
        FOOD_ATTRIBUTES_INFO.set_form_fields(self)
Example #13
0
    def take_effect(self, user, number):
        """
        Use this object.

        Args:
            user: (object) the object who uses this
            number: (int) the number of the object to use

        Returns:
            (result, number):
                result: (string) a description of the result
                number: (int) actually used number
        """
        if not user:
            raise ValueError("User should not be None.")

        if number <= 0:
            raise ValueError("Number should be above zero.")

        status_changed = False

        result = ""
        used = number
        if used > self.db.number:
            used = self.db.number

        status_changed = False
        for key in self.custom_attributes_handler.all():
            if user.attributes.has(key):
                # try to add to user's db
                target = user.db
            elif hasattr(user, key):
                # try to add to user's attribute
                target = user
            elif user.custom_attributes_handler.has(key):
                # try to add to user's cattr
                target = user.cattr
            else:
                # no target
                continue

            origin_value = getattr(target, key)
            increment = getattr(self.cattr, key) * used

            # check limit
            limit_key = "max_" + key
            limit_source = None
            if user.attributes.has(limit_key):
                # try to add to user's db
                limit_source = user.db
            elif hasattr(user, limit_key):
                # try to add to user's attribute
                limit_source = user
            elif user.custom_attributes_handler.has(limit_key):
                # try to add to user's cattr
                limit_source = user.cattr

            if limit_source is not None:
                limit_value = getattr(limit_source, limit_key)
                if origin_value + increment > limit_value:
                    increment = limit_value - origin_value

            # add value
            if increment != 0:
                setattr(target, key, origin_value + increment)
                status_changed = True

            # set result
            attribute_info = FOOD_ATTRIBUTES_INFO.for_key(key)

            if result:
                result += ", "

            if increment >= 0:
                result += "%s +%s" % (attribute_info["name"], increment)
            else:
                result += "%s %s" % (attribute_info["name"], increment)

        if status_changed:
            user.show_status()

        return result, used