def _pre_take_damage(stack_data): """Set player health/armor to allow projectile kill.""" if GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: return take_damage_info = make_object(TakeDamageInfo, stack_data[1]) attacker = Entity(take_damage_info.attacker) if attacker.classname != 'player': return victim = make_object(Entity, stack_data[0]) if victim.team_index == attacker.team_index: if 'gg_ffa' not in gg_plugin_manager: return classname = Entity(take_damage_info.weapon).classname if classname not in _projectile_weapons: return if 'gg_teamplay' in gg_plugin_manager and victim.team_index == attacker.team_index: return attacker = player_dictionary.from_index(attacker.index) if weapon_manager[classname].basename != attacker.level_weapon: return victim.health = 1 victim.armor = 0
def get_vec(value): if isinstance(value, int): return Entity(value).origin elif isinstance(value, BaseEntity): return Entity(value.index).origin else: return value
def place_stairs(self): exit = find(lambda room: room.name == 'exit', self.current_level.rooms) if (exit): x, y = exit.center self.down_stairs = Entity(Point(x, y), '>', 'Stairs', COLORS.get('stairs'), render_order=RenderOrder.STAIRS, always_visible=True) self.down_stairs.add_component(Stairs(self.dungeon_level + 1), "stairs") self.current_level.add_entity(self.down_stairs) entrance = find(lambda room: room.name == 'entrance', self.current_level.rooms) if (entrance): x, y = entrance.center self.up_stairs = Entity(Point(x, y), '<', 'Stairs', COLORS.get('stairs'), render_order=RenderOrder.STAIRS, always_visible=True) self.up_stairs.add_component(Stairs(self.dungeon_level - 1), "stairs") self.current_level.add_entity(self.up_stairs)
def __init__(self): self.looping = True self.player = Player(240, 240) self.player.weapons.append(Switcheroo()) self.player.weapons.append(Magnet()) self.entities = [] self.entities.append(self.player) self.entities.append(Entity(100, 380)) self.entities.append(Entity(300, 380)) self.objects = [] self.objects.append(KillPart(350, 100)) self.objects.append(KillPart(160, 200)) self.objects.append(KillPart(240, 400)) self.clock = pygame.time.Clock()
def _on_pre_death_obtain_weapons(self, victim, **kwargs): self.weapons = [ Entity(index).class_name for index in victim.weapon_indexes(not_filters='knife') ] self.location = victim.origin.copy() self.location.z += 1
def _add_weapon_ammo(self, value, classname=None, is_filters=None, not_filters=None): """Add ammo to the player's current value for the given arguments. Adds for the first weapon found from the given arguments. """ # Get the index for the given arguments index = self.get_weapon_index(classname, is_filters, not_filters) # Was no index found? if index is None: # Raise an error raise LookupError('No index found for given arguments ' '"{0}, {1}, {2}" for player "{3}"'.format( classname, is_filters, not_filters, self.userid)) # Get the entity's Entity instance weapon = Entity(index) # Get the current ammo value current = self.get_property_int(weapon_manager.ammoprop + '%03d' % weapon.ammoprop) # Add ammo to the current value self.set_property_int( weapon_manager.ammoprop + '%03d' % weapon.ammoprop, current + value)
def _spend_skills_on_level_up(player, race, amount): """ Callback for the race_level_up event to handle menu sending, bot auto-upgrades and level up effects. """ if (race.level > sum(skill.max_level for skill in race.skills) or race.level > race.max_level): return spend_skills_menu.send(player.index) if player.steamid == 'BOT': while race.unused_points > 0: skill = find_upgradable_skill(race) if skill: skill.level_up(1) levelup_sound.origin = player.origin levelup_sound.play(player.index) pointer = player.give_named_item('env_smokestack', 0, None, False) entity = Entity(index_from_pointer(pointer)) for output in ('basespread 10', 'spreadspeed 60', 'initial 0', 'speed 105', 'rate 50', 'startsize 7', 'endsize 2', 'twist 0', 'jetlength 100', 'angles 0 0 0', 'rendermode 18', 'renderamt 100', 'rendercolor 255 255 3', 'SmokeMaterial effects/yellowflare.vmt'): entity.add_output(output) entity.turn_on() attach_entity_to_player(player, entity) entity.delay(0.5, entity.turn_off)
def listener_on_entity_spawned(self, base_entity): if base_entity.classname != 'flashbang_projectile': return index = base_entity.index entity = Entity(index) for player in self._players: if player.inthandle == entity.owner_handle: break else: return temp_entity = TempEntity('BeamFollow') temp_entity.entity_index = index temp_entity.model_index = BEAM_MODEL.index temp_entity.halo_index = BEAM_MODEL.index temp_entity.life_time = 1 temp_entity.start_width = 3 temp_entity.end_width = 3 temp_entity.fade_length = 1 temp_entity.red = 255 temp_entity.green = 255 temp_entity.blue = 255 temp_entity.alpha = 150 temp_entity.create(RecipientFilter())
def push_by_damage_info(victim, attacker, info, map_data): inflictor = Entity(info.inflictor) d = victim.origin - inflictor.origin dmg_base = map_data['ARENA_DAMAGE_BASE'] base_force_h = map_data['ARENA_HORIZONTAL_FORCE_BASE'] force_v = map_data['ARENA_VERTICAL_FORCE'] vec_len = (d.x * d.x + d.y * d.y)**0.5 if vec_len == 0.0: return f = { 1: lambda x: x, 2: lambda x: x**0.5, 3: lambda x: x**(1.0 / 3.0), }.get(map_data['ARENA_FORCE_FALLOFF']) if f is None: return k_h = (base_force_h / vec_len) * f(info.damage / dmg_base) k_v = f(info.damage / dmg_base) victim.base_velocity = Vector(d.x * k_h, d.y * k_h, force_v * k_v)
def listener_on_entity_spawned(self, index, base_entity): if base_entity.classname != 'flashbang_projectile': return entity = Entity(index) if entity.owner_handle not in (self.prisoner.inthandle, self.guard.inthandle): return temp_entity = TempEntity('BeamFollow') temp_entity.entity_index = index temp_entity.model_index = BEAM_MODEL.index temp_entity.halo_index = BEAM_MODEL.index temp_entity.life_time = 1 temp_entity.start_width = 3 temp_entity.end_width = 3 temp_entity.fade_length = 1 temp_entity.red = 255 temp_entity.green = 255 temp_entity.blue = 255 temp_entity.alpha = 150 temp_entity.create(RecipientFilter())
def _dissolve_ragdoll(inthandle, current_type): """Dissolve/remove the player's ragdoll.""" try: entity = Entity(index_from_inthandle(inthandle)) except (OverflowError, ValueError): return # Should the ragdoll just be removed? if current_type == NUM_DISSOLVE_TYPES + 2: entity.remove() return # Set the target name for the player's ragdoll entity.target_name = f'ragdoll_{inthandle}' # Get the dissolver entity dissolver_entity = Entity.find_or_create('env_entity_dissolver') # Should a random dissolve type be chosen? if current_type == NUM_DISSOLVE_TYPES + 1: current_type = randrange(NUM_DISSOLVE_TYPES) # Set the magnitude dissolver_entity.magnitude = dissolver_magnitude.get_int() # Set the dissolve type dissolver_entity.dissolve_type = current_type # Dissolve the ragdoll dissolver_entity.dissolve(f'ragdoll_{inthandle}')
def pre_on_take_damage(args): # Get the victim victim = make_object(Player, args[0]) # Get TakeDamageInfo object info = make_object(TakeDamageInfo, args[1]) # Was it a self-inflicted damage? if info.attacker == victim.index: return # Check if attacker is a player entity = Entity(info.attacker) if not entity.is_player(): return # Get the attacker attacker = Player(info.attacker) # Do our thing if attacker.is_bot() and not victim.is_bot(): info.damage *= caches_from[victim.index].multiplier elif not attacker.is_bot() and victim.is_bot(): info.damage *= caches_to[attacker.index].multiplier
def _pre_damage_call_events(stack_data): take_damage_info = make_object(TakeDamageInfo, stack_data[1]) if not take_damage_info.attacker: return entity = Entity(take_damage_info.attacker) attacker = players[entity.index] if entity.is_player() else None victim = players[index_from_pointer(stack_data[0])] event_args = { 'attacker': attacker, 'victim': victim, 'take_damage_info': take_damage_info, } if attacker: if victim.team == attacker.team: attacker.hero.call_events('player_pre_teammate_attack', player=attacker, **event_args) victim.hero.call_events('player_pre_teammate_victim', player=victim, **event_args) return attacker.hero.call_events('player_pre_attack', player=attacker, **event_args) victim.hero.call_events('player_pre_victim', player=victim, **event_args) if victim.health <= take_damage_info.damage: attacker.hero.call_events('player_pre_death', player=victim, **event_args)
def _add_weapon_clip(self, value, classname=None, is_filters=None, not_filters=None): """Add ammo to the weapon's current value for the given arguments. Adds for the first weapon found from the given arguments. """ # Get the index for the given arguments index = self.get_weapon_index(classname, is_filters, not_filters) # Was no index found? if index is None: # Raise an error raise LookupError('No index found for given arguments ' '"{0}, {1}, {2}" for player "{3}"'.format( classname, is_filters, not_filters, self.userid)) # Get the entity's Entity instance weapon = Entity(index) # Add ammo to the weapon's clip weapon.clip += value
def is_world(index): if index == WORLD_ENTITY_INDEX: return True if Entity(index).classname != 'player': return True return False
def listener_on_entity_spawned(base_entity): if base_entity.classname not in valid_npc_classnames: return entity = Entity(base_entity.index) entity.spawn_flags |= 512 entity.set_key_value_int('sleepstate', 0) entity.call_input('SetRelationship', 'player D_HT 99')
def _change_model_world_model(entity): 'Changes a weapons world model upon being created.' ## Technically a <BaseEntity> instance, but who cares? hehe if entity.classname not in worldmodel_manager: return model = worldmodel_manager[entity.classname] weapon = Entity(entity.index) weapon._set_model(model.path)
def current_owner(self): """Return a Entity instance of the weapon's owner.""" # Does no player currently own the weapon? if self.owner == -1: return None # Return a Entity instance of the owner return Entity(index_from_inthandle(self.owner))
def get_weapon_color(self): """Return a tuple value for the player's active weapon's color.""" try: index = index_from_inthandle(self.active_weapon) except (ValueError, OverflowError): raise ValueError('No active weapon found for player "{0}"'.format( self.userid)) return Entity(index).color
def on_entity_spawned(base_entity): """Remove forbidden entities when they have spawned.""" if base_entity.classname in forbidden_entities: base_entity.remove() # Disable map functions as well elif base_entity.classname in map_functions: entity = Entity(base_entity.index) entity.call_input('Disable')
def set_weapon_color(self, color): """Set the player's active weapon's color.""" try: index = index_from_inthandle(self.active_weapon) except (ValueError, OverflowError): raise ValueError('No active weapon found for player "{0}"'.format( self.userid)) Entity(index).color = color
def map_to_sprites(game_map: List[List[int]]) -> arcade.SpriteList[Entity]: """ Take a grid of numbers and convert to sprites. """ sprite_list = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=16) # Take the tiles and make sprites out of them for y in range(len(game_map[0])): for x in range(len(game_map)): sprite = None # print(f"{game_map[x][y]} ", end="") if game_map[x][y] == TILE_WALL: sprite = Entity(x, y, WALL_TEXTURE_ID, colors['transparent']) sprite.name = "Wall" sprite.block_sight = True sprite.blocks = True sprite.visible_color = colors["light_wall"] sprite.not_visible_color = colors["dark_wall"] elif game_map[x][y] == TILE_FLOOR: sprite = Entity(x, y, FLOOR_TEXTURE_ID, colors['transparent']) sprite.name = "Ground" sprite.block_sight = False sprite.visible_color = colors["light_ground"] sprite.not_visible_color = colors["dark_ground"] elif game_map[x][y] == TILE_STAIRS_DOWN: sprite = Stairs(x, y, STAIRS_DOWN_TEXTURE_ID, colors['transparent']) sprite.name = "Stairs Down" sprite.block_sight = False sprite.visible_color = colors["light_ground"] sprite.not_visible_color = colors["dark_ground"] elif game_map[x][y] == TILE_HEALING_POTION: sprite = Potion(x, y) elif game_map[x][y] == TILE_LIGHTNING_SCROLL: sprite = LightningScroll(x, y) elif game_map[x][y] == TILE_FIREBALL_SCROLL: sprite = FireballScroll(x, y) elif game_map[x][y]: raise ValueError(f"Unknown number in map: {game_map[x][y]}") if sprite: sprite_list.append(sprite) # print() return sprite_list
def create_potion(point, usable): item = Entity(point, chr(173), usable.name, COLORS.get('equipment_uncommon'), render_order=RenderOrder.ITEM, item=Item(), usable=usable) return potion_description(item)
def ring_of_regeneration(point=None): equippable_component = Equippable(EquipmentSlot.RING, attribute=Regeneration()) item = Entity(point, chr(9), 'Ring of Regeneration', COLORS.get('equipment_rare'), render_order=RenderOrder.ITEM, equippable=equippable_component) return item
def key(point=None, unlocks=None): key = Entity(point, 'k', 'key', COLORS.get('light_door'), blocks=False, interaction=Interactions.NONE, render_order=RenderOrder.ITEM, item=Item()) key.add_component(Unlock(unlocks.uuid), 'unlock') return key
def take_damage_hook(stack_data): take_damage_info = make_object(TakeDamageInfo, stack_data[1]) attacker = Entity(take_damage_info.attacker) victim = make_object(Entity, stack_data[0]) if victim.index in entity_health: damage = take_damage_info.damage if entity_health[victim.index] <= 0: Delay(0.1, victim.remove) else: entity_health[victim.index] -= damage else: return
def pseudopod(point=None): equippable_component = Equippable(EquipmentSlot.MAIN_HAND, power=1) equippable_component.type_of_dice = 6 equippable_component.damage_type = DamageType.BLUNT item = Entity(point, ',', 'pseudopod', COLORS.get('equipment_uncommon'), equippable=equippable_component, render_order=RenderOrder.ITEM) return item
def listener_on_entity_spawned(index, base_entity): if base_entity.classname not in PROJECTILE_MAPPING: return entity = Entity(index) owner = entity.owner if owner is None: return saved_player = saved_player_manager[owner.index] weapon_classname = PROJECTILE_MAPPING[base_entity.classname] saved_player._nade_thrown(weapon_classname)
def initialize(self, index): """Initialize all hooks waiting for the given entity.""" # There is nothing to do if no hook is waiting if not self: return entity = Entity(index) for hook in tuple(self): # Try initializing the hook if hook.initialize(entity): # If it succeeded, remove the hook from the waiting list self.remove(hook)
def beam( recipients, delay, start, end, model_index, halo_index, start_frame, frame_rate, life, width, end_width, fade_length, amplitude, red, green, blue, alpha, speed, parent=False): """A simple wrapper for _TempEntities.beam_ent_point(). <start> and <end> can be entity indexes or Vector objects. If you set <parent> to True, the beam is parented to the given entity index(es). """ start_entity = -1 start_vector = None end_entity = -1 end_vector = None # Check start point if isinstance(start, int): if parent: start_entity = start else: start_vector = Entity(start).origin else: start_vector = start # Check end point if isinstance(end, int): if parent: end_entity = end else: end_vector = Entity(end).origin else: end_vector = end # Create the effect temp_entities.beam_ent_point( recipients, delay, start_entity, start_vector, end_entity, end_vector, model_index, halo_index, start_frame, frame_rate, life, width, end_width, fade_length, amplitude, red, green, blue, alpha, speed)