/// <summary> /// Activates a single target by running the links for that target /// </summary> /// <param name="rTarget"></param> protected virtual bool ActivateInstance(GameObject rTarget, object rData) { if (rTarget == null) { return(true); } IAttributeSource lAttributes = rTarget.GetComponent <IAttributeSource>(); if (lAttributes == null) { return(true); } Type lType = lAttributes.GetAttributeType(_AttributeName); if (lType == typeof(int)) { int lValue = 0; if (int.TryParse(_StringValue, out lValue)) { lAttributes.SetAttributeValue <int>(_AttributeName, lValue); } } else if (lType == typeof(float)) { float lValue = 0f; if (float.TryParse(_StringValue, out lValue)) { lAttributes.SetAttributeValue <float>(_AttributeName, lValue); } } else if (lType == typeof(string)) { lAttributes.SetAttributeValue <string>(_AttributeName, _StringValue); } return(true); }
/// <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(); }