示例#1
0
    override public void TriggerEffect()
    {
        //타겟 고르기
        skill.CollectTargets();
        //Debug.Log("타겟 초기화");
        if (skill.targetList == null || skill.targetList.Count == 0)
        {
            if (skill.onTriggerEvent != null)
            {
                skill.onTriggerEvent(skill, skillEvent);
            }

            return;
        }

        for (int i = 0; i < skill.targetList.Count; i++)
        {
            BattleHero target = skill.targetList[i];

            //타격 이펙트
            if (skillEvent != null && skillEvent.hitEffect)
            {
                GameObject hitEffectObj = Battle.GetObjectInPool(skillEvent.hitEffect.name);

                //풀링 안되어 있으면 함.
                if (!hitEffectObj)
                {
                    hitEffectObj      = GameObject.Instantiate(skillEvent.hitEffect, target.transform.position, Quaternion.identity, skill.owner.transform.parent) as GameObject;
                    hitEffectObj.name = skillEvent.hitEffect.name;
                    //hitEffectObj.AddComponent<SelfDestroyParticle>();
                    hitEffectObj.SetActive(false);
                    hitEffectObj.AddComponent <BattleGroupElement>();

                    Battle.AddObjectToPool(hitEffectObj);
                }

                if (hitEffectObj)
                {
                    //Vector3 hitPos = target.GetClosestPoint(skill.owner.transform.position);
                    Vector3 hitPos = target.collider.transform.position;// .GetClosestPoint(skill.owner.transform.position);
                    hitEffectObj.transform.position = hitPos;
                    if (skillEvent.attachToTarget)
                    {
                        hitEffectObj.transform.SetParent(target.transform);
                    }

                    hitEffectObj.transform.localScale = Vector3.one;

                    //캐릭터 위치에 따라 뒤집기
                    if (skill.owner is BattleHero)
                    {
                        BattleHero h      = skill.owner as BattleHero;
                        bool       isFlip = h.flipX;
                        float      x      = isFlip ? -1f : 1f;
                        hitEffectObj.transform.localScale = new Vector3(x, 1f, 1f);
                    }


                    //히트 파티클 오브젝트 활성
                    hitEffectObj.SetActive(true);
                    hitEffectObj.GetComponent <BattleGroupElement>().SetBattleGroup(skill.owner.battleGroup);

                    OrderController orderControllerA = hitEffectObj.GetComponent <OrderController>();
                    OrderController orderControllerB = target.GetComponent <OrderController>();
                    if (orderControllerA)
                    {
                        if (orderControllerB)
                        {
                            orderControllerA.parent = orderControllerB;
                        }
                        else
                        {
                            orderControllerA.parent = null;
                        }
                    }

                    ParticleSystem p = hitEffectObj.GetComponentInChildren <ParticleSystem>();
                    if (p)
                    {
                        p.Play();
                    }

                    Animation anim = hitEffectObj.GetComponentInChildren <Animation>();
                    if (anim)
                    {
                        anim.Play();
                    }
                }
            }

            bool isSuccessHit = false;

            //대상한테 데미지 적용. 힐은 피 채워줌
            if (!string.IsNullOrEmpty(skill.skillData.power))
            {
                double damageModifyType = 0d;
                if (skill.skillData.damageType == SkillBase.DamageType.Physical)
                {
                    damageModifyType = skill.owner.master.stats.GetValueOf(StatType.AttackPowerPhysical);
                }
                else if (skill.skillData.damageType == SkillBase.DamageType.Magical)
                {
                    damageModifyType = skill.owner.master.stats.GetValueOf(StatType.AttackPowerMagical);
                }

                double damageModifyRange = 0d;
                if (skill.skillData.rangeType == SkillBase.RangeType.Melee)
                {
                    damageModifyRange = skill.owner.master.stats.GetValueOf(StatType.AttackPowerMelee);
                }
                else if (skill.skillData.rangeType == SkillBase.RangeType.Range)
                {
                    damageModifyRange = skill.owner.master.stats.GetValueOf(StatType.AttackPowerRange);
                }

                double power = skill.GetPower(target) * (1 + damageModifyType * 0.0001d) * (1 + damageModifyRange * 0.0001d);

                //if (skill.owner.master.heroData.baseData.id.Contains("Centaur"))
                //    Debug.Log(power + ", " + skill.GetPower(target) + ", " + damageModifyType + ", " + damageModifyRange);

                if (skill.skillData.effectType == "Heal")
                {
                    target.Damage(skill.owner.master, -power, SkillBase.DamageType.Pure, skill, "Heal");
                }
                else if (skill.skillData.effectType == "Resurrect")
                {
                    target.Damage(skill.owner.master, -power, SkillBase.DamageType.Pure, skill, "Resurrect");
                    BattleHero h = target as BattleHero;
                    h.ReGen(true);
                }
                else
                {
                    //콜라 - 수호자 버프 처리
                    List <Buff> buffGuardList = target.buffController.buffList.FindAll(x => x.id == "Buff_Knight_Passive" &&
                                                                                       x.target == target && x.owner != target && !x.owner.isDie);
                    if (buffGuardList != null && buffGuardList.Count > 0)
                    {
                        int count = buffGuardList.Count;
                        for (int a = 0; a < count; a++)
                        {
                            //수호자들끼리 30%만큼 피해를 나눠서 받음
                            buffGuardList[a].owner.Damage(skill.owner.master, power * 0.3d * 1 / count, skill.skillData.damageType, skill, "Guard");
                        }

                        //직접 얻어 맞은애는 70%
                        isSuccessHit = target.Damage(skill.owner.master, power * 0.7d, skill.skillData.damageType, skill);
                    }
                    else
                    {
                        isSuccessHit = target.Damage(skill.owner.master, power, skill.skillData.damageType, skill);
                    }

                    //대상 흔들림
                    if (isSuccessHit && skill.skillData.forceType == SkillBase.ForceType.Shake)
                    {
                        target.Shake(0.4f, 0.15f, 0.03f);
                    }
                }
            }

            if (skill.skillData.effectType == "Trail_End")
            {
                skill.owner.GetComponentInChildren <EffectTrail>().OffEffect();
            }


            if (skill.skillData.forceType == SkillBase.ForceType.Dash)
            {
                if (skill.skillData.forcePower != 0f)
                {
                    float force = skill.skillData.forcePower;

                    Vector2 point = new Vector2(target.transform.position.x + force, target.transform.position.y);
                    target.Dash(point, 1);
                }
            }

            // 밀기
            if (skill.skillData.forceType == SkillBase.ForceType.Push)
            {
                if (skill.skillData.forcePower != 0f)
                {
                    float force = skill.skillData.forcePower;

                    //대상이 왼쪽에 있는 경우 반대로 함
                    if (target.transform.position.x < skill.transform.position.x)
                    {
                        force = -force;
                    }

                    //Debug.Log("force : " + force);
                    target.addedForce += (Vector3.right * force);
                    //Debug.Log("force : " + force);
                }
                //target.Knockback2(skill, skill.skillData.forcePower);
            }

            if (skill.skillData.forceType == SkillBase.ForceType.Pull)
            {
                float force = skill.skillData.forcePower;
                float filp  = Random.Range(2.5f, 3.5f);
                float y     = Random.Range(-1f, 1f);
                //대상이 왼쪽에 있는 경우 반대로 함
                if (target.transform.position.x < skill.transform.position.x)
                {
                    filp = -filp;
                }
                Vector2 point = new Vector2(skill.owner.master.transform.position.x + filp, skill.owner.master.transform.position.y + y);
                //Debug.Log(target.heroData.heroName + " 끌려옴");
                target.Pull(point, 1);
            }
            else if (skill.skillData.forceType == SkillBase.ForceType.Knockback)
            {
                // 표현이 넉백에 가까움..
                //밀어내기/당기기 효과
                if (skill.skillData.forcePower != 0f)
                {
                    float force = skill.skillData.forcePower;

                    //대상이 왼쪽에 있는 경우 반대로 함
                    if (target.transform.position.x < skill.transform.position.x)
                    {
                        force = -force;
                    }

                    target.addedForce += Vector3.right * force;
                }
            }
            else if (skill.skillData.forceType == SkillBase.ForceType.Knockback2)
            {
                target.Knockback2(skill, skill.skillData.forcePower);
            }
            else if (skill.skillData.forceType == SkillBase.ForceType.Airborne)
            {
                target.Airborne(skill, skill.skillData.forcePower);
            }
            else if (skill.skillData.forceType == SkillBase.ForceType.FallDown)
            {
                target.FallingDown(skill, skill.skillData.forcePower);
            }

            //버프 적용
            int r = UnityEngine.Random.Range(0, 10000);
            if (r <= skill.skillData.buffProbability)
            {
                target.buffController.AttachBuff(skill.owner.master, skill.skillData.buffID, skill.skillData.buffStack);
            }


            if (!isSuccessHit)
            {
                continue;
            }
        }

        if (skill.onTriggerEvent != null)
        {
            skill.onTriggerEvent(skill, skillEvent);
        }

        OnTrailEnd();
    }