Пример #1
0
        // "Graveyard" is a technical area in the bottom right corner of the map.
        private static void TeleportDeadPlayerCharacterToGraveyard(ICharacter character)
        {
            if (character.IsNpc)
            {
                // only player characters are teleported to graveyard
                return;
            }

            var publicState = character.GetPublicState <ICharacterPublicState>();

            if (!publicState.IsDead)
            {
                // player has been respawned
                return;
            }

            VehicleSystem.ServerCharacterExitCurrentVehicle(character, force: true);

            // disable the visual scope so the player cannot not see anyone and nobody could see the player
            Api.Server.Characters.SetViewScopeMode(character, isEnabled: false);
            var graveyardPosition = ServerGetGraveyardPosition();

            if (character.TilePosition != graveyardPosition)
            {
                ServerWorld.SetPosition(character, (Vector2D)graveyardPosition);
            }

            CharacterRespawnSystem.ServerRemoveInvalidStatusEffects(character);
        }
        public static void PlacePlayer(ICharacter character, bool isRespawn)
        {
            // please ensure that we don't touch any private properties as they're not initialized at the first spawn request
            // (player placed in the world and only then it's initialized)
            var           random        = Api.Random;
            Vector2Ushort?spawnPosition = null;

            var spawnZone = protoSpawnZone.ServerZoneInstance;

            if (!spawnZone.IsEmpty)
            {
                // TODO: this could be slow and might require distributing across the multiple frames
                if (isRespawn)
                {
                    spawnPosition = TryFindZoneSpawnPosition(character, spawnZone, random, isRespawn: true);
                }

                if (!spawnPosition.HasValue)
                {
                    spawnPosition = TryFindZoneSpawnPosition(character, spawnZone, random, isRespawn: false);
                }
            }

            if (!spawnPosition.HasValue)
            {
                // fallback - spawn in the center of the world
                var worldBounds = worldService.WorldBounds;
                var offset      = worldBounds.Offset;
                var size        = worldBounds.Size;
                spawnPosition = new Vector2Ushort((ushort)(offset.X + size.X / 2),
                                                  (ushort)(offset.Y + size.Y / 2));
            }

            worldService.SetPosition(character, spawnPosition.Value.ToVector2D());
        }
Пример #3
0
        private static void ServerTeleport(ICharacter player, Vector2D toPosition)
        {
            if (player.PhysicsBody.HasAnyShapeCollidingWithGroup(CollisionGroup.GetDefault()))
            {
                // perform position validity check
                toPosition = FindClosestValidPosition(toPosition);
            }
            else
            {
                // This is a character without the physical collider (probably a spectator).
                // It could be teleported anywhere.
            }

            ServerWorldService.SetPosition(player, toPosition);
        }