Пример #1
0
        public override void OnEnter(CharacterState characterState, Animator animator, AnimatorStateInfo stateInfo)
        {
            characterState.ATTACK_DATA.AttackTriggered = false;

            GameObject      obj  = PoolManager.Instance.GetObject(PoolObjectType.ATTACK_CONDITION);
            AttackCondition info = obj.GetComponent <AttackCondition>();

            if (AttackManager.Instance.ActiveAttacks == null)
            {
                AttackManager.Instance.ActiveAttacks      = new GameObject();
                AttackManager.Instance.ActiveAttacks.name = "ActiveAttacks";
                AttackManager.Instance.ActiveAttacks.transform.position = Vector3.zero;
                AttackManager.Instance.ActiveAttacks.transform.rotation = Quaternion.identity;
            }

            if (info.transform.parent == null)
            {
                info.transform.parent = AttackManager.Instance.ActiveAttacks.transform;
            }

            obj.SetActive(true);
            info.ResetInfo(this, characterState.characterControl);

            if (!AttackManager.Instance.CurrentAttacks.Contains(info))
            {
                AttackManager.Instance.CurrentAttacks.Add(info);
            }
        }
        void TakeDamage(AttackCondition info)
        {
            ProcessHitParticles(info);

            info.CurrentHits++;
            damageData.hp -= info.AttackAbility.Damage;

            AttackManager.Instance.ForceDeregister(control);
            control.ANIMATION_DATA.CurrentRunningAbilities.Clear();

            if (IsDead())
            {
                control.RAGDOLL_DATA.RagdollTriggered = true;
            }
            else
            {
                int randomIndex = Random.Range(0, (int)Hit_Reaction_States.COUNT);
                control.SkinnedMeshAnimator.Play(HashManager.Instance.DicHitReactionStates[(Hit_Reaction_States)randomIndex], 0, 0f);
            }

            ProcessFlyingRagdoll(info);

            if (!info.RegisteredTargets.Contains(this.control))
            {
                info.RegisteredTargets.Add(this.control);
            }
        }
        bool IsBlocked(AttackCondition info)
        {
            if (info == damageData.BlockedAttack && damageData.BlockedAttack != null)
            {
                return(true);
            }

            if (control.ANIMATION_DATA.IsRunning(typeof(Block)))
            {
                Vector3 dir = info.Attacker.transform.position - control.transform.position;

                if (dir.z > 0f)
                {
                    if (control.ROTATION_DATA.IsFacingForward())
                    {
                        return(true);
                    }
                }
                else if (dir.z < 0f)
                {
                    if (!control.ROTATION_DATA.IsFacingForward())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        bool IsInLethalRange(AttackCondition info)
        {
            for (int i = 0; i < control.RAGDOLL_DATA.ArrBodyParts.Length; i++)
            {
                float dist = Vector3.SqrMagnitude(
                    control.RAGDOLL_DATA.ArrBodyParts[i].transform.position - info.Attacker.transform.position);

                if (dist <= info.LethalRange)
                {
                    int             index           = Random.Range(0, control.RAGDOLL_DATA.ArrBodyParts.Length);
                    TriggerDetector triggerDetector = control.RAGDOLL_DATA.ArrBodyParts[index].GetComponent <TriggerDetector>();

                    damageData.damageTaken = new DamageTaken(
                        info.Attacker,
                        info.AttackAbility,
                        triggerDetector,
                        null,
                        Vector3.zero);

                    return(true);
                }
            }

            return(false);
        }
        bool IsCollided(AttackCondition info)
        {
            foreach (KeyValuePair <TriggerDetector, List <Collider> > data in
                     control.animationProgress.CollidingBodyParts)
            {
                foreach (Collider collider in data.Value)
                {
                    foreach (AttackPartType part in info.AttackParts)
                    {
                        if (info.Attacker.GetAttackingPart(part) ==
                            collider.gameObject)
                        {
                            damageData.damageTaken = new DamageTaken(
                                info.Attacker,
                                info.AttackAbility,
                                data.Key,
                                info.Attacker.GetAttackingPart(part),
                                Vector3.zero);

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
 void ProcessFlyingRagdoll(AttackCondition info)
 {
     if (info.AttackAbility.collateralDamageInfo.CreateCollateral)
     {
         control.RAGDOLL_DATA.flyingRagdollData.IsTriggered = true;
         control.RAGDOLL_DATA.flyingRagdollData.Attacker    = info.Attacker;
     }
 }
        void CheckCollidingWeapons(Collider col)
        {
            MeleeWeapon w = col.transform.root.gameObject.GetComponent <MeleeWeapon>();

            if (w == null)
            {
                return;
            }

            if (w.IsThrown)
            {
                if (w.Thrower != control)
                {
                    AttackCondition info = new AttackCondition();
                    info.CopyInfo(control.DAMAGE_DATA.AxeThrow, control);

                    control.DAMAGE_DATA.damageTaken = new DamageTaken(
                        w.Thrower,
                        control.DAMAGE_DATA.AxeThrow,
                        this,
                        null,
                        Vector3.zero);

                    control.DAMAGE_DATA.TakeDamage(info);

                    if (w.FlyForward)
                    {
                        w.transform.rotation = Quaternion.Euler(0f, 90f, 45f);
                    }
                    else
                    {
                        w.transform.rotation = Quaternion.Euler(0f, -90f, 45f);
                    }

                    w.transform.parent = this.transform;

                    Vector3 offset = this.transform.position - w.AxeTip.transform.position;
                    w.transform.position += offset;

                    w.IsThrown = false;
                    return;
                }
            }

            if (!control.animationProgress.CollidingWeapons.ContainsKey(this))
            {
                control.animationProgress.CollidingWeapons.Add(this, new List <Collider>());
            }

            if (!control.animationProgress.CollidingWeapons[this].Contains(col))
            {
                control.animationProgress.CollidingWeapons[this].Add(col);
            }
        }
 void ProcessDamage(AttackCondition info)
 {
     if (IsDead())
     {
         PushDeadBody(info);
     }
     else
     {
         if (!IsBlocked(info))
         {
             TakeDamage(info);
         }
     }
 }
        void ProcessHitParticles(AttackCondition info)
        {
            if (info.MustCollide)
            {
                CameraManager.Instance.ShakeCamera(0.3f);

                if (info.AttackAbility.UseDeathParticles)
                {
                    if (info.AttackAbility.ParticleType.ToString().Contains(VFX))
                    {
                        ShowHitParticles(info.Attacker, info.AttackAbility.ParticleType);
                    }
                }
            }
        }
        void PushDeadBody(AttackCondition info)
        {
            if (!info.RegisteredTargets.Contains(this.control))
            {
                if (info.AttackAbility.collateralDamageInfo.CreateCollateral)
                {
                    ShowHitParticles(info.Attacker, info.AttackAbility.ParticleType);
                    ProcessFlyingRagdoll(info);
                }

                info.RegisteredTargets.Add(this.control);
                control.RAGDOLL_DATA.ClearExistingVelocity();
                control.RAGDOLL_DATA.AddForceToDamagedPart(RagdollPushType.DEAD_BODY);
            }

            return;
        }
        bool AttackIsValid(AttackCondition info)
        {
            if (info == null)
            {
                return(false);
            }

            if (!info.isRegisterd)
            {
                return(false);
            }

            if (info.isFinished)
            {
                return(false);
            }

            if (info.CurrentHits >= info.MaxHits)
            {
                return(false);
            }

            if (info.Attacker == control)
            {
                return(false);
            }

            if (info.MustFaceAttacker)
            {
                Vector3 vec = this.transform.position - info.Attacker.transform.position;
                if (vec.z * info.Attacker.transform.forward.z < 0f)
                {
                    return(false);
                }
            }

            if (info.RegisteredTargets.Contains(this.control))
            {
                return(false);
            }

            return(true);
        }
        void CheckMarioStomp()
        {
            if (control.RIGID_BODY.velocity.y >= 0f)
            {
                MarioStompTargets.Clear();
                DownBlockingObjs.Clear();
                return;
            }

            if (MarioStompTargets.Count > 0)
            {
                control.RIGID_BODY.velocity = Vector3.zero;
                control.RIGID_BODY.AddForce(Vector3.up * 250f);

                foreach (CharacterControl c in MarioStompTargets)
                {
                    AttackCondition info = new AttackCondition();
                    info.CopyInfo(c.DAMAGE_DATA.MarioStompAttack, control);

                    int             index      = Random.Range(0, c.RAGDOLL_DATA.ArrBodyParts.Length);
                    TriggerDetector randomPart = c.RAGDOLL_DATA.ArrBodyParts[index].GetComponent <TriggerDetector>();

                    c.DAMAGE_DATA.damageTaken = new DamageTaken(
                        control,
                        c.DAMAGE_DATA.MarioStompAttack,
                        randomPart,
                        control.RightFoot_Attack,
                        Vector3.zero);

                    c.DAMAGE_DATA.TakeDamage(info);
                }

                MarioStompTargets.Clear();
                return;
            }

            CheckDownBlocking();

            if (DownBlockingObjs.Count > 0)
            {
                foreach (KeyValuePair <GameObject, GameObject> data in DownBlockingObjs)
                {
                    CharacterControl c = CharacterManager.Instance.
                                         GetCharacter(data.Value.transform.root.gameObject);

                    if (c != null)
                    {
                        if (c.boxCollider.center.y + c.transform.position.y < control.transform.position.y)
                        {
                            if (c != control)
                            {
                                if (!MarioStompTargets.Contains(c))
                                {
                                    MarioStompTargets.Add(c);
                                }
                            }
                        }
                    }
                }
            }
        }