예제 #1
0
    internal override void ApplyHpChange(SkillRunner caster, float hpChange, float damagePercent, int type)
    {
        if (OnBuff(Buff_Sp.INVENSIBLE))
        {
            return;
        }

        if (!GameConfig.IsMultiMode)
        {
            float _defence = (float)defence / (float)(defence + 0);

            if (caster != null)
            {
                float attack = caster.GetAttribute(Pathea.AttribType.Atk) * damagePercent + hpChange;
                float damage = attack * (1 - _defence) * Random.Range(0.9f, 1.1f);

                int damageType = type == 0 ? AiDamageTypeData.GetDamageType(caster) : type;
                damage *= AiDamageTypeData.GetDamageScale(damageType, defenceType);

                //Debug.Log(caster + " attack " + this.gameObject + (int)damage + " hp");
                if (caster.gameObject.Equals(this.gameObject))
                {
                    ApplyDamage(Mathf.CeilToInt(damage));
                }
                else
                {
                    ApplyDamage(caster.transform, Mathf.CeilToInt(damage));
                }
            }
            else
            {
                float attack = hpChange;
                float damage = attack * (1 - _defence) * Random.Range(0.9f, 1.1f);

                ApplyDamage(Mathf.CeilToInt(damage));
            }
        }
    }
예제 #2
0
        public void Update()
        {
            mUpdatePassTime += Time.deltaTime;
            if (mUpdatePassTime > mUpdateInterval)
            {
                mUpdatePassTime -= mUpdateInterval;

                if (mPlayerCtrlArea)
                {
                    CreatEnemyMode();
                    return;
                }

                DefenderBE = 0;
                EnemyBE    = 0;
                bool inBattle = IsInBattle();

                //DefenderAction
                for (int i = mDefenderList.Count - 1; i >= 0; i--)
                {
                    if (mDefenderList[i].mHp > 0)
                    {
                        //Atacker
                        if (inBattle && mEnemyList.Count > 0 && Convert.ToBoolean(mDefenderList[i].mType & (1 << 5)))
                        {
                            switch (mDefenderList[i].mAtkRange)
                            {
                            case EffectRange.Single:
                            {
                                BattleUnit target = mEnemyList[UnityEngine.Random.Range(0, mEnemyList.Count)];
                                float      damage = mDefenderList[i].mAtk * (1 - target.mDef / (target.mDef + DamageScale))
                                                    * AiDamageTypeData.GetDamageScale(mDefenderList[i].mAtkType, target.mDefType);
                                target.mHp -= damage * mUpdateInterval / mDefenderList[i].mAtkInterval;
                            }
                            break;

                            case EffectRange.Range:
                                foreach (BattleUnit enemy in mEnemyList)
                                {
                                    float damage = mDefenderList[i].mAtk * (1 - enemy.mDef / (enemy.mDef + DamageScale))
                                                   * AiDamageTypeData.GetDamageScale(mDefenderList[i].mAtkType, enemy.mDefType);
                                    enemy.mHp -= damage * mUpdateInterval / mDefenderList[i].mAtkInterval;
                                }
                                break;

                            case EffectRange.spread:
                            {
                                BattleUnit target = mEnemyList[UnityEngine.Random.Range(0, mEnemyList.Count)];
                                float      damage = mDefenderList[i].mAtk * (1 - target.mDef / (target.mDef + DamageScale))
                                                    * AiDamageTypeData.GetDamageScale(mDefenderList[i].mAtkType, target.mDefType);
                                target.mHp -= damage * mUpdateInterval / mDefenderList[i].mAtkInterval;

                                foreach (BattleUnit enemy in mEnemyList)
                                {
                                    if (target != enemy)
                                    {
                                        damage = mDefenderList[i].mAtk * (1 - enemy.mDef / (enemy.mDef + DamageScale))
                                                 * AiDamageTypeData.GetDamageScale(mDefenderList[i].mAtkType, enemy.mDefType) * mDefenderList[i].mSpreadFactor;
                                        enemy.mHp -= damage * mUpdateInterval / mDefenderList[i].mAtkInterval;
                                    }
                                }
                            }
                            break;
                            }
                        }

                        //Healer
                        if (Convert.ToBoolean(mDefenderList[i].mType & (1 << 6)))
                        {
                            switch (mDefenderList[i].mHealRange)
                            {
                            case EffectRange.Single:
                            {
                                BattleUnit target  = null;
                                float      maxHpDT = 0;
                                foreach (BattleUnit defender in mDefenderList)
                                {
                                    if (defender.mHp < defender.mMaxHp && Convert.ToBoolean(defender.mType & mDefenderList[i].mHealType))
                                    {
                                        if (maxHpDT < defender.mMaxHp - defender.mHp)
                                        {
                                            maxHpDT = defender.mMaxHp - defender.mHp;
                                            target  = defender;
                                        }
                                    }
                                }
                                if (target)
                                {
                                    target.mHp = Mathf.Clamp(target.mHp + mDefenderList[i].mHealPs * mUpdateInterval, 0, target.mMaxHp);
                                }
                            }
                            break;

                            case EffectRange.Range:
                                foreach (BattleUnit defender in mDefenderList)
                                {
                                    if (defender.mHp < defender.mMaxHp && Convert.ToBoolean(defender.mType & mDefenderList[i].mHealType))
                                    {
                                        defender.mHp = Mathf.Clamp(defender.mHp + mDefenderList[i].mHealPs * mUpdateInterval, 0, defender.mMaxHp);
                                    }
                                }
                                break;

                            case EffectRange.spread:
                            {
                                BattleUnit target  = null;
                                float      maxHpDT = 0;
                                foreach (BattleUnit defender in mDefenderList)
                                {
                                    if (defender.mHp < defender.mMaxHp && Convert.ToBoolean(defender.mType & mDefenderList[i].mHealType))
                                    {
                                        if (maxHpDT < defender.mMaxHp - defender.mHp)
                                        {
                                            maxHpDT = defender.mMaxHp - defender.mHp;
                                            target  = defender;
                                        }
                                    }
                                }
                                if (target)
                                {
                                    target.mHp = Mathf.Clamp(target.mHp + mDefenderList[i].mHealPs * mUpdateInterval, 0, target.mMaxHp);
                                }
                                foreach (BattleUnit defender in mDefenderList)
                                {
                                    if (defender != target && defender.mHp < defender.mMaxHp && Convert.ToBoolean(defender.mType & mDefenderList[i].mHealType))
                                    {
                                        defender.mHp = Mathf.Clamp(defender.mHp + mDefenderList[i].mHealPs * mUpdateInterval * mDefenderList[i].mSpreadFactor, 0, defender.mMaxHp);
                                    }
                                }
                            }
                            break;
                            }
                        }
                    }
                }


                //EnemyAction
                for (int i = mEnemyList.Count - 1; i >= 0; i--)
                {
                    if (mEnemyList[i].mHp > 0)
                    {
                        //Atacker
                        if (inBattle && mDefenderList.Count > 0 && Convert.ToBoolean(mEnemyList[i].mType & (1 << 5)))
                        {
                            switch (mEnemyList[i].mAtkRange)
                            {
                            case EffectRange.Single:
                            {
                                BattleUnit target = mDefenderList[UnityEngine.Random.Range(0, mDefenderList.Count)];
                                float      damage = mEnemyList[i].mAtk * (1 - target.mDef / (target.mDef + DamageScale))
                                                    * AiDamageTypeData.GetDamageScale(mEnemyList[i].mAtkType, target.mDefType);
                                target.mHp -= damage * mUpdateInterval / mEnemyList[i].mAtkInterval;
                            }
                            break;

                            case EffectRange.Range:
                                foreach (BattleUnit defender in mDefenderList)
                                {
                                    float damage = mEnemyList[i].mAtk * (1 - defender.mDef / (defender.mDef + DamageScale))
                                                   * AiDamageTypeData.GetDamageScale(mEnemyList[i].mAtkType, defender.mDefType);
                                    defender.mHp -= damage * mUpdateInterval / mEnemyList[i].mAtkInterval;
                                }
                                break;

                            case EffectRange.spread:
                            {
                                BattleUnit target = mDefenderList[UnityEngine.Random.Range(0, mDefenderList.Count)];
                                float      damage = mEnemyList[i].mAtk * (1 - target.mDef / (target.mDef + DamageScale))
                                                    * AiDamageTypeData.GetDamageScale(mEnemyList[i].mAtkType, target.mDefType);
                                target.mHp -= damage * mUpdateInterval / mEnemyList[i].mAtkInterval;

                                foreach (BattleUnit defender in mDefenderList)
                                {
                                    if (defender != target)
                                    {
                                        damage = mEnemyList[i].mAtk * (1 - defender.mDef / (defender.mDef + DamageScale))
                                                 * AiDamageTypeData.GetDamageScale(mEnemyList[i].mAtkType, defender.mDefType);
                                        defender.mHp -= damage * mUpdateInterval / mEnemyList[i].mAtkInterval;
                                    }
                                }
                            }
                            break;
                            }
                        }

                        //Healer
                        if (Convert.ToBoolean(mEnemyList[i].mType & (1 << 6)))
                        {
                            switch (mEnemyList[i].mHealRange)
                            {
                            case EffectRange.Single:
                            {
                                BattleUnit target  = null;
                                float      maxHpDT = 0;
                                foreach (BattleUnit enemy in mEnemyList)
                                {
                                    if (enemy.mHp < enemy.mMaxHp && Convert.ToBoolean(enemy.mType & mEnemyList[i].mHealType))
                                    {
                                        if (maxHpDT < enemy.mMaxHp - enemy.mHp)
                                        {
                                            maxHpDT = enemy.mMaxHp - enemy.mHp;
                                            target  = enemy;
                                        }
                                    }
                                }
                                if (target)
                                {
                                    target.mHp = Mathf.Clamp(target.mHp + mEnemyList[i].mHealPs * mUpdateInterval, 0, target.mMaxHp);
                                }
                            }
                            break;

                            case EffectRange.Range:
                                foreach (BattleUnit enemy in mEnemyList)
                                {
                                    if (enemy.mHp < enemy.mMaxHp && Convert.ToBoolean(enemy.mType & mEnemyList[i].mHealType))
                                    {
                                        enemy.mHp = Mathf.Clamp(enemy.mHp + mEnemyList[i].mHealPs * mUpdateInterval, 0, enemy.mMaxHp);
                                    }
                                }
                                break;

                            case EffectRange.spread:
                            {
                                BattleUnit target  = null;
                                float      maxHpDT = 0;
                                foreach (BattleUnit enemy in mEnemyList)
                                {
                                    if (enemy.mHp < enemy.mMaxHp && Convert.ToBoolean(enemy.mType & mEnemyList[i].mHealType))
                                    {
                                        if (maxHpDT < enemy.mMaxHp - enemy.mHp)
                                        {
                                            maxHpDT = enemy.mMaxHp - enemy.mHp;
                                            target  = enemy;
                                        }
                                    }
                                }
                                if (target)
                                {
                                    target.mHp = Mathf.Clamp(target.mHp + mEnemyList[i].mHealPs * mUpdateInterval, 0, target.mMaxHp);
                                }
                                foreach (BattleUnit enemy in mEnemyList)
                                {
                                    if (enemy != target && enemy.mHp < enemy.mMaxHp && Convert.ToBoolean(enemy.mType & mEnemyList[i].mHealType))
                                    {
                                        enemy.mHp = Mathf.Clamp(enemy.mHp + mEnemyList[i].mHealPs * mUpdateInterval * mEnemyList[i].mSpreadFactor, 0, enemy.mMaxHp);
                                    }
                                }
                            }
                            break;
                            }
                        }
                    }
                }

                //release things that need be remove,and count the BE
                for (int i = mDefenderList.Count - 1; i >= 0; i--)
                {
                    if (mDefenderList[i].mHp > 0)
                    {
                        DefenderBE += mDefenderList[i].mBE;
                    }
                    else
                    {
                        if (mDefenderList[i] == mParent.mSelfUnit)
                        {
                            mParent.OnBattleFail();
                        }

                        RemoveFromDragItemMgr(mDefenderList[i].gameObject);
//						foreach(ItemPackGui_N.DrawItem item in ItemPackGui_N.mDrawItemList)
//						{
//							if (GameObject.Equals(mDefenderList[i].gameObject,item.mObject))
//							{
//								mDefenderList.RemoveAt(i);
//								ItemPackGui_N.mDrawItemList.Remove(item);
//								break;
//							}
//						}
                    }
                }

                for (int i = mEnemyList.Count - 1; i >= 0; i--)
                {
                    if (mEnemyList[i].mHp > 0)
                    {
                        EnemyBE += mEnemyList[i].mBE;
                    }
                    else
                    {
                        GameObject.Destroy(mEnemyList[i].gameObject);
                        mEnemyList.RemoveAt(i);
                    }
                }

                if (DefenderBE == 0 && EnemyBE > 0)
                {
                    AreaUnit targetArea = null;
                    float    minForce   = 100000000f;
                    //enemy go to the near area which has the lessest force but higher force than self
                    foreach (AreaUnit area in mNearArea)
                    {
                        if (area.mDefenderForce > mDefenderForce && area.mDefenderForce < minForce)
                        {
                            targetArea = area;
                            minForce   = area.mDefenderForce;
                        }
                    }
                    // if can find area than choose the hightest force one
                    if (null == targetArea)
                    {
                        minForce = 0;
                        foreach (AreaUnit area in mNearArea)
                        {
                            if (area.mDefenderForce > minForce)
                            {
                                targetArea = area;
                                minForce   = area.mDefenderForce;
                            }
                        }
                    }

                    for (int i = mEnemyList.Count - 1; i >= 0; i--)
                    {
                        if (Convert.ToBoolean(mEnemyList[i].mType & 1) && mEnemyList[i].CanMove())
                        {
                            mEnemyList[i].Move();
                            targetArea.AddBattleUnit(mEnemyList[i]);
                            mEnemyList.RemoveAt(i);
                        }
                    }
                }
                // MoveAble unit go to other area which is inbattle and is nearest one
                else if (EnemyBE == 0 && DefenderBE > 0)
                {
                }
            }
        }