コード例 #1
0
    def weapon_indexes(
            self, classname=None, is_filters=None, not_filters=None):
        """Iterate over all currently held weapons by thier index."""
        # Is the weapon array supported for the current game?
        if _weapon_prop_length is None:
            return

        # Loop through the length of the weapon array
        for offset in range(_weapon_prop_length):

            # Get the player's current weapon at this offset
            handle = self.get_property_int(
                weapon_manager.myweapons + '%03i' % offset)

            # Get the weapon's index
            index = index_from_inthandle(handle, raise_exception=False)

            # Is this a valid index?
            if not index:

                # Move onto the next offset
                continue

            # Get the weapon's edict
            edict = Entity(index)

            # Get the weapon's classname
            weapon_class = edict.get_class_name()

            # Was a classname given and the current
            # weapon is not of that classname?
            if classname is not None and weapon_class != classname:

                # Do not yield this index
                continue

            # Import WeaponClassIter to use its functionality
            from filters.weapons import WeaponClassIter

            # Was a weapon type given and the
            # current weapon is not of that type?
            if not (is_filters is None and not_filters is None):
                if weapon_class not in list(WeaponClassIter(
                        is_filters, not_filters, 'classname')):

                    # Do not yield this index
                    continue

            # Yield the index
            yield index