Example #1
0
        void Update()
        {
            if (GameManager.Instance.DisableAI)
            {
                return;
            }

            // If a melee attack has reached the damage frame we can run a melee attempt
            if (mobile.DoMeleeDamage)
            {
                MeleeDamage();
                mobile.DoMeleeDamage = false;
            }
            // If a bow attack has reached the shoot frame we can shoot an arrow
            else if (mobile.ShootArrow)
            {
                ShootBow();
                mobile.ShootArrow = false;

                DaggerfallAudioSource dfAudioSource = GetComponent <DaggerfallAudioSource>();
                if (dfAudioSource)
                {
                    dfAudioSource.PlayOneShot((int)SoundClips.ArrowShoot, 1, 1.0f);
                }
            }

            // Countdown to next melee attack
            MeleeTimer -= Time.deltaTime;

            if (MeleeTimer < 0)
            {
                MeleeTimer = 0;
            }

            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;
            int         speed  = entity.Stats.LiveSpeed;

            // Note: Speed comparison here is reversed from classic. Classic's way makes fewer attack
            // attempts at higher speeds, so it seems backwards.
            if (GameManager.ClassicUpdate && (DFRandom.rand() % speed >= (speed >> 3) + 6 && MeleeTimer == 0))
            {
                if (!MeleeAnimation())
                {
                    return;
                }

                ResetMeleeTimer();
            }
        }
Example #2
0
        //saves the currently selected outfit. It grabs the seralized equip table and the
        //current outfitName (Which was just assigned by the player), and stores each into
        //their dictionaries using the same public index integer to ensure matches.
        void saveCurrentOutfit()
        {
            dfAudioSource.PlayOneShot(417, 1, .4f);
            //looks to see if outfit already exists using dict key.
            //if it finds it, updates that dictionary value.
            //if not, adds it to the list.
            if (outfitDictSerialized.ContainsKey(index))
            {
                outfitDictSerialized[index] = currentEquippedSerialized;
                outfitDictName[index]       = outfitName;
            }
            else
            {
                outfitDictSerialized.Add(index, currentEquippedSerialized);
                outfitDictName.Add(index, outfitName);
            }

            outfitName    = outfitDictName[index];
            currentOutfit = outfitName;
            selectedIndex = index;
        }
        void Update()
        {
            // Change sound presets
            if (Presets != lastPresets)
            {
                // Clear settings
                lastPresets  = Presets;
                rainLoop     = null;
                cricketsLoop = null;

                // Stop playing any loops
                if (dfAudioSource.AudioSource.isPlaying)
                {
                    dfAudioSource.AudioSource.Stop();
                    dfAudioSource.AudioSource.clip = null;
                    dfAudioSource.AudioSource.loop = false;
                }

                ApplyPresets();
                StartWaiting();
            }

            // Update sound volume
            dfAudioSource.AudioSource.volume = DaggerfallUnity.Settings.SoundVolume;

            // Start rain loop if not running
            if ((Presets == AmbientSoundPresets.Rain || Presets == AmbientSoundPresets.Storm) && rainLoop == null)
            {
                rainLoop = dfAudioSource.GetAudioClip((int)SoundClips.AmbientRaining);
                dfAudioSource.AudioSource.clip         = rainLoop;
                dfAudioSource.AudioSource.loop         = true;
                dfAudioSource.AudioSource.spatialBlend = 0;
                dfAudioSource.AudioSource.Play();
            }

            // Start crickets loop if not running
            if ((Presets == AmbientSoundPresets.ClearNight) && cricketsLoop == null)
            {
                cricketsLoop = dfAudioSource.GetAudioClip((int)SoundClips.AmbientCrickets);
                dfAudioSource.AudioSource.clip         = cricketsLoop;
                dfAudioSource.AudioSource.loop         = true;
                dfAudioSource.AudioSource.spatialBlend = 0;
                dfAudioSource.AudioSource.Play();
            }

            // Tick counters
            waitCounter      += Time.deltaTime;
            waterWaitCounter += Time.deltaTime;
            if (waitCounter > waitTime)
            {
                PlayEffects();
                StartWaiting();
            }

            // Play water sound effects. Timing based on classic.
            if (waterWaitCounter > Entity.PlayerEntity.ClassicUpdateInterval)
            {
                if (playerEnterExit && playerEnterExit.blockWaterLevel != 10000)
                {
                    // Chance to play gentle water sound at water surface
                    if (DFRandom.rand() < 50)
                    {
                        Vector3 waterSoundPosition = playerBehaviour.transform.position;
                        waterSoundPosition.y             = playerEnterExit.blockWaterLevel * -1 * MeshReader.GlobalScale;
                        waterSoundPosition.x            += Random.Range(-3, 3);
                        waterSoundPosition.y            += Random.Range(-3, 3);
                        dfAudioSource.transform.position = waterSoundPosition;
                        dfAudioSource.PlayOneShot((int)SoundClips.WaterGentle, 1, 3f);
                    }

                    // Chance to play water bubbles sound if player is underwater
                    if (playerEnterExit.IsPlayerSubmerged && DFRandom.rand() < 100)
                    {
                        dfAudioSource.PlayOneShot((int)SoundClips.AmbientWaterBubbles, 0);
                    }
                }
                waterWaitCounter = 0;
            }
        }