ReadOnlySoundPreset <CharacterSound> soundPresetMovement) GetSoundPresets(ICharacter character)
        {
            ReadOnlySoundPreset <CharacterSound> soundPresetCharacter = null;
            ReadOnlySoundPreset <CharacterSound> soundPresetMovement  = null;

            var protoCharacter = character.ProtoCharacter;

            if (protoCharacter is PlayerCharacter)
            {
                // try get sound preset overrides from the character equipment
                foreach (var item in character.SharedGetPlayerContainerEquipment()
                         .Items)
                {
                    switch (item.ProtoItem)
                    {
                    case IProtoItemEquipmentArmor chest:
                        soundPresetCharacter = chest.SoundPresetMovementOverride;
                        break;

                    case IProtoItemEquipmentHead head:
                        soundPresetMovement = head.SoundPresetCharacterOverride;
                        break;
                    }
                }
            }

            soundPresetCharacter ??= this.SoundPresetCharacter;
            soundPresetMovement ??= this.SoundPresetMovement;

            return(soundPresetCharacter, soundPresetMovement);
        }
 protected sealed override void PrepareProtoItemEquipment()
 {
     base.PrepareProtoItemEquipment();
     this.SoundPresetMovementOverride  = this.PrepareSoundPresetMovementOverride();
     this.SoundPresetFootstepsOverride = this.PrepareSoundPresetFootstepsOverride();
     this.PrepareProtoItemEquipmentChest();
 }
        protected void VerifySoundPreset <TSoundKey>(ReadOnlySoundPreset <TSoundKey> preset)
            where TSoundKey : struct, Enum
        {
            if (preset.SoundsCount > 0)
            {
                return;
            }

            Logger.Error(
                $"No {typeof(TSoundKey).Name} sounds found for skeleton {this.ShortId}. Sounds should be located at \"{ContentPaths.Sounds + this.SoundsFolderPath}\" (determined by property DefaultSoundsFolder of this class).");
        }
Beispiel #4
0
        protected sealed override void PrepareProto()
        {
            base.PrepareProto();
            this.SoundPresetObject = this.PrepareSoundPresetObject();
            this.PrepareProtoWorldObject();

            var type = this.GetType();

            this.IsInteractableObject = type.HasOverride(nameof(ClientInteractStart), isPublic: false) ||
                                        type.HasOverride(nameof(ClientInteractFinish), isPublic: false);
        }
Beispiel #5
0
        /// <summary>
        /// Prepares prototype - invoked after all scripts are loaded, so you can access other scripting
        /// entities by using <see cref="ProtoEntity.GetProtoEntity{TProtoEntity}" /> and
        /// <see cref="ProtoEntity.FindProtoEntities{TProtoEntity}" /> methods.
        /// </summary>
        protected sealed override void PrepareProto()
        {
            base.PrepareProto();

            var type = this.GetType();

            this.isUsableItem = type.HasOverride(nameof(ClientItemUseStart), isPublic: false) ||
                                type.HasOverride(nameof(ClientItemUseFinish), isPublic: false);

            this.SoundPresetItem = this.PrepareSoundPresetItem();

            this.PrepareProtoItem();
        }
Beispiel #6
0
        /// <summary>
        /// Prepares prototype - invoked after all scripts are loaded, so you can access other scripting
        /// entities by using <see cref="ProtoEntity.GetProtoEntity{TProtoEntity}" /> and
        /// <see cref="ProtoEntity.FindProtoEntities{TProtoEntity}" /> methods.
        /// </summary>
        protected sealed override void PrepareProto()
        {
            base.PrepareProto();

            var type = this.GetType();

            this.isUsableItem = type.HasOverride(nameof(ClientItemUseStart), isPublic: false) ||
                                type.HasOverride(nameof(ClientItemUseFinish), isPublic: false);

            this.SoundPresetItem = this.PrepareSoundPresetItem();

            var hints = new List <string>();

            this.PrepareHints(hints);
            this.DescriptionHints = hints;

            this.PrepareProtoItem();
        }
Beispiel #7
0
        /// <summary>
        /// Prepares prototype - invoked after all scripts are loaded, so you can access other scripting
        /// entities by using <see cref="ProtoEntity.GetProtoEntity{TProtoEntity}" /> and
        /// <see cref="ProtoEntity.FindProtoEntities{TProtoEntity}" /> methods.
        /// </summary>
        protected sealed override void PrepareProto()
        {
            var icon = this.PrepareIcon();

            if (icon is ITextureAtlasResource iconAtlas &&
                icon is not ITextureAtlasChunkResource)
            {
                // use the first chunk of the atlas texture
                icon = iconAtlas.Chunk(0, 0);
            }

            this.Icon = icon;

            var type = this.GetType();

            this.isUsableItem = type.HasOverride(nameof(ClientItemUseStart), isPublic: false) ||
                                type.HasOverride(nameof(ClientItemUseFinish), isPublic: false);

            this.SoundPresetItem = this.PrepareSoundPresetItem();

            this.PrepareProtoItem();
        }
Beispiel #8
0
        /// <summary>
        /// Prepares prototype - invoked after all scripts are loaded, so you can access other scripting
        /// entities by using <see cref="ProtoEntity.GetProtoEntity{TProtoEntity}" /> and
        /// <see cref="ProtoEntity.FindProtoEntities{TProtoEntity}" /> methods.
        /// </summary>
        protected sealed override void PrepareProto()
        {
            if (this.IsSkin)
            {
                if (!this.GetType().Name.StartsWith("Skin", StringComparison.Ordinal))
                {
                    throw new Exception(this.Id + " is a skin - its class name must start with \"Skin\"");
                }

                this.SkinId = SkinBinding.BindSkin(this);
            }

            // Please note: the icon is required on the server side as well e.g. to use for console commands
            // autocomplete (as it should not provide items that don't have icons).
            var icon = this.PrepareIcon();

            if (icon is ITextureAtlasResource iconAtlas
                and not ITextureAtlasChunkResource)
            {
                // use the first chunk of the atlas texture
                icon = iconAtlas.Chunk(0, 0);
            }

            this.Icon = icon;

            var type = this.GetType();

            this.isUsableItem = type.HasOverride(nameof(ClientItemUseStart), isPublic: false) ||
                                type.HasOverride(nameof(ClientItemUseFinish), isPublic: false);

            this.SoundPresetItem = this.PrepareSoundPresetItem();

            ((IProtoItemWithSkinData)this.BaseProtoItem)?.PrepareProtoItemLinkSkin(this);

            this.PrepareProtoItem();
        }
 protected sealed override ReadOnlySoundPreset <ItemSound> PrepareSoundPresetItem()
 {
     this.ObjectInteractionSoundsPreset = this.PrepareSoundPresetToolbox();
     return(ItemsSoundPresets.ItemGeneric);
 }
        private static void SkeletonOnAnimationEventFootstep(
            ICharacter character,
            IComponentSkeleton skeleton,
            SkeletonEventData e)
        {
            if (e.EventName != "Footstep")
            {
                return;
            }

            // play footstep sound
            GroundSoundMaterial groundSoundMaterial;

            var tile = character.Tile;

            // find the latest proto ground object with sound
            IProtoObjectWithGroundSoundMaterial protoGroundObject = null;

            foreach (var worldObject in tile.StaticObjects)
            {
                if (worldObject.ProtoStaticWorldObject is IProtoObjectWithGroundSoundMaterial proto)
                {
                    protoGroundObject = proto;
                }
            }

            if (protoGroundObject is not null)
            {
                // get sound material of proto ground object
                groundSoundMaterial = protoGroundObject.SharedGetGroundSoundMaterial();
            }
            else
            {
                // get sound material of proto tile
                var protoTile = (ProtoTile)tile.ProtoTile;
                groundSoundMaterial = protoTile.GroundSoundMaterial;
            }

            ReadOnlySoundPreset <GroundSoundMaterial> soundPresetMovement = null;
            var protoCharacter = character.ProtoCharacter;

            if (protoCharacter is PlayerCharacter &&
                PlayerCharacter.GetPublicState(character).CurrentVehicle is null)
            {
                // try get movement sound preset override
                foreach (var item in character.SharedGetPlayerContainerEquipment().Items)
                {
                    if (item.ProtoItem is IProtoItemEquipmentArmor protoItemEquipmentArmor)
                    {
                        soundPresetMovement = protoItemEquipmentArmor.SoundPresetFootstepsOverride;
                        break;
                    }
                }
            }

            var protoSkeleton = (ProtoCharacterSkeleton)protoCharacter.ClientGetCurrentProtoSkeleton(character);

            if (soundPresetMovement is null)
            {
                // movement sound preset is not overridden - use from this skeleton
                soundPresetMovement = protoSkeleton.SoundPresetFootsteps;
            }

            // use some pitch variation
            var pitch = RandomHelper.Range(protoSkeleton.FootstepsPitchVariationRange.From,
                                           protoSkeleton.FootstepsPitchVariationRange.To);

            var volume = protoSkeleton.VolumeFootsteps;

            // apply some volume variation
            volume *= RandomHelper.Range(protoSkeleton.FootstepsVolumeVariationRange.From,
                                         protoSkeleton.FootstepsVolumeVariationRange.To);
            // apply constant volume multiplier
            volume *= SoundConstants.VolumeFootstepsMultiplier;

            soundPresetMovement.PlaySound(
                groundSoundMaterial,
                character,
                volume: (float)volume,
                pitch: (float)pitch);
        }
 protected sealed override void PrepareProtoItemEquipment()
 {
     base.PrepareProtoItemEquipment();
     this.SoundPresetCharacterOverride = this.PrepareSoundPresetCharacterOverride();
     this.PrepareProtoItemEquipmentHead();
 }