public int CalcMagicPower(IRole pAtker, IRole pTarget, int pAdjustAtk, ref InteractionEffect pSpecial) // /*=0*/, ref InteractionEffect special)
        {
            if (pTarget is Character)
            {
                Character pUser = pTarget as Character;
                if (pUser.QueryTransformation != null && pUser.QueryTransformation.Lookface == 223)
                {
                    return(1);
                }
            }

            if (m_pOwner.Map.IsLineSkillMap())
            {
                return(1);
            }

            if (pTarget.QueryStatus(FlagInt.VORTEX) != null)
            {
                return(1);
            }

            int nAtk = pAtker.MagicAttack;

            if (pAtker.Magics.QueryMagic() != null)
            {
                float tPower = pAtker.Magics.QueryMagic().QueryPower();
                if (tPower > 30000)
                {
                    tPower = (tPower - 30000) / 100f;
                    nAtk   = (int)(nAtk * tPower);
                }
                else
                {
                    nAtk += (short)tPower;
                }
            }

            int nDef = pTarget.MagicDefense; // * (1 + (pTarget.Magic / 100));

            if (pTarget is Character)
            {
                int nCounter = (int)(pTarget.Counteraction / 10f);
                int nPene    = (int)(pAtker.Penetration / 100f);
                if (nCounter < nPene)
                {
                    if (!Calculations.ChanceCalc((nPene - nCounter)))
                    {
                        Character pUser = pTarget as Character;
                        nDef = (int)(nDef * (1 + (pUser.MagicDefenseBonus / 100f)));
                    }
                    else
                    {
                        nAtk      = (int)(nAtk * 1.25f);
                        pSpecial |= InteractionEffect.BREAKTHROUGH;
                    }
                }
                else
                {
                    Character pUser = pTarget as Character;
                    nDef = (int)(nDef * (1 + (pUser.MagicDefenseBonus / 100f)));
                }
            }

            int nDamage = (int)((nAtk - nDef) * (1f - (pTarget.GetReduceDamage() / 100f)));

            nDamage = (int)(nDamage * (1f - (pTarget.GetTortoiseGemEffect() / 100f)));

            if (pAtker is Character && pTarget.IsMonster())
            {
                nDamage = CalcDamageUser2Monster(nDamage, nDef, pAtker.Level, pTarget.Level);
                nDamage = pTarget.AdjustMagicDamage(nDamage);
                nDamage = AdjustMinDamageUser2Monster(nDamage, pAtker, pTarget);
            }
            else if (pAtker.IsMonster() && pTarget is Character)
            {
                nDamage = CalcDamageMonster2User(nDamage, nDef, pAtker.Level, pTarget.Level);
                nDamage = pTarget.AdjustMagicDamage(nDamage);
                nDamage = AdjustMinDamageMonster2User(nDamage, pAtker, pTarget);
            }
            else
            {
                nDamage = pAtker.AdjustMagicDamage(nDamage);
            }

            if (pAtker.BattlePower < pTarget.BattlePower)
            {
                if (pTarget is Character)
                {
                    int   levelDiff = pTarget.BattlePower - pAtker.BattlePower;
                    float disccount = 0;
                    if (levelDiff > 50)
                    {
                        disccount = 50;
                    }
                    else
                    {
                        disccount = 100 - levelDiff;
                    }

                    nDamage = (int)(nDamage * (disccount / 100));
                }
            }

            if (pAtker.SkillCriticalStrike > pTarget.Immunity)
            {
                if (Calculations.ChanceCalc((float)(pAtker.SkillCriticalStrike - pTarget.Immunity) / 100))
                {
                    nDamage   = (int)(nDamage * 2f);
                    pSpecial |= InteractionEffect.CRITICAL_STRIKE;
                }
            }

            if (QueryMagic() != null && QueryMagic().GetElement() > ElementType.NONE)
            {
                switch (QueryMagic().GetElement())
                {
                case ElementType.WATER:
                    pSpecial |= InteractionEffect.WATER_RESIST;
                    break;

                case ElementType.FIRE:
                    pSpecial |= InteractionEffect.FIRE_RESIST;
                    break;

                case ElementType.WOOD:
                    pSpecial |= InteractionEffect.WOOD_RESIST;
                    break;

                case ElementType.METAL:
                    pSpecial |= InteractionEffect.METAL_RESIST;
                    break;

                case ElementType.EARTH:
                    pSpecial |= InteractionEffect.EARTH_RESIST;
                    break;
                }
            }

            if (pAtker is Monster && QueryMagic() != null && QueryMagic().GetElement() > ElementType.NONE)
            {
                nDamage += pAtker.Magics.GetElementPower(pTarget);
                //switch (QueryMagic().GetElement())
                //{
                //    case ElementType.WATER:
                //        {
                //            nDamage = (int)(nDamage * (1 - (pTarget.WaterResistance / 100f)));
                //            break;
                //        }
                //    case ElementType.FIRE:
                //        {
                //            nDamage = (int)(nDamage * (1 - (pTarget.FireResistance / 100f)));
                //            break;
                //        }
                //    case ElementType.EARTH:
                //        {
                //            nDamage = (int)(nDamage * (1 - (pTarget.EarthResistance / 100f)));
                //            break;
                //        }
                //    case ElementType.WOOD:
                //        {
                //            nDamage = (int)(nDamage * (1 - (pTarget.WoodResistance / 100f)));
                //            break;
                //        }
                //    case ElementType.METAL:
                //        {
                //            nDamage = (int)(nDamage * (1 - (pTarget.MetalResistance / 100f)));
                //            break;
                //        }
                //}
            }

            if (pAtker is Character)
            {
                nDamage += pAtker.AddFinalMagicAttack;
            }
            if (pTarget is Character)
            {
                nDamage -= pTarget.AddFinalMagicDefense;
            }

            // Adjust synflag damage
            if (pTarget is DynamicNpc)
            {
                //var npc = pTarget as DynamicNpc;
                //if (npc.IsSynFlag()
                //    && npc.IsSynMoneyEmpty())
                nDamage = nDamage * Character.SYNWAR_NOMONEY_DAMAGETIMES;
            }

            return(Calculations.CutTrail(1, nDamage));
        }