コード例 #1
0
def wcs_teleport_command(command_info, player:convert_userid_to_player, x:float, y:float, z:float):
    if player is None:
        return

    location = Vector(x, y, z)
    origin = player.origin
    angles = QAngle(*player.get_property_vector('m_angAbsRotation'))

    forward = Vector()
    right = Vector()
    up = Vector()
    angles.get_angle_vectors(forward, right, up)

    forward.normalize()
    forward *= 10

    playerinfo = player.playerinfo
    mins, maxs = playerinfo.mins, playerinfo.maxs
    players = TraceFilterSimple(PlayerIter())

    for _ in range(100):
        ray = Ray(location, location, mins, maxs)
        trace = GameTrace()
        engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID, players, trace)

        if not trace.did_hit():
            player.teleport(origin=location)
            break

        location -= forward

        if location.get_distance(origin) <= 10.0:
            break
コード例 #2
0
    def is_in_solid(
            self, mask=ContentMasks.ALL, generator=None):
        """Return whether or not the entity is in solid.

        :param ContentMasks mask:
            Contents the ray can possibly collide with.
        :param generator:
            A callable that returns an iterable which contains
            :class:`BaseEntity` instances that are ignored by the ray.
        :rtype: bool
        """
        # Get the entity's origin
        origin = self.origin

        # Get a Ray object of the entity physic box
        ray = Ray(origin, origin, self.mins, self.maxs)

        # Get a new GameTrace instance
        trace = GameTrace()

        # Do the trace
        if generator is None:

            # No need to trace against anything but the world if we are going
            # to filter out everything regardless.
            engine_trace.clip_ray_to_entity(
                ray, mask, BaseEntity(WORLD_ENTITY_INDEX), trace
            )
        else:
            engine_trace.trace_ray(ray, mask, TraceFilterSimple(
                generator()), trace)

        # Return whether or not the trace did hit
        return trace.did_hit()
コード例 #3
0
    def _on_player_ultimate(self, player, **kwargs):
        if self.level == 0:
            return

        _cooldown = self.cooldowns['ultimate']
        if _cooldown <= 0:
            origin = player.eye_location
            view_vector = player.view_vector
            view_trace = self._get_trace(origin, origin + view_vector * 10000,
                                         ContentMasks.ALL, player, GameTrace())
            if view_trace.did_hit_world():
                wall = view_trace.end_position

            if origin.get_distance(wall) > 200:
                send_wcs_saytext_by_index(self._msg_f, player.index)
                return

            teleport_vector = None

            for i in range(1, 4):
                tmp_vector = wall + view_vector * (100 * i)
                tmp_trace = self._get_trace(tmp_vector, wall, ContentMasks.ALL,
                                            player, GameTrace())
                if tmp_trace.did_hit_world():
                    teleport_vector = tmp_trace.end_position + view_vector * 80
                    break

            if not teleport_vector:
                send_wcs_saytext_by_index(self._msg_f2, player.index)
                return

            teleport_vector.z -= 40

            safety_vector1 = safety_vector2 = teleport_vector
            safety_vector1.z += 80
            safety_vector1.x += 40
            safety_vector1.y -= 40
            safety_vector2.x -= 40
            safety_vector2.y += 40

            safety = self._get_trace(safety_vector1, safety_vector2,
                                     ContentMasks.ALL, player, GameTrace())

            if safety.did_hit_world():
                send_wcs_saytext_by_index(self._msg_f3, player.index)
                return

            if engine_trace.is_point_outside_of_world(teleport_vector):
                send_wcs_saytext_by_index(self._msg_f4, player.index)
                return

            player.teleport(teleport_vector, None, None)
            teleport_sound.play(player.index)
            self.cooldowns['ultimate'] = 10
        else:
            send_wcs_saytext_by_index(self._msg_c.format(time=_cooldown),
                                      player.index)
コード例 #4
0
ファイル: commands.py プロジェクト: oblivion1234/WCS
def get_wall_between_command(command_info, var:ConVar, x:float, y:float, z:float, x2:float, y2:float, z2:float):
    vector = Vector(x, y, z)
    vector2 = Vector(x, y, z)

    trace = GameTrace()
    ray = Ray(vector, vector2)

    engine_trace.trace_ray(ray, ContentMasks.ALL, None, trace)

    var.set_int(trace.did_hit_world())
コード例 #5
0
ファイル: commands.py プロジェクト: AlexxDone/WCS_GO
def get_wall_between(command):
    var = str(command[1])
    user_one = int(command[2])
    user_two = int(command[3])
    origin_vector = Player.from_userid(user_one).origin
    direction_vector = Player.from_userid(user_two).origin
    trace = GameTrace()
    engine_trace.trace_ray(Ray(origin_vector, direction_vector),
                           ContentMasks.ALL, None, trace)
    ConVar(var).set_int(trace.did_hit_world())
コード例 #6
0
def wcs_getwallbetween_command(command_info, var:ConVar, player:convert_userid_to_player, target:convert_userid_to_player):
    if player is None or target is None:
        var.set_int(-1)
        return

    vector = player.origin
    vector2 = target.origin

    trace = GameTrace()
    ray = Ray(vector, vector2)

    engine_trace.trace_ray(ray, ContentMasks.ALL, None, trace)

    var.set_int(trace.did_hit_world())
コード例 #7
0
ファイル: ctf.py プロジェクト: KirillMysnik/SP-CTF
    def _find_floor(self, origin):
        if origin is None:
            origin = self.origin

        end_trace_vec = origin + Vector(0, 0, -1) * MAX_TRACE_LENGTH

        trace = GameTrace()
        engine_trace.trace_ray(Ray(origin, end_trace_vec), ContentMasks.ALL,
                               TraceFilterSimple(), trace)

        if not trace.did_hit():
            return None

        return trace.end_position
コード例 #8
0
ファイル: entity.py プロジェクト: dsezen/Source.Python
    def is_in_solid(
            self, mask=ContentMasks.ALL, generator=BaseEntityGenerator):
        """Return whether or not the entity is in solid."""
        # Get a Ray object of the entity physic box
        ray = Ray(self.origin, self.origin, self.mins, self.maxs)

        # Get a new GameTrace instance
        trace = GameTrace()

        # Do the trace
        engine_trace.trace_ray(ray, mask, TraceFilterSimple(
            [entity.index for entity in generator()]), trace)

        # Return whether or not the trace did hit
        return trace.did_hit()
コード例 #9
0
    def is_in_solid(
            self, mask=ContentMasks.ALL, generator=BaseEntityGenerator):
        """Return whether or not the entity is in solid."""
        # Get a Ray object of the entity physic box
        ray = Ray(self.origin, self.origin, self.mins, self.maxs)

        # Get a new GameTrace instance
        trace = GameTrace()

        # Do the trace
        engine_trace.trace_ray(ray, mask, TraceFilterSimple(
            [entity.index for entity in generator()]), trace)

        # Return whether or not the trace did hit
        return trace.did_hit()
コード例 #10
0
    def get_trace_ray(self, mask=ContentMasks.ALL, trace_filter=None):
        """Return the player's current trace data.

        :param ContentMasks mask:
            Will be passed to the trace filter.
        :param TraceFilter trace_filter:
            The trace filter to use. If ``None`` was given
            :class:`engines.trace.TraceFilterSimple` will be used.
        :rtype: GameTrace
        """
        # Get the eye location of the player
        start_vec = self.eye_location

        # Calculate the greatest possible distance
        end_vec = start_vec + self.view_vector * MAX_TRACE_LENGTH

        # Create a new trace object
        trace = GameTrace()

        # Start the trace
        engine_trace.trace_ray(
            Ray(start_vec, end_vec), mask,
            TraceFilterSimple(
                (self, )) if trace_filter is None else trace_filter, trace)

        # Return the trace data
        return trace
コード例 #11
0
ファイル: commands.py プロジェクト: AlexxDone/WCS_GO
def check_space(position, mins, maxs):
    mask = ContentMasks.ALL
    generator = BaseEntityGenerator
    ray = Ray(position, position, mins, maxs)

    trace = GameTrace()
    engine_trace.trace_ray(ray, mask, TraceFilterSimple(generator()), trace)
    return trace
コード例 #12
0
    def validate_teleport(self, player, origin, teleport_vector):
        ## These vectors should create a line diagonally through the player model,
        ## allowing us to see if the teleport is safe.
        trace_vector1 = teleport_vector.copy()
        trace_vector2 = teleport_vector.copy()
        trace_vector1.z += 72
        trace_vector1.x += 26
        trace_vector1.y -= 26
        trace_vector2.x -= 26
        trace_vector2.y += 26

        check1 = self._get_trace(origin, teleport_vector,
                                 ContentMasks.PLAYER_SOLID, player,
                                 GameTrace())

        check2 = self._get_trace(trace_vector1, trace_vector2,
                                 ContentMasks.PLAYER_SOLID, player,
                                 GameTrace())

        return check1, check2
コード例 #13
0
ファイル: commands.py プロジェクト: AlexxDone/WCS_GO
def is_player_stuck(player_index, origin):
    '''Return whether or not the given player is stuck in solid.'''

    # Get the player's PlayerInfo instance...
    player_info = playerinfo_from_index(player_index)

    # Get the player's origin...
    #origin = player_info.origin

    # Get a Ray object based on the player physic box...
    ray = Ray(origin, origin, player_info.mins, player_info.maxs)

    # Get a new GameTrace instance...
    trace = GameTrace()

    # Do the trace...
    engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID,
                           TraceFilterSimple(PlayerIter()), trace)

    # Return whether or not the trace did hit...
    return trace.did_hit()
コード例 #14
0
    def is_in_solid(
            self, mask=ContentMasks.ALL, generator=BaseEntityGenerator):
        """Return whether or not the entity is in solid.

        :param ContentMasks mask:
            Contents the ray can possibly collide with.
        :param generator:
            A callable that returns an iterable which contains
            :class:`BaseEntity` instances that are ignored by the ray.
        :rtype: bool
        """
        # Get a Ray object of the entity physic box
        ray = Ray(self.origin, self.origin, self.mins, self.maxs)

        # Get a new GameTrace instance
        trace = GameTrace()

        # Do the trace
        engine_trace.trace_ray(ray, mask, TraceFilterSimple(
            generator()), trace)

        # Return whether or not the trace did hit
        return trace.did_hit()
コード例 #15
0
ファイル: _base.py プロジェクト: 2389736818/Source.Python
    def is_in_solid(
            self, mask=ContentMasks.ALL, generator=BaseEntityGenerator):
        """Return whether or not the entity is in solid.

        :param ContentMasks mask:
            Contents the ray can possibly collide with.
        :param generator:
            A callable that returns an iterable which contains
            :class:`BaseEntity` instances that are ignored by the ray.
        :rtype: bool
        """
        # Get a Ray object of the entity physic box
        ray = Ray(self.origin, self.origin, self.mins, self.maxs)

        # Get a new GameTrace instance
        trace = GameTrace()

        # Do the trace
        engine_trace.trace_ray(ray, mask, TraceFilterSimple(
            generator()), trace)

        # Return whether or not the trace did hit
        return trace.did_hit()
コード例 #16
0
def on_take_damage_alive_pre(stack_data):
    """Creates a FloatingNumber when a player takes damage."""
    # Get the Player instance of the victim.
    player_v = player_instances[index_from_pointer(stack_data[0])]
    # Get the CTakeDamageInfo instance.
    info = TakeDamageInfo._obj(stack_data[1])
    # Get the index of the entity that caused the damage.
    index_a = info.attacker

    # Did the player take damage from the world?
    if index_a == 0:
        # Are damage numbers disabled for world damage (world_damage set to 0)?
        if not world_damage.get_int():
            return

        number_origin = player_v.get_number_origin()
        unique_data = []

        for player in player_instances.values():
            # There's no need for bots to see the FloatingNumber.
            if player.is_bot():
                continue

            # Is the player not looking at the position where the
            # FloatingNumber is going to spawn?
            if not player.is_in_fov(target=number_origin):
                continue

            distance = number_origin.get_distance(player.origin)
            # Add this player's unique data to the list.
            unique_data.append({
                'angle': player.view_angle,
                'size': 10 + distance * DISTANCE_MULTIPLIER,
                'recipient': player.userid
                })

        # Will no one be able to see this FloatingNumber?
        if not unique_data:
            # Don't bother spawning it.
            return

        FloatingNumber.world_damage(
            origin=number_origin,
            # Since `info.damage` is a float, convert it to an integer before
            # converting it to a string to get rid of the decimal part.
            number=str(int(info.damage)),
            color=WHITE,
            unique_data=unique_data
            )

    # Or from a player?
    else:
        try:
            # Try to get the Player instance of the attacker.
            player_a = player_instances[index_a]
        except ValueError:
            # Damage was caused indirectly (grenade, projectile).
            try:
                # Try to get a Player instance again, but this time using the
                # the owner inthandle of the entity that caused the damage.
                player_a = player_instances.from_inthandle(
                    Entity(info.inflictor).owner_handle)
            except (ValueError, OverflowError):
                # ValueError: not a player.
                # OverflowError: invalid owner inthandle (-1).
                return

        # Is the attacker a bot?
        if player_a.is_bot():
            return

        # Self inflicted damage?
        if player_v is player_a:
            return

        number_origin = player_v.get_number_origin()
        velocity = None

        # Did the bullet go through another entity before hitting the player?
        if info.penetrated and wall_bangs.get_int():
            # Let's check if that entity is the world.
            trace = GameTrace()
            engine_trace.clip_ray_to_entity(
                # Create a Ray() from the attacker's eyes to the hit position.
                Ray(player_a.eye_location, info.position),
                ContentMasks.ALL,
                Entity(WORLD_ENTITY_INDEX),
                trace
            )

            # Is this an actual wall-bang (bullet went through world)?
            if trace.did_hit():
                # Calculate the directional vector from the wall to the player.
                from_wall = trace.start_position - trace.end_position
                # Calculate the offset for the FloatingNumber's new origin.
                origin_offset = 10 + from_wall.length * 0.01
                # Normalize it.
                # Vector(368.52, 40.71, -7.77) -> Vector(0.99, 0.10, -0.02)
                from_wall.normalize()
                # Change the origin of the FloatingNumber so it spawns in front
                # of the wall where the wall-bang took place.
                number_origin = trace.end_position + origin_offset * from_wall

                right, up = Vector(), Vector()
                from_wall.get_vector_vectors(right, up)

                velocity = from_wall * 25 + (
                    right * 35 * player_a.next_direction)
                # If the bullet went through something else (another player)
                # before hitting the wall, adjust how high the FloatingNumber
                # gets pushed.
                velocity.z = 75 * info.penetrated

        distance = number_origin.get_distance(player_a.origin)
        # TODO: Figure out a better way to allow other plugins to change the
        # color of the FloatingNumber. Or hardcode the colors to unused
        # DamageTypes (e.g. AIRBOAT = YELLOW, PHYSGUN = BLUE)?
        color = YELLOW if info.type == DamageTypes.AIRBOAT else WHITE

        FloatingNumber(
            origin=number_origin,
            number=str(int(info.damage)),
            # Change the color if it's a headshot.
            color=RED if player_v.last_hitgroup == 1 else color,
            angle=player_a.view_angle,
            # Increase the size depending on the distance.
            size=10 + distance * DISTANCE_MULTIPLIER,
            recipient=player_a.userid,
            velocity=velocity
        )
コード例 #17
0
 def can_see_location(self, vector):
     "Checks to see if the turret can see the <Vector> provided."
     trace = GameTrace()
     engine_trace.trace_ray(self.get_ray(vector), self.mask,
                            self.trace_filter, trace)
     return not trace.did_hit()
コード例 #18
0
    def create_beam(self):
        if self.prop is None:
            raise RuntimeError("Create prop first")

        end_trace_vec = self.origin + self.normal * MAX_TRACE_LENGTH

        trace = GameTrace()
        engine_trace.trace_ray(
            Ray(self.origin, end_trace_vec),
            ContentMasks.ALL,
            TraceFilterSimple(ignore=(self.prop.index, )),
            trace
        )

        if not trace.did_hit():
            return

        if self.owner.team == teams_by_name['ct']:
            beam_color = Color(100, 100, 255)
        else:
            beam_color = Color(255, 100, 100)

        self.beam_target = Entity.create("env_spark")
        self.beam_target.target_name = "_tripmines_target1_{}".format(self.id)
        self.beam_target.teleport(self.origin, None, None)
        self.beam_target.spawn()

        self.beam = Entity.create("env_beam")
        self.beam.target_name = "_tripmines_beam_{}".format(self.id)
        self.beam.spawn_flags = 1
        self.beam.teleport(trace.end_position, None, None)

        self.beam.set_key_value_float('BoltWidth', 1.0)
        self.beam.set_key_value_int('damage', 0)
        self.beam.set_key_value_float('HDRColorScale', 1.0)
        self.beam.set_key_value_int('life', 0)
        self.beam.set_key_value_string(
            'LightningStart', self.beam.target_name)
        self.beam.set_key_value_string(
            'LightningEnd', self.beam_target.target_name)
        self.beam.set_key_value_int('Radius', 255)
        self.beam.set_key_value_int('renderamt', 100)
        self.beam.set_key_value_color('rendercolor', beam_color)
        self.beam.set_key_value_int('StrikeTime', 1)
        self.beam.set_key_value_string('texture', "sprites/laserbeam.spr")
        self.beam.set_key_value_int('TextureScroll', 35)
        self.beam.set_key_value_int('TouchType', 3)

        self.beam.model = BEAM_MODEL
        self.beam.set_property_vector('m_vecEndPos', self.origin)

        self.beam.spawn()

        self.beam.call_input('TurnOff')
        self.beam.call_input('TurnOn')

        self.activated = True

        if config_manager['activation_sound'] != "":
            Sound(config_manager['activation_sound'],
                  index=self.prop.index,
                  attenuation=Attenuation.STATIC).play()
コード例 #19
0
    def _tick(self):
        now = time()
        players = {
            wcsplayer: player.origin
            for player, wcsplayer in self._filter
        }

        for wcsplayer in list(players.keys()):
            if wcsplayer.player.dead:
                warn(f'Player "{wcsplayer.name}" should NOT be here')

                del players[wcsplayer]

        ignore = TraceFilterSimple(PlayerIter())

        for ward in self.copy():
            if ward._next_tick <= now:
                try:
                    ward.on_tick()
                except:
                    except_hooks.print_exception()

                    try:
                        ward.on_disappear()
                    except:
                        except_hooks.print_exception()

                    self.remove(ward)

                    continue
                else:
                    ward._next_tick = now + ward.tick_interval

                    ward.duration -= 1

                    if not ward.duration:
                        try:
                            ward.on_disappear()
                        except:
                            except_hooks.print_exception()

                        self.remove(ward)

            entities = ward.entities
            team = ward.team_target

            for wcsplayer, origin in players.items():
                if team is None or wcsplayer.player.team == team:
                    trace = GameTrace()
                    ray = Ray(ward.origin, origin)

                    engine_trace.trace_ray(ray, ContentMasks.ALL, ignore,
                                           trace)

                    if ward.has_within(origin) and not trace.did_hit_world():
                        if wcsplayer in entities:
                            if entities[wcsplayer] <= now:
                                entities[
                                    wcsplayer] = now + ward.update_interval

                                try:
                                    ward.on_update(wcsplayer)
                                except:
                                    except_hooks.print_exception()
                        else:
                            entities[wcsplayer] = now + ward.update_interval

                            try:
                                ward.on_enter(wcsplayer)
                            except:
                                except_hooks.print_exception()
                    else:
                        if wcsplayer in entities:
                            del entities[wcsplayer]

                            try:
                                ward.on_exit(wcsplayer)
                            except:
                                except_hooks.print_exception()