Beispiel #1
0
        /// <summary>
        /// Activates the action on a single target
        /// </summary>
        /// <param name="rTarget">Target to activate on</param>
        protected bool ActivateInstance(GameObject rTarget)
        {
            if (rTarget == null)
            {
                return(false);
            }

            IAttributeSource lAttributeSource = rTarget.GetComponent <IAttributeSource>();

            if (lAttributeSource == null)
            {
                return(false);
            }

            if (!lAttributeSource.AttributeExists(AttributeName))
            {
                return(false);
            }

            float lValue = lAttributeSource.GetAttributeValue <float>(AttributeName);

            lValue = lValue + UnityEngine.Random.Range(MinRandom, MaxRandom);

            switch (ComparisonIndex)
            {
            case 0:
                return(lValue == Value);

            case 1:
                return(lValue != Value);

            case 2:
                return(lValue < Value);

            case 3:
                return(lValue <= Value);

            case 4:
                return(lValue > Value);

            case 5:
                return(lValue >= Value);
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Activates the action on a single target
        /// </summary>
        /// <param name="rTarget">Target to activate on</param>
        protected void ActivateInstance(GameObject rTarget)
        {
            Vector3 lPoint   = rTarget.transform.position;
            Vector3 lForward = rTarget.transform.forward;

            // Combatant that is attacking
            ICombatant lAttacker = (_Spell.Owner != null ? _Spell.Owner.GetComponent <ICombatant>() : null);

            // Determine who we're colliding with
            IActorCore  lDefenderCore = rTarget.GetComponent <IActorCore>();
            IDamageable lDamageable   = rTarget.GetComponent <IDamageable>();

            if (lDefenderCore == null)
            {
                IWeaponCore lWeaponCore = rTarget.GetComponent <IWeaponCore>();
                if (lWeaponCore != null)
                {
                    lDefenderCore = lWeaponCore.Owner.GetComponent <IActorCore>();
                    if (lDamageable == null)
                    {
                        lDamageable = lWeaponCore.Owner.GetComponent <IDamageable>();
                    }
                }
            }

            // Save the hit information
            Transform lHitTransform = GetClosestTransform(lPoint, rTarget.transform);
            Vector3   lCombatCenter = lHitTransform.position;
            Vector3   lHitDirection = Vector3.zero;

            if (lDefenderCore != null)
            {
                ICombatant lDefenderCombatant = lDefenderCore.gameObject.GetComponent <ICombatant>();
                if (lDefenderCombatant != null)
                {
                    lHitDirection = Quaternion.Inverse(lDefenderCore.Transform.rotation) * (lPoint - lDefenderCombatant.CombatOrigin).normalized;
                }
            }
            else
            {
                lHitDirection = Quaternion.Inverse(lHitTransform.rotation) * (lPoint - lCombatCenter).normalized;
            }

            // Determine the damage
            float lDamage = UnityEngine.Random.Range(_MinDamage, _MaxDamage);

            if (_DamageFloatValueIndex >= 0 && _Spell.Data.FloatValues != null)
            {
                lDamage = _Spell.Data.FloatValues[_DamageFloatValueIndex];
            }

            // Put together the combat round info
            CombatMessage lCombatMessage = CombatMessage.Allocate();

            lCombatMessage.ID               = CombatMessage.MSG_DEFENDER_ATTACKED;
            lCombatMessage.Attacker         = (lAttacker != null ? lAttacker.Transform.gameObject : _Spell.Owner);
            lCombatMessage.Defender         = (lDefenderCore != null ? lDefenderCore.Transform.gameObject : rTarget);
            lCombatMessage.Weapon           = null;
            lCombatMessage.DamageType       = _DamageType;
            lCombatMessage.ImpactType       = _ImpactType;
            lCombatMessage.Damage           = lDamage;
            lCombatMessage.AnimationEnabled = _PlayAnimation;
            lCombatMessage.HitPoint         = lPoint;
            lCombatMessage.HitDirection     = lHitDirection;
            lCombatMessage.HitVector        = lForward;
            lCombatMessage.HitTransform     = lHitTransform;

            // Let the defender react to the damage
            if (lDefenderCore != null)
            {
                lDefenderCore.SendMessage(lCombatMessage);
            }
            // If needed, send the damage directly to the actor core
            else if (lDamageable != null)
            {
                lDamageable.OnDamaged(lCombatMessage);
            }
            // Without an actor core, check if we can set attributes
            else
            {
                IAttributeSource lAttributeSource = rTarget.GetComponent <IAttributeSource>();
                if (lAttributeSource != null)
                {
                    float lHealth = lAttributeSource.GetAttributeValue <float>(EnumAttributeIDs.HEALTH);
                    lAttributeSource.SetAttributeValue(EnumAttributeIDs.HEALTH, Mathf.Max(lHealth - lCombatMessage.Damage, 0f));
                }
            }

            // Release the message
            lCombatMessage.Release();
        }