Ejemplo n.º 1
0
        private static void DespawnIdleVehiclesInPvP()
        {
            if (Api.IsEditor ||
                PveSystem.ServerIsPvE)
            {
                return;
            }

            var allVehicles = Server.World.GetWorldObjectsOfProto <IProtoVehicle>();

            // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
            foreach (IDynamicWorldObject vehicle in allVehicles)
            {
                var publicState = vehicle.GetPublicState <VehiclePublicState>();
                if (publicState.PilotCharacter is not null)
                {
                    continue;
                }

                if (VehicleDespawnSystem.ServerIsVehicleInsideOwnerBase(vehicle))
                {
                    // don't despawn vehicle as it's inside one of its owners base
                    continue;
                }

                VehicleGarageSystem.ServerPutIntoGarage(vehicle);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Barrier (a circle impenetrable area) is present only in PvE to prevent players from rushing
        /// into the boss area before the boss is spawned.
        /// </summary>
        private void ServerCreateBossAreaBarrier(ILogicObject worldEvent)
        {
            var publicState = GetPublicState(worldEvent);

            if (publicState.ServerBarrierPhysicsBody is not null)
            {
                return;
            }

            // create the barrier
            publicState.ServerBarrierPhysicsBody = this.SharedCreateBarrierPhysicsBody(worldEvent);

            var activeEventPosition = publicState.AreaCirclePosition;
            var barrierRadius       = this.AreaBarrierRadius + 1;

            if (barrierRadius > byte.MaxValue)
            {
                Logger.Error(
                    "The boss area circle should never have a radius larger than 255 tiles as it prevents players despawn in PvE: "
                    + worldEvent);
                barrierRadius = byte.MaxValue;
            }

            var barrierRadiusSqr = barrierRadius * barrierRadius;

            // despawn all player characters inside the barrier or very close to it
            using var tempCharacters = Api.Shared.GetTempList <ICharacter>();
            Server.World.GetCharactersInRadius(activeEventPosition,
                                               tempCharacters,
                                               (byte)barrierRadius,
                                               onlyPlayers: true);

            foreach (var character in tempCharacters.AsList())
            {
                CharacterDespawnSystem.DespawnCharacter(character);
            }

            // despawn all vehicles inside the barrier or very close to it
            using var tempListVehicles = Api.Shared.GetTempList <IDynamicWorldObject>();
            foreach (var protoVehicle in Api.FindProtoEntities <IProtoVehicle>())
            {
                tempListVehicles.Clear();
                protoVehicle.GetAllGameObjects(tempListVehicles.AsList());
                foreach (var vehicle in tempListVehicles.AsList())
                {
                    if (vehicle.TilePosition.TileSqrDistanceTo(activeEventPosition)
                        <= barrierRadiusSqr)
                    {
                        VehicleGarageSystem.ServerPutIntoGarage(vehicle);
                    }
                }
            }

            // Please note: NPC characters that are stuck inside the area are pushed outside it by the physics engine
        }