Esempio n. 1
0
        /// <summary>
        /// The Reaction of Getting hit based on the attack type
        /// </summary>
        /// <param name="attacker"> the character that attacking</param>
        /// <param name="currentAtk"></param>
        void ExecuteHurtBehavior(AttackBase currentAtk, Transform atkTransform)
        {
            ActorBehavior getHitBehavior = null;

            if (!model.cc.isGrounded)
            {
                switch (currentAtk.atkImpactType)
                {
                case AttackImpactType.Normal:
                    getHitBehavior = model.GetBehavior("Hurt_Grounded");     // todo change get hit to a standalone behavior
                    break;

                case AttackImpactType.KnockDown:
                    getHitBehavior = model.GetBehavior("Hurt_Falldown");     // todo change get hit to a standalone behavior
                    break;

                case AttackImpactType.HitFly:
                    getHitBehavior = model.GetBehavior("Hurt_Aerial");     // todo change get hit to a standalone behavior
                    break;
                }
            }
            else
            {
                getHitBehavior = model.GetBehavior("HitFly"); // todo change get hit to a standalone behavior
            }

            model.StartBehavior(getHitBehavior);

            // update the get hit behavior frame length based on the attackinfo's hitstun
            ApplyHitImpactFrames(currentAtk.hitImpact);
            // The hit animation conditions
            model.animHit = GetEnemyRelativePosition(model.character.transform, atkTransform);
        }
Esempio n. 2
0
 /// <summary>
 /// Update  behavior's position, rotation, and scale
 /// </summary>
 void UpdateHurtBoxTransformation(ActorBehavior behavior)
 {
     if (model.hurtBox != null)
     {
         HurtboxTransform hurtbox = behavior.hurtBoxInfo;
         model.hurtBox.SetLocalPosition(hurtbox.position);
         model.hurtBox.SetLocalRotation(hurtbox.rotation);
         model.hurtBox.SetLocalScale(hurtbox.scale);
     }
 }
Esempio n. 3
0
 /// <summary>
 ///  Reset all behavior actions
 /// </summary>
 void ResetBehaviorActions(ActorBehavior behavior)
 {
     if (behavior != null)
     {
         foreach (IBehaviorAction act in behavior.behaviorActions)
         {
             if (act != null)
             {
                 act.Exit(model);
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Constructor with id behavior and followUps
        /// </summary>
        /// <param name="id"></param>
        /// <param name="behavior"></param>
        /// <param name="_followUps"></param>
        public ChainBehavior(int id, ActorBehavior behavior, List <int> _followUps, int priority)
        {
            this.idIndex  = id;
            this.behavior = behavior;
            this.priority = priority;

            // because its reference type
            this.followUps.Clear();
            foreach (var followUp in _followUps)
            {
                this.followUps.Add(followUp);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Start a new Behavior
 /// </summary>
 /// <param name="newBehavior"></param>
 public void StartBehavior(ActorBehavior newBehavior)
 {
     if (isDead)
     {
         return;
     }
     fsm.StartBehavior(newBehavior);
     if (newBehavior != null)
     {
         DecreaseEnergy(newBehavior.energyPointCost);
         ReduceAirJumpPoint(newBehavior.airJumpPointCost);
     }
 }
        /// <summary>
        ///  Return a bool to determine if meet the next behavior's condition
        /// </summary>
        /// <returns></returns>
        bool CanStartNextBehavior()
        {
            if (model.chainBehaviors.Count == 0 || model.chainBehaviors == null)
            {
                Debug.LogError("There is no chain connection in your behaivor, please create chain connection by using ChainEditor");
                return(false);
            }

            // by default set to Default
            if (model.currentChainIndex >= model.chainBehaviors.Count)
            {
                model.currentChainIndex = 0;
            }

            int currentPriority = -1;

            for (int f = 0; f < model.chainBehaviors[model.currentChainIndex].followUps.Count; f++)
            {
                ChainBehavior nextChainBehavior = GetChainBehavior(f);
                ActorBehavior exceptedBehavior  = nextChainBehavior.behavior;
                // Check Input buffer
                if (GameManager_Input.Instance.bufferKeys.Any(p => p == exceptedBehavior.inputKey || p == exceptedBehavior.altInputKey)) // todo maybe add key combo and motion input buffer
                {
                    // the behaviors will have certain requirements
                    if (exceptedBehavior.MetRequirements(model))
                    {
                        // Update the current priority level
                        if (UpdatePriorityLevel(nextChainBehavior.priority, ref currentPriority))
                        {
                            // if there is no followups, then go to the index 1 which is Default behavior
                            model.currentChainIndex = (nextChainBehavior.followUps.Count > 0) ? nextChainBehavior.idIndex : 0;

                            //nextBehavior = model.GetBehavior(nextInputInfo.behaviorIndex);
                            nextBehavior = model.GetBehavior(exceptedBehavior.name);


                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 7
0
        /// <summary>
        ///  Start a new behavior
        /// </summary>
        /// <param name="newBehavior"></param>
        public void StartBehavior(ActorBehavior newBehavior)
        {
            if (newBehavior == null)
            {
                return;
            }
            // Reset the behavior actions' params for prevent some behaior enter new behavior before exiting the behavior
            ResetBehaviorActions(model.currentBehavior);
            model.currentFrame    = 0;           // reset current frame
            model.previousFrame   = -1;
            model.currentBehavior = newBehavior; // update current behavior to new behavior

            if (model.currentBehavior == GetBehavior("Default") || model.currentBehavior.isHurtBehavior || model.currentBehavior.canForceExecute)
            {
                model.currentChainIndex = 0;
            }
            model.CanCancel = false;

            // Reset hit info
            model.HitConfirm = false;
            model.friction   = model.currentBehavior.behaviorFriction;
            UpdateHurtBoxTransformation(model.currentBehavior); // update current behavior's position, rotation, and scale
            model.anim?.CrossFadeInFixedTime(model.currentBehavior.name, model.currentBehavior.blendRate);
        }