Ejemplo n.º 1
0
        /// <summary>
        /// Update is called by owning task once per frame as part of quest machine tick.
        /// Update is only called by task if active conditions are met.
        /// Perform any updates required here.
        /// </summary>
        /// <param name="caller">Task hosting this action.</param>
        public override void Update(Task caller)
        {
            var gameSeconds = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToSeconds();

            // Attempt to reload clip if not available
            // This can happen if player loads a game after action created
            if (clip == null && soundIndex != 0)
            {
                clip = DaggerfallUnity.Instance.SoundReader.GetAudioClip(soundIndex);
            }

            if (lastTimePlayed + interval <= gameSeconds)
            {
                timesPlayed++;
                if (count == 0 || (count > 0 && timesPlayed <= count))
                {
                    DaggerfallAudioSource source = QuestMachine.Instance.GetComponent <DaggerfallAudioSource>();
                    if (source != null && !source.IsPlaying())
                    {
                        source.PlayOneShot(soundIndex, 0, DaggerfallUnity.Settings.SoundVolume);
                        lastTimePlayed = gameSeconds;
                    }
                }
            }
            // Unlike message posts, the play sound command performs until task is cleared
            // The exception are sounds played X times, these will stop and start again on load or action rearming
        }
Ejemplo n.º 2
0
        private void Update()
        {
            // Exit if no caster
            if (!caster)
            {
                return;
            }

            // Execute based on target type
            if (!missileReleased)
            {
                switch (targetType)
                {
                case TargetTypes.ByTouch:
                    DoTouch();
                    break;

                case TargetTypes.SingleTargetAtRange:
                case TargetTypes.AreaAtRange:
                    DoMissile();
                    break;

                case TargetTypes.AreaAroundCaster:
                    DoAreaOfEffect(caster.transform.position, true);
                    break;

                default:
                    return;
                }
            }

            // Handle missile lifespan pre and post-impact
            if (!impactDetected)
            {
                // Transform missile along direction vector
                transform.position += (direction * MovementSpeed) * Time.deltaTime;

                // Update lifespan and self-destruct if expired (e.g. spell fired straight up and will never hit anything)
                lifespan += Time.deltaTime;
                if (lifespan > LifespanInSeconds)
                {
                    Destroy(gameObject);
                }
            }
            else
            {
                // Notify listeners work is done and automatically assign impact
                if (!impactAssigned)
                {
                    PlayImpactSound();
                    RaiseOnCompleteEvent();
                    AssignPayloadToTargets();
                    impactAssigned = true;

                    // Handle arrow
                    if (isArrow)
                    {
                        // Disable 3d arrow
                        goModel.gameObject.SetActive(false);

                        if (caster != GameManager.Instance.PlayerEntityBehaviour)
                        {
                            DaggerfallEntityBehaviour entityBehaviour = null;
                            if (arrowHit.transform)
                            {
                                entityBehaviour = arrowHit.transform.GetComponent <DaggerfallEntityBehaviour>();
                            }
                            if (entityBehaviour == caster.GetComponent <EnemySenses>().Target)
                            {
                                EnemyAttack attack = caster.GetComponent <EnemyAttack>();
                                if (attack)
                                {
                                    attack.BowDamage(goModel.transform.forward);
                                }
                            }
                        }
                        else
                        {
                            GameManager.Instance.WeaponManager.WeaponDamage(arrowHit, goModel.transform.forward, true);
                        }
                    }
                }

                // Track post impact lifespan and allow impact clip to finish playing
                postImpactLifespan += Time.deltaTime;
                if (postImpactLifespan > PostImpactLifespanInSeconds)
                {
                    myLight.enabled = false;
                    if (ImpactSound != SoundClips.None && !audioSource.IsPlaying())
                    {
                        Destroy(gameObject);
                    }
                }
            }

            // Update light
            UpdateLight();
        }
Ejemplo n.º 3
0
        private void Update()
        {
            // Exit if no caster
            if (!caster)
            {
                return;
            }

            // Execute based on target type
            if (!missileReleased)
            {
                switch (targetType)
                {
                case TargetTypes.ByTouch:
                    DoTouch();
                    break;

                case TargetTypes.SingleTargetAtRange:
                case TargetTypes.AreaAtRange:
                    DoMissile();
                    break;

                case TargetTypes.AreaAroundCaster:
                    DoAreaOfEffect(caster.transform.position, true);
                    break;

                default:
                    return;
                }
            }

            // Handle missile lifespan pre and post-impact
            if (!impactDetected)
            {
                // Transform missile along direction vector
                transform.position += (direction * MovementSpeed) * Time.deltaTime;

                // Update lifespan and self-destruct if expired (e.g. spell fired straight up and will never hit anything)
                lifespan += Time.deltaTime;
                if (lifespan > LifespanInSeconds)
                {
                    Destroy(gameObject);
                }
            }
            else
            {
                // Notify listeners work is done and automatically assign impact
                if (!impactAssigned)
                {
                    PlayImpactSound();
                    RaiseOnCompleteEvent();
                    AssignPayloadToTargets();
                    impactAssigned = true;
                }

                // Track post impact lifespan and allow impact clip to finish playing
                postImpactLifespan += Time.deltaTime;
                if (postImpactLifespan > PostImpactLifespanInSeconds)
                {
                    myLight.enabled = false;
                    if (ImpactSound != SoundClips.None && !audioSource.IsPlaying())
                    {
                        Destroy(gameObject);
                    }
                }
            }

            // Update light
            UpdateLight();
        }