示例#1
0
        public DamageSound(Sound sound, Vector2 damageRange, DamageSoundType damageType, string requiredTag = "")
        {
            this.sound       = sound;
            this.damageRange = damageRange;
            this.damageType  = damageType;

            this.requiredTag = requiredTag;
        }
示例#2
0
        public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position, float range = 2000.0f, List <string> tags = null)
        {
            damage = MathHelper.Clamp(damage + Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f);
            var sounds = damageSounds.FindAll(s =>
                                              damage >= s.damageRange.X &&
                                              damage <= s.damageRange.Y &&
                                              s.damageType == damageType &&
                                              (string.IsNullOrEmpty(s.requiredTag) || (tags != null && tags.Contains(s.requiredTag))));

            if (!sounds.Any())
            {
                return;
            }

            int selectedSound = Rand.Int(sounds.Count);

            sounds[selectedSound].sound.Play(1.0f, range, position);
            Debug.WriteLine("playing: " + sounds[selectedSound].sound);
        }
示例#3
0
        public AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
        {
            if (Submarine != null && Submarine.GodMode)
            {
                return(new AttackResult(0.0f, 0.0f));
            }
            if (!prefab.HasBody || prefab.IsPlatform)
            {
                return(new AttackResult(0.0f, 0.0f));
            }

            Vector2 transformedPos = worldPosition;

            if (Submarine != null)
            {
                transformedPos -= Submarine.Position;
            }

            int i = FindSectionIndex(transformedPos);

            if (i == -1)
            {
                return(new AttackResult(0.0f, 0.0f));
            }

            float damageAmount = attack.GetStructureDamage(deltaTime);

            AddDamage(i, damageAmount);

#if CLIENT
            GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f);

            if (playSound && !SectionBodyDisabled(i))
            {
                DamageSoundType damageSoundType = (attack.DamageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash;
                SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, worldPosition);
            }
#endif

            return(new AttackResult(damageAmount, 0.0f));
        }
示例#4
0
        public static IEnumerable <object> Init()
        {
            OverrideMusicType = null;

            XDocument doc = XMLExtensions.TryLoadXml("Content/Sounds/sounds.xml");

            if (doc == null)
            {
                yield return(CoroutineStatus.Failure);
            }

            SoundCount = 16 + doc.Root.Elements().Count();

            startDrone = Sound.Load("Content/Sounds/startDrone.ogg", false);
            startDrone.Play();

            yield return(CoroutineStatus.Running);

            waterAmbiences[0] = Sound.Load("Content/Sounds/Water/WaterAmbience1.ogg", false);
            yield return(CoroutineStatus.Running);

            waterAmbiences[1] = Sound.Load("Content/Sounds/Water/WaterAmbience2.ogg", false);
            yield return(CoroutineStatus.Running);

            flowSounds[0] = Sound.Load("Content/Sounds/Water/FlowSmall.ogg", false);
            yield return(CoroutineStatus.Running);

            flowSounds[1] = Sound.Load("Content/Sounds/Water/FlowMedium.ogg", false);
            yield return(CoroutineStatus.Running);

            flowSounds[2] = Sound.Load("Content/Sounds/Water/FlowLarge.ogg", false);
            yield return(CoroutineStatus.Running);

            for (int i = 0; i < 10; i++)
            {
                SplashSounds[i] = Sound.Load("Content/Sounds/Water/Splash" + (i) + ".ogg", false);
                yield return(CoroutineStatus.Running);
            }

            var xMusic = doc.Root.Elements("music").ToList();

            if (xMusic.Any())
            {
                musicClips = new BackgroundMusic[xMusic.Count];
                int i = 0;
                foreach (XElement element in xMusic)
                {
                    string  file     = element.GetAttributeString("file", "");
                    string  type     = element.GetAttributeString("type", "").ToLowerInvariant();
                    Vector2 priority = element.GetAttributeVector2("priorityrange", new Vector2(0.0f, 100.0f));

                    musicClips[i] = new BackgroundMusic(file, type, priority);

                    yield return(CoroutineStatus.Running);

                    i++;
                }
            }

            List <KeyValuePair <string, Sound> > miscSoundList = new List <KeyValuePair <string, Sound> >();

            damageSounds = new List <DamageSound>();

            foreach (XElement subElement in doc.Root.Elements())
            {
                yield return(CoroutineStatus.Running);

                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "music":
                    continue;

                case "damagesound":
                    Sound damageSound = Sound.Load(subElement.GetAttributeString("file", ""), false);
                    if (damageSound == null)
                    {
                        continue;
                    }

                    DamageSoundType damageSoundType = DamageSoundType.None;
                    Enum.TryParse <DamageSoundType>(subElement.GetAttributeString("damagesoundtype", "None"), false, out damageSoundType);

                    damageSounds.Add(new DamageSound(
                                         damageSound,
                                         subElement.GetAttributeVector2("damagerange", new Vector2(0.0f, 100.0f)),
                                         damageSoundType,
                                         subElement.GetAttributeString("requiredtag", "")));

                    break;

                default:
                    Sound sound = Sound.Load(subElement.GetAttributeString("file", ""), false);
                    if (sound != null)
                    {
                        miscSoundList.Add(new KeyValuePair <string, Sound>(subElement.Name.ToString().ToLowerInvariant(), sound));
                    }

                    break;
                }
            }

            miscSounds = miscSoundList.ToLookup(kvp => kvp.Key, kvp => kvp.Value);

            Initialized = true;

            yield return(CoroutineStatus.Success);
        }
示例#5
0
        public static void PlayDamageSound(DamageSoundType damageType, float damage, PhysicsBody body)
        {
            Vector2 bodyPosition = body.DrawPosition;

            PlayDamageSound(damageType, damage, bodyPosition, 800.0f);
        }
示例#6
0
        public AttackResult AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound)
        {
            bool  hitArmor        = false;
            float totalArmorValue = 0.0f;

            if (armorValue > 0.0f && SectorHit(armorSector, position))
            {
                hitArmor         = true;
                totalArmorValue += armorValue;
            }

            foreach (WearableSprite wearable in wearingItems)
            {
                if (wearable.WearableComponent.ArmorValue > 0.0f &&
                    SectorHit(wearable.WearableComponent.ArmorSectorLimits, position))
                {
                    hitArmor         = true;
                    totalArmorValue += wearable.WearableComponent.ArmorValue;
                }
            }

            if (hitArmor)
            {
                totalArmorValue = Math.Max(totalArmorValue, 0.0f);

                amount         = Math.Max(0.0f, amount - totalArmorValue);
                bleedingAmount = Math.Max(0.0f, bleedingAmount - totalArmorValue);
            }

#if CLIENT
            if (playSound)
            {
                DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;
                if (hitArmor)
                {
                    damageSoundType = DamageSoundType.LimbArmor;
                }

                SoundPlayer.PlayDamageSound(damageSoundType, amount, position);
            }

            float bloodParticleAmount = hitArmor || bleedingAmount <= 0.0f ? 0 : (int)Math.Min(amount / 5, 10);
            float bloodParticleSize   = MathHelper.Clamp(amount / 50.0f, 0.1f, 1.0f);

            for (int i = 0; i < bloodParticleAmount; i++)
            {
                var blood = GameMain.ParticleManager.CreateParticle(inWater ? "waterblood" : "blood", WorldPosition, Vector2.Zero, 0.0f, character.AnimController.CurrentHull);
                if (blood != null)
                {
                    blood.Size *= bloodParticleSize;
                }
            }

            if (bloodParticleAmount > 0 && character.CurrentHull != null)
            {
                character.CurrentHull.AddDecal("blood", WorldPosition, MathHelper.Clamp(bloodParticleSize, 0.5f, 1.0f));
            }
#endif

            damage += Math.Max(amount, bleedingAmount) / character.MaxHealth * 100.0f;

            return(new AttackResult(amount, bleedingAmount, hitArmor));
        }
示例#7
0
        public AttackResult AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound)
        {
            DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;

            bool  hitArmor        = false;
            float totalArmorValue = 0.0f;

            if (armorValue > 0.0f && SectorHit(armorSector, position))
            {
                hitArmor         = true;
                totalArmorValue += armorValue;
            }

            foreach (WearableSprite wearable in wearingItems)
            {
                if (wearable.WearableComponent.ArmorValue > 0.0f &&
                    SectorHit(wearable.WearableComponent.ArmorSectorLimits, position))
                {
                    hitArmor         = true;
                    totalArmorValue += wearable.WearableComponent.ArmorValue;
                }
            }


            if (hitArmor)
            {
                totalArmorValue = Math.Max(totalArmorValue, 0.0f);

                damageSoundType = DamageSoundType.LimbArmor;
                amount          = Math.Max(0.0f, amount - totalArmorValue);
                bleedingAmount  = Math.Max(0.0f, bleedingAmount - totalArmorValue);
            }

            if (playSound)
            {
                SoundPlayer.PlayDamageSound(damageSoundType, amount, position);
            }

            //Bleeding += bleedingAmount;
            //Damage += amount;

            float bloodAmount = hitArmor || bleedingAmount <= 0.0f ? 0 : (int)Math.Min((int)(amount * 2.0f), 20);

            for (int i = 0; i < bloodAmount; i++)
            {
                Vector2 particleVel = SimPosition - position;
                if (particleVel != Vector2.Zero)
                {
                    particleVel = Vector2.Normalize(particleVel);
                }

                GameMain.ParticleManager.CreateParticle("blood",
                                                        WorldPosition,
                                                        particleVel * Rand.Range(100.0f, 300.0f), 0.0f, character.AnimController.CurrentHull);
            }

            for (int i = 0; i < bloodAmount / 2; i++)
            {
                GameMain.ParticleManager.CreateParticle("waterblood", WorldPosition, Vector2.Zero, 0.0f, character.AnimController.CurrentHull);
            }

            damage += Math.Max(amount, bleedingAmount) / character.MaxHealth * 100.0f;


            return(new AttackResult(amount, bleedingAmount, hitArmor));
        }