Exemple #1
0
        /// <summary>
        /// Called when the reactor is first activated
        /// </summary>
        /// <returns>Determines if other reactors should process.</returns>
        public override bool Activate()
        {
            base.Activate();
            CombatMessage    combatMessage = (CombatMessage)mMessage;
            IDamageSource    damageSource  = (IDamageSource)combatMessage.Weapon;
            NeoFPSWeaponCore weapon        = (NeoFPSWeaponCore)combatMessage.Weapon;

            mDamageHandler.AddDamage(combatMessage.Damage, damageSource);

            // Get character kicker
            var character = mOwner.GetComponent <NeoFPS.ICharacter>();

            if (character != null)
            {
                var kicker = character.headTransformHandler.GetComponent <NeoFPS.AdditiveKicker>();
                if (kicker != null)
                {
                    // Kick the camera position & rotation
                    float kickDuration = 0.25f;
                    float kickRotation = 5f;
                    kicker.KickPosition(combatMessage.HitDirection * combatMessage.ImpactPower, kickDuration);
                    kicker.KickRotation(Quaternion.AngleAxis(kickRotation, Vector3.Cross(combatMessage.HitDirection, Vector3.up)), kickDuration);
                }
            }

            //Debug.Log(damageMessage.Sender + " hit for " + ((DamageMessage)mMessage).Damage + " on " + mOwner);
            Deactivate();
            return(true);
        }
        /// <summary>
        /// Called when the effect collides with something. This will
        /// spawn the collision effects, impart damage and destroy the
        /// the attached object (if required).
        /// </summary>
        /// <param name="hit">The raycast that registered the hit.</param>
        void OnCollision(RaycastHit hit)
        {
            for (int i = 0; i < collisionEffects.Length; i++)
            {
                MagicEffect instance = Instantiate(collisionEffects[i], hit.point + hit.normal, new Quaternion());
                instance.transform.LookAt(hit.point + hit.normal + hit.normal);

                IDamageHandler damageHandler = hit.collider.GetComponent <IDamageHandler>();
                if (damageHandler != null)
                {
                    damageHandler.AddDamage(damageAmount, hit, this);
                }

                IImpactHandler impactHandler = hit.collider.GetComponent <IImpactHandler>();
                if (impactHandler != null)
                {
                    impactHandler.HandlePointImpact(hit.point, transform.forward * impactForce);
                }

                Destroy(instance.gameObject, instance.duration);
            }
        }