Example #1
0
        /// <summary>Enables the Zone using the State</summary>
        private void ActivateStateZone()
        {
            switch (stateAction)
            {
            case StateAction.Activate:
                CurrentAnimal.State_Activate(stateID);
                break;

            case StateAction.AllowExit:
                if (CurrentAnimal.ActiveStateID == stateID)
                {
                    CurrentAnimal.ActiveState.AllowExit();
                }
                break;

            case StateAction.ForceActivate:
                CurrentAnimal.State_Force(stateID);
                break;

            case StateAction.Enable:
                CurrentAnimal.State_Enable(stateID);
                break;

            case StateAction.Disable:
                CurrentAnimal.State_Disable(stateID);
                break;

            default:
                break;
            }

            StatModifierOnActive.ModifyStat(AnimalStats);
            OnZoneActivation.Invoke(CurrentAnimal);
        }
Example #2
0
 /// <summary>Enables the Zone using the State</summary>
 private void ActivateStateZone()
 {
     if (CurrentAnimal.State_TryActivate(stateID))
     {
         StatModifier.ModifyStat(AnimalStats);
         AlignAnimal();
         OnZoneActivation.Invoke();
     }
 }
Example #3
0
        void OnDisable()
        {
            SelfStatExit.ModifyStat(SelfStats);
            Trigger.enabled = false;

            if (CurrentAnimal)
            {
                EnemyStatExit.ModifyStat(CurrentAnimal.GetComponentInChildren <Stats>());
            }

            AlreadyHitted = new List <Collider>();
            CurrentAnimal = null;
        }
Example #4
0
        void OnTriggerExit(Collider other)
        {
            if (other.isTrigger)
            {
                return;
            }
            var Root = other.transform.root;

            if (Root != CurrentAnimal)
            {
                return;                                            //If is another animal exiting the zone SKIP
            }
            if (AlreadyHitted.Find(item => item == Root))          //Remove the collider from the list that is exiting the zone.
            {
                AlreadyHitted.Remove(Root);
            }

            if (AlreadyHitted.Count == 0)                                        //When all the collides are removed from the list..
            {
                enemy = Root.GetComponentInChildren <IMDamage>();                //Get the Animal on the Other collider

                if (enemy != null)                                               //if the other does'nt have the animal script skip
                {
                    //  if (self == enemy) return;                                      //Don't Hit yourself
                    EnemyStatExit.ModifyStat(Root.GetComponentInChildren <Stats>());
                }
                CurrentAnimal = null;
            }
        }
Example #5
0
        void OnTriggerEnter(Collider other)
        {
            var Root = other.transform.root;

            if (other.isTrigger && TriggerInteraction == QueryTriggerInteraction.Ignore)
            {
                return;                                                                                                                             //just collapse when is a collider what we are hitting
            }
            if (!MalbersTools.Layer_in_LayerMask(other.gameObject.layer, HitLayer))
            {
                return;                                                                      //Just hit what is on the HitMask Layer
            }
            if (Root == Owner.transform)
            {
                return;                                                                    //Don't hit yourself;
            }
            if (!AlreadyHitted.Find(item => item == Root))                                 //if the entering collider is not already on the list add it
            {
                AlreadyHitted.Add(Root);
            }

            if (Root == CurrentAnimal)
            {
                return;                                                           //if the animal is the same, do nothing we already done the logic below
            }
            else
            {
                if (CurrentAnimal)
                {
                    AlreadyHitted = new List <Transform>();                        //Clean the colliders if you had a previus animal
                }
                CurrentAnimal = Root;                                              //Is a new Animal that is enetering the Attack Trigger

                var TargetPos = Root.position;

                var mesh = Root.GetComponentInChildren <Renderer>();
                if (mesh != null)
                {
                    TargetPos = mesh.bounds.center;                                         //Get the mesh Bounds Center
                }
                Vector3 direction = (Owner.position - TargetPos).normalized;                //Calculate the direction of the attack

                var interactable = other.transform.GetComponent <IInteractable>();          //Get the Animal on the Other collider

                interactable?.Interact();

                enemy = Root.GetComponentInChildren <IMDamage>();                           //Get the Animal on the Other collider

                if (enemy != null)                                                          //if the other does'nt have the Damagable Interface dont send the Damagable stuff
                {
                    enemy.HitDirection = direction;
                    enemy.Damage();
                    EnemyStatEnter.ModifyStat(Root.GetComponentInChildren <Stats>()); //Affect Stats
                }
                else if (other.attachedRigidbody && PushForce != 0)                   //If the other has a riggid body and it can be pushed
                {
                    other.attachedRigidbody.AddForce(-direction * PushForce, ForceMode.VelocityChange);
                }
            }
        }
Example #6
0
 void OnEnable()
 {
     SelfStatEnter.ModifyStat(SelfStats);
     Trigger.enabled   = true;
     Trigger.isTrigger = true;
     AlreadyHitted     = new List <Collider>();
     CurrentAnimal     = null;
 }
Example #7
0
        void OnTriggerEnter(Collider other)
        {
            if (other.isTrigger)
            {
                return;
            }

            if (!MalbersTools.CollidersLayer(other, LayerMask.GetMask("Animal")))
            {
                return;                                                                             //Just accept animal layer only
            }
            if (HeadOnly && !other.name.Contains(HeadName))
            {
                return;                                                                             //If is Head Only and no head was found Skip
            }
            MAnimal newAnimal = other.GetComponentInParent <MAnimal>();                             //Get the animal on the entering collider

            if (!newAnimal)
            {
                return;                                                                             //If there's no animal do nothing
            }
            if (animal_Colliders.Find(coll => coll == other) == null)                               //if the entering collider is not already on the list add it
            {
                animal_Colliders.Add(other);
            }

            if (newAnimal == CurrentAnimal)
            {
                return;                                                                //if the animal is the same do nothing (when entering two animals on the same Zone)
            }
            else
            {
                if (CurrentAnimal)
                {
                    animal_Colliders = new List <Collider>();                          //Clean the colliders
                }
                CurrentAnimal = newAnimal;                                             //Set a new Animal
                AnimalStats   = CurrentAnimal.GetComponentInParent <Stats>();

                StatModifierOnEnter.ModifyStat(AnimalStats);                         //Modify the stats when exit
                OnEnter.Invoke(CurrentAnimal);
                ActivateZone();
            }
        }
Example #8
0
        void OnTriggerExit(Collider other)
        {
            if (other.isTrigger)
            {
                return;
            }
            if (HeadOnly && !other.name.Contains(HeadName))
            {
                return;                                                     //if is only set to head and there's no head SKIP
            }
            MAnimal existing_animal = other.GetComponentInParent <MAnimal>();

            if (!existing_animal)
            {
                return;                                                              //If there's no animal script found skip all
            }
            if (existing_animal != CurrentAnimal)
            {
                return;                                                             //If is another animal exiting the zone SKIP
            }
            if (animal_Colliders.Find(item => item == other))                       //Remove the collider from the list that is exiting the zone.
            {
                animal_Colliders.Remove(other);
            }

            if (animal_Colliders.Count == 0)                                       //When all the collides are removed from the list..
            {
                OnExit.Invoke(CurrentAnimal);                                      //Invoke On Exit when all animal's colliders has exited the Zone
                StatModifierOnExit.ModifyStat(AnimalStats);                        //Modify the stats when exit

                if (zoneType == ZoneType.Stance && stanceAction == StanceAction.Stay && CurrentAnimal.Stance == stanceID.ID)
                {
                    CurrentAnimal.Stance_Reset();
                }

                ResetStoredAnimal();
            }
        }
Example #9
0
        public override void ExitState()
        {
            base.ExitState();
            MaxHeight                   = float.NegativeInfinity; //Resets MaxHeight
            DistanceToGround            = float.PositiveInfinity;
            FallBlend                   = 1;
            animal.UpdateDirectionSpeed = true; //Reset the Rotate Direction
            animal.CustomSpeed          = false;
            animal.SetFloatID(0);               //Reset the float ID



            if (AffectStat.ID != null)
            {
                if (FallCurrentDistance < FallMinDistance.Value)
                {
                    return;                                              //Meaning if we are on the safe minimun distance we do not get damage from falling
                }
                AffectStat.Value = (FallCurrentDistance) * 100 / FallMaxDistance;

                AffectStat.ModifyStat(animal.GetComponent <Stats>());
            }
        }
Example #10
0
        //void ResetAttackTrigger()
        //{
        //}

        void OnDisable()
        {
            SelfStatExit.ModifyStat(SelfStats);
            Trigger.enabled = false;
            AlreadyHitted   = new List <Transform>();
        }
Example #11
0
 void OnEnable()
 {
     SelfStatEnter.ModifyStat(SelfStats);
     Trigger.enabled = true;
     AlreadyHitted   = new List <Transform>();
 }
Example #12
0
        public virtual void OnHit(RaycastHit other)
        {
            if (other.transform)
            {
                if (AffectRigidBodies)
                {
                    other.rigidbody?.AddForceAtPosition(transform.forward * force, other.point);
                }

                AffectStat.Value = Damage;

                AffectStat.ModifyStat(other.transform.GetComponentInParent <Stats>());

                var interactable = other.transform.GetComponent <IInteractable>();
                interactable?.Interact();

                Damager.SetDamage(DeltaPos.normalized, other.transform, transform);
            }


            //  _Rigidbody.isKinematic = true;
            _Rigidbody.constraints = RigidbodyConstraints.FreezeAll;


            //FIX FOR SCALED OBJECTS
            Vector3 NewScale = other.transform.lossyScale;

            NewScale.x = 1f / Mathf.Max(NewScale.x, 0.0001f);
            NewScale.y = 1f / Mathf.Max(NewScale.y, 0.0001f);
            NewScale.z = 1f / Mathf.Max(NewScale.z, 0.0001f);

            GameObject Hlper = new GameObject();

            Hlper.name = name + "Link";

            Hlper.transform.parent     = other.collider.transform;
            Hlper.transform.localScale = NewScale;
            Hlper.transform.position   = other.point;
            //Hlper.transform.localPosition = other.transform.InverseTransformPoint(other.point);
            Hlper.transform.localRotation = Quaternion.identity;

            transform.parent        = Hlper.transform;
            transform.localScale    = Vector3.one;
            transform.localPosition = Vector3.zero;

            transform.position += transform.forward * Penetration; //Put the arrow a bit deeper in the collider

            Destroy(Hlper, AgeAfterImpact);
            Destroy(gameObject, AgeAfterImpact);

            OnHitTarget.Invoke(other);

            if (timeAfterImpact > 0)
            {
                Invoke("InvokeAfterImpact", timeAfterImpact);
            }
            else
            {
                AfterImpact.Invoke();
            }
        }
Example #13
0
 /// <summary>Instant Reaction ... without considering Active or Delay parameters</summary>
 public void Modify(Stats stats) => modifier.ModifyStat(stats);