Exemple #1
0
    def get_modifier(self,
                     check_type,
                     user_tags=None,
                     target_tags=None,
                     stat_list=None,
                     skill_list=None,
                     ability_list=None):
        """Returns an integer that is the value of our modifier for the listed tags and check.

            Args:
                check_type: The type of roll/check we're making
                user_tags: Tags of the user we wanna check
                target_tags: Tags of the target we wanna check
                stat_list: Only check modifiers for this stat
                skill_list: Only check modifiers for this skill
                ability_list: Only check modifiers for this ability

            Returns:
                Integer value of the total mods we calculate.
        """
        from django.db.models import Sum
        from world.conditions.models import RollModifier
        check_types = RollModifier.get_check_type_list(check_type)
        return self.modifiers.filter(check__in=check_types,
                                     user_tag__in=user_tags,
                                     target_tag__in=target_tags,
                                     stat__in=stat_list,
                                     skill__in=skill_list,
                                     ability__in=ability_list).aggregate(
                                         Sum('value'))[1]
Exemple #2
0
 def get_total_modifier(self,
                        check_type,
                        target_tags=None,
                        stat_list=None,
                        skill_list=None,
                        ability_list=None):
     """Gets all modifiers from their location and worn/wielded objects."""
     from django.db.models import Sum
     from world.conditions.models import RollModifier
     user_tags = self.modifier_tags or []
     user_tags.append("")
     # get modifiers from worn stuff we have and our location, if any
     all_objects = list(self.worn)
     if self.location:
         all_objects.append(self.location)
     all_objects.append(self)
     if self.weapon:
         all_objects.append(self.weapon)
     all_objects = [ob.id for ob in all_objects]
     check_types = RollModifier.get_check_type_list(check_type)
     return RollModifier.objects.filter(object_id__in=all_objects or [],
                                        check__in=check_types or [],
                                        user_tag__in=user_tags or [],
                                        target_tag__in=target_tags or [],
                                        stat__in=stat_list or [],
                                        skill__in=skill_list or [],
                                        ability__in=ability_list
                                        or []).aggregate(
                                            Sum('value'))['value__sum'] or 0