/// <summary> /// Clears the effect so it can be used again /// </summary> public virtual void Clear() { mAge = 0f; mTriggerTime = 0f; mActorCore = null; }
/// <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); } IActorCore lActorCore = rTarget.GetComponent <IActorCore>(); if (lActorCore == null) { return(true); } MagicMessage lMessage = MagicMessage.Allocate(); lMessage.Data = this; bool lIsAffected = lActorCore.TestAffected(lMessage); lMessage.Release(); return(lIsAffected); }
/// <summary> /// ActorCore constructor /// </summary> public ActorCoreEffect(ActorCore rActorCore) { mActorCore = rActorCore; }
/// <summary> /// Called to start the specific motion. If the motion /// were something like 'jump', this would start the jumping process /// </summary> /// <param name="rPrevMotion">Motion that this motion is taking over from</param> public override bool Activate(MotionControllerMotion rPrevMotion) { // Ensure we're not holding onto an old spell mSpellInstance = null; mStoredAnimatorSpeed = 0f; // Default the spell int lSpellIndex = mSpellIndex; // If a spell was specified (through the parameter), use it if (mParameter > 0) { lSpellIndex = mParameter; } // Allow the spell to be modified before the attack occurs MagicMessage lMessage = MagicMessage.Allocate(); lMessage.ID = MagicMessage.MSG_MAGIC_PRE_CAST; lMessage.Caster = mMotionController.gameObject; lMessage.SpellIndex = lSpellIndex; lMessage.CastingMotion = this; lMessage.Data = this; IActorCore lActorCore = mMotionController.gameObject.GetComponent <ActorCore>(); if (lActorCore != null) { lActorCore.SendMessage(lMessage); lSpellIndex = lMessage.SpellIndex; } #if USE_MESSAGE_DISPATCHER || OOTII_MD MessageDispatcher.SendMessage(lMessage); lSpellIndex = lMessage.SpellIndex; #endif MagicMessage.Release(lMessage); // Ensure we know what spell to cast if (mSpellInventory != null) { mSpellInstance = mSpellInventory.InstantiateSpell(lSpellIndex); } if (mSpellInstance == null) { return(false); } // Allow the casting mIKWeight = 0f; mHasCast = false; mIsInterrupted = false; mIsInterruptedReported = false; mHasReachedForward = false; mWasTraversal = (mActorController.State.Stance == EnumControllerStance.TRAVERSAL); // Rotate towards this target. If there's no camera, we'll // assume we're dealing with an NPC if (mMotionController._CameraTransform != null) { mTargetForward = mMotionController._CameraTransform.forward; } //// Ensure our combatant is setup //if (mCombatant != null) //{ // if (!mCombatant.OnAttackActivated(this)) // { // return false; // } //} // Run the approapriate cast int lMotionPhase = (mWasTraversal ? PHASE_STANDING_START : PHASE_START); mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, lMotionPhase, mSpellInstance.CastingStyle, 0, true); // Now, activate the motion return(base.Activate(rPrevMotion)); }
/// <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(); }