Example #1
0
    private void OnSpawnPlayer(PlayerSpawningEvent args)
    {
        // TODO: Cache all this if it ends up important.
        var points = EntityQuery <SpawnPointComponent>().ToList();

        _random.Shuffle(points);
        foreach (var spawnPoint in points)
        {
            var xform = Transform(spawnPoint.Owner);
            if (args.Station != null && _stationSystem.GetOwningStation(spawnPoint.Owner, xform) != args.Station)
            {
                continue;
            }

            if (_gameTicker.RunLevel == GameRunLevel.InRound && spawnPoint.SpawnType == SpawnPointType.LateJoin)
            {
                args.SpawnResult = _stationSpawning.SpawnPlayerMob(
                    xform.Coordinates,
                    args.Job,
                    args.HumanoidCharacterProfile,
                    args.Station);

                return;
            }
            else if (_gameTicker.RunLevel != GameRunLevel.InRound && spawnPoint.SpawnType == SpawnPointType.Job && (args.Job == null || spawnPoint.Job?.ID == args.Job.Prototype.ID))
            {
                args.SpawnResult = _stationSpawning.SpawnPlayerMob(
                    xform.Coordinates,
                    args.Job,
                    args.HumanoidCharacterProfile,
                    args.Station);

                return;
            }
        }

        // Ok we've still not returned, but we need to put them /somewhere/.
        // TODO: Refactor gameticker spawning code so we don't have to do this!
        foreach (var spawnPoint in points)
        {
            var xform = Transform(spawnPoint.Owner);
            args.SpawnResult = _stationSpawning.SpawnPlayerMob(
                xform.Coordinates,
                args.Job,
                args.HumanoidCharacterProfile,
                args.Station);

            return;
        }

        Logger.ErrorS("spawning", "No spawn points were available!");
    }
Example #2
0
    /// <summary>
    /// Attempts to spawn a player character onto the given station.
    /// </summary>
    /// <param name="station">Station to spawn onto.</param>
    /// <param name="job">The job to assign, if any.</param>
    /// <param name="profile">The character profile to use, if any.</param>
    /// <param name="stationSpawning">Resolve pattern, the station spawning component for the station.</param>
    /// <returns>The resulting player character, if any.</returns>
    /// <exception cref="ArgumentException">Thrown when the given station is not a station.</exception>
    /// <remarks>
    /// This only spawns the character, and does none of the mind-related setup you'd need for it to be playable.
    /// </remarks>
    public EntityUid?SpawnPlayerCharacterOnStation(EntityUid?station, Job?job, HumanoidCharacterProfile?profile, StationSpawningComponent?stationSpawning = null)
    {
        if (station != null && !Resolve(station.Value, ref stationSpawning))
        {
            throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));
        }

        var ev = new PlayerSpawningEvent(job, profile, station);

        RaiseLocalEvent(ev);

        DebugTools.Assert(ev.SpawnResult is { Valid: true } or null);

        return(ev.SpawnResult);
    }