def current_race(self, value): old = self._current_race assert old != value assert value in race_manager self.execute('changefromcmd', define=True) team = self.player.team if team >= 2: team_data[team][f'_internal_{old}_limit_allowed'].remove( self.userid) if not team_data[team][f'_internal_{old}_limit_allowed']: del team_data[team][f'_internal_{old}_limit_allowed'] if f'_internal_{value}_limit_allowed' not in team_data[team]: team_data[team][f'_internal_{value}_limit_allowed'] = [] team_data[team][f'_internal_{value}_limit_allowed'].append( self.userid) _restrictions.player_restrictions[self.userid].clear() restricted_weapons = race_manager[value].config.get( 'restrictweapon', []) if restricted_weapons: weapons = set() for weapon in restricted_weapons: if weapon.startswith('#'): weapons.update( map(lambda weapon_inst: weapon_inst.name, WeaponClassIter(weapon[1:]))) elif weapon.startswith('!'): # Objective items will never be restricted unless explicitly told weapons.update( map( lambda weapon_inst: weapon_inst.name, WeaponClassIter( not_filters=['objective', weapon[1:]]))) else: weapons.add(weapon) _restrictions.add_player_restrictions( self.player, *[weapon for weapon in weapons if weapon in weapon_manager]) self._current_race = value self.execute('changeintocmd', define=True) OnPlayerChangeRace.manager.notify(self, old, value)
def weapon_indexes(self, classname=None, is_filters=None, not_filters=None): """Iterate over the player's weapon indexes for the given arguments. :return: A generator of indexes. :rtype: generator """ # 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('{base}{offset:03d}'.format( base=weapon_manager.myweapons, offset=offset, )) # Try to get the index of the handle try: index = index_from_inthandle(handle) except (ValueError, OverflowError): continue # Get the weapon's classname weapon_class = edict_from_index(index).classname # 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 map( lambda value: value.name, WeaponClassIter(is_filters, not_filters)): # Do not yield this index continue # Yield the index yield index
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) try: index = index_from_inthandle(handle) except (ValueError, OverflowError): continue # Get the weapon's classname weapon_class = edict_from_index(index).classname # 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 map( lambda value: value.name, WeaponClassIter(is_filters, not_filters)): # Do not yield this index continue # Yield the index yield index
from listeners.tick import Delay # Mathlib from mathlib import NULL_VECTOR # Memory from memory import make_object # Players from players.constants import HitGroup # Studio from studio.cache import model_cache from studio.constants import INVALID_ATTACHMENT_INDEX # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get a list of projectiles for the game _projectile_weapons = [weapon.name for weapon in WeaponClassIter('grenade')] # Get a dictionary to store the delays _entity_delays = defaultdict(set) # ============================================================================= # >> CLASSES # ============================================================================= class Entity(BaseEntity): """Class used to interact directly with entities. Beside the standard way of doing stuff via methods and properties this class also provides dynamic attributes that depend on the entity that is being accessed with this class. You can print all dynamic properties by iterating over the following generators:
# ============================================================================ # >> GLOBAL VARIABLES # ============================================================================ _aliases = {} if (TRANSLATION_PATH / 'strings.ini').isfile(): _strings = LangStrings(TRANSLATION_PATH / 'strings') for key in _strings: for language, message in _strings[key].items(): _strings[key][language] = message.replace('#default', COLOR_DEFAULT).replace('#green', COLOR_GREEN).replace('#lightgreen', COLOR_LIGHTGREEN).replace('#darkgreen', COLOR_DARKGREEN) else: _strings = None _restrictions = WeaponRestrictionHandler() _all_weapons = set([x.basename for x in WeaponClassIter('all', ['melee', 'objective'])]) if (CFG_PATH / 'es_WCSlanguage_db.txt').isfile(): _languages = KeyValues.load_from_file(CFG_PATH / 'es_WCSlanguage_db.txt').as_dict() else: _languages = {} _repeats = defaultdict(list) # ============================================================================ # >> HELPER FUNCTIONS # ============================================================================ def validate_userid_after_delay(callback, userid, *args, validator=convert_userid_to_player): callback(None, validator(userid), *args)
chat_strings['force change team limit']) no_unused_message = SayText2(chat_strings['no unused']) no_access_message = SayText2(chat_strings['no access']) ability_team_message = SayText2(chat_strings['ability team']) ability_dead_message = SayText2(chat_strings['ability dead']) ability_deactivated_message = SayText2(chat_strings['ability deactivated']) ability_cooldown_message = SayText2(chat_strings['ability cooldown']) ability_level_message = SayText2(chat_strings['ability level']) top_public_announcement_message = SayText2( chat_strings['top public announcement']) top_private_announcement_message = SayText2( chat_strings['top private announcement']) top_stolen_notify_message = SayText2(chat_strings['top stolen notify']) _delays = defaultdict(set) _melee_weapons = [weapon.basename for weapon in WeaponClassIter('melee')] # ============================================================================ # >> FUNCTIONS # ============================================================================ def load(): # Is Github available? if IS_GITHUB_ENABLED: github_manager.refresh() database_manager.connect() race_manager.load_all() item_manager.load_all()
from .database import load_hero_data from .database import save_player_data from .database import save_hero_data from .database import manager ## ALL DECLARATION __all__ = ( 'players', 'unload_database', ) ## GLOBALS players = dict() all_weapons = set(weapon.name for weapon in WeaponClassIter()) for player in PlayerIter(): load_player_data(player) load_hero_data(player) players[player.userid] = player def unload_database(): manager.connection.commit() manager.connection.close() ## PLAYER MANAGMENT
from .info import info ## ALL DECLARATION __all__ = ( '_all_weapons', 'g_configs', 'g_configs_map', ) ## GLOBALS _weapons = [ item.name.split('_')[1] for item in WeaponClassIter(not_filters=['knife', 'objective']) ] _all_weapons = set(weapon.name for weapon in WeaponClassIter()) g_configs = dict() g_configs_map = dict() with ConfigManager(info.name) as _config: # # Displaying informations # _config.section('Restrictions') for weapon in _weapons: g_configs['restrict_' + weapon + '_ct'] = _config.cvar(
from warcraft.registration import events from warcraft.skill import Skill from warcraft.utility import classproperty ## warcraft.skills imports from ..skills.self_reduce_gravity import ReduceGravitySkill ## __all__ declaration __all__ = ("FlamePredator", ) ## flamepredator declaration _knifeonly = set(weapon.basename for weapon in WeaponClassIter(not_filters='knife')) class FlamePredator(Race): @classproperty def description(cls): return 'Recoded Flame Predator. (Kryptonite)' @classproperty def max_level(cls): return 99 @classproperty def requirement_sort_key(cls): return 10
from filters.weapons import WeaponClassIter from weapons.manager import weapon_manager ## __all__ = ( 'viewmodel_manager', 'worldmodel_manager', 'all_weapons', 'all_projectiles', 'all_class_names', ) ## all_weapons = [weapon.name for weapon in WeaponClassIter()] all_projectiles = list(weapon_manager.projectiles) all_class_names = all_weapons + all_projectiles ## class ModelManager(dict): '''A simplistic dictionary to store all changed models. This will raise exceptions if users try to apply more than 1 view model to a single weapon. ''' def __init__(self, name): self._name = name
from udm.info import info # Menus from udm.weapons.menus import primary_menu # Players from udm.players import PlayerEntity # Spawn Locations from udm.spawn_locations import menus # Weapons from udm.weapons import weapon_manager # ============================================================================= # >> FORBIDDEN ENTITIES # ============================================================================= # Store a list of forbidden entities forbidden_entities = list([ weapon_data.name for weapon_data in WeaponClassIter(is_filters='objective') ] + ['hostage_entity', 'item_defuser']) # ============================================================================= # >> MAP FUNCTIONS # ============================================================================= # Store a list of map functions to disable when they have spawned map_functions = ['func_bomb_target', 'func_buyzone', 'func_hostage_rescue'] # ============================================================================= # >> HELPER FUNCTIONS # ============================================================================= def prepare_player(player): """Prepare the player for battle.""" # Perform setting the player's spawn location on another thread